diff --git a/DDAlign/include/DDAlign/GlobalDetectorAlignment.h b/DDAlign/include/DDAlign/GlobalDetectorAlignment.h index 812f6e7d13d883652bd1a9abf69b6644f5a705b5..81706df592306180dff76a6cc18ae8d0381cc3bf 100644 --- a/DDAlign/include/DDAlign/GlobalDetectorAlignment.h +++ b/DDAlign/include/DDAlign/GlobalDetectorAlignment.h @@ -37,6 +37,8 @@ namespace dd4hep { public: /// Initializing constructor GlobalDetectorAlignment(DetElement e); + /// Initializing constructor + GlobalDetectorAlignment(DetElement&& e); /// Access debugging flag static bool debug(); /// Set debugging flag diff --git a/DDAlign/src/GlobalDetectorAlignment.cpp b/DDAlign/src/GlobalDetectorAlignment.cpp index 127a62372be7ab859d68a8d83e2e4295820b4fa2..15f1e12a44156c3f5c01e277ebad48f7755abead 100644 --- a/DDAlign/src/GlobalDetectorAlignment.cpp +++ b/DDAlign/src/GlobalDetectorAlignment.cpp @@ -146,6 +146,12 @@ GlobalDetectorAlignment::GlobalDetectorAlignment(DetElement e) { } +/// Initializing constructor +GlobalDetectorAlignment::GlobalDetectorAlignment(DetElement&& e) + : DetElement(e) +{ +} + /// Access debugging flag bool GlobalDetectorAlignment::debug() { return s_GlobalDetectorAlignment_debug; diff --git a/DDCAD/src/ASSIMPWriter.cpp b/DDCAD/src/ASSIMPWriter.cpp index b3440f3a2af41217e8143cea9d0f78c1d3e83e7b..f151eda924420f154d3fec7bb1bdb5bef38ba741 100644 --- a/DDCAD/src/ASSIMPWriter.cpp +++ b/DDCAD/src/ASSIMPWriter.cpp @@ -50,12 +50,15 @@ namespace { std::unique_ptr<TGeoHMatrix> mother(new TGeoHMatrix(to_global)); mother->Multiply(p->GetMatrix()); - if ( use ) - cont.push_back(std::make_pair(p, mother.get())); - if ( recursive ) - _collect(cont, recursive, *mother, p); - if ( use ) - mother.release(); + if ( use ) { + TGeoHMatrix* m = mother.release(); + cont.push_back(std::make_pair(p, m)); + if ( recursive ) + _collect(cont, recursive, *m, p); + } + else if ( recursive ) { + _collect(cont, recursive, *mother, p); + } } } bool equals(Vertex const &lhs, Vertex const &rhs) { diff --git a/DDCore/src/Grammar.cpp b/DDCore/src/Grammar.cpp index 5b1c9a26b0a32789aa7e9cdd8178a22d00ae16f3..817afb6cc17685f11484e0f10f1a805048afef72 100644 --- a/DDCore/src/Grammar.cpp +++ b/DDCore/src/Grammar.cpp @@ -117,14 +117,14 @@ dd4hep::BasicGrammar::~BasicGrammar() { #include <iostream> /// Prenote loadable grammar void dd4hep::BasicGrammar::pre_note(const std::type_info& info, - const BasicGrammar& (*fcn)(), - specialization_t specs) { + const BasicGrammar& (*fcn)(), + specialization_t specs) { key_type hash = dd4hep::detail::hash64(typeName(info)); #ifdef DD4HEP_DEBUG_PROPERTIES std::cout << "pre_note(1) " << typeName(info) - << " " << (void*)specs.str - << " " << (void*)specs.fromString - << std::endl; + << " " << (void*)specs.str + << " " << (void*)specs.fromString + << std::endl; #endif if ( !prenote_registry().emplace(hash, std::make_pair(fcn,specs)).second ) { auto j = prenote_registry().find(hash); @@ -132,9 +132,9 @@ void dd4hep::BasicGrammar::pre_note(const std::type_info& info, #ifdef DD4HEP_DEBUG_PROPERTIES const auto& gramm = entry.first(); std::cout << "pre_note(2) " << typeName(info) - << " " << (void*)gramm.specialization.fromString - << " " << (void*)entry.second.fromString - << std::endl; + << " " << (void*)gramm.specialization.fromString + << " " << (void*)entry.second.fromString + << std::endl; #endif if ( !(entry.first == fcn && entry.second == specs) ) { // Error: Already existing grammar. @@ -157,10 +157,10 @@ const dd4hep::BasicGrammar& dd4hep::BasicGrammar::get(key_type hash) { const auto& entry = (*i).second; const auto& gramm = *entry; std::cout << "get(1) " << hash - << " grammar: " << (void*)&gramm - << " " << (void*)gramm.specialization.fromString - << " " << (void*)entry->specialization.fromString - << std::endl; + << " grammar: " << (void*)&gramm + << " " << (void*)gramm.specialization.fromString + << " " << (void*)entry->specialization.fromString + << std::endl; #endif return *(i->second); } @@ -170,9 +170,9 @@ const dd4hep::BasicGrammar& dd4hep::BasicGrammar::get(key_type hash) { const auto& entry = (*j).second; const auto& gramm = entry.first(); std::cout << "get(2) " << hash - << " " << (void*)gramm.specialization.fromString - << " " << (void*)entry.second.fromString - << std::endl; + << " " << (void*)gramm.specialization.fromString + << " " << (void*)entry.second.fromString + << std::endl; #endif return (j->second.first)(); } @@ -270,7 +270,7 @@ bool dd4hep::BasicGrammar::fromString(void* ptr, const std::string& value) const if ( specialization.fromString ) return specialization.fromString(*this, ptr, value); except("Grammar", "Cannot deserialize object with incomplete grammar: %s [%s] %p fromString: %s", - type_name().c_str(), this->name.c_str(), (void*)this, (void*)specialization.fromString); + type_name().c_str(), this->name.c_str(), (void*)this, (void*)specialization.fromString); return false; } @@ -310,7 +310,7 @@ std::string dd4hep::detail::grammar_pre_parse_map(const std::string& in) { if ( str_open ) { str_open = false; } break; case ':': - if ( str_open ) { res += '\''; str_open = false; } + if ( str_open ) { res += '\''; } res += *c; res += ' '; res += '\''; @@ -340,8 +340,8 @@ std::string dd4hep::detail::grammar_pre_parse_map(const std::string& in) { case ']': case '}': if ( str_open ) { - res += '\''; - str_open = false; + res += '\''; + str_open = false; } res += *c ; break; @@ -350,9 +350,9 @@ std::string dd4hep::detail::grammar_pre_parse_map(const std::string& in) { break; default: if ( start ) { - if ( !obj_open ) res += '\''; - start = false; - str_open = true; + if ( !obj_open ) res += '\''; + start = false; + str_open = true; } ignore_blanks = false; res += *c; @@ -379,7 +379,7 @@ std::string dd4hep::detail::grammar_pre_parse_cont(const std::string& in) { if ( str_open ) { str_open = false; } break; case ':': - if ( str_open ) { res += '\''; str_open = false; } + if ( str_open ) { res += '\''; } res += *c; res += ' '; res += '\''; @@ -410,9 +410,9 @@ std::string dd4hep::detail::grammar_pre_parse_cont(const std::string& in) { break; default: if ( start ) { - res += '\''; - start = false; - str_open = true; + res += '\''; + start = false; + str_open = true; } ignore_blanks = false; res += *c; diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp index e7dccbea8d1436398b498dee8fd854bdf67df155..415101c1add8e9adbd93206d061054be18db3531 100644 --- a/DDCore/src/plugins/LCDDConverter.cpp +++ b/DDCore/src/plugins/LCDDConverter.cpp @@ -1021,9 +1021,9 @@ xml_h LCDDConverter::handleField(const std::string& /* name */, OverlayedField f if (!fld.isValid()) { PluginDebug dbg; PluginService::Create<NamedObject*>(type + "_Convert2Detector", &m_detDesc, &field, &fld); - throw std::runtime_error("Failed to locate plugin to convert electromagnetic field:" - + std::string(f->GetName()) + " of type " + type + ". " - + dbg.missingFactory(type)); + except("LCDDConverter", "Failed to locate plugin to convert electromagnetic field:" + + std::string(f->GetName()) + " of type " + type + ". " + + dbg.missingFactory(type)); } geo.doc_fields.append(field); } @@ -1055,23 +1055,28 @@ void LCDDConverter::handleProperties(Detector::Properties& prp) const { const GeoHandler* ptr = this; std::string nam = (*i).second; const Detector::PropertyValues& vals = prp[nam]; - std::string type = vals.find("type")->second; - std::string tag = type + "_Geant4_action"; - long result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals); - if (0 == result) { - PluginDebug dbg; - result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals); + auto iter = vals.find("type"); + if ( iter != vals.end() ) { + std::string type = iter->second; + std::string tag = type + "_Geant4_action"; + long result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals); if (0 == result) { - throw std::runtime_error("Failed to locate plugin to interprete files of type" - " \"" + tag + "\" - no factory:" + type + ". " + - dbg.missingFactory(tag)); + PluginDebug dbg; + result = PluginService::Create<long>(tag, &m_detDesc, ptr, &vals); + if (0 == result) { + except("LCDDConverter", "Failed to locate plugin to interprete files of type" + " \"" + tag + "\" - no factory:" + type + ". " + + dbg.missingFactory(tag)); + } } + result = *(long*) result; + if (result != 1) { + except("LCDDConverter", "Failed to invoke the plugin " + tag + " of type " + type); + } + printout(INFO,"","+++ Executed Successfully Detector setup module %s.", type.c_str()); + continue; } - result = *(long*) result; - if (result != 1) { - throw std::runtime_error("Failed to invoke the plugin " + tag + " of type " + type); - } - printout(INFO,"","+++ Executed Successfully Detector setup module %s.",type.c_str()); + printout(INFO,"","+++ FAILED to execute Detector setup module %s.", nam.c_str()); } } @@ -1317,15 +1322,18 @@ static long create_visASCII(Detector& description, int /* argc */, char** argv) for (xml_coll_t c(geo.doc_structure, _U(volume)); c; ++c) { xml_comp_t vol = c; xml_comp_t ref = c.child(_U(visref)); - xml_comp_t vis = (*vis_map.find(ref.refStr())).second; - xml_comp_t col = vis.child(_U(color)); - os << "vol:" << vol.nameStr() << sep << "vis:" << vis.nameStr() << sep - << "visible:" << vis.visible() << sep << "r:" - << col.R() << sep << "g:" << col.G() << sep << "b:" << col.B() << sep - << "alpha:" << col.alpha() << sep << "line_style:" - << vis.attr < std::string > (_U(line_style)) << sep - << "drawing_style:" << vis.attr < std::string> (_U(drawing_style)) << sep - << "show_daughters:" << vis.show_daughters() << sep << std::endl; + auto iter = vis_map.find(ref.refStr()); + if ( iter != vis_map.end() ) { + xml_comp_t vis = iter->second; + xml_comp_t col = vis.child(_U(color)); + os << "vol:" << vol.nameStr() << sep << "vis:" << vis.nameStr() << sep + << "visible:" << vis.visible() << sep << "r:" + << col.R() << sep << "g:" << col.G() << sep << "b:" << col.B() << sep + << "alpha:" << col.alpha() << sep << "line_style:" + << vis.attr < std::string > (_U(line_style)) << sep + << "drawing_style:" << vis.attr < std::string> (_U(drawing_style)) << sep + << "show_daughters:" << vis.show_daughters() << sep << std::endl; + } } os.close(); return 1; diff --git a/DDDigi/plugins/DigiDepositDropKilled.cpp b/DDDigi/plugins/DigiDepositDropKilled.cpp index 7928cd57eec5485e52d68ec5d2b42f69460c6189..89b35f32e3a387a6c4e482abde1ed030c76a2349 100644 --- a/DDDigi/plugins/DigiDepositDropKilled.cpp +++ b/DDDigi/plugins/DigiDepositDropKilled.cpp @@ -52,6 +52,7 @@ namespace dd4hep { if ( iter->second.flag&EnergyDeposit::KILLED ) { m->remove(iter); iter = (last_cell != ~0x0ULL) ? m->data.find(last_cell) : m->begin(); + if ( iter == m->end() ) iter = m->begin(); continue; } last_cell = iter->first; diff --git a/DDDigi/src/DigiContainerCombine.cpp b/DDDigi/src/DigiContainerCombine.cpp index ff7d3dbb6adfaf4077f8087c4aace7300f1c8c31..5e1164422d7c3d8172cc9d7393ff9e71aac6599f 100644 --- a/DDDigi/src/DigiContainerCombine.cpp +++ b/DDDigi/src/DigiContainerCombine.cpp @@ -65,14 +65,14 @@ public: for( auto& i : inputs ) { Key key(i.first); if ( combine->use_key(key) ) { - keys.emplace_back(key); - work.emplace_back(&i.second); - items.insert(key.item()); + keys.emplace_back(key); + work.emplace_back(&i.second); + items.insert(key.item()); } } ::snprintf(format, sizeof(format), - "%s Thread:%%2d+++ %%-32s Out-Mask: $%04X In-Mask: $%%04X Merged %%6ld %%s", - event.id(), combine->m_deposit_mask); + "%s Thread:%%2d+++ %%-32s Out-Mask: $%04X In-Mask: $%%04X Merged %%6ld %%s", + event.id(), combine->m_deposit_mask); format[sizeof(format)-1] = 0; } @@ -107,17 +107,17 @@ public: DepositVector out(nam, combine->m_deposit_mask, SegmentEntry::UNKNOWN); for( std::size_t j = start; j < keys.size(); ++j ) { if ( keys[j].item() == key.item() ) { - if ( DepositMapping* m = std::any_cast<DepositMapping>(work[j]) ) - merge_depos(out, *m, thr); - else if ( DepositVector* v = std::any_cast<DepositVector>(work[j]) ) - merge_depos(out, *v, thr); - else - break; - used_keys_insert(keys[j]); + if ( DepositMapping* m = std::any_cast<DepositMapping>(work[j]) ) + merge_depos(out, *m, thr); + else if ( DepositVector* v = std::any_cast<DepositVector>(work[j]) ) + merge_depos(out, *v, thr); + else + break; + used_keys_insert(keys[j]); } } key.set_mask(combine->m_deposit_mask); - outputs.emplace(key, std::move(out)); + outputs.emplace(std::move(key), std::move(out)); } /// Merge history records: implicitly assume identical item types are mapped sequentially @@ -127,19 +127,19 @@ public: DetectorHistory out(nam, combine->m_deposit_mask); for( std::size_t j=start; j < keys.size(); ++j ) { if ( keys[j].item() == key.item() ) { - DetectorHistory* next = std::any_cast<DetectorHistory>(work[j]); - if ( next ) { - std::string next_name = next->name; - cnt = (combine->m_erase_combined) ? out.merge(std::move(*next)) : out.insert(*next); - combine->info(format, thr, next_name.c_str(), keys[j].mask(), cnt, "histories"); - used_keys_insert(keys[j]); - cnt_hist += cnt; - cnt_conts++; - } + DetectorHistory* next = std::any_cast<DetectorHistory>(work[j]); + if ( next ) { + std::string next_name = next->name; + cnt = (combine->m_erase_combined) ? out.merge(std::move(*next)) : out.insert(*next); + combine->info(format, thr, next_name.c_str(), keys[j].mask(), cnt, "histories"); + used_keys_insert(keys[j]); + cnt_hist += cnt; + cnt_conts++; + } } } key.set_mask(combine->m_deposit_mask); - outputs.emplace(key, std::move(out)); + outputs.emplace(std::move(key), std::move(out)); } /// Merge detector rsponse records: implicitly assume identical item types are mapped sequentially @@ -149,19 +149,19 @@ public: DetectorResponse out(nam, combine->m_deposit_mask); for( std::size_t j=start; j < keys.size(); ++j ) { if ( keys[j].item() == key.item() ) { - DetectorResponse* next = std::any_cast<DetectorResponse>(work[j]); - if ( next ) { - std::string next_name = next->name; - cnt = (combine->m_erase_combined) ? out.merge(std::move(*next)) : out.insert(*next); - combine->info(format, thr, next_name.c_str(), keys[j].mask(), cnt, "responses"); - used_keys_insert(keys[j]); - cnt_response += cnt; - cnt_conts++; - } + DetectorResponse* next = std::any_cast<DetectorResponse>(work[j]); + if ( next ) { + std::string next_name = next->name; + cnt = (combine->m_erase_combined) ? out.merge(std::move(*next)) : out.insert(*next); + combine->info(format, thr, next_name.c_str(), keys[j].mask(), cnt, "responses"); + used_keys_insert(keys[j]); + cnt_response += cnt; + cnt_conts++; + } } } key.set_mask(combine->m_deposit_mask); - outputs.emplace(key, std::move(out)); + outputs.emplace(std::move(key), std::move(out)); } /// Merge particle objects: implicitly assume identical item types are mapped sequentially @@ -171,17 +171,19 @@ public: ParticleMapping out(nam, combine->m_deposit_mask); for( std::size_t j=start; j < keys.size(); ++j ) { if ( keys[j].item() == key.item() ) { - ParticleMapping* next = std::any_cast<ParticleMapping>(work[j]); - std::string next_name = next->name; - cnt = (combine->m_erase_combined) ? out.merge(std::move(*next)) : out.insert(*next); - combine->info(format, thr, next_name.c_str(), keys[j].mask(), cnt, "particles"); - used_keys_insert(keys[j]); - cnt_parts += cnt; - cnt_conts++; + ParticleMapping* next = std::any_cast<ParticleMapping>(work[j]); + if ( next ) { + std::string next_name = next->name; + cnt = (combine->m_erase_combined) ? out.merge(std::move(*next)) : out.insert(*next); + combine->info(format, thr, next_name.c_str(), keys[j].mask(), cnt, "particles"); + used_keys_insert(keys[j]); + cnt_parts += cnt; + cnt_conts++; + } } } key.set_mask(combine->m_deposit_mask); - outputs.emplace(key, std::move(out)); + outputs.emplace(std::move(key), std::move(out)); } /// Merge single item type @@ -189,26 +191,26 @@ public: const std::string& opt = combine->m_output_name_flag; for( std::size_t i=0; i < keys.size(); ++i ) { if ( keys[i].item() != itm ) - continue; + continue; /// Merge deposit mapping if ( DepositMapping* depom = std::any_cast<DepositMapping>(work[i]) ) { - if ( combine->m_merge_deposits ) merge(depom->name+opt, i, thr); + if ( combine->m_merge_deposits ) merge(depom->name+opt, i, thr); } /// Merge deposit vector else if ( DepositVector* depov = std::any_cast<DepositVector>(work[i]) ) { - if ( combine->m_merge_deposits ) merge(depov->name+opt, i, thr); + if ( combine->m_merge_deposits ) merge(depov->name+opt, i, thr); } /// Merge detector response else if ( DetectorResponse* resp = std::any_cast<DetectorResponse>(work[i]) ) { - if ( combine->m_merge_response ) merge_response(resp->name+opt, i, thr); + if ( combine->m_merge_response ) merge_response(resp->name+opt, i, thr); } /// Merge response history else if ( DetectorHistory* hist = std::any_cast<DetectorHistory>(work[i]) ) { - if ( combine->m_merge_history ) merge_hist(hist->name+opt, i, thr); + if ( combine->m_merge_history ) merge_hist(hist->name+opt, i, thr); } /// Merge particle container else if ( ParticleMapping* parts = std::any_cast<ParticleMapping>(work[i]) ) { - if ( combine->m_merge_particles ) merge_parts(parts->name+opt, i, thr); + if ( combine->m_merge_particles ) merge_parts(parts->name+opt, i, thr); } break; } @@ -221,8 +223,8 @@ public: }; template <> void DigiParallelWorker<DigiContainerCombine, - DigiContainerCombine::work_definition_t, - std::size_t>::execute(void* data) const { + DigiContainerCombine::work_definition_t, + std::size_t>::execute(void* data) const { calldata_t* args = reinterpret_cast<calldata_t*>(data); std::size_t cnt = 0; for( auto itm : args->items ) { @@ -301,9 +303,9 @@ bool DigiContainerCombine::use_key(Key key) const { /// Combine selected containers to one single deposit container std::size_t DigiContainerCombine::combine_containers(DigiContext& context, - DigiEvent& event, - DataSegment& inputs, - DataSegment& outputs) const + DigiEvent& event, + DataSegment& inputs, + DataSegment& outputs) const { work_definition_t def(this, event, inputs, outputs, m_used_keys_lock); if ( m_parallel ) { diff --git a/DDDigi/src/DigiStoreDump.cpp b/DDDigi/src/DigiStoreDump.cpp index 04f714dd41051bcaa6558853fab8483f58b44f5e..7fdf20bba0d5e437719abff7ef42dd7e0a968fea 100644 --- a/DDDigi/src/DigiStoreDump.cpp +++ b/DDDigi/src/DigiStoreDump.cpp @@ -74,7 +74,7 @@ template <> std::string DigiStoreDump::data_header(Key key, const std::string& t } template <> std::string DigiStoreDump::data_header(Key key, const std::string& tag, const std::any& data) const { - return data_header(key, tag, data.type()); + return data_header(std::move(key), tag, data.type()); } template <> std::vector<std::string> diff --git a/DDG4/include/DDG4/Geant4Kernel.h b/DDG4/include/DDG4/Geant4Kernel.h index f1022babfe5017252682d75b2a5cc8108539f3c6..385174646fd316a1a3138842a95814c32452ade2 100644 --- a/DDG4/include/DDG4/Geant4Kernel.h +++ b/DDG4/include/DDG4/Geant4Kernel.h @@ -61,17 +61,17 @@ namespace dd4hep { protected: /// Reference to the run manager - G4RunManager* m_runManager; + G4RunManager* m_runManager { nullptr }; /// Top level control directory - G4UIdirectory* m_control; + G4UIdirectory* m_control { nullptr }; /// Reference to Geant4 track manager - G4TrackingManager* m_trackMgr; + G4TrackingManager* m_trackMgr { nullptr }; /// Detector description object - Detector* m_detDesc; + Detector* m_detDesc { nullptr }; /// Property pool - PropertyManager m_properties; + PropertyManager m_properties { }; /// Reference to the user framework - UserFramework m_userFramework; + UserFramework m_userFramework { }; /// Action phases Phases m_phases; @@ -99,27 +99,27 @@ namespace dd4hep { int m_outputLevel; /// Master property: Number of execution threads in multi threaded mode. - int m_numThreads; + int m_numThreads = 0; /// Master property: Instantiate the Geant4 scoring manager object - int m_haveScoringMgr; + int m_haveScoringMgr = false; /// Registered action callbacks on configure - UserCallbacks m_actionConfigure; + UserCallbacks m_actionConfigure { }; /// Registered action callbacks on initialize - UserCallbacks m_actionInitialize; + UserCallbacks m_actionInitialize { }; /// Registered action callbacks on terminate - UserCallbacks m_actionTerminate; + UserCallbacks m_actionTerminate { }; /// Flag: Master instance (id<0) or worker (id >= 0) - unsigned long m_id, m_ident; + unsigned long m_id = 0, m_ident = 0; /// Access to geometry world G4VPhysicalVolume* m_world = 0; /// Parent reference - Geant4Kernel* m_master; - Geant4Kernel* m_shared; - Geant4Context* m_threadContext; + Geant4Kernel* m_master { nullptr }; + Geant4Kernel* m_shared { nullptr }; + Geant4Context* m_threadContext { nullptr }; bool isMaster() const { return this == m_master; } bool isWorker() const { return this != m_master; } diff --git a/DDG4/lcio/Geant4Output2LCIO.cpp b/DDG4/lcio/Geant4Output2LCIO.cpp index 61bff501a9f7e732dc63c4c542939f7c314d1f88..069b86600bea5ded54d7f3620db09d9b3e267436 100644 --- a/DDG4/lcio/Geant4Output2LCIO.cpp +++ b/DDG4/lcio/Geant4Output2LCIO.cpp @@ -365,7 +365,7 @@ lcio::LCCollectionVec* Geant4Output2LCIO::saveParticles(Geant4ParticleMap* parti const Geant4Particle* p = p_part[i]; MCParticleImpl* q = p_lcio[i]; const Geant4Particle::Particles& dau = p->daughters; - for(Geant4Particle::Particles::const_iterator j=dau.begin(); j!=dau.end(); ++j) { + for( Geant4Particle::Particles::const_iterator j=dau.begin(); j != dau.end(); ++j ) { int idau = *j; if ( (k=p_ids.find(idau)) == p_ids.end() ) { // Error!!! printout(FATAL,"Geant4Conversion","+++ Particle %d: FAILED to find daughter with ID:%d",p->id,idau); @@ -376,15 +376,17 @@ lcio::LCCollectionVec* Geant4Output2LCIO::saveParticles(Geant4ParticleMap* parti qdau->addParent(q); } const Geant4Particle::Particles& par = p->parents; - for(Geant4Particle::Particles::const_iterator j=par.begin(); j!=par.end(); ++j) { + for( Geant4Particle::Particles::const_iterator j=par.begin(); j != par.end(); ++j ) { int ipar = *j; // A parent ID iof -1 means NO parent, because a base of 0 is perfectly leagal! - if ( ipar>=0 && (k=p_ids.find(ipar)) == p_ids.end() ) { // Error!!! - printout(FATAL,"Geant4Conversion","+++ Particle %d: FAILED to find parent with ID:%d",p->id,ipar); - continue; + if ( ipar >= 0 ) { + if( (k=p_ids.find(ipar)) == p_ids.end() ) { // Error!!! + printout(FATAL,"Geant4Conversion","+++ Particle %d: FAILED to find parent with ID:%d",p->id,ipar); + continue; + } + int iqpar = (*k).second; + MCParticleImpl* qpar = p_lcio[iqpar]; + q->addParent(qpar); } - int iqpar = (*k).second; - MCParticleImpl* qpar = p_lcio[iqpar]; - q->addParent(qpar); } } } diff --git a/DDG4/plugins/Geant4EventReaderHepEvt.cpp b/DDG4/plugins/Geant4EventReaderHepEvt.cpp index 0a821a6716fbfcd43f29cff1d40219bcf85a8895..beddbab88e0dd50ac6a1f85e14f279335536f821 100644 --- a/DDG4/plugins/Geant4EventReaderHepEvt.cpp +++ b/DDG4/plugins/Geant4EventReaderHepEvt.cpp @@ -317,7 +317,7 @@ Geant4EventReaderHepEvt::readParticles(int /* event_number */, // // As with the parents, look for range, 2 discreet or 1 discreet // daughter. - if( (fd > -1) && (ld > -1) ) { + if( (fd > -1) && (fd < int(particles.size())) && (ld > -1) && (ld < int(particles.size())) ) { if(ld >= fd) { for(int id=fd;id<ld+1;id++) { // @@ -339,11 +339,11 @@ Geant4EventReaderHepEvt::readParticles(int /* event_number */, theParticle.addDaughter(particles[ld]); } } - else if(fd > -1) { + else if(fd > -1 && fd < int(particles.size())) { ParticleHandler part(particles[fd]); if ( !part.findParent(mcp) ) part.addParent(mcp); } - else if(ld > -1) { + else if(ld > -1 && ld < int(particles.size())) { ParticleHandler part(particles[ld]); if ( !part.findParent(mcp) ) part.addParent(mcp); } @@ -358,7 +358,7 @@ Geant4EventReaderHepEvt::readParticles(int /* event_number */, // based on the generator status, as this varies widely with different // generators. - for(std::size_t i=0; i<particles.size(); ++i ) { + for( std::size_t i=0; i < particles.size(); ++i ) { Geant4ParticleHandle p(particles[i]); if ( p->parents.size() == 0 ) { Geant4Vertex* vtx = new Geant4Vertex ; diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp index e075df7553a3d435bd92d326676bb221622fb427..9cedb5e5b40d0a16a45934c88679e9146bf9ac7a 100644 --- a/DDG4/plugins/Geant4EventReaderHepMC.cpp +++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp @@ -332,9 +332,11 @@ void HepMC::fix_particles(EventStream& info) { Geant4Vertex* v = iv.second; for (int pout : v->out) { EventStream::Particles::iterator ipp = parts.find(pout); - Geant4Particle* p = (*ipp).second; - for (int d : v->in) { - p->parents.insert(d); + if ( ipp != parts.end() ) { + Geant4Particle* p = (*ipp).second; + for (int d : v->in) { + p->parents.insert(d); + } } } } diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 1e00a3143e6f412020de164cac8643a69ee43932..9e5ff305ae44ea5d3521d3d2d3918a864b8a47cb 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -1263,19 +1263,24 @@ void Geant4Converter::handleProperties(Detector::Properties& prp) const { for( const auto& p : processors ) { const GeoHandler* hdlr = this; const Detector::PropertyValues& vals = prp[p.second]; - std::string type = vals.find("type")->second; - std::string tag = type + "_Geant4_action"; - Detector* det = const_cast<Detector*>(&m_detDesc); - long res = PluginService::Create<long>(tag, det, hdlr, &vals); - if ( 0 == res ) { - throw std::runtime_error("Failed to locate plugin to interprete files of type" - " \"" + tag + "\" - no factory:" + type); - } - res = *(long*)res; - if ( res != 1 ) { - throw std::runtime_error("Failed to invoke the plugin " + tag + " of type " + type); + auto iter = vals.find("type"); + if ( iter != vals.end() ) { + std::string type = iter->second; + std::string tag = type + "_Geant4_action"; + Detector* det = const_cast<Detector*>(&m_detDesc); + long res = PluginService::Create<long>(tag, det, hdlr, &vals); + if ( 0 == res ) { + throw std::runtime_error("Failed to locate plugin to interprete files of type" + " \"" + tag + "\" - no factory:" + type); + } + res = *(long*)res; + if ( res != 1 ) { + throw std::runtime_error("Failed to invoke the plugin " + tag + " of type " + type); + } + printout(outputLevel, "Geant4Converter", "+++++ Executed Successfully Geant4 setup module *%s*.", type.c_str()); + continue; } - printout(outputLevel, "Geant4Converter", "+++++ Executed Successfully Geant4 setup module *%s*.", type.c_str()); + printout(outputLevel, "Geant4Converter", "+++++ FAILED to execute Geant4 setup module *%s*.", p.second.c_str()); } } @@ -1599,11 +1604,13 @@ void Geant4Converter::printSensitive(SensitiveDetector sens_det, const std::set< for (const auto i : volset ) { std::map<Volume, G4LogicalVolume*>::iterator v = info.g4Volumes.find(i); - G4LogicalVolume* vol = (*v).second; - str.str(""); - str << " | " << "Volume:" << std::setw(24) << std::left << vol->GetName() << " " - << vol->GetNoDaughters() << " daughters."; - printout(INFO, "Geant4Converter", str.str().c_str()); + if ( v != info.g4Volumes.end() ) { + G4LogicalVolume* vol = (*v).second; + str.str(""); + str << " | " << "Volume:" << std::setw(24) << std::left << vol->GetName() << " " + << vol->GetNoDaughters() << " daughters."; + printout(INFO, "Geant4Converter", str.str().c_str()); + } } } diff --git a/DDG4/src/Geant4Kernel.cpp b/DDG4/src/Geant4Kernel.cpp index 8f83fa00b88f4152a7e758b82064b04515c963e7..f8c5596f1d015f3acbe091b86a4bd212a8df5b44 100644 --- a/DDG4/src/Geant4Kernel.cpp +++ b/DDG4/src/Geant4Kernel.cpp @@ -94,7 +94,7 @@ Geant4Kernel::Geant4Kernel(Detector& description_ref) declareProperty("OutputLevel", m_outputLevel = DEBUG); declareProperty("NumEvents", m_numEvent = 10); declareProperty("OutputLevels", m_clientLevels); - declareProperty("NumberOfThreads", m_numThreads); + declareProperty("NumberOfThreads", m_numThreads = 0); declareProperty("HaveScoringManager", m_haveScoringMgr = false); declareProperty("SensitiveTypes", m_sensitiveDetectorTypes); declareProperty("RunManagerType", m_runManagerType = "G4RunManager"); diff --git a/DDG4/src/Geant4ParticlePrint.cpp b/DDG4/src/Geant4ParticlePrint.cpp index ae7a46102c5640d7075f3c0886053905753a797e..85fafe9bc4dfd6036f90e4d178c6eabd8d8a393f 100644 --- a/DDG4/src/Geant4ParticlePrint.cpp +++ b/DDG4/src/Geant4ParticlePrint.cpp @@ -206,8 +206,11 @@ void Geant4ParticlePrint::printParticleTree(const G4Event* e, printParticle(txt, e, p); // For all particles, the set of daughters must be contained in the record. for( int id_dau : p->daughters ) { - Geant4ParticleHandle dau = (*particles.find(id_dau)).second; - printParticleTree(e, particles, level+1, dau); + auto iter = particles.find(id_dau); + if ( iter != particles.end() ) { + Geant4ParticleHandle dau = iter->second; + printParticleTree(e, particles, level+1, dau); + } } }