diff --git a/DDAlign/src/GlobalAlignmentCache.cpp b/DDAlign/src/GlobalAlignmentCache.cpp index fd36e210134346794ade8d658a0d7629f069758b..c177f8c0f757e031966e19452c285e2423b85665 100644 --- a/DDAlign/src/GlobalAlignmentCache.cpp +++ b/DDAlign/src/GlobalAlignmentCache.cpp @@ -157,7 +157,7 @@ vector<GlobalAlignment> GlobalAlignmentCache::matches(const string& match, bool const char* n = v.second->GetName(); if ( 0 == ::strncmp(n,match.c_str(),len) ) { if ( exclude_exact && len == ::strlen(n) ) continue; - result.push_back(GlobalAlignment(v.second)); + result.emplace_back(GlobalAlignment(v.second)); } } } @@ -194,7 +194,7 @@ void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) { while(stack.size() > 0) { Entry* e = stack.pop().release(); DetElement det = _detector(e->detector); - all[det].push_back(e); + all[det].emplace_back(e); if ( stack.hasMatrix(*e) || stack.needsReset(*e) || stack.resetChildren(*e) ) { detelt_updates.insert(make_pair(e->detector.path(),e->detector)); } diff --git a/DDAlign/src/GlobalAlignmentStack.cpp b/DDAlign/src/GlobalAlignmentStack.cpp index 789918ceea23fbf5d15d2cb803fc22a88fc68cc2..1a87663a759c0f4a8c96387cdec8de200d9fe2ef 100644 --- a/DDAlign/src/GlobalAlignmentStack.cpp +++ b/DDAlign/src/GlobalAlignmentStack.cpp @@ -171,8 +171,7 @@ dd4hep_ptr<GlobalAlignmentStack::StackEntry> GlobalAlignmentStack::pop() { vector<const GlobalAlignmentStack::StackEntry*> GlobalAlignmentStack::entries() const { vector<const StackEntry*> result; result.reserve(m_stack.size()); - for(Stack::const_iterator i=m_stack.begin(); i != m_stack.end(); ++i) - result.push_back((*i).second); + transform(begin(m_stack),end(m_stack),back_inserter(result),detail::select2nd(m_stack)); return result; } diff --git a/DDAlign/src/GlobalDetectorAlignment.cpp b/DDAlign/src/GlobalDetectorAlignment.cpp index 5d5316ae341b554c1d2caafcd581d9edefc495ab..35b26fb4e69ea01fa705c328922fc00512241427 100644 --- a/DDAlign/src/GlobalDetectorAlignment.cpp +++ b/DDAlign/src/GlobalDetectorAlignment.cpp @@ -130,11 +130,11 @@ namespace { // << " " << string((*j)->GetName()) << " "; if ( ::strcmp((*j).ptr()->GetName(),(*k).placement().ptr()->GetName()) ) { //cout << "[DE]"; - elements.push_back(make_pair(level,*k)); + elements.emplace_back(make_pair(level,*k)); ++k; } else { - //elements.push_back(make_pair(level,DetElement())); + //elements.emplace_back(make_pair(level,DetElement())); } //cout << " "; } @@ -236,10 +236,10 @@ GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, TGeoHMatr return _align(_alignment(*this),matrix,chk,overlap); else if ( elt_path[0] == '/' ) { GlobalAlignment a(elt_path); - volumeAlignments().push_back(a); + volumeAlignments().emplace_back(a); return _align(a,matrix,chk,overlap); } GlobalAlignment a(placementPath()+'/'+elt_path); - volumeAlignments().push_back(a); + volumeAlignments().emplace_back(a); return _align(a,matrix,chk,overlap); } diff --git a/DDCond/include/DDCond/ConditionsSelectors.h b/DDCond/include/DDCond/ConditionsSelectors.h index b3a26f26cca82b8d4f890504bb92f6ca7f69bd73..cda688aab2ea6c24fc3aa656d4488730ca770b35 100644 --- a/DDCond/include/DDCond/ConditionsSelectors.h +++ b/DDCond/include/DDCond/ConditionsSelectors.h @@ -50,7 +50,7 @@ namespace dd4hep { T& mapping; SequenceSelect(T& o) : mapping(o) { } bool operator()(Condition::Object* o) const - { mapping.insert(mapping.end(), o); return true; } + { mapping.emplace(mapping.end(), o); return true; } }; /// Mapped container selection operator for conditions mappings @@ -59,11 +59,11 @@ namespace dd4hep { * \version 1.0 * \ingroup DD4HEP_CONDITIONS */ - template <typename T> struct MapSelect : public Cond__Oper { + template <typename T> struct MapSelect : public Cond__Oper { T& mapping; - MapSelect(T& o) : mapping(o) { } + MapSelect(T& o) : mapping(o) { } bool operator()(Condition::Object* o) const - { return mapping.insert(std::make_pair(o->hash,o)).second; } + { return mapping.emplace(o->hash,o).second; } }; /// Helper to collect conditions using a ConditionsSelect base class @@ -76,8 +76,8 @@ namespace dd4hep { T& mapping; MapConditionsSelect(T& o) : mapping(o) { } virtual bool operator()(Condition::Object* o) const - { return mapping.insert(std::make_pair(o->hash,o)).second; } - virtual size_t size() const { return mapping.size(); } + { return mapping.emplace(o->hash,o).second; } + virtual size_t size() const { return mapping.size(); } }; /// Helper to insert objects into a conditions pool @@ -116,7 +116,7 @@ namespace dd4hep { ActiveSelect(T& p) : collection(p) {} bool operator()(object_t* o) const { if ( (o->flags & Condition::ACTIVE) ) { - collection.insert(collection.end(),o); + collection.emplace(collection.end(),o); return true; } return false; @@ -136,7 +136,7 @@ namespace dd4hep { KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) { } bool operator()(object_t* o) const { if ( o->hash == key ) { - collection.insert(collection.end(),o); + collection.emplace(collection.end(),o); return true; } return false; diff --git a/DDCond/src/ConditionsDataLoader.cpp b/DDCond/src/ConditionsDataLoader.cpp index b4c379d434348c141a554f52a88524eb3ed91e04..c9953cf1b153e3be97b920174c373b47fa1e4441 100644 --- a/DDCond/src/ConditionsDataLoader.cpp +++ b/DDCond/src/ConditionsDataLoader.cpp @@ -46,12 +46,12 @@ const dd4hep::Property& ConditionsDataLoader::operator[](const std::string& prop /// Add data source definition to loader void ConditionsDataLoader::addSource(const string& source, const IOV& iov) { - m_sources.push_back(make_pair(source,iov)); + m_sources.emplace_back(source,iov); } /// Add data source definition to loader void ConditionsDataLoader::addSource(const string& source) { - m_sources.push_back(make_pair(source,IOV(0,0))); + m_sources.emplace_back(source,IOV(0,0)); } /// Queue update to manager. diff --git a/DDCond/src/ConditionsDependencyHandler.cpp b/DDCond/src/ConditionsDependencyHandler.cpp index 01c93a25fca413abdd73fb309ebe1ef651968bb9..e34b758ebc5ac1d83c175036e892579d616fd143 100644 --- a/DDCond/src/ConditionsDependencyHandler.cpp +++ b/DDCond/src/ConditionsDependencyHandler.cpp @@ -66,11 +66,11 @@ ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager mgr, { const IOV& iov = m_pool.validity(); unsigned char* p = new unsigned char[dependencies.size()*sizeof(Work)]; - Dependencies::const_iterator idep = dependencies.begin(); m_block = (Work*)p; - for(size_t i=0; i<dependencies.size(); ++i, ++idep, p+=sizeof(Work)) { - Work* w = new(p) Work(this,(*idep).second,user_param,iov); - m_todo.insert(std::make_pair((*idep).first,w)); + for(const auto& d : dependencies) { + Work* w = new(p) Work(this,d.second,user_param,iov); + m_todo.emplace(d.first,w); + p += sizeof(Work); } m_iovType = iov.iovType; } @@ -117,7 +117,7 @@ void ConditionsDependencyHandler::resolve() { } ++num_resolved; // Fill an empty map of condition vectors for the block inserts - auto ret = work_pools.insert(make_pair(w->iov->keyData,tmp)); + auto ret = work_pools.emplace(w->iov->keyData,tmp); if ( ret.second ) { // There is sort of the hope that most conditions go into 1 pool... ret.first->second.reserve(m_todo.size()); @@ -127,7 +127,7 @@ void ConditionsDependencyHandler::resolve() { for( const auto& c : m_todo ) { w = c.second; auto& section = work_pools[w->iov->keyData]; - section.push_back(w->condition); + section.emplace_back(w->condition); #if 0 printout(prt_lvl,"DependencyHandler","++ Register %s %s %s [%s]", w->context.dependency->target.toString().c_str(), @@ -177,7 +177,7 @@ std::vector<Condition> ConditionsDependencyHandler::getByItem(Condition::itemkey item_selector(Condition::itemkey_type k) : key(k) {} int operator()(Condition cond) { ConditionKey::KeyMaker km(cond->hash); - if ( km.values.item_key == key ) conditions.push_back(cond); + if ( km.values.item_key == key ) conditions.emplace_back(cond); return 1; } }; diff --git a/DDCond/src/ConditionsIOVPool.cpp b/DDCond/src/ConditionsIOVPool.cpp index 3385dec36dd10ed67ed274ae8f80aa902588e297..ecb5558744cd91d75077a697848e249895f26295 100644 --- a/DDCond/src/ConditionsIOVPool.cpp +++ b/DDCond/src/ConditionsIOVPool.cpp @@ -196,7 +196,7 @@ size_t ConditionsIOVPool::select(const IOV& req_validity, std::vector<Element>& if ( !IOV::key_contains_range(i.first, req_key) ) { continue; } - valid.push_back(i.second); + valid.emplace_back(i.second); ++num_selected; } } diff --git a/DDCond/src/ConditionsManager.cpp b/DDCond/src/ConditionsManager.cpp index 8ca9ca5a76dad5fbc27a6d178ef28970f86e3f40..93ef6ee0920cae7bd90d30ad990893f48fc5b646 100644 --- a/DDCond/src/ConditionsManager.cpp +++ b/DDCond/src/ConditionsManager.cpp @@ -98,7 +98,7 @@ const vector<const IOVType*> ConditionsManagerObject::iovTypesUsed() const { vector<const IOVType*> result; const auto& types = this->iovTypes(); for ( const auto& i : types ) { - if ( int(i.type) != IOVType::UNKNOWN_IOV ) result.push_back(&i); + if ( int(i.type) != IOVType::UNKNOWN_IOV ) result.emplace_back(&i); } return result; } @@ -208,8 +208,9 @@ const vector<const IOVType*> ConditionsManager::iovTypesUsed() const { Object* obj = access(); vector<const IOVType*> result; const auto& types = obj->iovTypes(); + result.reserve(types.size()); for(const auto& i : types ) - if ( int(i.type) != IOVType::UNKNOWN_IOV ) result.push_back(&i); + if ( int(i.type) != IOVType::UNKNOWN_IOV ) result.emplace_back(&i); return result; } diff --git a/DDCond/src/ConditionsOperators.cpp b/DDCond/src/ConditionsOperators.cpp index 97afbc2d49db103acf849b8c5449518f00563a5d..d1eeea0a2914cab2f52cbd1d8d5c7e71155173f0 100644 --- a/DDCond/src/ConditionsOperators.cpp +++ b/DDCond/src/ConditionsOperators.cpp @@ -44,7 +44,7 @@ size_t Operators::collectAllConditions(ConditionsManager manager, RangeCondition RangeConditions rc; cp.second->select_all(rc); for( auto c : rc ) - conditions.push_back(c); + conditions.emplace_back(c); num_conditions += rc.size(); } } @@ -71,7 +71,7 @@ size_t Operators::collectAllConditions(ConditionsManager manager, std::map<int,C RangeConditions rc; cp.second->select_all(rc); for( auto c : rc ) - conditions.insert(make_pair(c->hash,c)); + conditions.emplace(c->hash,c); num_conditions += rc.size(); } } diff --git a/DDCond/src/ConditionsRepository.cpp b/DDCond/src/ConditionsRepository.cpp index e55633d9da0b78288d7de6065294cef471e44567..9738e18e53f468008b121d9ba15cf5cfeb30113c 100644 --- a/DDCond/src/ConditionsRepository.cpp +++ b/DDCond/src/ConditionsRepository.cpp @@ -94,7 +94,7 @@ namespace { e.name = element.attr<string>(_U(name)); e.address = element.attr<string>(_U(ref)); if ( data.size() == cap ) data.reserve(cap+500); - data.push_back(e); + data.emplace_back(e); } }; xml::DocumentHolder doc(xml::DocumentHandler().load(input)); @@ -187,7 +187,7 @@ namespace { size_t cap = data.capacity(); ::sscanf(text,"%16llX",&e.key); if ( data.size() == cap ) data.reserve(cap+500); - data.push_back(e); + data.emplace_back(e); } } while(in.good() && !in.eof() ); in.close(); diff --git a/DDCond/src/ConditionsRootPersistency.cpp b/DDCond/src/ConditionsRootPersistency.cpp index f75c99c78fe86d325a96d965b3a827bb97af93bc..28ed62862bdf00830ef6bef93483d05b2f3d84fb 100644 --- a/DDCond/src/ConditionsRootPersistency.cpp +++ b/DDCond/src/ConditionsRootPersistency.cpp @@ -45,7 +45,7 @@ namespace { Scanner(ConditionsRootPersistency::pool_type& p) : pool(p) {} /// Conditions callback for object processing virtual int process(Condition c) const override { - pool.push_back(c.ptr()); + pool.emplace_back(c.ptr()); return 1; } }; @@ -81,7 +81,7 @@ size_t ConditionsRootPersistency::add(const std::string& identifier, const IOV& iov, std::vector<Condition>& conditions) { DurationStamp stamp(this); - conditionPools.push_back(pair<iov_key_type, pool_type>()); + conditionPools.emplace_back(pair<iov_key_type, pool_type>()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; key.first = identifier; @@ -95,7 +95,7 @@ size_t ConditionsRootPersistency::add(const std::string& identifier, /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! size_t ConditionsRootPersistency::add(const string& identifier, ConditionsPool& pool) { DurationStamp stamp(this); - conditionPools.push_back(pair<iov_key_type, pool_type>()); + conditionPools.emplace_back(pair<iov_key_type, pool_type>()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; const IOV* iov = pool.iov; @@ -112,7 +112,7 @@ size_t ConditionsRootPersistency::add(const string& identifier, const Conditions size_t count = 0; DurationStamp stamp(this); for( const auto& p : pool.elements ) { - iovPools.push_back(pair<iov_key_type, pool_type>()); + iovPools.emplace_back(pair<iov_key_type, pool_type>()); pool_type& ent = iovPools.back().second; iov_key_type& key = iovPools.back().first; const IOV* iov = p.second->iov; @@ -129,7 +129,7 @@ size_t ConditionsRootPersistency::add(const string& identifier, const Conditions /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! size_t ConditionsRootPersistency::add(const string& identifier, const UserPool& pool) { DurationStamp stamp(this); - userPools.push_back(pair<iov_key_type, pool_type>()); + userPools.emplace_back(pair<iov_key_type, pool_type>()); pool_type& ent = userPools.back().second; iov_key_type& key = userPools.back().first; const IOV& iov = pool.validity(); diff --git a/DDCond/src/ConditionsTextRepository.cpp b/DDCond/src/ConditionsTextRepository.cpp index 3be4589ea3e265c08d1aeb68c093e4a0698dde19..d6b84bbe989c1e8072be6927da37442b93c9157c 100644 --- a/DDCond/src/ConditionsTextRepository.cpp +++ b/DDCond/src/ConditionsTextRepository.cpp @@ -92,7 +92,7 @@ namespace { e.name = element.attr<string>(_U(name)); e.address = element.attr<string>(_U(ref)); if ( data.size() == cap ) data.reserve(cap+500); - data.push_back(e); + data.emplace_back(e); } }; xml::DocumentHolder doc(xml::DocumentHandler().load(input)); @@ -188,7 +188,7 @@ namespace { size_t cap = data.capacity(); ::sscanf(text,"%16llX",&e.key); if ( data.size() == cap ) data.reserve(cap+500); - data.push_back(e); + data.emplace_back(e); } } while(in.good() && !in.eof() ); in.close(); diff --git a/DDCond/src/ConditionsTreePersistency.cpp b/DDCond/src/ConditionsTreePersistency.cpp index cb0fff8461b70a3c6b85d852fad598f8226c1db0..9d8311d1dd5e44a7986719189e3519352a5437fd 100644 --- a/DDCond/src/ConditionsTreePersistency.cpp +++ b/DDCond/src/ConditionsTreePersistency.cpp @@ -44,7 +44,7 @@ namespace { Scanner(ConditionsTreePersistency::pool_type& p) : pool(p) {} /// Conditions callback for object processing virtual int process(Condition c) const override { - pool.push_back(c.ptr()); + pool.emplace_back(c.ptr()); return 1; } }; @@ -80,21 +80,21 @@ size_t ConditionsTreePersistency::add(const std::string& identifier, const IOV& iov, std::vector<Condition>& conditions) { DurationStamp stamp(this); - conditionPools.push_back(pair<iov_key_type, pool_type>()); + conditionPools.emplace_back(pair<iov_key_type, pool_type>()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; key.first = identifier; key.second.first = make_pair(iov.iovType->name,iov.type); key.second.second = iov.key(); ent = conditions; - for(auto c : ent) c.ptr()->addRef(); + for(auto c : ent) c->addRef(); return ent.size(); } /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! size_t ConditionsTreePersistency::add(const string& identifier, ConditionsPool& pool) { DurationStamp stamp(this); - conditionPools.push_back(pair<iov_key_type, pool_type>()); + conditionPools.emplace_back(pair<iov_key_type, pool_type>()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; const IOV* iov = pool.iov; @@ -111,7 +111,7 @@ size_t ConditionsTreePersistency::add(const string& identifier, const Conditions size_t count = 0; DurationStamp stamp(this); for( const auto& p : pool.elements ) { - iovPools.push_back(pair<iov_key_type, pool_type>()); + iovPools.emplace_back(pair<iov_key_type, pool_type>()); pool_type& ent = iovPools.back().second; iov_key_type& key = iovPools.back().first; const IOV* iov = p.second->iov; diff --git a/DDCond/src/plugins/ConditionsLinearPool.cpp b/DDCond/src/plugins/ConditionsLinearPool.cpp index 15aa9e9278049c11b4c8a21d60058d4da3a1e8e9..3dbe032de509c2906e81b0cefb1cc1eb040c94c9 100644 --- a/DDCond/src/plugins/ConditionsLinearPool.cpp +++ b/DDCond/src/plugins/ConditionsLinearPool.cpp @@ -44,7 +44,7 @@ namespace dd4hep { template<typename MAPPING, typename BASE> class ConditionsLinearPool : public BASE { protected: - MAPPING m_entries; + MAPPING m_entries; /// Helper function to loop over the conditions container and apply a functor template <typename R,typename T> size_t loop(R& result, T functor) { @@ -78,7 +78,7 @@ namespace dd4hep { /// Register a new condition to this pool virtual bool insert(Condition condition) final - { m_entries.insert(m_entries.end(),condition.access()); return true; } + { m_entries.emplace(m_entries.end(),condition.access()); return true; } /// Register a new condition to this pool. May overload for performance reasons. virtual void insert(RangeConditions& rc) final @@ -128,10 +128,8 @@ namespace dd4hep { MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries; size_t len = entries.size(); if ( !m.empty() ) { - for(typename MAPPING::iterator i=m.begin(); i!=m.end(); ++i) { - Condition::Object* o = *i; - entries[o->iov].push_back(Condition(o)); - } + for(auto* o : m) + entries[o->iov].emplace_back(o); m.clear(); } return entries.size()-len; @@ -146,20 +144,20 @@ namespace dd4hep { if ( !m.empty() ) { unsigned int req_typ = req.iovType ? req.iovType->type : req.type; const IOV::Key& req_key = req.key(); - for(typename MAPPING::const_iterator i=m.begin(); i != m.end(); ++i) { - if ( key == (*i)->hash ) { - const IOV* _iov = (*i)->iov; + for(auto* e : m ) { + if ( key == e->hash ) { + const IOV* _iov = e->iov; unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type; if ( req_typ == typ ) { if ( IOV::key_is_contained(_iov->key(),req_key) ) // IOV test contained in key. Take it! - result.push_back(*i); + result.emplace_back(e); else if ( IOV::key_overlaps_lower_end(_iov->key(),req_key) ) // IOV overlap on test on the lower end of key - result.push_back(*i); + result.emplace_back(e); else if ( IOV::key_overlaps_higher_end(_iov->key(),req_key) ) // IOV overlap of test on the higher end of key - result.push_back(*i); + result.emplace_back(e); } } } diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp index d09a3b2111697f74758cabac7fc760cda701b542..d1d1a262a7b7572a0b7dc54ed9ec3720e7b89971 100644 --- a/DDCond/src/plugins/ConditionsMappedPool.cpp +++ b/DDCond/src/plugins/ConditionsMappedPool.cpp @@ -74,7 +74,7 @@ namespace dd4hep { /// Register a new condition to this pool virtual bool insert(Condition condition) final { Condition::Object* c = condition.access(); - bool result = m_entries.insert(std::make_pair(c->hash,c)).second; + bool result = m_entries.emplace(c->hash,c).second; if ( result ) return true; auto i = m_entries.find(c->hash); Condition present = (*i).second; @@ -89,7 +89,7 @@ namespace dd4hep { Condition::Object* o; for( Condition c : new_entries ) { o = c.access(); - m_entries.insert(std::make_pair(o->hash,o)); + m_entries.emplace(o->hash,o); } } @@ -146,7 +146,7 @@ namespace dd4hep { virtual size_t popEntries(UpdatePool::UpdateEntries& entries) final { detail::ClearOnReturn<MAPPING> clr(this->Self::m_entries); return this->Self::loop(entries, [&entries](const std::pair<Condition::key_type,Condition::Object*>& o) { - entries[o.second->iov].push_back(Condition(o.second));}); + entries[o.second->iov].emplace_back(o.second);}); } /// Select the conditions matching the DetElement and the conditions name @@ -154,27 +154,26 @@ namespace dd4hep { const IOV& req, RangeConditions& result) final { - //return this->Self::loop(entries, [&entries](const std::pair<key_type,Condition::Object*>& o) { - // entries[o.second->iov].push_back(Condition(o.second));}); MAPPING& m = this->ConditionsMappedPool<MAPPING,BASE>::m_entries; if ( !m.empty() ) { unsigned int req_typ = req.iovType ? req.iovType->type : req.type; const IOV::Key& req_key = req.key(); - for(typename MAPPING::const_iterator i=m.begin(); i != m.end(); ++i) { - Condition::Object* o = (*i).second; + result.reserve(m.size()); + for(const auto& e : m) { + Condition::Object* o = e.second; if ( key == o->hash ) { const IOV* _iov = o->iov; unsigned int typ = _iov->iovType ? _iov->iovType->type : _iov->type; if ( req_typ == typ ) { if ( IOV::key_is_contained(_iov->key(),req_key) ) // IOV test contained in key. Take it! - result.push_back(o); + result.emplace_back(o); else if ( IOV::key_overlaps_lower_end(_iov->key(),req_key) ) // IOV overlap on test on the lower end of key - result.push_back(o); + result.emplace_back(o); else if ( IOV::key_overlaps_higher_end(_iov->key(),req_key) ) // IOV overlap of test on the higher end of key - result.push_back(o); + result.emplace_back(o); } } } diff --git a/DDCond/src/plugins/ConditionsParser.cpp b/DDCond/src/plugins/ConditionsParser.cpp index 4cfd46ad113dc7550d0e16ff1d895664cce9470c..223ed360b49ff3054ea81455d43ce75d0add1f89 100644 --- a/DDCond/src/plugins/ConditionsParser.cpp +++ b/DDCond/src/plugins/ConditionsParser.cpp @@ -157,7 +157,7 @@ namespace dd4hep { if ( !arg->stack ) except("ConditionsParser","Non-existing Conditions stack:%s %d",__FILE__, __LINE__); else - arg->stack->push_back(val.release()); + arg->stack->emplace_back(val.release()); } else { dd4hep_ptr<Entry> val(_createStackEntry(param,e)); @@ -165,7 +165,7 @@ namespace dd4hep { if ( !arg->stack ) except("ConditionsParser","Non-existing Conditions stack:%s %d",__FILE__, __LINE__); else - arg->stack->push_back(val.release()); + arg->stack->emplace_back(val.release()); } } diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index 09af03258b51bf86f3c130aacae124a626f179a3..afc76e70a1d6c3484bd1faeb7b9ec62dc6cd6a2c 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -196,8 +196,8 @@ static int ddcond_conditions_pool_print(Detector& description, bool print_condit if ( argv[i] && 0 == ::strncmp(argv[i],"-processor",3) ) { vector<char*> args; for(int j=i; j<argc && argv[j] && 0 != ::strncmp(argv[i],"-end-processor",8); ++j) - args.push_back(argv[j]); - args.push_back(0); + args.emplace_back(argv[j]); + args.emplace_back(nullptr); return ddcond_conditions_pool_processor(description,true,print_conditions,int(args.size()-1),&args[0]); } } diff --git a/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp b/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp index 5b1c628530cde7e4e17c0ec52c6b807311dbfdd4..4289fa20bd79dd42891c87157db1adedb5254f87 100644 --- a/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp +++ b/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp @@ -101,7 +101,7 @@ void ConditionsSnapshotRootLoader::load_source(const std::string& nam) { TFile* f = TFile::Open(nam.c_str()); std::unique_ptr<ConditionsRootPersistency> p = ConditionsRootPersistency::load(f,"Conditions"); - buffers.push_back(p.release()); + buffers.emplace_back(p.release()); } size_t ConditionsSnapshotRootLoader::load_single(key_type /* key */, diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index e38d5b330fd0bee5b0ef54862e7f41ee412bb0ad..878cbb111d3b9aa3ff2f18a167f78a46358a23dd 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -388,7 +388,7 @@ ConditionsMappedUserPool<MAPPING>::get(Condition::key_type lower, Condition::key typename MAPPING::const_iterator first = m_conditions.lower_bound(lower); for(; first != m_conditions.end(); ++first ) { if ( (*first).first > upper ) break; - result.push_back((*first).second); + result.emplace_back((*first).second); } } return result; @@ -802,7 +802,7 @@ namespace dd4hep { vector<Condition> result; for( const auto& e : m_conditions ) { if ( e.second->hash >= lower && e.second->hash <= upper ) - result.push_back(e.second); + result.emplace_back(e.second); } return result; } diff --git a/DDCond/src/plugins/ConditionsXmlLoader.cpp b/DDCond/src/plugins/ConditionsXmlLoader.cpp index 58392103f087de36f39505a3b87b244e67b83c1f..1967bb814ea0fc30006804adb4a15efe70b7dbe5 100644 --- a/DDCond/src/plugins/ConditionsXmlLoader.cpp +++ b/DDCond/src/plugins/ConditionsXmlLoader.cpp @@ -123,11 +123,11 @@ size_t ConditionsXmlLoader::load_source(const std::string& nam, if ( condition.isValid() ) { if ( key == condition->hash ) { if ( req_validity.contains(condition.iov()) ) { - conditions.push_back(condition); + conditions.emplace_back(condition); continue; } } - m_buffer.push_back(condition); + m_buffer.emplace_back(condition); } } } @@ -149,7 +149,7 @@ size_t ConditionsXmlLoader::load_single(key_type key, const IOV* iov = condition->iov; if ( IOV::partial_match(req_validity,*iov) ) { if ( key == condition->hash ) { - conditions.push_back(condition); + conditions.emplace_back(condition); m_buffer.erase(j); return conditions.size()-len; } @@ -172,10 +172,10 @@ size_t ConditionsXmlLoader::load_range(key_type key, const IOV* iov = condition->iov; if ( IOV::partial_match(req_validity,*iov) ) { if ( key == condition->hash ) { - conditions.push_back(condition); + conditions.emplace_back(condition); } } - keep.push_back(condition); + keep.emplace_back(condition); } m_buffer = keep; return conditions.size()-len; diff --git a/DDCore/include/DD4hep/SurfaceInstaller.h b/DDCore/include/DD4hep/SurfaceInstaller.h index dbf4182a17138f405d8366c412b06c4153311d5e..99fc4ecc9c00eb5afa4c82c7d3875b2ed33aaddf 100644 --- a/DDCore/include/DD4hep/SurfaceInstaller.h +++ b/DDCore/include/DD4hep/SurfaceInstaller.h @@ -191,7 +191,7 @@ namespace { Surfaces::const_iterator is = m_surfaces.find(vol.ptr()); if ( is != m_surfaces.end() ) { VolSurface surf((*is).second); - dd4hep::rec::volSurfaceList(comp)->push_back(surf); + dd4hep::rec::volSurfaceList(comp)->emplace_back(surf); return true; } return false; @@ -201,7 +201,7 @@ namespace { template <typename UserData> void Installer<UserData>::addSurface(dd4hep::DetElement component, const dd4hep::rec::VolSurface& surf) { m_surfaces.insert(std::make_pair(surf.volume().ptr(),surf.ptr())); - dd4hep::rec::volSurfaceList(component)->push_back(surf); + dd4hep::rec::volSurfaceList(component)->emplace_back(surf); } /// Default (empty argument handler diff --git a/DDCore/include/DD4hep/detail/BasicGrammar_inl.h b/DDCore/include/DD4hep/detail/BasicGrammar_inl.h index 485fa5a8d91ecb63fde2a6c8156d8e791030a4f4..993ff83ab7e544e2576fdd43b4f055f7873da312 100644 --- a/DDCore/include/DD4hep/detail/BasicGrammar_inl.h +++ b/DDCore/include/DD4hep/detail/BasicGrammar_inl.h @@ -158,7 +158,7 @@ namespace dd4hep { for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !grammar.fromString(&val,*i) ) return 0; - p->push_back(val); + p->emplace_back(val); } return 1; } @@ -170,7 +170,7 @@ namespace dd4hep { for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !grammar.fromString(&val,*i) ) return 0; - p->push_back(val); + p->emplace_back(val); } return 1; } @@ -182,7 +182,7 @@ namespace dd4hep { for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !grammar.fromString(&val,*i) ) return 0; - p->insert(val); + p->emplace(val); } return 1; } @@ -194,7 +194,7 @@ namespace dd4hep { for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !grammar.fromString(&val,*i) ) return 0; - p->push_back(val); + p->emplace_back(val); } return 1; } @@ -206,7 +206,7 @@ namespace dd4hep { for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !grammar.fromString(&val,*i) ) return 0; - p->insert(val); + p->emplace(val); } return 1; } diff --git a/DDCore/include/DD4hep/detail/ContainerHelpers.h b/DDCore/include/DD4hep/detail/ContainerHelpers.h index 148bb47473b4344b62620e0a00ddb5daa3a11e5e..2f3de195c40c81444b82799ee4d6a67e10b39521 100644 --- a/DDCore/include/DD4hep/detail/ContainerHelpers.h +++ b/DDCore/include/DD4hep/detail/ContainerHelpers.h @@ -35,20 +35,20 @@ namespace dd4hep { template <typename Q, typename T> void insert_item(std::vector<T>& c, Q, const T& d) { - c.push_back(d); + c.emplace_back(d); } template <typename Q, typename T> void insert_item(std::vector<Q>& c, Q de, const T&) { - c.push_back(de); + c.emplace_back(de); } template <typename Q, typename T> void insert_item(std::list<T>& c, Q, const T& d) { - c.push_back(d); + c.emplace_back(d); } template <typename Q, typename T> void insert_item(std::list<Q>& c, Q de, const T&) { - c.push_back(de); + c.emplace_back(de); } template <typename Q, typename T> @@ -71,20 +71,20 @@ namespace dd4hep { template <typename Q, typename T> void insert_item(std::vector<std::pair<Q,T> >& c, Q de, const T& d) { - c.push_back(std::make_pair(de,d)); + c.emplace_back(std::make_pair(de,d)); } template <typename Q, typename T> void insert_item(std::vector<std::pair<std::string,T> >& c, Q de, const T& d) { - c.push_back(std::make_pair(de.path(),d)); + c.emplace_back(std::make_pair(de.path(),d)); } template <typename Q, typename T> void insert_item(std::list<std::pair<Q,T> >& c, Q de, const T& d) { - c.push_back(std::make_pair(de,d)); + c.emplace_back(std::make_pair(de,d)); } template <typename Q, typename T> void insert_item(std::list<std::pair<std::string,T> >& c, Q de, const T& d) { - c.push_back(std::make_pair(de.path(),d)); + c.emplace_back(std::make_pair(de.path(),d)); } template <typename Q, typename T> diff --git a/DDCore/include/DDSegmentation/BitFieldCoder.h b/DDCore/include/DDSegmentation/BitFieldCoder.h index 6428191a833b7344eec460c8d4338425bef1ceec..9f1030168fe52b016549d146364920210af518d3 100644 --- a/DDCore/include/DDSegmentation/BitFieldCoder.h +++ b/DDCore/include/DDSegmentation/BitFieldCoder.h @@ -292,7 +292,7 @@ namespace DDSegmentation { if( c != _del ) { if( _last == _del ) { - _tokens.push_back("") ; + _tokens.emplace_back("") ; } _tokens.back() += c ; } diff --git a/DDCore/include/DDSegmentation/MegatileLayerGridXY.h b/DDCore/include/DDSegmentation/MegatileLayerGridXY.h index 226d2bc53c664b5ca025188fcaa49674fea329a4..dccdf338b0e3035694a8c3cb803aeb7404b3989d 100644 --- a/DDCore/include/DDSegmentation/MegatileLayerGridXY.h +++ b/DDCore/include/DDSegmentation/MegatileLayerGridXY.h @@ -76,12 +76,12 @@ namespace dd4hep { } void setMegaTileCellsXY( unsigned int layer, int ix, int iy ) { - while ( _nCellsX.size()<=layer ) { - _nCellsX.push_back(0); - _nCellsY.push_back(0); - } - _nCellsX[layer] = ix; - _nCellsY[layer] = iy; + while ( _nCellsX.size()<=layer ) { + _nCellsX.emplace_back(0); + _nCellsY.emplace_back(0); + } + _nCellsX[layer] = ix; + _nCellsY[layer] = iy; } diff --git a/DDCore/include/DDSegmentation/SegmentationParameter.h b/DDCore/include/DDSegmentation/SegmentationParameter.h index ffe737863f2f0e00184fcec0b5edf4482eb0019a..98cd60bfd3efd6c4ae064dc7619b885ef3214086 100644 --- a/DDCore/include/DDSegmentation/SegmentationParameter.h +++ b/DDCore/include/DDSegmentation/SegmentationParameter.h @@ -36,7 +36,7 @@ namespace dd4hep { std::stringstream ss(s); std::string item; while (std::getline(ss, item, delimiter)) { - elements.push_back(item); + elements.emplace_back(item); } return elements; } @@ -287,7 +287,7 @@ namespace dd4hep { std::stringstream s; s << *it; s >> entry; - _value->push_back(entry); + _value->emplace_back(entry); } } } diff --git a/DDCore/include/DDSegmentation/TiledLayerGridXY.h b/DDCore/include/DDSegmentation/TiledLayerGridXY.h index 51be74245c683a608741716d65106d6c3a88ea6e..2ccb357331a91f8c39a4cbb180c9d9597ac8559b 100644 --- a/DDCore/include/DDSegmentation/TiledLayerGridXY.h +++ b/DDCore/include/DDSegmentation/TiledLayerGridXY.h @@ -104,11 +104,11 @@ namespace dd4hep { } /// set the coordinate layerOffset in X void setLayerOffsetX(double offset) { - _layerOffsetX.push_back(offset); + _layerOffsetX.emplace_back(offset); } /// set the coordinate layerOffset in Y void setLayerOffsetY(double offset) { - _layerOffsetY.push_back(offset); + _layerOffsetY.emplace_back(offset); } /// set the field name used for X void setFieldNameX(const std::string& fieldName) { @@ -125,12 +125,12 @@ namespace dd4hep { /// set the layer boundary dimension for X void setBoundaryLayerX(double halfX) { - _layerDimX.push_back(halfX); + _layerDimX.emplace_back(halfX); }; /// set the layer fraction cell size for X void setFractCellSizeXPerLayer(double newFractCellSizeX) { - _fractCellSizeXPerLayer.push_back(newFractCellSizeX); + _fractCellSizeXPerLayer.emplace_back(newFractCellSizeX); } /** \brief Returns a vector<double> of the cellDimensions of the given cell ID in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi diff --git a/DDCore/include/XML/Layering.h b/DDCore/include/XML/Layering.h index 54b9168f9911a39761a62b6058ae604197815ece..6d2a79707b1175d873c1e3e08fb08ebfcef33748 100644 --- a/DDCore/include/XML/Layering.h +++ b/DDCore/include/XML/Layering.h @@ -74,7 +74,7 @@ namespace dd4hep { return _thickness + _preOffset; } void add(const LayerSlice& slice) { - _slices.push_back(slice); + _slices.emplace_back(slice); } }; diff --git a/DDCore/src/AlignmentTools.cpp b/DDCore/src/AlignmentTools.cpp index 4d09c75dd0dca2865d74ef1cf5dc9255c41076f2..68628aef60b87bda84c53e30040c1007a1fcc21a 100644 --- a/DDCore/src/AlignmentTools.cpp +++ b/DDCore/src/AlignmentTools.cpp @@ -69,7 +69,7 @@ void dd4hep::detail::tools::computeIdeal(Alignment alignment) { for (size_t i = 0, n=path.size(); n>0 && i < n-1; ++i) { const PlacedVolume& p = path[i]; a.detectorTrafo.MultiplyLeft(p->GetMatrix()); - a.nodes.push_back(p); + a.nodes.emplace_back(p); } //a.worldTrafo = parent.nominal()->worldTrafo; //a.worldTrafo.MultiplyLeft(&a.detectorTrafo); diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp index 75c522c549267f9a5f854ac3bc6b375155ba0adb..a96c4daba842fad326d24c2e08fb813297ccecb1 100644 --- a/DDCore/src/ConditionDerived.cpp +++ b/DDCore/src/ConditionDerived.cpp @@ -199,7 +199,7 @@ DependencyBuilder::~DependencyBuilder() { /// Add a new dependency void DependencyBuilder::add(const ConditionKey& source) { if ( m_dependency ) { - m_dependency->dependencies.push_back(source); + m_dependency->dependencies.emplace_back(source); return; } except("Dependency","++ Invalid object. No further source may be added!"); diff --git a/DDCore/src/ConditionsMap.cpp b/DDCore/src/ConditionsMap.cpp index 5c7fc5789afeab48ca8a2000f4ec25be903a81bf..fe2942ba0dad0072e85fde8e11d60d9959abf396 100644 --- a/DDCore/src/ConditionsMap.cpp +++ b/DDCore/src/ConditionsMap.cpp @@ -74,7 +74,7 @@ std::vector<Condition> ConditionsMap::get(DetElement detector, virtual int process(Condition c) const override { Condition::key_type h = c->hash; if ( h >= lower && h <= upper ) { - result.push_back(c); + result.emplace_back(c); return 1; } return 0; diff --git a/DDCore/src/DetElement.cpp b/DDCore/src/DetElement.cpp index 5452d05cbf6e4e27ce1f21761a0a81badcd68caa..d42e136f5de010ddf217413927505a8284dbbcd3 100644 --- a/DDCore/src/DetElement.cpp +++ b/DDCore/src/DetElement.cpp @@ -75,7 +75,7 @@ void* DetElement::extension(unsigned long long int k, bool alert) const { /// Internal call to extend the detector element with an arbitrary structure accessible by the type void DetElement::i_addUpdateCall(unsigned int callback_type, const Callback& callback) const { - access()->updateCalls.push_back(make_pair(callback,callback_type)); + access()->updateCalls.emplace_back(callback,callback_type); } /// Remove callback from object @@ -241,7 +241,7 @@ void DetElement::check(bool cond, const string& msg) const { /// Add a new child subdetector element DetElement& DetElement::add(DetElement sdet) { if (isValid()) { - pair<Children::iterator, bool> r = object<Object>().children.insert(make_pair(sdet.name(), sdet)); + pair<Children::iterator, bool> r = object<Object>().children.emplace(sdet.name(), sdet); if (r.second) { sdet.access()->parent = *this; return *this; diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp index 76fd3808717315adfde9c5187d97e799d8affeb6..14b28c64f7c1ee615ef356381565f5b49d4d5d75 100644 --- a/DDCore/src/DetectorImp.cpp +++ b/DDCore/src/DetectorImp.cpp @@ -436,13 +436,13 @@ void DetectorImp::mapDetectorTypes() { HandleMap::const_iterator j=m_sensitive.find(det.name()); if ( j != m_sensitive.end() ) { SensitiveDetector sd((*j).second); - m_detectorTypes[sd.type()].push_back(det); + m_detectorTypes[sd.type()].emplace_back(det); } else if ( det.type() == "compound" ) { - m_detectorTypes[det.type()].push_back(det); + m_detectorTypes[det.type()].emplace_back(det); } else { - m_detectorTypes["passive"].push_back(det); + m_detectorTypes["passive"].emplace_back(det); } } } @@ -452,8 +452,9 @@ void DetectorImp::mapDetectorTypes() { vector<string> DetectorImp::detectorTypes() const { if ( m_manager->IsClosed() ) { vector<string> v; - for(DetectorTypeMap::const_iterator i=m_detectorTypes.begin(); i!=m_detectorTypes.end(); ++i) - v.push_back((*i).first); + v.reserve(m_detectorTypes.size()); + for(const auto& t : m_detectorTypes ) + v.emplace_back(t.first); return v; } throw runtime_error("detectorTypes: Call only available once the geometry is closed!"); @@ -488,8 +489,8 @@ vector<DetElement> DetectorImp::detectors(unsigned int includeFlag, unsigned int // ... if( ( det.typeFlag() & includeFlag ) == includeFlag && - ( det.typeFlag() & excludeFlag ) == 0 ) - dets.push_back( det ) ; + ( det.typeFlag() & excludeFlag ) == 0 ) + dets.emplace_back( det ) ; } } return dets ; diff --git a/DDCore/src/DetectorSelector.cpp b/DDCore/src/DetectorSelector.cpp index 3b57c84ec1eac97f116c511cea8615f77f47d179..40b2058ccbfbf42ef354cd8109a995510efddde5 100644 --- a/DDCore/src/DetectorSelector.cpp +++ b/DDCore/src/DetectorSelector.cpp @@ -62,7 +62,7 @@ DetectorSelector::detectors(unsigned int includeFlag, unsigned int excludeFlag ) // ... if( ( det.typeFlag() & includeFlag ) == includeFlag && ( det.typeFlag() & excludeFlag ) == 0 ) - result.push_back( det ) ; + result.emplace_back( det ) ; } } return result; diff --git a/DDCore/src/DetectorTools.cpp b/DDCore/src/DetectorTools.cpp index 18db92695b5833643e025406cd79bfddec0590c6..0626e6a3f855de5e7c41d49c52dede986553cb27 100644 --- a/DDCore/src/DetectorTools.cpp +++ b/DDCore/src/DetectorTools.cpp @@ -70,14 +70,14 @@ bool detail::tools::findChild(PlacedVolume parent, PlacedVolume child, Placement if ( parent.isValid() && child.isValid() ) { // Check self if ( parent.ptr() == child.ptr() ) { - path.push_back(child); + path.emplace_back(child); return true; } TIter next(parent->GetVolume()->GetNodes()); // Now check next layer children for (TGeoNode *daughter = (TGeoNode*) next(); daughter; daughter = (TGeoNode*) next()) { if ( daughter == child.ptr() ) { - path.push_back(daughter); + path.emplace_back(daughter); return true; } } @@ -88,7 +88,7 @@ bool detail::tools::findChild(PlacedVolume parent, PlacedVolume child, Placement bool res = findChild(daughter, child, sub_path); if (res) { path.insert(path.end(), sub_path.begin(), sub_path.end()); - path.push_back(daughter); + path.emplace_back(daughter); return res; } } @@ -101,14 +101,14 @@ static bool findChildByName(PlacedVolume parent, PlacedVolume child, detail::too if ( parent.isValid() && child.isValid() ) { // Check self if ( 0 == ::strcmp(parent.ptr()->GetName(),child.ptr()->GetName()) ) { - path.push_back(child); + path.emplace_back(child); return true; } TIter next(parent->GetVolume()->GetNodes()); // Now check next layer children for (TGeoNode *daughter = (TGeoNode*) next(); daughter; daughter = (TGeoNode*) next()) { if ( 0 == ::strcmp(daughter->GetName(),child.ptr()->GetName()) ) { - path.push_back(daughter); + path.emplace_back(daughter); return true; } } @@ -119,7 +119,7 @@ static bool findChildByName(PlacedVolume parent, PlacedVolume child, detail::too bool res = findChildByName(daughter, child, sub_path); if (res) { path.insert(path.end(), sub_path.begin(), sub_path.end()); - path.push_back(daughter); + path.emplace_back(daughter); return res; } } @@ -130,7 +130,7 @@ static bool findChildByName(PlacedVolume parent, PlacedVolume child, detail::too /// Collect detector elements to the top detector element (world) void detail::tools::elementPath(DetElement element, ElementPath& detectors) { for(DetElement par = element; par.isValid(); par = par.parent()) - detectors.push_back(par); + detectors.emplace_back(par); } /// Collect detector elements to any parent detector element @@ -138,12 +138,12 @@ void detail::tools::elementPath(DetElement parent, DetElement child, ElementPath detectors.clear(); if ( parent.isValid() && child.isValid() ) { if ( parent.ptr() == child.ptr() ) { - detectors.push_back(child); + detectors.emplace_back(child); return; } ElementPath elements; for(DetElement par = child; par.isValid(); par = par.parent()) { - elements.push_back(par); + elements.emplace_back(par); if ( par.ptr() == parent.ptr() ) { detectors = elements; return; @@ -159,7 +159,7 @@ void detail::tools::elementPath(DetElement parent, DetElement element, Placement for(DetElement par = element; par.isValid(); par = par.parent()) { PlacedVolume pv = par.placement(); if ( pv.isValid() ) { - det_nodes.push_back(pv); + det_nodes.emplace_back(pv); } if ( par.ptr() == parent.ptr() ) return; } @@ -171,7 +171,7 @@ void detail::tools::elementPath(DetElement element, PlacementPath& det_nodes) { for(DetElement par = element; par.isValid(); par = par.parent()) { PlacedVolume pv = par.placement(); if ( pv.isValid() ) { - det_nodes.push_back(pv); + det_nodes.emplace_back(pv); } } } @@ -255,7 +255,7 @@ static void detail::tools::makePlacementPath(PlacementPath det_nodes, PlacementP } } if ( det_nodes.size() > 0 ) { - all_nodes.push_back(det_nodes.back()); + all_nodes.emplace_back(det_nodes.back()); } } @@ -402,11 +402,11 @@ vector<string> detail::tools::pathElements(const string& path) { string tmp = path[0]=='/' ? path.substr(1) : path; for(size_t idx=tmp.find('/'); idx != string::npos; idx=tmp.find('/')) { string val = tmp.substr(0,idx); - result.push_back(val); + result.emplace_back(val); tmp = tmp.length()>idx ? tmp.substr(idx+1) : string(); } if ( !tmp.empty() ) { - result.push_back(tmp); + result.emplace_back(tmp); } } return result; diff --git a/DDCore/src/Fields.cpp b/DDCore/src/Fields.cpp index fb079957d89f379f76a00126499cb577eb21f03f..b642da53989ac90d445fadbabdc8821197b77eb3 100644 --- a/DDCore/src/Fields.cpp +++ b/DDCore/src/Fields.cpp @@ -109,13 +109,13 @@ void OverlayedField::add(CartesianField field) { bool isMag = field.MAGNETIC == (typ & field.MAGNETIC); if (isEle) { vector < CartesianField > &v = o->electric_components; - v.push_back(field); + v.emplace_back(field); o->type |= field.ELECTRIC; o->electric = v.size() == 1 ? field : CartesianField(); } if (isMag) { vector < CartesianField > &v = o->magnetic_components; - v.push_back(field); + v.emplace_back(field); o->type |= field.MAGNETIC; o->magnetic = v.size() == 1 ? field : CartesianField(); } diff --git a/DDCore/src/GeoHandler.cpp b/DDCore/src/GeoHandler.cpp index 7f63f9cc2d2274cffcc952eba0178da8c4d00bd5..faea76e28d3bb2ba6c341cb8fcafd1ff59895eab 100644 --- a/DDCore/src/GeoHandler.cpp +++ b/DDCore/src/GeoHandler.cpp @@ -41,8 +41,8 @@ namespace { collectSolid(geo, name + "_left", name + "_left", boolean->GetLeftShape(), boolean->GetLeftMatrix()); collectSolid(geo, name + "_right", name + "_right", boolean->GetRightShape(), boolean->GetRightMatrix()); } - geo.solids.insert(shape); - geo.trafos.push_back(make_pair(node, matrix)); + geo.solids.emplace(shape); + geo.trafos.emplace_back(node, matrix); } } @@ -94,7 +94,7 @@ GeoHandler& GeoHandler::collect(DetElement element, GeometryInfo& info) { // Note : assemblies and the world do not have a real volume nor a material if (info.volumeSet.find(vol) == info.volumeSet.end()) { info.volumeSet.insert(vol); - info.volumes.push_back(vol); + info.volumes.emplace_back(vol); } if (m.isValid()) info.materials.insert(m); diff --git a/DDCore/src/IDDescriptor.cpp b/DDCore/src/IDDescriptor.cpp index 8fc8b70e036b1c799dfaac63e2fe49ccb62288f8..981b3f4a8898671fe981a94d55929d523492536a 100644 --- a/DDCore/src/IDDescriptor.cpp +++ b/DDCore/src/IDDescriptor.cpp @@ -32,8 +32,8 @@ namespace { o->description = dsc; for (size_t i = 0; i < bf.size(); ++i) { const BitFieldElement* f = &bf[i]; - o->fieldIDs.push_back(make_pair(i, f->name())); - o->fieldMap.push_back(make_pair(f->name(), f)); + o->fieldIDs.emplace_back(i, f->name()); + o->fieldMap.emplace_back(f->name(), f); } } } @@ -138,7 +138,7 @@ void IDDescriptor::decodeFields(VolumeID vid, const vector<BitFieldElement>& v = access()->decoder.fields(); flds.clear(); for (auto& f : v ) - flds.push_back(make_pair(&f, f.value(vid))); + flds.emplace_back(&f, f.value(vid)); } /// Decode volume IDs and return string reprensentation for debugging purposes diff --git a/DDCore/src/JSON/Elements.cpp b/DDCore/src/JSON/Elements.cpp index 94259b0aa5df1260dadfe450b30fa0628b79fe5c..9a8c70586953ee596f6e5bbfbdfb8c0aba58fd24 100644 --- a/DDCore/src/JSON/Elements.cpp +++ b/DDCore/src/JSON/Elements.cpp @@ -358,7 +358,7 @@ vector<Attribute> Handle_t::attributes() const { if (m_node) { for(ptree::iterator i=m_node->second.begin(); i!=m_node->second.end(); ++i) { Attribute a = &(*i); - attrs.push_back(a); + attrs.emplace_back(a); } } return attrs; diff --git a/DDCore/src/Path.cpp b/DDCore/src/Path.cpp index 6d72f156214f5c8913aca39e61ebb6cc8b3561bd..a3e314be479e0ed7993f5a85581a99799c67884f 100644 --- a/DDCore/src/Path.cpp +++ b/DDCore/src/Path.cpp @@ -120,7 +120,7 @@ Path Path::normalize() const { char *token, *save=0; token = ::strtok_r(tmp,separators,&save); while(token) { - pathes.push_back(token); + pathes.emplace_back(token); token = ::strtok_r(0,separators,&save); } Path temp; diff --git a/DDCore/src/PluginCreators.cpp b/DDCore/src/PluginCreators.cpp index 60d0e1066bb72b5e7902b14c25b2ff45bc4033f3..262a986f7b95121cbe2fe7dbdc3bb3728be94aea 100644 --- a/DDCore/src/PluginCreators.cpp +++ b/DDCore/src/PluginCreators.cpp @@ -38,9 +38,9 @@ namespace dd4hep { for(int j=++i; j<argc && argv[j] && 0 != ::strncmp(argv[j],"-processor",4) && 0 != ::strncmp(argv[j],"-end-processor",8); ++j) - args.push_back(argv[j]); + args.emplace_back(argv[j]); int num_arg = int(args.size()); - args.push_back(0); + args.emplace_back(nullptr); processor = PluginService::Create<void*>(fac,&description,num_arg,&args[0]); if ( !processor ) { PluginDebug dbg; diff --git a/DDCore/src/Readout.cpp b/DDCore/src/Readout.cpp index b5a0506a412a25bbb848a87c3b82a2e23a816da7..ec3e861578e9ca61bbc11e5435d16b13e7bccbfa 100644 --- a/DDCore/src/Readout.cpp +++ b/DDCore/src/Readout.cpp @@ -68,21 +68,21 @@ vector<string> Readout::collectionNames() const { Object& ro = object<Object>(); if ( !ro.hits.empty() ) { for(const auto& hit : ro.hits ) - colls.push_back(hit.name); + colls.emplace_back(hit.name); } return colls; } throw runtime_error("dd4hep: Readout::collectionsNames: Cannot access object data [Invalid Handle]"); } -/// Access hit collections +/// Access hit collectionsy vector<const HitCollection*> Readout::collections() const { vector<const HitCollection*> colls; if ( isValid() ) { Object& ro = object<Object>(); if ( !ro.hits.empty() ) { for(const auto& hit : ro.hits ) - colls.push_back(&hit); + colls.emplace_back(&hit); } return colls; } diff --git a/DDCore/src/Shapes.cpp b/DDCore/src/Shapes.cpp index 4b412c1990d6bd1c60f86b0ae689d080ca594009..e5b1ce41cc7e336ecd0af2e74c344b14e0849f05 100644 --- a/DDCore/src/Shapes.cpp +++ b/DDCore/src/Shapes.cpp @@ -545,13 +545,13 @@ Polycone::Polycone(double startPhi, double deltaPhi, if((z.size()!=rmin.size()) || (z.size()!=rmax.size()) ) { throw runtime_error("dd4hep: Polycone: vectors z,rmin,rmax not of same length"); } - params.push_back(startPhi/units::deg); - params.push_back(deltaPhi/units::deg); - params.push_back(rmin.size()); + params.emplace_back(startPhi/units::deg); + params.emplace_back(deltaPhi/units::deg); + params.emplace_back(rmin.size()); for (size_t i = 0; i < rmin.size(); ++i) { - params.push_back(z[i] ); - params.push_back(rmin[i] ); - params.push_back(rmax[i] ); + params.emplace_back(z[i] ); + params.emplace_back(rmin[i] ); + params.emplace_back(rmax[i] ); } _assign(new TGeoPcon(¶ms[0]), "", "Polycone", true); } @@ -565,13 +565,13 @@ Polycone::Polycone(double startPhi, double deltaPhi, const vector<double>& r, co if((z.size()!=r.size()) ) { throw runtime_error("dd4hep: Polycone: vectors z,r not of same length"); } - params.push_back(startPhi/units::deg); - params.push_back(deltaPhi/units::deg); - params.push_back(r.size()); + params.emplace_back(startPhi/units::deg); + params.emplace_back(deltaPhi/units::deg); + params.emplace_back(r.size()); for (size_t i = 0; i < r.size(); ++i) { - params.push_back(z[i] ); - params.push_back(0.0 ); - params.push_back(r[i] ); + params.emplace_back(z[i] ); + params.emplace_back(0.0 ); + params.emplace_back(r[i] ); } _assign(new TGeoPcon(¶ms[0]), "", "Polycone", true); } @@ -591,13 +591,13 @@ Polycone::Polycone(const std::string& nam, double startPhi, double deltaPhi, if((z.size()!=rmin.size()) || (z.size()!=rmax.size()) ) { throw runtime_error("dd4hep: Polycone: vectors z,rmin,rmax not of same length"); } - params.push_back(startPhi/units::deg); - params.push_back(deltaPhi/units::deg); - params.push_back(rmin.size()); + params.emplace_back(startPhi/units::deg); + params.emplace_back(deltaPhi/units::deg); + params.emplace_back(rmin.size()); for (size_t i = 0; i < rmin.size(); ++i) { - params.push_back(z[i] ); - params.push_back(rmin[i] ); - params.push_back(rmax[i] ); + params.emplace_back(z[i] ); + params.emplace_back(rmin[i] ); + params.emplace_back(rmax[i] ); } _assign(new TGeoPcon(¶ms[0]), nam, "Polycone", true); } @@ -611,13 +611,13 @@ Polycone::Polycone(const std::string& nam, double startPhi, double deltaPhi, con if((z.size()!=r.size()) ) { throw runtime_error("dd4hep: Polycone: vectors z,r not of same length"); } - params.push_back(startPhi/units::deg); - params.push_back(deltaPhi/units::deg); - params.push_back(r.size()); + params.emplace_back(startPhi/units::deg); + params.emplace_back(deltaPhi/units::deg); + params.emplace_back(r.size()); for (size_t i = 0; i < r.size(); ++i) { - params.push_back(z[i] ); - params.push_back(0.0 ); - params.push_back(r[i] ); + params.emplace_back(z[i] ); + params.emplace_back(0.0 ); + params.emplace_back(r[i] ); } _assign(new TGeoPcon(¶ms[0]), nam, "Polycone", true); } @@ -630,18 +630,18 @@ void Polycone::addZPlanes(const vector<double>& rmin, const vector<double>& rmax if (rmin.size() < 2) { throw runtime_error("dd4hep: PolyCone::addZPlanes> Not enough Z planes. minimum is 2!"); } - params.push_back(sh->GetPhi1()); - params.push_back(sh->GetDphi()); - params.push_back(num + rmin.size()); + params.emplace_back(sh->GetPhi1()); + params.emplace_back(sh->GetDphi()); + params.emplace_back(num + rmin.size()); for (size_t i = 0; i < num; ++i) { - params.push_back(sh->GetZ(i)); - params.push_back(sh->GetRmin(i)); - params.push_back(sh->GetRmax(i)); + params.emplace_back(sh->GetZ(i)); + params.emplace_back(sh->GetRmin(i)); + params.emplace_back(sh->GetRmax(i)); } for (size_t i = 0; i < rmin.size(); ++i) { - params.push_back(z[i] ); - params.push_back(rmin[i] ); - params.push_back(rmax[i] ); + params.emplace_back(z[i] ); + params.emplace_back(rmin[i] ); + params.emplace_back(rmax[i] ); } _setDimensions(¶ms[0]); } @@ -1040,14 +1040,14 @@ void Polyhedra::make(const std::string& nam, int nsides, double start, double de } // No need to transform coordinates to cm. We are in the dd4hep world: all is already in cm. temp.reserve(4+z.size()*2); - temp.push_back(start); - temp.push_back(delta); - temp.push_back(double(nsides)); - temp.push_back(double(z.size())); + temp.emplace_back(start); + temp.emplace_back(delta); + temp.emplace_back(double(nsides)); + temp.emplace_back(double(z.size())); for(size_t i=0; i<z.size(); ++i) { - temp.push_back(z[i]); - temp.push_back(rmin[i]); - temp.push_back(rmax[i]); + temp.emplace_back(z[i]); + temp.emplace_back(rmin[i]); + temp.emplace_back(rmax[i]); } _assign(new TGeoPgon(&temp[0]), nam, "Polyhedra", false); } diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index 162be4e01276635fed76e680084e3f98509ab261..d30073f250e4ffb9affc78c995a5493b4e5691f2 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -134,7 +134,7 @@ namespace dd4hep { else if ( (e->flag&DetElement::Object::HAVE_SENSITIVE_DETECTOR) ) sd = m_detDesc.sensitiveDetector(e.name()); } - chain.push_back(node); + chain.emplace_back(node); if ( sd.isValid() && !pv_ids.empty() ) { Readout ro = sd.readout(); if ( ro.isValid() ) { diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp index fdd29381f994c2a5186dbed6efae3d11e9c0f3e9..5e0502d50a077a5256656f2ec0fe17ff8b741655 100644 --- a/DDCore/src/Volumes.cpp +++ b/DDCore/src/Volumes.cpp @@ -461,8 +461,7 @@ const PlacedVolume::VolIDs& PlacedVolume::volIDs() const { /// Add identifier PlacedVolume& PlacedVolume::addPhysVolID(const string& nam, int value) { - Object* obj = _data(*this); - obj->volIDs.push_back(make_pair(nam, value)); + _data(*this)->volIDs.emplace_back(nam, value); return *this; } diff --git a/DDCore/src/XML/DocumentHandler.cpp b/DDCore/src/XML/DocumentHandler.cpp index c28191b94a45c15b0aa253d86fd7b7cc270d489f..10aa758e62d19bdf14a798fb26a2f824dd6f6d7e 100644 --- a/DDCore/src/XML/DocumentHandler.cpp +++ b/DDCore/src/XML/DocumentHandler.cpp @@ -198,6 +198,11 @@ namespace dd4hep { parser->setCreateEntityReferenceNodes(false); parser->setDoNamespaces(false); parser->setDoSchema(true); + + ////parser->setDoNamespaces( true ); + //domParser->setDoSchema( true ); + ////parser->setHandleMultipleImports ( true ); + //domParser->setValidationSchemaFullChecking( true ); return parser; } } diff --git a/DDCore/src/XML/Layering.cpp b/DDCore/src/XML/Layering.cpp index 93dff1bc9343e521b4909c5aebfb3a5bb20db202..a3e6a285e6469acf5b379515a788c1ef766ed232 100644 --- a/DDCore/src/XML/Layering.cpp +++ b/DDCore/src/XML/Layering.cpp @@ -81,7 +81,7 @@ void LayeringCnv::fromCompact(Layering& layering) const { lay.compute(); // Add layer to stack once for each repetition for (int k = 0; k < repeat; ++k) - layers.push_back(new Layer(lay)); + layers.emplace_back(new Layer(lay)); } if (0 == count) { throw runtime_error("LayeringCnv::fromCompact: No layer children to be build!"); @@ -115,10 +115,9 @@ void Layering::sensitivePositionsInLayer(xml::Element e, std::vector<double>& se for (Collection_t s(lay, _U(slice)); s; ++s) { Component slice = s; pos += slice.thickness(); - if (slice.isSensitive()){ //store the position at the center of the slice - sens_pos.push_back(pos - slice.thickness()/2.); + sens_pos.emplace_back(pos - slice.thickness()/2.); } } } diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp index 01579326ac7616a54d9b53883d235134374cb38d..8b4f2b4ed9aa2ce63770f53aa9be873d7dcd746c 100644 --- a/DDCore/src/XML/XMLElements.cpp +++ b/DDCore/src/XML/XMLElements.cpp @@ -714,12 +714,12 @@ vector<Attribute> Handle_t::attributes() const { if (m_node) { #ifdef DD4HEP_USE_TINYXML for(TiXmlAttribute* a=_E(m_node)->FirstAttribute(); a; a=a->Next()) - attrs.push_back(Attribute(a)); + attrs.emplace_back(Attribute(a)); #else xercesc::DOMNamedNodeMap* l = _E(m_node)->getAttributes(); for (XmlSize_t i = 0, n = l->getLength(); i < n; ++i) { xercesc::DOMNode* attr_node = l->item(i); - attrs.push_back(Attribute(attr_node)); + attrs.emplace_back(Attribute(attr_node)); } #endif } diff --git a/DDCore/src/gdml/DetElementCreator.cpp b/DDCore/src/gdml/DetElementCreator.cpp index 25148bb88629a8c1b40edcc666b6d0aad36b55b1..392b3c2b2017b4448934241552824e308a28c6dd 100644 --- a/DDCore/src/gdml/DetElementCreator.cpp +++ b/DDCore/src/gdml/DetElementCreator.cpp @@ -162,7 +162,7 @@ DetElementCreator::~DetElementCreator() { printout(INFO,pref,"DetElementCreator: ++ Summary: SD: %-24s system:%04X Lvl:%3d Sensitives: %6d [Max: %6d].", (de.name()+string(":")).c_str(), de.id(), l.first.second, l.second.second, l.second.first); - fields[de].push_back(make_pair(l.first.second,l.second.first)); + fields[de].emplace_back(l.first.second,l.second.first); total_depth += l.second.second; ++total_cnt; } @@ -308,7 +308,7 @@ int DetElementCreator::process(PlacedVolume pv, int lvl, bool recursive) { (detector_volume_veto.empty() || pv_nam.find(detector_volume_veto) == string::npos) ) ) { - stack.push_back(Data(pv)); + stack.emplace_back(Data(pv)); if ( 0 == detector_volume_level ) { detector_volume_level = stack.size(); createTopLevelDetectors(pv); diff --git a/DDCore/src/plugins/CodeGenerator.cpp b/DDCore/src/plugins/CodeGenerator.cpp index b8d4674f84daa51d93e15c12c77e0298e6aa2e92..68378147c8428652579bdeaf34841047c253f145 100644 --- a/DDCore/src/plugins/CodeGenerator.cpp +++ b/DDCore/src/plugins/CodeGenerator.cpp @@ -211,7 +211,7 @@ namespace { if ( !r->user_limits.empty() ) { log << " vector<string> user_limits = {"; for(size_t i=0, n=r->user_limits.size(); i<n; ++i) - log << "r->user_limits.push_back(\"" << r->user_limits[i] << "\");" << newline; + log << "r->user_limits.emplace_back(\"" << r->user_limits[i] << "\");" << newline; } } @@ -231,7 +231,7 @@ namespace { Segmentation s = r->segmentation; if ( s.isValid() ) { log << "{ Segmentation s(\"" << s.name() << "\");" - << " segs.push_back(s); }" << newline; + << " segs.emplace_back(s); }" << newline; } } @@ -249,7 +249,7 @@ namespace { log << newline; log << "{ HitCollection c(\"" << c.name << "\",\"" << c.key << "\", " << c.key_min << sep << c.key_max << "); " - << " r->hits.push_back(c); } "; + << " r->hits.emplace_back(c); } "; } if ( !r->hits.empty() ) log << newline; log << " detector.add(r); }" << newline; diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index da641d19758369ac867b2d678f09a5ae10f9700a..80858ded86aae3c3c6b699fdc6710f8e45e024b9 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -212,7 +212,7 @@ static Ref_t create_DipoleField(Detector& /* description */, xml_h e) { val = coeff.coefficient() * mult; else val = _multiply<double>(coll.text(), mult); - ptr->coefficents.push_back(val); + ptr->coefficents.emplace_back(val); } obj.assign(ptr, c.nameStr(), c.typeStr()); return obj; @@ -248,9 +248,9 @@ static Ref_t create_MultipoleField(Detector& description, xml_h e) { val = coll.attr<double>(_U(value)) * mult; else val = coeff.coefficient(0.0) * mult; - ptr->coefficents.push_back(val); + ptr->coefficents.emplace_back(val); val = coeff.skew(0.0) * mult; - ptr->skews.push_back(val); + ptr->skews.emplace_back(val); } obj.assign(ptr, c.nameStr(), c.typeStr()); return obj; @@ -304,14 +304,14 @@ template <> void Converter<Plugin>::operator()(xml_h e) const { if ( type == "default" ) { for (xml_coll_t coll(e, _U(arg)); coll; ++coll) { string val = coll.attr<string>(_U(value)); - arguments.push_back(val); + arguments.emplace_back(val); } for (xml_coll_t coll(e, _U(argument)); coll; ++coll) { string val = coll.attr<string>(_U(value)); - arguments.push_back(val); + arguments.emplace_back(val); } for(vector<string>::iterator i=arguments.begin(); i!=arguments.end(); ++i) - argv.push_back(&((*i)[0])); + argv.emplace_back(&((*i)[0])); description.apply(name.c_str(),int(argv.size()), &argv[0]); return; } @@ -438,7 +438,7 @@ template <> void Converter<Material>::operator()(xml_h e) const { else except("Compact2Objects","Converting material: %s Element missing: %s",mname.c_str(),nam.c_str()); composite_fractions_total += fraction; - composite_fractions.push_back(fraction); + composite_fractions.emplace_back(fraction); } for (composites.reset(), ifrac=0; composites; ++composites, ++ifrac) { string nam = composites.attr<string>(_U(ref)); @@ -689,7 +689,7 @@ template <> void Converter<OpticalSurface>::operator()(xml_h element) const { val = ""; str >> val; if ( val.empty() && !str.good() ) break; - values.push_back(_toDouble(val)); + values.emplace_back(_toDouble(val)); } /// Create table and register table TGDMLMatrix* table = new TGDMLMatrix("",values.size()/cols, cols); @@ -737,7 +737,7 @@ template <> void Converter<PropertyTable>::operator()(xml_h e) const { val = ""; str >> val; if ( val.empty() && !str.good() ) break; - values.push_back(_toDouble(val)); + values.emplace_back(_toDouble(val)); if ( s_debug.matrix ) { cout << " state:" << (str.good() ? "OK " : "BAD") << " '" << val << "'"; if ( 0 == (values.size()%cols) ) cout << endl; @@ -826,7 +826,7 @@ template <> void Converter<Region>::operator()(xml_h elt) const { region.setStoreSecondaries(elt.attr<bool>(store_secondaries)); } for (xml_coll_t user_limits(e, _U(limitsetref)); user_limits; ++user_limits) - limits.push_back(user_limits.attr<string>(_U(name))); + limits.emplace_back(user_limits.attr<string>(_U(name))); description.addRegion(region); } @@ -867,7 +867,7 @@ template <> void Converter<Segmentation>::operator()(xml_h seg) const { vector<string> elts = DDSegmentation::splitString(par); for (const string& spar : elts ) { if ( spar.empty() ) continue; - valueVector.push_back(_toDouble(spar)); + valueVector.emplace_back(_toDouble(spar)); } typedef DDSegmentation::TypedSegmentationParameter< vector<double> > ParDouVec; static_cast<ParDouVec*>(p)->setTypedValue(valueVector); @@ -982,7 +982,7 @@ template <> void Converter<Readout>::operator()(xml_h e) const { "++ Readout[%s]: Add hit collection %s [%s] %d-%d", ro.name(), coll_name.c_str(), coll_key.c_str(), key_min, key_max); HitCollection hits(coll_name, coll_key, key_min, key_max); - ro->hits.push_back(hits); + ro->hits.emplace_back(hits); } } description.addReadout(ro); diff --git a/DDCore/src/plugins/PluginInvoker.cpp b/DDCore/src/plugins/PluginInvoker.cpp index 792cfddc02f977f0780052742da64ece7a588b56..55de9ff08ff0a7bf3caec6ce8d5d535dd5a98a2c 100644 --- a/DDCore/src/plugins/PluginInvoker.cpp +++ b/DDCore/src/plugins/PluginInvoker.cpp @@ -60,7 +60,7 @@ template <> void Converter<arg>::operator()(xml_h e) const { xml_comp_t c(e); string val = c.valueStr(); vector<string>* args = (vector<string>*)param; - args->push_back(val); + args->emplace_back(val); } /** Convert plugin objects @@ -74,11 +74,11 @@ template <> void Converter<plugin>::operator()(xml_h e) const { string nam = c.nameStr(); vector<string> args; vector<const char*> cargs; - //args.push_back("plugin:"+nam); + //args.emplace_back("plugin:"+nam); xml_coll_t(e,"arg").for_each(Converter<arg>(description,&args)); for(vector<string>::const_iterator i=args.begin(); i!=args.end();++i) - cargs.push_back((*i).c_str()); + cargs.emplace_back((*i).c_str()); printout(INFO,"ConverterPlugin","+++ Now executing plugin:%s [%d args]",nam.c_str(),int(cargs.size())); description.apply(nam.c_str(),int(cargs.size()),(char**)&cargs[0]); } diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp index 5410e13000a7b46cedcf3f0d53d7f02d00eed41f..74d99e108995b234c58212b054dd57f6d49bc03c 100644 --- a/DDCore/src/plugins/ShapePlugins.cpp +++ b/DDCore/src/plugins/ShapePlugins.cpp @@ -61,9 +61,9 @@ static Handle<TObject> create_Polycone(Detector&, xml_h element) { double start = e.startphi(0e0), deltaphi = e.deltaphi(2*M_PI); for(xml_coll_t c(e,_U(zplane)); c; ++c, ++num) { xml_comp_t plane(c); - rmin.push_back(plane.rmin()); - rmax.push_back(plane.rmax()); - z.push_back(plane.z()); + rmin.emplace_back(plane.rmin()); + rmax.emplace_back(plane.rmax()); + z.emplace_back(plane.z()); } if ( num < 2 ) { throw runtime_error("PolyCone Shape> Not enough Z planes. minimum is 2!"); @@ -237,9 +237,9 @@ static Handle<TObject> create_Polyhedra(Detector&, xml_h element) { std::vector<double> z, rmin, rmax; for ( xml_coll_t c(e,_U(plane)); c; ++c ) { xml_comp_t plane(c); - rmin.push_back(plane.rmin()); - rmax.push_back(plane.rmax()); - z.push_back(plane.z()); + rmin.emplace_back(plane.rmin()); + rmax.emplace_back(plane.rmax()); + z.emplace_back(plane.z()); } Solid solid = Polyhedra(e.numsides(),e.startphi(),e.deltaphi(),z,rmin,rmax); if ( e.hasAttr(_U(name)) ) solid->SetName(e.attr<string>(_U(name)).c_str()); @@ -252,15 +252,15 @@ static Handle<TObject> create_ExtrudedPolygon(Detector&, xml_h element) { std::vector<double> pt_x, pt_y, sec_z, sec_x, sec_y, sec_scale; for ( xml_coll_t sec(element, _U(section)); sec; ++sec ) { xml_dim_t section(sec); - sec_z.push_back(section.attr<double>(_U(z))); - sec_x.push_back(section.attr<double>(_U(x))); - sec_y.push_back(section.attr<double>(_U(y))); - sec_scale.push_back(section.attr<double>(_U(scale),1.0)); + sec_z.emplace_back(section.attr<double>(_U(z))); + sec_x.emplace_back(section.attr<double>(_U(x))); + sec_y.emplace_back(section.attr<double>(_U(y))); + sec_scale.emplace_back(section.attr<double>(_U(scale),1.0)); } for ( xml_coll_t pt(element, _U(point)); pt; ++pt ) { xml_dim_t point(pt); - pt_x.push_back(point.attr<double>(_U(x))); - pt_y.push_back(point.attr<double>(_U(y))); + pt_x.emplace_back(point.attr<double>(_U(x))); + pt_y.emplace_back(point.attr<double>(_U(y))); } Solid solid = ExtrudedPolygon(pt_x, pt_y, sec_z, sec_x, sec_y, sec_scale); if ( e.hasAttr(_U(name)) ) solid->SetName(e.attr<string>(_U(name)).c_str()); diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index 6392ec7abd8fa70c99247cec50a43abc7c4b276d..eef86ca03fe30775dd899b2b9689b27445e1767f 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -65,18 +65,18 @@ namespace { if ( use ) { ++argc; ++count; end = i; if ( 0 == ::strncmp(av[i],"-end-processor",6) ) { - argv.push_back(av[i]); + argv.emplace_back(av[i]); return; } else if ( 0 == ::strncmp(av[i],"-end-plugin",4) ) { // End of current plugin - argv.push_back((char*)"-end-processor"); + argv.emplace_back((char*)"-end-processor"); return; } else if ( 0 == ::strncmp(av[i],"-plugin",4) ) { // Start of next plugin - argv.push_back((char*)"-end-processor"); + argv.emplace_back((char*)"-end-processor"); return; } - argv.push_back(av[i]); + argv.emplace_back(av[i]); } } } @@ -180,7 +180,7 @@ static long run_function(Detector&, int argc, char** argv) { else if ( 0 == ::strncmp("-function",argv[i],4) ) func = argv[++i]; else - args.push_back(argv[i]); + args.emplace_back(argv[i]); } if ( lib.empty() || func.empty() ) { cout << diff --git a/DDCore/src/plugins/TGeoCodeGenerator.cpp b/DDCore/src/plugins/TGeoCodeGenerator.cpp index f7fc010c33296431db9a5fe1f09db9bad2215ec9..516f0ba55f190179432a5abe5d31a0a316ddb8aa 100644 --- a/DDCore/src/plugins/TGeoCodeGenerator.cpp +++ b/DDCore/src/plugins/TGeoCodeGenerator.cpp @@ -400,14 +400,14 @@ namespace { else if (cl == TGeoPgon::Class()) { const TGeoPgon* sh = (const TGeoPgon*) shape; vector<double> params; - params.push_back(sh->GetPhi1()); - params.push_back(sh->GetDphi()); - params.push_back(double(sh->GetNedges())); - params.push_back(double(sh->GetNz())); + params.emplace_back(sh->GetPhi1()); + params.emplace_back(sh->GetDphi()); + params.emplace_back(double(sh->GetNedges())); + params.emplace_back(double(sh->GetNz())); for(int i=0, n=sh->GetNz(); i<n; ++i) { - params.push_back(sh->GetZ(i)); - params.push_back(sh->GetRmin(i)); - params.push_back(sh->GetRmax(i)); + params.emplace_back(sh->GetZ(i)); + params.emplace_back(sh->GetRmin(i)); + params.emplace_back(sh->GetRmax(i)); } log << cl->GetName() << "* shape_" << pvoid << " = " << "new " << cl->GetName() << "(" << ¶ms[0] << ");" << newline; @@ -416,13 +416,13 @@ namespace { else if (cl == TGeoPcon::Class()) { const TGeoPcon* sh = (const TGeoPcon*) shape; vector<double> params; - params.push_back(sh->GetPhi1()); - params.push_back(sh->GetDphi()); - params.push_back(double(sh->GetNz())); + params.emplace_back(sh->GetPhi1()); + params.emplace_back(sh->GetDphi()); + params.emplace_back(double(sh->GetNz())); for(int i=0, n=sh->GetNz(); i<n; ++i) { - params.push_back(sh->GetZ(i)); - params.push_back(sh->GetRmin(i)); - params.push_back(sh->GetRmax(i)); + params.emplace_back(sh->GetZ(i)); + params.emplace_back(sh->GetRmin(i)); + params.emplace_back(sh->GetRmax(i)); } log << cl->GetName() << "* shape_" << pvoid << " = " << "new " << cl->GetName() << "(" << ¶ms[0] << ");" << newline; @@ -477,8 +477,8 @@ namespace { << "{" << newline << "\tstd::vector<double> vertices_" << pvoid << ";" << newline; for(int i=0; i<8; ++i) { - log << "\tvertices_" << pvoid << ".push_back(" << *v << ");" << newline; ++v; - log << "\tvertices_" << pvoid << ".push_back(" << *v << ");" << newline; ++v; + log << "\tvertices_" << pvoid << ".emplace_back(" << *v << ");" << newline; ++v; + log << "\tvertices_" << pvoid << ".emplace_back(" << *v << ");" << newline; ++v; } log << "\tshape_" << pvoid << " = new " << cl->GetName() << "(\"" << sh->GetName() << '"' @@ -493,7 +493,7 @@ namespace { << "{" << newline << "\tstd::vector<double> param_" << pvoid << ";" << newline; for( auto p : pars) - log << "\tparam_" << pvoid << ".push_back(" << p << ");" << newline; + log << "\tparam_" << pvoid << ".emplace_back(" << p << ");" << newline; log << "\tshape_" << pvoid << " = new " << cl->GetName() << "( ¶m_" << pvoid << "[0]);" << newline; log << "shape_" << pvoid << "->SetName(\"" << sh->GetName() << "\");" << newline; diff --git a/DDCore/src/plugins/VisProcessor.cpp b/DDCore/src/plugins/VisProcessor.cpp index 4cd69779a47cb5e801a387a97daa6d46ae0983e9..654e681ffbba8b3223881b3866074beec4f62953 100644 --- a/DDCore/src/plugins/VisProcessor.cpp +++ b/DDCore/src/plugins/VisProcessor.cpp @@ -194,17 +194,17 @@ static void* create_object(Detector& description, int argc, char** argv) { } else if ( ::strncmp(argv[i],"-elt-active",6) == 0 ) { Atom atom = helper.element(argv[++i]); - if ( atom.isValid() ) proc->activeElements.push_back(atom); + if ( atom.isValid() ) proc->activeElements.emplace_back(atom); continue; } else if ( ::strncmp(argv[i],"-mat-active",6) == 0 ) { Material mat = helper.material(argv[++i]); - if ( mat.isValid() ) proc->activeMaterials.push_back(mat); + if ( mat.isValid() ) proc->activeMaterials.emplace_back(mat); continue; } else if ( ::strncmp(argv[i],"-mat-inactive",6) == 0 ) { Material mat = helper.material(argv[++i]); - if ( mat.isValid() ) proc->inactiveMaterials.push_back(mat); + if ( mat.isValid() ) proc->inactiveMaterials.emplace_back(mat); continue; } else if ( ::strncmp(argv[i],"-all-inactive",6) == 0 ) { diff --git a/DDCore/src/plugins/VolumeMgrTest.cpp b/DDCore/src/plugins/VolumeMgrTest.cpp index 2f5516070ebf10065346695b8ad7a1fd3e54c3c1..7cb265decab6d909df5df9755f6dfa61deb852b2 100644 --- a/DDCore/src/plugins/VolumeMgrTest.cpp +++ b/DDCore/src/plugins/VolumeMgrTest.cpp @@ -95,7 +95,7 @@ VolIDTest::VolIDTest(Detector& description, DetElement sdet, size_t depth) : m_m PlacedVolume pv = sdet.placement(); VolIDs ids = pv.volIDs(); Chain chain; - chain.push_back(pv); + chain.emplace_back(pv); checkVolume(sdet, pv, ids, chain); walkVolume(sdet, pv, ids, chain, 1, depth); } @@ -286,7 +286,7 @@ void VolIDTest::walkVolume(DetElement detector, PlacedVolume pv, VolIDs ids, con Chain child_chain(chain); place.access(); // Test validity - child_chain.push_back(place); + child_chain.emplace_back(place); child_ids.insert(child_ids.end(), place.volIDs().begin(), place.volIDs().end()); //bool is_sensitive = place.volume().isSensitive(); //if ( is_sensitive || !child_ids.empty() ) { diff --git a/DDCore/src/python/PythonPlugin.cpp b/DDCore/src/python/PythonPlugin.cpp index 67ecee0f9189fd9424799a7394ee7c509140ad11..1a0e2beae87079b3e9719debea21c02c1f3c34d5 100644 --- a/DDCore/src/python/PythonPlugin.cpp +++ b/DDCore/src/python/PythonPlugin.cpp @@ -56,17 +56,17 @@ namespace { vector<pair<string, string> > commands; for(int i = 0; i < argc && argv[i]; ++i) { if ( 0 == ::strncmp("-import",argv[i],2) ) - commands.push_back(make_pair("import",argv[++i])); + commands.emplace_back(make_pair("import",argv[++i])); else if ( 0 == ::strncmp("-dd4hep", argv[i],2) ) - commands.push_back(make_pair("exec","import dd4hep")); + commands.emplace_back(make_pair("exec","import dd4hep")); else if ( 0 == ::strncmp("-macro", argv[i],2) ) - commands.push_back(make_pair("macro",argv[++i])); + commands.emplace_back(make_pair("macro",argv[++i])); else if ( 0 == ::strncmp("-exec", argv[i],2) ) - commands.push_back(make_pair("exec",argv[++i])); + commands.emplace_back(make_pair("exec",argv[++i])); else if ( 0 == ::strncmp("-eval", argv[i],2) ) - commands.push_back(make_pair("calc",argv[++i])); + commands.emplace_back(make_pair("calc",argv[++i])); else if ( 0 == ::strncmp("-prompt", argv[i],2) ) - commands.push_back(make_pair("prompt","")); + commands.emplace_back(make_pair("prompt","")); else usage(argc, argv); } diff --git a/DDCore/src/segmentations/BitFieldCoder.cpp b/DDCore/src/segmentations/BitFieldCoder.cpp index 26ca35fc60998ae8e727d9704ec67e7fe936f74d..d0d45ab965e9d86c16fef62f4ba745fe7eee11a5 100644 --- a/DDCore/src/segmentations/BitFieldCoder.cpp +++ b/DDCore/src/segmentations/BitFieldCoder.cpp @@ -148,8 +148,7 @@ namespace DDSegmentation { void BitFieldCoder::addField( const std::string& name, unsigned offset, int width ){ - _fields.push_back( BitFieldElement( name, offset, width ) ) ; - + _fields.emplace_back(name, offset, width); BitFieldElement& bfv = _fields.back() ; _map[ name ] = _fields.size()-1 ; diff --git a/DDCore/src/segmentations/MultiSegmentation.cpp b/DDCore/src/segmentations/MultiSegmentation.cpp index c04d1a4b51e8c42420230217068b1b5add2ad538..3c32418965bd26d0f250b37fba7625a63a76fe14 100644 --- a/DDCore/src/segmentations/MultiSegmentation.cpp +++ b/DDCore/src/segmentations/MultiSegmentation.cpp @@ -50,7 +50,7 @@ namespace dd4hep { e.key_min = key_min; e.key_max = key_max; e.segmentation = entry; - m_segmentations.push_back(e); + m_segmentations.emplace_back(e); } /// Set the underlying decoder diff --git a/DDCore/src/segmentations/Segmentation.cpp b/DDCore/src/segmentations/Segmentation.cpp index 52039388e399a0557b9ecb27faa87a2ecd8977a9..83ccd74ebb2ee2b75baa4f334177dff29fc2ef32 100644 --- a/DDCore/src/segmentations/Segmentation.cpp +++ b/DDCore/src/segmentations/Segmentation.cpp @@ -111,7 +111,7 @@ namespace dd4hep { Parameters Segmentation::parameters() const { Parameters pars; for ( const auto& it : _parameters ) - pars.push_back(it.second); + pars.emplace_back(it.second); return pars; } diff --git a/DDCore/src/segmentations/SegmentationFactory.cpp b/DDCore/src/segmentations/SegmentationFactory.cpp index 163a6d83e0e29f5fb624c1152cf39c9b0d5d0a6d..4806a4475df0476e7732858c32348b6066f81ae0 100644 --- a/DDCore/src/segmentations/SegmentationFactory.cpp +++ b/DDCore/src/segmentations/SegmentationFactory.cpp @@ -44,7 +44,7 @@ vector<std::string> SegmentationFactory::registeredSegmentations() const { vector<std::string> segmentationNames; map<std::string, SegmentationCreatorBase*>::const_iterator it; for (it = _segmentations.begin(); it != _segmentations.end(); ++ it) { - segmentationNames.push_back(it->first); + segmentationNames.emplace_back(it->first); } return segmentationNames; } diff --git a/DDCore/src/segmentations/TiledLayerSegmentation.cpp b/DDCore/src/segmentations/TiledLayerSegmentation.cpp index c79f44c18b9620cdcaeedb370f616050d9013c01..d2997687cb5561761f32f4b22e7e2349f086fa12 100644 --- a/DDCore/src/segmentations/TiledLayerSegmentation.cpp +++ b/DDCore/src/segmentations/TiledLayerSegmentation.cpp @@ -86,9 +86,9 @@ void TiledLayerSegmentation::setLayerDimensions(int layerIndex, double x, double } vector<int>::iterator it = find(_layerIndices.begin(), _layerIndices.end(), layerIndex); if (it == _layerIndices.end()) { - _layerIndices.push_back(layerIndex); - _layerDimensionsX.push_back(x); - _layerDimensionsY.push_back(y); + _layerIndices.emplace_back(layerIndex); + _layerDimensionsX.emplace_back(x); + _layerDimensionsY.emplace_back(y); } else { size_t index = it - _layerIndices.begin(); _layerDimensionsX[index] = x; diff --git a/DDDigi/include/DDDigi/DigiAction.h b/DDDigi/include/DDDigi/DigiAction.h index ff7b989767e3065d27b45d61d0a9b7bbd091dff0..a752ead24704dedf133884aa0946a9922323e1ef 100644 --- a/DDDigi/include/DDDigi/DigiAction.h +++ b/DDDigi/include/DDDigi/DigiAction.h @@ -113,7 +113,7 @@ namespace dd4hep { ~Actors() = default; size_t size() const { return m_v.size(); } void clear() { m_v.clear(); } - void add(T* obj) { m_v.push_back(obj); } + void add(T* obj) { m_v.emplace_back(obj); } void add_front(T* obj) { m_v.insert(m_v.begin(), obj); } const typename _V::value_type& operator[](size_t i) const { return m_v[i];} diff --git a/DDG4/include/DDG4/Geant4Action.h b/DDG4/include/DDG4/Geant4Action.h index 4837f0ec86a9c29bbcf160d641fd6d4c07538f98..fa83db1e8db9bb60941f3f1740d530c6d80d7f3c 100644 --- a/DDG4/include/DDG4/Geant4Action.h +++ b/DDG4/include/DDG4/Geant4Action.h @@ -150,7 +150,7 @@ namespace dd4hep { Actors() = default; ~Actors() = default; void clear() { m_v.clear(); } - void add(T* obj) { m_v.push_back(obj); } + void add(T* obj) { m_v.emplace_back(obj); } void add_front(T* obj) { m_v.insert(m_v.begin(), obj); } operator const _V&() const { return m_v; } operator _V&() { return m_v; } diff --git a/DDG4/include/DDG4/Geant4HitCollection.h b/DDG4/include/DDG4/Geant4HitCollection.h index ccbb19509ab29d43741d7f8360daee55ab4e1616..dde711f127178fc3983c615540e698a1e24357b4 100644 --- a/DDG4/include/DDG4/Geant4HitCollection.h +++ b/DDG4/include/DDG4/Geant4HitCollection.h @@ -333,7 +333,7 @@ namespace dd4hep { template <typename TYPE> void add(TYPE* hit_pointer) { Geant4HitWrapper w(m_manipulator->castHit(hit_pointer)); m_lastHit = m_hits.size(); - m_hits.push_back(w); + m_hits.emplace_back(w); } /// Add a new hit with a check, that the hit is of the same type template <typename TYPE> void add(VolumeID key, TYPE* hit_pointer) { @@ -341,7 +341,7 @@ namespace dd4hep { std::pair<Keys::iterator,bool> ret = m_keys.insert(std::make_pair(key,m_lastHit)); if ( ret.second ) { Geant4HitWrapper w(m_manipulator->castHit(hit_pointer)); - m_hits.push_back(w); + m_hits.emplace_back(w); return; } throw std::runtime_error("Attempt to insert hit with same key to G4 hit-collection "+GetName()); diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp index 13444f3e3d7f0cbd4b17456291cf466cd5e06ee4..40101c561b73849faca1ade32619c7187a382045 100644 --- a/DDG4/plugins/Geant4EventReaderHepMC.cpp +++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp @@ -233,7 +233,7 @@ Geant4EventReaderHepMC::readParticles(int /* ev_id */, //fg: for now we create exactly one event vertex here ( as before ) // this needs revisiting as HepMC allows to have more than one vertex ... Geant4Vertex* primary_vertex = new Geant4Vertex ; - vertices.push_back( primary_vertex ); + vertices.emplace_back( primary_vertex ); primary_vertex->x = 0; primary_vertex->y = 0; primary_vertex->z = 0; @@ -269,7 +269,7 @@ Geant4EventReaderHepMC::readParticles(int /* ev_id */, p->psx/MeV,p->psy/MeV,p->psz/MeV,p->time/ns, p->daughters.size(), p->parents.size()); - //output.push_back(p); + //output.emplace_back(p); //add particles to the 'primary vertex' if ( p->parents.size() == 0 ) { @@ -317,33 +317,32 @@ void HepMC::fix_particles(EventStream& info) { } } } - EventStream::Vertices::iterator j; - for(j=verts.begin(); j != verts.end(); ++j) { - Geant4Vertex* v = (*j).second; - for (ip=v->out.begin(); ip!=v->out.end();++ip) { - EventStream::Particles::iterator ipp = parts.find(*ip); + for(const auto& iv : verts) { + Geant4Vertex* v = iv.second; + for (int pout : v->out) { + EventStream::Particles::iterator ipp = parts.find(pout); Geant4Particle* p = (*ipp).second; - for (id=v->in.begin(); id!=v->in.end();++id) { - p->parents.insert(*id); + for (int d : v->in) { + p->parents.insert(d); } } } /// Particles originating from the beam (=no parents) must be /// be stripped off their parents and the status set to G4PARTICLE_GEN_DECAYED! vector<Geant4Particle*> beam; - for(i=parts.begin(); i != parts.end(); ++i) { - Geant4ParticleHandle p((*i).second); + for(const auto& ipart : parts) { + Geant4ParticleHandle p(ipart.second); if ( p->parents.size() == 0 ) { - for(id=p->daughters.begin(); id!=p->daughters.end();++id) { - Geant4Particle *pp = parts[*id]; - beam.push_back(pp); + for(int d : p->daughters) { + Geant4Particle *pp = parts[d]; + beam.emplace_back(pp); } } } - for(vector<Geant4Particle*>::iterator ipp=beam.begin(); ipp!=beam.end();++ipp) { + for(auto* ipp : beam) { //cout << "Clear parents of " << (*ipp)->id << endl; - (*ipp)->parents.clear(); - (*ipp)->status = G4PARTICLE_GEN_DECAYED; + ipp->parents.clear(); + ipp->status = G4PARTICLE_GEN_DECAYED; } } diff --git a/DDG4/plugins/Geant4HitExtractor.cpp b/DDG4/plugins/Geant4HitExtractor.cpp index cce859bec4f245a3e2a7107c5b56e122494ff0eb..4bdb773762478ad51e7ec53f600893de63820979 100644 --- a/DDG4/plugins/Geant4HitExtractor.cpp +++ b/DDG4/plugins/Geant4HitExtractor.cpp @@ -63,12 +63,12 @@ static void* _convertHitCollection(const char* source) { for(std::vector<SimpleHit*>::const_iterator k=c->begin(); k!=c->end(); ++k) { SimpleTracker::Hit* trh = dynamic_cast<SimpleTracker::Hit*>(*k); if ( trh ) { - pv->push_back(SimulationHit(trh->position, trh->energyDeposit)); + pv->emplace_back(SimulationHit(trh->position, trh->energyDeposit)); continue; } SimpleCalorimeter::Hit* cah = dynamic_cast<SimpleCalorimeter::Hit*>(*k); if ( cah ) { - pv->push_back(SimulationHit(cah->position, cah->energyDeposit)); + pv->emplace_back(SimulationHit(cah->position, cah->energyDeposit)); continue; } } diff --git a/DDG4/plugins/Geant4MaterialScanner.cpp b/DDG4/plugins/Geant4MaterialScanner.cpp index 284e050f771168f10b33b4a96285140fcee68c0b..cb9ff0a48d266fc54d0c573101244a17ca34cbc5 100644 --- a/DDG4/plugins/Geant4MaterialScanner.cpp +++ b/DDG4/plugins/Geant4MaterialScanner.cpp @@ -146,7 +146,7 @@ void Geant4MaterialScanner::operator()(const G4Step* step, G4SteppingManager*) { string postPath = post_handler.path(); #endif G4LogicalVolume* logVol = h.logvol(h.pre); - m_steps.push_back(new StepInfo(h.prePos(), h.postPos(), logVol)); + m_steps.emplace_back(new StepInfo(h.prePos(), h.postPos(), logVol)); } /// Registered callback on Begin-event diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp index ef5f0d6e1952679ca795d36ab40b07f215d8ed3f..1f809d9c8090a89a62ae65222baaf5853c49408b 100644 --- a/DDG4/plugins/Geant4SDActions.cpp +++ b/DDG4/plugins/Geant4SDActions.cpp @@ -169,7 +169,7 @@ namespace dd4hep { except("+++ Invalid CELL ID for hit!"); } } - hit->truth.push_back(contrib); + hit->truth.emplace_back(contrib); hit->energyDeposit += contrib.deposit; mark(step); return true; @@ -228,7 +228,7 @@ namespace dd4hep { } } hit->energyDeposit += contrib.deposit; - hit->truth.push_back(contrib); + hit->truth.emplace_back(contrib); track->SetTrackStatus(fStopAndKill); // don't step photon any further mark(h.track); return true; @@ -303,7 +303,7 @@ namespace dd4hep { except("+++ Invalid CELL ID for hit!"); } } - hit->truth.push_back(contrib); + hit->truth.emplace_back(contrib); hit->energyDeposit += contrib.deposit; mark(step); return true; diff --git a/DDG4/plugins/Geant4SensDet.cpp b/DDG4/plugins/Geant4SensDet.cpp index 85ff4ae81992d0fbf475761309bb83b6752cc166..79d8f604035eb43bd78d0aa2f3ac0452ac60d53f 100644 --- a/DDG4/plugins/Geant4SensDet.cpp +++ b/DDG4/plugins/Geant4SensDet.cpp @@ -136,7 +136,7 @@ namespace dd4hep { if ( coll.empty() ) { except("Geant4Sensitive: No collection defined for %s [Invalid name]",c_name()); } - collectionName.push_back(coll); + collectionName.emplace_back(coll); return collectionName.size()-1; } diff --git a/DDG4/plugins/Geant4XMLSetup.cpp b/DDG4/plugins/Geant4XMLSetup.cpp index 55d2fe6402c08588ca02fe16109a4a0463f48e58..9d68abe97f0b0e565ea25a94043baa9dbd471fd2 100644 --- a/DDG4/plugins/Geant4XMLSetup.cpp +++ b/DDG4/plugins/Geant4XMLSetup.cpp @@ -383,7 +383,7 @@ namespace dd4hep { p.ordAtRestDoIt = proc.attr<int>(_Unicode(ordAtRestDoIt)); p.ordAlongSteptDoIt = proc.attr<int>(_Unicode(ordAlongSteptDoIt)); p.ordPostStepDoIt = proc.attr<int>(_Unicode(ordPostStepDoIt)); - procs.push_back(p); + procs.emplace_back(p); printout(INFO,"Geant4Setup","+++ Converter<ParticleProcesses: Particle:%s add process %s %d %d %d", part_name.c_str(),p.name.c_str(),p.ordAtRestDoIt,p.ordAlongSteptDoIt,p.ordPostStepDoIt); } @@ -405,7 +405,7 @@ namespace dd4hep { Geant4PhysicsList::ParticleConstructors& parts = _object<Geant4PhysicsList>().particles(); xml_comp_t part(e); string n = part.nameStr(); - parts.push_back(n); + parts.emplace_back(n); printout(INFO,"Geant4Setup","+++ ParticleConstructor: Add Geant4 particle constructor '%s'",n.c_str()); } @@ -422,7 +422,7 @@ namespace dd4hep { Geant4PhysicsList::PhysicsConstructors& parts = _object<Geant4PhysicsList>().physics(); xml_comp_t part(e); string n = part.nameStr(); - parts.push_back(n); + parts.emplace_back(n); printout(INFO,"Geant4Setup","+++ PhysicsConstructor: Add Geant4 physics constructor '%s'",n.c_str()); } diff --git a/DDG4/src/Geant4ActionPhase.cpp b/DDG4/src/Geant4ActionPhase.cpp index d27f4c38f2338777a8833aa5d10dec5c7e303f84..68d53e5af0365d00ea5a03d90dec181fdaaa90a4 100644 --- a/DDG4/src/Geant4ActionPhase.cpp +++ b/DDG4/src/Geant4ActionPhase.cpp @@ -57,7 +57,7 @@ Geant4ActionPhase::~Geant4ActionPhase() { /// Add a new member to the phase bool Geant4ActionPhase::add(Geant4Action* action, Callback callback) { action->addRef(); - m_members.push_back(make_pair(action,callback)); + m_members.emplace_back(action,callback); return true; } diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index fd6a629c708b08346c33f5abbbf7ba78ae80263c..384573d1f96efa83f8f4f471b922e192a33d76e6 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -155,7 +155,7 @@ void Geant4AssemblyVolume::imprint(Geant4GeometryInfo& info, for( unsigned int i = 0; i < triplets.size(); i++ ) { const TGeoNode* node = pAssembly->m_entries[i]; Chain new_chain = chain; - new_chain.push_back(node); + new_chain.emplace_back(node); //cout << " Assembly: Entry: " << detail::tools::placementPath(new_chain) << endl; G4Transform3D Ta( *(triplets[i].GetRotation()), @@ -202,8 +202,8 @@ void Geant4AssemblyVolume::imprint(Geant4GeometryInfo& info, // Register the physical volume created by us so we can delete it later // - //fPVStore.push_back( pvPlaced.first ); - info.g4VolumeImprints[vol].push_back(make_pair(new_chain,pvPlaced.first)); + //fPVStore.emplace_back( pvPlaced.first ); + info.g4VolumeImprints[vol].emplace_back(make_pair(new_chain,pvPlaced.first)); #if 0 cout << " Assembly:Parent:" << parent->GetName() << " " << node->GetName() << " " << (void*)node << " G4:" << pvName.str() << " Daughter:" @@ -214,7 +214,7 @@ void Geant4AssemblyVolume::imprint(Geant4GeometryInfo& info, if ( pvPlaced.second ) { G4Exception("G4AssemblyVolume::MakeImprint(..)", "GeomVol0003", FatalException, "Fancy construct popping new mother from the stack!"); - //fPVStore.push_back( pvPlaced.second ); + //fPVStore.emplace_back( pvPlaced.second ); } } else if ( triplets[i].GetAssembly() ) { @@ -623,10 +623,10 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c z.reserve(nz); polygon.reserve(nz); for(size_t i=0; i<nz; ++i) { - z.push_back(G4ExtrudedSolid::ZSection(sh->GetZ(i) * CM_2_MM, + z.emplace_back(G4ExtrudedSolid::ZSection(sh->GetZ(i) * CM_2_MM, {sh->GetXOffset(i), sh->GetYOffset(i)}, sh->GetScale(i))); - polygon.push_back(G4TwoVector(sh->GetX(i) * CM_2_MM,sh->GetY(i) * CM_2_MM)); + polygon.emplace_back(G4TwoVector(sh->GetX(i) * CM_2_MM,sh->GetY(i) * CM_2_MM)); } solid = new G4ExtrudedSolid(name, polygon, z); } @@ -636,9 +636,9 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c double phi_total = (sh->GetDphi() + sh->GetPhi1()) * DEGREE_2_RAD; vector<double> rmin, rmax, z; for (Int_t i = 0; i < sh->GetNz(); ++i) { - rmin.push_back(sh->GetRmin(i) * CM_2_MM); - rmax.push_back(sh->GetRmax(i) * CM_2_MM); - z.push_back(sh->GetZ(i) * CM_2_MM); + rmin.emplace_back(sh->GetRmin(i) * CM_2_MM); + rmax.emplace_back(sh->GetRmax(i) * CM_2_MM); + z.emplace_back(sh->GetZ(i) * CM_2_MM); } solid = new G4Polyhedra(name, phi_start, phi_total, sh->GetNedges(), sh->GetNz(), &z[0], &rmin[0], &rmax[0]); } @@ -648,9 +648,9 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c double phi_total = (sh->GetDphi() + sh->GetPhi1()) * DEGREE_2_RAD; vector<double> rmin, rmax, z; for (Int_t i = 0; i < sh->GetNz(); ++i) { - rmin.push_back(sh->GetRmin(i) * CM_2_MM); - rmax.push_back(sh->GetRmax(i) * CM_2_MM); - z.push_back(sh->GetZ(i) * CM_2_MM); + rmin.emplace_back(sh->GetRmin(i) * CM_2_MM); + rmax.emplace_back(sh->GetRmax(i) * CM_2_MM); + z.emplace_back(sh->GetZ(i) * CM_2_MM); } solid = new G4Polycone(name, phi_start, phi_total, sh->GetNz(), &z[0], &rmin[0], &rmax[0]); } @@ -697,7 +697,7 @@ void* Geant4Converter::handleSolid(const string& name, const TGeoShape* shape) c TGeoTrap* sh = (TGeoTrap*) shape; Double_t* vtx_xy = sh->GetVertices(); for ( size_t i=0; i<8; ++i, vtx_xy +=2 ) - vertices.push_back(G4TwoVector(vtx_xy[0] * CM_2_MM,vtx_xy[1] * CM_2_MM)); + vertices.emplace_back(G4TwoVector(vtx_xy[0] * CM_2_MM,vtx_xy[1] * CM_2_MM)); solid = new G4GenericTrap(name, sh->GetDz() * CM_2_MM, vertices); } else if (shape->IsA() == TGeoCompositeShape::Class()) { @@ -983,7 +983,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) transform.dx(), transform.dy(), transform.dz()); Geant4AssemblyVolume* ass = (Geant4AssemblyVolume*)info.g4AssemblyVolumes[node]; Geant4AssemblyVolume::Chain chain; - chain.push_back(node); + chain.emplace_back(node); ass->imprint(info,node,chain,ass,(*volIt).second, transform, copy, checkOverlaps); return 0; } @@ -1205,8 +1205,8 @@ void* Geant4Converter::handleMaterialProperties(TObject* matrix) const { g4->bins.reserve(rows); g4->values.reserve(rows); for(size_t i=0; i<rows; ++i) { - g4->bins.push_back(m->Get(i,0) /* *CLHEP::eV/units::eV */); - g4->values.push_back(m->Get(i,1)); + g4->bins.emplace_back(m->Get(i,0) /* *CLHEP::eV/units::eV */); + g4->values.emplace_back(m->Get(i,1)); } printout(lvl, "Geant4Converter", "++ Successfully converted material property:%s : %s [%ld rows]", m->GetName(), m->GetTitle(), rows); diff --git a/DDG4/src/Geant4HitCollection.cpp b/DDG4/src/Geant4HitCollection.cpp index 87a9d33834b4d21e33a04025f92af540e7a61261..6c18230d0725d83e17b90a2e3b8a92efdbdbc93e 100644 --- a/DDG4/src/Geant4HitCollection.cpp +++ b/DDG4/src/Geant4HitCollection.cpp @@ -132,13 +132,14 @@ Geant4HitWrapper* Geant4HitCollection::findHitByKey(VolumeID key) { /// Release all hits from the Geant4 container and pass ownership to the caller void Geant4HitCollection::releaseData(const ComponentCast& cast, std::vector<void*>* result) { + result->reserve(m_hits.size()); for (size_t j = 0, n = m_hits.size(); j < n; ++j) { Geant4HitWrapper& w = m_hits.at(j); Manip* m = w.manip(); if (&cast == &m->cast) - result->push_back(w.release()); + result->emplace_back(w.release()); else - result->push_back(m->cast.apply_downCast(cast, w.release())); + result->emplace_back(m->cast.apply_downCast(cast, w.release())); } m_lastHit = ULONG_MAX; m_keys.clear(); @@ -146,21 +147,23 @@ void Geant4HitCollection::releaseData(const ComponentCast& cast, std::vector<voi /// Release all hits from the Geant4 container. Ownership stays with the container void Geant4HitCollection::getData(const ComponentCast& cast, std::vector<void*>* result) { + result->reserve(m_hits.size()); for (size_t j = 0, n = m_hits.size(); j < n; ++j) { Geant4HitWrapper& w = m_hits.at(j); Manip* m = w.manip(); if (&cast == &m->cast) - result->push_back(w.data()); + result->emplace_back(w.data()); else - result->push_back(m->cast.apply_downCast(cast, w.data())); + result->emplace_back(m->cast.apply_downCast(cast, w.data())); } } /// Release all hits from the Geant4 container and pass ownership to the caller void Geant4HitCollection::releaseHitsUnchecked(std::vector<void*>& result) { + result.reserve(m_hits.size()); for (size_t j = 0, n = m_hits.size(); j < n; ++j) { Geant4HitWrapper& w = m_hits.at(j); - result.push_back(w.release()); + result.emplace_back(w.release()); } m_lastHit = ULONG_MAX; m_keys.clear(); @@ -168,8 +171,9 @@ void Geant4HitCollection::releaseHitsUnchecked(std::vector<void*>& result) { /// Release all hits from the Geant4 container. Ownership stays with the container void Geant4HitCollection::getHitsUnchecked(std::vector<void*>& result) { + result.reserve(m_hits.size()); for (size_t j = 0, n = m_hits.size(); j < n; ++j) { Geant4HitWrapper& w = m_hits.at(j); - result.push_back(w.data()); + result.emplace_back(w.data()); } } diff --git a/DDG4/src/Geant4InputAction.cpp b/DDG4/src/Geant4InputAction.cpp index 537696bf90cfd03fb1bb090a991fd7d1372c5cef..d2c061a6a0a8b3a3ea8226d43d88a5d3e2835cf6 100644 --- a/DDG4/src/Geant4InputAction.cpp +++ b/DDG4/src/Geant4InputAction.cpp @@ -250,12 +250,12 @@ void Geant4InputAction::operator()(G4Event* event) { for(size_t i=0; i<vertices.size(); ++i ) { - inter->vertices[m_mask].push_back( vertices[i] ); + inter->vertices[m_mask].emplace_back( vertices[i] ); } // build collection of MCParticles - for(size_t i=0; i<primaries.size(); ++i ) { - Geant4ParticleHandle p(primaries[i]); + for(auto* primPart : primaries) { + Geant4ParticleHandle p(primPart); const double mom_scale = m_momScale; PropertyMask status(p->status); p->psx = mom_scale*p->psx; @@ -270,11 +270,7 @@ void Geant4InputAction::operator()(G4Event* event) { // // vtx->out.insert(p->id); // Stuff, to be given to Geant4 together with daughters // // } - inter->particles.insert(make_pair(p->id,p)); p.dumpWithMomentumAndVertex(outputLevel()-1,name(),"->"); } - - - } diff --git a/DDG4/src/Geant4InputHandling.cpp b/DDG4/src/Geant4InputHandling.cpp index 24383ac3585bae7a0c06a64e0798dfe509f4bca9..e1cc9fb19b87f4c4646a27ffb6e7ebfca31305fe 100644 --- a/DDG4/src/Geant4InputHandling.cpp +++ b/DDG4/src/Geant4InputHandling.cpp @@ -110,7 +110,7 @@ static void collectPrimaries(Geant4PrimaryMap* pm, dv->mask = mask; dv->in.insert(p->id); - interaction->vertices[vid].push_back(dv) ; + interaction->vertices[vid].emplace_back(dv) ; for(; dau; dau = dau->GetNext()) collectPrimaries(pm, interaction, dv, dau); @@ -129,7 +129,7 @@ dd4hep::sim::createPrimary(int mask, interaction->locked = true; interaction->mask = mask; v->mask = mask; - interaction->vertices[vid].push_back(v); + interaction->vertices[vid].emplace_back(v); for (G4PrimaryParticle *gp = gv->GetPrimary(); gp; gp = gp->GetNext() ) collectPrimaries(pm, interaction, v, gp); @@ -186,7 +186,7 @@ static void appendInteraction(const Geant4Action* caller, "Cannot handle 2 interactions with identical identifiers!"); } for(Geant4Vertex* vtx : (*iv).second ) - output->vertices[(*iv).first].push_back( vtx->addRef() ); + output->vertices[(*iv).first].emplace_back( vtx->addRef() ); } } @@ -370,7 +370,7 @@ getRelevant(set<int>& visited, if ( prim.find(p->id) == prim.end() ) { G4PrimaryParticle* p4 = createG4Primary(p); prim[p->id] = p4; - res.push_back(make_pair(p,p4)); + res.emplace_back(p,p4); } } else if ( p->daughters.size() > 0 ) { @@ -406,7 +406,7 @@ getRelevant(set<int>& visited, for(Primaries::iterator i=daughters.begin(); i!=daughters.end(); ++i) p4->SetDaughter((*i).second); } - res.push_back(make_pair(p,p4)); + res.emplace_back(p,p4); } else { for(Geant4Particle::Particles::const_iterator i=dau.begin(); i!=dau.end(); ++i) { diff --git a/DDG4/src/Geant4Output2ROOT.cpp b/DDG4/src/Geant4Output2ROOT.cpp index af5cef884acea57cd7bb805fc1cfb69fc54f781d..03b05dcacf71ccd54bcbd283094dde4b80c93e28 100644 --- a/DDG4/src/Geant4Output2ROOT.cpp +++ b/DDG4/src/Geant4Output2ROOT.cpp @@ -150,8 +150,9 @@ void Geant4Output2ROOT::saveEvent(OutputContext<G4Event>& /* ctxt */) { Manip* manipulator = Geant4HitWrapper::manipulator<Geant4Particle>(); const ParticleMap& pm = parts->particles(); vector<void*> particles; - for(ParticleMap::const_iterator i=pm.begin(); i!=pm.end(); ++i) { - particles.push_back((ParticleMap::mapped_type*)(*i).second); + particles.reserve(pm.size()); + for ( const auto& i : pm ) { + particles.emplace_back((ParticleMap::mapped_type*)i.second); } fill("MCParticles",manipulator->vec_type,&particles); } @@ -172,6 +173,7 @@ void Geant4Output2ROOT::saveCollection(OutputContext<G4Event>& /* ctxt */, G4VHi coll->getHitsUnchecked(hits); size_t nhits = coll->GetSize(); if ( m_handleMCTruth && m_truth && nhits > 0 ) { + hits.reserve(nhits); try { for(size_t i=0; i<nhits; ++i) { Geant4HitData* h = coll->hit(i); diff --git a/DDG4/src/Geant4Particle.cpp b/DDG4/src/Geant4Particle.cpp index ae2e83d64d9d69c451a223d6a6049fa4ef04e454..a257a2fdb0c5b44deea248bf0f17754fecaaba85 100644 --- a/DDG4/src/Geant4Particle.cpp +++ b/DDG4/src/Geant4Particle.cpp @@ -174,7 +174,7 @@ std::vector<G4ParticleDefinition*> Geant4ParticleHandle::g4DefinitionsRegEx(cons G4ParticleDefinition* p = iter->value(); ret = ::regexec(®, p->GetParticleName().c_str(), 0, NULL, 0); if (!ret) - results.push_back(p); + results.emplace_back(p); else if (ret == REG_NOMATCH) continue; else { diff --git a/DDG4/src/Geant4ParticleGenerator.cpp b/DDG4/src/Geant4ParticleGenerator.cpp index 2927dbfa79f2b58e0ed7e71bf3c4e97d2f846c23..f3002c529077729bb6bc428c257e994ed41efea3 100644 --- a/DDG4/src/Geant4ParticleGenerator.cpp +++ b/DDG4/src/Geant4ParticleGenerator.cpp @@ -80,21 +80,20 @@ void Geant4ParticleGenerator::printInteraction(int mask) const { /// Print single particle interaction identified by it's reference void Geant4ParticleGenerator::printInteraction(Geant4PrimaryInteraction* inter) const { - typedef Geant4PrimaryInteraction::VertexMap _V; int count = 0; if ( !inter ) { warning("printInteraction: Invalid interaction pointer [NULL-Pointer]."); return; } - for(_V::const_iterator iv=inter->vertices.begin(); iv!=inter->vertices.end(); ++iv) { - for( Geant4Vertex* v : (*iv).second ){ + for(const auto& iv : inter->vertices ) { + for( Geant4Vertex* v : iv.second ){ print("+-> Interaction [%d] %.3f GeV %s pos:(%.3f %.3f %.3f)[mm]", - count, m_energy/CLHEP::GeV, m_particleName.c_str(), - v->x/CLHEP::mm, v->y/CLHEP::mm, v->z/CLHEP::mm); + count, m_energy/CLHEP::GeV, m_particleName.c_str(), + v->x/CLHEP::mm, v->y/CLHEP::mm, v->z/CLHEP::mm); ++count; - for(set<int>::const_iterator i=v->out.begin(); i!=v->out.end(); ++i) { - Geant4ParticleHandle p = inter->particles[*i]; - p.dumpWithVertex(outputLevel(),name()," +->"); + for ( int i : v->out ) { + Geant4ParticleHandle p = inter->particles[i]; + p.dumpWithVertex(outputLevel(),name()," +->"); } } } @@ -125,7 +124,7 @@ void Geant4ParticleGenerator::operator()(G4Event*) { vtx->x = position.X(); vtx->y = position.Y(); vtx->z = position.Z(); - inter->vertices[m_mask].push_back( vtx ); + inter->vertices[m_mask].emplace_back( vtx ); for(int i=0; i<m_multiplicity; ++i) { double momentum = m_energy; Particle* p = new Particle(); @@ -154,7 +153,7 @@ void Geant4ParticleGenerator::operator()(G4Event*) { // p->vex = vtx->x; // p->vey = vtx->y; // p->vez = vtx->z; - inter->particles.insert(make_pair(p->id,p)); + inter->particles.emplace(p->id,p); vtx->out.insert(p->id); printout(INFO,name(),"Particle [%d] %s %.3f GeV direction:(%6.3f %6.3f %6.3f)", p->id, m_particleName.c_str(), momentum/CLHEP::GeV, diff --git a/DDG4/src/Geant4PhysicsList.cpp b/DDG4/src/Geant4PhysicsList.cpp index 2fd52f9206a17bcefd368ac6f0d32b71e40760d4..3b84e549f469ec3fd395b4d758c15f909ca9def9 100644 --- a/DDG4/src/Geant4PhysicsList.cpp +++ b/DDG4/src/Geant4PhysicsList.cpp @@ -135,12 +135,12 @@ void Geant4PhysicsList::dump() { /// Add physics particle constructor by name void Geant4PhysicsList::addParticleConstructor(const std::string& part_name) { - particles().push_back(part_name); + particles().emplace_back(part_name); } /// Add physics particle constructor by name void Geant4PhysicsList::addParticleGroup(const std::string& part_name) { - particlegroups().push_back(part_name); + particlegroups().emplace_back(part_name); } /// Add particle process by name with arguments @@ -155,7 +155,7 @@ void Geant4PhysicsList::addParticleProcess(const std::string& part_name, p.ordAtRestDoIt = ordAtRestDoIt; p.ordAlongSteptDoIt = ordAlongSteptDoIt; p.ordPostStepDoIt = ordPostStepDoIt; - processes(part_name).push_back(p); + processes(part_name).emplace_back(p); } /// Add discrete particle process by name with arguments @@ -164,12 +164,12 @@ void Geant4PhysicsList::addDiscreteParticleProcess(const std::string& part_name, { Process p; p.name = proc_name; - discreteProcesses(part_name).push_back(p); + discreteProcesses(part_name).emplace_back(p); } /// Add PhysicsConstructor by name void Geant4PhysicsList::addPhysicsConstructor(const std::string& phys_name) { - physics().push_back(phys_name); + physics().emplace_back(phys_name); } /// Access processes for one particle type @@ -220,7 +220,7 @@ void Geant4PhysicsList::adoptPhysicsConstructor(Geant4Action* action) { PhysicsConstructor ctor(action->name()); ctor.pointer = p; action->addRef(); - m_physics.push_back(ctor); + m_physics.emplace_back(ctor); return; } except("Failed to adopt action object %s as physics constructor. [Invalid-Base]",action->c_name()); diff --git a/DDG4/src/Geant4Primary.cpp b/DDG4/src/Geant4Primary.cpp index 311a708cbc9d0ac5bbe5b51bc72973ebcdf86f86..0682ab7e589093fac6453cf4e14fd9f4eb9a7060 100644 --- a/DDG4/src/Geant4Primary.cpp +++ b/DDG4/src/Geant4Primary.cpp @@ -12,6 +12,7 @@ //========================================================================== // Framework include files +#include "DD4hep/Printout.h" #include "DD4hep/Primitives.h" #include "DD4hep/InstanceCount.h" #include "DDG4/Geant4Primary.h" @@ -54,10 +55,8 @@ const Geant4Particle* Geant4PrimaryMap::get(const G4PrimaryParticle* particle) c /// Default destructor Geant4PrimaryInteraction::~Geant4PrimaryInteraction() { - - Geant4PrimaryInteraction::VertexMap::iterator iv, ivend; - for( iv=vertices.begin(), ivend=vertices.end(); iv != ivend; ++iv ){ - for( Geant4Vertex* vtx : (*iv).second ) + for(const auto& iv : vertices) { + for( Geant4Vertex* vtx : iv.second ) detail::ReleaseObject<Geant4Vertex*>()( vtx ); } detail::releaseObjects(particles); @@ -75,19 +74,14 @@ void Geant4PrimaryInteraction::setNextPID(int new_value) { /// Apply mask to all contained vertices and particles bool Geant4PrimaryInteraction::applyMask() { - - Geant4PrimaryInteraction::ParticleMap::iterator ip, ipend; - for( ip=particles.begin(), ipend=particles.end(); ip != ipend; ++ip ) - (*ip).second->mask = mask; + for(auto& ip : particles) + ip.second->mask = mask; - Geant4PrimaryInteraction::VertexMap::iterator iv, ivend; - for( iv=vertices.begin(), ivend=vertices.end(); iv != ivend; ++iv ){ - for( auto vtx : (*iv).second ) + for(auto& iv : vertices ) { + for(auto* vtx : iv.second ) vtx->mask = mask; } - return true; - } /// Default destructor @@ -101,31 +95,27 @@ void Geant4PrimaryEvent::add(int id, Geant4PrimaryInteraction* interaction) { Interactions::iterator i = m_interactions.find(id); if ( i == m_interactions.end() ) { interaction->mask = id; - m_interactions.insert(std::make_pair(id,interaction)); + m_interactions.emplace(id,interaction); return; } - char text[132]; - ::snprintf(text,sizeof(text),"Geant4PrimaryEvent: Interaction with ID '%d' " - "exists and cannot be added twice!",id); - throw std::runtime_error(text); + except("Geant4PrimaryEvent","+++ Interaction with ID '%d' " + "exists and cannot be added twice!",id); } - throw std::runtime_error("Geant4PrimaryEvent: CANNOT add invalid Interaction!"); + except("Geant4PrimaryEvent","+++ CANNOT add invalid Interaction!"); } /// Retrieve an interaction by it's ID Geant4PrimaryEvent::Interaction* Geant4PrimaryEvent::get(int mask) const { Interactions::const_iterator i = m_interactions.find(mask); - if ( i != m_interactions.end() ) { - return (*i).second; - } - return 0; + return (i != m_interactions.end()) ? (*i).second : 0; } /// Retrieve all intractions std::vector<Geant4PrimaryEvent::Interaction*> Geant4PrimaryEvent::interactions() const { std::vector<Interaction*> v; - for(Interactions::const_iterator i=m_interactions.begin(); i!=m_interactions.end(); ++i) - v.push_back((*i).second); + v.reserve(m_interactions.size()); + for(const auto& i : m_interactions) + v.emplace_back(i.second); return v; } diff --git a/DDG4/src/Geant4SensDetAction.cpp b/DDG4/src/Geant4SensDetAction.cpp index 4014890150e22ab1899c89db819f39aa51c984a6..9b3afa58fe9f9974a0e6337e48008ffb944ed9b5 100644 --- a/DDG4/src/Geant4SensDetAction.cpp +++ b/DDG4/src/Geant4SensDetAction.cpp @@ -299,7 +299,7 @@ void Geant4SensDetActionSequence::adopt(Geant4Filter* filter) { /// Initialize the usage of a hit collection. Returns the collection identifier size_t Geant4SensDetActionSequence::defineCollection(Geant4Sensitive* owner, const std::string& collection_name, create_t func) { - m_collections.push_back(make_pair(collection_name, make_pair(owner,func))); + m_collections.emplace_back(collection_name, make_pair(owner,func)); return m_collections.size() - 1; } diff --git a/DDG4/src/Geant4TouchableHandler.cpp b/DDG4/src/Geant4TouchableHandler.cpp index 56e387b3862e409e45541986185db25ea3b642fd..b15d568adfa62c7b9e7adf17b30afafba95b278c 100644 --- a/DDG4/src/Geant4TouchableHandler.cpp +++ b/DDG4/src/Geant4TouchableHandler.cpp @@ -47,7 +47,7 @@ Geant4TouchableHandler::Geant4PlacementPath Geant4TouchableHandler::placementPat path_val.reserve(n); for (i=0; i < n; ++i) { G4VPhysicalVolume* pv = touchable->GetVolume(i); - path_val.push_back(pv); + path_val.emplace_back(pv); } return path_val; } diff --git a/DDG4/src/Geant4VolumeManager.cpp b/DDG4/src/Geant4VolumeManager.cpp index b3ac6ca8a910538973b597154efe945a895b55cc..00f6bcca70315269bbf190568eb4d58142ca72d2 100644 --- a/DDG4/src/Geant4VolumeManager.cpp +++ b/DDG4/src/Geant4VolumeManager.cpp @@ -58,15 +58,15 @@ namespace { /// Populate the Volume manager void populate(DetElement e) { const DetElement::Children& c = e.children(); - for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) { - DetElement de = (*i).second; + for (const auto& i : c) { + DetElement de = i.second; PlacedVolume pv = de.placement(); if (pv.isValid()) { Chain chain; SensitiveDetector sd; PlacedVolume::VolIDs ids; m_entries.clear(); - chain.push_back(m_detDesc.world().placement().ptr()); + chain.emplace_back(m_detDesc.world().placement().ptr()); scanPhysicalVolume(pv.ptr(), ids, sd, chain); continue; } @@ -80,7 +80,7 @@ namespace { Volume vol = pv.volume(); PlacedVolume::VolIDs pv_ids = pv.volIDs(); - chain.push_back(node); + chain.emplace_back(node); ids.PlacedVolume::VolIDs::Base::insert(ids.end(), pv_ids.begin(), pv_ids.end()); if (vol.isSensitive()) { sd = vol.sensitiveDetector(); @@ -125,7 +125,7 @@ namespace { node = *(k); PlacementMap::const_iterator g4pit = m_geo.g4Placements.find(node); if (g4pit != m_geo.g4Placements.end()) { - path.push_back((*g4pit).second); + path.emplace_back((*g4pit).second); printout(print_chain, "Geant4VolumeManager", "+++ Chain: Node OK: %s [%s]", node->GetName(), (*g4pit).second->GetName().c_str()); continue; @@ -136,13 +136,13 @@ namespace { if ( iVolImp != m_geo.g4VolumeImprints.end() ) { const Imprints& imprints = (*iVolImp).second; //size_t len = kend-k; - for(Imprints::const_iterator iImp=imprints.begin(); iImp != imprints.end(); ++iImp) { - const VolumeChain& c = (*iImp).first; + for(const auto& imp : imprints ) { + const VolumeChain& c = imp.first; if ( c.size() <= control.size() && control == c ) { - path.push_back((*iImp).second); + path.emplace_back(imp.second); printout(print_chain, "Geant4VolumeManager", "+++ Chain: Node OK: %s %s -> %s", node->GetName(), detail::tools::placementPath(c,false).c_str(), - (*iImp).second->GetName().c_str()); + imp.second->GetName().c_str()); control.clear(); break; } diff --git a/UtilityApps/src/converter.cpp b/UtilityApps/src/converter.cpp index f36b6a8a63e1a1db3c1b5412fc28856a377e826d..c0131baeb8658e9d86f66882e2a646f7e31ac6b9 100644 --- a/UtilityApps/src/converter.cpp +++ b/UtilityApps/src/converter.cpp @@ -64,7 +64,7 @@ namespace { else if ( strncmp(argv[i],"-compact2vis",12)==0 ) compact2vis = true; else if ( strncmp(argv[i],"-input",2)==0 ) - geo_files.push_back(argv[++i]); + geo_files.emplace_back(argv[++i]); else if ( strncmp(argv[i],"-output",2)==0 ) output = ++i; else if ( strncmp(argv[i],"-ascii",5)==0 ) diff --git a/UtilityApps/src/display.cpp b/UtilityApps/src/display.cpp index f3e33ad793c3acde4adb6236e3572f02a4dd6080..f4fa3643a1c59fb94382f0924a3a68455a6cfe4a 100644 --- a/UtilityApps/src/display.cpp +++ b/UtilityApps/src/display.cpp @@ -20,23 +20,23 @@ int main(int argc,char** argv) { std::string level, visopt, opt, detector; bool dry = false; for(int i=0; i<argc; ++i) { - if ( i==1 && argv[i][0] != '-' ) av.push_back("-input"); - if ( strncmp(argv[i],"-load-only",4) == 0 ) dry = true, av.push_back(argv[i]); - else if ( strncmp(argv[i],"-dry-run",4) == 0 ) dry = true, av.push_back(argv[i]); + if ( i==1 && argv[i][0] != '-' ) av.emplace_back("-input"); + if ( strncmp(argv[i],"-load-only",4) == 0 ) dry = true, av.emplace_back(argv[i]); + else if ( strncmp(argv[i],"-dry-run",4) == 0 ) dry = true, av.emplace_back(argv[i]); else if ( strncmp(argv[i],"-visopt",4) == 0 ) visopt = argv[++i]; else if ( strncmp(argv[i],"-level", 4) == 0 ) level = argv[++i]; else if ( strncmp(argv[i],"-option",4) == 0 ) opt = argv[++i]; else if ( strncmp(argv[i],"-detector",4) == 0 ) detector = argv[++i]; - else av.push_back(argv[i]); + else av.emplace_back(argv[i]); } if ( !dry ) { - av.push_back("-interactive"); - av.push_back("-plugin"); - av.push_back("DD4hep_GeometryDisplay"); - if ( !opt.empty() ) av.push_back("-opt"), av.push_back(opt.c_str()); - if ( !level.empty() ) av.push_back("-level"), av.push_back(level.c_str()); - if ( !visopt.empty() ) av.push_back("-visopt"), av.push_back(visopt.c_str()); - if ( !detector.empty() ) av.push_back("-detector"), av.push_back(detector.c_str()); + av.emplace_back("-interactive"); + av.emplace_back("-plugin"); + av.emplace_back("DD4hep_GeometryDisplay"); + if ( !opt.empty() ) av.emplace_back("-opt"), av.emplace_back(opt.c_str()); + if ( !level.empty() ) av.emplace_back("-level"), av.emplace_back(level.c_str()); + if ( !visopt.empty() ) av.emplace_back("-visopt"), av.emplace_back(visopt.c_str()); + if ( !detector.empty() ) av.emplace_back("-detector"), av.emplace_back(detector.c_str()); } return dd4hep::execute::main_plugins("DD4hep_GeometryDisplay", av.size(), (char**)&av[0]); } diff --git a/UtilityApps/src/dumpdetector.cpp b/UtilityApps/src/dumpdetector.cpp index aad5ac5fced22de38747e541587071bf0f84f2f4..afd3bf5b652deb5551d698a774105c638b33376e 100644 --- a/UtilityApps/src/dumpdetector.cpp +++ b/UtilityApps/src/dumpdetector.cpp @@ -172,14 +172,14 @@ static int invoke_dump_detector(int argc, char** argv ){ std::list< DetElement > dets ; std::list< DetElement > daugs ; std::list< DetElement > gdaugs ; - daugs.push_back( world ) ; + daugs.emplace_back( world ) ; while( ! daugs.empty() ) { for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){ DetElement dau = *li ; DetElement::Children chMap = dau.children() ; for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){ DetElement de = (*it).second ; - gdaugs.push_back( de ) ; + gdaugs.emplace_back( de ) ; } } dets.splice( dets.end() , daugs ) ; diff --git a/UtilityApps/src/materialBudget.cpp b/UtilityApps/src/materialBudget.cpp index 798675b967987002fc61bc4e1645bb70eccb5aaf..8e74a00e48f2c2e3821441ef69feeb201a4efffd 100644 --- a/UtilityApps/src/materialBudget.cpp +++ b/UtilityApps/src/materialBudget.cpp @@ -136,7 +136,7 @@ int main_wrapper(int argc, char** argv) { else if( token == "subdet" ){ SDetHelper det ; iss >> det.name >> det.r0 >> det.z0 >> det.r1 >> det.z1 ; - subdets.push_back( det ); + subdets.emplace_back( det ); } if ( !iss.eof() || iss.fail() ){ diff --git a/UtilityApps/src/run_plugin.h b/UtilityApps/src/run_plugin.h index ac2701b82f3378e9921b2f9030ec4f39d38fc526..f0d534c4e1c50979b5262a270a6ceda3587b936f 100644 --- a/UtilityApps/src/run_plugin.h +++ b/UtilityApps/src/run_plugin.h @@ -136,13 +136,13 @@ namespace { //____________________________________________________________________________ int handle(int& i, int argc, char** argv) { if ( ::strncmp(argv[i],"-compact",5)==0 || ::strncmp(argv[i],"-input",4)==0 ) { - geo_files.push_back(argv[++i]); + geo_files.emplace_back(argv[++i]); if ( argc>i+2 && ::strncmp(argv[i+1],"-build_type",6)==0 ) { - build_types.push_back(argv[i+2]); + build_types.emplace_back(argv[i+2]); i += 2; } else { - build_types.push_back("BUILD_DEFAULT"); + build_types.emplace_back("BUILD_DEFAULT"); } } else if ( ::strncmp(argv[i],"-load_only",5)==0 ) @@ -173,14 +173,14 @@ namespace { ui = false; else if ( ::strncmp(argv[i],"-plugin",5)==0 ) { // Need to interprete plugin args here locally..... - plugins.push_back(std::vector<const char*>()); - plugins.back().push_back(argv[++i]); + plugins.emplace_back(std::vector<const char*>()); + plugins.back().emplace_back(argv[++i]); for( ++i; i < argc; ++i ) { if ( ::strncmp(argv[i],"-plugin",5)==0 ) { --i; break; } if ( ::strncmp(argv[i],"-end-plugin",4)==0 ) { break; } - plugins.back().push_back(argv[i]); + plugins.back().emplace_back(argv[i]); } - plugins.back().push_back(0); + plugins.back().emplace_back(nullptr); } else return 0; @@ -246,8 +246,8 @@ namespace dd4hep { usage_default(name); } else { // This is the default - args.geo_files.push_back(argv[i]); - args.build_types.push_back("BUILD_DEFAULT"); + args.geo_files.emplace_back(argv[i]); + args.build_types.emplace_back("BUILD_DEFAULT"); } } if ( args.geo_files.empty() )