diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp index d865315d200a60920e04d7d8bbe9cb8fc1fc3b75..40ffdf6637873903b785c91c36295f6da6bcc873 100644 --- a/DDCond/src/plugins/ConditionsMappedPool.cpp +++ b/DDCond/src/plugins/ConditionsMappedPool.cpp @@ -45,11 +45,13 @@ namespace DD4hep { */ template<typename MAPPING, typename BASE> class ConditionsMappedPool : public BASE { - protected: - typedef BASE Base; - typedef MAPPING Mapping; + public: + typedef BASE Base; + typedef MAPPING Mapping; typedef ConditionsMappedPool<Mapping,Base> Self; - typedef typename BASE::key_type key_type; + typedef typename BASE::key_type key_type; + + protected: Mapping m_entries; /// Helper function to loop over the conditions container and apply a functor @@ -131,7 +133,8 @@ namespace DD4hep { template<typename MAPPING, typename BASE> class ConditionsMappedUpdatePool : public ConditionsMappedPool<MAPPING,BASE> { - typedef ConditionsMappedPool<MAPPING,BASE> Self; + public: + typedef ConditionsMappedPool<MAPPING,BASE> Self; typedef typename ConditionsMappedPool<MAPPING,BASE>::key_type key_type; public: /// Default constructor @@ -143,7 +146,7 @@ namespace DD4hep { /// Adopt all entries sorted by IOV. Entries will be removed from the pool virtual size_t popEntries(UpdatePool::UpdateEntries& entries) { - ClearOnReturn<MAPPING> clear(this->Self::m_entries); + ClearOnReturn<MAPPING> clr(this->Self::m_entries); return this->Self::loop(entries, [&entries](const std::pair<key_type,Condition::Object*>& o) { entries[o.second->iov].push_back(Condition(o.second));}); #if 0 diff --git a/DDCore/include/DD4hep/BasicGrammar_inl.h b/DDCore/include/DD4hep/BasicGrammar_inl.h index 2080a968c6ef86ae1f47e2c0325822bc0970b05d..06c95e975ea4fcd6c7410283bf2615a05347c5e6 100644 --- a/DDCore/include/DD4hep/BasicGrammar_inl.h +++ b/DDCore/include/DD4hep/BasicGrammar_inl.h @@ -183,9 +183,9 @@ namespace DD4hep { /// Insertion function for std vectors template <typename TYPE> static int fill_data(std::vector<TYPE>* p,const std::vector<std::string>& temp) { - const BasicGrammar& g = BasicGrammar::instance<TYPE>(); TYPE val; - for(std::vector<std::string>::const_iterator i=temp.begin(); i != temp.end(); ++i) { + const BasicGrammar& g = BasicGrammar::instance<TYPE>(); + for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !g.fromString(&val,*i) ) return 0; p->push_back(val); @@ -195,9 +195,9 @@ namespace DD4hep { /// Insertion function for std lists template <typename TYPE> static int fill_data(std::list<TYPE>* p,const std::vector<std::string>& temp) { - const BasicGrammar& g = BasicGrammar::instance<TYPE>(); TYPE val; - for(std::vector<std::string>::const_iterator i=temp.begin(); i != temp.end(); ++i) { + const BasicGrammar& g = BasicGrammar::instance<TYPE>(); + for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !g.fromString(&val,*i) ) return 0; p->push_back(val); @@ -207,9 +207,9 @@ namespace DD4hep { /// Insertion function for std sets template <typename TYPE> static int fill_data(std::set<TYPE>* p,const std::vector<std::string>& temp) { - const BasicGrammar& g = BasicGrammar::instance<TYPE>(); TYPE val; - for(std::vector<std::string>::const_iterator i=temp.begin(); i != temp.end(); ++i) { + const BasicGrammar& g = BasicGrammar::instance<TYPE>(); + for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !g.fromString(&val,*i) ) return 0; p->insert(val); @@ -219,9 +219,9 @@ namespace DD4hep { /// Insertion function for std sets template <typename TYPE> static int fill_data(std::deque<TYPE>* p,const std::vector<std::string>& temp) { - const BasicGrammar& g = BasicGrammar::instance<TYPE>(); TYPE val; - for(std::vector<std::string>::const_iterator i=temp.begin(); i != temp.end(); ++i) { + const BasicGrammar& g = BasicGrammar::instance<TYPE>(); + for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !g.fromString(&val,*i) ) return 0; p->push_back(val); @@ -231,9 +231,9 @@ namespace DD4hep { /// Insertion function for std sets template <typename KEY, typename TYPE> static int fill_data(std::map<KEY,TYPE>* p,const std::vector<std::string>& temp) { - const BasicGrammar& g = BasicGrammar::instance<std::pair<KEY,TYPE> >(); std::pair<KEY,TYPE> val; - for(std::vector<std::string>::const_iterator i=temp.begin(); i != temp.end(); ++i) { + const BasicGrammar& g = BasicGrammar::instance<std::pair<KEY,TYPE> >(); + for(auto i=std::begin(temp); i != std::end(temp); ++i) { if ( !g.fromString(&val,*i) ) return 0; p->insert(val); diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index 78f720998befb8afc84bdcdbda03bf1c28442a6f..f3538de7fe3f91a38354ba85b739cd55425caeae 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -326,7 +326,7 @@ namespace DD4hep { * }; * * long counter = 0; - * for_each(conditons.begin(), conditions.end(), MyCounter(counter)); + * for_each(std::begin(conditons), std::end(conditions), MyCounter(counter)); * * \author M.Frank * \version 1.0 diff --git a/DDCore/include/DD4hep/ConditionsData.h b/DDCore/include/DD4hep/ConditionsData.h index 720409964890557cfa342af700dff8f7356fe87a..97010d646dd1bbf7576ef38d6f6fc5199a12345b 100644 --- a/DDCore/include/DD4hep/ConditionsData.h +++ b/DDCore/include/DD4hep/ConditionsData.h @@ -72,38 +72,38 @@ namespace DD4hep { } /// Simplify access to first item of the parameter list (const access) const Params::value_type& firstParam() const { - Params::const_iterator i=params.begin(); - if ( i != params.end() ) return (*i); + Params::const_iterator i=std::begin(params); + if ( i != std::end(params) ) return (*i); throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter"); } /// Simplify access to first item of the parameter list Params::value_type& firstParam() { - Params::iterator i=params.begin(); - if ( i != params.end() ) return (*i); + Params::iterator i=std::begin(params); + if ( i != std::end(params) ) return (*i); throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter"); } /// Simplify access to first item of the parameter list (const access) template <typename T> const T& first() const { - Params::const_iterator i=params.begin(); - if ( i != params.end() ) return (*i).second.get<T>(); + Params::const_iterator i=std::begin(params); + if ( i != std::end(params) ) return (*i).second.get<T>(); throw std::runtime_error("AbstractMap: Failed to access non-existing first item"); } /// Simplify access to first item of the parameter list template <typename T> T& first() { - Params::iterator i=params.begin(); - if ( i != params.end() ) return (*i).second.get<T>(); + Params::iterator i=std::begin(params); + if ( i != std::end(params) ) return (*i).second.get<T>(); throw std::runtime_error("AbstractMap: Failed to access non-existing first item"); } /// Simplify access to mapped item of the parameter list (const access) template <typename T> const T& operator[](const std::string& item) const { Params::const_iterator i=params.find(item); - if ( i != params.end() ) return (*i).second.get<T>(); + if ( i != std::end(params) ) return (*i).second.get<T>(); throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item); } /// Simplify access to mapped item of the parameter list template <typename T> T& operator[](const std::string& item) { Params::iterator i=params.find(item); - if ( i != params.end() ) return (*i).second.get<T>(); + if ( i != std::end(params) ) return (*i).second.get<T>(); throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item); } }; diff --git a/DDCore/src/DetectorSelector.cpp b/DDCore/src/DetectorSelector.cpp index 103f8724ff79c1c6e18c802f8efa1b21871b8bd6..27419a804b950430d66b5b0ca70b8d8f54386c2f 100644 --- a/DDCore/src/DetectorSelector.cpp +++ b/DDCore/src/DetectorSelector.cpp @@ -39,7 +39,7 @@ DetectorSelector::detectors(const string& type1, try { if ( !types[i]->empty() ) { const vector<DetElement>& v = lcdd.detectors(*(types[i])); - result.insert(result.end(),v.begin(),v.end()); + result.insert(end(result),begin(v),end(v)); } } catch(...) {} @@ -56,8 +56,8 @@ DetectorSelector::detectors(unsigned int includeFlag, unsigned int excludeFlag ) const LCDD::HandleMap& entries = lcdd.detectors(); result.reserve( entries.size() ) ; lcdd.detectors(""); // Just to ensure the geometry is closed.... - for(LCDD::HandleMap::const_iterator i=entries.begin(); i!=entries.end(); ++i) { - DetElement det((*i).second); + for(const auto& i : entries ) { + DetElement det(i.second); if ( det.parent().isValid() ) { // Exclude 'world' //fixme: what to do with compounds - add their daughters ? // ... diff --git a/DDCore/src/IDDescriptor.cpp b/DDCore/src/IDDescriptor.cpp index d4b5ab7bbe921c6abcffe3e546c3a81c460b71e5..74acf99007d352dadc5a7500414b0846c50972cd 100644 --- a/DDCore/src/IDDescriptor.cpp +++ b/DDCore/src/IDDescriptor.cpp @@ -65,7 +65,7 @@ unsigned IDDescriptor::maxBit() const { /// Access the field-id container const IDDescriptor::FieldIDs& IDDescriptor::ids() const { - if (isValid()) { + if ( isValid() ) { return data<Object>()->fieldIDs; } throw runtime_error("DD4hep: Attempt to access an invalid IDDescriptor object."); @@ -73,7 +73,7 @@ const IDDescriptor::FieldIDs& IDDescriptor::ids() const { /// Access the fieldmap container const IDDescriptor::FieldMap& IDDescriptor::fields() const { - if (isValid()) { + if ( isValid() ) { return data<Object>()->fieldMap; } throw runtime_error("DD4hep: Attempt to access an invalid IDDescriptor object."); @@ -82,10 +82,12 @@ const IDDescriptor::FieldMap& IDDescriptor::fields() const { /// Get the field descriptor of one field by name IDDescriptor::Field IDDescriptor::field(const string& field_name) const { const FieldMap& m = fields(); // This already checks the object validity - for (FieldMap::const_iterator i = m.begin(); i != m.end(); ++i) - if ((*i).first == field_name) - return (*i).second; - throw runtime_error("DD4hep: " + string(name()) + ": This ID descriptor has no field with the name:" + field_name); + for (const auto& i : m ) + if (i.first == field_name) + return i.second; + except("IDDescriptor","DD4hep: %s: This ID descriptor has no field with the name: %s", + name(),field_name.c_str()); + throw runtime_error("DD4hep"); // Never called. Simply make the compiler happy! } /// Get the field descriptor of one field by its identifier @@ -97,21 +99,21 @@ IDDescriptor::Field IDDescriptor::field(size_t identifier) const { /// Get the field identifier of one field by name size_t IDDescriptor::fieldID(const string& field_name) const { const FieldIDs& m = ids(); // This already checks the object validity - for (FieldIDs::const_iterator i = m.begin(); i != m.end(); ++i) - if ((*i).second == field_name) - return (*i).first; - throw runtime_error("DD4hep: " + string(name()) + ": This ID descriptor has no field with the name:" + field_name); + for (const auto& i : m ) + if (i.second == field_name) + return i.first; + except("IDDescriptor","DD4hep: %s: This ID descriptor has no field with the name: %s", + name(),field_name.c_str()); + throw runtime_error("DD4hep"); // Never called. Simply make the compiler happy! } /// Encode a set of volume identifiers (corresponding to this description of course!) to a volumeID. VolumeID IDDescriptor::encode(const std::vector<VolID>& id_vector) const { - typedef std::vector<VolID> VolIds; VolumeID id = 0; - for (VolIds::const_iterator i = id_vector.begin(); i != id_vector.end(); ++i) { - Field f = field((*i).first); - VolumeID vid = (*i).second; + for (const auto& i : id_vector ) { + Field f = field(i.first); int offset = f->offset(); - id |= ((f->value(vid<<offset) << offset)&f->mask()); + id |= ((f->value(i.second<<offset) << offset)&f->mask()); } return id; } @@ -119,13 +121,13 @@ VolumeID IDDescriptor::encode(const std::vector<VolID>& id_vector) const { /// Decode volume IDs and return filled descriptor with all fields void IDDescriptor::decodeFields(VolumeID vid, VolIDFields& flds) { flds.clear(); - if (isValid()) { + if ( isValid() ) { const vector<BitFieldValue*>& v = ptr()->fields(); - for (vector<BitFieldValue*>::const_iterator i = v.begin(); i != v.end(); ++i) - flds.push_back(VolIDField(*i, (*i)->value(vid))); + for (auto f : v ) + flds.push_back(VolIDField(f, f->value(vid))); return; } - throw runtime_error("DD4hep: Attempt to access an invalid IDDescriptor object."); + except("IDDescriptor","DD4hep: Attempt to access an invalid IDDescriptor object."); } /// Access the BitField64 object diff --git a/DDCore/src/Objects.cpp b/DDCore/src/Objects.cpp index a23fb575810d74ec22398f5d606079289fd93f54..b7d1c9095a13671db6a4ffe5ced6f5700a29a432 100644 --- a/DDCore/src/Objects.cpp +++ b/DDCore/src/Objects.cpp @@ -505,9 +505,8 @@ IDSpec::IDSpec(LCDD& lcdd, const string& name, const IDDescriptor& dsc) const IDDescriptor::FieldIDs& f = dsc.ids(); const IDDescriptor::FieldMap& m = dsc.fields(); object<Object>().Attr_length = dsc.maxBit(); - for(IDDescriptor::FieldIDs::const_iterator i=f.begin(); i!=f.end();++i) { - int ident = (*i).first; - const string& nam = (*i).second; + for(const auto& i : f ) { + const string& nam = i.second; const pair<int,int>& fld = m.find(nam)->second; addField(nam,fld); } diff --git a/DDCore/src/Readout.cpp b/DDCore/src/Readout.cpp index 2d83926ff9b67ba6e61d4f7a2de24d5435798da0..5a6e04dc3ef22d210f2c85cfe46cfabbe37f4743 100644 --- a/DDCore/src/Readout.cpp +++ b/DDCore/src/Readout.cpp @@ -67,8 +67,8 @@ vector<string> Readout::collectionNames() const { if ( isValid() ) { Object& ro = object<Object>(); if ( !ro.hits.empty() ) { - for(Object::Collections::const_iterator i=ro.hits.begin(); i!=ro.hits.end(); ++i) - colls.push_back((*i).name); + for(const auto& hit : ro.hits ) + colls.push_back(hit.name); } return colls; } @@ -81,8 +81,8 @@ vector<const HitCollection*> Readout::collections() const { if ( isValid() ) { Object& ro = object<Object>(); if ( !ro.hits.empty() ) { - for(Object::Collections::const_iterator i=ro.hits.begin(); i!=ro.hits.end(); ++i) - colls.push_back(&(*i)); + for(const auto& hit : ro.hits ) + colls.push_back(&hit); } return colls; } diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index 903a1d4f38a3b7f67c21c6772e8b60c72bb98060..cae3577d707d1d411bca0d0790acc645d43a25f6 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -53,8 +53,8 @@ namespace { parent_sd = m_lcdd.sensitiveDetector(e.name()); } //printout(INFO, "VolumeManager", "++ Executing %s plugin manager version",typ ? "***NEW***" : "***OLD***"); - 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; @@ -83,14 +83,14 @@ namespace { const DetElement::Children& c = e.children(); if (e.placement().ptr() == pv.ptr()) return e; - for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) { - DetElement de = (*i).second; - if (de.placement().ptr() == pv.ptr()) + for (const auto& i : c ) { + DetElement de = i.second; + if ( de.placement().ptr() == pv.ptr() ) return de; } - for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) { - DetElement de = findElt((*i).second, pv); - if (de.isValid()) + for (const auto& i : c ) { + DetElement de = findElt(i.second, pv); + if ( de.isValid() ) return de; } return DetElement(); @@ -499,12 +499,11 @@ VolumeManager VolumeManager::subdetector(VolumeID id) const { if (isValid()) { const Object& o = _data(); /// Need to perform a linear search, because the "system" tag width may vary between subdetectors - for (Detectors::const_iterator j = o.subdetectors.begin(); j != o.subdetectors.end(); ++j) { - const Object& mo = (*j).second._data(); - //VolumeID sys_id = mo.system.decode(id); - VolumeID sys_id = mo.system->value(id << mo.system->offset()); - if (sys_id == mo.sysID) - return (*j).second; + for (const auto& j : o.subdetectors ) { + const Object& mo = j.second._data(); + VolumeID sys_id = mo.system->value(id << mo.system->offset()); + if ( sys_id == mo.sysID ) + return j.second; } throw runtime_error("DD4hep: VolumeManager::subdetector(VolID): " "Attempt to access unknown subdetector section."); @@ -541,6 +540,7 @@ bool VolumeManager::adoptPlacement(VolumeID /* sys_id */, Context* context) { goto Fail; } #endif + if (i == o.volumes.end()) { o.volumes[vid] = context; o.detMask |= context->mask; diff --git a/DDG4/examples/initAClick.C b/DDG4/examples/initAClick.C index 4857f2ced66c839156cc8c7001ee58f293a7db98..4ba9f5cda2b78c00e7288beecb80c1f997e2aa8b 100644 --- a/DDG4/examples/initAClick.C +++ b/DDG4/examples/initAClick.C @@ -60,7 +60,7 @@ int initAClick(const char* command=0) { std::string rootsys = make_str(gSystem->Getenv("ROOTSYS")); std::string geant4 = make_str(gSystem->Getenv("G4INSTALL")); std::string dd4hep = make_str(gSystem->Getenv("DD4hepINSTALL")); - std::string clhep = make_str(gSystem->Getenv("CLHEP_DIR")); + std::string clhep = make_str(gSystem->Getenv("CLHEP_ROOT_DIR")); std::string defs = ""; std::string libs = " -L"+rootsys+"/lib"; std::string inc = " -I"+dd4hep+"/examples/DDG4/examples -I"+dd4hep + " -I"+dd4hep+"/include"; @@ -68,7 +68,7 @@ int initAClick(const char* command=0) { if ( !geant4.empty() ) { inc += " -I"+geant4+"/include/Geant4"; #ifdef __APPLE__ - libs += (" -L"+geant4+"/lib -L"+geant4+"/lib"); + libs += (" -L"+geant4+"/lib"); #else libs += (" -L"+geant4+"/lib -L"+geant4+"/lib64"); #endif @@ -77,14 +77,18 @@ int initAClick(const char* command=0) { // A bit unclear how to deal with CLHEP libraries here, // if CLHEP is not included in Geant4... inc += " -I"+clhep+"/include"; + std::string clhep_lib = make_str(gSystem->Getenv("CLHEP_LIBRARY_PATH")); + if ( !clhep_lib.empty() ) libs += " -L"+clhep_lib+"/lib"; } inc += " -Wno-shadow -g -O0" + defs; +#ifndef __APPLE__ libs += " -lCore -lMathCore -pthread -lm -ldl -rdynamic"; +#endif gSystem->AddIncludePath(inc.c_str()); gSystem->AddLinkedLibs(libs.c_str()); std::cout << "+++ Includes: " << gSystem->GetIncludePath() << std::endl; std::cout << "+++ Linked libs:" << gSystem->GetLinkedLibs() << std::endl; - int ret = gSystem->Load("libDDG4Plugins"); + int ret = 0; // gSystem->Load("libDDG4Plugins"); if ( 0 == ret ) { if ( command ) { processCommand(command, true); diff --git a/cmake/thisdd4hep.sh b/cmake/thisdd4hep.sh index a5f579e433ca6789af5bbd85f54493e40461826c..397fb0a54bdf80bf3cdbea64d5745ad3b1cff785 100644 --- a/cmake/thisdd4hep.sh +++ b/cmake/thisdd4hep.sh @@ -85,8 +85,10 @@ if [ ${Geant4_DIR} ]; then #---- if geant4 was built with external CLHEP we have to extend the dynamic search path if [ @GEANT4_USE_CLHEP@ ] ; then dd4hep_add_library_path @CLHEP_LIBRARY_PATH@; - export CLHEP_DIR=@CLHEP_ROOT_DIR@ fi; + export CLHEP_DIR=@CLHEP_ROOT_DIR@; + export CLHEP_ROOT_DIR=@CLHEP_ROOT_DIR@; + export CLHEP_LIBRARY_PATH=@CLHEP_LIBRARY_PATH@; dd4hep_add_library_path ${G4LIB_DIR}; unset G4ENV_INIT; unset G4LIB_DIR; diff --git a/examples/DDDB/scripts/run_dddb.sh b/examples/DDDB/scripts/run_dddb.sh index 29ed3efaf22d8c069def23e464fc2b04d5dc7f43..3a2c0845e537a6f310e4222df567c932b24caf91 100755 --- a/examples/DDDB/scripts/run_dddb.sh +++ b/examples/DDDB/scripts/run_dddb.sh @@ -123,9 +123,6 @@ if [ "$(uname)" == "Darwin" ]; then export DYLD_LIBRARY_PATH=${DD4HEP_LIBRARY_PATH} fi export DD4HEP_TRACE=ON; -echo "Command(1): ${debug} `which geoPluginRun` -destroy -plugin DDDB_Executor ${loader} ${params} ${input} ${config} ${exec} ${vis} ${plugins}" -echo "Command(2): ${debug} `which geoPluginRun` -destroy -plugin DDDB_Executor ${all_args} ${plugins}" - ARGS=`echo -plugin DDDB_Executor ${loader} ${params} ${input} ${config} ${exec} ${vis} ${plugins}`; echo "Command: ${debug} `which geoPluginRun` -destroy $ARGS"; if test -z "${debug}";then