From 49a4f6e4d0eed23d4e5f35d2b531c8e391b40a44 Mon Sep 17 00:00:00 2001 From: Markus Frank Date: Mon, 12 Feb 2024 09:14:50 +0100 Subject: [PATCH] Remove use of standard namespace from implementation --- DDAlign/src/AlignmentsCalib.cpp | 35 +- DDAlign/src/GlobalAlignmentCache.cpp | 82 +-- DDAlign/src/GlobalAlignmentOperators.cpp | 22 +- DDAlign/src/GlobalAlignmentStack.cpp | 53 +- DDAlign/src/GlobalAlignmentWriter.cpp | 47 +- DDAlign/src/GlobalDetectorAlignment.cpp | 82 +-- DDAlign/src/plugins/AlignmentsPlugins.cpp | 31 +- DDAlign/src/plugins/GlobalAlignmentParser.cpp | 85 +-- DDCAD/src/ASSIMPWriter.cpp | 120 +-- DDCAD/src/plugins/CADPlugins.cpp | 161 ++-- DDCond/src/ConditionsContent.cpp | 24 +- DDCond/src/ConditionsDependencyHandler.cpp | 48 +- DDCond/src/ConditionsIOVPool.cpp | 13 +- DDCond/src/ConditionsManager.cpp | 59 +- DDCond/src/ConditionsOperators.cpp | 14 +- DDCond/src/ConditionsPool.cpp | 18 +- DDCond/src/ConditionsRepository.cpp | 124 ++-- DDCond/src/ConditionsRootPersistency.cpp | 48 +- DDCond/src/ConditionsSlice.cpp | 72 +- DDCond/src/ConditionsTextRepository.cpp | 111 ++- DDCond/src/ConditionsTreePersistency.cpp | 83 ++- DDCond/src/Type1/Manager_Type1.cpp | 122 ++- DDCond/src/plugins/ConditionsLinearPool.cpp | 24 +- DDCond/src/plugins/ConditionsMappedPool.cpp | 19 +- DDCond/src/plugins/ConditionsMultiLoader.cpp | 29 +- DDCond/src/plugins/ConditionsParser.cpp | 48 +- DDCond/src/plugins/ConditionsPlugins.cpp | 88 +-- .../plugins/ConditionsRepositoryParser.cpp | 155 ++-- .../plugins/ConditionsRepositoryWriter.cpp | 181 +++-- .../plugins/ConditionsSnapshotRootLoader.cpp | 22 +- DDCond/src/plugins/ConditionsUserPool.cpp | 127 ++-- DDCond/src/plugins/ConditionsXmlLoader.cpp | 65 +- DDCore/include/XML/Layering.h | 2 +- DDCore/src/AlignmentData.cpp | 31 +- DDCore/src/AlignmentNominalMap.cpp | 10 +- DDCore/src/AlignmentTools.cpp | 16 +- DDCore/src/Alignments.cpp | 18 +- DDCore/src/AlignmentsCalculator.cpp | 28 +- DDCore/src/AlignmentsInterna.cpp | 21 +- DDCore/src/AlignmentsPrinter.cpp | 63 +- DDCore/src/AlignmentsProcessor.cpp | 47 +- DDCore/src/BuildType.cpp | 2 +- DDCore/src/Callback.cpp | 8 +- DDCore/src/CartesianGridXY.cpp | 13 +- DDCore/src/CartesianGridXYZ.cpp | 15 +- DDCore/src/CartesianGridXZ.cpp | 13 +- DDCore/src/CartesianGridYZ.cpp | 13 +- DDCore/src/CartesianStripX.cpp | 9 +- DDCore/src/CartesianStripY.cpp | 9 +- DDCore/src/CartesianStripZ.cpp | 9 +- DDCore/src/ComponentProperties.cpp | 57 +- DDCore/src/ConditionAny.cpp | 6 +- DDCore/src/ConditionDerived.cpp | 8 +- DDCore/src/Conditions.cpp | 53 +- DDCore/src/ConditionsData.cpp | 8 +- DDCore/src/ConditionsDebug.cpp | 11 +- DDCore/src/ConditionsInterna.cpp | 19 +- DDCore/src/ConditionsListener.cpp | 2 +- DDCore/src/ConditionsMap.cpp | 6 +- DDCore/src/ConditionsPrinter.cpp | 71 +- DDCore/src/ConditionsProcessor.cpp | 25 +- DDCore/src/DD4hepRootPersistency.cpp | 31 +- DDCore/src/DD4hepUI.cpp | 64 +- DDCore/src/DetectorData.cpp | 1 - DDCore/src/JSON/Detector.cpp | 4 +- DDCore/src/JSON/DocumentHandler.cpp | 13 +- DDCore/src/JSON/Elements.cpp | 83 ++- DDCore/src/JSON/Helpers.cpp | 4 +- DDCore/src/Path.cpp | 48 +- DDCore/src/XML/Detector.cpp | 2 +- DDCore/src/XML/DocumentHandler.cpp | 210 +++--- DDCore/src/XML/Layering.cpp | 109 ++- DDCore/src/XML/UriReader.cpp | 16 +- DDCore/src/XML/Utilities.cpp | 99 ++- DDCore/src/XML/VolumeBuilder.cpp | 141 ++-- DDCore/src/XML/XMLElements.cpp | 169 +++-- DDCore/src/plugins/Compact2Objects.cpp | 379 +++++----- .../src/segmentations/MultiSegmentation.cpp | 18 +- DDDigi/plugins/DigiRandomNoise.cpp | 3 +- DDDigi/src/DigiActionSequence.cpp | 7 +- DDDigi/src/DigiHandle.cpp | 16 +- DDDigi/src/DigiLockedAction.cpp | 5 +- DDDigi/src/DigiMonitorHandler.cpp | 33 +- DDDigi/src/DigiSegmentation.cpp | 2 - DDDigi/src/DigiSegmentationTool.cpp | 86 +-- DDDigi/src/DigiSynchronize.cpp | 7 +- DDDigi/src/noise/DigiSubdetectorSequence.cpp | 33 +- DDDigi/src/noise/FalphaNoise.cpp | 1 - DDDigi/test_task_queue.cpp | 9 +- DDEve/src/Annotation.cpp | 8 +- DDG4/plugins/Geant4CaloSmearShowerModel.cpp | 64 +- .../Geant4DetectorGeometryConstruction.cpp | 132 ++-- .../Geant4DetectorSensitivesConstruction.cpp | 52 +- DDG4/plugins/Geant4EscapeCounter.cpp | 35 +- DDG4/plugins/Geant4EventReaderGuineaPig.cpp | 37 +- DDG4/plugins/Geant4EventReaderHepEvt.cpp | 28 +- DDG4/plugins/Geant4EventReaderHepMC.cpp | 126 ++-- DDG4/plugins/Geant4FastPhysics.cpp | 1 - DDG4/plugins/Geant4FastSimShowerModel.cpp | 3 +- DDG4/plugins/Geant4FieldTrackingSetup.cpp | 31 +- DDG4/plugins/Geant4GDMLWriteAction.cpp | 8 +- DDG4/plugins/Geant4GFlashShowerModel.cpp | 1 - DDG4/plugins/Geant4GeometryScanner.cpp | 5 +- DDG4/plugins/Geant4HitDumpAction.cpp | 6 +- DDG4/plugins/Geant4HitExtractor.cpp | 1 - DDG4/plugins/Geant4HitTruthHandler.cpp | 18 +- DDG4/plugins/Geant4MaterialScanner.cpp | 37 +- DDG4/plugins/Geant4ParticleDumpAction.cpp | 18 +- DDG4/plugins/Geant4ROOTDump.cpp | 75 +- DDG4/plugins/Geant4SensDetFilters.cpp | 44 +- DDG4/plugins/Geant4TrackerWeightedSD.cpp | 20 +- .../Geant4UserActionInitialization.cpp | 13 +- DDG4/plugins/Geant4XMLSetup.cpp | 697 +++++++++--------- DDG4/reco/Geant4SurfaceTest.cpp | 33 +- DDG4/src/Geant4Action.cpp | 5 +- DDG4/src/Geant4Context.cpp | 3 +- DDG4/src/Geant4Data.cpp | 1 - DDG4/src/Geant4DataDump.cpp | 4 +- DDG4/src/Geant4DetectorConstruction.cpp | 34 +- DDG4/src/Geant4EventAction.cpp | 16 +- DDG4/src/Geant4Exec.cpp | 124 ++-- DDG4/src/Geant4FastSimShowerModel.cpp | 1 - DDG4/src/Geant4GDMLDetector.cpp | 5 +- DDG4/src/Geant4GeneratorAction.cpp | 26 +- DDG4/src/Geant4GeneratorWrapper.cpp | 31 +- DDG4/src/Geant4GeometryInfo.cpp | 21 +- DDG4/src/Geant4Handle.cpp | 76 +- DDG4/src/Geant4HierarchyDump.cpp | 78 +- DDG4/src/Geant4HitCollection.cpp | 13 +- DDG4/src/Geant4HitHandler.cpp | 15 +- DDG4/src/Geant4InputAction.cpp | 38 +- DDG4/src/Geant4InputHandling.cpp | 38 +- DDG4/src/Geant4IsotropeGenerator.cpp | 11 +- DDG4/src/Geant4Kernel.cpp | 43 +- DDG4/src/Geant4Mapping.cpp | 19 +- DDG4/src/Geant4Output2ROOT.cpp | 30 +- DDG4/src/Geant4OutputAction.cpp | 22 +- DDG4/src/Geant4Particle.cpp | 25 +- DDG4/src/Geant4ParticleGenerator.cpp | 24 +- DDG4/src/Geant4ParticleGun.cpp | 19 +- DDG4/src/Geant4ParticleHandler.cpp | 17 +- DDG4/src/Geant4ParticlePrint.cpp | 27 +- DDG4/src/Geant4PhysicsConstructor.cpp | 9 +- DDG4/src/Geant4PhysicsList.cpp | 72 +- DDG4/src/Geant4Primary.cpp | 11 +- DDG4/src/Geant4Random.cpp | 39 +- DDG4/src/Geant4RunAction.cpp | 24 +- DDG4/src/Geant4SensDetAction.cpp | 62 +- DDG4/src/Geant4StackingAction.cpp | 32 +- DDG4/src/Geant4StepHandler.cpp | 11 +- DDG4/src/Geant4SteppingAction.cpp | 24 +- DDG4/src/Geant4TestActions.cpp | 16 +- DDG4/src/Geant4TouchableHandler.cpp | 13 +- DDG4/src/Geant4TrackInformation.cpp | 4 +- DDG4/src/Geant4TrackingAction.cpp | 36 +- DDG4/src/Geant4TrackingPostAction.cpp | 11 +- DDG4/src/Geant4TrackingPreAction.cpp | 6 +- DDG4/src/Geant4UIManager.cpp | 17 +- DDG4/src/Geant4UIMessenger.cpp | 28 +- DDG4/src/Geant4UserInitialization.cpp | 14 +- DDG4/src/Geant4UserLimits.cpp | 44 +- DDG4/src/Geant4Vertex.cpp | 7 +- DDG4/src/Geant4VolumeManager.cpp | 127 ++-- DDG4/src/IoStreams.cpp | 10 +- DDG4/src/python/Geant4PythonAction.cpp | 16 +- DDG4/src/python/Geant4PythonCall.cpp | 4 - .../Geant4PythonDetectorConstruction.cpp | 17 +- .../Geant4PythonDetectorConstructionLast.cpp | 4 +- .../src/python/Geant4PythonInitialization.cpp | 13 +- DDG4/tpython/DDPython.cpp | 85 ++- 170 files changed, 3565 insertions(+), 3848 deletions(-) diff --git a/DDAlign/src/AlignmentsCalib.cpp b/DDAlign/src/AlignmentsCalib.cpp index aaa01c8e7..96ab2a08d 100644 --- a/DDAlign/src/AlignmentsCalib.cpp +++ b/DDAlign/src/AlignmentsCalib.cpp @@ -12,17 +12,14 @@ //========================================================================== // Framework includes -#include "DDAlign/AlignmentsCalib.h" +#include -#include "DD4hep/Memory.h" -#include "DD4hep/Printout.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/detail/AlignmentsInterna.h" +#include +#include +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::align; -typedef Condition::key_type key_type; /// Helper class to store information about alignment calibration items /** Implementation details: Alignment context entry @@ -34,12 +31,12 @@ typedef Condition::key_type key_type; */ class AlignmentsCalib::Entry { public: - Delta delta; - Delta original; - Condition source; - DetElement detector; - Condition::key_type target = 0; - int dirty = 0; + dd4hep::Delta delta; + dd4hep::Delta original; + dd4hep::Condition source; + dd4hep::DetElement detector; + dd4hep::Condition::key_type target = 0; + int dirty = 0; Entry() = default; Entry(const Entry& c) = delete; Entry& operator=(const Entry& c) = delete; @@ -57,13 +54,13 @@ AlignmentsCalib::~AlignmentsCalib() noexcept(false) { } /// Convenience only: Access detector element by path -DetElement AlignmentsCalib::detector(const string& path) const { +dd4hep::DetElement AlignmentsCalib::detector(const std::string& path) const { DetElement det(detail::tools::findElement(description,path)); return det; } /// Implementation: Add a new entry to the transaction stack. -pair +std::pair AlignmentsCalib::_set(DetElement detector, const Delta& delta) { ConditionKey tar_key(detector.key(),Keys::alignmentKey); UsedConditions::iterator i = used.find(tar_key.hash); @@ -103,14 +100,14 @@ AlignmentsCalib::_set(DetElement detector, const Delta& delta) { } /// (1) Add a new entry to an existing DetElement structure. -Condition::key_type +dd4hep::Condition::key_type AlignmentsCalib::set(DetElement det, const Delta& delta) { return _set(det.access(), delta).first; } /// (2) Add a new entry to an existing DetElement structure. -Condition::key_type -AlignmentsCalib::set(const string& path, const Delta& delta) { +dd4hep::Condition::key_type +AlignmentsCalib::set(const std::string& path, const Delta& delta) { return _set(detector(path).access(), delta).first; } diff --git a/DDAlign/src/GlobalAlignmentCache.cpp b/DDAlign/src/GlobalAlignmentCache.cpp index 28b4a4235..0c1fc436b 100644 --- a/DDAlign/src/GlobalAlignmentCache.cpp +++ b/DDAlign/src/GlobalAlignmentCache.cpp @@ -12,35 +12,33 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Printout.h" -#include "DDAlign/GlobalAlignmentCache.h" -#include "DDAlign/GlobalAlignmentOperators.h" -#include "DD4hep/detail/DetectorInterna.h" +#include +#include +#include +#include +#include // ROOT include files -#include "TGeoManager.h" +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::align; -using namespace dd4hep::align::DDAlign_standard_operations; -typedef GlobalAlignmentStack::StackEntry Entry; +using Entry = GlobalAlignmentStack::StackEntry; -DetElement _detector(DetElement child) { +dd4hep::DetElement _detector(dd4hep::DetElement child) { if ( child.isValid() ) { - DetElement p(child.parent()); + dd4hep::DetElement p(child.parent()); if ( p.isValid() && !p.parent().isValid() ) return child; else if ( !p.isValid() ) // World detector element... return child; return _detector(p); } - throw runtime_error("dd4hep: DetElement cannot determine detector parent [Invalid handle]"); + dd4hep::except("GlobalAlignmentCache", "DetElement cannot determine detector parent [Invalid handle]"); + return {}; } /// Default constructor -GlobalAlignmentCache::GlobalAlignmentCache(Detector& description, const string& sdPath, bool top) +GlobalAlignmentCache::GlobalAlignmentCache(Detector& description, const std::string& sdPath, bool top) : m_detDesc(description), m_sdPath(sdPath), m_sdPathLen(sdPath.length()), m_refCount(1), m_top(top) { } @@ -48,7 +46,7 @@ GlobalAlignmentCache::GlobalAlignmentCache(Detector& description, const string& /// Default destructor GlobalAlignmentCache::~GlobalAlignmentCache() { int nentries = (int)m_cache.size(); - int nsect = (int)m_detectors.size(); + int nsect = (int)m_detectors.size(); detail::releaseObjects(m_detectors); m_cache.clear(); printout(INFO,"GlobalAlignmentCache", @@ -103,26 +101,26 @@ bool GlobalAlignmentCache::insert(GlobalAlignment alignment) { } /// Retrieve the cache section corresponding to the path of an entry. -GlobalAlignmentCache* GlobalAlignmentCache::section(const string& path_name) const { - size_t idx, idq; +GlobalAlignmentCache* GlobalAlignmentCache::section(const std::string& path_name) const { + std::size_t idx, idq; if ( path_name[0] != '/' ) { return section(m_detDesc.world().placementPath()+'/'+path_name); } - else if ( (idx=path_name.find('/',1)) == string::npos ) { + else if ( (idx=path_name.find('/',1)) == std::string::npos ) { return (m_sdPath == path_name.c_str()+1) ? (GlobalAlignmentCache*)this : 0; } else if ( m_detectors.empty() ) { return 0; } - if ( (idq=path_name.find('/',idx+1)) != string::npos ) --idq; - string path = path_name.substr(idx+1,idq-idx); + if ( (idq=path_name.find('/',idx+1)) != std::string::npos ) --idq; + std::string path = path_name.substr(idx+1,idq-idx); SubdetectorAlignments::const_iterator j = m_detectors.find(path); return (j==m_detectors.end()) ? 0 : (*j).second; } /// Retrieve an alignment entry by its placement path -GlobalAlignment GlobalAlignmentCache::get(const string& path_name) const { - size_t idx, idq; +GlobalAlignment GlobalAlignmentCache::get(const std::string& path_name) const { + std::size_t idx, idq; unsigned int index = detail::hash32(path_name.c_str()+m_sdPathLen); Cache::const_iterator i = m_cache.find(index); if ( i != m_cache.end() ) { @@ -134,23 +132,24 @@ GlobalAlignment GlobalAlignmentCache::get(const string& path_name) const { else if ( path_name[0] != '/' ) { return get(m_detDesc.world().placementPath()+'/'+path_name); } - else if ( (idx=path_name.find('/',1)) == string::npos ) { + else if ( (idx=path_name.find('/',1)) == std::string::npos ) { // Escape: World volume and not found in cache --> not present return GlobalAlignment(0); } - if ( (idq=path_name.find('/',idx+1)) != string::npos ) --idq; - string path = path_name.substr(idx+1,idq-idx); + if ( (idq=path_name.find('/',idx+1)) != std::string::npos ) --idq; + std::string path = path_name.substr(idx+1, idq-idx); SubdetectorAlignments::const_iterator j = m_detectors.find(path); if ( j != m_detectors.end() ) return (*j).second->get(path_name); return GlobalAlignment(0); } /// Return all entries matching a given path. -vector GlobalAlignmentCache::matches(const string& match, bool exclude_exact) const { - vector result; +std::vector +GlobalAlignmentCache::matches(const std::string& match, bool exclude_exact) const { + std::vector result; GlobalAlignmentCache* c = section(match); if ( c ) { - size_t len = match.length(); + std::size_t len = match.length(); result.reserve(c->m_cache.size()); for(Cache::const_iterator i=c->m_cache.begin(); i!=c->m_cache.end();++i) { const Cache::value_type& v = *i; @@ -173,7 +172,7 @@ void GlobalAlignmentCache::commit(GlobalAlignmentStack& stack) { } /// Retrieve branch cache by name. If not present it will be created -GlobalAlignmentCache* GlobalAlignmentCache::subdetectorAlignments(const string& nam) { +GlobalAlignmentCache* GlobalAlignmentCache::subdetectorAlignments(const std::string& nam) { SubdetectorAlignments::const_iterator i = m_detectors.find(nam); if ( i == m_detectors.end() ) { GlobalAlignmentCache* ptr = new GlobalAlignmentCache(m_detDesc,nam,false); @@ -185,8 +184,8 @@ GlobalAlignmentCache* GlobalAlignmentCache::subdetectorAlignments(const string& /// Apply a complete stack of ordered alignments to the geometry structure void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) { - typedef map DetElementUpdates; - typedef map > sd_entries_t; + typedef std::map DetElementUpdates; + typedef std::map > sd_entries_t; TGeoManager& mgr = m_detDesc.manager(); DetElementUpdates detelt_updates; sd_entries_t all; @@ -218,10 +217,10 @@ void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) { elt->update(DetElement::PLACEMENT_CHANGED|DetElement::PLACEMENT_ELEMENT,elt.ptr()); } // Provide update callback for the highest detector element - string last_path = "?????"; + std::string last_path = "?????"; for(DetElementUpdates::iterator i=detelt_updates.begin(); i!=detelt_updates.end(); ++i) { - const string& path = (*i).first; - if ( path.find(last_path) == string::npos ) { + const std::string& path = (*i).first; + if ( path.find(last_path) == std::string::npos ) { DetElement elt((*i).second); printout(DEBUG,"GlobalAlignmentCache","+++ Trigger placement update for %s [1]",elt.path().c_str()); elt->update(DetElement::PLACEMENT_CHANGED|DetElement::PLACEMENT_HIGHEST,elt.ptr()); @@ -237,15 +236,16 @@ void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) { } /// Apply a vector of SD entries of ordered alignments to the geometry structure -void GlobalAlignmentCache::apply(const vector& changes) { - typedef map > Nodes; - Nodes nodes; +void GlobalAlignmentCache::apply(const std::vector& changes) { + std::map > nodes; + namespace ops = dd4hep::align::DDAlign_standard_operations; GlobalAlignmentSelector selector(*this,nodes,changes); + for_each(m_cache.begin(),m_cache.end(),selector.reset()); - for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); - for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); + for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); + for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); for_each(changes.begin(),changes.end(),selector.reset()); - for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); - for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); + for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); + for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor(*this,nodes)); } diff --git a/DDAlign/src/GlobalAlignmentOperators.cpp b/DDAlign/src/GlobalAlignmentOperators.cpp index 2488f3d75..9e8afef27 100644 --- a/DDAlign/src/GlobalAlignmentOperators.cpp +++ b/DDAlign/src/GlobalAlignmentOperators.cpp @@ -12,17 +12,15 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Printout.h" -#include "DD4hep/detail/DetectorInterna.h" -#include "DDAlign/GlobalAlignmentOperators.h" -#include "DDAlign/GlobalDetectorAlignment.h" +#include +#include +#include +#include +#include // C/C++ include files #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::align; void GlobalAlignmentOperator::insert(GlobalAlignment alignment) const { @@ -33,7 +31,7 @@ void GlobalAlignmentOperator::insert(GlobalAlignment alignment) const { void GlobalAlignmentSelector::operator()(Entries::value_type e) const { TGeoPhysicalNode* pn = 0; - nodes.emplace(e->path,make_pair(pn,e)); + nodes.emplace(e->path,std::make_pair(pn,e)); } void GlobalAlignmentSelector::operator()(const Cache::value_type& entry) const { @@ -44,11 +42,11 @@ void GlobalAlignmentSelector::operator()(const Cache::value_type& entry) const const char* p = pn->GetName(); bool reset_children = GlobalAlignmentStack::resetChildren(*e); if ( reset_children && ::strstr(p,e->path.c_str()) == p ) { - nodes.emplace(p,make_pair(pn,e)); + nodes.emplace(p,std::make_pair(pn,e)); break; } else if ( e->path == p ) { - nodes.emplace(p,make_pair(pn,e)); + nodes.emplace(p,std::make_pair(pn,e)); break; } } @@ -75,12 +73,12 @@ template <> void GlobalAlignmentActor: template <> void GlobalAlignmentActor::operator()(Nodes::value_type& n) const { TGeoPhysicalNode* p = n.second.first; - string np; + std::string np; if ( p->IsAligned() ) { for (Int_t i=0, nLvl=p->GetLevel(); i<=nLvl; i++) { TGeoNode* node = p->GetNode(i); TGeoMatrix* mat = node->GetMatrix(); // Node's relative matrix - np += string("/")+node->GetName(); + np += std::string("/")+node->GetName(); if ( !mat->IsIdentity() && i > 0 ) { // Ignore the 'world', is identity anyhow GlobalAlignment a = cache.get(np); if ( a.isValid() ) { diff --git a/DDAlign/src/GlobalAlignmentStack.cpp b/DDAlign/src/GlobalAlignmentStack.cpp index aa166d88d..846885e70 100644 --- a/DDAlign/src/GlobalAlignmentStack.cpp +++ b/DDAlign/src/GlobalAlignmentStack.cpp @@ -12,22 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Objects.h" -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDAlign/GlobalAlignmentStack.h" - -using namespace std; -using namespace dd4hep; +#include +#include +#include +#include +#include + using namespace dd4hep::align; -static dd4hep_ptr& _stack() { - static dd4hep_ptr s; +static dd4hep::dd4hep_ptr& _stack() { + static dd4hep::dd4hep_ptr s; return s; } -static dd4hep_ptr& _stack(GlobalAlignmentStack* obj) { - dd4hep_ptr& stk = _stack(); +static dd4hep::dd4hep_ptr& _stack(GlobalAlignmentStack* obj) { + dd4hep::dd4hep_ptr& stk = _stack(); stk.adopt(obj); return stk; } @@ -96,13 +94,13 @@ GlobalAlignmentStack::~GlobalAlignmentStack() { /// Static client accessor GlobalAlignmentStack& GlobalAlignmentStack::get() { if ( _stack().get() ) return *_stack(); - throw runtime_error("GlobalAlignmentStack> Stack not allocated -- may not be retrieved!"); + except("GlobalAlignmentStack", "Stack not allocated -- may not be retrieved!"); } /// Create an alignment stack instance. The creation of a second instance will be refused. void GlobalAlignmentStack::create() { if ( _stack().get() ) { - throw runtime_error("GlobalAlignmentStack> Stack already allocated. Multiple copies are not allowed!"); + except("GlobalAlignmentStack", "Stack already allocated. Multiple copies are not allowed!"); } _stack(new GlobalAlignmentStack()); } @@ -118,16 +116,17 @@ void GlobalAlignmentStack::release() { _stack(0); return; } - throw runtime_error("GlobalAlignmentStack> Attempt to delete non existing stack."); + except("GlobalAlignmentStack", "Attempt to delete non existing stack."); } /// Add a new entry to the cache. The key is the placement path -bool GlobalAlignmentStack::insert(const string& full_path, dd4hep_ptr& entry) { +bool GlobalAlignmentStack::insert(const std::string& full_path, dd4hep_ptr& entry) { if ( entry.get() && !full_path.empty() ) { entry->path = full_path; return add(entry); } - throw runtime_error("GlobalAlignmentStack> Attempt to apply an invalid alignment entry."); + except("GlobalAlignmentStack", "Attempt to apply an invalid alignment entry."); + return false; } /// Add a new entry to the cache. The key is the placement path @@ -143,33 +142,35 @@ bool GlobalAlignmentStack::add(dd4hep_ptr& entry) { StackEntry* e = entry.get(); // Need to make some checks BEFORE insertion if ( !e->detector.isValid() ) { - throw runtime_error("GlobalAlignmentStack> Invalid alignment entry [No such detector]"); + except("GlobalAlignmentStack", "Invalid alignment entry [No such detector]"); } printout(INFO,"GlobalAlignmentStack","Add node:%s",e->path.c_str()); m_stack.emplace(e->path,entry.release()); return true; } - throw runtime_error("GlobalAlignmentStack> The entry with path "+entry->path+ - " cannot be re-aligned twice in one transaction."); + except("GlobalAlignmentStack", "The entry with path "+entry->path+ + " cannot be re-aligned twice in one transaction."); } - throw runtime_error("GlobalAlignmentStack> Attempt to apply an invalid alignment entry."); + except("GlobalAlignmentStack", "Attempt to apply an invalid alignment entry."); + return false; } /// Retrieve an alignment entry of the current stack -dd4hep_ptr GlobalAlignmentStack::pop() { +dd4hep::dd4hep_ptr GlobalAlignmentStack::pop() { Stack::iterator i = m_stack.begin(); if ( i != m_stack.end() ) { dd4hep_ptr e((*i).second); m_stack.erase(i); return e; } - throw runtime_error("GlobalAlignmentStack> Alignment stack is empty. " - "Cannot pop entries - check size first!"); + except("GlobalAlignmentStack", "Alignment stack is empty. " + "Cannot pop entries - check size first!"); + return {}; } /// Get all pathes to be aligned -vector GlobalAlignmentStack::entries() const { - vector result; +std::vector GlobalAlignmentStack::entries() const { + std::vector result; result.reserve(m_stack.size()); transform(begin(m_stack),end(m_stack),back_inserter(result),detail::select2nd(m_stack)); return result; diff --git a/DDAlign/src/GlobalAlignmentWriter.cpp b/DDAlign/src/GlobalAlignmentWriter.cpp index 5c6b63133..33957606a 100644 --- a/DDAlign/src/GlobalAlignmentWriter.cpp +++ b/DDAlign/src/GlobalAlignmentWriter.cpp @@ -12,25 +12,24 @@ //========================================================================== // Framework includes -#include "DDAlign/GlobalAlignmentWriter.h" -#include "DDAlign/GlobalAlignmentCache.h" -#include "DDAlign/GlobalDetectorAlignment.h" -#include "DDAlign/AlignmentTags.h" +#include +#include +#include +#include -#include "DD4hep/Detector.h" -#include "DD4hep/Printout.h" -#include "DD4hep/MatrixHelpers.h" -#include "DD4hep/detail/DetectorInterna.h" -#include "XML/DocumentHandler.h" +#include +#include +#include +#include +#include -#include "TGeoMatrix.h" +#include // C/C++ include files #include using namespace dd4hep::align; -using namespace dd4hep; -using namespace std; +namespace xml = dd4hep::xml; /// Initializing Constructor GlobalAlignmentWriter::GlobalAlignmentWriter(Detector& description) : m_detDesc(description) @@ -47,19 +46,19 @@ GlobalAlignmentWriter::~GlobalAlignmentWriter() { /// Create the element corresponding to one single detector element without children xml::Element GlobalAlignmentWriter::createElement(xml::Document doc, DetElement element) const { xml::Element e(0), placement(0), elt = xml::Element(doc,_ALU(detelement)); - string path = element.placementPath(); + std::string path = element.placementPath(); GlobalAlignment a = element->global_alignment; GlobalDetectorAlignment det(element); - const vector& va = det.volumeAlignments(); elt.setAttr(_ALU(path),element.path()); if ( a.isValid() ) { addNode(elt,a); } - for(vector::const_iterator i=va.begin(); i!=va.end();++i) { + const std::vector& vol_alignments = det.volumeAlignments(); + for(const auto& alignment : vol_alignments ) { e = xml::Element(doc,_U(volume)); - e.setAttr(_ALU(path),(*i)->GetName()); - addNode(e,*i); + e.setAttr(_ALU(path), alignment->GetName()); + addNode(e, alignment); elt.append(e); } return elt; @@ -77,9 +76,9 @@ void GlobalAlignmentWriter::addNode(xml::Element elt, GlobalAlignment a) const printout(INFO,"GlobalAlignmentWriter","Write Delta constants for %s",a->GetName()); //mat.Print(); - if ( fabs(t[0]) > numeric_limits::epsilon() || - fabs(t[1]) > numeric_limits::epsilon() || - fabs(t[2]) > numeric_limits::epsilon() ) { + if ( fabs(t[0]) > std::numeric_limits::epsilon() || + fabs(t[1]) > std::numeric_limits::epsilon() || + fabs(t[2]) > std::numeric_limits::epsilon() ) { xml::Element e = xml::Element(elt.document(),_U(position)); e.setAttr(_U(x),_toString(t[0]/dd4hep::mm,"%f*mm")); e.setAttr(_U(y),_toString(t[1]/dd4hep::mm,"%f*mm")); @@ -88,9 +87,9 @@ void GlobalAlignmentWriter::addNode(xml::Element elt, GlobalAlignment a) const } if ( mat.IsRotation() ) { XYZAngles rot = detail::matrix::_xyzAngles(&mat); - if ( fabs(rot.X()) > numeric_limits::epsilon() || - fabs(rot.Y()) > numeric_limits::epsilon() || - fabs(rot.Z()) > numeric_limits::epsilon() ) { + if ( fabs(rot.X()) > std::numeric_limits::epsilon() || + fabs(rot.Y()) > std::numeric_limits::epsilon() || + fabs(rot.Z()) > std::numeric_limits::epsilon() ) { xml::Element e = xml::Element(elt.document(),_U(rotation)); // Don't know why the angles have the wrong sign.... @@ -133,7 +132,7 @@ xml::Document GlobalAlignmentWriter::dump(DetElement top, bool enable_transactio } /// Write the XML document structure to a file. -long GlobalAlignmentWriter::write(xml::Document doc, const string& output) const { +long GlobalAlignmentWriter::write(xml::Document doc, const std::string& output) const { xml::DocumentHandler docH; return docH.output(doc, output); } diff --git a/DDAlign/src/GlobalDetectorAlignment.cpp b/DDAlign/src/GlobalDetectorAlignment.cpp index 57fcecc4d..127a62372 100644 --- a/DDAlign/src/GlobalDetectorAlignment.cpp +++ b/DDAlign/src/GlobalDetectorAlignment.cpp @@ -12,17 +12,17 @@ //========================================================================== // Framework include files -#include "DDAlign/GlobalDetectorAlignment.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/MatrixHelpers.h" -#include "DD4hep/Printout.h" -#include "DD4hep/detail/Handle.inl" -#include "DD4hep/detail/DetectorInterna.h" +#include +#include +#include +#include +#include +#include +#include // ROOT include files -#include "TGeoMatrix.h" -#include "TGeoManager.h" +#include +#include #ifdef __GNUC__ // Disable some diagnostics. @@ -56,15 +56,11 @@ namespace dd4hep { } /* End namespace Aligments */ } /* End namespace dd4hep */ -using namespace std; -using namespace dd4hep; using namespace dd4hep::align; - -typedef vector > LevelElements; +typedef std::vector > LevelElements; DD4HEP_INSTANTIATE_HANDLE_NAMED(GlobalAlignmentData); - namespace { static bool s_GlobalDetectorAlignment_debug = false; @@ -75,22 +71,22 @@ namespace { TGeoMatrix* mm = n->GetNode()->GetMatrix(); bool dbg = GlobalDetectorAlignment::debug(); if ( dbg ) { - printout(INFO,"Alignment","DELTA matrix of %s",n->GetName()); + printout(dd4hep::INFO,"Alignment","DELTA matrix of %s",n->GetName()); transform->Print(); - printout(INFO,"Alignment","OLD matrix of %s",n->GetName()); + dd4hep::printout(dd4hep::INFO,"Alignment","OLD matrix of %s",n->GetName()); mm->Print(); } transform->MultiplyLeft(mm); // orig * delta n->Align(transform, 0, check, overlap); if ( dbg ) { - printout(INFO,"Alignment","NEW matrix of %s",n->GetName()); + dd4hep::printout(dd4hep::INFO,"Alignment","NEW matrix of %s",n->GetName()); n->GetNode()->GetMatrix()->Print(); } /* - printout(INFO,"Alignment","Apply new relative matrix mother to daughter:"); + printout(dd4hep::INFO,"Alignment","Apply new relative matrix mother to daughter:"); transform->Print(); transform->MultiplyLeft(mm); // orig * delta - printout(INFO,"Alignment","With deltas %s ....",n->GetName()); + printout(dd4hep::INFO,"Alignment","With deltas %s ....",n->GetName()); transform->Print(); n->Align(transform, 0, check, overlap); @@ -100,31 +96,33 @@ namespace { */ return GlobalAlignment(n); } - throw runtime_error("dd4hep: Cannot align non existing physical node. [Invalid Handle]"); + dd4hep::except("GlobalDetectorAlignment", "Cannot align non existing physical node. [Invalid Handle]"); + return { }; } GlobalAlignment _alignment(const GlobalDetectorAlignment& det) { - DetElement::Object& e = det._data(); + dd4hep::DetElement::Object& e = det._data(); if ( !e.global_alignment.isValid() ) { - string path = detail::tools::placementPath(det); - e.global_alignment = Ref_t(new GlobalAlignmentData(path)); + std::string path = dd4hep::detail::tools::placementPath(det); + e.global_alignment = dd4hep::Ref_t(new GlobalAlignmentData(path)); } - Handle h(e.global_alignment); + dd4hep::Handle h(e.global_alignment); if ( h.isValid() && h->global.isValid() ) { return h->global; } - throw runtime_error("dd4hep: Cannot access global alignment data. [Invalid Handle]"); + dd4hep::except("GlobalDetectorAlignment", "Cannot access global alignment data. [Invalid Handle]"); + return { }; } void _dumpParentElements(GlobalDetectorAlignment& det, LevelElements& elements) { int level = 0; - detail::tools::PlacementPath nodes; - detail::tools::ElementPath det_nodes; - detail::tools::placementPath(det,nodes); - detail::tools::elementPath(det,det_nodes); - /// cout << "Placement path:"; - detail::tools::PlacementPath::const_reverse_iterator j=nodes.rbegin(); - detail::tools::ElementPath::const_reverse_iterator k=det_nodes.rbegin(); + dd4hep::detail::tools::PlacementPath nodes; + dd4hep::detail::tools::ElementPath det_nodes; + dd4hep::detail::tools::placementPath(det,nodes); + dd4hep::detail::tools::elementPath(det,det_nodes); + /// std::cout << "Placement path:"; + dd4hep::detail::tools::PlacementPath::const_reverse_iterator j=nodes.rbegin(); + dd4hep::detail::tools::ElementPath::const_reverse_iterator k=det_nodes.rbegin(); for(; j!=nodes.rend(); ++j, ++level) { //cout << "(" << level << ") " << (void*)((*j).ptr()) // << " " << string((*j)->GetName()) << " "; @@ -136,9 +134,9 @@ namespace { else { //elements.emplace_back(level,DetElement()); } - //cout << " "; + //std::cout << " "; } - //cout << endl; + //std::cout << std::endl; } } @@ -161,7 +159,7 @@ bool GlobalDetectorAlignment::debug(bool value) { } /// Collect all placements from the detector element up to the world volume -void GlobalDetectorAlignment::collectNodes(vector& nodes) { +void GlobalDetectorAlignment::collectNodes(std::vector& nodes) { detail::tools::placementPath(*this,nodes); } @@ -171,13 +169,13 @@ GlobalAlignment GlobalDetectorAlignment::alignment() const { } /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements -vector& GlobalDetectorAlignment::volumeAlignments() { +std::vector& GlobalDetectorAlignment::volumeAlignments() { Handle h(_data().global_alignment); return h->volume_alignments; } /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements -const vector& GlobalDetectorAlignment::volumeAlignments() const { +const std::vector& GlobalDetectorAlignment::volumeAlignments() const { Handle h(_data().global_alignment); return h->volume_alignments; } @@ -208,28 +206,28 @@ GlobalAlignment GlobalDetectorAlignment::align(TGeoHMatrix* matrix, bool chk, do } /// Align the PhysicalNode of the placement of the detector element (translation only) -GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, const Position& pos, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const std::string& elt_path, const Position& pos, bool chk, double overlap) { return align(elt_path,detail::matrix::_transform(pos),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (rotation only) -GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, const RotationZYX& rot, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const std::string& elt_path, const RotationZYX& rot, bool chk, double overlap) { return align(elt_path,detail::matrix::_transform(rot),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (translation + rotation) GlobalAlignment -GlobalDetectorAlignment::align(const string& elt_path, const Position& pos, const RotationZYX& rot, bool chk, double overlap) { +GlobalDetectorAlignment::align(const std::string& elt_path, const Position& pos, const RotationZYX& rot, bool chk, double overlap) { return align(elt_path,detail::matrix::_transform(pos,rot),chk,overlap); } /// Align the physical node according to a generic Transform3D -GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, const Transform3D& transform, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const std::string& elt_path, const Transform3D& transform, bool chk, double overlap) { return align(elt_path,detail::matrix::_transform(transform),chk,overlap); } /// Align the physical node according to a generic TGeo matrix -GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, TGeoHMatrix* matrix, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const std::string& elt_path, TGeoHMatrix* matrix, bool chk, double overlap) { if ( elt_path.empty() ) return _align(_alignment(*this),matrix,chk,overlap); else if ( elt_path == placementPath() ) diff --git a/DDAlign/src/plugins/AlignmentsPlugins.cpp b/DDAlign/src/plugins/AlignmentsPlugins.cpp index 72cb3d011..8d0d62181 100644 --- a/DDAlign/src/plugins/AlignmentsPlugins.cpp +++ b/DDAlign/src/plugins/AlignmentsPlugins.cpp @@ -12,19 +12,17 @@ //========================================================================== // Framework includes -#include "DD4hep/Printout.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/DetFactoryHelper.h" +#include +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::align; // ====================================================================================== -#include "DDAlign/GlobalAlignmentWriter.h" -long create_global_alignment_xml_file(Detector& description, int argc, char** argv) { - DetElement top; - string output, path = "/world"; +#include +long create_global_alignment_xml_file(dd4hep::Detector& description, int argc, char** argv) { + dd4hep::DetElement top; + std::string output, path = "/world"; bool enable_transactions = false, arg_error = false; for(int i=1; i -arg [-arg] \n" " name: factory nameDD4hep_GlobalAlignmentWriter \n\n" " -output Path to the output file generated. \n" " -path Path to the detector element for which \n" " the alignment file should be written. \n" " -transactions Enable output transactions. \n" - "\tArguments given: " << arguments(argc,argv) << endl << flush; + "\tArguments given: " << dd4hep::arguments(argc,argv) << std::endl << std::flush; ::exit(EINVAL); } - printout(ALWAYS,"AlignmentXmlWriter", - "++ Writing dd4hep alignment constants of the \"%s\" DetElement tree to file \"%s\"", - path.c_str(), output.c_str()); - top = detail::tools::findDaughterElement(description.world(),path); + dd4hep::printout(dd4hep::ALWAYS,"AlignmentXmlWriter", + "++ Writing dd4hep alignment constants of the \"%s\" " + "DetElement tree to file \"%s\"", + path.c_str(), output.c_str()); + top = dd4hep::detail::tools::findDaughterElement(description.world(),path); if ( top.isValid() ) { GlobalAlignmentWriter wr(description); return wr.write(wr.dump(top,enable_transactions), output); } - except("AlignmentXmlWriter","++ Invalid top level detector element name: %s",path.c_str()); + dd4hep::except("AlignmentXmlWriter","++ Invalid top level detector element name: %s",path.c_str()); return 1; } DECLARE_APPLY(DD4hep_GlobalAlignmentXmlWriter, create_global_alignment_xml_file) diff --git a/DDAlign/src/plugins/GlobalAlignmentParser.cpp b/DDAlign/src/plugins/GlobalAlignmentParser.cpp index 7422399a6..9f92d9348 100644 --- a/DDAlign/src/plugins/GlobalAlignmentParser.cpp +++ b/DDAlign/src/plugins/GlobalAlignmentParser.cpp @@ -12,20 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Path.h" -#include "DD4hep/Mutex.h" -#include "DD4hep/Printout.h" -#include "XML/Conversions.h" -#include "XML/XMLParsers.h" -#include "XML/DocumentHandler.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/DetFactoryHelper.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "DDAlign/AlignmentTags.h" -#include "DDAlign/GlobalAlignmentStack.h" -#include "DDAlign/GlobalAlignmentCache.h" -#include "DDAlign/GlobalDetectorAlignment.h" +#include +#include +#include +#include // C/C++ include files #include @@ -52,13 +52,13 @@ namespace dd4hep { template <> void Converter::operator()(xml_h seq) const; template <> void Converter::operator()(xml_h seq) const; template <> void Converter::operator()(xml_h seq) const; + + static long setup_Alignment(Detector& description, const xml_h& e); } -using namespace std; -using namespace dd4hep; using namespace dd4hep::align; +using StackEntry = GlobalAlignmentStack::StackEntry; -static long setup_Alignment(Detector& description, const xml_h& e); /** Convert to enable/disable debugging. * @@ -66,13 +66,11 @@ static long setup_Alignment(Detector& description, const xml_h& e); * @version 1.0 * @date 01/04/2014 */ -template <> void Converter::operator()(xml_h e) const { +template <> void dd4hep::Converter::operator()(xml_h e) const { bool value = e.attr(_U(value)); GlobalDetectorAlignment::debug(value); } -typedef GlobalAlignmentStack::StackEntry StackEntry; - /** Convert volume objects * * @@ -88,19 +86,19 @@ typedef GlobalAlignmentStack::StackEntry StackEntry; * @version 1.0 * @date 01/04/2014 */ -template <> void Converter::operator()(xml_h e) const { +template <> void dd4hep::Converter::operator()(xml_h e) const { Delta val; GlobalAlignmentStack* stack = _option(); - pair* elt = _param >(); - string subpath = e.attr(_ALU(path)); + std::pair* elt = _param >(); + std::string subpath = e.attr(_ALU(path)); bool reset = e.hasAttr(_ALU(reset)) ? e.attr(_ALU(reset)) : true; bool reset_dau = e.hasAttr(_ALU(reset_children)) ? e.attr(_ALU(reset_children)) : true; bool check = e.hasAttr(_ALU(check_overlaps)); bool check_val = check ? e.attr(_ALU(check_overlaps)) : false; bool overlap = e.hasAttr(_ALU(overlap)); double ovl = overlap ? e.attr(_ALU(overlap)) : 0.001; - string elt_place = elt->first.placementPath(); - string placement = subpath[0]=='/' ? subpath : elt_place + "/" + subpath; + std::string elt_place = elt->first.placementPath(); + std::string placement = subpath[0]=='/' ? subpath : elt_place + "/" + subpath; printout(INFO,"Alignment"," path:%s placement:%s reset:%s children:%s", subpath.c_str(), placement.c_str(), yes_no(reset), yes_no(reset_dau)); @@ -115,7 +113,7 @@ template <> void Converter::operator()(xml_h e) const { dd4hep_ptr entry(new StackEntry(elt->first,placement,val,ovl)); stack->insert(entry); - pair vol_param(elt->first,subpath); + std::pair vol_param(elt->first,subpath); xml_coll_t(e,_U(volume)).for_each(Converter(description,&vol_param)); } @@ -135,10 +133,10 @@ template <> void Converter::operator()(xml_h e) const { * @version 1.0 * @date 01/04/2014 */ -template <> void Converter::operator()(xml_h e) const { +template <> void dd4hep::Converter::operator()(xml_h e) const { DetElement det(_param()); GlobalAlignmentStack* stack = _option(); - string path = e.attr(_ALU(path)); + std::string path = e.attr(_ALU(path)); bool check = e.hasAttr(_ALU(check_overlaps)); bool check_val = check ? e.attr(_ALU(check_overlaps)) : false; bool reset = e.hasAttr(_ALU(reset)) ? e.attr(_ALU(reset)) : false; @@ -146,11 +144,11 @@ template <> void Converter::operator()(xml_h e) const { bool overlap = e.hasAttr(_ALU(overlap)); double ovl = overlap ? e.attr(_ALU(overlap)) : 0.001; DetElement elt = detail::tools::findDaughterElement(det,path); - string placement = elt.isValid() ? elt.placementPath() : string("-----"); + std::string placement = elt.isValid() ? elt.placementPath() : std::string("-----"); if ( !elt.isValid() ) { - string err = "dd4hep: DetElement "+det.path()+" has no child:"+path+" [No such child]"; - throw runtime_error(err); + except("GlocalAlignmentParser", + "dd4hep: DetElement %s has no child: %s [No such child]", det.path().c_str(), path.c_str()); } Delta delta; @@ -165,7 +163,8 @@ template <> void Converter::operator()(xml_h e) const { if ( reset_dau ) delta.flags |= GlobalAlignmentStack::RESET_CHILDREN; if ( check_val ) delta.flags |= GlobalAlignmentStack::CHECKOVL_VALUE; - printout(INFO,"Alignment","path:%s [%s] placement:%s matrix:%s reset:%s children:%s", + printout(INFO, + "Alignment","path:%s [%s] placement:%s matrix:%s reset:%s children:%s", path.c_str(), elt.isValid() ? elt.path().c_str() : "-----", placement.c_str(), @@ -175,7 +174,7 @@ template <> void Converter::operator()(xml_h e) const { dd4hep_ptr entry(new StackEntry(elt,placement,delta,ovl)); stack->insert(entry); - pair vol_param(elt,""); + std::pair vol_param(elt,""); xml_coll_t(e,_U(volume)).for_each(Converter(description,&vol_param,optional)); xml_coll_t(e,_ALU(detelement)).for_each(Converter(description,elt.ptr(),optional)); xml_coll_t(e,_U(include)).for_each(Converter(description,elt.ptr(),optional)); @@ -192,10 +191,10 @@ template <> void Converter::operator()(xml_h e) const { * @version 1.0 * @date 01/04/2014 */ -template <> void Converter::operator()(xml_h element) const { +template <> void dd4hep::Converter::operator()(xml_h element) const { xml::DocumentHolder doc(xml::DocumentHandler().load(element, element.attr_value(_U(ref)))); xml_h node = doc.root(); - string tag = node.tag(); + std::string tag = node.tag(); if ( tag == "alignment" ) Converter(description,param,optional)(node); else if ( tag == "global_alignment" ) @@ -205,7 +204,7 @@ template <> void Converter::operator()(xml_h element) const { else if ( tag == "subdetectors" || tag == "detelements" ) xml_coll_t(node,_ALU(detelements)).for_each(Converter(description,param,optional)); else - throw runtime_error("Undefined tag name in XML structure:"+tag+" XML parsing abandoned."); + except("GlocalAlignmentParser", "Undefined tag name in XML structure: %s XML parsing abandoned.", tag.c_str()); } /** Convert alignment objects @@ -220,7 +219,7 @@ template <> void Converter::operator()(xml_h element) const { * @version 1.0 * @date 01/04/2014 */ -template <> void Converter::operator()(xml_h e) const { +template <> void dd4hep::Converter::operator()(xml_h e) const { /// Now we process all allowed elements within the alignment tag: /// , , and xml_coll_t(e,_ALU(debug)).for_each(Converter(description,param,optional)); @@ -236,9 +235,9 @@ template <> void Converter::operator()(xml_h e) const { * @version 1.0 * @date 01/04/2014 */ -static long setup_Alignment(Detector& description, const xml_h& e) { - static dd4hep_mutex_t s_mutex; - dd4hep_lock_t lock(s_mutex); +long dd4hep::setup_Alignment(dd4hep::Detector& description, const xml_h& e) { + static dd4hep::dd4hep_mutex_t s_mutex; + dd4hep::dd4hep_lock_t lock(s_mutex); bool open_trans = e.hasChild(_ALU(open_transaction)); bool close_trans = e.hasChild(_ALU(close_transaction)); @@ -251,8 +250,10 @@ static long setup_Alignment(Detector& description, const xml_h& e) { GlobalAlignmentStack::create(); } if ( !GlobalAlignmentStack::exists() ) { - printout(ERROR,"GlobalAlignment","Request process global alignments without cache."); - printout(ERROR,"GlobalAlignment","Call plugin DD4hep_GlobalAlignmentInstall first OR add XML tag "); + printout(ERROR,"GlobalAlignment", + "Request process global alignments without cache."); + printout(ERROR,"GlobalAlignment", + "Call plugin DD4hep_GlobalAlignmentInstall first OR add XML tag "); except("GlobalAlignment","Request process global alignments without cache."); } GlobalAlignmentStack& stack = GlobalAlignmentStack::get(); @@ -277,7 +278,7 @@ DECLARE_XML_DOC_READER(global_alignment,setup_Alignment) * @version 1.0 * @date 01/04/2014 */ -static long install_Alignment(Detector& description, int, char**) { +static long install_Alignment(dd4hep::Detector& description, int, char**) { GlobalAlignmentCache::install(description); return 1; } diff --git a/DDCAD/src/ASSIMPWriter.cpp b/DDCAD/src/ASSIMPWriter.cpp index f468c63e0..b3440f3a2 100644 --- a/DDCAD/src/ASSIMPWriter.cpp +++ b/DDCAD/src/ASSIMPWriter.cpp @@ -33,27 +33,25 @@ /// C/C++ include files #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::cad; using Vertex = Tessellated::Vertex_t; namespace { - void _collect(std::vector >& cont, - bool recursive, const TGeoHMatrix& to_global, PlacedVolume pv) + void _collect(std::vector >& cont, + bool recursive, const TGeoHMatrix& to_global, dd4hep::PlacedVolume pv) { - Volume v = pv.volume(); + dd4hep::Volume v = pv.volume(); for(Int_t i=0; iGetNdaughters(); ++i) { - PlacedVolume p = v->GetNode(i); - Solid sol = p.volume().solid(); - bool use = sol->IsA() != TGeoShapeAssembly::Class(); - unique_ptr mother(new TGeoHMatrix(to_global)); + dd4hep::PlacedVolume p = v->GetNode(i); + dd4hep::Solid sol = p.volume().solid(); + bool use = sol->IsA() != TGeoShapeAssembly::Class(); + std::unique_ptr mother(new TGeoHMatrix(to_global)); mother->Multiply(p->GetMatrix()); if ( use ) - cont.push_back(make_pair(p, mother.get())); + cont.push_back(std::make_pair(p, mother.get())); if ( recursive ) _collect(cont, recursive, *mother, p); if ( use ) @@ -63,8 +61,8 @@ namespace { bool equals(Vertex const &lhs, Vertex const &rhs) { constexpr double kTolerance = 1.e-32; return TMath::Abs(lhs[0] - rhs[0]) < kTolerance && - TMath::Abs(lhs[1] - rhs[1]) < kTolerance && - TMath::Abs(lhs[2] - rhs[2]) < kTolerance; + TMath::Abs(lhs[1] - rhs[1]) < kTolerance && + TMath::Abs(lhs[2] - rhs[2]) < kTolerance; } struct TessellateShape { @@ -73,42 +71,46 @@ namespace { virtual ~TessellateShape() = default; RootCsg::TBaseMesh* make_mesh(TGeoShape* sh) const; RootCsg::TBaseMesh* collect_composite(TGeoCompositeShape* sh) const; - unique_ptr build_mesh(int id, const std::string& name, TGeoShape* shape); - unique_ptr tessellate_primitive(const std::string& name, Solid solid); - unique_ptr close_tessellated(int id, TGeoShape* shape, int nskip, unique_ptr&& tes); + std::unique_ptr build_mesh(int id, const std::string& name, TGeoShape* shape); + std::unique_ptr tessellate_primitive(const std::string& name, dd4hep::Solid solid); + std::unique_ptr close_tessellated(int id, TGeoShape* shape, int nskip, std::unique_ptr&& tes); }; - unique_ptr TessellateShape::close_tessellated(int id, TGeoShape* shape, int nskip, unique_ptr&& tes) { - string nam = shape->GetName(), typ = "["+string(shape->IsA()->GetName())+"]"; + std::unique_ptr + TessellateShape::close_tessellated(int id, TGeoShape* shape, int nskip, std::unique_ptr&& tes) { + std::string nam = shape->GetName(), typ = "["+std::string(shape->IsA()->GetName())+"]"; nam = nam.substr(0, nam.find("_0x")); tes->CloseShape(true, true, true); if ( nskip > 0 ) { - printout(ALWAYS,"ASSIMPWriter","+++ %3d %-48s %-24s Skipped %3ld/%-4d degenerate facets %4d vertices closed:%s defined:%s", - id, nam.c_str(), typ.c_str(), nskip, tes->GetNfacets(), tes->GetNvertices(), - yes_no(tes->IsClosedBody()), yes_no(tes->IsDefined())); + dd4hep::printout(dd4hep::ALWAYS, + "ASSIMPWriter","+++ %3d %-48s %-24s Skipped %3ld/%-4d degenerate facets %4d vertices closed:%s defined:%s", + id, nam.c_str(), typ.c_str(), nskip, tes->GetNfacets(), tes->GetNvertices(), + dd4hep::yes_no(tes->IsClosedBody()), dd4hep::yes_no(tes->IsDefined())); } else { - printout(ALWAYS,"ASSIMPWriter","+++ %3d %-48s %-24s Tessellated %4d facets %4d vertices closed:%s defined:%s", - id, nam.c_str(), typ.c_str(), - tes->GetNfacets(), tes->GetNvertices(), - yes_no(tes->IsClosedBody()), - yes_no(tes->IsDefined())); + dd4hep::printout(dd4hep::ALWAYS, + "ASSIMPWriter","+++ %3d %-48s %-24s Tessellated %4d facets %4d vertices closed:%s defined:%s", + id, nam.c_str(), typ.c_str(), + tes->GetNfacets(), tes->GetNvertices(), + dd4hep::yes_no(tes->IsClosedBody()), + dd4hep::yes_no(tes->IsDefined())); } - cout << flush; + std::cout << std::flush; return move(tes); } - unique_ptr TessellateShape::build_mesh(int id, const std::string& name, TGeoShape* shape) { - auto mesh = unique_ptr(this->make_mesh(shape)); - size_t nskip = 0; - vector vertices; + std::unique_ptr TessellateShape::build_mesh(int id, const std::string& name, TGeoShape* shape) { + auto mesh = std::unique_ptr(this->make_mesh(shape)); + std::vector vertices; + std::size_t nskip = 0; + vertices.reserve(mesh->NumberOfVertices()); - map vtx_index_replacements; + std::map vtx_index_replacements; for( size_t ipoint = 0, npoints = mesh->NumberOfVertices(); ipoint < npoints; ++ipoint ) { long found = -1; const double* v = mesh->GetVertex(ipoint); Vertex vtx(v[0], v[1], v[2]); - for(size_t i=0; i < vertices.size(); ++i) { + for(std::size_t i=0; i < vertices.size(); ++i) { if ( equals(vertices[i],vtx) ) { vtx_index_replacements[ipoint] = found = i; break; @@ -119,12 +121,12 @@ namespace { vertices.emplace_back(v[0], v[1], v[2]); } } - size_t vtx_len = vertices.size(); - unique_ptr tes = make_unique(name.c_str(), vertices); - for( size_t ipoly = 0, npols = mesh->NumberOfPolys(); ipoly < npols; ++ipoly) { - size_t npoints = mesh->SizeOfPoly(ipoly); + std::size_t vtx_len = vertices.size(); + std::unique_ptr tes = std::make_unique(name.c_str(), vertices); + for( std::size_t ipoly = 0, npols = mesh->NumberOfPolys(); ipoly < npols; ++ipoly) { + std::size_t npoints = mesh->SizeOfPoly(ipoly); if ( npoints >= 3 ) { - printout(DEBUG,"ASSIMPWriter","+++ Got polygon with %ld points",npoints); + printout(dd4hep::DEBUG,"ASSIMPWriter","+++ Got polygon with %ld points",npoints); /// /// 3-vertex polygons automatically translate to GL_TRIANGLES /// See Kronos documentation to glBegin / glEnd from the glu library: @@ -138,13 +140,13 @@ namespace { /// One triangle is defined for each vertex presented after the first two vertices. /// Vertices 1 , n + 1 , and n + 2 define triangle n. /// N - 2 triangles are drawn. - size_t v0 = mesh->GetVertexIndex(ipoly, 0); - size_t vv0 = vtx_index_replacements[v0]; - for( size_t ipoint = 0; ipoint < npoints-2; ++ipoint ) { - size_t v1 = mesh->GetVertexIndex(ipoly, ipoint+1); - size_t v2 = mesh->GetVertexIndex(ipoly, ipoint+2); - size_t vv1 = vtx_index_replacements[v1]; - size_t vv2 = vtx_index_replacements[v2]; + std::size_t v0 = mesh->GetVertexIndex(ipoly, 0); + std::size_t vv0 = vtx_index_replacements[v0]; + for( std::size_t ipoint = 0; ipoint < npoints-2; ++ipoint ) { + std::size_t v1 = mesh->GetVertexIndex(ipoly, ipoint+1); + std::size_t v2 = mesh->GetVertexIndex(ipoly, ipoint+2); + std::size_t vv1 = vtx_index_replacements[v1]; + std::size_t vv2 = vtx_index_replacements[v2]; if ( vv0 > vtx_len || vv1 > vtx_len || vv2 > vtx_len ) { ++nskip; continue; @@ -177,7 +179,7 @@ namespace { /// For odd n, vertices n, n + 1 , and n + 2 define triangle n. /// For even n, vertices n + 1 , n, and n + 2 define triangle n. /// N - 2 triangles are drawn. - for( size_t ipoint = 0; ipoint < npoints-2; ++ipoint ) { + for( std::size_t ipoint = 0; ipoint < npoints-2; ++ipoint ) { vtx_t v0(mesh->GetVertex(mesh->GetVertexIndex(ipoly, ipoint))); vtx_t v1(mesh->GetVertex(mesh->GetVertexIndex(ipoly, ipoint+1))); vtx_t v2(mesh->GetVertex(mesh->GetVertexIndex(ipoly, ipoint+2))); @@ -209,11 +211,11 @@ namespace { // Do not wonder about this logic. // GetBuffer3D (->make_mesh) uses static variable fgTransform of TGeoShape! glmat->Multiply(node->GetLeftMatrix()); - auto left_mesh = unique_ptr(make_mesh(left)); + auto left_mesh = std::unique_ptr(make_mesh(left)); *glmat = © glmat->Multiply(node->GetRightMatrix()); - auto right_mesh = unique_ptr(make_mesh(right)); + auto right_mesh = std::unique_ptr(make_mesh(right)); *glmat = © switch (oper) { @@ -229,14 +231,14 @@ namespace { } } - unique_ptr TessellateShape::tessellate_primitive(const std::string& name, Solid solid) { + std::unique_ptr TessellateShape::tessellate_primitive(const std::string& name, dd4hep::Solid solid) { using vtx_t = Vertex; const TBuffer3D& buf3D = solid->GetBuffer3D(TBuffer3D::kAll, false); struct pol_t { int c, n; int segs[1]; } *pol = nullptr; struct seg_t { int c, _1, _2; }; const seg_t* segs = (seg_t*)buf3D.fSegs; const vtx_t* vtcs = (vtx_t*)buf3D.fPnts; - size_t i, num_facet = 0; + std::size_t i, num_facet = 0; const Int_t* q; for( i=0, q=buf3D.fPols; in)) { @@ -244,7 +246,7 @@ namespace { for( int j=0; j < pol->n-1; ++j ) num_facet += 2; } - unique_ptr tes = make_unique(name.c_str(), num_facet); + std::unique_ptr tes = std::make_unique(name.c_str(), num_facet); q = buf3D.fPols; for( i=0, q=buf3D.fPols; i > placements; int build_mode = ((flags&0x1) != 0) ? 1 : 0; bool dump_facets = ((flags&0x2) != 0); - vector materials; - TGeoHMatrix toGlobal; + std::vector materials; + TGeoHMatrix toGlobal; for( auto pv : places ) _collect(placements, recursive, toGlobal, pv); - size_t num_mesh = placements.size(); + std::size_t num_mesh = placements.size(); aiScene scene; scene.mNumMaterials = 0; @@ -316,9 +318,9 @@ int ASSIMPWriter::write(const std::string& file_name, auto* geo_transform = TGeoShape::GetTransform(); TGeoHMatrix identity; - for( size_t imesh=0; imesh < num_mesh; ++imesh ) { - unique_ptr trafo(placements[imesh].second); - unique_ptr shape_holder; + for( std::size_t imesh=0; imesh < num_mesh; ++imesh ) { + std::unique_ptr trafo(placements[imesh].second); + std::unique_ptr shape_holder; PlacedVolume pv = placements[imesh].first; Volume vol = pv.volume(); Solid sol = vol.solid(); @@ -348,12 +350,12 @@ int ASSIMPWriter::write(const std::string& file_name, continue; } - size_t num_vert = 0; + std::size_t num_vert = 0; for( long j=0, n=tes->GetNfacets(); j < n; ++j ) num_vert += tes->GetFacet(j).GetNvert(); - size_t index = std::numeric_limits::max(); - for( size_t j=0; j::max(); + for( std::size_t j=0; j -using namespace std; -using namespace dd4hep; -using namespace dd4hep::detail; +using dd4hep::except; +using dd4hep::printout; /// If the path to the CAD file does not directly exist try to resolve it: -static string resolve_path(xml_h e, const string& file) { - error_code errc; +static std::string resolve_path(xml_h e, const std::string& file) { + std::error_code errc; std::string fname; /// Use the xml utilities in the DocumentHandler to resolve the relative path if ( file.length() > 7 && file.substr(0,7) == "file://" ) fname = file.substr(7); else fname = file; - if ( !filesystem::exists(fname, errc) ) { - string fn = xml::DocumentHandler::system_path(e, fname); + if ( !std::filesystem::exists(fname, errc) ) { + std::string fn = dd4hep::xml::DocumentHandler::system_path(e, fname); if ( fn.length() > 7 && fn.substr(0,7) == "file://" ) fn = fn.substr(7); if ( !std::filesystem::exists(fn, errc) ) { - auto fp = filesystem::path(xml::DocumentHandler::system_path(e)).parent_path(); + auto fp = std::filesystem::path(dd4hep::xml::DocumentHandler::system_path(e)).parent_path(); except("CAD_Shape","+++ CAD file: %s (= %s + %s) is not accessible [%d: %s]", fn.c_str(), fp.c_str(), fname.c_str(), errc.value(), errc.message().c_str()); @@ -50,8 +49,8 @@ static string resolve_path(xml_h e, const string& file) { return fname; } -static void* read_CAD_Volume(Detector& dsc, int argc, char** argv) { - string fname; +static void* read_CAD_Volume(dd4hep::Detector& dsc, int argc, char** argv) { + std::string fname; double scale = 1.0; bool help = false; for(int i = 0; i < argc && argv[i]; ++i) { @@ -64,16 +63,16 @@ static void* read_CAD_Volume(Detector& dsc, int argc, char** argv) { } if ( fname.empty() || help ) { - cout << + std::cout << "Usage: -plugin DD4hep_CAD_export -arg [-arg] \n\n" " -input Input file name. \n" " -scale Scale factor when importing shapes. \n" " -help Print this help output. \n" - " Arguments given: " << arguments(argc,argv) << endl << flush; + " Arguments given: " << dd4hep::arguments(argc,argv) << std::endl << std::flush; ::exit(EINVAL); } - auto volumes = cad::ASSIMPReader(dsc).readVolumes(fname, scale); + auto volumes = dd4hep::cad::ASSIMPReader(dsc).readVolumes(fname, scale); if ( volumes.empty() ) { except("CAD_Volume","+++ CAD file: %s does not contain any " "understandable tessellated volumes.", fname.c_str()); @@ -83,12 +82,12 @@ static void* read_CAD_Volume(Detector& dsc, int argc, char** argv) { } DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_read_CAD_volumes,read_CAD_Volume) -static Handle create_CAD_Shape(Detector& dsc, xml_h e) { +static dd4hep::Handle create_CAD_Shape(dd4hep::Detector& dsc, xml_h e) { xml_elt_t elt(e); - cad::ASSIMPReader rdr(dsc); - string fname = resolve_path(e, elt.attr(_U(ref))); - long flags = elt.hasAttr(_U(flags)) ? elt.attr(_U(flags)) : 0; - double unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : dd4hep::cm; + dd4hep::cad::ASSIMPReader rdr(dsc); + std::string fname = resolve_path(e, elt.attr(_U(ref))); + long flags = elt.hasAttr(_U(flags)) ? elt.attr(_U(flags)) : 0; + double unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : dd4hep::cm; if ( flags ) rdr.flags = flags; auto shapes = rdr.readShapes(fname, unit); @@ -96,18 +95,18 @@ static Handle create_CAD_Shape(Detector& dsc, xml_h e) { except("CAD_Shape","+++ CAD file: %s does not contain any " "understandable tessellated shapes.", fname.c_str()); } - Solid solid; - size_t count = shapes.size(); + dd4hep::Solid solid; + std::size_t count = shapes.size(); if ( count == 1 ) { solid = shapes[0].release(); } else { if ( elt.hasAttr(_U(item)) ) { - size_t which = elt.attr(_U(item)); + std::size_t which = elt.attr(_U(item)); solid = shapes[which].release(); } else if ( elt.hasAttr(_U(mesh)) ) { - size_t which = elt.attr(_U(mesh)); + std::size_t which = elt.attr(_U(mesh)); solid = shapes[which].release(); } else { @@ -115,25 +114,25 @@ static Handle create_CAD_Shape(Detector& dsc, xml_h e) { "You need to add a selector.", fname.c_str(), shapes.size()); } } - if ( elt.hasAttr(_U(name)) ) solid->SetName(elt.attr(_U(name)).c_str()); + if ( elt.hasAttr(_U(name)) ) solid->SetName(elt.attr(_U(name)).c_str()); return solid; } DECLARE_XML_SHAPE(CAD_Shape__shape_constructor,create_CAD_Shape) -static Handle create_CAD_Assembly(Detector& dsc, xml_h e) { - xml_elt_t elt(e); - string fname = resolve_path(e, elt.attr(_U(ref))); - double unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : dd4hep::cm; - auto volumes = cad::ASSIMPReader(dsc).readVolumes(fname, unit); +static dd4hep::Handle create_CAD_Assembly(dd4hep::Detector& dsc, xml_h e) { + xml_elt_t elt(e); + std::string fname = resolve_path(e, elt.attr(_U(ref))); + double unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : dd4hep::cm; + auto volumes = dd4hep::cad::ASSIMPReader(dsc).readVolumes(fname, unit); if ( volumes.empty() ) { except("CAD_Shape","+++ CAD file: %s does not contain any " "understandable tessellated volumes.", fname.c_str()); } - Assembly assembly("assembly"); - for(size_t i=0; i < volumes.size(); ++i) + dd4hep::Assembly assembly("assembly"); + for(std::size_t i=0; i < volumes.size(); ++i) assembly.placeVolume(volumes[i].release()); - if ( elt.hasAttr(_U(name)) ) assembly->SetName(elt.attr(_U(name)).c_str()); + if ( elt.hasAttr(_U(name)) ) assembly->SetName(elt.attr(_U(name)).c_str()); return assembly; } DECLARE_XML_VOLUME(CAD_Assembly__volume_constructor,create_CAD_Assembly) @@ -182,12 +181,12 @@ DECLARE_XML_VOLUME(CAD_Assembly__volume_constructor,create_CAD_Assembly) * * */ -static Handle create_CAD_Volume(Detector& dsc, xml_h e) { - xml_elt_t elt(e); - double unit = elt.attr(_U(unit)); - string fname = resolve_path(e, elt.attr(_U(ref))); - long flags = elt.hasAttr(_U(flags)) ? elt.attr(_U(flags)) : 0; - cad::ASSIMPReader rdr(dsc); +static dd4hep::Handle create_CAD_Volume(dd4hep::Detector& dsc, xml_h e) { + xml_elt_t elt(e); + double unit = elt.attr(_U(unit)); + std::string fname = resolve_path(e, elt.attr(_U(ref))); + long flags = elt.hasAttr(_U(flags)) ? elt.attr(_U(flags)) : 0; + dd4hep::cad::ASSIMPReader rdr(dsc); if ( flags ) rdr.flags = flags; auto volumes = rdr.readVolumes(fname, unit); @@ -195,47 +194,46 @@ static Handle create_CAD_Volume(Detector& dsc, xml_h e) { except("CAD_Volume","+++ CAD file: %s does not contain any " "understandable tessellated volumes.", fname.c_str()); } - Volume envelope; + dd4hep::Volume envelope; if ( elt.hasChild(_U(envelope)) ) { - string typ = "DD4hep_StdVolume"; + std::string typ = "DD4hep_StdVolume"; xml_h x_env = elt.child(_U(envelope)); - TObject* pvol = PluginService::Create(typ, &dsc, &x_env); + TObject* pvol = dd4hep::PluginService::Create(typ, &dsc, &x_env); envelope = dynamic_cast(pvol); if ( !envelope.isValid() ) { - except("CAD_Volume", - "+++ Unable to determine envelope to CAD shape: %s",fname.c_str()); + except("CAD_Volume", "+++ Unable to determine envelope to CAD shape: %s",fname.c_str()); } } else { - envelope = Assembly("envelope"); + envelope = dd4hep::Assembly("envelope"); } xml_dim_t x_envpos = elt.child(_U(position),false); xml_dim_t x_envrot = elt.child(_U(rotation),false); - Position env_pos; - RotationZYX env_rot; + dd4hep::Position env_pos; + dd4hep::RotationZYX env_rot; if ( x_envpos && x_envrot ) { - env_rot = RotationZYX(x_envrot.z(0), x_envrot.y(0), x_envrot.x(0)); - env_pos = Position(x_envpos.x(0), x_envpos.y(0), x_envpos.z(0)); + env_rot = dd4hep::RotationZYX(x_envrot.z(0), x_envrot.y(0), x_envrot.x(0)); + env_pos = dd4hep::Position(x_envpos.x(0), x_envpos.y(0), x_envpos.z(0)); } else if ( x_envpos ) - env_pos = Position(x_envpos.x(0), x_envpos.y(0), x_envpos.z(0)); + env_pos = dd4hep::Position(x_envpos.x(0), x_envpos.y(0), x_envpos.z(0)); else if ( x_envrot ) - env_rot = RotationZYX(x_envrot.z(0), x_envrot.y(0), x_envrot.x(0)); + env_rot = dd4hep::RotationZYX(x_envrot.z(0), x_envrot.y(0), x_envrot.x(0)); - Transform3D env_trafo(env_rot, env_pos); - Material default_material; + dd4hep::Transform3D env_trafo(env_rot, env_pos); + dd4hep::Material default_material; xml_dim_t x_mat = elt.child(_U(material),false); if ( x_mat.ptr() ) default_material = dsc.material(x_mat.nameStr()); - else if ( elt.hasAttr(_U(material)) ) default_material = dsc.material(elt.attr(_U(material))); + else if ( elt.hasAttr(_U(material)) ) default_material = dsc.material(elt.attr(_U(material))); if ( elt.hasChild(_U(volume)) ) { - map volume_map; + std::map volume_map; for (xml_coll_t c(elt,_U(volume)); c; ++c ) volume_map.emplace(xml_dim_t(c).id(),c); - for (size_t i=0; i < volumes.size(); ++i) { - Volume vol = volumes[i].release(); - Material mat = default_material; + for (std::size_t i=0; i < volumes.size(); ++i) { + dd4hep::Volume vol = volumes[i].release(); + dd4hep::Material mat = default_material; auto is = volume_map.find(i); if ( is == volume_map.end() ) { envelope.placeVolume(vol); @@ -246,24 +244,24 @@ static Handle create_CAD_Volume(Detector& dsc, xml_h e) { xml_dim_t x_rot = x_vol.child(_U(rotation),false); if ( x_vol.hasAttr(_U(material)) ) { - string mat_name = x_vol.attr(_U(material)); + std::string mat_name = x_vol.attr(_U(material)); mat = dsc.material(mat_name); if ( !mat.isValid() ) except("CAD_MultiVolume","+++ Failed to access material "+mat_name); vol.setMaterial(mat); } - Position pos; - RotationZYX rot; + dd4hep::Position pos; + dd4hep::RotationZYX rot; if ( x_pos && x_rot ) { - rot = RotationZYX(x_rot.z(0), x_rot.y(0), x_rot.x(0)); - pos = Position(x_pos.x(0), x_pos.y(0), x_pos.z(0)); + rot = dd4hep::RotationZYX(x_rot.z(0), x_rot.y(0), x_rot.x(0)); + pos = dd4hep::Position(x_pos.x(0), x_pos.y(0), x_pos.z(0)); } else if ( x_pos ) - pos = Position(x_pos.x(0), x_pos.y(0), x_pos.z(0)); + pos = dd4hep::Position(x_pos.x(0), x_pos.y(0), x_pos.z(0)); else if ( x_rot ) - rot = RotationZYX(x_rot.z(0), x_rot.y(0), x_rot.x(0)); + rot = dd4hep::RotationZYX(x_rot.z(0), x_rot.y(0), x_rot.x(0)); - PlacedVolume pv = envelope.placeVolume(vol,env_trafo*Transform3D(rot, pos)); + dd4hep::PlacedVolume pv = envelope.placeVolume(vol,env_trafo*dd4hep::Transform3D(rot, pos)); vol.setAttributes(dsc, x_vol.regionStr(), x_vol.limitsStr(), x_vol.visStr()); for (xml_coll_t cc(x_vol,_U(physvolid)); cc; ++cc ) { xml_dim_t vid = cc; @@ -273,8 +271,8 @@ static Handle create_CAD_Volume(Detector& dsc, xml_h e) { } } else { - for(size_t i=0; i < volumes.size(); ++i) { - Volume vol = volumes[i].release(); + for(std::size_t i=0; i < volumes.size(); ++i) { + dd4hep::Volume vol = volumes[i].release(); if ( vol.isValid() ) { if ( (vol.material() == dsc.air()) && default_material.isValid() ) vol.setMaterial(default_material); @@ -282,7 +280,7 @@ static Handle create_CAD_Volume(Detector& dsc, xml_h e) { } } } - if ( elt.hasAttr(_U(name)) ) envelope->SetName(elt.attr(_U(name)).c_str()); + if ( elt.hasAttr(_U(name)) ) envelope->SetName(elt.attr(_U(name)).c_str()); return envelope; } DECLARE_XML_VOLUME(CAD_MultiVolume__volume_constructor,create_CAD_Volume) @@ -291,11 +289,11 @@ DECLARE_XML_VOLUME(CAD_MultiVolume__volume_constructor,create_CAD_Volume) /** * */ -static long CAD_export(Detector& description, int argc, char** argv) { - bool recursive = false, help = false; - string volume, detector, fname, ftype; - double scale = 1.0; - int flags = 0; +static long CAD_export(dd4hep::Detector& description, int argc, char** argv) { + bool recursive = false, help = false; + std::string volume, detector, fname, ftype; + double scale = 1.0; + int flags = 0; for(int i = 0; i < argc && argv[i]; ++i) { if ( 0 == ::strncmp( "-output",argv[i],4) ) fname = argv[++i]; @@ -319,7 +317,7 @@ static long CAD_export(Detector& description, int argc, char** argv) { if ( fname.empty() || ftype.empty() ) help = true; if ( volume.empty() && detector.empty() ) help = true; if ( help ) { - cout << + std::cout << "Usage: -plugin DD4hep_CAD_export -arg [-arg] \n\n" " -output Output file name. \n" " -type Output file type. \n" @@ -329,17 +327,17 @@ static long CAD_export(Detector& description, int argc, char** argv) { " -help Print this help output. \n" " -scale Unit scale before writing output data. \n" " -flags Flagsging helper to pass args -- Experts only. \n" - " Arguments given: " << arguments(argc,argv) << endl << flush; + " Arguments given: " << dd4hep::arguments(argc,argv) << std::endl << std::flush; ::exit(EINVAL); } - PlacedVolume pv; + dd4hep::PlacedVolume pv; if ( !detector.empty() ) { - DetElement elt; + dd4hep::DetElement elt; if ( detector == "/world" ) elt = description.world(); else - elt = detail::tools::findElement(description,detector); + elt = dd4hep::detail::tools::findElement(description,detector); if ( !elt.isValid() ) { except("DD4hep_CAD_export","+++ Invalid DetElement path: %s",detector.c_str()); } @@ -349,17 +347,18 @@ static long CAD_export(Detector& description, int argc, char** argv) { pv = elt.placement(); } else if ( !volume.empty() ) { - pv = detail::tools::findNode(description.world().placement(), volume); + pv = dd4hep::detail::tools::findNode(description.world().placement(), volume); if ( !pv.isValid() ) { except("DD4hep_CAD_export","+++ Invalid placement path: %s",volume.c_str()); } } - cad::ASSIMPWriter wr(description); + dd4hep::cad::ASSIMPWriter wr(description); if ( flags ) wr.flags = flags; - std::vector places {pv}; + std::vector places {pv}; auto num_mesh = wr.write(fname, ftype, places, recursive, scale); if ( num_mesh < 0 ) { - printout(ERROR, "DD4hep_CAD_export","+++ Failed to export shapes to CAD file: %s [%s]", + printout(dd4hep::ERROR, "DD4hep_CAD_export", + "+++ Failed to export shapes to CAD file: %s [%s]", fname.c_str(), ftype.c_str()); } return 1; diff --git a/DDCond/src/ConditionsContent.cpp b/DDCond/src/ConditionsContent.cpp index a5f414599..b7fbabae9 100644 --- a/DDCond/src/ConditionsContent.cpp +++ b/DDCond/src/ConditionsContent.cpp @@ -12,12 +12,10 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsContent.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/Printout.h" +#include +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; /// Default constructor @@ -95,16 +93,16 @@ bool ConditionsContent::remove(Condition::key_type hash) { return false; } -pair +std::pair ConditionsContent::insertKey(Condition::key_type hash) { auto ret = m_conditions.emplace(hash,(ConditionsLoadInfo*)0); //printout(DEBUG,"ConditionsContent","++ Insert key: %016X",hash); - if ( ret.second ) return pair(hash,0); - return pair(0,0); + if ( ret.second ) return { hash, 0 }; + return { 0,0 }; } /// Add a new conditions key. T must inherit from class ConditionsContent::Info -pair +std::pair ConditionsContent::addLocationInfo(Condition::key_type hash, ConditionsLoadInfo* info) { if ( info ) { //printout(DEBUG,"ConditionsContent","++ Add location key: %016X",hash); @@ -115,11 +113,11 @@ ConditionsContent::addLocationInfo(Condition::key_type hash, ConditionsLoadInfo* } info->release(); } - return pair(0,0); + return { 0,0 }; } /// Add a new shared conditions dependency -pair +std::pair ConditionsContent::addDependency(ConditionDependency* dep) { auto ret = m_derived.emplace(dep->key(),dep); @@ -139,11 +137,11 @@ ConditionsContent::addDependency(ConditionDependency* dep) except("DeConditionsRequests", "++ Dependency already exists: %s [%08X] [%016llX]", path, maker.values.item_key, maker.hash); - return pair(0,0); + return std::pair(0,0); } /// Add a new conditions dependency (Built internally from arguments) -std::pair +std::pair ConditionsContent::addDependency(DetElement de, Condition::itemkey_type item, std::shared_ptr callback) diff --git a/DDCond/src/ConditionsDependencyHandler.cpp b/DDCond/src/ConditionsDependencyHandler.cpp index e69b3558f..29fd5c2ab 100644 --- a/DDCond/src/ConditionsDependencyHandler.cpp +++ b/DDCond/src/ConditionsDependencyHandler.cpp @@ -12,13 +12,12 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsDependencyHandler.h" -#include "DDCond/ConditionsManagerObject.h" -#include "DD4hep/ConditionsProcessor.h" -#include "DD4hep/Printout.h" -#include "TTimeStamp.h" +#include +#include +#include +#include +#include -using namespace dd4hep; using namespace dd4hep::cond; namespace { @@ -46,7 +45,8 @@ void ConditionsDependencyHandler::Work::do_intersection(const IOV* iov_ptr) { } } -Condition ConditionsDependencyHandler::Work::resolve(Work*& current) { +dd4hep::Condition +ConditionsDependencyHandler::Work::resolve(Work*& current) { Work* previous = current; current = this; state = RESOLVED; @@ -86,7 +86,7 @@ ConditionsDependencyHandler::~ConditionsDependencyHandler() { } /// ConditionResolver implementation: Access to the detector description instance -Detector& ConditionsDependencyHandler::detectorDescription() const { +dd4hep::Detector& ConditionsDependencyHandler::detectorDescription() const { return m_manager->detectorDescription(); } @@ -164,17 +164,20 @@ bool ConditionsDependencyHandler::registerOne(const IOV& iov, Condition cond) } /// Handle multi-condition inserts by callbacks: block insertions of conditions with identical IOV -size_t ConditionsDependencyHandler::registerMany(const IOV& iov, const std::vector& values) { +std::size_t +ConditionsDependencyHandler::registerMany(const IOV& iov, const std::vector& values) { return m_pool.registerMany(iov, values); } /// Interface to access conditions by hash value of the DetElement (only valid at resolve!) -std::vector ConditionsDependencyHandler::get(DetElement de) { +std::vector +ConditionsDependencyHandler::get(DetElement de) { return this->get(de.key()); } /// Interface to access conditions by hash value of the item (only valid at resolve!) -std::vector ConditionsDependencyHandler::getByItem(Condition::itemkey_type key) { +std::vector +ConditionsDependencyHandler::getByItem(Condition::itemkey_type key) { if ( m_state == RESOLVED ) { struct item_selector { std::vector conditions; @@ -197,7 +200,8 @@ std::vector ConditionsDependencyHandler::getByItem(Condition::itemkey } /// Interface to access conditions by hash value of the DetElement (only valid at resolve!) -std::vector ConditionsDependencyHandler::get(Condition::detkey_type det_key) { +std::vector +ConditionsDependencyHandler::get(Condition::detkey_type det_key) { if ( m_state == RESOLVED ) { ConditionKey::KeyMaker lower(det_key, Condition::FIRST_ITEM_KEY); ConditionKey::KeyMaker upper(det_key, Condition::LAST_ITEM_KEY); @@ -211,14 +215,16 @@ std::vector ConditionsDependencyHandler::get(Condition::detkey_type d } /// ConditionResolver implementation: Interface to access conditions -Condition ConditionsDependencyHandler::get(Condition::key_type key, bool throw_if_not) { +dd4hep::Condition +ConditionsDependencyHandler::get(Condition::key_type key, bool throw_if_not) { return this->get(key, nullptr, throw_if_not); } /// ConditionResolver implementation: Interface to access conditions -Condition ConditionsDependencyHandler::get(Condition::key_type key, - const ConditionDependency* dependency, - bool throw_if_not) +dd4hep::Condition +ConditionsDependencyHandler::get(Condition::key_type key, + const ConditionDependency* dependency, + bool throw_if_not) { /// If we are not already resolving here, we follow the normal procedure Condition c = m_pool.get(key); @@ -324,14 +330,14 @@ void ConditionsDependencyHandler::do_callback(Work* work) { } else { printout(ERROR,"DependencyHandler", - "+++ Callback handler returned invalid condition. Key:%s %c%s%c", - work->context.dependency->target.toString().c_str(), + "+++ Callback handler returned invalid condition. Key:%s %c%s%c", + work->context.dependency->target.toString().c_str(), #if defined(DD4HEP_CONDITIONS_DEBUG) - '[',work->context.dependency->detector.path().c_str(),']' + '[',work->context.dependency->detector.path().c_str(),']' #else - ' ',"",' ' + ' ',"",' ' #endif - ); + ); throw std::runtime_error("Invalid derived condition callback"); } return; diff --git a/DDCond/src/ConditionsIOVPool.cpp b/DDCond/src/ConditionsIOVPool.cpp index 823a94ed5..23d188a67 100644 --- a/DDCond/src/ConditionsIOVPool.cpp +++ b/DDCond/src/ConditionsIOVPool.cpp @@ -12,15 +12,14 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsCleanup.h" -#include "DDCond/ConditionsDataLoader.h" +#include +#include +#include +#include +#include -#include "DD4hep/detail/ConditionsInterna.h" +#include -using namespace dd4hep; using namespace dd4hep::cond; /// Default constructor diff --git a/DDCond/src/ConditionsManager.cpp b/DDCond/src/ConditionsManager.cpp index d96700c28..81217e816 100644 --- a/DDCond/src/ConditionsManager.cpp +++ b/DDCond/src/ConditionsManager.cpp @@ -12,24 +12,21 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Errors.h" -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/detail/Handle.inl" -#include "DD4hep/PluginCreators.h" - -#include "DD4hep/ConditionsListener.h" -#include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsManagerObject.h" - -using namespace std; -using namespace dd4hep; +#include +#include +#include +#include +#include +#include + +#include +#include +#include + using namespace dd4hep::cond; DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsManagerObject); - /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -94,8 +91,8 @@ void ConditionsManagerObject::onRemove(Condition condition) { } /// Access the used/registered IOV types -const vector ConditionsManagerObject::iovTypesUsed() const { - vector result; +const std::vector ConditionsManagerObject::iovTypesUsed() const { + std::vector result; const auto& types = this->iovTypes(); for ( const auto& i : types ) { if ( i.type != IOVType::UNKNOWN_IOV ) result.emplace_back(&i); @@ -107,15 +104,15 @@ const vector ConditionsManagerObject::iovTypesUsed() const { void ConditionsManagerObject::fromString(const std::string& data, IOV& iov) { size_t id1 = data.find(','); size_t id2 = data.find('#'); - if ( id2 == string::npos ) { + if ( id2 == std::string::npos ) { except("ConditionsManager","+++ Unknown IOV string representation: %s",data.c_str()); } - string iov_name = data.substr(id2+1); + std::string iov_name = data.substr(id2+1); IOV::Key key; int nents = 0; /// Need assignment from long (k1,k2) for compatibility with Apple MAC long k1 = 0, k2 = 0; - if ( id1 != string::npos ) { + if ( id1 != std::string::npos ) { nents = ::sscanf(data.c_str(),"%ld,%ld#",&k1,&k2) == 2 ? 2 : 0; key.second = k2; key.first = k1; @@ -143,7 +140,7 @@ void ConditionsManagerObject::fromString(const std::string& data, IOV& iov) { } /// Register IOV using new string data -ConditionsPool* ConditionsManagerObject::registerIOV(const string& data) { +ConditionsPool* ConditionsManagerObject::registerIOV(const std::string& data) { IOV iov(0); // Convert string to IOV fromString(data, iov); @@ -173,17 +170,17 @@ ConditionsManager& ConditionsManager::initialize() { } /// Access the detector description -Detector& ConditionsManager::detectorDescription() const { +dd4hep::Detector& ConditionsManager::detectorDescription() const { return access()->detectorDescription(); } /// Access to the property manager -PropertyManager& ConditionsManager::properties() const { +dd4hep::PropertyManager& ConditionsManager::properties() const { return access()->properties(); } /// Access to properties -Property& ConditionsManager::operator[](const std::string& property_name) const { +dd4hep::Property& ConditionsManager::operator[](const std::string& property_name) const { return access()->properties().property(property_name); } @@ -193,13 +190,13 @@ ConditionsDataLoader& ConditionsManager::loader() const { } /// Register new IOV type if it does not (yet) exist. -pair -ConditionsManager::registerIOVType(size_t iov_type, const string& iov_name) const { +std::pair +ConditionsManager::registerIOVType(size_t iov_type, const std::string& iov_name) const { return access()->registerIOVType(iov_type, iov_name); } /// Access IOV by its name -const IOVType* ConditionsManager::iovType (const string& iov_name) const { +const dd4hep::IOVType* ConditionsManager::iovType (const std::string& iov_name) const { return access()->iovType(iov_name); } @@ -209,9 +206,9 @@ ConditionsIOVPool* ConditionsManager::iovPool(const IOVType& iov_type) const { } /// Access the used/registered IOV types -const vector ConditionsManager::iovTypesUsed() const { +const std::vector ConditionsManager::iovTypesUsed() const { Object* obj = access(); - vector result; + std::vector result; const auto& types = obj->iovTypes(); result.reserve(types.size()); for(const auto& i : types ) @@ -220,7 +217,7 @@ const vector ConditionsManager::iovTypesUsed() const { } /// Register IOV with type and key -ConditionsPool* ConditionsManager::registerIOV(const string& iov_rep) const { +ConditionsPool* ConditionsManager::registerIOV(const std::string& iov_rep) const { IOV iov(0); Object* o = access(); o->fromString(iov_rep, iov); @@ -244,12 +241,12 @@ ConditionsPool* ConditionsManager::registerIOV(const IOVType& typ, IOV::Key key) } /// Create IOV from string -void ConditionsManager::fromString(const string& iov_str, IOV& iov) const { +void ConditionsManager::fromString(const std::string& iov_str, IOV& iov) const { access()->fromString(iov_str, iov); } /// Register a whole block of conditions with identical IOV. -size_t ConditionsManager::blockRegister(ConditionsPool& pool, const std::vector& cond) const { +std::size_t ConditionsManager::blockRegister(ConditionsPool& pool, const std::vector& cond) const { return access()->blockRegister(pool, cond); } diff --git a/DDCond/src/ConditionsOperators.cpp b/DDCond/src/ConditionsOperators.cpp index d1eeea0a2..11359025e 100644 --- a/DDCond/src/ConditionsOperators.cpp +++ b/DDCond/src/ConditionsOperators.cpp @@ -12,18 +12,16 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/detail/ConditionsInterna.h" -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsOperators.h" +#include +#include +#include +#include +#include +#include // C/C++ include files #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; /// Select all condition from the conditions manager registered at the Detector object diff --git a/DDCond/src/ConditionsPool.cpp b/DDCond/src/ConditionsPool.cpp index 039c33392..bcffef9e8 100644 --- a/DDCond/src/ConditionsPool.cpp +++ b/DDCond/src/ConditionsPool.cpp @@ -12,16 +12,14 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsManagerObject.h" -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/detail/Handle.inl" -#include "DD4hep/ConditionsPrinter.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include +#include +#include +#include +#include -using std::string; -using namespace dd4hep; using namespace dd4hep::cond; DD4HEP_INSTANTIATE_HANDLE_NAMED(UpdatePool); @@ -47,7 +45,7 @@ void ConditionsPool::print() const { } /// Print pool basics -void ConditionsPool::print(const string& opt) const { +void ConditionsPool::print(const std::string& opt) const { printout(INFO,"ConditionsPool","+++ %s Conditions for pool with IOV: %-32s age:%3d [%4d entries]", opt.c_str(), GetName(), age_value, size()); if ( opt == "*" || opt == "ALL" ) { diff --git a/DDCond/src/ConditionsRepository.cpp b/DDCond/src/ConditionsRepository.cpp index 49e2309f6..3ef3695a0 100644 --- a/DDCond/src/ConditionsRepository.cpp +++ b/DDCond/src/ConditionsRepository.cpp @@ -12,14 +12,14 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsRepository.h" -#include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsTags.h" -#include "DD4hep/detail/ConditionsInterna.h" -#include "DD4hep/Printout.h" -#include "XML/DocumentHandler.h" -#include "XML/XMLTags.h" +#include +#include +#include +#include +#include +#include +#include +#include // C/C++ include files #include @@ -28,15 +28,13 @@ #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; -typedef xml::Handle_t xml_h; -typedef xml::Element xml_elt_t; -typedef xml::Document xml_doc_t; -typedef xml::Collection_t xml_coll_t; +typedef dd4hep::xml::Handle_t xml_h; +typedef dd4hep::xml::Element xml_elt_t; +typedef dd4hep::xml::Document xml_doc_t; +typedef dd4hep::xml::Collection_t xml_coll_t; -typedef map AllConditions; +typedef std::map AllConditions; /// Default constructor ConditionsRepository::ConditionsRepository() { @@ -48,7 +46,7 @@ ConditionsRepository::~ConditionsRepository() { namespace { - int createXML(const string& output, const AllConditions& all) { + int createXML(const std::string& output, const AllConditions& all) { const char comment[] = "\n" " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" " ++++ Linear collider detector description Detector in C++ ++++\n" @@ -62,8 +60,8 @@ namespace { xml_elt_t root = doc.root(), cond(0); for( const auto& i : all ) { char text[32]; - Condition c = i.second; - ::snprintf(text,sizeof(text),"0x%16llX",c.key()); + dd4hep::Condition c = i.second; + std::snprintf(text,sizeof(text),"0x%16llX",c.key()); root.append(cond = xml_elt_t(doc, _U(ref))); cond.setAttr(_U(key), text); #if !defined(DD4HEP_MINIMAL_CONDITIONS) @@ -71,7 +69,7 @@ namespace { cond.setAttr(_U(ref), c.address()); #endif } - printout(ALWAYS,"ConditionsRepository","++ Handled %ld conditions.",all.size()); + dd4hep::printout(dd4hep::ALWAYS,"ConditionsRepository","++ Handled %ld conditions.",all.size()); if ( !output.empty() ) { return docH.output(doc, output); } @@ -79,7 +77,7 @@ namespace { } /// Load the repository from file and fill user passed data structory - int readXML(const string& input, ConditionsRepository::Data& data) { + int readXML(const std::string& input, ConditionsRepository::Data& data) { struct Conv { /// Reference to optional user defined parameter ConditionsRepository::Data& data; @@ -87,60 +85,60 @@ namespace { Conv(ConditionsRepository::Data& p) : data(p) {} /// Callback operator to be specialized depending on the element type void operator()(xml_h element) const { - string key = element.attr(_U(key)); - size_t cap = data.capacity(); + std::string key = element.attr(_U(key)); + std::size_t cap = data.capacity(); ConditionsRepository::Entry e; ::sscanf(key.c_str(),"0x%16llX",&e.key); - e.name = element.attr(_U(name)); - e.address = element.attr(_U(ref)); + e.name = element.attr(_U(name)); + e.address = element.attr(_U(ref)); if ( data.size() == cap ) data.reserve(cap+500); data.emplace_back(e); } }; - xml::DocumentHolder doc(xml::DocumentHandler().load(input)); + dd4hep::xml::DocumentHolder doc(dd4hep::xml::DocumentHandler().load(input)); xml_h root = doc.root(); xml_coll_t(root, _U(ref)).for_each(Conv(data)); return 1; } #if defined(DD4HEP_MINIMAL_CONDITIONS) - int createText(const string& output, const AllConditions&, char) + int createText(const std::string& output, const AllConditions&, char) #else - int createText(const string& output, const AllConditions& all, char sep) + int createText(const std::string& output, const AllConditions& all, char sep) #endif { - ofstream out(output); + std::ofstream out(output); #if !defined(DD4HEP_MINIMAL_CONDITIONS) - size_t siz_nam=0, siz_add=0, siz_tot=0; + std::size_t siz_nam=0, siz_add=0, siz_tot=0; char fmt[64], text[2*PATH_MAX+64]; if ( !out.good() ) { - except("ConditionsRepository", - "++ Failed to open output file:%s [errno:%d %s]", - output.c_str(), errno, ::strerror(errno)); + dd4hep::except("ConditionsRepository", + "++ Failed to open output file:%s [errno:%d %s]", + output.c_str(), errno, ::strerror(errno)); } else if ( sep ) { - ::snprintf(fmt,sizeof(fmt),"%%16llX%c%%s%c%%s%c",sep,sep,sep); + std::snprintf(fmt,sizeof(fmt),"%%16llX%c%%s%c%%s%c",sep,sep,sep); } else { for( const auto& i : all ) { - Condition::Object* c = i.second.ptr(); - size_t siz_n = c->name.length(); - size_t siz_a = c->address.length(); + dd4hep::Condition::Object* c = i.second.ptr(); + std::size_t siz_n = c->name.length(); + std::size_t siz_a = c->address.length(); if ( siz_nam < siz_n ) siz_nam = siz_n; if ( siz_add < siz_a ) siz_add = siz_a; if ( siz_tot < (siz_n+siz_a) ) siz_tot = siz_n+siz_a; } siz_tot += 8+2+1; - ::snprintf(fmt,sizeof(fmt),"%%16llX %%-%lds %%-%lds",long(siz_nam),long(siz_add)); + std::snprintf(fmt,sizeof(fmt),"%%16llX %%-%lds %%-%lds",long(siz_nam),long(siz_add)); } out << "dd4hep." << char(sep ? sep : '-') << "." << long(siz_nam) << "." << long(siz_add) - << "." << long(siz_tot) << endl; + << "." << long(siz_tot) << std::endl; for( const auto& i : all ) { - Condition c = i.second; - ::snprintf(text, sizeof(text), fmt, c.key(), c.name(), c.address().c_str()); - out << text << endl; + dd4hep::Condition c = i.second; + std::snprintf(text, sizeof(text), fmt, c.key(), c.name(), c.address().c_str()); + out << text << std::endl; } #endif out.close(); @@ -148,11 +146,11 @@ namespace { } /// Load the repository from file and fill user passed data structory - int readText(const string& input, ConditionsRepository::Data& data) { - size_t idx, siz_nam, siz_add, siz_tot; + int readText(const std::string& input, ConditionsRepository::Data& data) { + std::size_t idx, siz_nam, siz_add, siz_tot; char sep, c, text[2*PATH_MAX]; ConditionsRepository::Entry e; - ifstream in(input); + std::ifstream in(input); in >> c >> c >> c >> c >> c >> c >> c >> sep >> c >> siz_nam @@ -167,34 +165,34 @@ namespace { text[0] = 0; in.getline(text,sizeof(text),'\n'); if ( in.good() ) { - text[sizeof(text)-1] = 0; + text[sizeof(text)-1] = 0; if ( siz_tot ) { - text[8] = 0; + text[8] = 0; // Direct access mode with fixed record size if ( 9+siz_nam < sizeof(text) ) { text[9+siz_nam] = 0; e.name = text+9; - } + } if ( 10+siz_nam+siz_add < (long)sizeof(text) ) { text[10+siz_nam+siz_add] = 0; e.address = text+10+siz_nam; - if ( (idx=e.name.find(' ')) != string::npos && idx < e.name.length() ) + if ( (idx=e.name.find(' ')) != std::string::npos && idx < e.name.length() ) e.name[idx] = 0; - if ( (idx=e.address.find(' ')) != string::npos && idx < e.address.length() ) + if ( (idx=e.address.find(' ')) != std::string::npos && idx < e.address.length() ) e.address[idx] = 0; } else { - except("ConditionsRepository","+++ Invalid record encountered. [Sever error]"); + dd4hep::except("ConditionsRepository","+++ Invalid record encountered. [Sever error]"); } } else { // Variable record size e.name=text+9; - if ( (idx=e.name.find(sep)) != string::npos && idx < sizeof(text)-10 ) + if ( (idx=e.name.find(sep)) != std::string::npos && idx < sizeof(text)-10 ) text[9+idx] = 0, e.address=text+idx+10, e.name=text+9; - if ( (idx=e.address.find(sep)) != string::npos && idx < e.address.length() ) + if ( (idx=e.address.find(sep)) != std::string::npos && idx < e.address.length() ) e.address[idx] = 0; - else if ( (idx=e.address.find('\n')) != string::npos && idx < e.address.length() ) + else if ( (idx=e.address.find('\n')) != std::string::npos && idx < e.address.length() ) e.address[idx] = 0; } size_t cap = data.capacity(); @@ -209,7 +207,7 @@ namespace { } /// Save the repository to file -int ConditionsRepository::save(ConditionsManager manager, const string& output) const { +int ConditionsRepository::save(ConditionsManager manager, const std::string& output) const { AllConditions all; const auto types = manager.iovTypesUsed(); for( const IOVType* type : types ) { @@ -226,19 +224,19 @@ int ConditionsRepository::save(ConditionsManager manager, const string& output) } } - if ( output.find(".xml") != string::npos ) { + if ( output.find(".xml") != std::string::npos ) { /// Write XML file with conditions addresses return createXML(output, all); } - else if ( output.find(".txt") != string::npos ) { + else if ( output.find(".txt") != std::string::npos ) { /// Write fixed records with conditions addresses return createText(output, all, 0); } - else if ( output.find(".daf") != string::npos ) { + else if ( output.find(".daf") != std::string::npos ) { /// Write fixed records with conditions addresses return createText(output, all, 0); } - else if ( output.find(".csv") != string::npos ) { + else if ( output.find(".csv") != std::string::npos ) { /// Write records separated by ';' with conditions addresses return createText(output, all, ';'); } @@ -246,17 +244,17 @@ int ConditionsRepository::save(ConditionsManager manager, const string& output) } /// Load the repository from file and fill user passed data structory -int ConditionsRepository::load(const string& input, Data& data) const { - if ( input.find(".xml") != string::npos ) { +int ConditionsRepository::load(const std::string& input, Data& data) const { + if ( input.find(".xml") != std::string::npos ) { return readXML(input, data); } - else if ( input.find(".txt") != string::npos ) { + else if ( input.find(".txt") != std::string::npos ) { return readText(input, data); } - else if ( input.find(".daf") != string::npos ) { + else if ( input.find(".daf") != std::string::npos ) { return readText(input, data); } - else if ( input.find(".csv") != string::npos ) { + else if ( input.find(".csv") != std::string::npos ) { return readText(input, data); } return 0; diff --git a/DDCond/src/ConditionsRootPersistency.cpp b/DDCond/src/ConditionsRootPersistency.cpp index 28ed62862..f90589058 100644 --- a/DDCond/src/ConditionsRootPersistency.cpp +++ b/DDCond/src/ConditionsRootPersistency.cpp @@ -12,22 +12,19 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DDCond/ConditionsSlice.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsRootPersistency.h" +#include +#include +#include +#include -#include "TFile.h" -#include "TTimeStamp.h" +#include +#include typedef dd4hep::cond::ConditionsRootPersistency __ConditionsRootPersistency; /// ROOT Class implementation directive ClassImp(__ConditionsRootPersistency) - -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; // Local namespace for anonymous stuff @@ -39,12 +36,12 @@ namespace { * \version 1.0 * \ingroup DD4HEP_CONDITIONS */ - struct Scanner : public Condition::Processor { + struct Scanner : public dd4hep::Condition::Processor { ConditionsRootPersistency::pool_type& pool; /// Constructor Scanner(ConditionsRootPersistency::pool_type& p) : pool(p) {} /// Conditions callback for object processing - virtual int process(Condition c) const override { + virtual int process(dd4hep::Condition c) const override { pool.emplace_back(c.ptr()); return 1; } @@ -66,7 +63,7 @@ ConditionsRootPersistency::ConditionsRootPersistency() : TNamed() { } /// Initializing constructor -ConditionsRootPersistency::ConditionsRootPersistency(const string& name, const string& title) +ConditionsRootPersistency::ConditionsRootPersistency(const std::string& name, const std::string& title) : TNamed(name.c_str(), title.c_str()) { } @@ -77,11 +74,12 @@ ConditionsRootPersistency::~ConditionsRootPersistency() { } /// Add conditions content to be saved. Note, that dependent conditions shall not be saved! -size_t ConditionsRootPersistency::add(const std::string& identifier, - const IOV& iov, - std::vector& conditions) { +std::size_t ConditionsRootPersistency::add(const std::string& identifier, + const IOV& iov, + std::vector& conditions) +{ DurationStamp stamp(this); - conditionPools.emplace_back(pair()); + conditionPools.emplace_back(std::pair()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; key.first = identifier; @@ -93,9 +91,9 @@ 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) { +size_t ConditionsRootPersistency::add(const std::string& identifier, ConditionsPool& pool) { DurationStamp stamp(this); - conditionPools.emplace_back(pair()); + conditionPools.emplace_back(std::pair()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; const IOV* iov = pool.iov; @@ -108,11 +106,11 @@ size_t ConditionsRootPersistency::add(const string& identifier, ConditionsPool& } /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! -size_t ConditionsRootPersistency::add(const string& identifier, const ConditionsIOVPool& pool) { +size_t ConditionsRootPersistency::add(const std::string& identifier, const ConditionsIOVPool& pool) { size_t count = 0; DurationStamp stamp(this); for( const auto& p : pool.elements ) { - iovPools.emplace_back(pair()); + iovPools.emplace_back(std::pair()); pool_type& ent = iovPools.back().second; iov_key_type& key = iovPools.back().first; const IOV* iov = p.second->iov; @@ -127,9 +125,9 @@ 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) { +size_t ConditionsRootPersistency::add(const std::string& identifier, const UserPool& pool) { DurationStamp stamp(this); - userPools.emplace_back(pair()); + userPools.emplace_back(std::pair()); pool_type& ent = userPools.back().second; iov_key_type& key = userPools.back().first; const IOV& iov = pool.validity(); @@ -142,7 +140,7 @@ size_t ConditionsRootPersistency::add(const string& identifier, const UserPool& } /// Open ROOT file in read mode -TFile* ConditionsRootPersistency::openFile(const string& fname) { +TFile* ConditionsRootPersistency::openFile(const std::string& fname) { TDirectory::TContext context; TFile* file = TFile::Open(fname.c_str()); if ( file && !file->IsZombie()) return file; @@ -171,7 +169,7 @@ void ConditionsRootPersistency::clear() { /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! std::unique_ptr -ConditionsRootPersistency::load(TFile* file,const string& obj) { +ConditionsRootPersistency::load(TFile* file,const std::string& obj) { std::unique_ptr p; if ( file && !file->IsZombie()) { TTimeStamp start; @@ -304,7 +302,7 @@ int ConditionsRootPersistency::save(TFile* file) { } /// Save the data content to a root file -int ConditionsRootPersistency::save(const string& fname) { +int ConditionsRootPersistency::save(const std::string& fname) { DurationStamp stamp(this); //TDirectory::TContext context; TFile* file = TFile::Open(fname.c_str(),"RECREATE"); diff --git a/DDCond/src/ConditionsSlice.cpp b/DDCond/src/ConditionsSlice.cpp index 0be5e5029..9c97fd96d 100644 --- a/DDCond/src/ConditionsSlice.cpp +++ b/DDCond/src/ConditionsSlice.cpp @@ -12,13 +12,11 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsSlice.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/Printout.h" +#include +#include +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; /// Initializing constructor @@ -29,7 +27,7 @@ ConditionsSlice::ConditionsSlice(ConditionsManager mgr) : manager(mgr) /// Initializing constructor ConditionsSlice::ConditionsSlice(ConditionsManager mgr, - const shared_ptr& cont) + const std::shared_ptr& cont) : manager(mgr), content(cont) { InstanceCount::increment(this); @@ -55,10 +53,10 @@ void ConditionsSlice::derefPools() { } /// Access the combined IOV of the slice from the pool -const IOV& ConditionsSlice::iov() const { +const dd4hep::IOV& ConditionsSlice::iov() const { if ( pool.get() ) return pool->validity(); - dd4hep::except("ConditionsSlice", - "pool-iov: Failed to access validity of non-existing pool."); + except("ConditionsSlice", + "pool-iov: Failed to access validity of non-existing pool."); return pool->validity(); } @@ -74,29 +72,29 @@ bool ConditionsSlice::manage(ConditionsPool* p, Condition condition, ManageFlag bool ret = false; if ( flg®ISTER_MANAGER ) { if ( !p ) { - dd4hep::except("ConditionsSlice", - "manage_condition: Cannot access conditions pool according to IOV:%s.", - pool->validity().str().c_str()); + except("ConditionsSlice", + "manage_condition: Cannot access conditions pool according to IOV:%s.", + pool->validity().str().c_str()); } ret = manager.registerUnlocked(*p,condition); if ( !ret ) { - dd4hep::except("ConditionsSlice", - "manage_condition: Failed to register condition %016llx according to IOV:%s.", - condition->hash, pool->validity().str().c_str()); + except("ConditionsSlice", + "manage_condition: Failed to register condition %016llx according to IOV:%s.", + condition->hash, pool->validity().str().c_str()); } } if ( flg®ISTER_POOL ) { ret = pool->insert(condition); if ( !ret ) { - dd4hep::except("ConditionsSlice", - "manage_condition: Failed to register condition %016llx to user pool with IOV:%s.", - condition->hash, pool->validity().str().c_str()); + except("ConditionsSlice", + "manage_condition: Failed to register condition %016llx to user pool with IOV:%s.", + condition->hash, pool->validity().str().c_str()); } } return ret; } - dd4hep::except("ConditionsSlice", - "manage_condition: Cannot manage invalid condition!"); + except("ConditionsSlice", + "manage_condition: Cannot manage invalid condition!"); return false; } @@ -107,14 +105,14 @@ bool ConditionsSlice::manage(Condition condition, ManageFlag flg) { } /// Access all conditions from a given detector element -vector ConditionsSlice::get(DetElement detector) const { +std::vector ConditionsSlice::get(DetElement detector) const { return pool->get(detector,FIRST_ITEM,LAST_ITEM); } /// No ConditionsMap overload: Access all conditions within a key range in the interval [lower,upper] -vector ConditionsSlice::get(DetElement detector, - Condition::itemkey_type lower, - Condition::itemkey_type upper) const { +std::vector ConditionsSlice::get(DetElement detector, + Condition::itemkey_type lower, + Condition::itemkey_type upper) const { return pool->get(detector, lower, upper); } @@ -123,25 +121,25 @@ bool ConditionsSlice::insert(DetElement detector, Condition::itemkey_type key, C if ( condition.isValid() ) { ConditionsPool* p = manager.registerIOV(pool->validity()); if ( !p ) { - dd4hep::except("ConditionsSlice", - "manage_condition: Cannot access conditions pool according to IOV:%s.", - pool->validity().str().c_str()); + except("ConditionsSlice", + "manage_condition: Cannot access conditions pool according to IOV:%s.", + pool->validity().str().c_str()); } bool ret = manager.registerUnlocked(*p,condition); if ( !ret ) { - dd4hep::except("ConditionsSlice", - "manage_condition: Failed to register condition %016llx according to IOV:%s.", - condition->hash, pool->validity().str().c_str()); + except("ConditionsSlice", + "manage_condition: Failed to register condition %016llx according to IOV:%s.", + condition->hash, pool->validity().str().c_str()); } return pool->insert(detector, key, condition); } - dd4hep::except("ConditionsSlice", - "insert_condition: Cannot insert invalid condition to the user pool!"); + except("ConditionsSlice", + "insert_condition: Cannot insert invalid condition to the user pool!"); return false; } /// ConditionsMap overload: Access a condition -Condition ConditionsSlice::get(DetElement detector, Condition::itemkey_type key) const { +dd4hep::Condition ConditionsSlice::get(DetElement detector, Condition::itemkey_type key) const { return pool->get(detector, key); } @@ -160,14 +158,14 @@ void ConditionsSlice::scan(DetElement detector, namespace { - struct SliceOper : public ConditionsSelect { + struct SliceOper : public dd4hep::ConditionsSelect { ConditionsContent& content; SliceOper(ConditionsContent& c) : content(c) {} void operator()(const ConditionsIOVPool::Elements::value_type& v) { v.second->select_all(*this); } - bool operator()(Condition::Object* c) const { - if ( 0 == (c->flags&Condition::DERIVED) ) { + bool operator()(dd4hep::Condition::Object* c) const { + if ( 0 == (c->flags&dd4hep::Condition::DERIVED) ) { #if !defined(DD4HEP_MINIMAL_CONDITIONS) content.addLocation(c->hash,c->address); #endif diff --git a/DDCond/src/ConditionsTextRepository.cpp b/DDCond/src/ConditionsTextRepository.cpp index cad11d8cd..73967f410 100644 --- a/DDCond/src/ConditionsTextRepository.cpp +++ b/DDCond/src/ConditionsTextRepository.cpp @@ -27,15 +27,14 @@ #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; -typedef xml::Handle_t xml_h; -typedef xml::Element xml_elt_t; -typedef xml::Document xml_doc_t; -typedef xml::Collection_t xml_coll_t; -typedef map AllConditions; +typedef dd4hep::xml::Handle_t xml_h; +typedef dd4hep::xml::Element xml_elt_t; +typedef dd4hep::xml::Document xml_doc_t; +typedef dd4hep::xml::Collection_t xml_coll_t; + +typedef std::map AllConditions; /// Default constructor. Allocates resources ConditionsTextRepository::ConditionsTextRepository() { @@ -47,7 +46,7 @@ ConditionsTextRepository::~ConditionsTextRepository() { namespace { - int createXML(const string& output, const AllConditions& all) { + int createXML(const std::string& output, const AllConditions& all) { char text[32]; const char comment[] = "\n" " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" @@ -69,7 +68,7 @@ namespace { cond.setAttr(_U(ref), c.second.address()); #endif } - printout(ALWAYS,"ConditionsRepository","++ Handled %ld conditions.",all.size()); + dd4hep::printout(dd4hep::ALWAYS,"ConditionsRepository","++ Handled %ld conditions.",all.size()); if ( !output.empty() ) { return docH.output(doc, output); } @@ -77,7 +76,7 @@ namespace { } /// Load the repository from file and fill user passed data structory - int readXML(const string& input, ConditionsTextRepository::Data& data) { + int readXML(const std::string& input, ConditionsTextRepository::Data& data) { struct Conv { /// Reference to optional user defined parameter ConditionsTextRepository::Data& data; @@ -85,45 +84,45 @@ namespace { Conv(ConditionsTextRepository::Data& p) : data(p) {} /// Callback operator to be specialized depending on the element type void operator()(xml_h element) const { - string key = element.attr(_U(key)); + std::string key = element.attr(_U(key)); size_t cap = data.capacity(); ConditionsTextRepository::Entry e; ::sscanf(key.c_str(),"0x%16llX",&e.key); - e.name = element.attr(_U(name)); - e.address = element.attr(_U(ref)); + e.name = element.attr(_U(name)); + e.address = element.attr(_U(ref)); if ( data.size() == cap ) data.reserve(cap+500); data.emplace_back(e); } }; - xml::DocumentHolder doc(xml::DocumentHandler().load(input)); + dd4hep::xml::DocumentHolder doc(dd4hep::xml::DocumentHandler().load(input)); xml_h root = doc.root(); xml_coll_t(root, _U(ref)).for_each(Conv(data)); return 1; } #if defined(DD4HEP_MINIMAL_CONDITIONS) - int createText(const string& output, const AllConditions&, char) + int createText(const std::string& output, const AllConditions&, char) #else - int createText(const string& output, const AllConditions& all, char sep) + int createText(const std::string& output, const AllConditions& all, char sep) #endif { - ofstream out(output); + std::ofstream out(output); #if !defined(DD4HEP_MINIMAL_CONDITIONS) - size_t siz_nam=0, siz_add=0, siz_tot=0; + std::size_t siz_nam=0, siz_add=0, siz_tot=0; char fmt[64], text[2*PATH_MAX+64]; if ( !out.good() ) { - except("ConditionsTextRepository", - "++ Failed to open output file:%s [errno:%d %s]", - output.c_str(), errno, ::strerror(errno)); + dd4hep::except("ConditionsTextRepository", + "++ Failed to open output file:%s [errno:%d %s]", + output.c_str(), errno, ::strerror(errno)); } else if ( sep ) { - ::snprintf(fmt,sizeof(fmt),"%%16llX%c%%s%c%%s%c",sep,sep,sep); + std::snprintf(fmt,sizeof(fmt),"%%16llX%c%%s%c%%s%c",sep,sep,sep); } else { for( const auto& i : all ) { - Condition::Object* c = i.second.ptr(); - size_t siz_n = c->name.length(); - size_t siz_a = c->address.length(); + dd4hep::Condition::Object* c = i.second.ptr(); + std::size_t siz_n = c->name.length(); + std::size_t siz_a = c->address.length(); if ( siz_add < siz_a ) siz_add = siz_a; if ( siz_nam < siz_n ) siz_nam = siz_n; if ( siz_tot < (siz_n+siz_a) ) siz_tot = siz_n+siz_a; @@ -134,11 +133,11 @@ namespace { out << "dd4hep." << char(sep ? sep : '-') << "." << long(siz_nam) << "." << long(siz_add) - << "." << long(siz_tot) << endl; + << "." << long(siz_tot) << std::endl; for( const auto& i : all ) { - Condition c = i.second; - ::snprintf(text, sizeof(text), fmt, c.key(), c.name(), c.address().c_str()); - out << text << endl; + dd4hep::Condition c = i.second; + std::snprintf(text, sizeof(text), fmt, c.key(), c.name(), c.address().c_str()); + out << text << std::endl; } #endif out.close(); @@ -146,12 +145,12 @@ namespace { } /// Load the repository from file and fill user passed data structory - int readText(const string& input, ConditionsTextRepository::Data& data) { - size_t idx; + int readText(const std::string& input, ConditionsTextRepository::Data& data) { + std::size_t idx; ConditionsTextRepository::Entry e; - size_t siz_nam, siz_add, siz_tot; + std::size_t siz_nam, siz_add, siz_tot; char sep, c, text[2*PATH_MAX+64]; - ifstream in(input); + std::ifstream in(input); in >> c >> c >> c >> c >> c >> c >> c >> sep >> c >> siz_nam >> c >> siz_add @@ -162,36 +161,36 @@ namespace { text[0] = 0; in.getline(text,sizeof(text),'\n'); if ( in.good() ) { - size_t idx_nam = 9+siz_nam= sizeof(text) ) - except("ConditionsTextRepository","Inconsistent input data in %s: %s -> (%lld,%lld,%lld)", - __FILE__, input.c_str(), siz_nam, siz_add, siz_tot); + dd4hep::except("ConditionsTextRepository","Inconsistent input data in %s: %s -> (%lld,%lld,%lld)", + __FILE__, input.c_str(), siz_nam, siz_add, siz_tot); else if ( 10+siz_nam+siz_add >= sizeof(text) ) - except("ConditionsTextRepository","Inconsistent input data in %s: %s -> (%lld,%lld,%lld)", - __FILE__, input.c_str(), siz_nam, siz_add, siz_tot); + dd4hep::except("ConditionsTextRepository","Inconsistent input data in %s: %s -> (%lld,%lld,%lld)", + __FILE__, input.c_str(), siz_nam, siz_add, siz_tot); else if ( siz_tot ) { // Direct access mode with fixed record size text[8] = text[idx_nam] = text[idx_add] = 0; e.name = text+9; e.address = text+idx_nam+1; - if ( (idx=e.name.find(' ')) != string::npos ) + if ( (idx=e.name.find(' ')) != std::string::npos ) e.name[idx]=0; - if ( (idx=e.address.find(' ')) != string::npos ) + if ( (idx=e.address.find(' ')) != std::string::npos ) e.address[idx]=0; } else { // Variable record size e.name=text+9; - if ( (idx=e.name.find(sep)) != string::npos && idx+10 < sizeof(text) ) + if ( (idx=e.name.find(sep)) != std::string::npos && idx+10 < sizeof(text) ) text[9+idx]=0, e.address=text+idx+10, e.name=text+9; - if ( (idx=e.address.find(sep)) != string::npos ) + if ( (idx=e.address.find(sep)) != std::string::npos ) e.address[idx]=0; - else if ( (idx=e.address.find('\n')) != string::npos ) + else if ( (idx=e.address.find('\n')) != std::string::npos ) e.address[idx]=0; } - size_t cap = data.capacity(); - ::sscanf(text,"%16llX",&e.key); + std::size_t cap = data.capacity(); + std::sscanf(text,"%16llX",&e.key); if ( data.size() == cap ) data.reserve(cap+500); data.emplace_back(e); } @@ -202,7 +201,7 @@ namespace { } /// Save the repository to file -int ConditionsTextRepository::save(ConditionsManager manager, const string& output) const { +int ConditionsTextRepository::save(ConditionsManager manager, const std::string& output) const { AllConditions all; const auto types = manager.iovTypesUsed(); for( const IOVType* type : types ) { @@ -219,19 +218,19 @@ int ConditionsTextRepository::save(ConditionsManager manager, const string& outp } } - if ( output.find(".xml") != string::npos ) { + if ( output.find(".xml") != std::string::npos ) { /// Write XML file with conditions addresses return createXML(output, all); } - else if ( output.find(".txt") != string::npos ) { + else if ( output.find(".txt") != std::string::npos ) { /// Write fixed records with conditions addresses return createText(output, all, 0); } - else if ( output.find(".daf") != string::npos ) { + else if ( output.find(".daf") != std::string::npos ) { /// Write fixed records with conditions addresses return createText(output, all, 0); } - else if ( output.find(".csv") != string::npos ) { + else if ( output.find(".csv") != std::string::npos ) { /// Write records separated by ';' with conditions addresses return createText(output, all, ';'); } @@ -239,17 +238,17 @@ int ConditionsTextRepository::save(ConditionsManager manager, const string& outp } /// Load the repository from file and fill user passed data structory -int ConditionsTextRepository::load(const string& input, Data& data) const { - if ( input.find(".xml") != string::npos ) { +int ConditionsTextRepository::load(const std::string& input, Data& data) const { + if ( input.find(".xml") != std::string::npos ) { return readXML(input, data); } - else if ( input.find(".txt") != string::npos ) { + else if ( input.find(".txt") != std::string::npos ) { return readText(input, data); } - else if ( input.find(".daf") != string::npos ) { + else if ( input.find(".daf") != std::string::npos ) { return readText(input, data); } - else if ( input.find(".csv") != string::npos ) { + else if ( input.find(".csv") != std::string::npos ) { return readText(input, data); } return 0; diff --git a/DDCond/src/ConditionsTreePersistency.cpp b/DDCond/src/ConditionsTreePersistency.cpp index 9d8311d1d..033103be3 100644 --- a/DDCond/src/ConditionsTreePersistency.cpp +++ b/DDCond/src/ConditionsTreePersistency.cpp @@ -12,21 +12,18 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DDCond/ConditionsSlice.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsTreePersistency.h" +#include +#include +#include +#include -#include "TFile.h" -#include "TTimeStamp.h" +#include +#include typedef dd4hep::cond::ConditionsTreePersistency __ConditionsTreePersistency; /// ROOT Class implementation directive ClassImp(__ConditionsTreePersistency) - -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; // Local namespace for anonymous stuff @@ -38,12 +35,12 @@ namespace { * \version 1.0 * \ingroup DD4HEP_CONDITIONS */ - struct Scanner : public Condition::Processor { + struct Scanner : public dd4hep::Condition::Processor { ConditionsTreePersistency::pool_type& pool; /// Constructor Scanner(ConditionsTreePersistency::pool_type& p) : pool(p) {} /// Conditions callback for object processing - virtual int process(Condition c) const override { + virtual int process(dd4hep::Condition c) const override { pool.emplace_back(c.ptr()); return 1; } @@ -65,7 +62,7 @@ ConditionsTreePersistency::ConditionsTreePersistency() : TNamed() { } /// Initializing constructor -ConditionsTreePersistency::ConditionsTreePersistency(const string& name, const string& title) +ConditionsTreePersistency::ConditionsTreePersistency(const std::string& name, const std::string& title) : TNamed(name.c_str(), title.c_str()) { } @@ -76,11 +73,12 @@ ConditionsTreePersistency::~ConditionsTreePersistency() { } /// Add conditions content to be saved. Note, that dependent conditions shall not be saved! -size_t ConditionsTreePersistency::add(const std::string& identifier, - const IOV& iov, - std::vector& conditions) { +std::size_t ConditionsTreePersistency::add(const std::string& identifier, + const IOV& iov, + std::vector& conditions) +{ DurationStamp stamp(this); - conditionPools.emplace_back(pair()); + conditionPools.emplace_back(std::pair()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; key.first = identifier; @@ -92,9 +90,9 @@ size_t ConditionsTreePersistency::add(const std::string& identifier, } /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! -size_t ConditionsTreePersistency::add(const string& identifier, ConditionsPool& pool) { +std::size_t ConditionsTreePersistency::add(const std::string& identifier, ConditionsPool& pool) { DurationStamp stamp(this); - conditionPools.emplace_back(pair()); + conditionPools.emplace_back(std::pair()); pool_type& ent = conditionPools.back().second; iov_key_type& key = conditionPools.back().first; const IOV* iov = pool.iov; @@ -107,11 +105,11 @@ size_t ConditionsTreePersistency::add(const string& identifier, ConditionsPool& } /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! -size_t ConditionsTreePersistency::add(const string& identifier, const ConditionsIOVPool& pool) { - size_t count = 0; +std::size_t ConditionsTreePersistency::add(const std::string& identifier, const ConditionsIOVPool& pool) { + std::size_t count = 0; DurationStamp stamp(this); for( const auto& p : pool.elements ) { - iovPools.emplace_back(pair()); + iovPools.emplace_back(std::pair()); pool_type& ent = iovPools.back().second; iov_key_type& key = iovPools.back().first; const IOV* iov = p.second->iov; @@ -126,7 +124,7 @@ size_t ConditionsTreePersistency::add(const string& identifier, const Conditions } /// Open ROOT file in read mode -TFile* ConditionsTreePersistency::openFile(const string& fname) { +TFile* ConditionsTreePersistency::openFile(const std::string& fname) { TDirectory::TContext context; TFile* file = TFile::Open(fname.c_str()); if ( file && !file->IsZombie()) return file; @@ -154,7 +152,7 @@ void ConditionsTreePersistency::clear() { /// Add conditions content to the saved. Note, that dependent conditions shall not be saved! std::unique_ptr -ConditionsTreePersistency::load(TFile* file,const string& obj) { +ConditionsTreePersistency::load(TFile* file,const std::string& obj) { std::unique_ptr p; if ( file && !file->IsZombie()) { TTimeStamp start; @@ -174,13 +172,14 @@ ConditionsTreePersistency::load(TFile* file,const string& obj) { } /// Load ConditionsPool(s) and populate conditions manager -size_t ConditionsTreePersistency::_import(ImportStrategy strategy, - persistent_type& persistent_pools, - const std::string& id, - const std::string& iov_type, - const IOV::Key& iov_key, - ConditionsManager mgr) { - size_t count = 0; +std::size_t ConditionsTreePersistency::_import(ImportStrategy strategy, + persistent_type& persistent_pools, + const std::string& id, + const std::string& iov_type, + const IOV::Key& iov_key, + ConditionsManager mgr) +{ + std::size_t count = 0; std::pair iovTyp(false,0); for (auto& iovp : persistent_pools ) { bool use = false; @@ -243,29 +242,29 @@ size_t ConditionsTreePersistency::_import(ImportStrategy strategy, } /// Load ConditionsIOVPool and populate conditions manager -size_t ConditionsTreePersistency::importIOVPool(const std::string& identifier, - const std::string& iov_type, - ConditionsManager mgr) +std::size_t ConditionsTreePersistency::importIOVPool(const std::string& identifier, + const std::string& iov_type, + ConditionsManager mgr) { DurationStamp stamp(this); return _import(IMPORT_ALL,iovPools,identifier,iov_type,IOV::Key(),mgr); } /// Load ConditionsIOVPool and populate conditions manager -size_t ConditionsTreePersistency::importConditionsPool(const std::string& identifier, - const std::string& iov_type, - ConditionsManager mgr) +std::size_t ConditionsTreePersistency::importConditionsPool(const std::string& identifier, + const std::string& iov_type, + ConditionsManager mgr) { DurationStamp stamp(this); return _import(IMPORT_ALL,conditionPools,identifier,iov_type,IOV::Key(),mgr); } /// Load conditions pool and populate conditions manager. Allow tro be selective also for the key -size_t ConditionsTreePersistency::importConditionsPool(ImportStrategy strategy, - const std::string& identifier, - const std::string& iov_type, - const IOV::Key& iov_key, - ConditionsManager mgr) { +std::size_t ConditionsTreePersistency::importConditionsPool(ImportStrategy strategy, + const std::string& identifier, + const std::string& iov_type, + const IOV::Key& iov_key, + ConditionsManager mgr) { return _import(strategy,conditionPools,identifier,iov_type,iov_key,mgr); } @@ -278,7 +277,7 @@ int ConditionsTreePersistency::save(TFile* file) { } /// Save the data content to a root file -int ConditionsTreePersistency::save(const string& fname) { +int ConditionsTreePersistency::save(const std::string& fname) { DurationStamp stamp(this); //TDirectory::TContext context; TFile* file = TFile::Open(fname.c_str(),"RECREATE"); diff --git a/DDCond/src/Type1/Manager_Type1.cpp b/DDCond/src/Type1/Manager_Type1.cpp index 5b5081e46..a15ecf23c 100644 --- a/DDCond/src/Type1/Manager_Type1.cpp +++ b/DDCond/src/Type1/Manager_Type1.cpp @@ -12,38 +12,36 @@ //========================================================================== // Framework include files -#include "DDCond/Type1/Manager_Type1.h" - -#include "DD4hep/Detector.h" -#include "DD4hep/World.h" -#include "DD4hep/Errors.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Factories.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/PluginCreators.h" -#include "DD4hep/ConditionsListener.h" -#include "DD4hep/detail/Handle.inl" -#include "DD4hep/detail/DetectorInterna.h" -#include "DD4hep/detail/ConditionsInterna.h" - -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsEntry.h" -#include "DDCond/ConditionsCleanup.h" -#include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsDataLoader.h" - -using namespace std; -using namespace dd4hep; +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + using namespace dd4hep::cond; typedef UpdatePool::UpdateEntries Updates; -typedef RangeConditions RC; +typedef dd4hep::RangeConditions RC; DD4HEP_INSTANTIATE_HANDLE_NAMED(Manager_Type1); -static void* ddcond_create_manager_instance(Detector& description, int, char**) { +static void* ddcond_create_manager_instance(dd4hep::Detector& description, int, char**) { return (ConditionsManagerObject*)new Manager_Type1(description); } DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsManager_Type1,ddcond_create_manager_instance) @@ -54,15 +52,15 @@ namespace { struct Range {}; struct Discrete {}; - int s_debug = INFO; + int s_debug = dd4hep::INFO; /// Helper: IOV Check function declaration - template const IOVType* check_iov_type(const Manager_Type1* o, const IOV* iov); + template const dd4hep::IOVType* check_iov_type(const Manager_Type1* o, const dd4hep::IOV* iov); /// Helper: Specialized IOV check - template <> const IOVType* check_iov_type(const Manager_Type1* o, const IOV* iov) { + template <> const dd4hep::IOVType* check_iov_type(const Manager_Type1* o, const dd4hep::IOV* iov) { if ( iov ) { - const IOVType* typ = iov->iovType ? iov->iovType : o->iovType(iov->type); + const dd4hep::IOVType* typ = iov->iovType ? iov->iovType : o->iovType(iov->type); if ( typ ) { if ( iov->type == typ->type ) { if ( typ->type < o->m_rawPool.size() ) { @@ -77,45 +75,45 @@ namespace { } /// Helper: Specialized IOV check for discrete IOV values - template <> const IOVType* check_iov_type(const Manager_Type1* o, const IOV* iov) { - const IOVType* typ = check_iov_type(o,iov); + template <> const dd4hep::IOVType* check_iov_type(const Manager_Type1* o, const dd4hep::IOV* iov) { + const dd4hep::IOVType* typ = check_iov_type(o,iov); if ( typ && !iov->has_range() ) return typ; return 0; } #if 0 /// Helper: Specialized IOV check for range IOV values - template <> const IOVType* check_iov_type(const Manager_Type1* o, const IOV* iov) { - const IOVType* typ = check_iov_type(o,iov); + template <> const dd4hep::IOVType* check_iov_type(const Manager_Type1* o, const dd4hep::IOV* iov) { + const dd4hep::IOVType* typ = check_iov_type(o,iov); if ( typ && iov->has_range() ) return typ; return 0; } #endif /// Helper: Check conditions result for consistency - template void __check_values__(const Manager_Type1* o, Condition::key_type key, const IOV* iov) + template void __check_values__(const Manager_Type1* o, dd4hep::Condition::key_type key, const dd4hep::IOV* iov) { if ( !iov ) { - except("ConditionsMgr","+++ Invalid IOV to access condition: %16llX. [Null-reference]",key); + dd4hep::except("ConditionsMgr","+++ Invalid IOV to access condition: %16llX. [Null-reference]",key); } - const IOVType* typ = check_iov_type(o,iov); + const dd4hep::IOVType* typ = check_iov_type(o,iov); if ( !typ ) { // Severe: We have an unknown IOV type. This is not allowed, // because we do not known hot to handle it..... - except("ConditionsMgr","+++ Invalid IOV type [%d] to access condition: %16llX.", - iov->type, key); + dd4hep::except("ConditionsMgr","+++ Invalid IOV type [%d] to access condition: %16llX.", + iov->type, key); } } /// Helper: Check if the conditions range covers the entire IOV span - bool is_range_complete(const IOV& iov, const RC& conditions) { + bool is_range_complete(const dd4hep::IOV& iov, const RC& conditions) { if ( !conditions.empty() ) { // We need to check if the entire range is covered. // For every key.second we must find a key.first, which is at least as big - IOV::Key test=iov.keyData; + dd4hep::IOV::Key test=iov.keyData; // The range may be returned unordered. Hence, // we have to try to match at most conditions.size() times until we really know - for(size_t j = 0; j < conditions.size(); ++j ) { + for( std::size_t j = 0; j < conditions.size(); ++j ) { for(const auto& cond : conditions ) { - const IOV::Key& k = cond->iov->key(); + const dd4hep::IOV::Key& k = cond->iov->key(); if ( k.first <= test.first+1 && k.second >= test.first ) test.first = k.second; if ( k.first+1 <= test.second && k.second >= test.second ) test.second = k.first; //printout(INFO,"Test","IOV: %ld,%ld --> %ld,%ld",k.first,k.second, test.first, test.second); @@ -128,7 +126,7 @@ namespace { } template - void __callListeners(const Manager_Type1::Listeners& listeners, PMF pmf, Condition& cond) { + void __callListeners(const Manager_Type1::Listeners& listeners, PMF pmf, dd4hep::Condition& cond) { for(const auto& listener : listeners ) (listener.first->*pmf)(cond, listener.second); } @@ -157,7 +155,7 @@ Manager_Type1::~Manager_Type1() { void Manager_Type1::initialize() { if ( !m_updatePool.get() ) { - string typ = m_loaderType; + std::string typ = m_loaderType; const void* argv_loader[] = {"ConditionsDataLoader", this, 0}; const void* argv_pool[] = {this, 0, 0}; m_loader.reset(createPlugin(typ,m_detDesc,2,argv_loader)); @@ -173,13 +171,14 @@ void Manager_Type1::initialize() { } /// Register new IOV type if it does not (yet) exist. -pair Manager_Type1::registerIOVType(size_t iov_index, const string& iov_name) { +std::pair +Manager_Type1::registerIOVType(std::size_t iov_index, const std::string& iov_name) { if ( iov_index Manager_Type1::registerIOVType(size_t iov_index, cons typ.name = iov_name; typ.type = iov_index; m_rawPool[typ.type] = new ConditionsIOVPool(&typ); - return make_pair(true,&typ); + return { true, &typ }; } except("ConditionsMgr","Cannot register IOV section %d of type %d. Value out of bounds: [%d,%d]", iov_name.c_str(), iov_index, 0, int(m_iovTypes.size())); - return make_pair(false,(IOVType*)0); + return { false, nullptr }; } /// Access IOV by its type -const IOVType* Manager_Type1::iovType (size_t iov_index) const { +const dd4hep::IOVType* Manager_Type1::iovType (size_t iov_index) const { if ( iov_indextype = typ.type; iov->keyData = key; const void* argv_pool[] = {this, iov, 0}; - shared_ptr cond_pool(createPlugin(m_poolType,m_detDesc,2,argv_pool)); + std::shared_ptr cond_pool(createPlugin(m_poolType,m_detDesc,2,argv_pool)); pool->elements.emplace(key,cond_pool); printout(INFO,"ConditionsMgr","Created IOV Pool for:%s",iov->str().c_str()); return cond_pool.get(); @@ -268,16 +267,13 @@ bool Manager_Type1::registerUnlocked(ConditionsPool& pool, Condition cond) { } /// Register a whole block of conditions with identical IOV. -size_t Manager_Type1::blockRegister(ConditionsPool& pool, const vector& cond) const { - size_t result = 0; - //string typ; +std::size_t Manager_Type1::blockRegister(ConditionsPool& pool, const std::vector& cond) const { + std::size_t result = 0; for(auto c : cond) { if ( c.isValid() ) { c->iov = pool.iov; c->setFlag(Condition::ACTIVE); pool.insert(c); - //typ = typeName(typeid(*(c.ptr()))); - //if ( typ.find("Static") != string::npos ) cout << "++Insert: " << typ << endl; if ( !m_onRegister.empty() ) { __callListeners(m_onRegister, &ConditionsListener::onRegisterCondition, c); } @@ -293,7 +289,7 @@ size_t Manager_Type1::blockRegister(ConditionsPool& pool, const vectorConditionsManagerObject::registerIOV(e->validity); Condition condition(e->name,e->type); @@ -360,8 +356,8 @@ int Manager_Type1::clean(const IOVType* typ, int max_age) { } /// Invoke cache cleanup with user defined policy -pair Manager_Type1::clean(const ConditionsCleanup& cleaner) { - pair count(0,0); +std::pair Manager_Type1::clean(const ConditionsCleanup& cleaner) { + std::pair count(0,0); for( TypedConditionPool::iterator i=m_rawPool.begin(); i != m_rawPool.end(); ++i) { ConditionsIOVPool* p = *i; if ( p && cleaner(*p) ) { @@ -373,8 +369,8 @@ pair Manager_Type1::clean(const ConditionsCleanup& cleaner) { } /// Full cleanup of all managed conditions. -pair Manager_Type1::clear() { - pair count(0,0); +std::pair Manager_Type1::clear() { + std::pair count(0,0); for( TypedConditionPool::iterator i=m_rawPool.begin(); i != m_rawPool.end(); ++i) { ConditionsIOVPool* p = *i; if ( p ) { diff --git a/DDCond/src/plugins/ConditionsLinearPool.cpp b/DDCond/src/plugins/ConditionsLinearPool.cpp index 3dbe032de..4f35ba93d 100644 --- a/DDCond/src/plugins/ConditionsLinearPool.cpp +++ b/DDCond/src/plugins/ConditionsLinearPool.cpp @@ -14,11 +14,11 @@ #define DDCOND_CONDITIONSLINEARPOOL_H // Framework include files -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsSelectors.h" +#include +#include +#include -#include "DD4hep/Printout.h" +#include // C/C++ include files #include @@ -185,10 +185,9 @@ namespace dd4hep { //========================================================================== // Framework include files -//#include "DDCond/ConditionsLinearPool.h" -#include "DD4hep/InstanceCount.h" +//#include +#include -using dd4hep::Handle; using namespace dd4hep::cond; /// Default constructor @@ -196,7 +195,6 @@ template ConditionsLinearPool::ConditionsLinearPool(ConditionsManager mgr, IOV* i) : BASE(mgr, i) { - this->BASE::SetName(i ? i->str().c_str() : "Unknown IOV"); this->BASE::SetTitle("ConditionsLinearPool"); InstanceCount::increment(this); @@ -219,10 +217,8 @@ namespace dd4hep { } /* End namespace cond */ } /* End namespace dd4hep */ -#include "DD4hep/Factories.h" +#include namespace { - using namespace dd4hep; - ConditionsManager _mgr(int argc, char** argv) { if ( argc > 0 ) { ConditionsManager::Object* m = (ConditionsManager::Object*)argv[0]; @@ -231,9 +227,9 @@ namespace { dd4hep::except("ConditionsLinearPool","++ Insufficient arguments: arg[0] = ConditionManager!"); return ConditionsManager(0); } - IOV* _iov(int argc, char** argv) { + dd4hep::IOV* _iov(int argc, char** argv) { if ( argc > 1 ) { - IOV* i = (IOV*)argv[1]; + dd4hep::IOV* i = (dd4hep::IOV*)argv[1]; return i; } dd4hep::except("ConditionsLinearPool","++ Insufficient arguments: arg[1] = IOV!"); @@ -241,7 +237,7 @@ namespace { } #define _CR(fun,x,b,y) void* fun(dd4hep::Detector&, int argc, char** argv) \ - { return new b,y>(_mgr(argc,argv), _iov(argc,argv)); } + { return new b,y>(_mgr(argc,argv), _iov(argc,argv)); } /// Create a conditions pool based on STL vectors _CR(create_vector_pool,std::vector,ConditionsLinearPool,ConditionsPool) /// Create a conditions pool based on STL lists diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp index d1d1a262a..ee8f26759 100644 --- a/DDCond/src/plugins/ConditionsMappedPool.cpp +++ b/DDCond/src/plugins/ConditionsMappedPool.cpp @@ -14,11 +14,11 @@ #define DDCOND_CONDITIONSMAPPEDPOOL_H // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsSelectors.h" +#include +#include // C/C++ include files #include @@ -54,7 +54,7 @@ namespace dd4hep { Mapping m_entries; /// Helper function to loop over the conditions container and apply a functor - template size_t loop(R& result, T functor) { + template std::size_t loop(R& result, T functor) { size_t len = result.size(); for_each(m_entries.begin(),m_entries.end(),functor); return result.size() - len; @@ -198,8 +198,8 @@ namespace dd4hep { //========================================================================== // Framework include files -//#include "DDCond/ConditionsMappedPool.h" -#include "DD4hep/InstanceCount.h" +//#include +#include using dd4hep::Handle; using namespace dd4hep::cond; @@ -219,9 +219,8 @@ ConditionsMappedPool::~ConditionsMappedPool() { InstanceCount::decrement(this); } -#include "DD4hep/Factories.h" +#include namespace { - using namespace dd4hep; ConditionsManager _mgr(int argc, char** argv) { if ( argc > 0 ) { ConditionsManagerObject* m = (ConditionsManagerObject*)argv[0]; @@ -231,7 +230,7 @@ namespace { return ConditionsManager(0); } #define _CR(fun,x,b,y) void* fun(dd4hep::Detector&, int argc, char** argv) \ - { return new b,y>(_mgr(argc,argv)); } + { return new b,y>(_mgr(argc,argv)); } /// Create a conditions pool based on STL maps _CR(create_map_pool,std::map,ConditionsMappedPool,ConditionsPool) diff --git a/DDCond/src/plugins/ConditionsMultiLoader.cpp b/DDCond/src/plugins/ConditionsMultiLoader.cpp index c4ae170b8..14b09d54f 100644 --- a/DDCond/src/plugins/ConditionsMultiLoader.cpp +++ b/DDCond/src/plugins/ConditionsMultiLoader.cpp @@ -16,8 +16,8 @@ #define DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H // Framework include files -#include "DDCond/ConditionsDataLoader.h" -#include "DD4hep/Printout.h" +#include +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -86,14 +86,13 @@ namespace dd4hep { //========================================================================== // Framework include files -//#include "ConditionsMultiLoader.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Factories.h" -#include "DD4hep/PluginCreators.h" -#include "DDCond/ConditionsManager.h" +//#include +#include +#include +#include +#include // Forward declartions -using std::string; using namespace dd4hep::cond; namespace { @@ -106,7 +105,7 @@ namespace { DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_Conditions_multi_Loader,create_loader) /// Standard constructor, initializes variables -ConditionsMultiLoader::ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const string& nam) +ConditionsMultiLoader::ConditionsMultiLoader(Detector& description, ConditionsManager mgr, const std::string& nam) : ConditionsDataLoader(description, mgr, nam) { } @@ -122,15 +121,15 @@ ConditionsMultiLoader::load_source(const std::string& nam, OpenSources::iterator iop = m_openSources.find(nam); if ( iop == m_openSources.end() ) { size_t idx = nam.find(':'); - if ( idx == string::npos ) { + if ( idx == std::string::npos ) { except("ConditionsMultiLoader","Invalid data source specification: "+nam); } - string ident = nam.substr(0,idx); + std::string ident = nam.substr(0,idx); Loaders::iterator ild = m_loaders.find(ident); ConditionsDataLoader* loader = 0; if ( ild == m_loaders.end() ) { - string typ = "DD4hep_Conditions_"+ident+"_Loader"; - string fac = ident+"_ConditionsDataLoader"; + std::string typ = "DD4hep_Conditions_"+ident+"_Loader"; + std::string fac = ident+"_ConditionsDataLoader"; const void* argv[] = {fac.c_str(), m_mgr.ptr(), 0}; loader = createPlugin(typ,m_detector,2,argv); if ( !loader ) { @@ -160,7 +159,7 @@ size_t ConditionsMultiLoader::load_range(key_type key, const IOV& iov = (*i).second; if ( iov.type == req_validity.type ) { if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) ) { - const string& nam = (*i).first; + const std::string& nam = (*i).first; ConditionsDataLoader* loader = load_source(nam, req_validity); loader->load_range(key, req_validity, conditions); } @@ -180,7 +179,7 @@ size_t ConditionsMultiLoader::load_single(key_type key, const IOV& iov = (*i).second; if ( iov.type == req_validity.type ) { if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) ) { - const string& nam = (*i).first; + const std::string& nam = (*i).first; ConditionsDataLoader* loader = load_source(nam, req_validity); loader->load_single(key, req_validity, conditions); } diff --git a/DDCond/src/plugins/ConditionsParser.cpp b/DDCond/src/plugins/ConditionsParser.cpp index 223ed360b..4b13dd692 100644 --- a/DDCond/src/plugins/ConditionsParser.cpp +++ b/DDCond/src/plugins/ConditionsParser.cpp @@ -12,22 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "XML/Conversions.h" -#include "XML/XMLElements.h" -#include "XML/DocumentHandler.h" -#include "DD4hep/Printout.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/DetFactoryHelper.h" +#include +#include +#include +#include +#include +#include +#include -#include "DDCond/ConditionsTags.h" -#include "DDCond/ConditionsEntry.h" -#include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsDataLoader.h" +#include +#include +#include +#include -/* - * dd4hep namespace declaration - */ +/// Namespace for the AIDA detector description toolkit namespace dd4hep { namespace { @@ -57,8 +55,6 @@ namespace dd4hep { template <> void Converter::operator()(xml_h seq) const; } -using std::string; -using namespace dd4hep; using namespace dd4hep::cond; /// Namespace for the AIDA detector description toolkit @@ -75,19 +71,19 @@ namespace dd4hep { }; /// Helper: Extract the validity from the xml element - string _getValidity(xml_h elt) { + std::string _getValidity(xml_h elt) { if ( !elt.ptr() ) return "Infinite"; else if ( !elt.hasAttr(_UC(validity)) ) return _getValidity(elt.parent()); - return elt.attr(_UC(validity)); + return elt.attr(_UC(validity)); } /// Helper: Extract the required detector element from the parsing information DetElement _getDetector(void* param, xml_h e) { ConversionArg* arg = static_cast(param); DetElement detector = arg ? arg->detector : DetElement(); - string subpath = e.hasAttr(_U(path)) ? e.attr(_U(path)) : string(); + std::string subpath = e.hasAttr(_U(path)) ? e.attr(_U(path)) : std::string(); return subpath.empty() ? detector : detail::tools::findDaughterElement(detector,subpath); } @@ -95,7 +91,7 @@ namespace dd4hep { Entry* _createStackEntry(void* param, xml_h element) { xml_comp_t e(element); DetElement elt = _getDetector(param, element); - string name = e.hasAttr(_U(name)) ? e.nameStr() : e.tag(); + std::string name = e.hasAttr(_U(name)) ? e.nameStr() : e.tag(); return new Entry(elt,name,e.tag(),_getValidity(element),detail::hash32(name)); } @@ -133,7 +129,7 @@ namespace dd4hep { */ template <> void Converter::operator()(xml_h e) const { xml_comp_t elt(e); - string tag = elt.tag(); + std::string tag = elt.tag(); ConversionArg* arg = _param(); if ( !arg ) except("ConditionsParser","++ Invalid parser argument [Internal Error]"); @@ -153,7 +149,7 @@ namespace dd4hep { xml_coll_t(e,_U(star)).for_each(Converter(description,param,optional)); else if ( tag == "alignment" ) { dd4hep_ptr val(_createStackEntry(param,e)); - val->value = elt.attr(_U(ref)); + val->value = elt.attr(_U(ref)); if ( !arg->stack ) except("ConditionsParser","Non-existing Conditions stack:%s %d",__FILE__, __LINE__); else @@ -210,15 +206,15 @@ namespace dd4hep { * @version 1.0 * @date 01/04/2014 */ -static void* setup_global_Conditions(Detector& description, int argc, char** argv) { +static void* setup_global_Conditions(dd4hep::Detector& description, int argc, char** argv) { if ( argc == 2 ) { xml_h e = xml_h::Elt_t(argv[0]); ConditionsStack* stack = (ConditionsStack*)argv[1]; - ConversionArg args(description.world(), stack); - (dd4hep::Converter(description,&args))(e); + dd4hep::ConversionArg args(description.world(), stack); + (dd4hep::Converter(description,&args))(e); return &description; } - except("XML_DOC_READER","Invalid number of arguments to interprete conditions: %d != %d.",argc,2); + dd4hep::except("XML_DOC_READER","Invalid number of arguments to interprete conditions: %d != %d.",argc,2); return 0; } DECLARE_DD4HEP_CONSTRUCTOR(XMLConditionsParser,setup_global_Conditions) diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index 4590b7745..a675c0856 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -12,25 +12,29 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Conditions.h" -#include "DD4hep/PluginCreators.h" -#include "DD4hep/DetFactoryHelper.h" -#include "DD4hep/ConditionsPrinter.h" -#include "DD4hep/DetectorProcessor.h" -#include "DD4hep/ConditionsProcessor.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsSlice.h" -#include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsRepository.h" -#include "DDCond/ConditionsManagerObject.h" +#include +#include +#include +#include +#include +#include + +// C/C++ include files #include -using namespace std; using namespace dd4hep; using namespace dd4hep::cond; @@ -47,7 +51,7 @@ static int ddcond_install_cond_mgr (Detector& description, int argc, char** argv Handle mgr(description.extension(false)); if ( !mgr.isValid() ) { bool arg_error = false; - string factory = "DD4hep_ConditionsManager_Type1"; + std::string factory = "DD4hep_ConditionsManager_Type1"; for(int i = 0; i < argc && argv[i]; ++i) { if ( 0 == ::strncmp("-type",argv[i],4) ) factory = argv[++i]; @@ -58,14 +62,14 @@ static int ddcond_install_cond_mgr (Detector& description, int argc, char** argv } if ( arg_error ) { /// Help printout describing the basic command line interface - cout << + std::cout << "Usage: -plugin -arg [-arg] \n" " name: factory name DD4hep_ConditionsManagerInstaller \n" " -type Manager type. \n" " Default: ConditionsManagerObject_Type1_t \n" " -handle Pointer to Handle to pass pointer \n" " to the caller. \n" - "\tArguments given: " << arguments(argc,argv) << endl << flush; + "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush; ::exit(EINVAL); } ConditionsManagerObject* obj = createPlugin(factory,description); @@ -99,7 +103,7 @@ DECLARE_APPLY(DD4hep_ConditionsManagerInstaller,ddcond_install_cond_mgr) * \version 1.0 * \date 01/04/2016 */ -static ConditionsSlice* ddcond_prepare(Detector& description, const string& iov_typ, long iov_val, int argc, char** argv) { +static ConditionsSlice* ddcond_prepare(Detector& description, const std::string& iov_typ, long iov_val, int argc, char** argv) { const IOVType* iovtype = 0; long iovvalue = iov_val; ConditionsManager manager = ConditionsManager::from(description); @@ -119,8 +123,8 @@ static ConditionsSlice* ddcond_prepare(Detector& description, const string& iov_ "++ Unknown IOV value supplied for iov type %s.",iovtype->str().c_str()); IOV iov(iovtype,iovvalue); - shared_ptr content(new ConditionsContent()); - unique_ptr slice(new ConditionsSlice(manager,content)); + std::shared_ptr content(new ConditionsContent()); + std::unique_ptr slice(new ConditionsSlice(manager,content)); cond::fill_content(manager,*content,*iovtype); manager.prepare(iov, *slice); printout(INFO,"Conditions", @@ -139,7 +143,7 @@ static ConditionsSlice* ddcond_prepare(Detector& description, const string& iov_ * \date 01/04/2016 */ static int ddcond_conditions_pool_processor(Detector& description, bool process_pool, bool process_conditions, int argc, char** argv) { - unique_ptr proc(createProcessor(description,argc,argv)); + std::unique_ptr proc(createProcessor(description,argc,argv)); ConditionsManager manager = ConditionsManager::from(description); const auto types = manager.iovTypesUsed(); @@ -194,7 +198,7 @@ static int ddcond_conditions_pool_print(Detector& description, bool print_condit if ( argc > 0 ) { for(int i = 0; i < argc; ++i) { if ( argv[i] && 0 == ::strncmp(argv[i],"-processor",3) ) { - vector args; + std::vector args; for(int j=i; j= 2 ) { - string iov_typ = argv[0]; + std::string iov_typ = argv[0]; IOV::Key::first_type iov_key = *(IOV::Key::first_type*)argv[1]; dd4hep_ptr slice(ddcond_prepare(description,iov_typ,iov_key,argc,argv)); UserPool* pool = slice->pool.get(); @@ -365,8 +369,8 @@ DECLARE_APPLY(DD4hep_ConditionsSynchronize,ddcond_synchronize_conditions) */ static long ddcond_clean_conditions(Detector& description, int argc, char** argv) { if ( argc > 0 ) { - string iov_type = argv[0]; - int max_age = *(int*)argv[1]; + std::string iov_type = argv[0]; + int max_age = *(int*)argv[1]; printout(INFO,"Conditions", "+++ ConditionsUpdate: Cleaning conditions... type:%s max age:%d", iov_type.c_str(), max_age); @@ -389,11 +393,10 @@ DECLARE_APPLY(DD4hep_ConditionsClean,ddcond_clean_conditions) * \version 1.0 * \date 17/11/2016 */ -#include "DD4hep/PluginTester.h" template static void* create_printer(Detector& description, int argc,char** argv) { - PrintLevel print_level = INFO; - string prefix = "", name = ""; + PrintLevel print_level = INFO; + std::string prefix = "", name = ""; int flags = 0, have_pool = 0, arg_error = false; for(int i=0; i -arg [-arg] \n" " name: factory name(s) DD4hep_ConditionsPrinter, \n" " dd4hep_AlignmentsPrinter \n" @@ -421,7 +424,7 @@ static void* create_printer(Detector& description, int argc,char** argv) { " -pool Attach conditions user pool from \n" " PluginTester's slice instance attached. \n\n" " -print Printout level for the printer object. \n" - "\tArguments given: " << arguments(argc,argv) << endl << flush; + "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush; ::exit(EINVAL); } DetElement world = description.world(); @@ -436,8 +439,7 @@ static void* create_printer(Detector& description, int argc,char** argv) { if ( !name.empty() ) p->name = name; return (void*)dynamic_cast(createProcessorWrapper(p)); } -#include "DD4hep/ConditionsPrinter.h" -#include "DD4hep/AlignmentsPrinter.h" + static void* create_cond_printer(Detector& description, int argc,char** argv) { return create_printer(description,argc,argv); } @@ -456,7 +458,7 @@ DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsPrinter,create_cond_printer) */ static long ddcond_create_repository(Detector& description, int argc, char** argv) { bool arg_error = false; - string output = ""; + std::string output = ""; for(int i=0; i -arg [-arg] \n" " name: factory name DD4hep_ConditionsCreateRepository \n\n" " -output Output file name. \n\n" - "\tArguments given: " << arguments(argc,argv) << endl << flush; + "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush; ::exit(EINVAL); } printout(INFO,"Conditions", @@ -492,7 +494,7 @@ DECLARE_APPLY(DD4hep_ConditionsCreateRepository,ddcond_create_repository) static long ddcond_dump_repository(Detector& /* description */, int argc, char** argv) { typedef ConditionsRepository::Data Data; bool arg_error = false; - string input = ""; + std::string input = ""; Data data; for(int i=0; i -arg [-arg] \n" " name: factory name DD4hep_ConditionsDumpRepository \n\n" " -input Input file name. \n\n" - "\tArguments given: " << arguments(argc,argv) << endl << flush; + "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush; ::exit(EINVAL); } printout(INFO,"Conditions","+++ ConditionsRepository: Dumping %s",input.c_str()); @@ -514,7 +516,7 @@ static long ddcond_dump_repository(Detector& /* description */, int argc, char** printout(INFO,"Repository","%-8s %-60s %-60s","Key","Name","Address"); for(Data::const_iterator i=data.begin(); i!=data.end(); ++i) { const ConditionsRepository::Entry& e = *i; - string add = e.address; + std::string add = e.address; if ( add.length() > 80 ) add = e.address.substr(0,60) + "..."; printout(INFO,"Repository","%16llX %s",e.key,e.name.c_str()); printout(INFO,"Repository"," -> %s",e.address.c_str()); @@ -538,7 +540,7 @@ TO BE DONE!!! */ static long ddcond_load_repository(Detector& /* description */, int argc, char** argv) { if ( argc > 0 ) { - string input = argv[0]; + std::string input = argv[0]; printout(INFO,"Conditions","+++ ConditionsRepository: Loading %s",input.c_str()); ConditionsRepository::Data data; ConditionsRepository().load(input, data); diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp index 797a8f27b..3112ba2e9 100644 --- a/DDCond/src/plugins/ConditionsRepositoryParser.cpp +++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp @@ -12,20 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "XML/Conversions.h" -#include "XML/XMLParsers.h" -#include "XML/DocumentHandler.h" -#include "DD4hep/Path.h" -#include "DD4hep/Printout.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/AlignmentData.h" -#include "DD4hep/OpaqueDataBinder.h" -#include "DD4hep/DetFactoryHelper.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "DDCond/ConditionsTags.h" -#include "DDCond/ConditionsManager.h" +#include +#include // C/C++ include files #include @@ -68,15 +68,13 @@ namespace dd4hep { template <> void Converter::operator()(xml_h seq) const; } -using std::string; -using namespace dd4hep; using namespace dd4hep::cond; /// Anonymous local stuff only used in this module namespace { /// Module print level - static PrintLevel s_parseLevel = DEBUG; + static dd4hep::PrintLevel s_parseLevel = dd4hep::DEBUG; /// Local helper class to interprete XML conditions /** @@ -85,12 +83,12 @@ namespace { * \date 01/11/2016 */ struct ConversionArg { - DetElement detector; + dd4hep::DetElement detector; ConditionsPool* pool; ConditionsManager manager; ConversionArg() = delete; ConversionArg(const ConversionArg&) = delete; - ConversionArg(DetElement det, ConditionsManager m) : detector(det), pool(0), manager(m) + ConversionArg(dd4hep::DetElement det, ConditionsManager m) : detector(det), pool(0), manager(m) { } ConversionArg& operator=(const ConversionArg&) = delete; }; @@ -102,17 +100,17 @@ namespace { * \date 01/11/2016 */ struct CurrentDetector { - DetElement detector; - ConversionArg* arg; + dd4hep::DetElement detector; + ConversionArg* arg; CurrentDetector(ConversionArg* a) : arg(a) { detector = arg->detector; } ~CurrentDetector() { arg->detector = detector; } - void set(const string& path) { + void set(const std::string& path) { if ( !path.empty() ) { - arg->detector = detail::tools::findDaughterElement(detector,path); + arg->detector = dd4hep::detail::tools::findDaughterElement(detector,path); } } }; @@ -142,24 +140,24 @@ namespace { * \version 1.0 * \date 01/11/2016 */ - Condition create_condition(DetElement det, xml_h e) { + dd4hep::Condition create_condition(dd4hep::DetElement det, xml_h e) { xml_dim_t elt(e); - string tag = elt.tag(); - string typ = elt.hasAttr(_U(type)) ? elt.typeStr() : tag; - string nam = elt.hasAttr(_U(name)) ? elt.nameStr() : tag; - string add = xml::DocumentHandler::system_path(e); - string cond_nam = det.path()+"#"+nam; - Condition cond(cond_nam, typ); - cond->hash = ConditionKey::hashCode(det, nam); - printout(s_parseLevel,"XMLConditions","++ Processing condition tag:%s name:%s type:%s [%s] hash:%016X det:%p", - tag.c_str(), cond.name(), typ.c_str(), - Path(add).filename().c_str(), cond.key(), det.ptr()); + std::string tag = elt.tag(); + std::string typ = elt.hasAttr(_U(type)) ? elt.typeStr() : tag; + std::string nam = elt.hasAttr(_U(name)) ? elt.nameStr() : tag; + std::string add = xml_handler_t::system_path(e); + std::string cond_nam = det.path()+"#"+nam; + dd4hep::Condition cond(cond_nam, typ); + cond->hash = dd4hep::ConditionKey::hashCode(det, nam); + dd4hep::printout(s_parseLevel,"XMLConditions","++ Processing condition tag:%s name:%s type:%s [%s] hash:%016X det:%p", + tag.c_str(), cond.name(), typ.c_str(), + dd4hep::Path(add).filename().c_str(), cond.key(), det.ptr()); #if !defined(DD4HEP_MINIMAL_CONDITIONS) cond->address = add; cond->value = ""; cond->validity = ""; if ( elt.hasAttr(_U(comment)) ) { - cond->comment = elt.attr(_U(comment)); + cond->comment = elt.attr(_U(comment)); } #endif //ConditionsKeyAssign(det).addKey(cond.name()); @@ -172,19 +170,19 @@ namespace { * \version 1.0 * \date 01/11/2016 */ - template Condition bind_condition(const BINDER& bnd, - DetElement det, - xml_h e, - const std::string& type="") + template dd4hep::Condition bind_condition(const BINDER& bnd, + dd4hep::DetElement det, + xml_h e, + const std::string& type="") { xml_dim_t elt(e); - string typ = type.empty() ? elt.typeStr() : type; - string val = elt.hasAttr(_U(value)) ? elt.valueStr() : elt.text(); - Condition con = create_condition(det, e); - string unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : string(""); + std::string typ = type.empty() ? elt.typeStr() : type; + std::string val = elt.hasAttr(_U(value)) ? elt.valueStr() : elt.text(); + dd4hep::Condition con = create_condition(det, e); + std::string unit = elt.hasAttr(_U(unit)) ? elt.attr(_U(unit)) : std::string(""); if ( !unit.empty() ) val += "*"+unit; con->value = val; - detail::OpaqueDataBinder::bind(bnd, con, typ, val); + dd4hep::detail::OpaqueDataBinder::bind(bnd, con, typ, val); return con; } } @@ -199,11 +197,11 @@ namespace dd4hep { * \date 01/04/2014 */ template <> void Converter::operator()(xml_h element) const { - xml_dim_t e = element; - string nam = e.nameStr(); - size_t id = e.id() >= 0 ? e.id() : INT_MAX; + xml_dim_t e = element; + std::string nam = e.nameStr(); + std::size_t id = e.id() >= 0 ? e.id() : INT_MAX; ConversionArg* arg = _param(); - printout(s_parseLevel,"XMLConditions","++ Registering IOV type: [%d]: %s",int(id),nam.c_str()); + dd4hep::printout(s_parseLevel,"XMLConditions","++ Registering IOV type: [%d]: %s",int(id),nam.c_str()); const IOVType* iov_type = arg->manager.registerIOVType(id,nam).second; if ( !iov_type ) { except("XMLConditions","Failed to register iov type: [%d]: %s",int(id),nam.c_str()); @@ -217,15 +215,15 @@ namespace dd4hep { * \date 01/04/2014 */ template <> void Converter::operator()(xml_h element) const { - xml_dim_t e = element; - string val = e.attr(_UC(validity)); - ConversionArg* arg = _param(); + xml_dim_t e = element; + std::string val = e.attr(_UC(validity)); + ConversionArg* arg = _param(); CurrentPool pool(arg); pool.set(arg->manager.registerIOV(val)); if ( e.hasAttr(_U(ref)) ) { - string ref = e.attr(_U(ref)); - printout(s_parseLevel,"XMLConditions","++ Reading IOV file: %s -> %s",val.c_str(),ref.c_str()); + std::string ref = e.attr(_U(ref)); + dd4hep::printout(s_parseLevel,"XMLConditions","++ Reading IOV file: %s -> %s",val.c_str(),ref.c_str()); xml::DocumentHolder doc(xml::DocumentHandler().load(element, element.attr_value(_U(ref)))); Converter(description,param,optional)(doc.root()); return; @@ -247,8 +245,8 @@ namespace dd4hep { } for( xml_coll_t c(element,_UC(property)); c; ++c) { xml_dim_t d = c; - string nam = d.nameStr(); - string val = d.valueStr(); + std::string nam = d.nameStr(); + std::string val = d.valueStr(); try { printout(s_parseLevel,"XMLConditions","++ Setup conditions Manager[%s] = %s", nam.c_str(),val.c_str()); @@ -270,8 +268,8 @@ namespace dd4hep { * \date 01/04/2014 */ template <> void Converter::operator()(xml_h e) const { - ConversionArg* arg = _param(); - Condition con = bind_condition(detail::ValueBinder(), arg->detector, e); + ConversionArg* arg = _param(); + dd4hep::Condition con = bind_condition(detail::ValueBinder(), arg->detector, e); arg->manager.registerUnlocked(*arg->pool, con); } @@ -284,8 +282,8 @@ namespace dd4hep { * \date 01/04/2014 */ template <> void Converter::operator()(xml_h e) const { - ConversionArg* arg = _param(); - Condition con = bind_condition(detail::ValueBinder(), arg->detector, e, "double"); + ConversionArg* arg = _param(); + dd4hep::Condition con = bind_condition(detail::ValueBinder(), arg->detector, e, "double"); con->setFlag(Condition::PRESSURE); arg->manager.registerUnlocked(*arg->pool, con); } @@ -299,8 +297,8 @@ namespace dd4hep { * \date 01/04/2014 */ template <> void Converter::operator()(xml_h e) const { - ConversionArg* arg = _param(); - Condition con = bind_condition(detail::ValueBinder(), arg->detector, e, "double"); + ConversionArg* arg = _param(); + dd4hep::Condition con = bind_condition(detail::ValueBinder(), arg->detector, e, "double"); con->setFlag(Condition::TEMPERATURE); arg->manager.registerUnlocked(*arg->pool, con); } @@ -312,8 +310,8 @@ namespace dd4hep { * \date 01/04/2014 */ template <> void Converter::operator()(xml_h e) const { - ConversionArg* arg = _param(); - Condition con = create_condition(arg->detector, e); + ConversionArg* arg = _param(); + dd4hep::Condition con = create_condition(arg->detector, e); xml::parse_sequence(e, con->data); arg->manager.registerUnlocked(*arg->pool, con); } @@ -325,8 +323,8 @@ namespace dd4hep { * \date 01/04/2014 */ template <> void Converter::operator()(xml_h e) const { - ConversionArg* arg = _param(); - Condition con = create_condition(arg->detector, e); + ConversionArg* arg = _param(); + dd4hep::Condition con = create_condition(arg->detector, e); xml::parse_mapping(e, con->data); arg->manager.registerUnlocked(*arg->pool, con); } @@ -340,7 +338,7 @@ namespace dd4hep { template <> void Converter::operator()(xml_h e) const { xml_h child_rot, child_pos, child_piv; ConversionArg* arg = _param(); - Condition con = create_condition(arg->detector, e); + dd4hep::Condition con = create_condition(arg->detector, e); //Delta& del = con.bind(); xml::parse_delta(e, con->data); con->setFlag(Condition::ALIGNMENT_DELTA); @@ -358,7 +356,7 @@ namespace dd4hep { ConversionArg* arg = _param(); CurrentDetector detector(arg); if ( elt.hasAttr(_U(path)) ) { - detector.set(e.attr(_U(path))); + detector.set(e.attr(_U(path))); printout(s_parseLevel,"XMLConditions","++ Processing condition for:%s", arg->detector.path().c_str()); } @@ -395,7 +393,7 @@ namespace dd4hep { */ template <> void Converter::operator()(xml_h e) const { xml_comp_t elt(e); - string tag = elt.tag(); + std::string tag = elt.tag(); if ( tag == "repository" ) Converter(description,param,optional)(e); else if ( tag == "manager" ) @@ -430,36 +428,35 @@ namespace dd4hep { * \version 1.0 * \date 01/04/2014 */ -static long setup_repository_loglevel(Detector& /* description */, int argc, char** argv) { +static long setup_repository_loglevel(dd4hep::Detector& /* description */, int argc, char** argv) { if ( argc == 1 ) { - s_parseLevel = printLevel(argv[0]); + s_parseLevel = dd4hep::printLevel(argv[0]); return 1; } - except("ConditionsXMLRepositoryPrintLevel","++ Invalid plugin arguments: %s", - arguments(argc,argv).c_str()); + dd4hep::except("ConditionsXMLRepositoryPrintLevel","++ Invalid plugin arguments: %s", + dd4hep::arguments(argc,argv).c_str()); return 0; } DECLARE_APPLY(DD4hep_ConditionsXMLRepositoryPrintLevel,setup_repository_loglevel) -#include "DD4hep/DD4hepUI.h" - +#include /// Basic entry point to read alignment conditions files /** * \author M.Frank * \version 1.0 * \date 01/04/2014 */ -static long setup_repository_Conditions(Detector& description, int argc, char** argv) { +static long setup_repository_Conditions(dd4hep::Detector& description, int argc, char** argv) { if ( argc == 1 ) { - detail::DD4hepUI ui(description); - string fname(argv[0]); + dd4hep::detail::DD4hepUI ui(description); + std::string fname(argv[0]); ConditionsManager mgr(ui.conditionsMgr()); ConversionArg arg(description.world(), mgr); - xml::DocumentHolder doc(xml::DocumentHandler().load(fname)); - (dd4hep::Converter(description,&arg))(doc.root()); + xml_doc_holder_t doc(xml_handler_t().load(fname)); + (dd4hep::Converter(description,&arg))(doc.root()); return 1; } - except("XML_DOC_READER","Invalid number of arguments to interprete conditions: %d != %d.",argc,1); + dd4hep::except("XML_DOC_READER","Invalid number of arguments to interprete conditions: %d != %d.",argc,1); return 0; } DECLARE_APPLY(DD4hep_ConditionsXMLRepositoryParser,setup_repository_Conditions) diff --git a/DDCond/src/plugins/ConditionsRepositoryWriter.cpp b/DDCond/src/plugins/ConditionsRepositoryWriter.cpp index 91e74498b..219642337 100644 --- a/DDCond/src/plugins/ConditionsRepositoryWriter.cpp +++ b/DDCond/src/plugins/ConditionsRepositoryWriter.cpp @@ -14,9 +14,9 @@ #define DD4HEP_DDCOND_CONDITIONSREPOSITORYWRITER_H // Framework include files -#include "DD4hep/Detector.h" -#include "XML/XMLElements.h" -#include "DDCond/ConditionsManager.h" +#include +#include +#include // C/C++ include files @@ -90,20 +90,20 @@ namespace dd4hep { //========================================================================== // Framework include files -#include "XML/XMLElements.h" -#include "XML/DocumentHandler.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Alignments.h" -#include "DD4hep/AlignmentData.h" -#include "DD4hep/OpaqueDataBinder.h" -#include "DD4hep/ConditionsProcessor.h" -#include "DD4hep/DetFactoryHelper.h" -#include "DD4hep/detail/ConditionsInterna.h" -#include "DD4hep/detail/AlignmentsInterna.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "DDCond/ConditionsTags.h" -#include "DDCond/ConditionsSlice.h" -#include "DDCond/ConditionsManagerObject.h" +#include +#include +#include // C/C++ include files #include @@ -112,18 +112,17 @@ namespace dd4hep { #include #include -using std::string; -using std::shared_ptr; -using std::stringstream; -using namespace dd4hep; using namespace dd4hep::cond; namespace units = dd4hep; +namespace xml = dd4hep::xml; +using dd4hep::printout; +using dd4hep::_toString; /// Anonymous local stuff only used in this module namespace { /// Module print level - static PrintLevel s_printLevel = INFO; + static dd4hep::PrintLevel s_printLevel = dd4hep::INFO; class pressure; class temperature; @@ -134,9 +133,9 @@ namespace { xml::Element root; public: PropertyDumper(xml::Element p) : root(p) {} - void operator()(const std::pair& p) const { + void operator()(const std::pair& p) const { xml::Element e = xml::Element(root.document(),_UC(property)); - string val = p.second.str(); + std::string val = p.second.str(); if ( val[0] == '\'' ) val = p.second.str().c_str()+1; if ( !val.empty() && val[val.length()-1] == '\'' ) val[val.length()-1] = 0; e.setAttr(_U(name), p.first); @@ -145,9 +144,9 @@ namespace { } }; - template xml::Element _convert(xml::Element par, Condition c); + template xml::Element _convert(xml::Element par, dd4hep::Condition c); - xml::Element make(xml::Element e, Condition c) { + xml::Element make(xml::Element e, dd4hep::Condition c) { char hash[64]; std::string nam = c.name(); std::string cn = nam.substr(nam.find('#')+1); @@ -156,22 +155,22 @@ namespace { e.setAttr(_U(key),hash); return e; } - xml::Element _convert(xml::Element par, const Translation3D& tr) { + xml::Element _convert(xml::Element par, const dd4hep::Translation3D& tr) { xml::Element e = xml::Element(par.document(),_U(pivot)); - const Translation3D::Vector& v = tr.Vect(); + const dd4hep::Translation3D::Vector& v = tr.Vect(); e.setAttr(_U(x),_toString(v.X()/dd4hep::mm,"%f*mm")); e.setAttr(_U(y),_toString(v.Y()/dd4hep::mm,"%f*mm")); e.setAttr(_U(z),_toString(v.Z()/dd4hep::mm,"%f*mm")); return e; } - xml::Element _convert(xml::Element par, const Position& pos) { + xml::Element _convert(xml::Element par, const dd4hep::Position& pos) { xml::Element e = xml::Element(par.document(),_U(position)); e.setAttr(_U(x),_toString(pos.X()/dd4hep::mm,"%f*mm")); e.setAttr(_U(y),_toString(pos.Y()/dd4hep::mm,"%f*mm")); e.setAttr(_U(z),_toString(pos.Z()/dd4hep::mm,"%f*mm")); return e; } - xml::Element _convert(xml::Element par, const RotationZYX& rot) { + xml::Element _convert(xml::Element par, const dd4hep::RotationZYX& rot) { xml::Element e = xml::Element(par.document(),_U(rotation)); double z, y, x; rot.GetComponents(z,y,x); @@ -180,80 +179,80 @@ namespace { e.setAttr(_U(z),_toString(z/dd4hep::rad,"%f*rad")); return e; } - template <> xml::Element _convert(xml::Element par, Condition c) { + template <> xml::Element _convert(xml::Element par, dd4hep::Condition c) { xml::Element v = make(xml::Element(par.document(),_U(value)),c); - OpaqueData& data = c.data(); + dd4hep::OpaqueData& data = c.data(); v.setAttr(_U(type),data.dataType()); v.setAttr(_U(value),data.str()); return v; } - template <> xml::Element _convert(xml::Element par, Condition c) { + template <> xml::Element _convert(xml::Element par, dd4hep::Condition c) { xml::Element press = make(xml::Element(par.document(),_UC(pressure)),c); press.setAttr(_U(value),c.get()/(100e0*units::pascal)); press.setAttr(_U(unit),"hPa"); return press; } - template <> xml::Element _convert(xml::Element par, Condition c) { + template <> xml::Element _convert(xml::Element par, dd4hep::Condition c) { xml::Element temp = make(xml::Element(par.document(),_UC(temperature)),c); temp.setAttr(_U(value),c.get()/units::kelvin); temp.setAttr(_U(unit),"kelvin"); return temp; } - template <> xml::Element _convert(xml::Element par, Condition c) { - xml::Element align = make(xml::Element(par.document(),_UC(alignment_delta)),c); - const Delta& delta = c.get(); - if ( delta.flags&Delta::HAVE_TRANSLATION ) + template <> xml::Element _convert(xml::Element par, dd4hep::Condition c) { + xml::Element align = make(xml::Element(par.document(),_UC(alignment_delta)),c); + const dd4hep::Delta& delta = c.get(); + if ( delta.flags&dd4hep::Delta::HAVE_TRANSLATION ) align.append(_convert(align,delta.translation)); - if ( delta.flags&Delta::HAVE_ROTATION ) + if ( delta.flags&dd4hep::Delta::HAVE_ROTATION ) align.append(_convert(align,delta.rotation)); - if ( delta.flags&Delta::HAVE_PIVOT ) + if ( delta.flags&dd4hep::Delta::HAVE_PIVOT ) align.append(_convert(align,delta.pivot)); return align; } - template <> xml::Element _convert(xml::Element par, Condition c) { + template <> xml::Element _convert(xml::Element par, dd4hep::Condition c) { char hash[64]; - typedef ConditionKey::KeyMaker KM; - AlignmentCondition acond = c; - KM km(c.key()); - const Delta& delta = acond.data().delta; - xml::Element align(xml::Element(par.document(),_UC(alignment_delta))); - Condition::key_type key = KM(km.values.det_key,align::Keys::deltaKey).hash; + typedef dd4hep::ConditionKey::KeyMaker KM; + dd4hep::AlignmentCondition acond = c; + KM km(c.key()); + const dd4hep::Delta& delta = acond.data().delta; + xml::Element align(xml::Element(par.document(),_UC(alignment_delta))); + dd4hep::Condition::key_type key = KM(km.values.det_key,dd4hep::align::Keys::deltaKey).hash; ::snprintf(hash,sizeof(hash),"%llX",key); - align.setAttr(_U(name),align::Keys::deltaName); + align.setAttr(_U(name), dd4hep::align::Keys::deltaName); align.setAttr(_U(key),hash); - if ( delta.flags&Delta::HAVE_TRANSLATION ) + if ( delta.flags&dd4hep::Delta::HAVE_TRANSLATION ) align.append(_convert(align,delta.translation)); - if ( delta.flags&Delta::HAVE_ROTATION ) + if ( delta.flags&dd4hep::Delta::HAVE_ROTATION ) align.append(_convert(align,delta.rotation)); - if ( delta.flags&Delta::HAVE_PIVOT ) + if ( delta.flags&dd4hep::Delta::HAVE_PIVOT ) align.append(_convert(align,delta.pivot)); return align; } - xml::Element _seq(xml::Element v, Condition c, const char* tag, const char* match) { - OpaqueData& data = c.data(); - string typ = data.dataType(); + xml::Element _seq(xml::Element v, dd4hep::Condition c, const char* tag, const char* match) { + dd4hep::OpaqueData& data = c.data(); + std::string typ = data.dataType(); size_t len = ::strlen(match); size_t idx = typ.find(match); size_t idq = typ.find(',',idx+len); - if ( idx != string::npos && idq != string::npos ) { - string subtyp = tag; + if ( idx != std::string::npos && idq != std::string::npos ) { + std::string subtyp = tag; subtyp += "["+typ.substr(idx+len,idq-idx-len)+"]"; v.setAttr(_U(type),subtyp); xml::Handle_t(v.ptr()).setText(data.str()); return v; } - except("Writer","++ Unknwon XML conversion to type: %s",typ.c_str()); + dd4hep::except("Writer","++ Unknwon XML conversion to type: %s",typ.c_str()); return v; } - template <> xml::Element _convert >(xml::Element par, Condition c) { + template <> xml::Element _convert >(xml::Element par, dd4hep::Condition c) { xml::Element v = make(xml::Element(par.document(),_UC(sequence)),c); return _seq(v,c,"vector","::vector<"); } - template <> xml::Element _convert >(xml::Element par, Condition c) { + template <> xml::Element _convert >(xml::Element par, dd4hep::Condition c) { xml::Element v = make(xml::Element(par.document(),_UC(sequence)),c); return _seq(v,c,"list","::list<"); } - template <> xml::Element _convert >(xml::Element par, Condition c) { + template <> xml::Element _convert >(xml::Element par, dd4hep::Condition c) { xml::Element v = make(xml::Element(par.document(),_UC(sequence)),c); return _seq(v,c,"set","::set<"); } @@ -291,9 +290,9 @@ size_t ConditionsXMLRepositoryWriter::collect(xml::Element root, ConditionsSlice root.append(repo); repo.append(iov); - ::snprintf(text,sizeof(text),"%ld,%ld#%s", - long(validity.keyData.first), long(validity.keyData.second), - validity.iovType->name.c_str()); + std::snprintf(text,sizeof(text),"%ld,%ld#%s", + long(validity.keyData.first), long(validity.keyData.second), + validity.iovType->name.c_str()); iov.setAttr(_UC(validity),text); return collect(iov,slice,slice.manager->detectorDescription().world()); } @@ -334,7 +333,7 @@ size_t ConditionsXMLRepositoryWriter::collect(xml::Element root, std::vector conds; conditionsCollector(slice,conds)(detector); if ( !conds.empty() ) { - stringstream comment; + std::stringstream comment; Condition cond_align, cond_delta; xml::Element conditions = xml::Element(root.document(),_UC(detelement)); conditions.setAttr(_U(path),detector.path()); @@ -366,7 +365,7 @@ size_t ConditionsXMLRepositoryWriter::collect(xml::Element root, cond_delta = c; } else { - const OpaqueData& data = c.data(); + const dd4hep::OpaqueData& data = c.data(); const std::type_info& typ = data.typeInfo(); #if defined(DD4HEP_HAVE_ALL_PARSERS) if ( typ == typeid(char) || typ == typeid(unsigned char) || @@ -374,11 +373,11 @@ size_t ConditionsXMLRepositoryWriter::collect(xml::Element root, typ == typeid(int) || typ == typeid(unsigned int) || typ == typeid(long) || typ == typeid(unsigned long) || typ == typeid(float) || typ == typeid(double) || - typ == typeid(bool) || typ == typeid(string) ) + typ == typeid(bool) || typ == typeid(std::string) ) #else if ( typ == typeid(int) || typ == typeid(long) || typ == typeid(float) || typ == typeid(double) || - typ == typeid(bool) || typ == typeid(string) ) + typ == typeid(bool) || typ == typeid(std::string) ) #endif { conditions.append(_convert(conditions,c)); @@ -416,7 +415,7 @@ size_t ConditionsXMLRepositoryWriter::collect(xml::Element root, ++m_numConverted; } else if ( cond_delta.isValid() ) { - conditions.append(_convert(conditions,cond_delta)); + conditions.append(_convert(conditions,cond_delta)); ++m_numConverted; } } @@ -428,8 +427,8 @@ size_t ConditionsXMLRepositoryWriter::collect(xml::Element root, // ====================================================================================== /// Write the XML document structure to a file. -long ConditionsXMLRepositoryWriter::write(xml::Document doc, const string& output) const { - xml::DocumentHandler docH; +long ConditionsXMLRepositoryWriter::write(xml::Document doc, const std::string& output) const { + xml_handler_t docH; long ret = docH.output(doc, output); if ( !output.empty() ) { printout(INFO,"Writer","++ Successfully wrote %ld conditions (%ld unconverted) to file: %s", @@ -444,12 +443,12 @@ long ConditionsXMLRepositoryWriter::write(xml::Document doc, const string& outpu * \version 1.0 * \date 01/04/2014 */ -static long write_repository_conditions(Detector& description, int argc, char** argv) { +static long write_repository_conditions(dd4hep::Detector& description, int argc, char** argv) { ConditionsManager manager = ConditionsManager::from(description); - const IOVType* iovtype = 0; - long iovvalue = -1; - long mgr_prop = 0; - string output; + const dd4hep::IOVType* iovtype = 0; + long iovvalue = -1; + long mgr_prop = 0; + std::string output; for(int i=0; i Output file name. Default: stdout "); - printout(ALWAYS,"Plugin-Help"," -manager Add manager properties to the output. "); - printout(ALWAYS,"Plugin-Help"," -iov_type IOV type to be selected. "); - printout(ALWAYS,"Plugin-Help"," -iov_value IOV value to create the conditions snapshot."); + printout(dd4hep::ALWAYS,"Plugin-Help","Usage: dd4hep_XMLConditionsRepositoryWriter --opt [--opt] "); + printout(dd4hep::ALWAYS,"Plugin-Help"," -output Output file name. Default: stdout "); + printout(dd4hep::ALWAYS,"Plugin-Help"," -manager Add manager properties to the output. "); + printout(dd4hep::ALWAYS,"Plugin-Help"," -iov_type IOV type to be selected. "); + printout(dd4hep::ALWAYS,"Plugin-Help"," -iov_value IOV value to create the conditions snapshot."); ::exit(EINVAL); } } if ( 0 == iovtype ) - except("ConditionsPrepare","++ Unknown IOV type supplied."); + dd4hep::except("ConditionsPrepare","++ Unknown IOV type supplied."); if ( 0 > iovvalue ) - except("ConditionsPrepare", - "++ Unknown IOV value supplied for iov type %s.",iovtype->str().c_str()); + dd4hep::except("ConditionsPrepare", + "++ Unknown IOV value supplied for iov type %s.",iovtype->str().c_str()); - IOV iov(iovtype,iovvalue); - shared_ptr content(new ConditionsContent()); - shared_ptr slice(new ConditionsSlice(manager,content)); - cond::fill_content(manager,*content,*iovtype); + dd4hep::IOV iov(iovtype,iovvalue); + std::shared_ptr content(new ConditionsContent()); + std::shared_ptr slice(new ConditionsSlice(manager,content)); + dd4hep::cond::fill_content(manager,*content,*iovtype); ConditionsManager::Result cres = manager.prepare(iov, *slice); - printout(INFO,"Conditions", + printout(dd4hep::INFO, "Conditions", "++ Selected conditions: %7ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) for IOV:%-12s", cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing, iovtype ? iov.str().c_str() : "???"); @@ -507,16 +506,16 @@ DECLARE_APPLY(DD4hep_ConditionsXMLRepositoryWriter,write_repository_conditions) * \version 1.0 * \date 01/04/2014 */ -static long write_repository_manager(Detector& description, int argc, char** argv) { +static long write_repository_manager(dd4hep::Detector& description, int argc, char** argv) { ConditionsManager manager = ConditionsManager::from(description); - string output; + std::string output; for(int i=0; ii+1) output = argv[++i]; else if ( ::strncmp(argv[i],"-help",2) == 0 ) { - printout(ALWAYS,"Plugin-Help","Usage: dd4hep_XMLConditionsManagerWriter --opt [--opt] "); - printout(ALWAYS,"Plugin-Help"," -output Output file name. Default: stdout "); + printout(dd4hep::ALWAYS,"Plugin-Help","Usage: dd4hep_XMLConditionsManagerWriter --opt [--opt] "); + printout(dd4hep::ALWAYS,"Plugin-Help"," -output Output file name. Default: stdout "); ::exit(EINVAL); } } diff --git a/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp b/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp index 1c4425987..b52b29a09 100644 --- a/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp +++ b/DDCond/src/plugins/ConditionsSnapshotRootLoader.cpp @@ -15,9 +15,9 @@ #define DD4HEP_CONDITIONS_CONDIITONSSNAPSHOTROOTLOADER_H // Framework include files -#include "DDCond/ConditionsDataLoader.h" -#include "DDCond/ConditionsRootPersistency.h" -#include "DD4hep/Printout.h" +#include +#include +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -61,24 +61,22 @@ namespace dd4hep { } /* End namespace dd4hep */ #endif /* DD4HEP_CONDITIONS_CONDIITONSSNAPSHOTROOTLOADER_H */ -//#include "ConditionsSnapshotRootLoader.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Factories.h" -#include "DD4hep/PluginCreators.h" -#include "DD4hep/detail/ConditionsInterna.h" +//#include +#include +#include +#include +#include -#include "TFile.h" +#include // C/C++ include files #include // Forward declartions -using std::string; -using namespace dd4hep; using namespace dd4hep::cond; namespace { - void* create_loader(Detector& description, int argc, char** argv) { + void* create_loader(dd4hep::Detector& description, int argc, char** argv) { const char* name = argc>0 ? argv[0] : "XMLLoader"; ConditionsManagerObject* mgr = (ConditionsManagerObject*)(argc>0 ? argv[1] : 0); return new ConditionsSnapshotRootLoader(description,ConditionsManager(mgr),name); diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index d98152a2a..368c381f6 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -14,8 +14,8 @@ #define DDCOND_CONDITIONSMAPPEDUSERPOOL_H // Framework include files -#include "DDCond/ConditionsPool.h" -#include "DD4hep/ConditionsMap.h" +#include +#include // C/C++ include files #include @@ -151,41 +151,40 @@ namespace dd4hep { //========================================================================== // Framework include files -//#include "DDCond/ConditionsMappedPool.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Factories.h" -#include "DD4hep/InstanceCount.h" +//#include +#include +#include +#include -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsSelectors.h" -#include "DDCond/ConditionsDataLoader.h" -#include "DDCond/ConditionsManagerObject.h" -#include "DDCond/ConditionsDependencyHandler.h" +#include +#include +#include +#include +#include +// C/C++ include files #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::cond; namespace { - class SimplePrint : public Condition::Processor { + class SimplePrint : public dd4hep::Condition::Processor { /// Conditions callback for object processing - virtual int process(Condition) const override { return 1; } + virtual int process(dd4hep::Condition) const override { return 1; } /// Conditions callback for object processing - virtual int operator()(Condition) const override { return 1; } + virtual int operator()(dd4hep::Condition) const override { return 1; } /// Conditions callback for object processing in maps - virtual int operator()(const pair& i) const override { - Condition c = i.second; - printout(INFO,"UserPool","++ %16llX/%16llX Val:%s %s",i.first, c->hash, c->value.c_str(), c.str().c_str()); + virtual int operator()(const std::pair& i) const override { + dd4hep::Condition c = i.second; + dd4hep::printout(dd4hep::INFO,"UserPool","++ %16llX/%16llX Val:%s %s",i.first, c->hash, c->value.c_str(), c.str().c_str()); return 1; } }; - template struct MapSelector : public ConditionsSelect { + template struct MapSelector : public dd4hep::ConditionsSelect { T& m; MapSelector(T& o) : m(o) {} - bool operator()(Condition::Object* o) const + bool operator()(dd4hep::Condition::Object* o) const { return m.emplace(o->hash,o).second; } }; template MapSelector mapSelector(T& container) @@ -193,14 +192,14 @@ namespace { template struct Inserter { T& m; - IOV* iov; - Inserter(T& o, IOV* i=0) : m(o), iov(i) {} - void operator()(const Condition& c) { - Condition::Object* o = c.ptr(); + dd4hep::IOV* iov; + Inserter(T& o, dd4hep::IOV* i=0) : m(o), iov(i) {} + void operator()(const dd4hep::Condition& c) { + dd4hep::Condition::Object* o = c.ptr(); m.emplace(o->hash,o); if ( iov ) iov->iov_intersection(o->iov->key()); } - void operator()(const pair& e) { (*this)(e.second); } + void operator()(const std::pair& e) { (*this)(e.second); } }; } @@ -229,7 +228,7 @@ ConditionsMappedUserPool::~ConditionsMappedUserPool() { InstanceCount::decrement(this); } -template inline Condition::Object* +template inline dd4hep::Condition::Object* ConditionsMappedUserPool::i_findCondition(Condition::key_type key) const { typename MAPPING::const_iterator i=m_conditions.find(key); #if 0 @@ -263,7 +262,7 @@ size_t ConditionsMappedUserPool::size() const { /// Print pool content template -void ConditionsMappedUserPool::print(const string& opt) const { +void ConditionsMappedUserPool::print(const std::string& opt) const { const IOV* iov = &m_iov; printout(INFO,"UserPool","+++ %s Conditions for USER pool with IOV: %-32s [%4d entries]", opt.c_str(), iov->str().c_str(), size()); @@ -297,13 +296,13 @@ bool ConditionsMappedUserPool::exists(const ConditionKey& key) const /// Check if a condition exists in the pool and return it to the caller template -Condition ConditionsMappedUserPool::get(Condition::key_type hash) const { +dd4hep::Condition ConditionsMappedUserPool::get(Condition::key_type hash) const { return i_findCondition(hash); } /// Check if a condition exists in the pool and return it to the caller template -Condition ConditionsMappedUserPool::get(const ConditionKey& key) const { +dd4hep::Condition ConditionsMappedUserPool::get(const ConditionKey& key) const { return i_findCondition(key.hash); } @@ -323,13 +322,13 @@ ConditionsMappedUserPool::registerOne(const IOV& iov, } /// Do block insertions of conditions with identical IOV including registration to the manager -template size_t +template std::size_t ConditionsMappedUserPool::registerMany(const IOV& iov, - const vector& conds) { + const std::vector& conds) { if ( iov.iovType ) { ConditionsPool* pool = m_manager.registerIOV(*iov.iovType,iov.keyData); if ( pool ) { - size_t result = m_manager.blockRegister(*pool, conds); + std::size_t result = m_manager.blockRegister(*pool, conds); if ( result == conds.size() ) { for(auto c : conds) i_insert(c.ptr()); return result; @@ -364,12 +363,12 @@ bool ConditionsMappedUserPool::insert(DetElement detector, /// ConditionsMap overload: Access a condition template -Condition ConditionsMappedUserPool::get(DetElement detector, unsigned int item_key) const { +dd4hep::Condition ConditionsMappedUserPool::get(DetElement detector, unsigned int item_key) const { return get(ConditionKey::KeyMaker(detector.key(), item_key).hash); } /// No ConditionsMap overload: Access all conditions within a key range in the interval [lower,upper] -template std::vector +template std::vector ConditionsMappedUserPool::get(DetElement detector, Condition::itemkey_type lower, Condition::itemkey_type upper) const { @@ -379,9 +378,9 @@ ConditionsMappedUserPool::get(DetElement detector, } /// Specialization for std::map: Access all conditions within a given key range -template std::vector +template std::vector ConditionsMappedUserPool::get(Condition::key_type lower, Condition::key_type upper) const { - vector result; + std::vector result; if ( !m_conditions.empty() ) { typename MAPPING::const_iterator first = m_conditions.lower_bound(lower); for(; first != m_conditions.end(); ++first ) { @@ -442,9 +441,9 @@ bool ConditionsMappedUserPool::remove(Condition::key_type hash_key) /// Evaluate and register all derived conditions from the dependency list template -size_t ConditionsMappedUserPool::compute(const Dependencies& deps, - ConditionUpdateUserContext* user_param, - bool force) +std::size_t ConditionsMappedUserPool::compute(const Dependencies& deps, + ConditionUpdateUserContext* user_param, + bool force) { if ( !deps.empty() ) { Dependencies missing; @@ -484,10 +483,10 @@ size_t ConditionsMappedUserPool::compute(const Dependencies& deps, namespace { struct COMP { - typedef pair Dep; - typedef pair Cond; - typedef pair Info; - typedef pair Cond2; + typedef std::pair Dep; + typedef std::pair Cond; + typedef std::pair Info; + typedef std::pair Cond2; bool operator()(const Dep& a,const Cond& b) const { return a.first < b.first; } bool operator()(const Cond& a,const Dep& b) const { return a.first < b.first; } @@ -505,8 +504,8 @@ ConditionsMappedUserPool::prepare(const IOV& required, ConditionsSlice& slice, ConditionUpdateUserContext* user_param) { - typedef vector > CalcMissing; - typedef vector > CondMissing; + typedef std::vector > CalcMissing; + typedef std::vector > CondMissing; const auto& slice_cond = slice.content->conditions(); const auto& slice_calc = slice.content->derived(); auto& slice_miss_cond = slice.missingConditions(); @@ -519,8 +518,8 @@ ConditionsMappedUserPool::prepare(const IOV& required, // This is a critical operation, because we have to ensure the // IOV pools are ONLY manipulated by the current thread. // Otherwise the selection and the population are unsafe! - static mutex lock; - lock_guard guard(lock); + static std::mutex lock; + std::lock_guard guard(lock); m_conditions.clear(); slice_miss_cond.clear(); @@ -598,7 +597,7 @@ ConditionsMappedUserPool::prepare(const IOV& required, // if ( num_calc_miss > 0 ) { if ( do_load ) { - map deps(calc_missing.begin(),last_calc); + std::map deps(calc_missing.begin(),last_calc); ConditionsDependencyHandler handler(m_manager, *this, deps, user_param); /// 1rst pass: Compute/create the missing condiions handler.compute(); @@ -633,7 +632,7 @@ ConditionsMappedUserPool::load(const IOV& required, ConditionsSlice& slice, ConditionUpdateUserContext* /* user_param */) { - typedef vector > CondMissing; + typedef std::vector > CondMissing; const auto& slice_cond = slice.content->conditions(); auto& slice_miss_cond = slice.missingConditions(); bool do_load = m_manager->doLoadConditions(); @@ -644,8 +643,8 @@ ConditionsMappedUserPool::load(const IOV& required, // This is a critical operation, because we have to ensure the // IOV pools are ONLY manipulated by the current thread. // Otherwise the selection and the population are unsafe! - static mutex lock; - lock_guard guard(lock); + static std::mutex lock; + std::lock_guard guard(lock); m_conditions.clear(); slice_miss_cond.clear(); @@ -707,7 +706,7 @@ ConditionsMappedUserPool::compute(const IOV& required, ConditionsSlice& slice, ConditionUpdateUserContext* user_param) { - typedef vector > CalcMissing; + typedef std::vector > CalcMissing; const auto& slice_calc = slice.content->derived(); auto& slice_miss_calc = slice.missingDerivations(); bool do_load = m_manager->doLoadConditions(); @@ -718,8 +717,8 @@ ConditionsMappedUserPool::compute(const IOV& required, // This is a critical operation, because we have to ensure the // IOV pools are ONLY manipulated by the current thread. // Otherwise the selection and the population are unsafe! - static mutex lock; - lock_guard guard(lock); + static std::mutex lock; + std::lock_guard guard(lock); slice_miss_calc.clear(); CalcMissing calc_missing(slice_calc.size()+m_conditions.size()); @@ -741,7 +740,7 @@ ConditionsMappedUserPool::compute(const IOV& required, // if ( num_calc_miss > 0 ) { if ( do_load ) { - map deps(calc_missing.begin(),last_calc); + std::map deps(calc_missing.begin(),last_calc); ConditionsDependencyHandler handler(m_manager, *this, deps, user_param); /// 1rst pass: Compute/create the missing condiions @@ -778,7 +777,7 @@ namespace dd4hep { /// Namespace for implementation details of the AIDA detector description toolkit namespace cond { - typedef unordered_map umap_t; + typedef std::unordered_map umap_t; /// Access all conditions within a given key range /** Specialization necessary, since unordered maps have no lower bound. @@ -796,7 +795,7 @@ namespace dd4hep { */ template<> std::vector ConditionsMappedUserPool::get(Condition::key_type lower, Condition::key_type upper) const { - vector result; + std::vector result; for( const auto& e : m_conditions ) { if ( e.second->hash >= lower && e.second->hash <= upper ) result.emplace_back(e.second); @@ -808,24 +807,24 @@ namespace dd4hep { namespace { template - void* create_pool(Detector&, int argc, char** argv) { + void* create_pool(dd4hep::Detector&, int argc, char** argv) { if ( argc > 1 ) { ConditionsManagerObject* m = (ConditionsManagerObject*)argv[0]; ConditionsIOVPool* p = (ConditionsIOVPool*)argv[1]; UserPool* pool = new ConditionsMappedUserPool(m, p); return pool; } - except("ConditionsMappedUserPool","++ Insufficient arguments: arg[0] = ConditionManager!"); + dd4hep::except("ConditionsMappedUserPool","++ Insufficient arguments: arg[0] = ConditionManager!"); return 0; } } // Factory for the user pool using a binary tree map -void* create_map_user_pool(Detector& description, int argc, char** argv) -{ return create_pool >(description, argc, argv); } +void* create_map_user_pool(dd4hep::Detector& description, int argc, char** argv) +{ return create_pool >(description, argc, argv); } DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMapUserPool, create_map_user_pool) // Factory for the user pool using a binary tree map -void* create_unordered_map_user_pool(Detector& description, int argc, char** argv) -{ return create_pool >(description, argc, argv); } +void* create_unordered_map_user_pool(dd4hep::Detector& description, int argc, char** argv) +{ return create_pool >(description, argc, argv); } DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsUnorderedMapUserPool, create_map_user_pool) diff --git a/DDCond/src/plugins/ConditionsXmlLoader.cpp b/DDCond/src/plugins/ConditionsXmlLoader.cpp index 1967bb814..71ae953e7 100644 --- a/DDCond/src/plugins/ConditionsXmlLoader.cpp +++ b/DDCond/src/plugins/ConditionsXmlLoader.cpp @@ -15,8 +15,8 @@ #define DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H // Framework include files -#include "DDCond/ConditionsDataLoader.h" -#include "DD4hep/Printout.h" +#include +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -44,18 +44,18 @@ namespace dd4hep { /// Default destructor virtual ~ConditionsXmlLoader(); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load_single(key_type key, - const IOV& req_validity, - RangeConditions& conditions); + virtual std::size_t load_single(key_type key, + const IOV& req_validity, + RangeConditions& conditions); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load_range( key_type key, - const IOV& req_validity, - RangeConditions& conditions); + virtual std::size_t load_range( key_type key, + const IOV& req_validity, + RangeConditions& conditions); /// Optimized update using conditions slice data - virtual size_t load_many( const IOV& /* req_validity */, - RequiredItems& /* work */, - LoadedItems& /* loaded */, - IOV& /* conditions_validity */) + virtual std::size_t load_many( const IOV& /* req_validity */, + RequiredItems& /* work */, + LoadedItems& /* loaded */, + IOV& /* conditions_validity */) { except("ConditionsLoader","+++ update: Invalid call!"); return 0; @@ -65,26 +65,24 @@ namespace dd4hep { } /* End namespace dd4hep */ #endif /* DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H */ -//#include "ConditionsXmlLoader.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Factories.h" -#include "DD4hep/PluginCreators.h" -#include "DD4hep/detail/ConditionsInterna.h" +// #include +#include +#include +#include +#include -#include "XML/XMLElements.h" -#include "XML/DocumentHandler.h" -#include "DDCond/ConditionsEntry.h" +#include +#include +#include // C/C++ include files #include // Forward declartions -using std::string; -using namespace dd4hep; using namespace dd4hep::cond; namespace { - void* create_loader(Detector& description, int argc, char** argv) { + void* create_loader(dd4hep::Detector& description, int argc, char** argv) { const char* name = argc>0 ? argv[0] : "XMLLoader"; ConditionsManagerObject* mgr = (ConditionsManagerObject*)(argc>0 ? argv[1] : 0); return new ConditionsXmlLoader(description,ConditionsManager(mgr),name); @@ -107,8 +105,8 @@ size_t ConditionsXmlLoader::load_source(const std::string& nam, const IOV& req_validity, RangeConditions& conditions) { - size_t len = conditions.size(); - string fac = "XMLConditionsParser"; + std::size_t len = conditions.size(); + std::string fac = "XMLConditionsParser"; xml::DocumentHolder doc(xml::DocumentHandler().load(nam)); xml::Handle_t handle = doc.root(); ConditionsStack stack; @@ -136,11 +134,11 @@ size_t ConditionsXmlLoader::load_source(const std::string& nam, return conditions.size()-len; } -size_t ConditionsXmlLoader::load_single(key_type key, - const IOV& req_validity, - RangeConditions& conditions) +std::size_t ConditionsXmlLoader::load_single(key_type key, + const IOV& req_validity, + RangeConditions& conditions) { - size_t len = conditions.size(); + std::size_t len = conditions.size(); if ( m_buffer.empty() && !m_sources.empty() ) { return load_source(m_sources.begin()->first, key, req_validity, conditions); } @@ -158,11 +156,11 @@ size_t ConditionsXmlLoader::load_single(key_type key, return conditions.size()-len; } -size_t ConditionsXmlLoader::load_range(key_type key, - const IOV& req_validity, - RangeConditions& conditions) +std::size_t ConditionsXmlLoader::load_range(key_type key, + const IOV& req_validity, + RangeConditions& conditions) { - size_t len = conditions.size(); + std::size_t len = conditions.size(); while ( !m_sources.empty() ) { load_source(m_sources.begin()->first, key, req_validity, conditions); } @@ -180,4 +178,3 @@ size_t ConditionsXmlLoader::load_range(key_type key, m_buffer = keep; return conditions.size()-len; } - diff --git a/DDCore/include/XML/Layering.h b/DDCore/include/XML/Layering.h index 90becd834..58021b9f0 100644 --- a/DDCore/include/XML/Layering.h +++ b/DDCore/include/XML/Layering.h @@ -15,7 +15,7 @@ #define XML_LAYERING_H // Framework include files -#include "XML/XMLElements.h" +#include // C/C++ include files #include diff --git a/DDCore/src/AlignmentData.cpp b/DDCore/src/AlignmentData.cpp index cdc3af51d..3461f6c13 100644 --- a/DDCore/src/AlignmentData.cpp +++ b/DDCore/src/AlignmentData.cpp @@ -12,18 +12,19 @@ //========================================================================== // Framework include files -#include "DD4hep/AlignmentData.h" -#include "DD4hep/MatrixHelpers.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/DetElement.h" -#include "DD4hep/OpaqueData.h" -#include "DD4hep/Primitives.h" +#include +#include +#include +#include +#include +#include // ROOT include files -#include "TGeoMatrix.h" +#include + +// C/C++ include files #include -using namespace std; using namespace dd4hep; /// Copy constructor @@ -84,12 +85,12 @@ void Delta::computeMatrix(TGeoHMatrix& tr_delta) const { } /// print alignment delta object -ostream& operator << (ostream& ostr, const Delta& data) { - string res; - stringstream str; +std::ostream& operator << (std::ostream& ostr, const Delta& data) { + std::string res; + std::stringstream str; str << "[" << data.translation << "," << data.rotation << "," << data.pivot << "]"; res = str.str(); - for(size_t i=0; i static auto s_registry = GrammarRegistry::pre_note(1) .pre_note(1) .pre_note >(1); diff --git a/DDCore/src/AlignmentNominalMap.cpp b/DDCore/src/AlignmentNominalMap.cpp index 547ebb5ac..c4d6569c8 100644 --- a/DDCore/src/AlignmentNominalMap.cpp +++ b/DDCore/src/AlignmentNominalMap.cpp @@ -12,11 +12,11 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/DetectorProcessor.h" -#include "DD4hep/AlignmentsNominalMap.h" -#include "DD4hep/detail/AlignmentsInterna.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include +#include +#include using namespace dd4hep; using align::Keys; diff --git a/DDCore/src/AlignmentTools.cpp b/DDCore/src/AlignmentTools.cpp index 68628aef6..4315cf591 100644 --- a/DDCore/src/AlignmentTools.cpp +++ b/DDCore/src/AlignmentTools.cpp @@ -12,16 +12,16 @@ //========================================================================== // Framework include files -#include "DD4hep/IOV.h" -#include "DD4hep/Printout.h" -#include "DD4hep/MatrixHelpers.h" -#include "DD4hep/AlignmentTools.h" -#include "DD4hep/DetectorTools.h" -#include "DD4hep/detail/DetectorInterna.h" -#include "DD4hep/detail/AlignmentsInterna.h" +#include +#include +#include +#include +#include +#include +#include // ROOT include files -#include "TGeoMatrix.h" +#include using dd4hep::PlacedVolume; using dd4hep::Alignment; diff --git a/DDCore/src/Alignments.cpp b/DDCore/src/Alignments.cpp index d870e1ab1..124a63f12 100644 --- a/DDCore/src/Alignments.cpp +++ b/DDCore/src/Alignments.cpp @@ -12,22 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/AlignmentData.h" -#include "DD4hep/detail/AlignmentsInterna.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include // C/C++ include files #include - -using namespace std; using namespace dd4hep; -const string dd4hep::align::Keys::deltaName("alignment_delta"); +const std::string dd4hep::align::Keys::deltaName("alignment_delta"); const dd4hep::Condition::itemkey_type dd4hep::align::Keys::deltaKey = dd4hep::ConditionKey::itemCode("alignment_delta"); -const string dd4hep::align::Keys::alignmentName("alignment"); +const std::string dd4hep::align::Keys::alignmentName("alignment"); const dd4hep::Condition::itemkey_type dd4hep::align::Keys::alignmentKey = dd4hep::ConditionKey::itemCode("alignment"); @@ -36,7 +34,7 @@ Alignment::Processor::Processor() { } /// Initializing constructor to create a new object (Specialized for AlignmentNamedObject) -Alignment::Alignment(const string& nam) { +Alignment::Alignment(const std::string& nam) { char* p = (char*)::operator new(sizeof(Object)+sizeof(AlignmentData)); Object* o = new(p) Object(nam, "alignment", p+sizeof(Object), sizeof(AlignmentData)); assign(o, nam, "alignment"); @@ -44,7 +42,7 @@ Alignment::Alignment(const string& nam) { } /// Initializing constructor to create a new object (Specialized for AlignmentObject) -AlignmentCondition::AlignmentCondition(const string& nam) { +AlignmentCondition::AlignmentCondition(const std::string& nam) { char* p = (char*)::operator new(sizeof(Object)+sizeof(AlignmentData)); Object* o = new(p) Object(nam, "alignment", p+sizeof(Object), sizeof(AlignmentData)); assign(o, nam, "alignment"); @@ -77,7 +75,7 @@ const TGeoHMatrix& Alignment::detectorTransformation() const { } /// Access to the node list -const vector& Alignment::nodes() const { +const std::vector& Alignment::nodes() const { return access()->values().nodes; } diff --git a/DDCore/src/AlignmentsCalculator.cpp b/DDCore/src/AlignmentsCalculator.cpp index f9710d840..1e6452c7e 100644 --- a/DDCore/src/AlignmentsCalculator.cpp +++ b/DDCore/src/AlignmentsCalculator.cpp @@ -12,20 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/Conditions.h" -#include "DD4hep/ConditionsMap.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/MatrixHelpers.h" -#include "DD4hep/ConditionDerived.h" -#include "DD4hep/DetectorProcessor.h" -#include "DD4hep/AlignmentsProcessor.h" -#include "DD4hep/AlignmentsCalculator.h" -#include "DD4hep/detail/AlignmentsInterna.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace dd4hep; using namespace dd4hep::align; -typedef AlignmentsCalculator::Result Result; +using Result = AlignmentsCalculator::Result; /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -72,8 +72,8 @@ namespace dd4hep { class Calculator::Context { public: - typedef std::map DetectorMap; - typedef std::map Keys; + typedef std::map DetectorMap; + typedef std::map Keys; typedef std::vector Entries; DetectorMap detectors; @@ -324,5 +324,5 @@ size_t AlignmentsCalculator::extract_deltas(DetElement start, return deltas.size(); } -#include "DD4hep/GrammarUnparsed.h" +#include static auto s_registry = GrammarRegistry::pre_note(1); diff --git a/DDCore/src/AlignmentsInterna.cpp b/DDCore/src/AlignmentsInterna.cpp index e8a3be4f8..a874636a0 100644 --- a/DDCore/src/AlignmentsInterna.cpp +++ b/DDCore/src/AlignmentsInterna.cpp @@ -12,17 +12,16 @@ //========================================================================== // Framework includes -#include "DD4hep/IOV.h" -#include "DD4hep/World.h" -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/detail/Handle.inl" -#include "DD4hep/detail/DetectorInterna.h" -#include "DD4hep/detail/AlignmentsInterna.h" +#include +#include +#include +#include +#include +#include +#include -using namespace std; using namespace dd4hep; -using namespace dd4hep::detail; +using AlignmentObject = detail::AlignmentObject; DD4HEP_INSTANTIATE_HANDLE_UNNAMED(AlignmentData); #if defined(DD4HEP_MINIMAL_CONDITIONS) @@ -42,7 +41,7 @@ AlignmentObject::AlignmentObject() } /// Standard constructor -AlignmentObject::AlignmentObject(const string& nam, const string& tit, void* p, size_t len) +AlignmentObject::AlignmentObject(const std::string& nam, const std::string& tit, void* p, size_t len) : ConditionObject(nam, tit), alignment_data(0) { InstanceCount::increment(this); @@ -67,5 +66,5 @@ void AlignmentObject::clear() { flags = Condition::ALIGNMENT_DERIVED; } -#include "DD4hep/GrammarUnparsed.h" +#include static auto s_registry = GrammarRegistry::pre_note(); diff --git a/DDCore/src/AlignmentsPrinter.cpp b/DDCore/src/AlignmentsPrinter.cpp index 49e0139e8..7de759f07 100644 --- a/DDCore/src/AlignmentsPrinter.cpp +++ b/DDCore/src/AlignmentsPrinter.cpp @@ -12,22 +12,21 @@ //========================================================================== // Framework includes -#include "Parsers/Parsers.h" -#include "DD4hep/Printout.h" -#include "DD4hep/AlignmentsPrinter.h" -#include "DD4hep/AlignmentsProcessor.h" -#include "DD4hep/detail/AlignmentsInterna.h" +#include +#include +#include +#include +#include +#include // C/C++ include files #include -#include "TClass.h" -using namespace std; using namespace dd4hep; using namespace dd4hep::align; /// Initializing constructor -AlignmentsPrinter::AlignmentsPrinter(ConditionsMap* cond_map, const string& pref, int flg) +AlignmentsPrinter::AlignmentsPrinter(ConditionsMap* cond_map, const std::string& pref, int flg) : mapping(cond_map), name("Alignment"), prefix(pref), printLevel(INFO), m_flag(flg) { } @@ -41,7 +40,7 @@ int AlignmentsPrinter::operator()(Alignment a) const { /// Callback to output alignments information of an entire DetElement int AlignmentsPrinter::operator()(DetElement de, int level) const { if ( mapping ) { - vector alignments; + std::vector alignments; alignmentsCollector(*mapping,alignments)(de, level); printout(printLevel, name, "++ %s %-3ld Alignments for DE %s", prefix.c_str(), alignments.size(), de.path().c_str()); @@ -55,7 +54,7 @@ int AlignmentsPrinter::operator()(DetElement de, int level) const { } /// Initializing constructor -AlignedVolumePrinter::AlignedVolumePrinter(ConditionsMap* cond_map, const string& pref,int flg) +AlignedVolumePrinter::AlignedVolumePrinter(ConditionsMap* cond_map, const std::string& pref,int flg) : AlignmentsPrinter(cond_map, pref, flg) { name = "Alignment"; @@ -68,12 +67,12 @@ int AlignedVolumePrinter::operator()(Alignment a) const { } /// Default printout of an alignment entry -void dd4hep::align::printAlignment(PrintLevel lvl, const string& prefix, Alignment a) { +void dd4hep::align::printAlignment(PrintLevel lvl, const std::string& prefix, Alignment a) { if ( a.isValid() ) { Alignment::Object* ptr = a.ptr(); const AlignmentData& data = a.data(); const Delta& D = data.delta; - string new_prefix = prefix; + std::string new_prefix = prefix; new_prefix.assign(prefix.length(),' '); printout(lvl,prefix,"++ %s \t [%p] Typ:%s", new_prefix.c_str(), a.ptr(), @@ -90,14 +89,14 @@ void dd4hep::align::printAlignment(PrintLevel lvl, const string& prefix, Alignme } } -static string replace_all(const string& in, const string& from, const string& to) { - string res = in; - size_t idx; - while( string::npos != (idx=res.find(from)) ) +static std::string replace_all(const std::string& in, const std::string& from, const std::string& to) { + std::string res = in; + std::size_t idx; + while( std::string::npos != (idx=res.find(from)) ) res.replace(idx,from.length(),to); return res; } -static string _transformPoint2World(const AlignmentData& data, const Position& local) { +static std::string _transformPoint2World(const AlignmentData& data, const Position& local) { char text[256]; Position world = data.localToWorld(local); ::snprintf(text,sizeof(text),"Local: (%7.3f , %7.3f , %7.3f ) -- > World: (%7.3f , %7.3f , %7.3f )", @@ -105,7 +104,7 @@ static string _transformPoint2World(const AlignmentData& data, const Position& l return text; } -static string _transformPoint2Detector(const AlignmentData& data, const Position& local) { +static std::string _transformPoint2Detector(const AlignmentData& data, const Position& local) { char text[256]; Position world = data.localToDetector(local); ::snprintf(text,sizeof(text),"Local: (%7.3f , %7.3f , %7.3f ) -- > Parent: (%7.3f , %7.3f , %7.3f )", @@ -113,14 +112,14 @@ static string _transformPoint2Detector(const AlignmentData& data, const Position return text; } -void dd4hep::align::printAlignment(PrintLevel lvl, const string& prefix, - const string& opt, DetElement de, Alignment alignment) +void dd4hep::align::printAlignment(PrintLevel lvl, const std::string& prefix, + const std::string& opt, DetElement de, Alignment alignment) { - const string& tag = prefix; + const std::string& tag = prefix; const AlignmentData& align_data = alignment.data(); Condition align_cond;// = align_data.condition; const Delta& align_delta = align_data.delta; - string par = de.parent().isValid() ? de.parent().path() : string(); + std::string par = de.parent().isValid() ? de.parent().path() : std::string(); Box bbox = de.placement().volume().solid(); /// The edge positions of the bounding box: Position p1( bbox.x(), bbox.y(), bbox.z()); @@ -148,22 +147,22 @@ void dd4hep::align::printAlignment(PrintLevel lvl, const string& prefix, alignment.ptr()); } if ( align_delta.hasTranslation() ) { - stringstream str; + std::stringstream str; Position copy(align_delta.translation * (1./dd4hep::cm)); Parsers::toStream(copy, str); printout(lvl,tag,"++ %s DELTA Translation: %s [cm]", opt.c_str(), replace_all(str.str(),"\n","").c_str()); } if ( align_delta.hasPivot() ) { - stringstream str; + std::stringstream str; Delta::Pivot copy(align_delta.pivot.Vect() * (1./dd4hep::cm)); Parsers::toStream(copy, str); - string res = replace_all(str.str(),"\n",""); + std::string res = replace_all(str.str(),"\n",""); res = "( "+replace_all(res," "," , ")+" )"; printout(lvl,tag,"++ %s DELTA Pivot: %s [cm]", opt.c_str(), res.c_str()); } if ( align_delta.hasRotation() ) { - stringstream str; + std::stringstream str; Parsers::toStream(align_delta.rotation, str); printout(lvl,tag,"++ %s DELTA Rotation: %s [rad]", opt.c_str(), replace_all(str.str(),"\n","").c_str()); } @@ -193,10 +192,10 @@ void dd4hep::align::printAlignment(PrintLevel lvl, const string& prefix, } /// Default printout of a detector element entry -void dd4hep::align::printElement(PrintLevel prt_level, const string& prefix, DetElement de, ConditionsMap& pool) { - string tag = prefix+"Element"; +void dd4hep::align::printElement(PrintLevel prt_level, const std::string& prefix, DetElement de, ConditionsMap& pool) { + std::string tag = prefix+"Element"; if ( de.isValid() ) { - vector alignments; + std::vector alignments; alignmentsCollector(pool,alignments)(de); printout(prt_level,tag,"++ Alignments of DE %s [%d entries]", de.path().c_str(), int(alignments.size())); @@ -208,13 +207,13 @@ void dd4hep::align::printElement(PrintLevel prt_level, const string& prefix, Det } /// PrintElement placement with/without alignment applied -void dd4hep::align::printElementPlacement(PrintLevel lvl, const string& prefix, DetElement de, ConditionsMap& pool) { - string tag = prefix+"Element"; +void dd4hep::align::printElementPlacement(PrintLevel lvl, const std::string& prefix, DetElement de, ConditionsMap& pool) { + std::string tag = prefix+"Element"; if ( de.isValid() ) { char text[132]; Alignment nominal = de.nominal(); Box bbox = de.placement().volume().solid(); - vector alignments; + std::vector alignments; alignmentsCollector(pool,alignments)(de); ::memset(text,'=',sizeof(text)); diff --git a/DDCore/src/AlignmentsProcessor.cpp b/DDCore/src/AlignmentsProcessor.cpp index 1659a1acb..eabe06478 100644 --- a/DDCore/src/AlignmentsProcessor.cpp +++ b/DDCore/src/AlignmentsProcessor.cpp @@ -12,13 +12,12 @@ //========================================================================== // Framework includes -#include "DD4hep/Printout.h" -#include "DD4hep/AlignmentsProcessor.h" -#include "DD4hep/ConditionsProcessor.h" -#include "DD4hep/detail/ContainerHelpers.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include +#include +#include -using namespace std; using namespace dd4hep; using namespace dd4hep::align; @@ -27,7 +26,7 @@ template int DeltaCollector::operator()(DetElement de, int level) const { if ( de.isValid() ) { int count = 0; - vector conditions; + std::vector conditions; cond::conditionsCollector(mapping,conditions)(de,level); for( auto cond : conditions ) { if ( cond->testFlag(Condition::ALIGNMENT_DELTA) ) { @@ -46,7 +45,7 @@ template int AlignmentsCollector::operator()(DetElement de, int level) const { if ( de.isValid() ) { int count = 0; - vector conditions; + std::vector conditions; cond::conditionsCollector(mapping,conditions)(de,level); for( auto cond : conditions ) { if ( cond->testFlag(Condition::ALIGNMENT_DERIVED) ) { @@ -68,26 +67,26 @@ namespace dd4hep { /// Namespace for the AIDA detector description toolkit supporting XML utilities namespace align { - template class DeltaCollector >; - template class DeltaCollector >; - template class DeltaCollector >; - template class DeltaCollector > >; - template class DeltaCollector > >; + template class DeltaCollector >; + template class DeltaCollector >; + template class DeltaCollector >; + template class DeltaCollector > >; + template class DeltaCollector > >; - template class DeltaCollector >; - template class DeltaCollector >; - template class DeltaCollector >; + template class DeltaCollector >; + template class DeltaCollector >; + template class DeltaCollector >; - template class AlignmentsCollector >; - template class AlignmentsCollector >; - template class AlignmentsCollector >; - template class AlignmentsCollector > >; - template class AlignmentsCollector > >; + template class AlignmentsCollector >; + template class AlignmentsCollector >; + template class AlignmentsCollector >; + template class AlignmentsCollector > >; + template class AlignmentsCollector > >; - template class AlignmentsCollector >; - template class AlignmentsCollector >; - template class AlignmentsCollector >; + template class AlignmentsCollector >; + template class AlignmentsCollector >; + template class AlignmentsCollector >; } /* End namespace align */ } /* End namespace dd4hep */ diff --git a/DDCore/src/BuildType.cpp b/DDCore/src/BuildType.cpp index 05b3e4dfe..8eb690142 100644 --- a/DDCore/src/BuildType.cpp +++ b/DDCore/src/BuildType.cpp @@ -12,7 +12,7 @@ //========================================================================== // Framework includes -#include "DD4hep/BuildType.h" +#include // C/C++ include files #include diff --git a/DDCore/src/Callback.cpp b/DDCore/src/Callback.cpp index c28ded38d..c943f1720 100644 --- a/DDCore/src/Callback.cpp +++ b/DDCore/src/Callback.cpp @@ -12,13 +12,11 @@ //========================================================================== // Framework include files -#include "DD4hep/Callback.h" -#include "DD4hep/Exceptions.h" - -using namespace dd4hep; +#include +#include /// Check the compatibility of two typed objects. The test is the result of a dynamic_cast -void CallbackSequence::checkTypes(const std::type_info& typ1, const std::type_info& typ2, void* test) { +void dd4hep::CallbackSequence::checkTypes(const std::type_info& typ1, const std::type_info& typ2, void* test) { if (!test) { throw unrelated_type_error(typ1, typ2, "Cannot install a callback for these 2 types."); } diff --git a/DDCore/src/CartesianGridXY.cpp b/DDCore/src/CartesianGridXY.cpp index 949aefba3..daa7d155f 100644 --- a/DDCore/src/CartesianGridXY.cpp +++ b/DDCore/src/CartesianGridXY.cpp @@ -12,12 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/CartesianGridXY.h" -#include "DDSegmentation/CartesianGridXY.h" +#include +#include -// C/C++ include files - -using namespace std; using namespace dd4hep; /// determine the position based on the cell ID @@ -74,12 +71,12 @@ void CartesianGridXY::setOffsetY(double offset) const { } /// access the field name used for X -const string& CartesianGridXY::fieldNameX() const { +const std::string& CartesianGridXY::fieldNameX() const { return access()->implementation->fieldNameX(); } /// access the field name used for Y -const string& CartesianGridXY::fieldNameY() const { +const std::string& CartesianGridXY::fieldNameY() const { return access()->implementation->fieldNameY(); } @@ -92,6 +89,6 @@ const string& CartesianGridXY::fieldNameY() const { -# size in x -# size in y */ -vector CartesianGridXY::cellDimensions(const CellID& id) const { +std::vector CartesianGridXY::cellDimensions(const CellID& id) const { return access()->implementation->cellDimensions(id); } diff --git a/DDCore/src/CartesianGridXYZ.cpp b/DDCore/src/CartesianGridXYZ.cpp index ae4017c7a..bd610e524 100644 --- a/DDCore/src/CartesianGridXYZ.cpp +++ b/DDCore/src/CartesianGridXYZ.cpp @@ -12,12 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/CartesianGridXYZ.h" -#include "DDSegmentation/CartesianGridXYZ.h" +#include +#include -// C/C++ include files - -using namespace std; using namespace dd4hep; /// determine the position based on the cell ID @@ -94,17 +91,17 @@ void CartesianGridXYZ::setOffsetZ(double offset) const { } /// access the field name used for X -const string& CartesianGridXYZ::fieldNameX() const { +const std::string& CartesianGridXYZ::fieldNameX() const { return access()->implementation->fieldNameX(); } /// access the field name used for Y -const string& CartesianGridXYZ::fieldNameY() const { +const std::string& CartesianGridXYZ::fieldNameY() const { return access()->implementation->fieldNameY(); } /// access the field name used for Z -const string& CartesianGridXYZ::fieldNameZ() const { +const std::string& CartesianGridXYZ::fieldNameZ() const { return access()->implementation->fieldNameZ(); } @@ -118,6 +115,6 @@ const string& CartesianGridXYZ::fieldNameZ() const { -# size in y -# size in z */ -vector CartesianGridXYZ::cellDimensions(const CellID& id) const { +std::vector CartesianGridXYZ::cellDimensions(const CellID& id) const { return access()->implementation->cellDimensions(id); } diff --git a/DDCore/src/CartesianGridXZ.cpp b/DDCore/src/CartesianGridXZ.cpp index 8bc00bd89..907559173 100644 --- a/DDCore/src/CartesianGridXZ.cpp +++ b/DDCore/src/CartesianGridXZ.cpp @@ -12,12 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/CartesianGridXZ.h" -#include "DDSegmentation/CartesianGridXZ.h" +#include +#include -// C/C++ include files - -using namespace std; using namespace dd4hep; /// determine the position based on the cell ID @@ -74,12 +71,12 @@ void CartesianGridXZ::setOffsetZ(double offset) const { } /// access the field name used for X -const string& CartesianGridXZ::fieldNameX() const { +const std::string& CartesianGridXZ::fieldNameX() const { return access()->implementation->fieldNameX(); } /// access the field name used for Z -const string& CartesianGridXZ::fieldNameZ() const { +const std::string& CartesianGridXZ::fieldNameZ() const { return access()->implementation->fieldNameZ(); } @@ -92,6 +89,6 @@ const string& CartesianGridXZ::fieldNameZ() const { -# size in x -# size in z */ -vector CartesianGridXZ::cellDimensions(const CellID& id) const { +std::vector CartesianGridXZ::cellDimensions(const CellID& id) const { return access()->implementation->cellDimensions(id); } diff --git a/DDCore/src/CartesianGridYZ.cpp b/DDCore/src/CartesianGridYZ.cpp index a7fbc27a6..4a9ab3e03 100644 --- a/DDCore/src/CartesianGridYZ.cpp +++ b/DDCore/src/CartesianGridYZ.cpp @@ -12,12 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/CartesianGridYZ.h" -#include "DDSegmentation/CartesianGridYZ.h" +#include +#include -// C/C++ include files - -using namespace std; using namespace dd4hep; /// determine the position based on the cell ID @@ -74,12 +71,12 @@ void CartesianGridYZ::setOffsetZ(double offset) const { } /// access the field name used for Y -const string& CartesianGridYZ::fieldNameY() const { +const std::string& CartesianGridYZ::fieldNameY() const { return access()->implementation->fieldNameY(); } /// access the field name used for Z -const string& CartesianGridYZ::fieldNameZ() const { +const std::string& CartesianGridYZ::fieldNameZ() const { return access()->implementation->fieldNameZ(); } @@ -92,6 +89,6 @@ const string& CartesianGridYZ::fieldNameZ() const { -# size in y -# size in z */ -vector CartesianGridYZ::cellDimensions(const CellID& id) const { +std::vector CartesianGridYZ::cellDimensions(const CellID& id) const { return access()->implementation->cellDimensions(id); } diff --git a/DDCore/src/CartesianStripX.cpp b/DDCore/src/CartesianStripX.cpp index 413150051..653fa590c 100644 --- a/DDCore/src/CartesianStripX.cpp +++ b/DDCore/src/CartesianStripX.cpp @@ -12,10 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/CartesianStripX.h" -#include "DDSegmentation/CartesianStripX.h" +#include +#include -using namespace std; using namespace dd4hep; /// determine the position based on the cell ID @@ -44,7 +43,7 @@ double CartesianStripX::offsetX() const { return access()->implementation->offse void CartesianStripX::setOffsetX(double offset) const { access()->implementation->setOffsetX(offset); } /// access the field name used for X -const string& CartesianStripX::fieldNameX() const { return access()->implementation->fieldNameX(); } +const std::string& CartesianStripX::fieldNameX() const { return access()->implementation->fieldNameX(); } /** \brief Returns a vector of the cellDimensions of the given cell ID in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi @@ -55,6 +54,6 @@ const string& CartesianStripX::fieldNameX() const { return access()->implementat -# size in x -# size in y */ -vector CartesianStripX::cellDimensions(const CellID& id) const { +std::vector CartesianStripX::cellDimensions(const CellID& id) const { return access()->implementation->cellDimensions(id); } diff --git a/DDCore/src/CartesianStripY.cpp b/DDCore/src/CartesianStripY.cpp index 91e38b48b..a75fe16cc 100644 --- a/DDCore/src/CartesianStripY.cpp +++ b/DDCore/src/CartesianStripY.cpp @@ -12,10 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/CartesianStripY.h" -#include "DDSegmentation/CartesianStripY.h" +#include +#include -using namespace std; using namespace dd4hep; /// determine the position based on the cell ID @@ -44,7 +43,7 @@ double CartesianStripY::offsetY() const { return access()->implementation->offse void CartesianStripY::setOffsetY(double offset) const { access()->implementation->setOffsetY(offset); } /// access the field name used for Y -const string& CartesianStripY::fieldNameY() const { return access()->implementation->fieldNameY(); } +const std::string& CartesianStripY::fieldNameY() const { return access()->implementation->fieldNameY(); } /** \brief Returns a vector of the cellDimensions of the given cell ID in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi @@ -55,6 +54,6 @@ const string& CartesianStripY::fieldNameY() const { return access()->implementat -# size in x -# size in y */ -vector CartesianStripY::cellDimensions(const CellID& id) const { +std::vector CartesianStripY::cellDimensions(const CellID& id) const { return access()->implementation->cellDimensions(id); } diff --git a/DDCore/src/CartesianStripZ.cpp b/DDCore/src/CartesianStripZ.cpp index 8ea1333f2..72336031c 100644 --- a/DDCore/src/CartesianStripZ.cpp +++ b/DDCore/src/CartesianStripZ.cpp @@ -12,10 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/CartesianStripZ.h" -#include "DDSegmentation/CartesianStripZ.h" +#include +#include -using namespace std; using namespace dd4hep; /// determine the position based on the cell ID @@ -44,7 +43,7 @@ double CartesianStripZ::offsetZ() const { return access()->implementation->offse void CartesianStripZ::setOffsetZ(double offset) const { access()->implementation->setOffsetZ(offset); } /// access the field name used for Z -const string& CartesianStripZ::fieldNameZ() const { return access()->implementation->fieldNameZ(); } +const std::string& CartesianStripZ::fieldNameZ() const { return access()->implementation->fieldNameZ(); } /** \brief Returns a vector of the cellDimensions of the given cell ID in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi @@ -55,6 +54,6 @@ const string& CartesianStripZ::fieldNameZ() const { return access()->implementat -# size in x -# size in y */ -vector CartesianStripZ::cellDimensions(const CellID& id) const { +std::vector CartesianStripZ::cellDimensions(const CellID& id) const { return access()->implementation->cellDimensions(id); } diff --git a/DDCore/src/ComponentProperties.cpp b/DDCore/src/ComponentProperties.cpp index 429e2b2f2..148f4d8b2 100644 --- a/DDCore/src/ComponentProperties.cpp +++ b/DDCore/src/ComponentProperties.cpp @@ -12,45 +12,44 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/Primitives.h" -#include "Parsers/Parsers.h" -#include "DD4hep/ComponentProperties.h" +#include +#include +#include +#include // C/C++ include files #include #include -using namespace std; using namespace dd4hep; /// Property type name -string Property::type(const Property& property) { +std::string Property::type(const Property& property) { return type(property.grammar().type()); } /// Property type name -string Property::type(const type_info& typ) { +std::string Property::type(const std::type_info& typ) { return typeName(typ); } /// Property type name -string Property::type() const { +std::string Property::type() const { return Property::type(grammar().type()); } const BasicGrammar& Property::grammar() const { if ( m_hdl ) return *m_hdl; - throw runtime_error("Attempt to access property grammar from invalid object."); + throw std::runtime_error("Attempt to access property grammar from invalid object."); } /// Conversion to string value -string Property::str() const { +std::string Property::str() const { if ( m_hdl && m_par ) { return m_hdl->str(m_par); } - throw runtime_error("Attempt to access property grammar from invalid object."); + throw std::runtime_error("Attempt to access property grammar from invalid object."); } /// Conversion from string value @@ -59,7 +58,7 @@ const Property& Property::str(const std::string& input) const { m_hdl->fromString(m_par,input); return *this; } - throw runtime_error("Attempt to access property grammar from invalid object."); + throw std::runtime_error("Attempt to access property grammar from invalid object."); } /// Conversion from string value @@ -68,16 +67,16 @@ Property& Property::str(const std::string& input) { m_hdl->fromString(m_par,input); return *this; } - throw runtime_error("Attempt to access property grammar from invalid object."); + throw std::runtime_error("Attempt to access property grammar from invalid object."); } /// Assignment operator / set new balue Property& Property::operator=(const char* val) { if ( val ) { - this->set < string > (val); + this->set < std::string > (val); return *this; } - throw runtime_error("Attempt to set invalid string to property!"); + throw std::runtime_error("Attempt to set invalid string to property!"); } /// Default constructor @@ -106,53 +105,53 @@ bool PropertyManager::exists(const std::string& name) const { } /// Verify that this property does not exist (throw exception if the name was found) -void PropertyManager::verifyNonExistence(const string& name) const { +void PropertyManager::verifyNonExistence(const std::string& name) const { Properties::const_iterator i = m_properties.find(name); if (i == m_properties.end()) return; - throw runtime_error("The property:" + name + " already exists for this component."); + throw std::runtime_error("The property:" + name + " already exists for this component."); } /// Verify that this property exists (throw exception if the name was not found) PropertyManager::Properties::const_iterator -PropertyManager::verifyExistence(const string& name) const { +PropertyManager::verifyExistence(const std::string& name) const { Properties::const_iterator i = m_properties.find(name); if (i != m_properties.end()) return i; - throw runtime_error("PropertyManager: Unknown property:" + name); + throw std::runtime_error("PropertyManager: Unknown property:" + name); } /// Verify that this property exists (throw exception if the name was not found) PropertyManager::Properties::iterator -PropertyManager::verifyExistence(const string& name) { +PropertyManager::verifyExistence(const std::string& name) { Properties::iterator i = m_properties.find(name); if (i != m_properties.end()) return i; - throw runtime_error("PropertyManager: Unknown property:" + name); + throw std::runtime_error("PropertyManager: Unknown property:" + name); } /// Access property by name (CONST) -Property& PropertyManager::property(const string& name) { +Property& PropertyManager::property(const std::string& name) { return (*verifyExistence(name)).second; } /// Access property by name -const Property& PropertyManager::property(const string& name) const { +const Property& PropertyManager::property(const std::string& name) const { return (*verifyExistence(name)).second; } /// Access property by name -Property& PropertyManager::operator[](const string& name) { +Property& PropertyManager::operator[](const std::string& name) { return (*verifyExistence(name)).second; } /// Access property by name -const Property& PropertyManager::operator[](const string& name) const { +const Property& PropertyManager::operator[](const std::string& name) const { return (*verifyExistence(name)).second; } /// Add a new property -void PropertyManager::add(const string& name, const Property& prop) { +void PropertyManager::add(const std::string& name, const Property& prop) { verifyNonExistence(name); m_properties.emplace(name, prop); } @@ -173,16 +172,16 @@ PropertyConfigurable::~PropertyConfigurable() { } /// Check property for existence -bool PropertyConfigurable::hasProperty(const string& nam) const { +bool PropertyConfigurable::hasProperty(const std::string& nam) const { return m_properties.exists(nam); } /// Access single property -Property& PropertyConfigurable::property(const string& nam) { +Property& PropertyConfigurable::property(const std::string& nam) { return properties()[nam]; } -#include "DD4hep/GrammarParsed.h" +#include namespace dd4hep { namespace Parsers { template <> int parse(Property& result, const std::string& input) { diff --git a/DDCore/src/ConditionAny.cpp b/DDCore/src/ConditionAny.cpp index 7e974f493..60cf360a2 100644 --- a/DDCore/src/ConditionAny.cpp +++ b/DDCore/src/ConditionAny.cpp @@ -12,9 +12,9 @@ //========================================================================== // Framework includes -#include "DD4hep/Printout.h" -#include "DD4hep/ConditionAny.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include // C/C++ include files #include diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp index 1ebd6c2ba..1f99f1926 100644 --- a/DDCore/src/ConditionDerived.cpp +++ b/DDCore/src/ConditionDerived.cpp @@ -12,10 +12,10 @@ //========================================================================== // Framework includes -#include "DD4hep/Printout.h" -#include "DD4hep/Detector.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/ConditionDerived.h" +#include +#include +#include +#include // C/C++ include files diff --git a/DDCore/src/Conditions.cpp b/DDCore/src/Conditions.cpp index eb4b66c3b..9f5667b82 100644 --- a/DDCore/src/Conditions.cpp +++ b/DDCore/src/Conditions.cpp @@ -12,25 +12,24 @@ //========================================================================== // Framework includes -#include "DD4hep/Printout.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include // C/C++ include files #include #include #include -using namespace std; using namespace dd4hep; namespace { int s_have_inventory = 0; struct KeyTracer { - map item_names; - mutex lock; - void add(Condition::itemkey_type key,const string& item) { + std::map item_names; + std::mutex lock; + void add(Condition::itemkey_type key,const std::string& item) { if ( s_have_inventory > 0 ) { - std::lock_guard protect(lock); + std::lock_guard protect(lock); item_names.emplace(key, item); } } @@ -40,7 +39,7 @@ namespace { return (*i).second; } char text[32]; - ::snprintf(text,sizeof(text),"%08X",key); + std::snprintf(text,sizeof(text),"%08X",key); return text; } } s_key_tracer; @@ -75,7 +74,7 @@ Condition::Condition(key_type hash_key) : Handle() } /// Initializing constructor for a pure, undecorated conditions object -Condition::Condition(const string& nam, const string& typ) : Handle() +Condition::Condition(const std::string& nam, const std::string& typ) : Handle() { Object* o = new Object(); assign(o,nam,typ); @@ -83,7 +82,7 @@ Condition::Condition(const string& nam, const string& typ) : Handle() } /// Initializing constructor for a pure, undecorated conditions object with payload buffer -Condition::Condition(const string& nam,const string& typ, size_t memory) +Condition::Condition(const std::string& nam,const std::string& typ, size_t memory) : Handle() { void* ptr = ::operator new(sizeof(Object)+memory); @@ -93,12 +92,12 @@ Condition::Condition(const string& nam,const string& typ, size_t memory) } /// Output method -string Condition::str(int flags) const { - stringstream output; +std::string Condition::str(int flags) const { + std::stringstream output; Object* o = access(); #if defined(DD4HEP_CONDITIONS_HAVE_NAME) if ( 0 == (flags&NO_NAME) ) - output << setw(16) << left << o->name; + output << std::setw(16) << std::left << o->name; #endif if ( flags&WITH_IOV ) { const IOV* ptr_iov = o->iovData(); @@ -143,28 +142,28 @@ const dd4hep::IOV& Condition::iov() const { #if !defined(DD4HEP_MINIMAL_CONDITIONS) /// Access the type field of the condition -const string& Condition::type() const { +const std::string& Condition::type() const { return access()->type; } /// Access the value field of the condition as a string -const string& Condition::value() const { +const std::string& Condition::value() const { return access()->value; } /// Access the comment field of the condition -const string& Condition::comment() const { +const std::string& Condition::comment() const { return access()->comment; } /// Access the address string [e.g. database identifier] -const string& Condition::address() const { +const std::string& Condition::address() const { return access()->address; } #endif /// Access to the type information -const type_info& Condition::typeInfo() const { +const std::type_info& Condition::typeInfo() const { return descriptor().type(); } @@ -210,7 +209,7 @@ const dd4hep::BasicGrammar& Condition::descriptor() const { invalidHandleError(); // This code is never reached, since function above throws exception! // Needed to satisfay CppCheck - throw runtime_error("Null pointer in Grammar object"); + throw std::runtime_error("Null pointer in Grammar object"); } return *grammar; } @@ -220,7 +219,7 @@ ConditionsSelect::~ConditionsSelect() { } /// Constructor from string -ConditionKey::KeyMaker::KeyMaker(DetElement detector, const string& value) { +ConditionKey::KeyMaker::KeyMaker(DetElement detector, const std::string& value) { KeyMaker key_maker(detector.key(), detail::hash32(value)); hash = key_maker.hash; s_key_tracer.add(key_maker.values.item_key, value); @@ -232,14 +231,14 @@ ConditionKey::KeyMaker::KeyMaker(DetElement detector, Condition::itemkey_type it } /// Constructor from string -ConditionKey::KeyMaker::KeyMaker(Condition::detkey_type det_key, const string& value) { +ConditionKey::KeyMaker::KeyMaker(Condition::detkey_type det_key, const std::string& value) { KeyMaker key_maker(det_key, detail::hash32(value)); hash = key_maker.hash; s_key_tracer.add(key_maker.values.item_key, value); } /// Constructor from string -ConditionKey::ConditionKey(DetElement detector, const string& value) { +ConditionKey::ConditionKey(DetElement detector, const std::string& value) { KeyMaker key_maker(detector.key(), value); hash = key_maker.hash; s_key_tracer.add(key_maker.values.item_key, value); @@ -249,7 +248,7 @@ ConditionKey::ConditionKey(DetElement detector, const string& value) { } /// Constructor from detector element key and item sub-key -ConditionKey::ConditionKey(Condition::detkey_type det_key, const string& value) { +ConditionKey::ConditionKey(Condition::detkey_type det_key, const std::string& value) { KeyMaker key_maker(det_key, value); s_key_tracer.add(key_maker.values.item_key, value); hash = key_maker.hash; @@ -278,7 +277,7 @@ Condition::key_type ConditionKey::hashCode(DetElement detector, const char* valu } /// Hash code generation from input string -Condition::key_type ConditionKey::hashCode(DetElement detector, const string& value) { +Condition::key_type ConditionKey::hashCode(DetElement detector, const std::string& value) { KeyMaker key_maker(detector.key(), value); s_key_tracer.add(key_maker.values.item_key, value); return key_maker.hash; @@ -292,20 +291,20 @@ Condition::itemkey_type ConditionKey::itemCode(const char* value) { } /// 32 bit hashcode of the item -Condition::itemkey_type ConditionKey::itemCode(const string& value) { +Condition::itemkey_type ConditionKey::itemCode(const std::string& value) { Condition::itemkey_type code = detail::hash32(value); s_key_tracer.add(code, value); return code; } /// Conversion to string -string ConditionKey::toString() const { +std::string ConditionKey::toString() const { dd4hep::ConditionKey::KeyMaker key(hash); char text[64]; ::snprintf(text,sizeof(text),"%08X-%08X",key.values.det_key, key.values.item_key); #if defined(DD4HEP_CONDITIONS_HAVE_NAME) if ( !name.empty() ) { - stringstream str; + std::stringstream str; str << "(" << name << ") " << text; return str.str(); } diff --git a/DDCore/src/ConditionsData.cpp b/DDCore/src/ConditionsData.cpp index 2392bc02d..9b79c1567 100644 --- a/DDCore/src/ConditionsData.cpp +++ b/DDCore/src/ConditionsData.cpp @@ -12,9 +12,9 @@ //========================================================================== // Framework includes -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/ConditionsData.h" +#include +#include +#include using namespace dd4hep::cond; @@ -76,5 +76,5 @@ AbstractMap& AbstractMap::operator=(const AbstractMap& c) { return *this; } -#include "DD4hep/GrammarUnparsed.h" +#include static auto s_registry = dd4hep::GrammarRegistry::pre_note(1); diff --git a/DDCore/src/ConditionsDebug.cpp b/DDCore/src/ConditionsDebug.cpp index d17e8a947..ca30abf20 100644 --- a/DDCore/src/ConditionsDebug.cpp +++ b/DDCore/src/ConditionsDebug.cpp @@ -12,24 +12,23 @@ //========================================================================== // Framework include files -#include "DD4hep/Conditions.h" -#include "DD4hep/ConditionsDebug.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include -using std::string; using namespace dd4hep::cond; std::string dd4hep::cond::cond_name(const dd4hep::Condition::Object* c) { #if defined(DD4HEP_MINIMAL_CONDITIONS) dd4hep::ConditionKey::KeyMaker key(c->hash); char text[64]; - ::snprintf(text,sizeof(text),"%08X-%08X",key.values.det_key, key.values.item_key); + std::snprintf(text,sizeof(text),"%08X-%08X", key.values.det_key, key.values.item_key); return text; #else return c->name; #endif } -string dd4hep::cond::cond_name(Condition c) { +std::string dd4hep::cond::cond_name(Condition c) { return cond_name(c.ptr()); } diff --git a/DDCore/src/ConditionsInterna.cpp b/DDCore/src/ConditionsInterna.cpp index 0a08de596..044938b87 100644 --- a/DDCore/src/ConditionsInterna.cpp +++ b/DDCore/src/ConditionsInterna.cpp @@ -12,12 +12,11 @@ //========================================================================== // Framework includes -#include "DD4hep/IOV.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/detail/Handle.inl" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include +#include -using namespace std; using namespace dd4hep; #if defined(DD4HEP_CONDITIONS_HAVE_NAME) @@ -45,10 +44,10 @@ detail::ConditionObject::ConditionObject() /// Standard constructor #if defined(DD4HEP_CONDITIONS_HAVE_NAME) -detail::ConditionObject::ConditionObject(const string& nam,const string& tit) +detail::ConditionObject::ConditionObject(const std::string& nam,const std::string& tit) : NamedObject(nam, tit), data() #else -detail::ConditionObject::ConditionObject(const string& ,const string& ) +detail::ConditionObject::ConditionObject(const std::string& ,const std::string& ) : data() #endif { @@ -68,7 +67,7 @@ void detail::ConditionObject::release() { /// Data offset from the opaque data block pointer to the condition size_t detail::ConditionObject::offset() { static _P p((void*)0x1000); - static size_t off = _P(&p.o->data.grammar).character - p.character + sizeof(OpaqueData::grammar); + static std::size_t off = _P(&p.o->data.grammar).character - p.character + sizeof(OpaqueData::grammar); return off; } @@ -97,5 +96,5 @@ const dd4hep::IOVType* detail::ConditionObject::iovType() const { } -#include "DD4hep/GrammarUnparsed.h" -static auto s_registry = GrammarRegistry::pre_note >(1); +#include +static auto s_registry = GrammarRegistry::pre_note >(1); diff --git a/DDCore/src/ConditionsListener.cpp b/DDCore/src/ConditionsListener.cpp index 3e43d6ccf..129f41848 100644 --- a/DDCore/src/ConditionsListener.cpp +++ b/DDCore/src/ConditionsListener.cpp @@ -12,7 +12,7 @@ //========================================================================== // Framework include files -#include "DD4hep/ConditionsListener.h" +#include using namespace dd4hep::cond; diff --git a/DDCore/src/ConditionsMap.cpp b/DDCore/src/ConditionsMap.cpp index c9f496a11..844622774 100644 --- a/DDCore/src/ConditionsMap.cpp +++ b/DDCore/src/ConditionsMap.cpp @@ -12,9 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/ConditionsMap.h" -#include "DD4hep/detail/ConditionsInterna.h" +#include +#include +#include using namespace dd4hep; diff --git a/DDCore/src/ConditionsPrinter.cpp b/DDCore/src/ConditionsPrinter.cpp index 2d0552723..a51935319 100644 --- a/DDCore/src/ConditionsPrinter.cpp +++ b/DDCore/src/ConditionsPrinter.cpp @@ -12,25 +12,24 @@ //========================================================================== // Framework includes -#include "Parsers/Parsers.h" -#include "DD4hep/Printout.h" -#include "DD4hep/ConditionsData.h" -#include "DD4hep/ConditionsPrinter.h" -#include "DD4hep/ConditionsProcessor.h" +#include +#include +#include +#include +#include -#include "DD4hep/detail/ConditionsInterna.h" +#include // C/C++ include files #include -using namespace std; using namespace dd4hep; using namespace dd4hep::cond; namespace { /// C++ version: replace all occurrences of a string - string str_replace(const std::string& str, const std::string& pattern, const std::string& replacement) { - string res = str; + std::string str_replace(const std::string& str, const std::string& pattern, const std::string& replacement) { + std::string res = str; for(size_t id=res.find(pattern); id != std::string::npos; id = res.find(pattern) ) res.replace(id,pattern.length(),replacement); return res; @@ -76,11 +75,11 @@ ConditionsPrinter::ParamPrinter::ParamPrinter(ConditionsPrinter* printer, PrintL /// Callback to output conditions information void ConditionsPrinter::ParamPrinter::operator()(const AbstractMap::Params::value_type& obj) const { - const type_info& type = obj.second.typeInfo(); + const std::type_info& type = obj.second.typeInfo(); ++m_parent->numParam; - if ( type == typeid(string) ) { - string value = obj.second.get().c_str(); - size_t len = value.length(); + if ( type == typeid(std::string) ) { + std::string value = obj.second.get().c_str(); + std::size_t len = value.length(); if ( len > m_parent->lineLength ) { value.erase(m_parent->lineLength); value += "..."; @@ -100,8 +99,8 @@ void ConditionsPrinter::ParamPrinter::operator()(const AbstractMap::Params::valu obj.second.str().c_str()); } else { - string value = obj.second.str(); - size_t len = value.length(); + std::string value = obj.second.str(); + std::size_t len = value.length(); if ( len > m_parent->lineLength ) { value.erase(m_parent->lineLength); value += "..."; @@ -115,7 +114,7 @@ void ConditionsPrinter::ParamPrinter::operator()(const AbstractMap::Params::valu } /// Initializing constructor -ConditionsPrinter::ConditionsPrinter(ConditionsMap* cond_map, const string& pref, int flg) +ConditionsPrinter::ConditionsPrinter(ConditionsMap* cond_map, const std::string& pref, int flg) : mapping(cond_map), m_flag(flg), name("Condition"), prefix(pref) { m_print = new ParamPrinter(this, printLevel); @@ -137,13 +136,13 @@ ConditionsPrinter::~ConditionsPrinter() { int ConditionsPrinter::operator()(Condition cond) const { m_print->printLevel = printLevel; if ( cond.isValid() ) { - string repr = cond.str(m_flag); - Condition::Object* ptr = cond.ptr(); + std::string repr = cond.str(m_flag); + Condition::Object* ptr = cond.ptr(); if ( repr.length() > lineLength ) repr = repr.substr(0,lineLength)+"..."; printout(this->printLevel,name, "++ %s%s", prefix.c_str(), repr.c_str()); - string new_prefix = prefix; + std::string new_prefix = prefix; new_prefix.assign(prefix.length(),' '); if ( !cond.is_bound() ) { printout(this->printLevel,name,"++ %s \tPath:%s Key:%16llX Type:%s (%s)", @@ -151,11 +150,11 @@ int ConditionsPrinter::operator()(Condition cond) const { typeName(typeid(*ptr)).c_str()); return 1; } - const type_info& type = cond.typeInfo(); - const OpaqueData& opaque = cond.data(); + const std::type_info& type = cond.typeInfo(); + const OpaqueData& opaque = cond.data(); printout(this->printLevel,name,"++ %s \tPath:%s Key:%16llX Type:%s", new_prefix.c_str(), cond.name(), cond.key(), opaque.dataType().c_str()); - //string values = opaque.str(); + //std::string values = opaque.str(); //if ( values.length() > lineLength ) values = values.substr(0,130)+"..."; //printout(this->printLevel,name,"++ %s \tData:%s", new_prefix.c_str(), values.c_str()); if ( type == typeid(AbstractMap) ) { @@ -176,18 +175,18 @@ int ConditionsPrinter::operator()(Condition cond) const { } } else if ( type == typeid(Delta) ) { - string piv; - stringstream str_tr, str_rot, str_piv; + std::string piv; + std::stringstream str_tr, str_rot, str_piv; const Delta& D = cond.get(); if ( D.hasTranslation() ) { - Position copy(D.translation * (1./dd4hep::cm)); - Parsers::toStream(copy, str_tr); + Position copy(D.translation * (1./dd4hep::cm)); + Parsers::toStream(copy, str_tr); } if ( D.hasRotation() ) { - Parsers::toStream(D.rotation, str_rot); + Parsers::toStream(D.rotation, str_rot); } if ( D.hasPivot() ) { - Position copy(D.pivot.Vect() * (1./dd4hep::cm)); + Position copy(D.pivot.Vect() * (1./dd4hep::cm)); Parsers::toStream(copy, str_piv); piv = str_replace(str_piv.str(),"\n",""); piv = str_replace(piv," "," , "); @@ -206,8 +205,8 @@ int ConditionsPrinter::operator()(Condition cond) const { ); } else if ( type == typeid(AlignmentData) ) { - string piv; - stringstream str_tr, str_rot, str_piv; + std::string piv; + std::stringstream str_tr, str_rot, str_piv; const Delta& D = cond.get().delta; if ( D.hasTranslation() ) Parsers::toStream(D.translation, str_tr); if ( D.hasRotation() ) Parsers::toStream(D.rotation, str_rot); @@ -230,9 +229,9 @@ int ConditionsPrinter::operator()(Condition cond) const { piv.c_str() ); } - else if ( type == typeid(string) ) { - string value = cond.get().c_str(); - size_t len = value.length(); + else if ( type == typeid(std::string) ) { + std::string value = cond.get().c_str(); + std::size_t len = value.length(); if ( len > lineLength ) { value = value.substr(0,lineLength); value += "..."; @@ -244,8 +243,8 @@ int ConditionsPrinter::operator()(Condition cond) const { value.c_str()); } else { - string value = cond.str(); - size_t len = value.length(); + std::string value = cond.str(); + std::size_t len = value.length(); if ( len > lineLength ) { value = value.substr(0,lineLength); value += "..."; @@ -264,7 +263,7 @@ int ConditionsPrinter::operator()(Condition cond) const { /// Processing callback to print conditions int ConditionsPrinter::operator()(DetElement de, int level) const { if ( mapping ) { - vector conditions; + std::vector conditions; conditionsCollector(*mapping,conditions)(de,level); printout(this->printLevel, name, "++ %s %-3ld Conditions for DE %s", prefix.c_str(), conditions.size(), de.path().c_str()); diff --git a/DDCore/src/ConditionsProcessor.cpp b/DDCore/src/ConditionsProcessor.cpp index 9a3514e6e..a31c652b5 100644 --- a/DDCore/src/ConditionsProcessor.cpp +++ b/DDCore/src/ConditionsProcessor.cpp @@ -12,11 +12,10 @@ //========================================================================== // Framework includes -#include "DD4hep/Printout.h" -#include "DD4hep/ConditionsProcessor.h" -#include "DD4hep/detail/ContainerHelpers.h" +#include +#include +#include -using namespace std; using namespace dd4hep; using namespace dd4hep::cond; @@ -48,14 +47,14 @@ namespace dd4hep { namespace cond { //template class ConditionsCollector; - template class ConditionsCollector >; - template class ConditionsCollector >; - template class ConditionsCollector >; - template class ConditionsCollector > >; - template class ConditionsCollector > >; - - template class ConditionsCollector >; - template class ConditionsCollector >; - template class ConditionsCollector >; + template class ConditionsCollector >; + template class ConditionsCollector >; + template class ConditionsCollector >; + template class ConditionsCollector > >; + template class ConditionsCollector > >; + + template class ConditionsCollector >; + template class ConditionsCollector >; + template class ConditionsCollector >; } /* End namespace cond */ } /* End namespace dd4hep */ diff --git a/DDCore/src/DD4hepRootPersistency.cpp b/DDCore/src/DD4hepRootPersistency.cpp index fb3711405..fa8a525bc 100644 --- a/DDCore/src/DD4hepRootPersistency.cpp +++ b/DDCore/src/DD4hepRootPersistency.cpp @@ -12,20 +12,19 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/DD4hepRootPersistency.h" -#include "DD4hep/detail/ObjectsInterna.h" -#include "DD4hep/detail/SegmentationsInterna.h" +#include +#include +#include +#include // ROOT include files -#include "TFile.h" -#include "TTimeStamp.h" +#include +#include #include ClassImp(DD4hepRootPersistency) using namespace dd4hep; -using namespace std; namespace { /// Ensure nominal alignments are loaded before saving @@ -95,7 +94,7 @@ int DD4hepRootPersistency::save(Detector& description, const char* fname, const DetectorData::unpatchRootStreamer(TGeoNode::Class()); return nBytes; } - catch (const exception& e) { + catch (const std::exception& e) { DetectorData::unpatchRootStreamer(TGeoVolume::Class()); DetectorData::unpatchRootStreamer(TGeoNode::Class()); except("DD4hepRootPersistency","Exception %s while saving file %s",e.what(), fname); @@ -118,7 +117,7 @@ int DD4hepRootPersistency::load(Detector& description, const char* fname, const if ( f && !f->IsZombie()) { try { TTimeStamp start; - unique_ptr persist((DD4hepRootPersistency*)f->Get(instance)); + std::unique_ptr persist((DD4hepRootPersistency*)f->Get(instance)); if ( persist.get() ) { DetectorData* source = persist->m_data; #if 0 @@ -189,7 +188,7 @@ int DD4hepRootPersistency::load(Detector& description, const char* fname, const f->ls(); delete f; } - catch (const exception& e) { + catch (const std::exception& e) { DetectorData::unpatchRootStreamer(TGeoVolume::Class()); DetectorData::unpatchRootStreamer(TGeoNode::Class()); except("DD4hepRootPersistency","Exception %s while loading file %s",e.what(), fname); @@ -207,22 +206,20 @@ int DD4hepRootPersistency::load(Detector& description, const char* fname, const return 0; } +#include +#include +#include -#include "DD4hep/detail/DetectorInterna.h" -#include "DD4hep/detail/ConditionsInterna.h" -#include "DD4hep/detail/AlignmentsInterna.h" namespace { class PersistencyChecks { - public: - size_t errors = 0; /// Default constructor PersistencyChecks() = default; - size_t checkConstant(const std::pair& obj) { + size_t checkConstant(const std::pair& obj) { if ( obj.first.empty() || obj.second->name.empty() ) { printout(ERROR,"chkConstant","+++ Invalid constant: key error %s <> %s [%s]", obj.first.c_str(), obj.second->GetName(), obj.second->GetTitle()); @@ -238,7 +235,7 @@ namespace { return 1; } - size_t checkProperty(const std::pair >& obj) { + size_t checkProperty(const std::pair >& obj) { if ( obj.first.empty() || obj.second.empty() ) { printout(ERROR,"chkProperty","+++ Empty property set: %s",obj.first.c_str()); ++errors; diff --git a/DDCore/src/DD4hepUI.cpp b/DDCore/src/DD4hepUI.cpp index bd58a2fce..5972e252b 100644 --- a/DDCore/src/DD4hepUI.cpp +++ b/DDCore/src/DD4hepUI.cpp @@ -12,54 +12,52 @@ //========================================================================== // Framework includes -#include "DD4hep/DD4hepUI.h" -#include "DD4hep/Printout.h" -#include "TRint.h" +#include +#include +#include -using namespace std; using namespace dd4hep; -using namespace dd4hep::detail; namespace { - string _visLevel(int lvl) { + std::string _visLevel(int lvl) { char text[32]; - ::snprintf(text,sizeof(text),"%d",lvl); + std::snprintf(text,sizeof(text),"%d",lvl); return text; } } /// Default constructor -DD4hepUI::DD4hepUI(Detector& instance) : m_detDesc(instance) { +detail::DD4hepUI::DD4hepUI(Detector& instance) : m_detDesc(instance) { } /// Default destructor -DD4hepUI::~DD4hepUI() { +detail::DD4hepUI::~DD4hepUI() { } /// Access to the Detector instance -Detector* DD4hepUI::instance() const { +Detector* detail::DD4hepUI::instance() const { return &m_detDesc; } /// Access to the Detector instance -Detector* DD4hepUI::detectorDescription() const { +Detector* detail::DD4hepUI::detectorDescription() const { return &m_detDesc; } /// Set the printout level from the interactive prompt -PrintLevel DD4hepUI::setPrintLevel(PrintLevel level) const { +PrintLevel detail::DD4hepUI::setPrintLevel(PrintLevel level) const { return dd4hep::setPrintLevel(level); } /// Set the visualization level when invoking the display -int DD4hepUI::setVisLevel(int value) { +int detail::DD4hepUI::setVisLevel(int value) { int old_value = visLevel; visLevel = value; return old_value; } /// Install the dd4hep conditions manager object -Handle DD4hepUI::conditionsMgr() const { +Handle detail::DD4hepUI::conditionsMgr() const { if ( !m_condMgr.isValid() ) { const void* argv[] = {"-handle",&m_condMgr,0}; if ( 1 != apply("DD4hep_ConditionsManagerInstaller",2,(char**)argv) ) { @@ -73,7 +71,7 @@ Handle DD4hepUI::conditionsMgr() const { } /// Load conditions from file -long DD4hepUI::loadConditions(const std::string& fname) const { +long detail::DD4hepUI::loadConditions(const std::string& fname) const { Handle h = conditionsMgr(); if ( h.isValid() ) { m_detDesc.fromXML(fname, BUILD_DEFAULT); @@ -83,7 +81,7 @@ long DD4hepUI::loadConditions(const std::string& fname) const { } /// Install the dd4hep alignment manager object -Handle DD4hepUI::alignmentMgr() const { +Handle detail::DD4hepUI::alignmentMgr() const { if ( !m_alignMgr.isValid() ) { const void* argv[] = {"-handle",&m_alignMgr,0}; if ( 1 != apply("DD4hep_AlignmentsManagerInstaller",2,(char**)argv) ) { @@ -97,41 +95,41 @@ Handle DD4hepUI::alignmentMgr() const { } /// Detector interface: Manipulate geometry using facroy converter -long DD4hepUI::apply(const char* factory, int argc, char** argv) const { +long detail::DD4hepUI::apply(const char* factory, int argc, char** argv) const { return m_detDesc.apply(factory, argc, argv); } /// Detector interface: Read any geometry description or alignment file -void DD4hepUI::fromXML(const std::string& fname, DetectorBuildType type) const { +void detail::DD4hepUI::fromXML(const std::string& fname, DetectorBuildType type) const { return m_detDesc.fromXML(fname, type); } /// Detector interface: Draw the scene on a OpenGL pane -void DD4hepUI::draw() const { +void detail::DD4hepUI::draw() const { drawSubtree("/world"); } /// Detector interface: Re-draw the entire scene -void DD4hepUI::redraw() const { +void detail::DD4hepUI::redraw() const { redrawSubtree("/world"); } /// Detector interface: Draw detector sub-tree the scene on a OpenGL pane -void DD4hepUI::drawSubtree(const char* path) const { - string vis = _visLevel(visLevel); +void detail::DD4hepUI::drawSubtree(const char* path) const { + std::string vis = _visLevel(visLevel); const void* av[] = {"-detector", path, "-option", "ogl", "-level", vis.c_str(), 0}; m_detDesc.apply("DD4hep_GeometryDisplay", 2, (char**)av); } /// Detector interface: Re-draw the entire sub-tree scene -void DD4hepUI::redrawSubtree(const char* path) const { - string vis = _visLevel(visLevel); +void detail::DD4hepUI::redrawSubtree(const char* path) const { + std::string vis = _visLevel(visLevel); const void* av[] = {"-detector", path, "-option", "oglsame", "-level", vis.c_str(), 0}; m_detDesc.apply("DD4hep_GeometryDisplay", 4, (char**)av); } /// Dump the volume tree -long DD4hepUI::dumpVols(int argc, char** argv) const { +long detail::DD4hepUI::dumpVols(int argc, char** argv) const { if ( argc==0 ) { const void* av[] = {"-positions","-pointers",0}; return m_detDesc.apply("DD4hep_VolumeDump",2,(char**)av); @@ -140,25 +138,25 @@ long DD4hepUI::dumpVols(int argc, char** argv) const { } /// Dump the DetElement tree with placements -long DD4hepUI::dumpDet(const char* path) const { +long detail::DD4hepUI::dumpDet(const char* path) const { const void* args[] = {"--detector", path ? path : "/world", 0}; return m_detDesc.apply("DD4hep_DetectorVolumeDump",2,(char**)args); } /// Dump the DetElement tree with placements -long DD4hepUI::dumpDetMaterials(const char* path) const { +long detail::DD4hepUI::dumpDetMaterials(const char* path) const { const void* args[] = {"--detector", path ? path : "/world", "--materials", "--shapes", 0}; return m_detDesc.apply("DD4hep_DetectorVolumeDump",4,(char**)args); } /// Dump the DetElement tree with placements -long DD4hepUI::dumpStructure(const char* path) const { +long detail::DD4hepUI::dumpStructure(const char* path) const { const void* args[] = {"--detector", path ? path : "/world", 0}; return m_detDesc.apply("DD4hep_DetectorDump",2,(char**)args); } /// Dump the entire detector description object to a root file -long DD4hepUI::saveROOT(const char* file_name) const { +long detail::DD4hepUI::saveROOT(const char* file_name) const { if ( file_name ) { const void* av[] = {"-output",file_name,0}; return m_detDesc.apply("DD4hep_Geometry2ROOT",2,(char**)av); @@ -168,7 +166,7 @@ long DD4hepUI::saveROOT(const char* file_name) const { } /// Import the entire detector description object from a root file -long DD4hepUI::importROOT(const char* file_name) const { +long detail::DD4hepUI::importROOT(const char* file_name) const { if ( file_name ) { const void* av[] = {"-input",file_name,0}; return m_detDesc.apply("DD4hep_RootLoader",2,(char**)av); @@ -178,9 +176,9 @@ long DD4hepUI::importROOT(const char* file_name) const { } /// Create ROOT interpreter instance -long DD4hepUI::createInterpreter(int argc, char** argv) { +long detail::DD4hepUI::createInterpreter(int argc, char** argv) { if ( 0 == gApplication ) { - pair a(argc,argv); + std::pair a(argc,argv); gApplication = new TRint("DD4hepUI", &a.first, a.second); printout(INFO,"DD4hepUI","++ Created ROOT interpreter instance for DD4hepUI."); return 1; @@ -191,7 +189,7 @@ long DD4hepUI::createInterpreter(int argc, char** argv) { } /// Execute ROOT interpreter instance -long DD4hepUI::runInterpreter() const { +long detail::DD4hepUI::runInterpreter() const { if ( 0 != gApplication ) { if ( !gApplication->IsRunning() ) { gApplication->Run(); diff --git a/DDCore/src/DetectorData.cpp b/DDCore/src/DetectorData.cpp index f2ba99d47..0a9bc5183 100644 --- a/DDCore/src/DetectorData.cpp +++ b/DDCore/src/DetectorData.cpp @@ -26,7 +26,6 @@ #include #include - namespace dd4hep { namespace detail { class DetectorImp; }} using namespace dd4hep; diff --git a/DDCore/src/JSON/Detector.cpp b/DDCore/src/JSON/Detector.cpp index 2d4498fca..b19565c7d 100644 --- a/DDCore/src/JSON/Detector.cpp +++ b/DDCore/src/JSON/Detector.cpp @@ -13,11 +13,11 @@ #ifndef DD4HEP_NONE // Framework include files -#include "JSON/Detector.h" +#include // Instantiate here the concrete implementations #define DD4HEP_DIMENSION_NS json using namespace dd4hep::DD4HEP_DIMENSION_NS; -#include "Parsers/detail/Detector.imp" +#include #endif diff --git a/DDCore/src/JSON/DocumentHandler.cpp b/DDCore/src/JSON/DocumentHandler.cpp index af803f29f..14572832a 100644 --- a/DDCore/src/JSON/DocumentHandler.cpp +++ b/DDCore/src/JSON/DocumentHandler.cpp @@ -21,7 +21,6 @@ #include #include -using namespace std; using namespace dd4hep::json; /// Default constructor @@ -33,13 +32,13 @@ DocumentHandler::~DocumentHandler() { } /// Load XML file and parse it. -Document DocumentHandler::load(const string& fname) const { - string fn = fname; - if ( fname.find("://") != string::npos ) fn = fname.substr(fname.find("://")+3); - //string cmd = "cat "+fn; +Document DocumentHandler::load(const std::string& fname) const { + std::string fn = fname; + if ( fname.find("://") != std::string::npos ) fn = fname.substr(fname.find("://")+3); + //std::string cmd = "cat "+fn; //::printf("\n\n+++++ Dump json file: %s\n\n\n",fn.c_str()); //::system(cmd.c_str()); - unique_ptr doc(new JsonElement(fn, ptree())); + std::unique_ptr doc(new JsonElement(fn, ptree())); boost::property_tree::read_json(fn,doc->second); return doc.release(); } @@ -47,5 +46,5 @@ Document DocumentHandler::load(const string& fname) const { /// Parse a standalong XML string into a document. Document DocumentHandler::parse(const char* doc_string, size_t length) const { if ( doc_string && length ) {} - throw runtime_error("Bla"); + throw std::runtime_error("Bla"); } diff --git a/DDCore/src/JSON/Elements.cpp b/DDCore/src/JSON/Elements.cpp index af5d417cc..a52804c1e 100644 --- a/DDCore/src/JSON/Elements.cpp +++ b/DDCore/src/JSON/Elements.cpp @@ -12,8 +12,8 @@ //========================================================================== // Framework include files -#include "JSON/Printout.h" -#include "JSON/Elements.h" +#include +#include // C/C++ include files #include @@ -21,21 +21,20 @@ #include #include -using namespace std; using namespace dd4hep::json; static const size_t INVALID_NODE = ~0U; // Forward declarations namespace dd4hep { - std::pair _toInteger(const string& value); - std::pair _toFloatingPoint(const string& value); - void _toDictionary(const string& name, const string& value, const string& typ); - string _getEnviron(const string& env); + std::pair _toInteger(const std::string& value); + std::pair _toFloatingPoint(const std::string& value); + void _toDictionary(const std::string& name, const std::string& value, const std::string& typ); + std::string _getEnviron(const std::string& env); } // Static storage namespace { - string _checkEnviron(const string& env) { - string r = dd4hep::_getEnviron(env); + std::string _checkEnviron(const std::string& env) { + std::string r = dd4hep::_getEnviron(env); return r.empty() ? env : r; } } @@ -50,7 +49,7 @@ namespace { JsonElement* node_first(JsonElement* e, const char* tag) { if ( e ) { - string t(tag); + std::string t(tag); if ( t == "*" ) { ptree::iterator i = e->second.begin(); return i != e->second.end() ? &(*i) : 0; @@ -61,7 +60,7 @@ namespace { return 0; } - size_t node_count(JsonElement* e, const string& t) { + size_t node_count(JsonElement* e, const std::string& t) { return e ? (t=="*" ? e->second.size() : e->second.count(t)) : 0; } @@ -78,64 +77,64 @@ namespace { } } -string dd4hep::json::_toString(Attribute attr) { +std::string dd4hep::json::_toString(Attribute attr) { if (attr) return _toString(attribute_value(attr)); return ""; } -template static inline string __to_string(T value, const char* fmt) { +template static inline std::string __to_string(T value, const char* fmt) { char text[128]; ::snprintf(text, sizeof(text), fmt, value); return text; } /// Do-nothing version. Present for completeness and argument interchangeability -string dd4hep::json::_toString(const char* s) { +std::string dd4hep::json::_toString(const char* s) { if ( !s || *s == 0 ) return ""; else if ( !(*s == '$' && *(s+1) == '{') ) return s; return _checkEnviron(s); } /// Do-nothing version. Present for completeness and argument interchangeability -string dd4hep::json::_toString(const string& s) { +std::string dd4hep::json::_toString(const std::string& s) { if ( s.length() < 3 || s[0] != '$' ) return s; else if ( !(s[0] == '$' && s[1] == '{') ) return s; return _checkEnviron(s); } /// Format unsigned long integer to string with arbitrary format -string dd4hep::json::_toString(unsigned long v, const char* fmt) { +std::string dd4hep::json::_toString(unsigned long v, const char* fmt) { return __to_string(v, fmt); } /// Format unsigned integer (32 bits) to string with arbitrary format -string dd4hep::json::_toString(unsigned int v, const char* fmt) { +std::string dd4hep::json::_toString(unsigned int v, const char* fmt) { return __to_string(v, fmt); } /// Format signed integer (32 bits) to string with arbitrary format -string dd4hep::json::_toString(int v, const char* fmt) { +std::string dd4hep::json::_toString(int v, const char* fmt) { return __to_string(v, fmt); } /// Format signed long integer to string with arbitrary format -string dd4hep::json::_toString(long v, const char* fmt) { +std::string dd4hep::json::_toString(long v, const char* fmt) { return __to_string(v, fmt); } /// Format single procision float number (32 bits) to string with arbitrary format -string dd4hep::json::_toString(float v, const char* fmt) { +std::string dd4hep::json::_toString(float v, const char* fmt) { return __to_string(v, fmt); } /// Format double procision float number (64 bits) to string with arbitrary format -string dd4hep::json::_toString(double v, const char* fmt) { +std::string dd4hep::json::_toString(double v, const char* fmt) { return __to_string(v, fmt); } /// Format pointer to string with arbitrary format -string dd4hep::json::_ptrToString(const void* v, const char* fmt) { +std::string dd4hep::json::_ptrToString(const void* v, const char* fmt) { return __to_string(v, fmt); } @@ -149,7 +148,7 @@ int dd4hep::json::_toInt(const char* value) { bool dd4hep::json::_toBool(const char* value) { if (value) { - string s = _toString(value); + std::string s = _toString(value); return s == "true"; } return false; @@ -171,7 +170,7 @@ template void dd4hep::json::_toDictionary(const char* name, T value dd4hep::_toDictionary(name, _toString(value), "number"); } -template void dd4hep::json::_toDictionary(const char* name, const string& value); +template void dd4hep::json::_toDictionary(const char* name, const std::string& value); template void dd4hep::json::_toDictionary(const char* name, unsigned long value); template void dd4hep::json::_toDictionary(const char* name, unsigned int value); template void dd4hep::json::_toDictionary(const char* name, unsigned short value); @@ -182,7 +181,7 @@ template void dd4hep::json::_toDictionary(const char* name, float value); template void dd4hep::json::_toDictionary(const char* name, double value); /// Evaluate string constant using environment stored in the evaluator -string dd4hep::json::getEnviron(const string& env) { +std::string dd4hep::json::getEnviron(const std::string& env) { return dd4hep::_getEnviron(env); } @@ -194,7 +193,7 @@ NodeList::NodeList(const NodeList& copy) } /// Initializing constructor -NodeList::NodeList(JsonElement* node, const string& tag_value) +NodeList::NodeList(JsonElement* node, const std::string& tag_value) : m_tag(tag_value), m_node(node) { reset(); @@ -207,7 +206,7 @@ NodeList::~NodeList() { /// Reset the nodelist JsonElement* NodeList::reset() { if ( m_tag == "*" ) - m_ptr = make_pair(m_node->second.ordered_begin(), m_node->second.not_found()); + m_ptr = std::make_pair(m_node->second.ordered_begin(), m_node->second.not_found()); else m_ptr = m_node->second.equal_range(m_tag); if ( m_ptr.first != m_ptr.second ) @@ -269,8 +268,8 @@ bool Handle_t::hasAttr(const char* tag_value) const { } /// Retrieve a collection of all attributes of this DOM element -vector Handle_t::attributes() const { - vector < Attribute > attrs; +std::vector Handle_t::attributes() const { + std::vector < Attribute > attrs; if (m_node) { for(ptree::iterator i=m_node->second.begin(); i!=m_node->second.end(); ++i) { Attribute a = &(*i); @@ -286,12 +285,12 @@ size_t Handle_t::numChildren(const char* t, bool throw_exception) const { return 0; else if (n != INVALID_NODE) return n; - string msg = "Handle_t::numChildren: "; + std::string msg = "Handle_t::numChildren: "; if (m_node) msg += "Element [" + tag() + "] has no children of type '" + _toString(t) + "'"; else msg += "Element [INVALID] has no children of type '" + _toString(t) + "'"; - throw runtime_error(msg); + throw std::runtime_error(msg); } /// Remove a single child node identified by its handle from the tree of the element @@ -299,12 +298,12 @@ Handle_t Handle_t::child(const char* t, bool throw_exception) const { Elt_t e = node_first(m_node, t); if (e || !throw_exception) return e; - string msg = "Handle_t::child: "; + std::string msg = "Handle_t::child: "; if (m_node) msg += "Element [" + tag() + "] has no child of type '" + _toString(t) + "'"; else msg += "Element [INVALID]. Cannot remove child of type: '" + _toString(t) + "'"; - throw runtime_error(msg); + throw std::runtime_error(msg); } NodeList Handle_t::children(const char* tag_value) const { @@ -320,12 +319,12 @@ Attribute Handle_t::attr_ptr(const char* t) const { Attribute a = attribute_node(m_node, t); if (0 != a) return a; - string msg = "Handle_t::attr_ptr: "; + std::string msg = "Handle_t::attr_ptr: "; if (m_node) msg += "Element [" + tag() + "] has no attribute of type '" + _toString(t) + "'"; else msg += "Element [INVALID] has no attribute of type '" + _toString(t) + "'"; - throw runtime_error(msg); + throw std::runtime_error(msg); } /// Access attribute name (throws exception if not present) @@ -333,7 +332,7 @@ const char* Handle_t::attr_name(const Attribute a) const { if (a) { return a->first.c_str(); } - throw runtime_error("Attempt to access invalid XML attribute object!"); + throw std::runtime_error("Attempt to access invalid XML attribute object!"); } /// Access attribute value by the attribute's unicode name (throws exception if not present) @@ -358,7 +357,7 @@ Handle_t Document::root() const { if ( m_doc ) { return m_doc; } - throw runtime_error("Document::root: Invalid handle!"); + throw std::runtime_error("Document::root: Invalid handle!"); } /// Assign new document. Old document is dropped. @@ -403,11 +402,11 @@ size_t Collection_t::size() const { } /// Helper function to throw an exception -void Collection_t::throw_loop_exception(const exception& e) const { +void Collection_t::throw_loop_exception(const std::exception& e) const { if (m_node) { - throw runtime_error(string(e.what()) + "\n" + "dd4hep: Error interpreting XML nodes of type <" + tag() + "/>"); + throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting XML nodes of type <" + tag() + "/>"); } - throw runtime_error(string(e.what()) + "\n" + "dd4hep: Error interpreting collections XML nodes."); + throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting collections XML nodes."); } void Collection_t::operator++() const { @@ -444,8 +443,8 @@ void dd4hep::json::dumpTree(Element elt) { void dd4hep::json::dumpTree(const JsonElement* elt) { struct Dump { - void operator()(const JsonElement* e, const string& tag) const { - string t = tag+" "; + void operator()(const JsonElement* e, const std::string& tag) const { + std::string t = tag+" "; printout(INFO,"DumpTree","+++ %s %s: %s",tag.c_str(), e->first.c_str(), e->second.data().c_str()); for(auto i=e->second.begin(); i!=e->second.end(); ++i) (*this)(&(*i), t); diff --git a/DDCore/src/JSON/Helpers.cpp b/DDCore/src/JSON/Helpers.cpp index bd8bcbff4..8c172d166 100644 --- a/DDCore/src/JSON/Helpers.cpp +++ b/DDCore/src/JSON/Helpers.cpp @@ -12,8 +12,8 @@ //========================================================================== // Framework include files -#include "JSON/Dimension.inl" -#include "JSON/ChildValue.inl" +#include +#include // Instantiate here the concrete implementations #define DD4HEP_DIMENSION_NS json diff --git a/DDCore/src/Path.cpp b/DDCore/src/Path.cpp index a3e314be4..b8b2e9b0e 100644 --- a/DDCore/src/Path.cpp +++ b/DDCore/src/Path.cpp @@ -13,15 +13,15 @@ // //========================================================================== -#include "DD4hep/Path.h" +/// Framework include files +#include + +/// C/C++ include files #include #include #include #include -using namespace std; -using namespace dd4hep; - namespace { const char dot = '.'; const char separator = '/'; @@ -31,11 +31,11 @@ namespace { inline bool is_separator(char c) { return c == separator; } - bool is_root_separator(const string& str, size_t pos) + bool is_root_separator(const std::string& str, size_t pos) // pos is position of the separator { if ( str.empty() || is_separator(str[pos]) ) { - throw runtime_error("precondition violation"); + throw std::runtime_error("precondition violation"); } // subsequent logic expects pos to be for leftmost slash of a set while (pos > 0 && is_separator(str[pos-1])) @@ -51,7 +51,7 @@ namespace { return str.find_first_of(separators, 2) == pos; } - size_t filename_pos(const string& str,size_t end_pos) + size_t filename_pos(const std::string& str,size_t end_pos) // return 0 if str itself is filename (or empty) { // case: "//" @@ -66,34 +66,36 @@ namespace { // set pos to start of last element size_t pos(str.find_last_of(separators, end_pos-1)); - return (pos == string::npos // path itself must be a filename (or empty) + return (pos == std::string::npos // path itself must be a filename (or empty) || (pos == 1 && is_separator(str[0]))) // or net ? 0 // so filename is entire string : pos + 1; // or starts after delimiter } // return npos if no root_directory found - size_t root_directory_start(const string& path, size_t size) { + size_t root_directory_start(const std::string& path, size_t size) { // case "//" if (size == 2 && is_separator(path[0]) - && is_separator(path[1])) return string::npos; + && is_separator(path[1])) return std::string::npos; // case "//net {/}" if (size > 3 && is_separator(path[0]) && is_separator(path[1]) && !is_separator(path[2])) { - string::size_type pos(path.find_first_of(separators, 2)); - return pos < size ? pos : string::npos; + std::string::size_type pos(path.find_first_of(separators, 2)); + return pos < size ? pos : std::string::npos; } // case "/" if (size > 0 && is_separator(path[0])) return 0; - return string::npos; + return std::string::npos; } } +using Path = dd4hep::Path; + const Path& Path::detail::dot_path() { static Path p("."); return p; @@ -113,7 +115,7 @@ Path Path::normalize() const { if (empty()) return *this; - vector pathes; + std::vector pathes; char tmp[PATH_MAX]; ::strncpy(tmp, string_data(), sizeof(tmp)); tmp[sizeof(tmp)-1] = 0; @@ -124,10 +126,10 @@ Path Path::normalize() const { token = ::strtok_r(0,separators,&save); } Path temp; - vector::const_iterator start(pathes.begin()); - vector::const_iterator last(pathes.end()); - vector::const_iterator stop(last--); - for (vector::const_iterator itr(start); itr != stop; ++itr) { + std::vector::const_iterator start(pathes.begin()); + std::vector::const_iterator last(pathes.end()); + std::vector::const_iterator stop(last--); + for (std::vector::const_iterator itr(start); itr != stop; ++itr) { // ignore "." except at start and last Path itr_path(*itr); if (itr_path.native().size() == 1 @@ -136,7 +138,7 @@ Path Path::normalize() const { && itr != last) continue; // ignore a name and following ".." - if ( temp.empty() && itr_path.find(colon) != string::npos ) { + if ( temp.empty() && itr_path.find(colon) != std::string::npos ) { temp = itr_path; continue; } @@ -145,7 +147,7 @@ Path Path::normalize() const { && (itr_path.native())[0] == dot && (itr_path.native())[1] == dot) // dot dot { - string lf(temp.filename().native()); + std::string lf(temp.filename().native()); if (lf.size() > 0 && (lf.size() != 1 || (lf[0] != dot && lf[0] != separator)) && (lf.size() != 2 || (lf[0] != dot && lf[1] != dot)) ) @@ -165,7 +167,7 @@ Path Path::normalize() const { // } //} - vector::const_iterator next(itr); + std::vector::const_iterator next(itr); if (temp.empty() && ++next != stop && next == last && *last == detail::dot_path()) { temp /= detail::dot_path(); } @@ -192,7 +194,7 @@ size_t Path::parent_path_end() const { ; --end_pos) {} - return (end_pos == 1 && root_dir_pos == 0 && filename_was_separator) ? string::npos : end_pos; + return (end_pos == 1 && root_dir_pos == 0 && filename_was_separator) ? std::string::npos : end_pos; } @@ -203,7 +205,7 @@ Path& Path::remove_filename() { Path Path::parent_path() const { size_t end_pos(parent_path_end()); - return end_pos == string::npos ? Path() : Path(string_data(), string_data() + end_pos); + return end_pos == std::string::npos ? Path() : Path(string_data(), string_data() + end_pos); } Path Path::filename() const diff --git a/DDCore/src/XML/Detector.cpp b/DDCore/src/XML/Detector.cpp index 693f390d2..1662debb3 100644 --- a/DDCore/src/XML/Detector.cpp +++ b/DDCore/src/XML/Detector.cpp @@ -13,7 +13,7 @@ #ifndef DD4HEP_NONE // Framework include files -#include "XML/XMLDetector.h" +#include // Instantiate here the concrete implementations #define DD4HEP_DIMENSION_NS xml diff --git a/DDCore/src/XML/DocumentHandler.cpp b/DDCore/src/XML/DocumentHandler.cpp index 10aa758e6..f929732a2 100644 --- a/DDCore/src/XML/DocumentHandler.cpp +++ b/DDCore/src/XML/DocumentHandler.cpp @@ -12,9 +12,9 @@ //========================================================================== // Framework include files -#include "XML/Printout.h" -#include "XML/UriReader.h" -#include "XML/DocumentHandler.h" +#include +#include +#include // C/C++ include files #include @@ -25,41 +25,39 @@ #ifndef _WIN32 #include #endif -#include "TSystem.h" +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::xml; namespace { - string undressed_file_name(const string& fn) { + std::string undressed_file_name(const std::string& fn) { if ( !fn.empty() ) { TString tfn(fn); gSystem->ExpandPathName(tfn); - return string(tfn.Data()); + return std::string(tfn.Data()); } return fn; } - int s_minPrintLevel = INFO; + int s_minPrintLevel = dd4hep::INFO; } #ifndef __TIXML__ -#include "xercesc/framework/LocalFileFormatTarget.hpp" -#include "xercesc/framework/StdOutFormatTarget.hpp" -#include "xercesc/framework/MemBufFormatTarget.hpp" -#include "xercesc/framework/MemBufInputSource.hpp" -#include "xercesc/sax/SAXParseException.hpp" -#include "xercesc/sax/EntityResolver.hpp" -#include "xercesc/sax/InputSource.hpp" -#include "xercesc/parsers/XercesDOMParser.hpp" -#include "xercesc/util/XMLEntityResolver.hpp" -#include "xercesc/util/PlatformUtils.hpp" -#include "xercesc/util/XercesDefs.hpp" -#include "xercesc/util/XMLUni.hpp" -#include "xercesc/util/XMLURL.hpp" -#include "xercesc/util/XMLString.hpp" -#include "xercesc/dom/DOM.hpp" -#include "xercesc/sax/ErrorHandler.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace xercesc; @@ -95,7 +93,7 @@ namespace dd4hep { /// Dom Error handler callback bool DocumentErrorHandler::handleError(const DOMError& domError) { - string err = "DOM UNKNOWN: "; + std::string err = "DOM UNKNOWN: "; switch (domError.getSeverity()) { case DOMError::DOM_SEVERITY_WARNING: err = "DOM WARNING: "; @@ -120,22 +118,22 @@ namespace dd4hep { } /// Error handler void DocumentErrorHandler::error(const SAXParseException& e) { - string m(_toString(e.getMessage())); - if (m.find("The values for attribute 'name' must be names or name tokens") != string::npos - || m.find("The values for attribute 'ID' must be names or name tokens") != string::npos - || m.find("for attribute 'name' must be Name or Nmtoken") != string::npos - || m.find("for attribute 'ID' must be Name or Nmtoken") != string::npos - || m.find("for attribute 'name' is invalid Name or NMTOKEN value") != string::npos - || m.find("for attribute 'ID' is invalid Name or NMTOKEN value") != string::npos) + std::string m(_toString(e.getMessage())); + if (m.find("The values for attribute 'name' must be names or name tokens") != std::string::npos + || m.find("The values for attribute 'ID' must be names or name tokens") != std::string::npos + || m.find("for attribute 'name' must be Name or Nmtoken") != std::string::npos + || m.find("for attribute 'ID' must be Name or Nmtoken") != std::string::npos + || m.find("for attribute 'name' is invalid Name or NMTOKEN value") != std::string::npos + || m.find("for attribute 'ID' is invalid Name or NMTOKEN value") != std::string::npos) return; - string sys(_toString(e.getSystemId())); + std::string sys(_toString(e.getSystemId())); printout(ERROR,"XercesC","+++ Error at file \"%s\", Line %d Column: %d Message:%s", sys.c_str(), int(e.getLineNumber()), int(e.getColumnNumber()), m.c_str()); } /// Fatal error handler void DocumentErrorHandler::fatalError(const SAXParseException& e) { - string m(_toString(e.getMessage())); - string sys(_toString(e.getSystemId())); + std::string m(_toString(e.getMessage())); + std::string sys(_toString(e.getSystemId())); printout(FATAL,"XercesC","+++ FATAL Error at file \"%s\", Line %d Column: %d Message:%s", sys.c_str(), int(e.getLineNumber()), int(e.getColumnNumber()), m.c_str()); } @@ -171,13 +169,13 @@ namespace dd4hep { /// Entity resolver overload to use uri reader InputSource *read_uri(XMLResourceIdentifier *id) { if ( m_reader ) { - string buf, systemID(_toString(id->getSystemId())); + std::string buf, systemID(_toString(id->getSystemId())); if ( m_reader->load(systemID, buf) ) { const XMLByte* input = (const XMLByte*)XMLString::replicate(buf.c_str()); #if 0 - string baseURI(_toString(id->getBaseURI())); - string schema(_toString(id->getSchemaLocation())); - string ns(_toString(id->getNameSpace())); + std::string baseURI(_toString(id->getBaseURI())); + std::string schema(_toString(id->getSchemaLocation())); + std::string ns(_toString(id->getNameSpace())); if ( s_minPrintLevel <= INFO ) { printout(INFO,"XercesC","+++ Resolved URI: sysID:%s uri:%s ns:%s schema:%s", systemID.c_str(), baseURI.c_str(), ns.c_str(), schema.c_str()); @@ -208,7 +206,7 @@ namespace dd4hep { } /// Dump DOM tree using XercesC handles - void dumpTree(DOMNode* doc, ostream& os) { + void dumpTree(DOMNode* doc, std::ostream& os) { if ( doc ) { DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(Strng_t("LS")); MemBufFormatTarget *tar = new MemBufFormatTarget(); @@ -217,7 +215,7 @@ namespace dd4hep { out->setByteStream(tar); wrt->getDomConfig()->setParameter(Strng_t("format-pretty-print"), true); wrt->write(doc, out); - os << tar->getRawBuffer() << endl << flush; + os << tar->getRawBuffer() << std::endl << std::flush; out->release(); wrt->release(); return; @@ -226,15 +224,15 @@ namespace dd4hep { } /// Dump DOM tree using XercesC handles - void dump_doc(DOMDocument* doc, ostream& os) { + void dump_doc(DOMDocument* doc, std::ostream& os) { dumpTree(doc,os); } /// Dump DOM tree using XercesC handles - void dump_tree(Handle_t elt, ostream& os) { + void dump_tree(Handle_t elt, std::ostream& os) { dumpTree((DOMNode*)elt.ptr(),os); } /// Dump DOM tree using XercesC handles - void dump_tree(Document doc, ostream& os) { + void dump_tree(Document doc, std::ostream& os) { dump_doc((DOMDocument*)doc.ptr(),os); } } @@ -242,36 +240,36 @@ namespace dd4hep { #ifdef DD4HEP_NONE /// System ID of a given XML entity -string DocumentHandler::system_path(Handle_t base, const string& fn) { - string path = system_path(base); - string dir = ::dirname((char*)path.c_str()); +std::string DocumentHandler::system_path(Handle_t base, const std::string& fn) { + std::string path = system_path(base); + std::string dir = ::dirname((char*)path.c_str()); return dir+fn; } #else -#include "TUri.h" -#include "TUrl.h" +#include +#include #endif /// System ID of a given XML entity -string DocumentHandler::system_path(Handle_t base, const string& fn) { - string path, dir = system_path(base); +std::string DocumentHandler::system_path(Handle_t base, const std::string& fn) { + std::string path, dir = system_path(base); TUri uri_base(dir.c_str()), uri_rel(fn.c_str()); TUrl url_base(dir.c_str()); path = TUri::MergePaths(uri_rel,uri_base); TUri final(path.c_str()); final.Normalise(); - path = url_base.GetProtocol()+string("://")+final.GetUri().Data(); + path = url_base.GetProtocol()+std::string("://")+final.GetUri().Data(); if ( path[path.length()-1]=='/' ) path = path.substr(0,path.length()-1); return path; } /// System ID of a given XML entity -string DocumentHandler::system_path(Handle_t base) { +std::string DocumentHandler::system_path(Handle_t base) { DOMElement* elt = (DOMElement*)base.ptr(); - string path = _toString(elt->getBaseURI()); + std::string path = _toString(elt->getBaseURI()); if ( path[0] == '/' ) { - string tmp = "file:"+path; + std::string tmp = "file:"+path; return tmp; } return path; @@ -279,7 +277,7 @@ string DocumentHandler::system_path(Handle_t base) { /// Load secondary XML file with relative addressing with respect to handle Document DocumentHandler::load(Handle_t base, const XMLCh* fname, UriReader* reader) const { - string path; + std::string path; DOMElement* elt = (DOMElement*)base.ptr(); try { Document doc; @@ -294,21 +292,21 @@ Document DocumentHandler::load(Handle_t base, const XMLCh* fname, UriReader* rea } return load(path, reader); } - catch(const exception& exc) { - string b = _toString(elt->getBaseURI()); - string e = _toString(fname); + catch(const std::exception& exc) { + std::string b = _toString(elt->getBaseURI()); + std::string e = _toString(fname); printout(DEBUG,"DocumentHandler","+++ URI exception: %s -> %s [%s]",b.c_str(),e.c_str(),exc.what()); } catch(...) { - string b = _toString(elt->getBaseURI()); - string e = _toString(fname); + std::string b = _toString(elt->getBaseURI()); + std::string e = _toString(fname); printout(DEBUG,"DocumentHandler","+++ URI exception: %s -> %s",b.c_str(),e.c_str()); } if ( reader ) { - string buf, sys = system_path(base,fname); + std::string buf, sys = system_path(base,fname); #if 0 - string buf, sys, dir = _toString(elt->getBaseURI()); - string fn = _toString(fname); + std::string buf, sys, dir = _toString(elt->getBaseURI()); + std::string fn = _toString(fname); dir = ::dirname((char*)dir.c_str()); while( fn.substr(0,3) == "../" ) { dir = ::dirname((char*)dir.c_str()); @@ -329,21 +327,21 @@ Document DocumentHandler::load(Handle_t base, const XMLCh* fname, UriReader* rea } /// Load XML file and parse it using URI resolver to read data. -Document DocumentHandler::load(const string& fname, UriReader* reader) const { - string path; +Document DocumentHandler::load(const std::string& fname, UriReader* reader) const { + std::string path; printout(DEBUG,"DocumentHandler","+++ Loading document URI: %s",fname.c_str()); try { size_t idx = fname.find(':'); size_t idq = fname.find('/'); - if ( idq == string::npos ) idq = 0; - XMLURL xerurl = (const XMLCh*) Strng_t(idx==string::npos || idx>idq ? "file:"+fname : fname); - string proto = _toString(xerurl.getProtocolName()); + if ( idq == std::string::npos ) idq = 0; + XMLURL xerurl = (const XMLCh*) Strng_t(idx==std::string::npos || idx>idq ? "file:"+fname : fname); + std::string proto = _toString(xerurl.getProtocolName()); path = _toString(xerurl.getPath()); printout(DEBUG,"DocumentHandler","+++ protocol:%s path:%s",proto.c_str(), path.c_str()); } catch(...) { } - unique_ptr < XercesDOMParser > parser(make_parser(reader)); + std::unique_ptr < XercesDOMParser > parser(make_parser(reader)); try { if ( !path.empty() ) { parser->parse(path.c_str()); @@ -358,13 +356,13 @@ Document DocumentHandler::load(const string& fname, UriReader* reader) const { return (XmlDocument*)0; } } - catch (const exception& e) { + catch (const std::exception& e) { printout(ERROR,"DocumentHandler","+++ Exception(XercesC): parse(path):%s",e.what()); try { parser->parse(fname.c_str()); if ( reader ) reader->parserLoaded(path); } - catch (const exception& ex) { + catch (const std::exception& ex) { printout(FATAL,"DocumentHandler","+++ Exception(XercesC): parse(URI):%s",ex.what()); throw; } @@ -375,7 +373,7 @@ Document DocumentHandler::load(const string& fname, UriReader* reader) const { /// Parse a standalong XML string into a document. Document DocumentHandler::parse(const char* bytes, size_t length, const char* sys_id, UriReader* rdr) const { - unique_ptr < XercesDOMParser > parser(make_parser(rdr)); + std::unique_ptr < XercesDOMParser > parser(make_parser(rdr)); MemBufInputSource src((const XMLByte*)bytes, length, sys_id, false); parser->parse(src); DOMDocument* doc = parser->adoptDocument(); @@ -385,7 +383,7 @@ Document DocumentHandler::parse(const char* bytes, size_t length, const char* sy } /// Write xml document to output file (stdout if file name empty) -int DocumentHandler::output(Document doc, const string& fname) const { +int DocumentHandler::output(Document doc, const std::string& fname) const { XMLFormatTarget *tar = 0; DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(Strng_t("LS")); DOMLSOutput *out = imp->createLSOutput(); @@ -394,7 +392,7 @@ int DocumentHandler::output(Document doc, const string& fname) const { if (fname.empty()) tar = new StdOutFormatTarget(); else { - string fn = undressed_file_name(fname); + std::string fn = undressed_file_name(fname); tar = new LocalFileFormatTarget(Strng_t(fn)); } out->setByteStream(tar); @@ -408,7 +406,7 @@ int DocumentHandler::output(Document doc, const string& fname) const { #else -#include "XML/tinyxml.h" +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -434,7 +432,7 @@ namespace dd4hep { }} namespace { - static string _clean_fname(const string& s) { + static std::string _clean_fname(const std::string& s) { std::string const& temp = getEnviron(s); std::string temp2 = undressed_file_name(temp.empty() ? s : temp); if ( strncmp(temp2.c_str(),"file:",5)==0 ) return temp2.substr(5); @@ -443,13 +441,13 @@ namespace { } /// System ID of a given XML entity -string DocumentHandler::system_path(Handle_t base, const string& fname) { - string fn, clean = _clean_fname(fname); +std::string DocumentHandler::system_path(Handle_t base, const std::string& fname) { + std::string fn, clean = _clean_fname(fname); struct stat st; Element elt(base); // Poor man's URI handling. Xerces is much much better here if ( elt ) { - string bn = Xml(elt.document()).d->Value(); + std::string bn = Xml(elt.document()).d->Value(); #ifdef _WIN32 char drive[_MAX_DRIVE], dir[_MAX_DIR], file[_MAX_FNAME], ext[_MAX_EXT]; ::_splitpath(bn.c_str(),drive,dir,file,ext); @@ -472,8 +470,8 @@ string DocumentHandler::system_path(Handle_t base, const string& fname) { } /// System ID of a given XML entity -string DocumentHandler::system_path(Handle_t base) { - string fn; +std::string DocumentHandler::system_path(Handle_t base) { + std::string fn; Element elt(base); // Poor man's URI handling. Xerces is much much better here if ( elt ) { @@ -484,7 +482,7 @@ string DocumentHandler::system_path(Handle_t base) { /// Load XML file and parse it using URI resolver to read data. Document DocumentHandler::load(const std::string& fname, UriReader* reader) const { - string clean = _clean_fname(fname); + std::string clean = _clean_fname(fname); if ( reader ) { printout(WARNING,"DocumentHandler","+++ Loading document URI: %s %s", fname.c_str(),"[URI Resolution is not supported by TiXML]"); @@ -526,7 +524,7 @@ Document DocumentHandler::load(const std::string& fname, UriReader* reader) cons /// Load XML file and parse it using URI resolver to read data. Document DocumentHandler::load(Handle_t base, const XmlChar* fname, UriReader* reader) const { - string path = system_path(base, fname); + std::string path = system_path(base, fname); return load(path,reader); } @@ -543,7 +541,7 @@ Document DocumentHandler::parse(const char* bytes, size_t length, const char* /* size_t len = length; // TiXml does not support white spaces at the end. Check and remove. if ( str_len+1 != len || bytes[str_len] != 0 || ::isspace(bytes[str_len-1]) ) { - unique_ptr data(new char[len+1]); + std::unique_ptr data(new char[len+1]); char* buff = data.get(); try { ::memcpy(buff, bytes, len+1); @@ -567,13 +565,13 @@ Document DocumentHandler::parse(const char* bytes, size_t length, const char* /* printout(FATAL,"DocumentHandler", "+++ XML Document error: %s Location Line:%d Column:%d", doc->Value(), doc->ErrorRow(), doc->ErrorCol()); - throw runtime_error(string("dd4hep: ")+doc->ErrorDesc()); + throw std::runtime_error(std::string("dd4hep: ")+doc->ErrorDesc()); } - throw runtime_error("dd4hep: Unknown error while parsing XML document string with TiXml."); + throw std::runtime_error("dd4hep: Unknown error while parsing XML document string with TiXml."); } - throw runtime_error("dd4hep: FAILED to parse invalid document string [NULL] with TiXml."); + throw std::runtime_error("dd4hep: FAILED to parse invalid document string [NULL] with TiXml."); } - catch(exception& e) { + catch(std::exception& e) { printout(ERROR,"DocumentHandler","+++ Exception (TinyXML): parse(string):%s",e.what()); } delete doc; @@ -581,8 +579,8 @@ Document DocumentHandler::parse(const char* bytes, size_t length, const char* /* } /// Write xml document to output file (stdout if file name empty) -int DocumentHandler::output(Document doc, const string& fname) const { - string fn = undressed_file_name(fname); +int DocumentHandler::output(Document doc, const std::string& fname) const { + std::string fn = undressed_file_name(fname); FILE* file = fn.empty() ? stdout : ::fopen(fn.c_str(),"w"); if ( !file ) { printout(ERROR,"DocumentHandler","+++ Failed to open output file: %s",fname.c_str()); @@ -595,7 +593,7 @@ int DocumentHandler::output(Document doc, const string& fname) const { } /// Dump partial or full XML trees -void dd4hep::xml::dump_tree(Handle_t elt, ostream& os) { +void dd4hep::xml::dump_tree(Handle_t elt, std::ostream& os) { TiXmlNode* node = (TiXmlNode*)elt.ptr(); TiXmlPrinter printer; printer.SetStreamPrinting(); @@ -604,7 +602,7 @@ void dd4hep::xml::dump_tree(Handle_t elt, ostream& os) { } /// Dump partial or full XML documents -void dd4hep::xml::dump_tree(Document doc, ostream& os) { +void dd4hep::xml::dump_tree(Document doc, std::ostream& os) { TiXmlDocument* node = (TiXmlDocument*)doc.ptr(); TiXmlPrinter printer; printer.SetStreamPrinting(); @@ -659,29 +657,29 @@ Document DocumentHandler::parse(const char* bytes, size_t length) const { } /// System ID of a given XML entity -string DocumentHandler::system_path(Handle_t base, const XmlChar* fname) { - string fn = _toString(fname); +std::string DocumentHandler::system_path(Handle_t base, const XmlChar* fname) { + std::string fn = _toString(fname); return system_path(base, fn); } /// System directory of a given XML entity -string DocumentHandler::system_directory(Handle_t base, const XmlChar* fname) { - string path = system_path(base,fname); - string dir = ::dirname((char*)path.c_str()); +std::string DocumentHandler::system_directory(Handle_t base, const XmlChar* fname) { + std::string path = system_path(base,fname); + std::string dir = ::dirname((char*)path.c_str()); return dir; } /// System directory of a given XML entity -string DocumentHandler::system_directory(Handle_t base) { - string path = system_path(base); - string dir = ::dirname((char*)path.c_str()); +std::string DocumentHandler::system_directory(Handle_t base) { + std::string path = system_path(base); + std::string dir = ::dirname((char*)path.c_str()); return dir; } /// Create new XML document by parsing empty xml buffer Document DocumentHandler::create(const char* tag, const char* comment) const { - string top(tag); - string empty = "\n"; + std::string top(tag); + std::string empty = "\n"; empty += "<" + top + "/>\0\0"; Document doc = parse(empty.c_str(), empty.length() + 1); if (comment) { @@ -698,10 +696,10 @@ Document DocumentHandler::create(const std::string& tag, const std::string& comm /// Dump partial or full XML trees to stdout void dd4hep::xml::dump_tree(Handle_t elt) { - dump_tree(elt,cout); + dump_tree(elt,std::cout); } /// Dump partial or full XML documents to stdout void dd4hep::xml::dump_tree(Document doc) { - dump_tree(doc,cout); + dump_tree(doc,std::cout); } diff --git a/DDCore/src/XML/Layering.cpp b/DDCore/src/XML/Layering.cpp index a3e6a285e..c1f37895b 100644 --- a/DDCore/src/XML/Layering.cpp +++ b/DDCore/src/XML/Layering.cpp @@ -13,107 +13,92 @@ #ifndef DD4HEP_NONE // Framework include files -#include "DD4hep/Primitives.h" -#include "XML/XMLDetector.h" -#include "XML/Layering.h" -#include "XML/XMLTags.h" +#include +#include +#include +#include -// C/C++ include files -#include -#include -#include -#include - -using namespace std; -using namespace dd4hep; -using namespace dd4hep::xml; - -void Layer::compute() { +void dd4hep::Layer::compute() { _thickness = 0.; - for (vector::const_iterator i = _slices.begin(); i != _slices.end(); ++i) + for (std::vector::const_iterator i = _slices.begin(); i != _slices.end(); ++i) _thickness += (*i)._thickness; } -double LayerStack::sectionThickness(size_t is, size_t ie) const { +double dd4hep::LayerStack::sectionThickness(std::size_t is, std::size_t ie) const { double thick = 0.; if (is > ie) - throw runtime_error( - "LayerStack::sectionThickness: First index (" + _toString(is) + ") " - "must be <= second index (" + _toString(ie) + ")!"); + except("LayerStack", + "sectionThickness: First index (%ld) must be <= second index (%ld)!", is, ie); else if (is > _layers.size()) - throw runtime_error( - "LayerStack::sectionThickness: First index (" + _toString(is) + ") " - "out of range. #layers=" + _toString(_layers.size()) - + ")."); + except("LayerStack", + "sectionThickness: First index (%ld) out of range. #layers=%ld).", is, _layers.size()); else if (ie > _layers.size()) - throw runtime_error( - "LayerStack::sectionThickness: Second index (" + _toString(is) + ") " - "out of range. #layers=" + _toString(_layers.size()) - + ")."); - for (size_t i = is; i <= ie; ++i) + except("LayerStack", + "sectionThickness: Second index (%ld) out of range. #layers=%ld).", is, _layers.size()); + for (std::size_t i = is; i <= ie; ++i) thick += _layers[i]->thicknessWithPreOffset(); return thick; } -Layering::Layering(Element e) { - LayeringCnv(e).fromCompact(*this); -} - -const Layer* Layering::layer(size_t which) const { - return _stack.layers()[which]; -} - -void LayeringCnv::fromCompact(Layering& layering) const { - vector& layers = layering.layers(); +void dd4hep::xml::LayeringCnv::fromCompact(Layering& layering) const { + std::vector& layers = layering.layers(); int count = 0; for_each(layers.begin(), layers.end(), detail::deletePtr); - for (Collection_t c(m_element, _U (layer)); c; ++c) { + for( xml_coll_t c(m_element, _U (layer)); c; ++c ) { Layer lay; - Component layer = c; + xml_comp_t layer = c; int repeat = layer.hasAttr(_U(repeat)) ? layer.repeat() : 1; ++count; - for (Collection_t s(c, _U(slice)); s; ++s) { - Component slice = s; - string mat = slice.materialStr(); - LayerSlice lslice(slice.isSensitive(), slice.thickness(), mat); + for (xml_coll_t s(c, _U(slice)); s; ++s) { + xml_comp_t slice = s; + std::string material = slice.materialStr(); + LayerSlice lslice(slice.isSensitive(), slice.thickness(), material); lay.add(lslice); } lay.compute(); // Add layer to stack once for each repetition - for (int k = 0; k < repeat; ++k) + for( int k = 0; k < repeat; ++k ) layers.emplace_back(new Layer(lay)); } if (0 == count) { - throw runtime_error("LayeringCnv::fromCompact: No layer children to be build!"); + throw std::runtime_error("LayeringCnv::fromCompact: No layer children to be build!"); } } -double Layering::singleLayerThickness(xml::Element e) const { - Component lay = e; +dd4hep::Layering::Layering(xml_elt_t e) { + xml::LayeringCnv(e).fromCompact(*this); +} + +const dd4hep::Layer* dd4hep::Layering::layer(std::size_t which) const { + return _stack.layers()[which]; +} + +double dd4hep::Layering::singleLayerThickness(xml_elt_t e) const { + xml_comp_t lay = e; double thickness = 0e0; - for (Collection_t s(lay, _U(slice)); s; ++s) { - Component slice = s; + for (xml_coll_t s(lay, _U(slice)); s; ++s) { + xml_comp_t slice = s; thickness += slice.thickness(); } return thickness; } -double Layering::absorberThicknessInLayer(xml::Element e) const { - Component lay = e; +double dd4hep::Layering::absorberThicknessInLayer(xml_elt_t e) const { + xml_comp_t lay = e; double thickness = 0e0; - for (Collection_t s(lay, _U(slice)); s; ++s) { - Component slice = s; + for (xml_coll_t s(lay, _U(slice)); s; ++s) { + xml_comp_t slice = s; if (slice.isRadiator()) thickness += slice.thickness(); } return thickness; } -void Layering::sensitivePositionsInLayer(xml::Element e, std::vector& sens_pos) const { - Component lay = e; - double pos=-singleLayerThickness(e)/2.0; - for (Collection_t s(lay, _U(slice)); s; ++s) { - Component slice = s; +void dd4hep::Layering::sensitivePositionsInLayer(xml_elt_t e, std::vector& sens_pos) const { + xml_comp_t lay = e; + double pos =- singleLayerThickness(e)/2.0; + for (xml_coll_t s(lay, _U(slice)); s; ++s) { + xml_comp_t slice = s; pos += slice.thickness(); if (slice.isSensitive()){ //store the position at the center of the slice @@ -123,8 +108,8 @@ void Layering::sensitivePositionsInLayer(xml::Element e, std::vector& se } -Layering::~Layering(){ - vector& layers = this->layers(); +dd4hep::Layering::~Layering(){ + std::vector& layers = this->layers(); for_each(layers.begin(), layers.end(), detail::deletePtr); layers.clear(); } diff --git a/DDCore/src/XML/UriReader.cpp b/DDCore/src/XML/UriReader.cpp index 8efc65272..eaa7cec8a 100644 --- a/DDCore/src/XML/UriReader.cpp +++ b/DDCore/src/XML/UriReader.cpp @@ -12,21 +12,19 @@ //========================================================================== // Framework include files -#include "XML/UriReader.h" - -using namespace std; +#include /// Default destructor dd4hep::xml::UriReader::~UriReader() { } /// Resolve a given URI to a string containing the data -bool dd4hep::xml::UriReader::load(const string& system_id, string& data) { +bool dd4hep::xml::UriReader::load(const std::string& system_id, std::string& data) { return this->load(system_id, context(), data); } /// Inform reader about a locally (e.g. by XercesC) handled source load -void dd4hep::xml::UriReader::parserLoaded(const string& system_id) { +void dd4hep::xml::UriReader::parserLoaded(const std::string& system_id) { this->parserLoaded(system_id, context()); } @@ -57,21 +55,21 @@ bool dd4hep::xml::UriContextReader::isBlocked(const std::string& path) const { } /// Resolve a given URI to a string containing the data -bool dd4hep::xml::UriContextReader::load(const string& system_id, string& data) { +bool dd4hep::xml::UriContextReader::load(const std::string& system_id, std::string& data) { return m_reader->load(system_id, context(), data); } /// Resolve a given URI to a string containing the data -bool dd4hep::xml::UriContextReader::load(const string& system_id, UserContext* ctxt, string& data) { +bool dd4hep::xml::UriContextReader::load(const std::string& system_id, UserContext* ctxt, std::string& data) { return m_reader->load(system_id, ctxt, data); } /// Inform reader about a locally (e.g. by XercesC) handled source load -void dd4hep::xml::UriContextReader::parserLoaded(const string& system_id) { +void dd4hep::xml::UriContextReader::parserLoaded(const std::string& system_id) { m_reader->parserLoaded(system_id, context()); } /// Inform reader about a locally (e.g. by XercesC) handled source load -void dd4hep::xml::UriContextReader::parserLoaded(const string& system_id, UserContext* ctxt) { +void dd4hep::xml::UriContextReader::parserLoaded(const std::string& system_id, UserContext* ctxt) { m_reader->parserLoaded(system_id, ctxt); } diff --git a/DDCore/src/XML/Utilities.cpp b/DDCore/src/XML/Utilities.cpp index 32c6f95f0..f26e7b4b7 100644 --- a/DDCore/src/XML/Utilities.cpp +++ b/DDCore/src/XML/Utilities.cpp @@ -13,19 +13,17 @@ #ifndef DD4HEP_NONE // Framework include files -#include "XML/Utilities.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Detector.h" -#include "DD4hep/DetFactoryHelper.h" -#include "Math/Polar2D.h" +#include +#include +#include +#include +#include +#include class TObject; -using namespace std; -using namespace dd4hep; -using namespace dd4hep::detail; using namespace dd4hep::xml::tools; +using dd4hep::printout; namespace { static constexpr const char* TAG_LIMITSETREF = "limitsetref"; @@ -40,11 +38,11 @@ namespace { } /// Create layered transformation from xml information -Transform3D dd4hep::xml::createTransformation(xml::Element e) { +dd4hep::Transform3D dd4hep::xml::createTransformation(xml::Element e) { int flag = 0; Transform3D position, rotation, result; for( xml_coll_t c(e,_U(star)); c; ++c ) { - string tag = c.tag(); + std::string tag = c.tag(); xml_dim_t x_elt = c; if ( tag == "positionRPhiZ" ) { if ( flag == 1 ) result = position * result; @@ -82,56 +80,56 @@ Transform3D dd4hep::xml::createTransformation(xml::Element e) { } /// Create a solid shape using the plugin mechanism from the attributes of the XML element -Solid dd4hep::xml::createShape(Detector& description, - const std::string& shape_type, - xml::Element element) { - string fac = shape_type + "__shape_constructor"; +dd4hep::Solid dd4hep::xml::createShape(Detector& description, + const std::string& shape_type, + xml::Element element) { + std::string fac = shape_type + "__shape_constructor"; xml::Handle_t solid_elt = element; Solid solid = Solid(PluginService::Create(fac, &description, &solid_elt)); if ( !solid.isValid() ) { PluginDebug dbg; PluginService::Create(fac, &description, &solid_elt); - except("xml::createShape","Failed to create solid of type %s [%s]", - shape_type.c_str(),dbg.missingFactory(shape_type).c_str()); + dd4hep::except("xml::createShape","Failed to create solid of type %s [%s]", + shape_type.c_str(),dbg.missingFactory(shape_type).c_str()); } return solid; } /// Create a volume using the plugin mechanism from the attributes of the XML element -Volume dd4hep::xml::createStdVolume(Detector& description, xml::Element element) { +dd4hep::Volume dd4hep::xml::createStdVolume(Detector& description, xml::Element element) { xml_dim_t e(element); if ( e.hasAttr(_U(material)) ) { xml_dim_t x_s = e.child(_U(shape)); - string typ = x_s.typeStr(); - Material mat = description.material(e.attr(_U(material))); + std::string typ = x_s.typeStr(); + Material mat = description.material(e.attr(_U(material))); Solid sol = createShape(description, typ, x_s); Volume vol("volume", sol, mat); - if ( e.hasAttr(_U(name)) ) vol->SetName(e.attr(_U(name)).c_str()); + if ( e.hasAttr(_U(name)) ) vol->SetName(e.attr(_U(name)).c_str()); vol.setAttributes(description,e.regionStr(),e.limitsStr(),e.visStr()); return vol; } xml_h h = e; xml_attr_t a = h.attr_nothrow(_U(type)); if ( a ) { - string typ = h.attr(a); + std::string typ = h.attr(a); if ( typ.substr(1) == "ssembly" ) { Assembly vol("assembly"); - if ( e.hasAttr(_U(name)) ) vol->SetName(e.attr(_U(name)).c_str()); + if ( e.hasAttr(_U(name)) ) vol->SetName(e.attr(_U(name)).c_str()); vol.setAttributes(description,e.regionStr(),e.limitsStr(),e.visStr()); return vol; } } - except("xml::createVolume","Failed to create volume. No material specified!"); + dd4hep::except("xml::createVolume","Failed to create volume. No material specified!"); return Volume(); } /// Create a volume using the plugin mechanism from the attributes of the XML element -Volume dd4hep::xml::createVolume(Detector& description, - const std::string& typ, - xml::Element element) { +dd4hep::Volume dd4hep::xml::createVolume(Detector& description, + const std::string& typ, + xml::Element element) { if ( !typ.empty() ) { xml_dim_t e(element); - string fac = typ + "__volume_constructor"; + std::string fac = typ + "__volume_constructor"; xml::Handle_t elt = element; TObject* obj = PluginService::Create(fac, &description, &elt); Volume vol = Volume(dynamic_cast(obj)); @@ -141,20 +139,20 @@ Volume dd4hep::xml::createVolume(Detector& description, except("xml::createShape","Failed to create volume of type %s [%s]", typ.c_str(),dbg.missingFactory(typ).c_str()); } - if ( e.hasAttr(_U(name)) ) vol->SetName(e.attr(_U(name)).c_str()); + if ( e.hasAttr(_U(name)) ) vol->SetName(e.attr(_U(name)).c_str()); vol.setAttributes(description,e.regionStr(),e.limitsStr(),e.visStr()); return vol; } - except("xml::createVolume","Failed to create volume. No materiaWNo type specified!"); + dd4hep::except("xml::createVolume","Failed to create volume. No materiaWNo type specified!"); return Volume(); } -Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, - dd4hep::xml::Handle_t e, - dd4hep::DetElement sdet) +dd4hep::Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, + dd4hep::xml::Handle_t e, + dd4hep::DetElement sdet) { xml_det_t x_det = e; - string det_name = x_det.nameStr(); + std::string det_name = x_det.nameStr(); xml_comp_t x_env = x_det.child( dd4hep::xml::Strng_t("envelope") ) ; xml_comp_t x_shape = x_env.child( _U(shape) ); @@ -185,23 +183,14 @@ Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, Box env_solid = xml_comp_t( x_shape ).createShape(); if( !env_solid.isValid() ){ - - throw std::runtime_error( std::string(" Cannot create envelope volume : ") + x_shape.typeStr() + - std::string(" for detector " ) + det_name ) ; + dd4hep::except("createPlacedEnvelope","Cannot create envelope volume : %s for detector %s.", + x_shape.typeStr(), det_name.c_str()); } - Material env_mat = description.material( x_shape.materialStr() ); - envelope = Volume( det_name+"_envelope", env_solid, env_mat ); } - - PlacedVolume env_pv ; - - Volume mother = description.pickMotherVolume(sdet); - - // ---- place the envelope into the mother volume // only specify transformations given in xml // to allow for optimization @@ -223,10 +212,9 @@ Volume dd4hep::xml::createPlacedEnvelope( dd4hep::Detector& description, return envelope; } - void dd4hep::xml::setDetectorTypeFlag( dd4hep::xml::Handle_t e, dd4hep::DetElement sdet ) { xml_det_t x_det = e; - string det_name = x_det.nameStr(); + std::string det_name = x_det.nameStr(); try{ xml_comp_t x_dettype = x_det.child( dd4hep::xml::Strng_t("type_flags") ) ; @@ -245,21 +233,21 @@ void dd4hep::xml::setDetectorTypeFlag( dd4hep::xml::Handle_t e, dd4hep::DetElem namespace { template - std::size_t _propagate(bool debug, - bool apply_to_children, - Volume vol, - TYPE item, - const Volume& (Volume::*apply)(const TYPE&) const) { + std::size_t _propagate(bool debug, + bool apply_to_children, + dd4hep::Volume vol, + TYPE item, + const dd4hep::Volume& (dd4hep::Volume::*apply)(const TYPE&) const) { std::size_t count = 0; if ( !vol->IsAssembly() ) { - printout(debug ? ALWAYS : DEBUG,"VolumeConfig", "++ Volume: %s apply setting %s", vol.name(), item.name()); + printout(debug ? dd4hep::ALWAYS : dd4hep::DEBUG,"VolumeConfig", "++ Volume: %s apply setting %s", vol.name(), item.name()); (vol.*apply)(item); ++count; } if ( apply_to_children ) { - std::set handled; + std::set handled; for (Int_t idau = 0, ndau = vol->GetNdaughters(); idau < ndau; ++idau) { - Volume v = vol->GetNode(idau)->GetVolume(); + dd4hep::Volume v = vol->GetNode(idau)->GetVolume(); if ( handled.find(v) == handled.end() ) { handled.insert(v); count += _propagate(debug, apply_to_children, v, item, apply); @@ -268,7 +256,6 @@ namespace { } return count; } - } /// Configure volume properties from XML element diff --git a/DDCore/src/XML/VolumeBuilder.cpp b/DDCore/src/XML/VolumeBuilder.cpp index 67e73543e..b9929e099 100644 --- a/DDCore/src/XML/VolumeBuilder.cpp +++ b/DDCore/src/XML/VolumeBuilder.cpp @@ -13,21 +13,17 @@ #ifndef DD4HEP_NONE // Framework include files -#include "XML/VolumeBuilder.h" -#include "XML/Utilities.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Detector.h" -#include "DD4hep/DetFactoryHelper.h" -#include "Math/Polar2D.h" +#include +#include +#include +#include +#include +#include +#include -#include "TClass.h" +#include - -using namespace std; -using namespace dd4hep; -using namespace dd4hep::detail; -using namespace dd4hep::xml::tools; +using dd4hep::xml::tools::VolumeBuilder; /// Initializing constructor VolumeBuilder::VolumeBuilder(Detector& dsc, xml_h x_parent, SensitiveDetector sd) @@ -42,13 +38,13 @@ VolumeBuilder::VolumeBuilder(Detector& dsc, xml_h x_parent, SensitiveDetector sd } /// Collect a set of materials from the leafs of an xml tag -size_t VolumeBuilder::collectMaterials(xml_h element) { - size_t len = materials.size(); +std::size_t VolumeBuilder::collectMaterials(xml_h element) { + std::size_t len = materials.size(); for( xml_coll_t c(element,_U(material)); c; ++c ) { - xml_comp_t x_c = c; - string nam = x_c.nameStr(); - string val = x_c.valueStr(); - Material mat = description.material(val); + xml_comp_t x_c = c; + std::string nam = x_c.nameStr(); + std::string val = x_c.valueStr(); + Material mat = description.material(val); materials[nam] = mat; } return materials.size()-len; @@ -58,7 +54,7 @@ size_t VolumeBuilder::collectMaterials(xml_h element) { void VolumeBuilder::registerShape(const std::string& nam, Solid shape) { auto is = shapes.find(nam); if ( is == shapes.end() ) { - shapes[nam] = make_pair(xml_h(0), shape); + shapes[nam] = std::make_pair(xml_h(0), shape); return; } except("VolumeBuilder","+++ Shape %s is already known to this builder unit. ",nam.c_str()); @@ -74,14 +70,14 @@ void VolumeBuilder::registerVolume(const std::string& nam, Volume volume) { volume.solid()->IsA()->GetName(), volume.visAttributes().name(), yes_no(volume.isSensitive())); - volumes[nam] = make_pair(xml_h(0), volume); + volumes[nam] = std::make_pair(xml_h(0), volume); return; } except("VolumeBuilder","+++ Volume %s is already known to this builder unit. ",nam.c_str()); } /// Access a registered volume by name -Volume VolumeBuilder::volume(const std::string& nam) const { +dd4hep::Volume VolumeBuilder::volume(const std::string& nam) const { auto iv = volumes.find(nam); if ( iv == volumes.end() ) { auto ib = vol_veto.find(nam); @@ -99,7 +95,7 @@ Volume VolumeBuilder::volume(const std::string& nam) const { } /// Access element from shape cache by name. Invalid returns means 'veto'. Otherwise exception -Solid VolumeBuilder::getShape(const string& nam) const { +dd4hep::Solid VolumeBuilder::getShape(const std::string& nam) const { auto is = shapes.find(nam); if ( is == shapes.end() ) { auto ib = shape_veto.find(nam); @@ -117,12 +113,12 @@ Solid VolumeBuilder::getShape(const string& nam) const { } /// Create a new shape from the information given in the xml handle -Solid VolumeBuilder::makeShape(xml_h handle) { - xml_comp_t x = handle; - string nam; - xml_attr_t a = handle.attr_nothrow(_U(name)); +dd4hep::Solid VolumeBuilder::makeShape(xml_h handle) { + xml_comp_t x = handle; + xml_attr_t a = handle.attr_nothrow(_U(name)); + std::string nam; if ( a ) { - nam = handle.attr(a); + nam = handle.attr(a); auto is = shapes.find(nam); if ( is != shapes.end() ) { except("VolumeBuilder","+++ The named shape %s is already known to this builder unit. " @@ -139,7 +135,7 @@ Solid VolumeBuilder::makeShape(xml_h handle) { /// Check if this volume is part of the volumes to be built for this description type a = handle.attr_nothrow(_U(build)); if ( a ) { - string build = handle.attr(a); + std::string build = handle.attr(a); if ( !buildMatch(build,buildType) ) { printout(INFO,"VolumeBuilder", "+++ Shape %s does NOT match build requirements. [Ignored]",nam.c_str()); @@ -148,7 +144,7 @@ Solid VolumeBuilder::makeShape(xml_h handle) { } } /// Now we create the shape.... - string type = x.attr(_U(type)); + std::string type = x.attr(_U(type)); Solid solid = xml::createShape(description, type, x); if ( !solid.isValid() ) { except("VolumeBuilder","+++ Failed to create shape %s of type: %s", @@ -157,7 +153,7 @@ Solid VolumeBuilder::makeShape(xml_h handle) { /// And register it if it is not anonymous if ( !nam.empty() ) { solid.setName(nam); - shapes.emplace(nam,make_pair(handle,solid)); + shapes.emplace(nam,std::make_pair(handle,solid)); } printout(debug ? ALWAYS : DEBUG, "VolumeBuilder", "+++ Created shape of type: %s name: %s",type.c_str(), nam.c_str()); @@ -165,17 +161,17 @@ Solid VolumeBuilder::makeShape(xml_h handle) { } /// Build all identifiers in the passed parent xml element -size_t VolumeBuilder::buildShapes(xml_h handle) { - size_t len = shapes.size(); +std::size_t VolumeBuilder::buildShapes(xml_h handle) { + std::size_t len = shapes.size(); for( xml_coll_t c(handle,_U(shape)); c; ++c ) { xml_elt_t x = c; - string nam = x.attr(_U(name)); + std::string nam = x.attr(_U(name)); auto is = shapes.find(nam); if ( is == shapes.end() ) { /// Check if this volume is part of the volumes to be built for this description type xml_attr_t x_build = c.attr_nothrow(_U(build)); if ( x_build ) { - string build = c.attr(x_build); + std::string build = c.attr(x_build); if ( !buildMatch(build,buildType) ) { printout(INFO,"VolumeBuilder", "+++ Shape %s does NOT match build requirements. [Ignored]",nam.c_str()); @@ -183,7 +179,7 @@ size_t VolumeBuilder::buildShapes(xml_h handle) { continue; } } - string type = x.attr(_U(type)); + std::string type = x.attr(_U(type)); Solid solid = xml::createShape(description, type, c); if ( !solid.isValid() ) { except("VolumeBuilder","+++ Failed to create shape %s of type: %s", @@ -192,7 +188,7 @@ size_t VolumeBuilder::buildShapes(xml_h handle) { printout(debug ? ALWAYS : DEBUG,"VolumeBuilder", "+++ Building shape from XML: %s of type: %s", nam.c_str(), solid->IsA()->GetName()); - shapes.emplace(nam,make_pair(c,solid)); + shapes.emplace(nam,std::make_pair(c,solid)); continue; } except("VolumeBuilder","+++ Shape %s is already known to this builder unit. " @@ -202,17 +198,17 @@ size_t VolumeBuilder::buildShapes(xml_h handle) { } /// Build all identifiers in the passed parent xml element -size_t VolumeBuilder::buildVolumes(xml_h handle) { - size_t len = volumes.size(); +std::size_t VolumeBuilder::buildVolumes(xml_h handle) { + std::size_t len = volumes.size(); xml_elt_t x_comp(0); for( xml_coll_t c(handle,_U(volume)); c; ++c ) { - Solid solid; - xml_comp_t x = c; - string nam = x.attr(_U(name)); + Solid solid; + xml_comp_t x = c; + std::string nam = x.attr(_U(name)); xml_attr_t attr = c.attr_nothrow(_U(build)); /// Check if this volume is part of the volumes to be built for this description type if ( attr ) { - string build = c.attr(attr); + std::string build = c.attr(attr); if ( !buildMatch(build,buildType) ) { printout(INFO,"VolumeBuilder", "+++ Volume %s does NOT match build requirements. [Ignored]",nam.c_str()); @@ -222,10 +218,10 @@ size_t VolumeBuilder::buildVolumes(xml_h handle) { bool is_sensitive = c.attr_nothrow(_U(sensitive)); /// Check if the volume is implemented by a factory if ( (attr=c.attr_nothrow(_U(type))) ) { - string typ = c.attr(attr); + std::string typ = c.attr(attr); Volume vol = xml::createVolume(description, typ, c); vol.setAttributes(description,x.regionStr(),x.limitsStr(),x.visStr()); - volumes.emplace(nam,make_pair(c,vol)); + volumes.emplace(nam,std::make_pair(c,vol)); /// Check if the volume is sensitive if ( is_sensitive ) { vol.setSensitiveDetector(sensitive); @@ -241,7 +237,7 @@ size_t VolumeBuilder::buildVolumes(xml_h handle) { /// Check if the volume has a shape attribute --> shape reference if ( (attr=c.attr_nothrow(_U(shape))) ) { - string ref = c.attr(attr); + std::string ref = c.attr(attr); if ( !(solid=getShape(ref)).isValid() ) continue; } /// Else use anonymous shape embedded in volume @@ -251,11 +247,11 @@ size_t VolumeBuilder::buildVolumes(xml_h handle) { /// We have a real volume here with a concrete shape: if ( solid.isValid() ) { - Material mat = description.material(x.attr(_U(material))); + Material mat = description.material(x.attr(_U(material))); Volume vol(nam, solid, mat); placeDaughters(detector, vol, x); vol.setAttributes(description,x.regionStr(),x.limitsStr(),x.visStr()); - volumes.emplace(nam,make_pair(c,vol)); + volumes.emplace(nam,std::make_pair(c,vol)); /// Check if the volume is sensitive if ( is_sensitive ) { vol.setSensitiveDetector(sensitive); @@ -274,7 +270,7 @@ size_t VolumeBuilder::buildVolumes(xml_h handle) { Assembly vol(nam); placeDaughters(detector, vol, x); vol.setAttributes(description,x.regionStr(),x.limitsStr(),x.visStr()); - volumes.emplace(nam,make_pair(c,vol)); + volumes.emplace(nam,std::make_pair(c,vol)); printout(debug ? ALWAYS : DEBUG,"VolumeBuilder", "+++ Building assembly from XML: %-20s shape:%-24s vis:%s", nam.c_str(), vol->GetShape()->IsA()->GetName(), x.visStr().c_str()); @@ -296,7 +292,7 @@ void VolumeBuilder::_placeSingleVolume(DetElement parent, Volume vol, xml_h c) if ( !attr ) { except("VolumeBuilder","+++ The xml volume element has no 'logvol' or 'volume' attribute!"); } - string nam = c.attr(attr); + std::string nam = c.attr(attr); if ( vol_veto.find(nam) != vol_veto.end() ) { return; } @@ -310,12 +306,11 @@ void VolumeBuilder::_placeSingleVolume(DetElement parent, Volume vol, xml_h c) Volume daughter = (*iv).second.second; attr = c.attr_nothrow(_U(transformation)); if ( attr ) { - string tr_nam = c.attr(attr); + std::string tr_nam = c.attr(attr); auto it = transformations.find(tr_nam); if ( it == transformations.end() ) { except("VolumeBuilder", - "+++ Failed to locate name transformation %s " - "[typo somewhere in the XML?]", + "+++ Failed to locate name transformation %s [typo in the XML?]", nam.c_str()); } const Transform3D& tr = (*it).second.second; @@ -327,7 +322,7 @@ void VolumeBuilder::_placeSingleVolume(DetElement parent, Volume vol, xml_h c) } xml_attr_t attr_nam = c.attr_nothrow(_U(name)); if ( attr_nam ) { - string phys_nam = c.attr(attr_nam); + std::string phys_nam = c.attr(attr_nam); pv->SetName(phys_nam.c_str()); } attr = c.attr_nothrow(_U(element)); @@ -338,11 +333,11 @@ void VolumeBuilder::_placeSingleVolume(DetElement parent, Volume vol, xml_h c) } else if ( attr ) { int elt_id = parent.id(); - string elt = c.attr(attr); + std::string elt = c.attr(attr); attr = c.attr_nothrow(_U(id)); if ( attr ) { elt_id = c.attr(attr); - elt += c.attr(attr); + elt += c.attr(attr); } DetElement de(parent, elt, elt_id); de.setPlacement(pv); @@ -364,7 +359,7 @@ void VolumeBuilder::_placeParamVolumes(DetElement parent, Volume vol, xml_h c) if ( !attr ) { except("VolumeBuilder","+++ The xml volume element has no 'logvol' or 'volume' attribute!"); } - string nam = x_phys.attr(attr); + std::string nam = x_phys.attr(attr); if ( vol_veto.find(nam) != vol_veto.end() ) { return; } @@ -384,7 +379,7 @@ void VolumeBuilder::_placeParamVolumes(DetElement parent, Volume vol, xml_h c) attr_tr = c.attr_nothrow(_U(transformation)); Transform3D tr; if ( attr_tr ) { - string tr_nam = c.attr(attr_tr); + std::string tr_nam = c.attr(attr_tr); auto it = transformations.find(tr_nam); if ( it == transformations.end() ) { except("VolumeBuilder", @@ -399,14 +394,14 @@ void VolumeBuilder::_placeParamVolumes(DetElement parent, Volume vol, xml_h c) } Transform3D transformation(Position(0,0,0)); int elt_id = -1; - string elt, phys_nam; + std::string elt, phys_nam; attr_nam = x_phys.attr_nothrow(_U(name)); if ( attr_nam ) { - phys_nam = x_phys.attr(_U(name))+"_%d"; + phys_nam = x_phys.attr(_U(name))+"_%d"; } if ( attr_elt ) { elt_id = parent.id(); - elt = c.attr(attr_elt); + elt = c.attr(attr_elt); } int number = c.attr(_U(number)); printout(debug ? ALWAYS : DEBUG,"VolumeBuilder","+++ Mother:%s place volume %s %d times.", @@ -414,7 +409,7 @@ void VolumeBuilder::_placeParamVolumes(DetElement parent, Volume vol, xml_h c) for(int i=0; iSetName(_toString(i,phys_nam.c_str()).c_str()); + //pv->SetName(_toStd::String(i,phys_nam.c_str()).c_str()); } if ( attr_elt ) { DetElement de(parent,elt,elt_id); @@ -429,15 +424,15 @@ void VolumeBuilder::_placeParamVolumes(DetElement parent, Volume vol, xml_h c) } /// Load include tags contained in the passed XML handle -size_t VolumeBuilder::load(xml_h element, const string& tag) { - size_t count = 0; +std::size_t VolumeBuilder::load(xml_h element, const std::string& tag) { + std::size_t count = 0; for( xml_coll_t c(element,Unicode(tag)); c; ++c ) { - string ref = c.attr(_U(ref)); - unique_ptr doc(new xml::DocumentHolder(xml::DocumentHandler().load(element, c.attr_value(_U(ref))))); + std::string ref = c.attr(_U(ref)); + std::unique_ptr doc(new xml::DocumentHolder(xml::DocumentHandler().load(element, c.attr_value(_U(ref))))); xml_h vols = doc->root(); printout(debug ? ALWAYS : DEBUG, "VolumeBuilder", "++ Processing xml document %s.", doc->uri().c_str()); - included_docs[ref] = unique_ptr(doc.release()); + included_docs[ref] = std::unique_ptr(doc.release()); buildShapes(vols); buildVolumes(vols); ++count; @@ -461,22 +456,22 @@ VolumeBuilder& VolumeBuilder::placeDaughters(DetElement parent, Volume vol, xml_ } /// Build all identifiers in the passed parent xml element -size_t VolumeBuilder::buildTransformations(Handle_t handle) { - size_t len = transformations.size(); +std::size_t VolumeBuilder::buildTransformations(Handle_t handle) { + std::size_t len = transformations.size(); for( xml_coll_t c(handle,_U(transformation)); c; ++c ) { - string nam = xml_comp_t(c).nameStr(); - transformations.emplace(nam,make_pair(c,xml::createTransformation(c))); + std::string nam = xml_comp_t(c).nameStr(); + transformations.emplace(nam,std::make_pair(c,xml::createTransformation(c))); } return transformations.size() - len; } /// Place the detector object into the mother volume returned by the Detector instance -PlacedVolume VolumeBuilder::placeDetector(Volume vol) { +dd4hep::PlacedVolume VolumeBuilder::placeDetector(Volume vol) { return placeDetector(vol, x_det); } /// Place the detector object into the mother volume returned by the Detector instance -PlacedVolume VolumeBuilder::placeDetector(Volume vol, xml_h handle) { +dd4hep::PlacedVolume VolumeBuilder::placeDetector(Volume vol, xml_h handle) { xml_comp_t x = handle; xml_dim_t x_pos = x_det.child(_U(position),false); xml_dim_t x_rot = x_det.child(_U(rotation),false); diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp index c392552ab..9d0ec3f8d 100644 --- a/DDCore/src/XML/XMLElements.cpp +++ b/DDCore/src/XML/XMLElements.cpp @@ -34,25 +34,24 @@ #include #include -using namespace std; using namespace dd4hep::xml; static const size_t INVALID_NODE = ~0U; static int s_float_precision = -1; // Forward declarations namespace dd4hep { - std::pair _toInteger(const string& value); - std::pair _toFloatingPoint(const string& value); - void _toDictionary(const string& name, const string& value, const string& typ); - string _getEnviron(const string& env); + std::pair _toInteger(const std::string& value); + std::pair _toFloatingPoint(const std::string& value); + void _toDictionary(const std::string& name, const std::string& value, const std::string& typ); + std::string _getEnviron(const std::string& env); } // Static storage namespace { bool s_resolve_environment = true; - string _checkEnviron(const string& env) { + std::string _checkEnviron(const std::string& env) { if ( s_resolve_environment ) { - string r = dd4hep::_getEnviron(env); + std::string r = dd4hep::_getEnviron(env); return r.empty() ? env : r; } return env; @@ -163,12 +162,12 @@ namespace { size_t node_count(XmlElement* e, const Tag_t& t) { size_t cnt = 0; if ( e ) { - const string& tag = t; + const std::string& tag = t; xercesc::DOMElement *ee = Xml(e).e; if ( ee ) { for(xercesc::DOMElement* elt=ee->getFirstElementChild(); elt; elt=elt->getNextElementSibling()) { if ( elt->getParentNode() == ee ) { - string child_tag = _toString(elt->getTagName()); + std::string child_tag = _toString(elt->getTagName()); if ( tag == "*" || child_tag == tag ) ++cnt; } } @@ -178,13 +177,13 @@ namespace { } XmlElement* node_first(XmlElement* e, const Tag_t& t) { if ( e ) { - const string& tag = t; + const std::string& tag = t; xercesc::DOMElement* ee = Xml(e).e; if ( ee ) { for(xercesc::DOMElement* elt=ee->getFirstElementChild(); elt; elt=elt->getNextElementSibling()) { if ( elt->getParentNode() == ee ) { if ( tag == "*" ) return _XE(elt); - string child_tag = _toString(elt->getTagName()); + std::string child_tag = _toString(elt->getTagName()); if ( child_tag == tag ) return _XE(elt); } } @@ -195,9 +194,9 @@ namespace { } /// Convert XML char to std::string -string dd4hep::xml::_toString(const XmlChar *toTranscode) { +std::string dd4hep::xml::_toString(const XmlChar *toTranscode) { char *buff = XmlString::transcode(toTranscode); - string tmp(buff == 0 ? "" : buff); + std::string tmp(buff == 0 ? "" : buff); XmlString::release(&buff); if ( tmp.length()<3 ) return tmp; if ( !(tmp[0] == '$' && tmp[1] == '{') ) return tmp; @@ -232,54 +231,54 @@ int dd4hep::xml::get_float_precision() { } /// Convert attribute value to string -string dd4hep::xml::_toString(Attribute attr) { +std::string dd4hep::xml::_toString(Attribute attr) { if (attr) return _toString(attribute_value(attr)); return ""; } -template static inline string __to_string(T value, const char* fmt) { +template static inline std::string __to_string(T value, const char* fmt) { char text[128]; ::snprintf(text, sizeof(text), fmt, value); return text; } /// Do-nothing version. Present for completeness and argument interchangeability -string dd4hep::xml::_toString(const char* s) { +std::string dd4hep::xml::_toString(const char* s) { if ( !s || *s == 0 ) return ""; else if ( !(*s == '$' && *(s+1) == '{') ) return s; return _checkEnviron(s); } /// Do-nothing version. Present for completeness and argument interchangeability -string dd4hep::xml::_toString(const string& s) { +std::string dd4hep::xml::_toString(const std::string& s) { if ( s.length() < 3 || s[0] != '$' ) return s; else if ( !(s[0] == '$' && s[1] == '{') ) return s; return _checkEnviron(s); } /// Format unsigned long integer to string with arbitrary format -string dd4hep::xml::_toString(unsigned long v, const char* fmt) { +std::string dd4hep::xml::_toString(unsigned long v, const char* fmt) { return __to_string(v, fmt); } /// Format unsigned integer (32 bits) to string with arbitrary format -string dd4hep::xml::_toString(unsigned int v, const char* fmt) { +std::string dd4hep::xml::_toString(unsigned int v, const char* fmt) { return __to_string(v, fmt); } /// Format signed integer (32 bits) to string with arbitrary format -string dd4hep::xml::_toString(int v, const char* fmt) { +std::string dd4hep::xml::_toString(int v, const char* fmt) { return __to_string(v, fmt); } /// Format signed long integer to string with arbitrary format -string dd4hep::xml::_toString(long v, const char* fmt) { +std::string dd4hep::xml::_toString(long v, const char* fmt) { return __to_string(v, fmt); } /// Format single procision float number (32 bits) to string with arbitrary format -string dd4hep::xml::_toString(float v, const char* fmt) { +std::string dd4hep::xml::_toString(float v, const char* fmt) { if ( s_float_precision >= 0 ) { char format[32]; ::snprintf(format, sizeof(format), "%%.%de", s_float_precision); @@ -289,7 +288,7 @@ string dd4hep::xml::_toString(float v, const char* fmt) { } /// Format double procision float number (64 bits) to string with arbitrary format -string dd4hep::xml::_toString(double v, const char* fmt) { +std::string dd4hep::xml::_toString(double v, const char* fmt) { if ( s_float_precision >= 0 ) { char format[32]; ::snprintf(format, sizeof(format), "%%.%de", s_float_precision); @@ -299,23 +298,23 @@ string dd4hep::xml::_toString(double v, const char* fmt) { } /// Convert Strng_t to std::string -string dd4hep::xml::_toString(const Strng_t& s) { +std::string dd4hep::xml::_toString(const Strng_t& s) { return _toString(Tag_t(s)); } /// Convert Tag_t to std::string -string dd4hep::xml::_toString(const Tag_t& s) { +std::string dd4hep::xml::_toString(const Tag_t& s) { return s.str(); } /// Format pointer to string with arbitrary format -string dd4hep::xml::_ptrToString(const void* v, const char* fmt) { +std::string dd4hep::xml::_ptrToString(const void* v, const char* fmt) { return __to_string(v, fmt); } long dd4hep::xml::_toLong(const XmlChar* value) { if (value) { - string s = _toString(value); + std::string s = _toString(value); return dd4hep::_toInteger(s).second; } return -1; @@ -324,8 +323,8 @@ long dd4hep::xml::_toLong(const XmlChar* value) { unsigned long dd4hep::xml::_toULong(const XmlChar* value) { long val = _toLong(value); if ( val >= 0 ) return (unsigned long) val; - string s = _toString(value); - throw runtime_error("dd4hep: Severe error during expression evaluation of " + s); + std::string s = _toString(value); + throw std::runtime_error("dd4hep: Severe error during expression evaluation of " + s); } int dd4hep::xml::_toInt(const XmlChar* value) { @@ -338,7 +337,7 @@ unsigned int dd4hep::xml::_toUInt(const XmlChar* value) { bool dd4hep::xml::_toBool(const XmlChar* value) { if (value) { - string s = _toString(value); + std::string s = _toString(value); char c = ::toupper(s[0]); if ( c == 'T' || c == '1' ) return true; if ( c == 'F' || c == '0' ) return false; @@ -349,7 +348,7 @@ bool dd4hep::xml::_toBool(const XmlChar* value) { float dd4hep::xml::_toFloat(const XmlChar* value) { if (value) { - string s = _toString(value); + std::string s = _toString(value); return (float) dd4hep::_toFloatingPoint(s).second; } return 0.0; @@ -357,14 +356,14 @@ float dd4hep::xml::_toFloat(const XmlChar* value) { double dd4hep::xml::_toDouble(const XmlChar* value) { if (value) { - string s = _toString(value); + std::string s = _toString(value); return dd4hep::_toFloatingPoint(s).second; } return 0.0; } void dd4hep::xml::_toDictionary(const XmlChar* name, const XmlChar* value) { - string n = _toString(name).c_str(), v = _toString(value); + std::string n = _toString(name).c_str(), v = _toString(value); dd4hep::_toDictionary(n, v, "number"); } @@ -390,7 +389,7 @@ template void dd4hep::xml::_toDictionary(const XmlChar* name, const char* value) #endif template void dd4hep::xml::_toDictionary(const XmlChar* name, const Tag_t& value); template void dd4hep::xml::_toDictionary(const XmlChar* name, const Strng_t& value); -template void dd4hep::xml::_toDictionary(const XmlChar* name, const string& value); +template void dd4hep::xml::_toDictionary(const XmlChar* name, const std::string& value); template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned long value); template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned int value); template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned short value); @@ -401,7 +400,7 @@ template void dd4hep::xml::_toDictionary(const XmlChar* name, float value); template void dd4hep::xml::_toDictionary(const XmlChar* name, double value); /// Evaluate string constant using environment stored in the evaluator -string dd4hep::xml::getEnviron(const string& env) { +std::string dd4hep::xml::getEnviron(const std::string& env) { return dd4hep::_getEnviron(env); } @@ -413,17 +412,17 @@ bool dd4hep::xml::enableEnvironResolution(bool new_value) { } template -static inline string i_add(const string& a, B b) { - string r = a; +static inline std::string i_add(const std::string& a, B b) { + std::string r = a; r += b; return r; } -Strng_t dd4hep::xml::operator+(const Strng_t& a, const string& b) { +Strng_t dd4hep::xml::operator+(const Strng_t& a, const std::string& b) { return _toString(a.ptr()) + b; } -Strng_t dd4hep::xml::operator+(const string& a, const Strng_t& b) { +Strng_t dd4hep::xml::operator+(const std::string& a, const Strng_t& b) { return a + _toString(b.ptr()); } @@ -432,7 +431,7 @@ Strng_t dd4hep::xml::operator+(const Strng_t& a, const char* b) { } Strng_t dd4hep::xml::operator+(const char* a, const Strng_t& b) { - return string(a) + _toString(b.ptr()); + return std::string(a) + _toString(b.ptr()); } Strng_t dd4hep::xml::operator+(const Strng_t& a, const Strng_t& b) { @@ -440,48 +439,48 @@ Strng_t dd4hep::xml::operator+(const Strng_t& a, const Strng_t& b) { } Tag_t dd4hep::xml::operator+(const Tag_t& a, const char* b) { - string res = a.str() + b; + std::string res = a.str() + b; return Tag_t(res); } Tag_t dd4hep::xml::operator+(const char* a, const Tag_t& b) { - string res = a + b.str(); + std::string res = a + b.str(); return Tag_t(res); } Tag_t dd4hep::xml::operator+(const Tag_t& a, const Strng_t& b) { - string res = a.str() + _toString(b); + std::string res = a.str() + _toString(b); return Tag_t(res); } -Tag_t dd4hep::xml::operator+(const Tag_t& a, const string& b) { - string res = a.str() + b; +Tag_t dd4hep::xml::operator+(const Tag_t& a, const std::string& b) { + std::string res = a.str() + b; return Tag_t(res); } #ifndef DD4HEP_USE_TINYXML Strng_t dd4hep::xml::operator+(const Strng_t& a, const XmlChar* b) { - string res = _toString(a.ptr()) + _toString(b); + std::string res = _toString(a.ptr()) + _toString(b); return Tag_t(res); } Strng_t dd4hep::xml::operator+(const XmlChar* a, const Strng_t& b) { - string res = _toString(a) + _toString(b.ptr()); + std::string res = _toString(a) + _toString(b.ptr()); return Tag_t(res); } -Strng_t dd4hep::xml::operator+(const XmlChar* a, const string& b) { - string res = _toString(a) + b; +Strng_t dd4hep::xml::operator+(const XmlChar* a, const std::string& b) { + std::string res = _toString(a) + b; return Tag_t(res); } -Strng_t dd4hep::xml::operator+(const string& a, const XmlChar* b) { - string res = a + _toString(b); +Strng_t dd4hep::xml::operator+(const std::string& a, const XmlChar* b) { + std::string res = a + _toString(b); return Tag_t(res); } Tag_t dd4hep::xml::operator+(const Tag_t& a, const XmlChar* b) { - string res = a.str() + _toString(b); + std::string res = a.str() + _toString(b); return Tag_t(res); } @@ -509,7 +508,7 @@ Strng_t& Strng_t::operator=(const Strng_t& s) { return *this; } -Strng_t& Strng_t::operator=(const string& s) { +Strng_t& Strng_t::operator=(const std::string& s) { if (m_xml) XmlString::release (&m_xml); m_xml = XmlString::transcode(s.c_str()); @@ -553,7 +552,7 @@ Tag_t& Tag_t::operator=(const Strng_t& s) { return *this; } -Tag_t& Tag_t::operator=(const string& s) { +Tag_t& Tag_t::operator=(const std::string& s) { if (m_xml) XmlString::release (&m_xml); m_xml = XmlString::transcode(s.c_str()); @@ -594,7 +593,7 @@ XmlElement* NodeList::next() const { xercesc::DOMElement *elt = Xml(m_ptr).e; for(elt=elt->getNextElementSibling(); elt; elt=elt->getNextElementSibling()) { if ( m_tag.str() == "*" ) return m_ptr=Xml(elt).xe; - string child_tag = _toString(elt->getTagName()); + std::string child_tag = _toString(elt->getTagName()); if ( child_tag == m_tag ) return m_ptr=Xml(elt).xe; } return m_ptr=0; @@ -611,7 +610,7 @@ XmlElement* NodeList::previous() const { xercesc::DOMElement *elt = Xml(m_ptr).e; for(elt=elt->getPreviousElementSibling(); elt; elt=elt->getPreviousElementSibling()) { if ( m_tag.str()=="*" ) return m_ptr=Xml(elt).xe; - string child_tag = _toString(elt->getTagName()); + std::string child_tag = _toString(elt->getTagName()); if ( child_tag == m_tag ) return m_ptr=Xml(elt).xe; } return m_ptr=0; @@ -652,12 +651,12 @@ Handle_t Handle_t::clone(XmlDocument* new_doc) const { XmlElement* e = _XE(_N(m_node)->Clone()->ToElement()); if ( e ) return e; } - throw runtime_error("TiXml: Handle_t::clone: Invalid source handle type [No element type]."); + throw std::runtime_error("TiXml: Handle_t::clone: Invalid source handle type [No element type]."); #else return Elt_t(_D(new_doc)->importNode(_E(m_node), true)); #endif } - throw runtime_error("Xml: Handle_t::clone: Invalid source handle."); + throw std::runtime_error("Xml: Handle_t::clone: Invalid source handle."); } /// Access the element's parent element @@ -676,8 +675,8 @@ bool Handle_t::hasAttr(const XmlChar* tag_value) const { } /// Retrieve a collection of all attributes of this DOM element -vector Handle_t::attributes() const { - vector < Attribute > attrs; +std::vector Handle_t::attributes() const { + std::vector < Attribute > attrs; if (m_node) { #ifdef DD4HEP_USE_TINYXML for(TiXmlAttribute* a=_E(m_node)->FirstAttribute(); a; a=a->Next()) @@ -699,12 +698,12 @@ size_t Handle_t::numChildren(const XmlChar* t, bool throw_exception) const { return 0; else if (n != INVALID_NODE) return n; - string msg = "Handle_t::numChildren: "; + std::string msg = "Handle_t::numChildren: "; if (m_node) msg += "Element [" + tag() + "] has no children of type '" + _toString(t) + "'"; else msg += "Element [INVALID] has no children of type '" + _toString(t) + "'"; - throw runtime_error(msg); + throw std::runtime_error(msg); } /// Remove a single child node identified by its handle from the tree of the element @@ -712,12 +711,12 @@ Handle_t Handle_t::child(const XmlChar* t, bool throw_exception) const { Elt_t e = node_first(m_node, t); if (e || !throw_exception) return e; - string msg = "Handle_t::child: "; + std::string msg = "Handle_t::child: "; if (m_node) msg += "Element [" + tag() + "] has no child of type '" + _toString(t) + "'"; else msg += "Element [INVALID]. Cannot remove child of type: '" + _toString(t) + "'"; - throw runtime_error(msg); + throw std::runtime_error(msg); } NodeList Handle_t::children(const XmlChar* tag_value) const { @@ -738,7 +737,7 @@ Handle_t Handle_t::remove(Handle_t node) const { #endif if (e) return node.ptr(); - string msg = "Handle_t::remove: "; + std::string msg = "Handle_t::remove: "; if (m_node && node.ptr()) msg += "Element [" + tag() + "] has no child of type '" + node.tag() + "'"; else if (node) @@ -746,7 +745,7 @@ Handle_t Handle_t::remove(Handle_t node) const { else if (!node) msg += "Element [INVALID]. Cannot remove [INVALID] child. Big Shit!!!!"; - throw runtime_error(msg); + throw std::runtime_error(msg); } /// Remove children with a given tag name from the DOM node @@ -772,7 +771,7 @@ void Handle_t::setValue(const XmlChar* text_value) const { } /// Set the element's value -void Handle_t::setValue(const string& text_value) const { +void Handle_t::setValue(const std::string& text_value) const { #ifdef DD4HEP_USE_TINYXML _N(m_node)->setNodeValue(text_value.c_str()); #else @@ -790,7 +789,7 @@ void Handle_t::setText(const XmlChar* text_value) const { } /// Set the element's text -void Handle_t::setText(const string& text_value) const { +void Handle_t::setText(const std::string& text_value) const { #ifdef DD4HEP_USE_TINYXML _N(m_node)->LinkEndChild(new TiXmlText(text_value.c_str())); #else @@ -840,12 +839,12 @@ Attribute Handle_t::attr_ptr(const XmlChar* t) const { Attribute a = attribute_node(m_node, t); if (0 != a) return a; - string msg = "Handle_t::attr_ptr: "; + std::string msg = "Handle_t::attr_ptr: "; if (m_node) msg += "Element [" + tag() + "] has no attribute of type '" + _toString(t) + "'"; else msg += "Element [INVALID] has no attribute of type '" + _toString(t) + "'"; - throw runtime_error(msg); + throw std::runtime_error(msg); } /// Access attribute name (throws exception if not present) @@ -853,7 +852,7 @@ const XmlChar* Handle_t::attr_name(const Attribute a) const { if (a) { return Xml(a).a->getName(); } - throw runtime_error("Attempt to access invalid XML attribute object!"); + throw std::runtime_error("Attempt to access invalid XML attribute object!"); } /// Access attribute value by the attribute's unicode name (throws exception if not present) @@ -901,7 +900,7 @@ Attribute Handle_t::setAttr(const XmlChar* name, double val) const { } /// Generic attribute setter with string value -Attribute Handle_t::setAttr(const XmlChar* name, const string& val) const { +Attribute Handle_t::setAttr(const XmlChar* name, const std::string& val) const { return setAttr(name, Strng_t(val.c_str())); } @@ -944,7 +943,7 @@ Handle_t Handle_t::setRef(const XmlChar* tag_value, const XmlChar* ref_name) { } /// Add reference child as a new child node. The obj must have the "name" attribute! -Handle_t Handle_t::setRef(const XmlChar* tag_value, const string& ref_name) { +Handle_t Handle_t::setRef(const XmlChar* tag_value, const std::string& ref_name) { return setRef(tag_value, Strng_t(ref_name).ptr()); } @@ -990,13 +989,13 @@ static unsigned int adler32(unsigned int adler, const XmlChar* xml_buff, size_t typedef unsigned int (fcn_t)(unsigned int, const XmlChar*, size_t); unsigned int Handle_t::checksum(unsigned int param, fcn_t fcn) const { #ifdef DD4HEP_USE_TINYXML - typedef map StringMap; + typedef map StringMap; TiXmlNode* n = Xml(m_node).n; if ( n ) { if ( 0 == fcn ) fcn = adler32; switch (n->Type()) { case TiXmlNode::ELEMENT: { - map m; + map m; TiXmlElement* e = n->ToElement(); TiXmlAttribute* p=e->FirstAttribute(); for(; p; p=p->Next()) m.emplace(p->Name(),p->Value()); @@ -1041,7 +1040,7 @@ Handle_t Document::createElt(const XmlChar* tag_value) const { Handle_t Document::root() const { if (m_doc) return _XE(_D(m_doc)->getDocumentElement()); - throw runtime_error("Document::root: Invalid handle!"); + throw std::runtime_error("Document::root: Invalid handle!"); } /// Acces the document URI @@ -1050,7 +1049,7 @@ std::string Document::uri() const { Tag_t val(_D(m_doc)->getDocumentURI()); return val; } - throw runtime_error("Document::uri: Invalid handle!"); + throw std::runtime_error("Document::uri: Invalid handle!"); } /// Assign new document. Old document is dropped. @@ -1096,7 +1095,7 @@ Handle_t Element::clone(Handle_t h) const { if (m_element && h) { return h.clone(Document::DOC(document())); } - throw runtime_error("Element::clone: Invalid element pointer -- unable to clone node!"); + throw std::runtime_error("Element::clone: Invalid element pointer -- unable to clone node!"); } Attribute Element::getAttr(const XmlChar* name) const { @@ -1109,7 +1108,7 @@ Attribute Element::setRef(const XmlChar* tag_value, const XmlChar* ref_name) con } /// Set the reference attribute to the node (adds attribute ref="ref-name") -Attribute Element::setRef(const XmlChar* tag_value, const string& ref_name) const { +Attribute Element::setRef(const XmlChar* tag_value, const std::string& ref_name) const { return setRef(tag_value, Strng_t(ref_name).ptr()); } @@ -1148,7 +1147,7 @@ void Element::addComment(const char* text_value) const { } /// Add comment node to the element -void Element::addComment(const string& text_value) const { +void Element::addComment(const std::string& text_value) const { addComment(text_value.c_str()); } @@ -1177,13 +1176,13 @@ RefElement& RefElement::operator=(const RefElement& e) { const XmlChar* RefElement::name() const { if (0 == m_name) - cout << "Error:tag=" << m_element.tag() << endl; + std::cout << "Error:tag=" << m_element.tag() << std::endl; return attribute_value(m_name); } const XmlChar* RefElement::refName() const { if (0 == m_name) - cout << "Error:tag=" << m_element.tag() << endl; + std::cout << "Error:tag=" << m_element.tag() << std::endl; return attribute_value(m_name); } @@ -1221,11 +1220,11 @@ size_t Collection_t::size() const { } /// Helper function to throw an exception -void Collection_t::throw_loop_exception(const exception& e) const { +void Collection_t::throw_loop_exception(const std::exception& e) const { if (m_node) { - throw runtime_error(string(e.what()) + "\n" + "dd4hep: Error interpreting XML nodes of type <" + tag() + "/>"); + throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting XML nodes of type <" + tag() + "/>"); } - throw runtime_error(string(e.what()) + "\n" + "dd4hep: Error interpreting collections XML nodes."); + throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting collections XML nodes."); } void Collection_t::operator++() const { diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 8290733a0..90376b959 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -52,7 +52,6 @@ #include #include -using namespace std; using namespace dd4hep; /// Namespace for the AIDA detector description toolkit @@ -105,9 +104,9 @@ namespace dd4hep { namespace { static UInt_t unique_mat_id = 0xAFFEFEED; - void throw_print(const string& msg) { + void throw_print(const std::string& msg) { printout(ERROR, "Compact", msg.c_str()); - throw runtime_error(msg); + throw std::runtime_error(msg); } class DebugOptions { public: @@ -130,7 +129,7 @@ namespace { static Ref_t create_ConstantField(Detector& /* description */, xml_h e) { CartesianField obj; xml_comp_t field(e), strength(e.child(_U(strength))); - string t = e.attr(_U(field)); + std::string t = e.attr(_U(field)); ConstantField* ptr = new ConstantField(); ptr->field_type = ::toupper(t[0]) == 'E' ? CartesianField::ELECTRIC : CartesianField::MAGNETIC; ptr->direction.SetX(strength.x()); @@ -194,17 +193,17 @@ DECLARE_XMLELEMENT(solenoid,create_SolenoidField) static Ref_t create_DipoleField(Detector& /* description */, xml_h e) { xml_comp_t c(e); CartesianField obj; - DipoleField* ptr = new DipoleField(); - double lunit = c.hasAttr(_U(lunit)) ? c.attr(_U(lunit)) : 1.0; - double funit = c.hasAttr(_U(funit)) ? c.attr(_U(funit)) : 1.0; - double val, mult = funit; + DipoleField* ptr = new DipoleField(); + double lunit = c.hasAttr(_U(lunit)) ? c.attr(_U(lunit)) : 1.0; + double funit = c.hasAttr(_U(funit)) ? c.attr(_U(funit)) : 1.0; + double val, mult = funit; if (c.hasAttr(_U(zmin))) - ptr->zmin = _multiply(c.attr(_U(zmin)), lunit); + ptr->zmin = _multiply(c.attr(_U(zmin)), lunit); if (c.hasAttr(_U(zmax))) - ptr->zmax = _multiply(c.attr(_U(zmax)), lunit); + ptr->zmax = _multiply(c.attr(_U(zmax)), lunit); if (c.hasAttr(_U(rmax))) - ptr->rmax = _multiply(c.attr(_U(rmax)), lunit); + ptr->rmax = _multiply(c.attr(_U(rmax)), lunit); for (xml_coll_t coll(c, _U(dipole_coeff)); coll; ++coll, mult /= lunit) { xml_dim_t coeff = coll; if ( coeff.hasAttr(_U(value)) ) @@ -223,13 +222,13 @@ DECLARE_XMLELEMENT(DipoleMagnet,create_DipoleField) static Ref_t create_MultipoleField(Detector& description, xml_h e) { xml_dim_t c(e), child; - CartesianField obj; + CartesianField obj; MultipoleField* ptr = new MultipoleField(); - double lunit = c.hasAttr(_U(lunit)) ? c.attr(_U(lunit)) : 1.0; - double funit = c.hasAttr(_U(funit)) ? c.attr(_U(funit)) : 1.0; - double val, mult = funit, bz = 0.0; - RotationZYX rot; - Position pos; + double lunit = c.hasAttr(_U(lunit)) ? c.attr(_U(lunit)) : 1.0; + double funit = c.hasAttr(_U(funit)) ? c.attr(_U(funit)) : 1.0; + double val, mult = funit, bz = 0.0; + RotationZYX rot; + Position pos; if (c.hasAttr(_U(Z))) bz = c.Z() * funit; if ((child = c.child(_U(position), false))) { // Position is not mandatory! @@ -239,7 +238,7 @@ static Ref_t create_MultipoleField(Detector& description, xml_h e) { rot.SetComponents(child.z(), child.y(), child.x()); } if ((child = c.child(_U(shape), false))) { // Shape is not mandatory - string type = child.typeStr(); + std::string type = child.typeStr(); ptr->volume = xml::createShape(description, type, child); } ptr->B_z = bz; @@ -296,7 +295,7 @@ bool check_process_file(Detector& description, std::string filename) { template <> void Converter::operator()(xml_h e) const { for (xml_coll_t coll(e, _U(type)); coll; ++coll) { int val = coll.attr(_U(value)); - string nam = coll.attr(_U(name)); + std::string nam = coll.attr(_U(name)); if ( nam.substr(0,6) == "isotop" ) s_debug.isotopes = (0 != val); else if ( nam.substr(0,6) == "elemen" ) s_debug.elements = (0 != val); else if ( nam.substr(0,6) == "materi" ) s_debug.materials = (0 != val); @@ -320,25 +319,25 @@ template <> void Converter::operator()(xml_h e) const { * */ template <> void Converter::operator()(xml_h e) const { - xml_comp_t plugin(e); - string name = plugin.nameStr(); - string type = "default"; + xml_comp_t plugin(e); + std::string name = plugin.nameStr(); + std::string type = "default"; if ( xml_attr_t typ_attr = e.attr_nothrow(_U(type)) ) { - type = e.attr(typ_attr); + type = e.attr(typ_attr); } if ( type == "default" ) { - vector argv; - vector arguments; + std::vector argv; + std::vector arguments; for (xml_coll_t coll(e, _U(arg)); coll; ++coll) { - string val = coll.attr(_U(value)); + std::string val = coll.attr(_U(value)); arguments.emplace_back(val); } for (xml_coll_t coll(e, _U(argument)); coll; ++coll) { - string val = coll.attr(_U(value)); + std::string val = coll.attr(_U(value)); arguments.emplace_back(val); } - for(vector::iterator i=arguments.begin(); i!=arguments.end(); ++i) + for(std::vector::iterator i=arguments.begin(); i!=arguments.end(); ++i) argv.emplace_back(&((*i)[0])); description.apply(name.c_str(),int(argv.size()), &argv[0]); return; @@ -366,9 +365,9 @@ template <> void Converter::operator()(xml_h e) const { template <> void Converter::operator()(xml_h e) const { if ( e.tag() != "include" ) { xml_ref_t constant(e); - string nam = constant.attr(_U(name)); - string val = constant.attr(_U(value)); - string typ = constant.hasAttr(_U(type)) ? constant.attr(_U(type)) : "number"; + std::string nam = constant.attr(_U(name)); + std::string val = constant.attr(_U(value)); + std::string typ = constant.hasAttr(_U(type)) ? constant.attr(_U(type)) : "number"; Constant c(nam, val, typ); _toDictionary(nam, val, typ); description.addConstant(c); @@ -393,11 +392,11 @@ template <> void Converter::operator()(xml_h e) const { */ template <> void Converter
::operator()(xml_h e) const { xml_comp_t c(e); - Header h(e.attr(_U(name)), e.attr(_U(title), "Undefined")); - h.setUrl(e.attr(_U(url), "Undefined")); - h.setAuthor(e.attr(_U(author), "Undefined")); - h.setStatus(e.attr(_U(status), "development")); - h.setVersion(e.attr(_U(version), "Undefined")); + Header h(e.attr(_U(name)), e.attr(_U(title), "Undefined")); + h.setUrl(e.attr(_U(url), "Undefined")); + h.setAuthor(e.attr(_U(author), "Undefined")); + h.setStatus(e.attr(_U(status), "development")); + h.setVersion(e.attr(_U(version), "Undefined")); h.setComment(e.hasChild(_U(comment)) ? e.child(_U(comment)).text() : "No Comment"); description.setHeader(h); } @@ -438,7 +437,7 @@ template <> void Converter::operator()(xml_h e) const { if ( !density.ptr() ) { throw_print("Compact2Objects[ERROR]: material without density tag ( ) provided: " - + string( matname ) ) ; + + std::string( matname ) ) ; } if ( density.hasAttr(_U(unit)) ) { dens_unit = density.attr(_U(unit))/xml::_toDouble(_Unicode(gram/cm3)); @@ -446,15 +445,15 @@ template <> void Converter::operator()(xml_h e) const { if ( dens_unit != 1.0 ) { dens_val *= dens_unit; printout(s_debug.materials ? ALWAYS : DEBUG, "Compact","Density unit: %.3f [%s] raw: %.3f normalized: %.3f ", - dens_unit, density.attr(_U(unit)).c_str(), dens_val, (dens_val*dens_unit)); + dens_unit, density.attr(_U(unit)).c_str(), dens_val, (dens_val*dens_unit)); } mat = mix = new TGeoMixture(matname, composites.size(), dens_val); - size_t ifrac = 0; - vector composite_fractions; - double composite_fractions_total = 0.0; + std::size_t ifrac = 0; + std::vector composite_fractions; + double composite_fractions_total = 0.0; for (composites.reset(); composites; ++composites) { - string nam = composites.attr(_U(ref)); - double fraction = composites.attr(_U(n)); + std::string nam = composites.attr(_U(ref)); + double fraction = composites.attr(_U(n)); if (0 != (comp_mat = mgr.GetMaterial(nam.c_str()))) fraction *= comp_mat->GetA(); else if (0 != (comp_elt = table->FindElement(nam.c_str()))) @@ -465,16 +464,16 @@ template <> void Converter::operator()(xml_h e) const { composite_fractions.emplace_back(fraction); } for (composites.reset(), ifrac=0; composites; ++composites, ++ifrac) { - string nam = composites.attr(_U(ref)); - double fraction = composite_fractions[ifrac]/composite_fractions_total; + std::string nam = composites.attr(_U(ref)); + double fraction = composite_fractions[ifrac]/composite_fractions_total; if (0 != (comp_mat = mgr.GetMaterial(nam.c_str()))) mix->AddElement(comp_mat, fraction); else if (0 != (comp_elt = table->FindElement(nam.c_str()))) mix->AddElement(comp_elt, fraction); } for (fractions.reset(); fractions; ++fractions) { - string nam = fractions.attr(_U(ref)); - double fraction = fractions.attr(_U(n)); + std::string nam = fractions.attr(_U(ref)); + double fraction = fractions.attr(_U(n)); if (0 != (comp_mat = mgr.GetMaterial(nam.c_str()))) mix->AddElement(comp_mat, fraction); else if (0 != (comp_elt = table->FindElement(nam.c_str()))) @@ -490,7 +489,7 @@ template <> void Converter::operator()(xml_h e) const { temp_unit = temperature.attr(_U(unit)); temp_val = temperature.attr(_U(value)) * temp_unit; } - xml_h pressure = x_mat.child(_U(P), false); + xml_h pressure = x_mat.child(_U(P), false); double pressure_val = description.stdConditions().pressure; if ( pressure.ptr() ) { double pressure_unit = _toDouble("pascal"); @@ -516,11 +515,11 @@ template <> void Converter::operator()(xml_h e) const { for(xml_coll_t properties(x_mat, _U(constant)); properties; ++properties) { xml_elt_t p = properties; if ( p.hasAttr(_U(ref)) ) { - bool err = kFALSE; - string ref = p.attr(_U(ref)); + bool err = kFALSE; + std::string ref = p.attr(_U(ref)); mgr.GetProperty(ref.c_str(), &err); /// Check existence if ( err == kFALSE ) { - string prop_nam = p.attr(_U(name)); + std::string prop_nam = p.attr(_U(name)); mat->AddConstProperty(prop_nam.c_str(), ref.c_str()); printout(s_debug.materials ? ALWAYS : DEBUG, "Compact", "++ material %-16s add constant property: %s -> %s.", @@ -531,8 +530,8 @@ template <> void Converter::operator()(xml_h e) const { throw_print("Compact2Objects[ERROR]: Converting material:" + mname + " ConstProperty missing in TGeoManager: " + ref); } else if ( p.hasAttr(_U(value)) ) { - stringstream str; - string ref, prop_nam = p.attr(_U(name)); + std::stringstream str; + std::string ref, prop_nam = p.attr(_U(name)); str << prop_nam << "_" << (void*)mat; ref = str.str(); mgr.AddProperty(ref.c_str(), p.attr(_U(value))); /// Check existence @@ -542,8 +541,8 @@ template <> void Converter::operator()(xml_h e) const { mat->GetName(), prop_nam.c_str(), ref.c_str()); } else if ( p.hasAttr(_U(option)) ) { - string prop_nam = p.attr(_U(name)); - string prop_typ = p.attr(_U(option)); + std::string prop_nam = p.attr(_U(name)); + std::string prop_typ = p.attr(_U(option)); mat->AddConstProperty(prop_nam.c_str(), prop_typ.c_str()); printout(s_debug.materials ? ALWAYS : DEBUG, "Compact", "++ material %-16s add constant property: %s -> %s.", @@ -554,10 +553,10 @@ template <> void Converter::operator()(xml_h e) const { for(xml_coll_t properties(x_mat, _U(property)); properties; ++properties) { xml_elt_t p = properties; if ( p.hasAttr(_U(ref)) ) { - string ref = p.attr(_U(ref)); + std::string ref = p.attr(_U(ref)); TGDMLMatrix* gdmlMat = mgr.GetGDMLMatrix(ref.c_str()); if ( gdmlMat ) { - string prop_nam = p.attr(_U(name)); + std::string prop_nam = p.attr(_U(name)); mat->AddProperty(prop_nam.c_str(), ref.c_str()); printout(s_debug.materials ? ALWAYS : DEBUG, "Compact", "++ material %-16s add property: %s -> %s.", @@ -579,7 +578,7 @@ template <> void Converter::operator()(xml_h e) const { // TGeo has no notion of a material "formula" // Hence, treat the formula the same way as the material itself if (x_mat.hasAttr(_U(formula))) { - string form = x_mat.attr(_U(formula)); + std::string form = x_mat.attr(_U(formula)); if (form != matname) { medium = mgr.GetMedium(form.c_str()); if (0 == medium) { @@ -601,18 +600,18 @@ template <> void Converter::operator()(xml_h e) const { template <> void Converter::operator()(xml_h e) const { xml_dim_t isotope(e); TGeoManager& mgr = description.manager(); - string nam = isotope.nameStr(); + std::string nam = isotope.nameStr(); TGeoElementTable* tab = mgr.GetElementTable(); TGeoIsotope* iso = tab->FindIsotope(nam.c_str()); // Create the isotope object in the event it is not yet present from the XML data if ( !iso ) { - xml_ref_t atom(isotope.child(_U(atom))); - int n = isotope.attr(_U(N)); - int z = isotope.attr(_U(Z)); - double value = atom.attr(_U(value)); - string unit = atom.attr(_U(unit)); - double a = value * _multiply(unit,"mol/g"); + xml_ref_t atom(isotope.child(_U(atom))); + std::string unit = atom.attr(_U(unit)); + double value = atom.attr(_U(value)); + double a = value * _multiply(unit,"mol/g"); + int n = isotope.attr(_U(N)); + int z = isotope.attr(_U(Z)); iso = new TGeoIsotope(nam.c_str(), z, n, a); printout(s_debug.isotopes ? ALWAYS : DEBUG, "Compact", "++ Converting isotope %-16s Z:%3d N:%3d A:%8.4f [g/mol]", @@ -647,12 +646,12 @@ template <> void Converter::operator()(xml_h e) const { TGeoElement* elt = tab->FindElement(name.c_str()); if ( !elt ) { if ( elem.hasChild(_U(atom)) ) { - xml_ref_t atom(elem.child(_U(atom))); - string formula = elem.attr(_U(formula)); - double value = atom.attr(_U(value)); - string unit = atom.attr(_U(unit)); - int z = elem.attr(_U(Z)); - double a = value*_multiply(unit,"mol/g"); + xml_ref_t atom(elem.child(_U(atom))); + std::string formula = elem.attr(_U(formula)); + double value = atom.attr(_U(value)); + std::string unit = atom.attr(_U(unit)); + int z = elem.attr(_U(Z)); + double a = value*_multiply(unit,"mol/g"); printout(s_debug.elements ? ALWAYS : DEBUG, "Compact", "++ Converting element %-16s [%-3s] Z:%3d A:%8.4f [g/mol]", name.c_str(), formula.c_str(), z, a); @@ -660,15 +659,15 @@ template <> void Converter::operator()(xml_h e) const { } else { int num_isotopes = 0; - string formula = elem.hasAttr(_U(formula)) ? elem.attr(_U(formula)) : name.str(); + std::string formula = elem.hasAttr(_U(formula)) ? elem.attr(_U(formula)) : name.str(); for( xml_coll_t i(elem,_U(fraction)); i; ++i) ++num_isotopes; elt = new TGeoElement(name.c_str(), formula.c_str(), num_isotopes); tab->AddElement(elt); for( xml_coll_t i(elem,_U(fraction)); i; ++i) { - double frac = i.attr(_U(n)); - string ref = i.attr(_U(ref)); - TGeoIsotope* iso = tab->FindIsotope(ref.c_str()); + double frac = i.attr(_U(n)); + std::string ref = i.attr(_U(ref)); + TGeoIsotope* iso = tab->FindIsotope(ref.c_str()); if ( !iso ) { except("Compact","Element %s cannot be constructed. Isotope '%s' (fraction: %.3f) missing!", name.c_str(), ref.c_str(), frac); @@ -716,7 +715,7 @@ template <> void Converter::operator()(xml_h e) const { temp_unit = temperature.attr(_U(unit)); temp_val = temperature.attr(_U(value)) * temp_unit; } - xml_h pressure = cond.child(_U(P), false); + xml_h pressure = cond.child(_U(P), false); double pressure_val = description.stdConditions().pressure; if ( pressure.ptr() ) { double pressure_unit = _toDouble("pascal"); @@ -738,17 +737,17 @@ template <> void Converter::operator()(xml_h e) const { template <> void Converter::operator()(xml_h element) const { xml_elt_t e = element; TGeoManager& mgr = description.manager(); - std::string sname = e.attr(_U(name)); - string ref, pname; + std::string sname = e.attr(_U(name)); + std::string ref, pname; // Defaults from Geant4 OpticalSurface::EModel model = OpticalSurface::Model::kMglisur; OpticalSurface::EFinish finish = OpticalSurface::Finish::kFpolished; OpticalSurface::EType type = OpticalSurface::Type::kTdielectric_metal; Double_t value = 1.0; - if ( e.hasAttr(_U(type)) ) type = OpticalSurface::stringToType(e.attr(_U(type))); - if ( e.hasAttr(_U(model)) ) model = OpticalSurface::stringToModel(e.attr(_U(model))); - if ( e.hasAttr(_U(finish)) ) finish = OpticalSurface::stringToFinish(e.attr(_U(finish))); + if ( e.hasAttr(_U(type)) ) type = OpticalSurface::stringToType(e.attr(_U(type))); + if ( e.hasAttr(_U(model)) ) model = OpticalSurface::stringToModel(e.attr(_U(model))); + if ( e.hasAttr(_U(finish)) ) finish = OpticalSurface::stringToFinish(e.attr(_U(finish))); if ( e.hasAttr(_U(value)) ) value = e.attr(_U(value)); OpticalSurface surf(description, sname, model, finish, type, value); if ( s_debug.surface ) { @@ -756,10 +755,10 @@ template <> void Converter::operator()(xml_h element) const { sname.c_str(), int(type), int(model), int(finish), value); } for (xml_coll_t props(e, _U(property)); props; ++props) { - pname = props.attr(_U(name)); + pname = props.attr(_U(name)); if ( props.hasAttr(_U(ref)) ) { bool err = kFALSE; - ref = props.attr(_U(ref)); + ref = props.attr(_U(ref)); mgr.GetProperty(ref.c_str(), &err); /// Check existence surf->AddProperty(pname.c_str(), ref.c_str()); if ( s_debug.surface ) { @@ -767,11 +766,11 @@ template <> void Converter::operator()(xml_h element) const { } continue; } - size_t cols = props.attr(_U(coldim)); - xml_attr_t opt = props.attr_nothrow(_U(option)); - stringstream str(props.attr(_U(values))), str_nam; - string val; - vector values; + std::size_t cols = props.attr(_U(coldim)); + xml_attr_t opt = props.attr_nothrow(_U(option)); + std::stringstream str(props.attr(_U(values))), str_nam; + std::string val; + std::vector values; while ( !str.eof() ) { val = ""; str >> val; @@ -781,13 +780,13 @@ template <> void Converter::operator()(xml_h element) const { /// Create table and register table TGDMLMatrix* table = new TGDMLMatrix("",values.size()/cols, cols); if ( opt ) { - string tit = e.attr(opt); + std::string tit = e.attr(opt); str_nam << tit << "|"; } str_nam << pname << "__" << (void*)table; table->SetName(str_nam.str().c_str()); table->SetTitle(pname.c_str()); - for (size_t i=0, n=values.size(); iSet(i/cols, i%cols, values[i]); surf->AddProperty(pname.c_str(), table->GetName()); description.manager().AddGDMLMatrix(table); @@ -797,10 +796,10 @@ template <> void Converter::operator()(xml_h element) const { // In case there were constant surface properties specified: convert them here for(xml_coll_t properties(e, _U(constant)); properties; ++properties) { xml_elt_t p = properties; - pname = p.attr(_U(name)); + pname = p.attr(_U(name)); if ( p.hasAttr(_U(ref)) ) { bool err = kFALSE; - ref = p.attr(_U(ref)); + ref = p.attr(_U(ref)); mgr.GetProperty(ref.c_str(), &err); /// Check existence if ( err == kFALSE ) { surf->AddConstProperty(pname.c_str(), ref.c_str()); @@ -814,7 +813,7 @@ template <> void Converter::operator()(xml_h element) const { " ConstProperty missing in TGeoManager: " + ref); } else if ( p.hasAttr(_U(value)) ) { - stringstream str; + std::stringstream str; str << pname << "_" << (void*)surf.ptr(); ref = str.str(); mgr.AddProperty(ref.c_str(), p.attr(_U(value))); /// Check existence @@ -824,7 +823,7 @@ template <> void Converter::operator()(xml_h element) const { surf->GetName(), pname.c_str(), ref.c_str()); } else if ( p.hasAttr(_U(option)) ) { - string ptyp = p.attr(_U(option)); + std::string ptyp = p.attr(_U(option)); surf->AddConstProperty(pname.c_str(), ptyp.c_str()); printout(s_debug.surface ? ALWAYS : DEBUG, "Compact", "++ surface %-16s add constant property: %s -> %s.", @@ -840,8 +839,8 @@ template <> void Converter::operator()(xml_h element) const { * */ template <> void Converter::operator()(xml_h e) const { - double value = e.attr(_U(value)); - string name = e.attr(_U(name)); + double value = e.attr(_U(value)); + std::string name = e.attr(_U(name)); description.manager().AddProperty(name.c_str(), value); if ( s_debug.matrix ) { printout(ALWAYS,"Compact","+++ Reading property %s : %f",name.c_str(), value); @@ -849,7 +848,7 @@ template <> void Converter::operator()(xml_h e) const { #if 0 xml_attr_t opt = e.attr_nothrow(_U(title)); if ( opt ) { - string val = e.attr(opt); + std::string val = e.attr(opt); TNamed* nam = description.manager().GetProperty(name.c_str()); if ( !nam ) { except("Compact","Failed to access just added manager property: %s",name.c_str()); @@ -865,35 +864,35 @@ template <> void Converter::operator()(xml_h e) const { * */ template <> void Converter::operator()(xml_h e) const { - vector vals; - size_t cols = e.attr(_U(coldim)); - stringstream str(e.attr(_U(values))); + std::vector vals; + std::size_t cols = e.attr(_U(coldim)); + std::stringstream str(e.attr(_U(values))); if ( s_debug.matrix ) { printout(ALWAYS,"Compact","+++ Reading property table %s with %d columns.", - e.attr(_U(name)).c_str(), cols); + e.attr(_U(name)).c_str(), cols); } vals.reserve(1024); while ( !str.eof() ) { - string item; + std::string item; str >> item; if ( item.empty() && !str.good() ) break; vals.emplace_back(_toDouble(item)); if ( s_debug.matrix ) { - cout << " state:" << (str.good() ? "OK " : "BAD") << " '" << item << "'"; - if ( 0 == (vals.size()%cols) ) cout << endl; + std::cout << " state:" << (str.good() ? "OK " : "BAD") << " '" << item << "'"; + if ( 0 == (vals.size()%cols) ) std::cout << std::endl; } } if ( s_debug.matrix ) { - cout << endl; + std::cout << std::endl; } /// Create table and register table xml_attr_t opt = e.attr_nothrow(_U(option)); PropertyTable tab(description, - e.attr(_U(name)), - opt ? e.attr(opt).c_str() : "", + e.attr(_U(name)), + opt ? e.attr(opt).c_str() : "", vals.size()/cols, cols); - for( size_t i=0, n=vals.size(); i < n; ++i ) + for( std::size_t i=0, n=vals.size(); i < n; ++i ) tab->Set(i/cols, i%cols, vals[i]); //if ( s_debug.matrix ) tab->Print(); } @@ -913,7 +912,7 @@ template <> void Converter::operator()(xml_h e) const { * alpha="0.5"/> */ template <> void Converter::operator()(xml_h e) const { - VisAttr attr(e.attr(_U(name))); + VisAttr attr(e.attr(_U(name))); float alpha = 1.0; float red = 1.0; float green = 1.0; @@ -921,10 +920,10 @@ template <> void Converter::operator()(xml_h e) const { bool use_ref = false; if(e.hasAttr(_U(ref))) { use_ref = true; - auto refName = e.attr(_U(ref)); + auto refName = e.attr(_U(ref)); const auto refAttr = description.visAttributes(refName); if(!refAttr.isValid() ) { - throw runtime_error("reference VisAttr " + refName + " does not exist"); + except("Compact","+++ Reference VisAttr %s does not exist", refName.c_str()); } // Just copying things manually. // I think a handle's copy constructor/assignment would reuse the underlying pointer... maybe? @@ -948,7 +947,7 @@ template <> void Converter::operator()(xml_h e) const { if (e.hasAttr(_U(visible))) attr.setVisible(e.attr(_U(visible))); if (e.hasAttr(_U(lineStyle))) { - string ls = e.attr(_U(lineStyle)); + std::string ls = e.attr(_U(lineStyle)); if (ls == "unbroken") attr.setLineStyle(VisAttr::SOLID); else if (ls == "broken") @@ -959,7 +958,7 @@ template <> void Converter::operator()(xml_h e) const { attr.setLineStyle(VisAttr::SOLID); } if (e.hasAttr(_U(drawingStyle))) { - string ds = e.attr(_U(drawingStyle)); + std::string ds = e.attr(_U(drawingStyle)); if (ds == "wireframe") attr.setDrawingStyle(VisAttr::WIREFRAME); else if (ds == "solid") @@ -984,7 +983,7 @@ template <> void Converter::operator()(xml_h e) const { template <> void Converter::operator()(xml_h elt) const { xml_dim_t e = elt; Region region(e.nameStr()); - vector& limits = region.limits(); + auto& limits = region.limits(); xml_attr_t cut = elt.attr_nothrow(_U(cut)); xml_attr_t threshold = elt.attr_nothrow(_U(threshold)); xml_attr_t store_secondaries = elt.attr_nothrow(_U(store_secondaries)); @@ -1002,7 +1001,7 @@ template <> void Converter::operator()(xml_h elt) const { region.setStoreSecondaries(elt.attr(store_secondaries)); } for (xml_coll_t user_limits(e, _U(limitsetref)); user_limits; ++user_limits) - limits.emplace_back(user_limits.attr(_U(name))); + limits.emplace_back(user_limits.attr(_U(name))); description.addRegion(region); } @@ -1015,9 +1014,9 @@ template <> void Converter::operator()(xml_h elt) const { * */ template <> void Converter::operator()(xml_h seg) const { - string type = seg.attr(_U(type)); - string name = seg.hasAttr(_U(name)) ? seg.attr(_U(name)) : string(); - std::pair* opt = _option >(); + std::string type = seg.attr(_U(type)); + std::string name = seg.hasAttr(_U(name)) ? seg.attr(_U(name)) : std::string(); + std::pair* opt = _option >(); const BitFieldCoder* bitfield = &opt->second->decoder; Segmentation segment(type, name, bitfield); @@ -1028,7 +1027,7 @@ template <> void Converter::operator()(xml_h seg) const { for(const auto p : pars ) { xml::Strng_t pNam(p->name()); if ( seg.hasAttr(pNam) ) { - string pType = p->type(); + std::string pType = p->type(); if ( pType.compare("int") == 0 ) { typedef DDSegmentation::TypedSegmentationParameter ParInt; static_cast(p)->setTypedValue(seg.attr(pNam)); @@ -1036,22 +1035,22 @@ template <> void Converter::operator()(xml_h seg) const { typedef DDSegmentation::TypedSegmentationParameter ParFloat; static_cast(p)->setTypedValue(seg.attr(pNam)); } else if ( pType.compare("doublevec") == 0 ) { - vector valueVector; - string par = seg.attr(pNam); + std::vector valueVector; + std::string par = seg.attr(pNam); printout(s_debug.segmentation ? ALWAYS : DEBUG, "Compact", - "++ Converting this string structure: %s.",par.c_str()); - vector elts = DDSegmentation::splitString(par); - for (const string& spar : elts ) { + "++ Converting this std::string structure: %s.",par.c_str()); + std::vector elts = DDSegmentation::splitString(par); + for (const std::string& spar : elts ) { if ( spar.empty() ) continue; valueVector.emplace_back(_toDouble(spar)); } - typedef DDSegmentation::TypedSegmentationParameter< vector > ParDouVec; + typedef DDSegmentation::TypedSegmentationParameter< std::vector > ParDouVec; static_cast(p)->setTypedValue(valueVector); } else if ( pType.compare("double" ) == 0) { typedef DDSegmentation::TypedSegmentationParameterParDouble; static_cast(p)->setTypedValue(seg.attr(pNam)); } else { - p->setValue(seg.attr(pNam)); + p->setValue(seg.attr(pNam)); } } else if (not p->isOptional()) { throw_print("FAILED to create segmentation: " + type + @@ -1075,7 +1074,7 @@ template <> void Converter::operator()(xml_h seg) const { key_max = x_seg.key_max(); } else { - stringstream tree; + std::stringstream tree; xml::dump_tree(sub,tree); throw_print("Nested segmentations: Invalid key specification:"+tree.str()); } @@ -1102,8 +1101,8 @@ template <> void Converter::operator()(xml_h seg) const { */ template <> void Converter::operator()(xml_h e) const { xml_h seg = e.child(_U(segmentation), false); - xml_h id = e.child(_U(id)); - string name = e.attr(_U(name)); + xml_h id = e.child(_U(id)); + std::string name = e.attr(_U(name)); std::pair opt; Readout ro(name); @@ -1131,16 +1130,16 @@ template <> void Converter::operator()(xml_h e) const { ro.name(), id ? "ID: " : "", id ? id.text().c_str() : ""); for(xml_coll_t colls(e,_U(hits_collections)); colls; ++colls) { - string hits_key; - if ( colls.hasAttr(_U(key)) ) hits_key = colls.attr(_U(key)); + std::string hits_key; + if ( colls.hasAttr(_U(key)) ) hits_key = colls.attr(_U(key)); for(xml_coll_t coll(colls,_U(hits_collection)); coll; ++coll) { xml_dim_t c(coll); - string coll_name = c.nameStr(); - string coll_key = hits_key; + std::string coll_name = c.nameStr(); + std::string coll_key = hits_key; long key_min = 0, key_max = 0; if ( c.hasAttr(_U(key)) ) { - coll_key = c.attr(_U(key)); + coll_key = c.attr(_U(key)); } if ( c.hasAttr(_U(key_value)) ) { key_max = key_min = c.key_value(); @@ -1150,7 +1149,7 @@ template <> void Converter::operator()(xml_h e) const { key_max = c.key_max(); } else { - stringstream tree; + std::stringstream tree; xml::dump_tree(e,tree); throw_print("Readout: Invalid specification for multiple hit collections."+tree.str()); } @@ -1180,14 +1179,14 @@ DECLARE_XML_DOC_READER(readout,load_readout) */ template <> void Converter::operator()(xml_h e) const { Limit limit; - LimitSet ls(e.attr(_U(name))); + LimitSet ls(e.attr(_U(name))); printout(s_debug.limits ? ALWAYS : DEBUG, "Compact", "++ Converting LimitSet structure: %s.",ls.name()); for (xml_coll_t c(e, _U(limit)); c; ++c) { - limit.name = c.attr(_U(name)); - limit.particles = c.attr(_U(particles)); - limit.content = c.attr(_U(value)); - limit.unit = c.attr(_U(unit)); + limit.name = c.attr(_U(name)); + limit.particles = c.attr(_U(particles)); + limit.content = c.attr(_U(value)); + limit.unit = c.attr(_U(unit)); limit.value = _multiply(limit.content, limit.unit); ls.addLimit(limit); printout(s_debug.limits ? ALWAYS : DEBUG, "Compact", @@ -1197,9 +1196,9 @@ template <> void Converter::operator()(xml_h e) const { } limit.name = "cut"; for (xml_coll_t c(e, _U(cut)); c; ++c) { - limit.particles = c.attr(_U(particles)); - limit.content = c.attr(_U(value)); - limit.unit = c.attr(_U(unit)); + limit.particles = c.attr(_U(particles)); + limit.content = c.attr(_U(value)); + limit.unit = c.attr(_U(unit)); limit.value = _multiply(limit.content, limit.unit); ls.addCut(limit); printout(s_debug.limits ? ALWAYS : DEBUG, "Compact", @@ -1217,17 +1216,17 @@ template <> void Converter::operator()(xml_h e) const { * ... */ template <> void Converter::operator()(xml_h e) const { - string name = e.attr(_U(name)); + std::string name = e.attr(_U(name)); Detector::Properties& prp = description.properties(); if ( name.empty() ) throw_print("Failed to convert properties. No name given!"); - vector a = e.attributes(); + std::vector a = e.attributes(); if ( prp.find(name) == prp.end() ) prp.emplace(name, Detector::PropertyValues()); for (xml_attr_t i : a ) - prp[name].emplace(xml_tag_t(e.attr_name(i)).str(),e.attr(i)); + prp[name].emplace(xml_tag_t(e.attr_name(i)).str(),e.attr(i)); } /** Specialized converter for electric and magnetic fields @@ -1239,9 +1238,9 @@ template <> void Converter::operator()(xml_h e) const { * */ template <> void Converter::operator()(xml_h e) const { - string msg = "updated"; - string name = e.attr(_U(name)); - string type = e.attr(_U(type)); + std::string msg = "updated"; + std::string name = e.attr(_U(name)); + std::string type = e.attr(_U(type)); CartesianField field = description.field(name); if ( !field.isValid() ) { // The field is not present: We create it and add it to Detector @@ -1258,13 +1257,13 @@ template <> void Converter::operator()(xml_h e) const { // Now update the field structure with the generic part ie. set its properties CartesianField::Properties& prp = field.properties(); for ( xml_coll_t c(e, _U(properties)); c; ++c ) { - string props_name = c.attr(_U(name)); - vectora = c.attributes(); + std::string props_name = c.attr(_U(name)); + std::vectora = c.attributes(); if ( prp.find(props_name) == prp.end() ) { prp.emplace(props_name, Detector::PropertyValues()); } for ( xml_attr_t i : a ) - prp[props_name].emplace(xml_tag_t(c.attr_name(i)).str(), c.attr(i)); + prp[props_name].emplace(xml_tag_t(c.attr_name(i)).str(), c.attr(i)); if (c.hasAttr(_U(global)) && c.attr(_U(global))) { description.field().properties() = prp; @@ -1287,12 +1286,12 @@ template <> void Converter::operator()(xml_h e) const { * */ template <> void Converter::operator()(xml_h element) const { - string name = element.attr(_U(name)); + std::string name = element.attr(_U(name)); try { SensitiveDetector sd = description.sensitiveDetector(name); xml_attr_t type = element.attr_nothrow(_U(type)); if ( type ) { - sd.setType(element.attr(type)); + sd.setType(element.attr(type)); } xml_attr_t verbose = element.attr_nothrow(_U(verbose)); if ( verbose ) { @@ -1304,7 +1303,7 @@ template <> void Converter::operator()(xml_h element) const { } xml_attr_t limits = element.attr_nothrow(_U(limits)); if ( limits ) { - string l = element.attr(limits); + std::string l = element.attr(limits); LimitSet ls = description.limitSet(l); if (!ls.isValid()) { throw_print("Converter: Request for non-existing limitset:" + l); @@ -1313,7 +1312,7 @@ template <> void Converter::operator()(xml_h element) const { } xml_attr_t region = element.attr_nothrow(_U(region)); if ( region ) { - string r = element.attr(region); + std::string r = element.attr(region); Region reg = description.region(r); if (!reg.isValid()) { throw_print("Converter: Request for non-existing region:" + r); @@ -1322,7 +1321,7 @@ template <> void Converter::operator()(xml_h element) const { } xml_attr_t hits = element.attr_nothrow(_U(hits_collection)); if (hits) { - sd.setHitsCollection(element.attr(hits)); + sd.setHitsCollection(element.attr(hits)); } xml_attr_t ecut = element.attr_nothrow(_U(ecut)); xml_attr_t eunit = element.attr_nothrow(_U(eunit)); @@ -1339,7 +1338,7 @@ template <> void Converter::operator()(xml_h element) const { if (sequence) { } } - catch (const exception& e) { + catch (const std::exception& e) { printout(ERROR, "Compact", "++ FAILED to convert sensitive detector: %s: %s", name.c_str(), e.what()); } catch (...) { @@ -1347,7 +1346,7 @@ template <> void Converter::operator()(xml_h element) const { } } -static void setChildTitles(const pair& e) { +static void setChildTitles(const std::pair& e) { DetElement parent = e.second.parent(); const DetElement::Children& children = e.second.children(); if (::strlen(e.second->GetTitle()) == 0) { @@ -1361,10 +1360,10 @@ template <> void Converter::operator()(xml_h element) const { static const char* req_typs = ::getenv("REQUIRED_DETECTOR_TYPES"); static const char* ign_dets = ::getenv("IGNORED_DETECTORS"); static const char* ign_typs = ::getenv("IGNORED_DETECTOR_TYPES"); - string type = element.attr(_U(type)); - string name = element.attr(_U(name)); - string name_match = ":" + name + ":"; - string type_match = ":" + type + ":"; + std::string type = element.attr(_U(type)); + std::string name = element.attr(_U(name)); + std::string name_match = ":" + name + ":"; + std::string type_match = ":" + type + ":"; if (req_dets && !strstr(req_dets, name_match.c_str())) return; @@ -1385,13 +1384,13 @@ template <> void Converter::operator()(xml_h element) const { } } try { - string par_name; + std::string par_name; xml_attr_t attr_par = element.attr_nothrow(_U(parent)); xml_elt_t elt_par(0); if (attr_par) - par_name = element.attr(attr_par); + par_name = element.attr(attr_par); else if ( (elt_par=element.child(_U(parent),false)) ) - par_name = elt_par.attr(_U(name)); + par_name = elt_par.attr(_U(name)); if ( !par_name.empty() ) { // We have here a nested detector. If the mother volume is not yet registered // it must be done here, so that the detector constructor gets the correct answer from @@ -1407,9 +1406,9 @@ template <> void Converter::operator()(xml_h element) const { SensitiveDetector sd; Segmentation seg; if ( attr_ro ) { - Readout ro = description.readout(element.attr(attr_ro)); + Readout ro = description.readout(element.attr(attr_ro)); if (!ro.isValid()) { - throw runtime_error("No Readout structure present for detector:" + name); + except("Compact","No Readout structure present for detector:" + name); } seg = ro.segmentation(); sd = SensitiveDetector(name, "sensitive"); @@ -1420,7 +1419,7 @@ template <> void Converter::operator()(xml_h element) const { Ref_t sens = sd; DetElement det(Ref_t(PluginService::Create(type, &description, &element, &sens))); if (det.isValid()) { - setChildTitles(make_pair(name, det)); + setChildTitles(std::make_pair(name, det)); if ( sd.isValid() ) { det->flag |= DetElement::Object::HAVE_SENSITIVE_DETECTOR; } @@ -1436,19 +1435,19 @@ template <> void Converter::operator()(xml_h element) const { if (!det.isValid()) { PluginDebug dbg; PluginService::Create(type, &description, &element, &sens); - throw runtime_error("Failed to execute subdetector creation plugin. " + dbg.missingFactory(type)); + except("Compact","Failed to execute subdetector creation plugin. %s", dbg.missingFactory(type).c_str()); } description.addDetector(det); description.surfaceManager().registerSurfaces(det); return; } - catch (const exception& e) { + catch (const std::exception& e) { printout(ERROR, "Compact", "++ FAILED to convert subdetector: %s: %s", name.c_str(), e.what()); - terminate(); + std::terminate(); } catch (...) { printout(ERROR, "Compact", "++ FAILED to convert subdetector: %s: %s", name.c_str(), "UNKNONW Exception"); - terminate(); + std::terminate(); } } @@ -1475,27 +1474,27 @@ template <> void Converter::operator()(xml_h element) const { /// Read material entries from a seperate file in one of the include sections of the geometry template <> void Converter::operator()(xml_h element) const { - string base = xml::DocumentHandler::system_directory(element); - string file = element.attr(_U(ref)); - vector argv{&file[0], &base[0]}; + std::string base = xml::DocumentHandler::system_directory(element); + std::string file = element.attr(_U(ref)); + std::vector argv{&file[0], &base[0]}; description.apply("DD4hep_JsonProcessor",int(argv.size()), &argv[0]); } /// Read alignment entries from a seperate file in one of the include sections of the geometry template <> void Converter::operator()(xml_h element) const { - PrintLevel level = s_debug.includes ? ALWAYS : DEBUG; - string fname = element.attr(_U(ref)); - size_t idx = fname.find("://"); + PrintLevel level = s_debug.includes ? ALWAYS : DEBUG; + std::string fname = element.attr(_U(ref)); + std::size_t idx = fname.find("://"); std::error_code ec; - if ( idx == string::npos && filesystem::exists(fname, ec) ) { + if ( idx == std::string::npos && std::filesystem::exists(fname, ec) ) { // Regular file without protocol specification printout(level, "Compact","++ Processing xml document %s.", fname.c_str()); this->description.fromXML(fname); } - else if ( idx == string::npos ) { + else if ( idx == std::string::npos ) { // File relative to location of xml tag (protocol specification not possible) - string location = xml::DocumentHandler::system_path(element, fname); + std::string location = xml::DocumentHandler::system_path(element, fname); printout(level, "Compact","++ Processing xml document %s.", location.c_str()); this->description.fromXML(location); } @@ -1516,8 +1515,8 @@ template <> void Converter::operator()(xml_h element) const { xml_elt_t x_world(element); xml_comp_t x_shape = x_world.child(_U(shape), false); xml_attr_t att = x_world.getAttr(_U(material)); - Material mat = att ? description.material(x_world.attr(att)) : description.air(); - Volume world_vol; + Material mat = att ? description.material(x_world.attr(att)) : description.air(); + Volume world_vol; /// Create the shape and the corresponding volume if ( x_shape ) { @@ -1562,15 +1561,15 @@ template <> void Converter::operator()(xml_h element) cons xml_comp_t shape = parallel.child(_U(shape)); xml_dim_t pos = element.child(_U(position),false); xml_dim_t rot = element.child(_U(rotation),false); - string name = element.attr(_U(name)); - string path = element.attr(_U(anchor)); + std::string name = element.attr(_U(name)); + std::string path = element.attr(_U(anchor)); bool conn = element.attr(_U(connected),false); DetElement anchor(detail::tools::findElement(description, path)); Position position = pos ? Position(pos.x(), pos.y(), pos.z()) : Position(); RotationZYX rotation = rot ? RotationZYX(rot.z(), rot.y(), rot.x()) : RotationZYX(); Material mat = parallel.hasAttr(_U(material)) - ? description.material(parallel.attr(_U(material))) + ? description.material(parallel.attr(_U(material))) : description.air(); VisAttr vis = parallel.hasAttr(_U(vis)) ? description.invisible() @@ -1610,7 +1609,7 @@ template <> void Converter::operator()(xml_h element) cons /// Read material entries from a seperate file in one of the include sections of the geometry template <> void Converter::operator()(xml_h element) const { - string type = element.hasAttr(_U(type)) ? element.attr(_U(type)) : string("xml"); + std::string type = element.hasAttr(_U(type)) ? element.attr(_U(type)) : std::string("xml"); if ( type == "xml" ) { xml::DocumentHolder doc(xml::DocumentHandler().load(element, element.attr_value(_U(ref)))); if ( s_debug.include_guard ) { @@ -1622,7 +1621,7 @@ template <> void Converter::operator()(xml_h element) const { printout(ALWAYS, "Compact","++ Processing xml document %s.",doc.uri().c_str()); } xml_h node = doc.root(); - string tag = node.tag(); + std::string tag = node.tag(); if ( tag == "lccdd" ) Converter(this->description)(node); else if ( tag == "define" ) @@ -1683,7 +1682,7 @@ template <> void Converter::operator()(xml_h element) const { if ( steer.hasAttr(_U(reflect)) ) build_reflections = steer.attr(_U(reflect)); for (xml_coll_t clr(steer, _U(clear)); clr; ++clr) { - string nam = clr.hasAttr(_U(name)) ? clr.attr(_U(name)) : string(); + std::string nam = clr.hasAttr(_U(name)) ? clr.attr(_U(name)) : std::string(); if ( nam.substr(0,6) == "elemen" ) { TGeoElementTable* table = description.manager().GetElementTable(); table->TGeoElementTable::~TGeoElementTable(); diff --git a/DDCore/src/segmentations/MultiSegmentation.cpp b/DDCore/src/segmentations/MultiSegmentation.cpp index 6dd0c4c00..c00b5ec4e 100644 --- a/DDCore/src/segmentations/MultiSegmentation.cpp +++ b/DDCore/src/segmentations/MultiSegmentation.cpp @@ -11,20 +11,19 @@ #include #include -using namespace std; - namespace dd4hep { + namespace DDSegmentation { /// default constructor using an encoding string - MultiSegmentation::MultiSegmentation(const string& cellEncoding) + MultiSegmentation::MultiSegmentation(const std::string& cellEncoding) : Segmentation(cellEncoding), m_discriminator(0), m_debug(0) { // define type and description _type = "MultiSegmentation"; _description = "Multi-segmenation wrapper segmentation"; //registerParameter("debug", "Debug flag", m_debug, 0); - registerParameter("key", "Diskriminating field", m_discriminatorId, ""); + registerParameter("key", "Diskriminating field", m_discriminatorId, ""); } /// Default constructor used by derived classes passing an existing decoder @@ -35,7 +34,7 @@ namespace dd4hep { _type = "MultiSegmentation"; _description = "Multi-segmenation wrapper segmentation"; //registerParameter("debug", "Debug flag", m_debug, 0); - registerParameter("key", "Diskriminating field", m_discriminatorId, ""); + registerParameter("key", "Diskriminating field", m_discriminatorId, ""); } /// destructor @@ -82,7 +81,8 @@ namespace dd4hep { } } } - throw runtime_error("MultiSegmentation: Invalid sub-segmentation identifier!");; + except("MultiSegmentation", "Invalid sub-segmentation identifier!"); + throw std::string("Invalid sub-segmentation identifier!"); } /// determine the position based on the cell ID @@ -95,13 +95,9 @@ namespace dd4hep { return subsegmentation(vID).cellID(localPosition, globalPosition, vID); } - vector MultiSegmentation::cellDimensions(const CellID& cID) const { + std::vector MultiSegmentation::cellDimensions(const CellID& cID) const { return subsegmentation(cID).cellDimensions(cID); } } /* namespace DDSegmentation */ } /* namespace dd4hep */ - -// This is done DDCore/src/plugins/ReadoutSegmentations.cpp so the plugin is not part of libDDCore -// needs also #include "DD4hep/Factories.h" -// DECLARE_SEGMENTATION(MultiSegmentation,create_segmentation) diff --git a/DDDigi/plugins/DigiRandomNoise.cpp b/DDDigi/plugins/DigiRandomNoise.cpp index 72b435c80..290c2e1d0 100644 --- a/DDDigi/plugins/DigiRandomNoise.cpp +++ b/DDDigi/plugins/DigiRandomNoise.cpp @@ -82,13 +82,12 @@ namespace dd4hep { // C/C++ include files -using namespace std; using namespace dd4hep::digi; DECLARE_DIGIACTION_NS(dd4hep::digi,DigiRandomNoise) /// Standard constructor -DigiRandomNoise::DigiRandomNoise(const DigiKernel& kernel, const string& nam) +DigiRandomNoise::DigiRandomNoise(const DigiKernel& kernel, const std::string& nam) : DigiEventAction(kernel, nam) { declareProperty("Probability", m_probability); diff --git a/DDDigi/src/DigiActionSequence.cpp b/DDDigi/src/DigiActionSequence.cpp index 4815074fb..8596a94a1 100644 --- a/DDDigi/src/DigiActionSequence.cpp +++ b/DDDigi/src/DigiActionSequence.cpp @@ -18,11 +18,10 @@ // C/C++ include files #include -using namespace std; using namespace dd4hep::digi; /// Standard constructor -DigiActionSequence::DigiActionSequence(const DigiKernel& kernel, const string& nam) +DigiActionSequence::DigiActionSequence(const DigiKernel& kernel, const std::string& nam) : DigiSynchronize(kernel, nam) { InstanceCount::increment(this); @@ -50,7 +49,7 @@ void DigiActionSequence::execute(DigiContext& context) const { } /// Standard constructor -DigiSequentialActionSequence::DigiSequentialActionSequence(const DigiKernel& kernel, const string& nam) +DigiSequentialActionSequence::DigiSequentialActionSequence(const DigiKernel& kernel, const std::string& nam) : DigiActionSequence(kernel, nam) { this->m_parallel = false; @@ -63,7 +62,7 @@ DigiSequentialActionSequence::~DigiSequentialActionSequence() { } /// Standard constructor -DigiParallelActionSequence::DigiParallelActionSequence(const DigiKernel& kernel, const string& nam) +DigiParallelActionSequence::DigiParallelActionSequence(const DigiKernel& kernel, const std::string& nam) : DigiActionSequence(kernel, nam) { this->m_parallel = true; diff --git a/DDDigi/src/DigiHandle.cpp b/DDDigi/src/DigiHandle.cpp index f115968ee..dee3922d2 100644 --- a/DDDigi/src/DigiHandle.cpp +++ b/DDDigi/src/DigiHandle.cpp @@ -25,12 +25,11 @@ // C/C++ include files #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::digi; /// Namespace for the AIDA detector description toolkit namespace dd4hep { + /// Namespace for the Digitization part of the AIDA detector description toolkit namespace digi { @@ -75,14 +74,14 @@ namespace dd4hep { template TYPE* _create_object(const DigiKernel& kernel, const TypeName& typ) { TYPE* object = _raw_create(typ.first, kernel, typ.second); if (!object && typ.first == typ.second) { - string _t = typeName(typeid(TYPE)); + std::string _t = typeName(typeid(TYPE)); printout(DEBUG, "DigiHandle", "Object factory for %s not found. Try out %s", typ.second.c_str(), _t.c_str()); object = _raw_create(_t, kernel, typ.second); if (!object) { size_t idx = _t.rfind(':'); - if (idx != string::npos) - _t = string(_t.substr(idx + 1)); + if (idx != std::string::npos) + _t = std::string(_t.substr(idx + 1)); printout(DEBUG, "DigiHandle", "Try out object factory for %s",_t.c_str()); object = _raw_create(_t, kernel, typ.second); } @@ -95,7 +94,7 @@ namespace dd4hep { } template - DigiHandle::DigiHandle(const DigiKernel& kernel, const string& type_name) { + DigiHandle::DigiHandle(const DigiKernel& kernel, const std::string& type_name) { value = _create_object(kernel,TypeName::split(type_name)); } @@ -124,7 +123,7 @@ namespace dd4hep { value->addRef(); } - template Property& DigiHandle::operator[](const string& property_name) const { + template Property& DigiHandle::operator[](const std::string& property_name) const { PropertyManager& pm = checked_value(value)->properties(); return pm[property_name]; } @@ -185,7 +184,7 @@ namespace dd4hep { KernelHandle::KernelHandle(DigiKernel* k) : value(k) { } - Property& KernelHandle::operator[](const string& property_name) const { + Property& KernelHandle::operator[](const std::string& property_name) const { PropertyManager& pm = checked_value(value)->properties(); return pm[property_name]; } @@ -200,6 +199,7 @@ namespace dd4hep { namespace dd4hep { /// Namespace for the Digitization part of the AIDA detector description toolkit namespace digi { + template class DigiHandle; template class DigiHandle; template class DigiHandle; diff --git a/DDDigi/src/DigiLockedAction.cpp b/DDDigi/src/DigiLockedAction.cpp index daa112fd8..6dbf68c2c 100644 --- a/DDDigi/src/DigiLockedAction.cpp +++ b/DDDigi/src/DigiLockedAction.cpp @@ -16,14 +16,11 @@ #include #include -// C/C++ include files - -using namespace std; using namespace dd4hep::digi; /// Standard constructor -DigiLockedAction::DigiLockedAction(const DigiKernel& kernel, const string& nam) +DigiLockedAction::DigiLockedAction(const DigiKernel& kernel, const std::string& nam) : DigiEventAction(kernel, nam) { InstanceCount::increment(this); diff --git a/DDDigi/src/DigiMonitorHandler.cpp b/DDDigi/src/DigiMonitorHandler.cpp index 31abb1180..1d8cf7a59 100644 --- a/DDDigi/src/DigiMonitorHandler.cpp +++ b/DDDigi/src/DigiMonitorHandler.cpp @@ -20,11 +20,10 @@ /// C/C++ include files -using namespace std; using namespace dd4hep::digi; /// Standard constructor -DigiMonitorHandler::DigiMonitorHandler(const DigiKernel& kernel, const string& nam) +DigiMonitorHandler::DigiMonitorHandler(const DigiKernel& kernel, const std::string& nam) : DigiAction(kernel, nam) { declareProperty("MonitorOutput", m_output_file); @@ -52,24 +51,24 @@ void DigiMonitorHandler::adopt(DigiAction* source, TNamed* object) { void DigiMonitorHandler::save() { if ( !m_output_file.empty() ) { TFile* output = TFile::Open(m_output_file.c_str(), - "DD4hep Digitization monitoring information", - "RECREATE"); + "DD4hep Digitization monitoring information", + "RECREATE"); TDirectory::TContext top_context(output); if ( output && !output->IsZombie() ) { for( const auto& m : m_monitors ) { - const auto* act = m.first; - const auto& items = m.second; - const auto& nam = act->name(); - std::string title = "Monitor items of digitization action "+nam; - TDirectory* direc = output->mkdir(nam.c_str(), title.c_str(), kTRUE); - TDirectory::TContext action_context(direc); - for( const auto* itm : items ) { - Int_t nbytes = direc->WriteTObject(itm); - if ( nbytes <= 0 ) { - error("+++ Failed to write object: %s -> %s", nam.c_str(), itm->GetName()); - } - } - direc->Write(); + const auto* act = m.first; + const auto& items = m.second; + const auto& nam = act->name(); + std::string title = "Monitor items of digitization action "+nam; + TDirectory* direc = output->mkdir(nam.c_str(), title.c_str(), kTRUE); + TDirectory::TContext action_context(direc); + for( const auto* itm : items ) { + Int_t nbytes = direc->WriteTObject(itm); + if ( nbytes <= 0 ) { + error("+++ Failed to write object: %s -> %s", nam.c_str(), itm->GetName()); + } + } + direc->Write(); } output->Write(); output->Close(); diff --git a/DDDigi/src/DigiSegmentation.cpp b/DDDigi/src/DigiSegmentation.cpp index cdbedb446..e59fb0af6 100644 --- a/DDDigi/src/DigiSegmentation.cpp +++ b/DDDigi/src/DigiSegmentation.cpp @@ -18,7 +18,6 @@ #include #include - std::shared_ptr dd4hep::digi::create_cell_scanner(Solid solid, Segmentation segment) { std::string typ = "DigiCellScanner" + @@ -29,7 +28,6 @@ dd4hep::digi::create_cell_scanner(Solid solid, Segmentation segment) { std::shared_ptr dd4hep::digi::create_cell_scanner(const std::string& typ, Segmentation segment) { - using namespace dd4hep; SegmentationObject* seg = segment.ptr(); DigiCellScanner* scan = PluginService::Create(typ, seg); if ( !scan ) { diff --git a/DDDigi/src/DigiSegmentationTool.cpp b/DDDigi/src/DigiSegmentationTool.cpp index b71d4ae4f..c0a01a4c6 100644 --- a/DDDigi/src/DigiSegmentationTool.cpp +++ b/DDDigi/src/DigiSegmentationTool.cpp @@ -16,16 +16,16 @@ #include #include +// C/C++ include files #include -using namespace std; using namespace dd4hep::digi; namespace { void scan_detector(const DigiSegmentationTool& tool, - const string& split_by, - map >& splits, - dd4hep::DetElement de, dd4hep::VolumeID vid, dd4hep::VolumeID mask) { + const std::string& split_by, + std::map >& splits, + dd4hep::DetElement de, dd4hep::VolumeID vid, dd4hep::VolumeID mask) { dd4hep::PlacedVolume plc = de.placement(); const auto& new_ids = plc.volIDs(); dd4hep::VolumeID new_vid = vid; @@ -34,10 +34,10 @@ namespace { new_vid |= tool.iddescriptor.encode(new_ids); new_msk |= tool.iddescriptor.get_mask(new_ids); for (const auto& id : new_ids) { - if ( id.first == split_by ) { - splits.emplace(new_vid, make_pair(de, id.second)); - return; - } + if ( id.first == split_by ) { + splits.emplace(new_vid, std::make_pair(de, id.second)); + return; + } } } for ( const auto& c : de.children() ) @@ -46,7 +46,7 @@ namespace { } /// Split field name -const string& DigiSegmentContext::name() const { +const std::string& DigiSegmentContext::name() const { if ( this->field ) { return this->field->name(); } @@ -74,56 +74,56 @@ DigiSegmentationTool::DigiSegmentationTool(Detector& desc) } /// Setup tool to handle a given detector of the geometry -void DigiSegmentationTool::set_detector(const string& det_name) { +void DigiSegmentationTool::set_detector(const std::string& det_name) { const char* det = det_name.c_str(); this->detector = this->description.detector(det_name); if ( !this->detector.isValid() ) { except("DigiSegmentationTool", - "FAILED: Cannot access subdetector %s from the detector description.", det); + "FAILED: Cannot access subdetector %s from the detector description.", det); } this->sensitive = this->description.sensitiveDetector(det_name); if ( !sensitive.isValid() ) { except("DigiSegmentationTool", - "FAILED: Cannot access sensitive detector for %s.", det); + "FAILED: Cannot access sensitive detector for %s.", det); } this->iddescriptor = this->sensitive.idSpec(); if ( !this->iddescriptor.isValid() ) { except("DigiSegmentationTool", - "FAILED: Cannot access ID descriptor for detector %s.", det); + "FAILED: Cannot access ID descriptor for detector %s.", det); } } /// Access the readout collection keys -vector DigiSegmentationTool::collection_names() const { +std::vector DigiSegmentationTool::collection_names() const { if ( this->sensitive.isValid() ) { Readout rd = this->sensitive.readout(); - vector names = rd.collectionNames(); + std::vector names = rd.collectionNames(); if ( names.empty() ) names.emplace_back(rd.name()); return names; } except("DigiSegmentationTool", - "+++ collection_names: Readout not valid. Is the proper detector set ?"); + "+++ collection_names: Readout not valid. Is the proper detector set ?"); return {}; } /// Access the readout collection keys -vector DigiSegmentationTool::collection_keys() const { +std::vector DigiSegmentationTool::collection_keys() const { return collection_keys(0x0); } /// Access the readout collection keys -vector DigiSegmentationTool::collection_keys(Key::mask_type mask) const { - vector keys; - vector names = collection_names(); +std::vector DigiSegmentationTool::collection_keys(Key::mask_type mask) const { + std::vector keys; + std::vector names = collection_names(); for( const auto& collection : names ) keys.emplace_back(Key(collection, mask)); return keys; } /// Access the readout collection keys -vector -DigiSegmentationTool::collection_keys(const vector& detectors) const { - vector keys; +std::vector +DigiSegmentationTool::collection_keys(const std::vector& detectors) const { + std::vector keys; for( const auto& det : detectors ) { DigiSegmentationTool tool(this->description); tool.set_detector(det); @@ -134,11 +134,11 @@ DigiSegmentationTool::collection_keys(const vector& detectors) const { } /// Access the readout collection keys -vector -DigiSegmentationTool::collection_keys(const vector& detectors, - Key::mask_type mask) const +std::vector +DigiSegmentationTool::collection_keys(const std::vector& detectors, + Key::mask_type mask) const { - vector keys; + std::vector keys; for( const auto& det : detectors ) { DigiSegmentationTool tool(this->description); tool.set_detector(det); @@ -150,7 +150,7 @@ DigiSegmentationTool::collection_keys(const vector& detectors, /// Create a split context depending on the segmentation field DigiSegmentContext -DigiSegmentationTool::split_context(const string& split_by) const { +DigiSegmentationTool::split_context(const std::string& split_by) const { DigiSegmentContext splitter; splitter.cell_mask = ~0x0UL; splitter.detector = this->detector; @@ -169,23 +169,23 @@ DigiSegmentationTool::split_context(const string& split_by) const { } splitter.cell_mask = (splitter.cell_mask << e->width()); printout(INFO,"DigiSegmentationTool", - "%-24s %-8s [%3d,%7d] width:%2d offset:%2d mask:%016lX Split:%016lX Det:%016lX Cells:%016lX", - this->iddescriptor.name(), e->name().c_str(), - e->minValue(), e->maxValue(), e->width(), e->offset(), - e->mask(), splitter.split_mask, splitter.det_mask, splitter.cell_mask); + "%-24s %-8s [%3d,%7d] width:%2d offset:%2d mask:%016lX Split:%016lX Det:%016lX Cells:%016lX", + this->iddescriptor.name(), e->name().c_str(), + e->minValue(), e->maxValue(), e->width(), e->offset(), + e->mask(), splitter.split_mask, splitter.det_mask, splitter.cell_mask); if ( splitter.field ) break; } if ( !splitter.field ) { except("DigiSegmentationTool", - "FAILED: The ID descriptor for detector %s has no field %s.", - this->detector.name(), split_by.c_str()); + "FAILED: The ID descriptor for detector %s has no field %s.", + this->detector.name(), split_by.c_str()); } return splitter; } /// Create full set of detector segments which can be split according to the context -set DigiSegmentationTool::split_segmentation(const string& split_by) const { - map > segmentation_splits; +std::set DigiSegmentationTool::split_segmentation(const std::string& split_by) const { + std::map > segmentation_splits; PlacedVolume place = this->detector.placement(); const auto& ids = place.volIDs(); VolumeID vid = this->iddescriptor.encode(ids); @@ -195,22 +195,22 @@ set DigiSegmentationTool::split_segmentation(const string& split_by) if ( !fld ) { except("DigiSegmentationTool","Field discriminator %s does not exist in ID descriptor %s", - split_by.c_str(), this->iddescriptor.name()); + split_by.c_str(), this->iddescriptor.name()); } ::scan_detector(*this, split_by, segmentation_splits, this->detector, vid, msk); - stringstream str; - set splits; + std::stringstream str; + std::set splits; for( const auto& id : segmentation_splits ) { auto val = ((id.first&fld->mask())>>fld->offset()); splits.insert(val); } for( const auto& id : splits ) { - str << setw(16) << hex << setfill(' ') << id << " "; + str << std::setw(16) << std::hex << std::setfill(' ') << id << " "; } printout(INFO,"DigiSegmentationTool", - "%-24s has %ld entries and %ld parallel entries when splitting by \"%s\"", - det, segmentation_splits.size(), splits.size(), split_by.c_str()); + "%-24s has %ld entries and %ld parallel entries when splitting by \"%s\"", + det, segmentation_splits.size(), splits.size(), split_by.c_str()); printout(INFO,"DigiSegmentationTool","%-24s --> %-12s ids: %s", - "", split_by.c_str(), str.str().c_str()); + "", split_by.c_str(), str.str().c_str()); return splits; } diff --git a/DDDigi/src/DigiSynchronize.cpp b/DDDigi/src/DigiSynchronize.cpp index 4729c818e..3c365a3e8 100644 --- a/DDDigi/src/DigiSynchronize.cpp +++ b/DDDigi/src/DigiSynchronize.cpp @@ -20,7 +20,6 @@ // C/C++ include files #include -using namespace std; using namespace dd4hep::digi; @@ -31,7 +30,7 @@ DigiParallelWorker secs = chrono::high_resolution_clock::now() - start; + std::chrono::duration secs = std::chrono::high_resolution_clock::now() - start; const DigiEvent& ev = *context.event; debug("%s+++ Event: %8d (DigiSynchronize) Parallel: %-4s %3ld actions [%8.3g sec]", ev.id(), ev.eventNumber, yes_no(m_parallel), m_actors.size(), diff --git a/DDDigi/src/noise/DigiSubdetectorSequence.cpp b/DDDigi/src/noise/DigiSubdetectorSequence.cpp index 2120f8a62..c21225b50 100644 --- a/DDDigi/src/noise/DigiSubdetectorSequence.cpp +++ b/DDDigi/src/noise/DigiSubdetectorSequence.cpp @@ -27,11 +27,10 @@ // C/C++ include files #include -using namespace std; using namespace dd4hep::digi; /// Standard constructor -DigiSubdetectorSequence::DigiSubdetectorSequence(const DigiKernel& kernel, const string& nam) +DigiSubdetectorSequence::DigiSubdetectorSequence(const DigiKernel& kernel, const std::string& nam) : DigiActionSequence(kernel, nam) { declareProperty("detector",m_detectorName); @@ -69,13 +68,13 @@ void DigiSubdetectorSequence::scan_sensitive(PlacedVolume pv, VolumeID vid, Volu Volume vol = pv.volume(); if ( vol.isSensitive() ) { Solid sol = vol.solid(); - auto key = make_pair(sol->IsA(), m_segmentation); + auto key = std::make_pair(sol->IsA(), m_segmentation); auto is = m_scanners.find(key); if ( is == m_scanners.end() ) { - is = m_scanners.insert(make_pair(key, create_cell_scanner(sol, m_segmentation))).first; + is = m_scanners.insert(std::make_pair(key, create_cell_scanner(sol, m_segmentation))).first; } } - for (int idau = 0, ndau = pv->GetNdaughters(); idau < ndau; ++idau) { + for ( int idau = 0, ndau = pv->GetNdaughters(); idau < ndau; ++idau ) { PlacedVolume p(pv->GetDaughter(idau)); const VolIDs& new_ids = p.volIDs(); if ( !new_ids.empty() ) { @@ -99,8 +98,8 @@ void DigiSubdetectorSequence::scan_detector(DetElement de, VolumeID vid, VolumeI for (const auto& id : new_ids) { if ( id.first == m_segmentName ) { VolumeID rid = detail::reverseBits(new_vid); - m_parallelVid.emplace(make_pair(rid, Context(de, new_vid, rid, new_msk))); - m_parallelDet.emplace(make_pair(de, new_vid)); + m_parallelVid.emplace(std::make_pair(rid, Context(de, new_vid, rid, new_msk))); + m_parallelDet.emplace(std::make_pair(de, new_vid)); scan_sensitive(de.placement(), new_vid, new_msk); return; } @@ -114,12 +113,12 @@ void DigiSubdetectorSequence::scan_detector(DetElement de, VolumeID vid, VolumeI void DigiSubdetectorSequence::process_cell(DigiContext&, const DigiCellScanner& , const DigiCellData& /* data */) const { #if 0 Segmentation seg = m_sensDet.readout().segmentation(); - string desc = m_idDesc.str(data.cell_id); - info("Sensitive: [%s/%s] vid:%s %s", - data.solid->IsA()->GetName(), - seg.type().c_str(), - volumeID(data.cell_id).c_str(), - desc.c_str()); + std::string desc = m_idDesc.str(data.cell_id); + info("Sensitive: [%s/%s] vid:%s %s", + data.solid->IsA()->GetName(), + seg.type().c_str(), + volumeID(data.cell_id).c_str(), + desc.c_str()); if ( data.cell_id ) { } #endif @@ -133,7 +132,7 @@ void DigiSubdetectorSequence::process_context(DigiContext& context, { Volume vol = pv.volume(); if ( vol.isSensitive() ) { - auto key = make_pair(vol->GetShape()->IsA(), m_segmentation); + auto key = std::make_pair(vol->GetShape()->IsA(), m_segmentation); auto is = m_scanners.find(key); if ( is == m_scanners.end() ) { except("Fatal error in process_context: Invalid cell scanner. vid: %016X",vid); @@ -157,7 +156,7 @@ void DigiSubdetectorSequence::execute(DigiContext& context) const { const Context& c = d.second; auto vid = c.detector_id; auto det = c.detector; - string id_desc = m_idDesc.str(vid); + std::string id_desc = m_idDesc.str(vid); info(" Order:%-64s vid:%s %s %s", det.path().c_str(), volumeID(d.first).c_str(), volumeID(vid).c_str(), id_desc.c_str()); process_context(context, c, c.detector.placement(), c.detector_id, c.detector_mask); @@ -168,11 +167,11 @@ void DigiSubdetectorSequence::execute(DigiContext& context) const { } /// Access subdetector from the detector description -dd4hep::DetElement DigiSubdetectorSequence::subdetector(const string& nam) const { +dd4hep::DetElement DigiSubdetectorSequence::subdetector(const std::string& nam) const { return m_kernel.detectorDescription().detector(nam); } /// Access sensitive detector from the detector description -dd4hep::SensitiveDetector DigiSubdetectorSequence::sensitiveDetector(const string& nam) const { +dd4hep::SensitiveDetector DigiSubdetectorSequence::sensitiveDetector(const std::string& nam) const { return m_kernel.detectorDescription().sensitiveDetector(nam); } diff --git a/DDDigi/src/noise/FalphaNoise.cpp b/DDDigi/src/noise/FalphaNoise.cpp index 615557999..01c564e56 100644 --- a/DDDigi/src/noise/FalphaNoise.cpp +++ b/DDDigi/src/noise/FalphaNoise.cpp @@ -19,7 +19,6 @@ #include #include -using namespace std; using namespace dd4hep::detail; #ifdef __GSL_FALPHA_NOISE diff --git a/DDDigi/test_task_queue.cpp b/DDDigi/test_task_queue.cpp index 76ae7e9a1..710ede707 100644 --- a/DDDigi/test_task_queue.cpp +++ b/DDDigi/test_task_queue.cpp @@ -12,8 +12,6 @@ //========================================================================== #include #include -using namespace tbb; -using namespace std; class say_hello { int cnt = 0; @@ -26,10 +24,9 @@ class say_hello { } }; -int main( ) -{ - task_scheduler_init init(2); - task_group tg1, tg2, tg3; +int main() { + tbb::task_scheduler_init init(2); + tbb::task_group tg1, tg2, tg3; for(int i=0; i<200; ++i) { tg1.run(std::move(say_hello("child(1)",i))); tg2.run(std::move(say_hello("child(2)",i))); diff --git a/DDEve/src/Annotation.cpp b/DDEve/src/Annotation.cpp index 2aa6565db..7974ab78c 100644 --- a/DDEve/src/Annotation.cpp +++ b/DDEve/src/Annotation.cpp @@ -12,10 +12,10 @@ //========================================================================== // Framework include files -#include "DDEve/Annotation.h" -#include "DD4hep/InstanceCount.h" -#include "TEveViewer.h" -#include "TGLViewer.h" +#include +#include +#include +#include // C/C++ include files diff --git a/DDG4/plugins/Geant4CaloSmearShowerModel.cpp b/DDG4/plugins/Geant4CaloSmearShowerModel.cpp index fa8405969..56b4415e5 100644 --- a/DDG4/plugins/Geant4CaloSmearShowerModel.cpp +++ b/DDG4/plugins/Geant4CaloSmearShowerModel.cpp @@ -24,8 +24,8 @@ #include // Geant4 include files -#include "G4SystemOfUnits.hh" -#include "G4FastStep.hh" +#include +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -48,38 +48,38 @@ namespace dd4hep { double NoiseEnergyResolution { -1e0 }; double resolution(double momentum) const { - double res = -1e0; - double mom = momentum/CLHEP::GeV; - if ( this->StocasticEnergyResolution > 0 && - this->ConstantEnergyResolution > 0 && - this->NoiseEnergyResolution > 0 ) { - res = std::sqrt(std::pow( this->StocasticEnergyResolution / std::sqrt( mom ), 2 ) + // stochastic - std::pow( this->ConstantEnergyResolution, 2 ) + // constant - std::pow( this->NoiseEnergyResolution / mom, 2 ) ); // noise - } - else if ( this->StocasticEnergyResolution > 0 && - this->ConstantEnergyResolution > 0 ) { - res = std::sqrt(std::pow( this->StocasticEnergyResolution / std::sqrt( mom ), 2 ) + // stochastic - std::pow( this->ConstantEnergyResolution, 2 ) ); // constant - } - else if ( this->StocasticEnergyResolution > 0 ) { - res = this->StocasticEnergyResolution / std::sqrt( mom ); // stochastic - } - else if ( this->ConstantEnergyResolution > 0 ) { - res = this->ConstantEnergyResolution; // constant - } - return res; + double res = -1e0; + double mom = momentum/CLHEP::GeV; + if ( this->StocasticEnergyResolution > 0 && + this->ConstantEnergyResolution > 0 && + this->NoiseEnergyResolution > 0 ) { + res = std::sqrt(std::pow( this->StocasticEnergyResolution / std::sqrt( mom ), 2 ) + // stochastic + std::pow( this->ConstantEnergyResolution, 2 ) + // constant + std::pow( this->NoiseEnergyResolution / mom, 2 ) ); // noise + } + else if ( this->StocasticEnergyResolution > 0 && + this->ConstantEnergyResolution > 0 ) { + res = std::sqrt(std::pow( this->StocasticEnergyResolution / std::sqrt( mom ), 2 ) + // stochastic + std::pow( this->ConstantEnergyResolution, 2 ) ); // constant + } + else if ( this->StocasticEnergyResolution > 0 ) { + res = this->StocasticEnergyResolution / std::sqrt( mom ); // stochastic + } + else if ( this->ConstantEnergyResolution > 0 ) { + res = this->ConstantEnergyResolution; // constant + } + return res; } double smearEnergy(double mom) const { - double resolution = this->resolution(mom); - double smeared = mom; - if ( resolution > 0e0 ) { - for( smeared = -1e0; smeared < 0e0; ) { // Ensure that the resulting value is not negative - smeared = mom * Geant4Random::instance()->gauss(1e0, resolution); - } - } - return smeared; + double resolution = this->resolution(mom); + double smeared = mom; + if ( resolution > 0e0 ) { + for( smeared = -1e0; smeared < 0e0; ) { // Ensure that the resulting value is not negative + smeared = mom * Geant4Random::instance()->gauss(1e0, resolution); + } + } + return smeared; } }; @@ -113,7 +113,7 @@ namespace dd4hep { // Consider only primary tracks and smear according to the parametrized resolution // ELSE: simply set the value of the (initial) energy of the particle is deposited in the step if ( !spot.primary->GetParentID() ) { - deposit = locals.smearEnergy(deposit); + deposit = locals.smearEnergy(deposit); } hit.SetEnergy(deposit); step.ProposeTotalEnergyDeposited(deposit); diff --git a/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp b/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp index e4f870f54..b81de1075 100644 --- a/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp +++ b/DDG4/plugins/Geant4DetectorGeometryConstruction.cpp @@ -126,13 +126,11 @@ namespace dd4hep { #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; DECLARE_GEANT4ACTION(Geant4DetectorGeometryConstruction) /// Initializing constructor for other clients -Geant4DetectorGeometryConstruction::Geant4DetectorGeometryConstruction(Geant4Context* ctxt, const string& nam) +Geant4DetectorGeometryConstruction::Geant4DetectorGeometryConstruction(Geant4Context* ctxt, const std::string& nam) : Geant4DetectorConstruction(ctxt,nam) { declareProperty("DebugMaterials", m_debugMaterials); @@ -194,9 +192,9 @@ void Geant4DetectorGeometryConstruction::constructGeo(Geant4DetectorConstruction enableUI(); } -pair +std::pair Geant4DetectorGeometryConstruction::resolve_path(const char* vol_path) const { - string p = vol_path; + std::string p = vol_path; Detector& det = context()->kernel().detectorDescription(); PlacedVolume top = det.world().placement(); PlacedVolume pv = detail::tools::findNode(top, p); @@ -217,19 +215,19 @@ int Geant4DetectorGeometryConstruction::printMaterial(const char* mat_name) { for ( auto it = g4map.begin(); it != g4map.end(); ++it ) { const auto* mat = (*it).second; if ( mat->GetName() == mat_name ) { - stringstream output; + std::stringstream output; const auto* ion = mat->GetIonisation(); printP2("+++ Dump of GEANT4 material: %s", mat_name); output << mat; if ( ion ) { output << " MEE: "; - output << setprecision(12); + output << std::setprecision(12); output << ion->GetMeanExcitationEnergy()/CLHEP::eV; output << " [eV]"; } else output << " MEE: UNKNOWN"; - always("+++ printMaterial: \n%s\n", output.str().c_str()); + always("+++ printMaterial: \n%s\n", output.str().c_str()); return 1; } } @@ -254,51 +252,51 @@ int Geant4DetectorGeometryConstruction::printVolumeObj(const char* vol_path, Pla const auto* ion = mat->GetIonisation(); Solid sh = pv.volume().solid(); if ( flg ) { - printP2("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - printP2("+++ Dump of GEANT4 solid: %s", vol_path); + printP2("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + printP2("+++ Dump of GEANT4 solid: %s", vol_path); } - stringstream output; + std::stringstream output; if ( flg ) { - output << mat; - if ( ion ) { - output << " MEE: "; - output << setprecision(12); - output << ion->GetMeanExcitationEnergy()/CLHEP::eV; - output << " [eV]"; - } - else - output << " MEE: UNKNOWN"; + output << mat; + if ( ion ) { + output << " MEE: "; + output << std::setprecision(12); + output << ion->GetMeanExcitationEnergy()/CLHEP::eV; + output << " [eV]"; + } + else + output << " MEE: UNKNOWN"; } if ( flg ) { - output << endl << *sol; - printP2("%s", output.str().c_str()); - printP2("+++ Dump of ROOT solid: %s", vol_path); - sh->InspectShape(); - if ( sh->IsA() == TGeoScaledShape::Class() ) { - TGeoScaledShape* scaled = (TGeoScaledShape*)sh.ptr(); - const Double_t* scale = scaled->GetScale()->GetScale(); - double dot = scale[0]*scale[1]*scale[2]; - printP2("+++ TGeoScaledShape: %8.3g %8.3g %8.3g [%s]", scale[0], scale[1], scale[2], - dot > 0e0 ? "RIGHT handed" : "LEFT handed"); - } - else if ( pit != g4map.g4Placements.end() ) { - const G4VPhysicalVolume* pl = (*pit).second; - const G4RotationMatrix* rot = pl->GetRotation(); - const G4ThreeVector& tr = pl->GetTranslation(); - G4Transform3D transform(rot ? *rot : G4RotationMatrix(), tr); - HepGeom::Scale3D sc; - HepGeom::Rotate3D rr; - G4Translate3D tt; - transform.getDecomposition(sc,rr,tt); - double dot = sc(0,0)*sc(1,1)*sc(2,2); - printP2("+++ TGeoShape: %8.3g %8.3g %8.3g [%s]", sc(0,0), sc(1,1), sc(2,2), - dot > 0e0 ? "RIGHT handed" : "LEFT handed"); - } - const TGeoMatrix* matrix = pv->GetMatrix(); - printP2("+++ TGeoMatrix: %s", - matrix->TestBit(TGeoMatrix::kGeoReflection) ? "LEFT handed" : "RIGHT handed"); - printP2("+++ Shape: %s cubic volume: %8.3g mm^3 area: %8.3g mm^2", - sol->GetName().c_str(), sol->GetCubicVolume(), sol->GetSurfaceArea()); + output << std::endl << *sol; + printP2("%s", output.str().c_str()); + printP2("+++ Dump of ROOT solid: %s", vol_path); + sh->InspectShape(); + if ( sh->IsA() == TGeoScaledShape::Class() ) { + TGeoScaledShape* scaled = (TGeoScaledShape*)sh.ptr(); + const Double_t* scale = scaled->GetScale()->GetScale(); + double dot = scale[0]*scale[1]*scale[2]; + printP2("+++ TGeoScaledShape: %8.3g %8.3g %8.3g [%s]", scale[0], scale[1], scale[2], + dot > 0e0 ? "RIGHT handed" : "LEFT handed"); + } + else if ( pit != g4map.g4Placements.end() ) { + const G4VPhysicalVolume* pl = (*pit).second; + const G4RotationMatrix* rot = pl->GetRotation(); + const G4ThreeVector& tr = pl->GetTranslation(); + G4Transform3D transform(rot ? *rot : G4RotationMatrix(), tr); + HepGeom::Scale3D sc; + HepGeom::Rotate3D rr; + G4Translate3D tt; + transform.getDecomposition(sc,rr,tt); + double dot = sc(0,0)*sc(1,1)*sc(2,2); + printP2("+++ TGeoShape: %8.3g %8.3g %8.3g [%s]", sc(0,0), sc(1,1), sc(2,2), + dot > 0e0 ? "RIGHT handed" : "LEFT handed"); + } + const TGeoMatrix* matrix = pv->GetMatrix(); + printP2("+++ TGeoMatrix: %s", + matrix->TestBit(TGeoMatrix::kGeoReflection) ? "LEFT handed" : "RIGHT handed"); + printP2("+++ Shape: %s cubic volume: %8.3g mm^3 area: %8.3g mm^2", + sol->GetName().c_str(), sol->GetCubicVolume(), sol->GetSurfaceArea()); } return 1; } @@ -309,7 +307,7 @@ int Geant4DetectorGeometryConstruction::printVolumeObj(const char* vol_path, Pla warning("+++ printVolume: volume %s is an assembly...need to resolve imprint",vol_path); for(Int_t i=0; i < v->GetNdaughters(); ++i) { TGeoNode* dau_nod = v->GetNode(i); - string p = vol_path + string("/") + dau_nod->GetName(); + std::string p = vol_path + std::string("/") + dau_nod->GetName(); printVolumeObj(p.c_str(), dau_nod, flg); } return 0; @@ -340,13 +338,13 @@ int Geant4DetectorGeometryConstruction::printVolumeTree(const char* vol_path) { auto [p, pv] = resolve_path(vol_path); if ( pv.isValid() ) { if ( printVolumeObj(p.c_str(), pv, ~0x0) ) { - TGeoVolume* vol = pv->GetVolume(); - for(Int_t i=0; i < vol->GetNdaughters(); ++i) { - PlacedVolume dau_pv(vol->GetNode(i)); - string path = (p + "/") + dau_pv.name(); - if ( printVolumeTree(path.c_str()) ) { - } - } + TGeoVolume* vol = pv->GetVolume(); + for(Int_t i=0; i < vol->GetNdaughters(); ++i) { + PlacedVolume dau_pv(vol->GetNode(i)); + std::string path = (p + "/") + dau_pv.name(); + if ( printVolumeTree(path.c_str()) ) { + } + } } return 1; } @@ -360,13 +358,13 @@ int Geant4DetectorGeometryConstruction::printVolTree(const char* vol_path) { auto [p, pv] = resolve_path(vol_path); if ( pv.isValid() ) { if ( printVolumeObj(p.c_str(), pv, 0) ) { - TGeoVolume* vol = pv->GetVolume(); - for(Int_t i=0; i < vol->GetNdaughters(); ++i) { - PlacedVolume dau_pv(vol->GetNode(i)); - string path = (p + "/") + dau_pv.name(); - if ( printVolTree(path.c_str()) ) { - } - } + TGeoVolume* vol = pv->GetVolume(); + for(Int_t i=0; i < vol->GetNdaughters(); ++i) { + PlacedVolume dau_pv(vol->GetNode(i)); + std::string path = (p + "/") + dau_pv.name(); + if ( printVolTree(path.c_str()) ) { + } + } } return 1; } @@ -437,8 +435,8 @@ int Geant4DetectorGeometryConstruction::writeGDML(const char* output) { return 0; } -void Geant4DetectorGeometryConstruction::printG4(const string& prefix, const G4VPhysicalVolume* g4pv) const { - string path = prefix + "/"; +void Geant4DetectorGeometryConstruction::printG4(const std::string& prefix, const G4VPhysicalVolume* g4pv) const { + std::string path = prefix + "/"; printP2( "+++ GEANT4 volume: %s", prefix.c_str()); auto* g4v = g4pv->GetLogicalVolume(); for(size_t i=0, n=g4v->GetNoDaughters(); i /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -46,31 +46,29 @@ namespace dd4hep { // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DD4hep/Printout.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Detector.h" +#include +#include +#include +#include -#include "DDG4/Geant4Mapping.h" -#include "DDG4/Geant4Kernel.h" -#include "DDG4/Factories.h" +#include +#include +#include // ROOT include files -#include "TGeoManager.h" +#include // Geant4 include files -#include "G4SDManager.hh" -#include "G4PVPlacement.hh" -#include "G4VSensitiveDetector.hh" +#include +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; DECLARE_GEANT4ACTION(Geant4DetectorSensitivesConstruction) /// Initializing constructor for other clients -Geant4DetectorSensitivesConstruction::Geant4DetectorSensitivesConstruction(Geant4Context* ctxt, const string& nam) - : Geant4DetectorConstruction(ctxt,nam) +Geant4DetectorSensitivesConstruction::Geant4DetectorSensitivesConstruction(Geant4Context* ctxt, const std::string& nam) +: Geant4DetectorConstruction(ctxt,nam) { InstanceCount::increment(this); } @@ -84,13 +82,13 @@ Geant4DetectorSensitivesConstruction::~Geant4DetectorSensitivesConstruction() { void Geant4DetectorSensitivesConstruction::constructSensitives(Geant4DetectorConstructionContext* ctxt) { Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); const Geant4Kernel& kernel = context()->kernel(); - const auto& types = kernel.sensitiveDetectorTypes(); - const string& dflt = kernel.defaultSensitiveDetectorType(); - for(const auto& iv : p->sensitives ) { + const auto& types = kernel.sensitiveDetectorTypes(); + const std::string& dflt = kernel.defaultSensitiveDetectorType(); + for( const auto& iv : p->sensitives ) { SensitiveDetector sd = iv.first; - string nam = sd.name(); - auto iter = types.find(nam); - string typ = (iter != types.end()) ? (*iter).second : dflt; + std::string nam = sd.name(); + auto iter = types.find(nam); + std::string typ = (iter != types.end()) ? (*iter).second : dflt; G4VSensitiveDetector* g4sd = PluginService::Create(typ, nam, &ctxt->description); if (g4sd) { @@ -101,9 +99,9 @@ void Geant4DetectorSensitivesConstruction::constructSensitives(Geant4DetectorCon PluginDebug dbg; g4sd = PluginService::Create(typ, nam, &ctxt->description); if ( !g4sd ) { - throw runtime_error("ConstructSDandField: FATAL Failed to " - "create Geant4 sensitive detector " + nam + - " (" + sd.type() + ") of type " + typ + "."); + throw std::runtime_error("ConstructSDandField: FATAL Failed to " + "create Geant4 sensitive detector " + nam + + " (" + sd.type() + ") of type " + typ + "."); } print("Geant4SDConstruction", "+++ Subdetector: %-32s type: %-16s factory: %s.", nam.c_str(), sd.type().c_str(), typ.c_str()); @@ -113,8 +111,8 @@ void Geant4DetectorSensitivesConstruction::constructSensitives(Geant4DetectorCon for(const TGeoVolume* vol : iv.second ) { G4LogicalVolume* g4v = p->g4Volumes[vol]; if ( !g4v ) { - throw runtime_error("ConstructSDandField: Failed to access G4LogicalVolume for SD "+ - nam + " of type " + typ + "."); + throw std::runtime_error("ConstructSDandField: Failed to access G4LogicalVolume for SD "+ + nam + " of type " + typ + "."); } ctxt->setSensitiveDetector(g4v,g4sd); } diff --git a/DDG4/plugins/Geant4EscapeCounter.cpp b/DDG4/plugins/Geant4EscapeCounter.cpp index 13b573ac1..283c5c7a0 100644 --- a/DDG4/plugins/Geant4EscapeCounter.cpp +++ b/DDG4/plugins/Geant4EscapeCounter.cpp @@ -14,9 +14,9 @@ #define DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H // Framework include files -#include "DD4hep/DetElement.h" -#include "DDG4/Geant4SensDetAction.h" -#include "DDG4/Geant4SteppingAction.h" +#include +#include +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -63,27 +63,26 @@ namespace dd4hep { // Author : M.Frank // //==================================================================== -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" +// Framework include files +#include +#include -#include "DDG4/Geant4TouchableHandler.h" -#include "DDG4/Geant4TrackHandler.h" -#include "DDG4/Geant4StepHandler.h" -#include "DDG4/Geant4Mapping.h" -#include "DDG4/Geant4Data.h" +#include +#include +#include +#include +#include -#include "CLHEP/Units/SystemOfUnits.h" -#include "G4VProcess.hh" +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor -Geant4EscapeCounter::Geant4EscapeCounter(Geant4Context* ctxt, const string& nam, DetElement det, Detector& description_ref) +Geant4EscapeCounter::Geant4EscapeCounter(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& description_ref) : Geant4Sensitive(ctxt, nam, det, description_ref) { - string coll_name = name()+"Hits"; + std::string coll_name = name()+"Hits"; m_needsControl = true; declareProperty("Shells",m_detectorNames); m_collectionID = defineCollection(coll_name); @@ -100,7 +99,7 @@ bool Geant4EscapeCounter::process(const G4Step* step, G4TouchableHistory* /* his Geant4StepHandler h(step); Geant4TrackHandler th(h.track); Geant4TouchableHandler handler(step); - string hdlr_path = handler.path(); + std::string hdlr_path = handler.path(); Position prePos = h.prePos(); Position postPos = h.postPos(); Geant4HitCollection* coll = collection(m_collectionID); @@ -132,6 +131,6 @@ bool Geant4EscapeCounter::process(const G4Step* step, G4TouchableHistory* /* his return true; } -#include "DDG4/Factories.h" +#include DECLARE_GEANT4SENSITIVE(Geant4EscapeCounter) diff --git a/DDG4/plugins/Geant4EventReaderGuineaPig.cpp b/DDG4/plugins/Geant4EventReaderGuineaPig.cpp index f8ba18c53..548725d20 100644 --- a/DDG4/plugins/Geant4EventReaderGuineaPig.cpp +++ b/DDG4/plugins/Geant4EventReaderGuineaPig.cpp @@ -14,16 +14,16 @@ /** \addtogroup Geant4EventReader * @{ - \package Geant4EventReaderGuineaPig + \package Geant4EventReaderGuineaPig * \brief Reader for ascii files with e+e- pairs created from GuineaPig. * * -@} - */ + @} +*/ // Framework include files -#include "DDG4/Geant4InputAction.h" +#include // C/C++ include files #include @@ -71,15 +71,14 @@ namespace dd4hep { // Framework include files -#include "DDG4/Factories.h" -#include "DD4hep/Printout.h" -#include "CLHEP/Units/SystemOfUnits.h" -#include "CLHEP/Units/PhysicalConstants.h" +#include +#include +#include +#include // C/C++ include files #include -using namespace std; using namespace dd4hep::sim; typedef dd4hep::detail::ReferenceBitMask PropertyMask; @@ -87,15 +86,15 @@ typedef dd4hep::detail::ReferenceBitMask PropertyMask; DECLARE_GEANT4_EVENT_READER(Geant4EventReaderGuineaPig) /// Initializing constructor -Geant4EventReaderGuineaPig::Geant4EventReaderGuineaPig(const string& nam) +Geant4EventReaderGuineaPig::Geant4EventReaderGuineaPig(const std::string& nam) : Geant4EventReader(nam), m_input(), m_part_num(-1) { // Now open the input file: - m_input.open(nam.c_str(),ifstream::in); + m_input.open(nam.c_str(), std::ifstream::in); if ( !m_input.good() ) { - string err = "+++ Geant4EventReaderGuineaPig: Failed to open input stream:"+nam+ - " Error:"+string(strerror(errno)); - throw runtime_error(err); + std::string err = "+++ Geant4EventReaderGuineaPig: Failed to open input stream:"+nam+ + " Error:"+std::string(strerror(errno)); + throw std::runtime_error(err); } } @@ -145,7 +144,7 @@ Geant4EventReaderGuineaPig::moveToEvent(int event_number) { } for (unsigned i = 0; i::max(), m_input.widen('\n'))){ + if (m_input.ignore(std::numeric_limits::max(), m_input.widen('\n'))){ //just skipping the line } else @@ -162,15 +161,13 @@ Geant4EventReaderGuineaPig::moveToEvent(int event_number) { Geant4EventReader::EventReaderStatus Geant4EventReaderGuineaPig::readParticles(int /* event_number */, Vertices& vertices, - vector& particles) { + std::vector& particles) { // if no number of particles per event set, we will read the whole file if ( m_part_num < 0 ) m_part_num = std::numeric_limits::max() ; - - // First check the input file status if ( m_input.eof() ) { return EVENT_READER_EOF; @@ -212,8 +209,8 @@ Geant4EventReaderGuineaPig::readParticles(int /* event_number */, std::stringstream m_input_str( lineStr ) ; m_input_str >> Energy - >> betaX >> betaY >> betaZ - >> posX >> posY >> posZ ; + >> betaX >> betaY >> betaZ + >> posX >> posY >> posZ ; // printf(" ------- %e %e %e %e %e %e %e \n", Energy,betaX, betaY,betaZ,posX,posY,posZ ) ; diff --git a/DDG4/plugins/Geant4EventReaderHepEvt.cpp b/DDG4/plugins/Geant4EventReaderHepEvt.cpp index f1fc11701..0a821a671 100644 --- a/DDG4/plugins/Geant4EventReaderHepEvt.cpp +++ b/DDG4/plugins/Geant4EventReaderHepEvt.cpp @@ -88,9 +88,8 @@ namespace dd4hep { // C/C++ include files #include -using namespace std; using namespace dd4hep::sim; -typedef dd4hep::detail::ReferenceBitMask PropertyMask; +using PropertyMask = dd4hep::detail::ReferenceBitMask; #define HEPEvtShort 1 #define HEPEvtLong 2 @@ -100,14 +99,14 @@ namespace { class Geant4EventReaderHepEvtShort : public Geant4EventReaderHepEvt { public: /// Initializing constructor - explicit Geant4EventReaderHepEvtShort(const string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtShort) {} + explicit Geant4EventReaderHepEvtShort(const std::string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtShort) {} /// Default destructor virtual ~Geant4EventReaderHepEvtShort() {} }; class Geant4EventReaderHepEvtLong : public Geant4EventReaderHepEvt { public: /// Initializing constructor - explicit Geant4EventReaderHepEvtLong(const string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtLong) {} + explicit Geant4EventReaderHepEvtLong(const std::string& nam) : Geant4EventReaderHepEvt(nam,HEPEvtLong) {} /// Default destructor virtual ~Geant4EventReaderHepEvtLong() {} }; @@ -120,15 +119,14 @@ DECLARE_GEANT4_EVENT_READER(Geant4EventReaderHepEvtLong) /// Initializing constructor -Geant4EventReaderHepEvt::Geant4EventReaderHepEvt(const string& nam, int format) +Geant4EventReaderHepEvt::Geant4EventReaderHepEvt(const std::string& nam, int format) : Geant4EventReader(nam), m_input(), m_format(format) { // Now open the input file: - m_input.open(nam.c_str(),ifstream::in); + m_input.open(nam.c_str(), std::ifstream::in); if ( !m_input.good() ) { - string err = "+++ Geant4EventReaderHepEvt: Failed to open input stream:"+nam+ - " Error:"+string(strerror(errno)); - throw runtime_error(err); + except("Geant4EventReaderHepEvt","+++ Failed to open input stream: %s Error:%s", + nam.c_str(), ::strerror(errno)); } } @@ -147,8 +145,8 @@ Geant4EventReaderHepEvt::moveToEvent(int event_number) { std::vector particles; Vertices vertices ; EventReaderStatus sc = readParticles(m_currEvent,vertices,particles); - for_each(vertices.begin(),vertices.end(),detail::deleteObject); - for_each(particles.begin(),particles.end(),detail::deleteObject); + for_each(vertices.begin(), vertices.end(), detail::deleteObject); + for_each(particles.begin(), particles.end(), detail::deleteObject); if ( sc != EVENT_READER_OK ) return sc; //Current event is increased in readParticles already! // ++m_currEvent; @@ -162,7 +160,7 @@ Geant4EventReaderHepEvt::moveToEvent(int event_number) { Geant4EventReader::EventReaderStatus Geant4EventReaderHepEvt::readParticles(int /* event_number */, Vertices& vertices, - vector& particles) { + std::vector& particles) { // First check the input file status @@ -208,8 +206,8 @@ Geant4EventReaderHepEvt::readParticles(int /* event_number */, double VHEP3(0); // z vertex position in mm double VHEP4(0); // production time in mm/c - vector daughter1; - vector daughter2; + std::vector daughter1; + std::vector daughter2; for( unsigned IHEP=0; IHEPparents.size() == 0 ) { Geant4Vertex* vtx = new Geant4Vertex ; diff --git a/DDG4/plugins/Geant4EventReaderHepMC.cpp b/DDG4/plugins/Geant4EventReaderHepMC.cpp index 83ee40ac7..e075df755 100644 --- a/DDG4/plugins/Geant4EventReaderHepMC.cpp +++ b/DDG4/plugins/Geant4EventReaderHepMC.cpp @@ -93,9 +93,8 @@ namespace dd4hep { #include #include -using namespace std; using namespace dd4hep::sim; -typedef dd4hep::detail::ReferenceBitMask PropertyMask; +using PropertyMask = dd4hep::detail::ReferenceBitMask; // Factory entry DECLARE_GEANT4_EVENT_READER(Geant4EventReaderHepMC) @@ -126,8 +125,8 @@ namespace dd4hep { float scale; float alpha_qcd; float alpha_qed; - vector weights; - vector random; + std::vector weights; + std::vector random; /// Default constructor EventHeader() : id(0), num_vertices(0), bp1(0), bp2(0), signal_process_id(0), signal_process_vertex(0), @@ -149,10 +148,10 @@ namespace dd4hep { typedef std::map Vertices; typedef std::map Particles; - istream& instream; + std::istream& instream; // io information - string key; + std::string key; double mom_unit, pos_unit; int io_type; @@ -162,7 +161,7 @@ namespace dd4hep { Particles m_particles; /// Default constructor - EventStream(istream& in) : instream(in), mom_unit(0.0), pos_unit(0.0), + EventStream(std::istream& in) : instream(in), mom_unit(0.0), pos_unit(0.0), io_type(0), xsection(0.0), xsection_err(0.0) { use_default_units(); } /// Check if data stream is in proper state and has data @@ -170,7 +169,7 @@ namespace dd4hep { Geant4Vertex* vertex(int i); Particles& particles() { return m_particles; } Vertices& vertices() { return m_vertices; } - void set_io(int typ, const string& k) + void set_io(int typ, const std::string& k) { io_type = typ; key = k; } void use_default_units() { mom_unit = CLHEP::MeV; pos_unit = CLHEP::mm; } @@ -178,16 +177,16 @@ namespace dd4hep { void clear(); }; - char get_input(istream& is, istringstream& iline); - int read_until_event_end(istream & is); - int read_weight_names(EventStream &, istringstream& iline); - int read_particle(EventStream &info, istringstream& iline, Geant4Particle * p); - int read_vertex(EventStream &info, istream& is, istringstream & iline); - int read_event_header(EventStream &info, istringstream & input, EventHeader& header); - int read_cross_section(EventStream &info, istringstream & input); - int read_units(EventStream &info, istringstream & input); - int read_heavy_ion(EventStream &, istringstream & input); - int read_pdf(EventStream &, istringstream & input); + char get_input(std::istream& is, std::istringstream& iline); + int read_until_event_end(std::istream & is); + int read_weight_names(EventStream &, std::istringstream& iline); + int read_particle(EventStream &info, std::istringstream& iline, Geant4Particle * p); + int read_vertex(EventStream &info, std::istream& is, std::istringstream & iline); + int read_event_header(EventStream &info, std::istringstream & input, EventHeader& header); + int read_cross_section(EventStream &info, std::istringstream & input); + int read_units(EventStream &info, std::istringstream & input); + int read_heavy_ion(EventStream &, std::istringstream & input); + int read_pdf(EventStream &, std::istringstream & input); Geant4Vertex* vertex(EventStream& info, int i); void fix_particles(EventStream &info); } @@ -199,14 +198,13 @@ namespace dd4hep { //#define DD4HEP_DEBUG_HEP_MC_PARTICLE 418 /// Initializing constructor -Geant4EventReaderHepMC::Geant4EventReaderHepMC(const string& nam) +Geant4EventReaderHepMC::Geant4EventReaderHepMC(const std::string& nam) : Geant4EventReader(nam), m_input(), m_events(0) { // Now open the input file: - m_input.open(nam.c_str(),BOOST_IOS::in|BOOST_IOS::binary); + m_input.open(nam.c_str(), BOOST_IOS::in|BOOST_IOS::binary); if ( not m_input.is_open() ) { - except("Geant4EventReaderHepMC","+++ Failed to open input stream: %s Error:%s.", - nam.c_str(), ::strerror(errno)); + except("+++ Failed to open input stream: %s Error:%s.", nam.c_str(), ::strerror(errno)); } m_events = new HepMC::EventStream(m_input); } @@ -260,7 +258,7 @@ Geant4EventReaderHepMC::readParticles(int /* ev_id */, output.reserve(parts.size()); transform(parts.begin(),parts.end(),back_inserter(output),detail::reference2nd(parts)); m_events->clear(); - if (pos.mag2() > numeric_limits::epsilon() ) { + if (pos.mag2() > std::numeric_limits::epsilon() ) { for(Particles::iterator k=output.begin(); k != output.end(); ++k) { Geant4ParticleHandle p(*k); p->vsx += pos.x(); @@ -311,7 +309,7 @@ void HepMC::fix_particles(EventStream& info) { Geant4Vertex* v = vertex(info,end_vtx_id); #if defined(DD4HEP_DEBUG_HEP_MC_VERTEX) if ( end_vtx_id == DD4HEP_DEBUG_HEP_MC_VERTEX ) { - cout << "End-vertex:" << end_vtx_id << endl; + std::cout << "End-vertex:" << end_vtx_id << std::endl; } #endif if ( v ) { @@ -323,7 +321,7 @@ void HepMC::fix_particles(EventStream& info) { EventStream::Particles::iterator ipp = parts.find(*id); Geant4Particle* dau = ipp != parts.end() ? (*ipp).second : 0; if ( !dau ) - cout << "ERROR: Invalid daughter particle: " << *id << endl; + std::cout << "ERROR: Invalid daughter particle: " << *id << std::endl; else dau->parents.insert(p->id); p->daughters.insert(*id); @@ -342,7 +340,7 @@ void HepMC::fix_particles(EventStream& info) { } /// Particles originating from the beam (=no parents) must be /// be stripped off their parents and the status set to G4PARTICLE_GEN_DECAYED! - vector beam; + std::vector beam; for(const auto& ipart : parts) { Geant4ParticleHandle p(ipart.second); if ( p->parents.size() == 0 ) { @@ -353,7 +351,7 @@ void HepMC::fix_particles(EventStream& info) { } } for(auto* ipp : beam) { - //cout << "Clear parents of " << (*ipp)->id << endl; + //std::cout << "Clear parents of " << (*ipp)->id << std::endl; ipp->parents.clear(); ipp->status = G4PARTICLE_GEN_DECAYED; } @@ -364,18 +362,18 @@ Geant4Vertex* HepMC::vertex(EventStream& info, int i) { return (it==info.vertices().end()) ? 0 : (*it).second; } -char HepMC::get_input(istream& is, istringstream& iline) { +char HepMC::get_input(std::istream& is, std::istringstream& iline) { char value = is.peek(); if ( !is ) { // make sure the stream is valid - cerr << "StreamHelpers: setting badbit." << endl; - is.clear(ios::badbit); + std::cerr << "StreamHelpers: setting badbit." << std::endl; + is.clear(std::ios::badbit); return -1; } - string line, firstc; + std::string line, firstc; getline(is,line); if ( !is ) { // make sure the stream is valid - cerr << "StreamHelpers: setting badbit." << endl; - is.clear(ios::badbit); + std::cerr << "StreamHelpers: setting badbit." << std::endl; + is.clear(std::ios::badbit); return -1; } iline.clear(); @@ -384,8 +382,8 @@ char HepMC::get_input(istream& is, istringstream& iline) { return iline ? value : -1; } -int HepMC::read_until_event_end(istream & is) { - string line; +int HepMC::read_until_event_end(std::istream & is) { + std::string line; while ( is ) { char val = is.peek(); if( val == 'E' ) { // next event @@ -397,23 +395,23 @@ int HepMC::read_until_event_end(istream & is) { return 0; } -int HepMC::read_weight_names(EventStream&, istringstream&) { +int HepMC::read_weight_names(EventStream&, std::istringstream&) { #if 0 - int HepMC::read_weight_names(EventStream& info, istringstream& iline) + int HepMC::read_weight_names(EventStream& info, std::istringstream& iline) size_t name_size = 0; iline >> name_size; info.weights.names.clear(); info.weights.weights.clear(); - string name; + std::string name; WeightContainer namedWeight; - string::size_type i1 = line.find("\""), i2, len = line.size(); + std::string::size_type i1 = line.find("\""), i2, len = line.size(); for(size_t ii = 0; ii < name_size; ++ii) { // weight names may contain blanks if(i1 >= len) { - cout << "debug: attempting to read past the end of the named weight line " << endl; - cout << "debug: We should never get here" << endl; - cout << "debug: Looking for the end of this event" << endl; + std::cout << "debug: attempting to read past the end of the named weight line " << std::endl; + std::cout << "debug: We should never get here" << std::endl; + std::cout << "debug: Looking for the end of this event" << std::endl; read_until_event_end(is); } i2 = line.find("\"",i1+1); @@ -430,7 +428,7 @@ int HepMC::read_weight_names(EventStream&, istringstream&) { return 1; } -int HepMC::read_particle(EventStream &info, istringstream& input, Geant4Particle * p) { +int HepMC::read_particle(EventStream &info, std::istringstream& input, Geant4Particle * p) { float ene = 0., theta = 0., phi = 0; int size = 0, stat=0; PropertyMask status(p->status); @@ -440,7 +438,7 @@ int HepMC::read_particle(EventStream &info, istringstream& input, Geant4Particle p->id = info.particles().size(); #if defined(DD4HEP_DEBUG_HEP_MC_PARTICLE) if ( p->id == DD4HEP_DEBUG_HEP_MC_PARTICLE ) { - cout << "Particle id: " << p->id << endl; + std::cout << "Particle id: " << p->id << std::endl; } #endif p->charge = 0; @@ -481,7 +479,7 @@ int HepMC::read_particle(EventStream &info, istringstream& input, Geant4Particle p->genStatus = stat&G4PARTICLE_GEN_STATUS_MASK; // read flow patterns if any exist. Protect against tainted readings. - size = min(size,100); + size = std::min(size,100); for (int i = 0; i < size; ++i ) { input >> p->colorFlow[0] >> p->colorFlow[1]; if(!input) return 0; @@ -489,9 +487,9 @@ int HepMC::read_particle(EventStream &info, istringstream& input, Geant4Particle return 1; } -int HepMC::read_vertex(EventStream &info, istream& is, istringstream & input) { +int HepMC::read_vertex(EventStream &info, std::istream& is, std::istringstream & input) { int id=0, dummy = 0, num_orphans_in=0, num_particles_out=0, weights_size=0; - vector weights; + std::vector weights; Geant4Vertex* v = new Geant4Vertex(); Geant4Particle* p; @@ -561,13 +559,13 @@ int HepMC::read_vertex(EventStream &info, istream& is, istringstream & input) } else { delete p; - throw runtime_error("Invalid number of particles...."); + except("HepMC", "Invalid number of particles...."); } } return 1; } -int HepMC::read_event_header(EventStream &info, istringstream & input, EventHeader& header) { +int HepMC::read_event_header(EventStream &info, std::istringstream & input, EventHeader& header) { // read values into temp variables, then fill GenEvent int random_states_size = 0; input >> header.id; @@ -599,7 +597,7 @@ int HepMC::read_event_header(EventStream &info, istringstream & input, EventHead input >> weights_size; if( input.fail() ) return 0; - vector wgt(weights_size); + std::vector wgt(weights_size); for(size_t ii = 0; ii < weights_size; ++ii ) input >> wgt[ii]; if( input.fail() ) return 0; @@ -609,14 +607,14 @@ int HepMC::read_event_header(EventStream &info, istringstream & input, EventHead return 1; } -int HepMC::read_cross_section(EventStream &info, istringstream & input) { +int HepMC::read_cross_section(EventStream &info, std::istringstream & input) { input >> info.xsection >> info.xsection_err; return input.fail() ? 0 : 1; } -int HepMC::read_units(EventStream &info, istringstream & input) { +int HepMC::read_units(EventStream &info, std::istringstream & input) { if( info.io_type == gen ) { - string mom, pos; + std::string mom, pos; input >> mom >> pos; if ( !input.fail() ) { if ( mom == "KEV" ) info.mom_unit = CLHEP::keV; @@ -632,7 +630,7 @@ int HepMC::read_units(EventStream &info, istringstream & input) { return input.fail() ? 0 : 1; } -int HepMC::read_heavy_ion(EventStream &, istringstream & input) { +int HepMC::read_heavy_ion(EventStream &, std::istringstream & input) { // read values into temp variables, then create a new HeavyIon object int nh =0, np =0, nt =0, nc =0, neut = 0, prot = 0, nw =0, nwn =0, nwnw =0; @@ -640,7 +638,7 @@ int HepMC::read_heavy_ion(EventStream &, istringstream & input) { input >> nh >> np >> nt >> nc >> neut >> prot >> nw >> nwn >> nwnw; input >> impact >> plane >> xcen >> inel; /* - cerr << "Reading heavy ion, but igoring data!" << endl; + std::cerr << "Reading heavy ion, but igoring data!" << std::endl; ion->set_Ncoll_hard(nh); ion->set_Npart_proj(np); ion->set_Npart_targ(nt); @@ -658,7 +656,7 @@ int HepMC::read_heavy_ion(EventStream &, istringstream & input) { return input.fail() ? 0 : 1; } -int HepMC::read_pdf(EventStream &, istringstream & input) { +int HepMC::read_pdf(EventStream &, std::istringstream & input) { // read values into temp variables, then create a new PdfInfo object int id1 =0, id2 =0; double x1 = 0., x2 = 0., scale = 0., pdf1 = 0., pdf2 = 0.; @@ -673,7 +671,7 @@ int HepMC::read_pdf(EventStream &, istringstream & input) { if ( input.fail() ) return 0; /* - cerr << "Reading pdf, but igoring data!" << endl; + std::cerr << "Reading pdf, but igoring data!" << std::endl; pdf->set_id1( id1 ); pdf->set_id2( id2 ); pdf->set_x1( x1 ); @@ -698,7 +696,7 @@ int HepMC::read_pdf(EventStream &, istringstream & input) { bool HepMC::EventStream::ok() const { // make sure the stream is good if ( instream.eof() || instream.fail() ) { - instream.clear(ios::badbit); + instream.clear(std::ios::badbit); return false; } return true; @@ -721,7 +719,7 @@ bool HepMC::EventStream::read() { ++num_evt; while( instream.good() ) { char value = instream.peek(); - istringstream input_line; + std::istringstream input_line; ++num_line; if ( value == 'E' && event_read ) break; @@ -743,7 +741,7 @@ bool HepMC::EventStream::read() { switch( value ) { case 'H': { int iotype = 0; - string key_value; + std::string key_value; input_line >> key_value; // search for event listing key before first event only. key_value = key_value.substr(0,key_value.find('\r')); @@ -773,9 +771,9 @@ bool HepMC::EventStream::read() { iotype = extascii_pdt; if( iotype != 0 && this->io_type != iotype ) { - cerr << "GenEvent::find_end_key: iotype keys have changed. " - << "MALFORMED INPUT" << endl; - instream.clear(ios::badbit); + std::cerr << "GenEvent::find_end_key: iotype keys have changed. " + << "MALFORMED INPUT" << std::endl; + instream.clear(std::ios::badbit); return false; } else if ( iotype != 0 ) { @@ -815,7 +813,7 @@ bool HepMC::EventStream::read() { continue; case 'P': // we should not find this line - cerr << "streaming input: found unexpected Particle line." << endl; + std::cerr << "streaming input: found unexpected Particle line." << std::endl; continue; default: // ignore everything else diff --git a/DDG4/plugins/Geant4FastPhysics.cpp b/DDG4/plugins/Geant4FastPhysics.cpp index 9e59a52e0..e083c5390 100644 --- a/DDG4/plugins/Geant4FastPhysics.cpp +++ b/DDG4/plugins/Geant4FastPhysics.cpp @@ -87,7 +87,6 @@ namespace dd4hep { // Geant4 include files #include -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor diff --git a/DDG4/plugins/Geant4FastSimShowerModel.cpp b/DDG4/plugins/Geant4FastSimShowerModel.cpp index d676f63bb..4c74063e5 100644 --- a/DDG4/plugins/Geant4FastSimShowerModel.cpp +++ b/DDG4/plugins/Geant4FastSimShowerModel.cpp @@ -14,8 +14,7 @@ // Framework include files #include -using namespace dd4hep; -using namespace dd4hep::sim; +using dd4hep::sim::Geant4FastSimShowerModel; #include DECLARE_GEANT4ACTION(Geant4FastSimShowerModel) diff --git a/DDG4/plugins/Geant4FieldTrackingSetup.cpp b/DDG4/plugins/Geant4FieldTrackingSetup.cpp index 0c153099a..b43a85bb1 100644 --- a/DDG4/plugins/Geant4FieldTrackingSetup.cpp +++ b/DDG4/plugins/Geant4FieldTrackingSetup.cpp @@ -147,28 +147,26 @@ namespace dd4hep { #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Local declaration in anonymous namespace namespace { struct Geant4SetupPropertyMap { - const map& vals; - Geant4SetupPropertyMap(const map& v) : vals(v) {} - string value(const string& key) const; - double toDouble(const string& key) const; - bool operator[](const string& key) const { return vals.find(key) != vals.end(); } + const std::map& vals; + Geant4SetupPropertyMap(const std::map& v) : vals(v) {} + std::string value(const std::string& key) const; + double toDouble(const std::string& key) const; + bool operator[](const std::string& key) const { return vals.find(key) != vals.end(); } }; - string Geant4SetupPropertyMap::value(const string& key) const { - Detector::PropertyValues::const_iterator iV = vals.find(key); + std::string Geant4SetupPropertyMap::value(const std::string& key) const { + dd4hep::Detector::PropertyValues::const_iterator iV = vals.find(key); return iV == vals.end() ? "" : (*iV).second; } - double Geant4SetupPropertyMap::toDouble(const string& key) const { - return _toDouble(this->value(key)); + double Geant4SetupPropertyMap::toDouble(const std::string& key) const { + return dd4hep::_toDouble(this->value(key)); } } @@ -238,14 +236,17 @@ int Geant4FieldTrackingSetup::execute(Detector& description) { return 1; } -static long setup_fields(Detector& description, const dd4hep::detail::GeoHandler& /* cnv */, const map& vals) { +static long setup_fields(dd4hep::Detector& description, + const dd4hep::detail::GeoHandler& /* cnv */, + const std::map& vals) +{ struct XMLFieldTrackingSetup : public Geant4FieldTrackingSetup { - XMLFieldTrackingSetup(const map& values) : Geant4FieldTrackingSetup() { + XMLFieldTrackingSetup(const std::map& values) : Geant4FieldTrackingSetup() { Geant4SetupPropertyMap pm(values); - Detector::PropertyValues::const_iterator iV = values.find("min_chord_step"); + dd4hep::Detector::PropertyValues::const_iterator iV = values.find("min_chord_step"); eq_typ = pm.value("equation"); stepper_typ = pm.value("stepper"); - min_chord_step = _toDouble((iV==values.end()) ? string("1e-2 * mm") : (*iV).second); + min_chord_step = dd4hep::_toDouble((iV==values.end()) ? std::string("1e-2 * mm") : (*iV).second); if ( pm["eps_min"] ) eps_min = pm.toDouble("eps_min"); if ( pm["eps_max"] ) eps_max = pm.toDouble("eps_max"); if ( pm["delta_chord"] ) delta_chord = pm.toDouble("delta_chord"); diff --git a/DDG4/plugins/Geant4GDMLWriteAction.cpp b/DDG4/plugins/Geant4GDMLWriteAction.cpp index 0696f24ce..69d2382d5 100644 --- a/DDG4/plugins/Geant4GDMLWriteAction.cpp +++ b/DDG4/plugins/Geant4GDMLWriteAction.cpp @@ -100,12 +100,10 @@ namespace dd4hep { #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor -Geant4GDMLWriteAction::Geant4GDMLWriteAction(Geant4Context* ctxt, const string& nam) +Geant4GDMLWriteAction::Geant4GDMLWriteAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = true; @@ -130,7 +128,7 @@ void Geant4GDMLWriteAction::installCommandMessenger() { /// Write geometry to GDML void Geant4GDMLWriteAction::writeGDML() { - string fname = m_output; + std::string fname = m_output; struct stat buff; if ( fname.empty() ) { error("+++ No GDML file name given. Please set the output file (property Output)"); @@ -148,7 +146,7 @@ void Geant4GDMLWriteAction::writeGDML() { #ifdef GEANT4_NO_GDML warning("+++ writeGDML: GDML not found in the present Geant4 build! Output: %s not written", fname.c_str()); #else - unique_ptr parser(new G4GDMLParser()); + std::unique_ptr parser(new G4GDMLParser()); parser->SetRegionExport(m_exportRegions != 0); parser->SetEnergyCutsExport(m_exportEnergyCuts != 0); #if G4VERSION_NUMBER>=1030 diff --git a/DDG4/plugins/Geant4GFlashShowerModel.cpp b/DDG4/plugins/Geant4GFlashShowerModel.cpp index 2ec874852..711be5109 100644 --- a/DDG4/plugins/Geant4GFlashShowerModel.cpp +++ b/DDG4/plugins/Geant4GFlashShowerModel.cpp @@ -123,7 +123,6 @@ namespace dd4hep { // C/C++ include files #include -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor diff --git a/DDG4/plugins/Geant4GeometryScanner.cpp b/DDG4/plugins/Geant4GeometryScanner.cpp index 717de5f80..48f1cdb24 100644 --- a/DDG4/plugins/Geant4GeometryScanner.cpp +++ b/DDG4/plugins/Geant4GeometryScanner.cpp @@ -96,7 +96,6 @@ namespace dd4hep { #include #include -using namespace std; using namespace dd4hep::sim; #include @@ -106,7 +105,7 @@ DECLARE_GEANT4ACTION(Geant4GeometryScanner) Geant4GeometryScanner::StepInfo::StepInfo(const Position& prePos, const Position& postPos, const G4LogicalVolume* vol, - const string& p) + const std::string& p) : pre(prePos), post(postPos), path(p), volume(vol) { } @@ -126,7 +125,7 @@ Geant4GeometryScanner::StepInfo& Geant4GeometryScanner::StepInfo::operator=(cons } /// Standard constructor -Geant4GeometryScanner::Geant4GeometryScanner(Geant4Context* ctxt, const string& nam) +Geant4GeometryScanner::Geant4GeometryScanner(Geant4Context* ctxt, const std::string& nam) : Geant4SteppingAction(ctxt,nam) { m_needsControl = true; diff --git a/DDG4/plugins/Geant4HitDumpAction.cpp b/DDG4/plugins/Geant4HitDumpAction.cpp index 507e710ce..4e2621275 100644 --- a/DDG4/plugins/Geant4HitDumpAction.cpp +++ b/DDG4/plugins/Geant4HitDumpAction.cpp @@ -83,12 +83,10 @@ namespace dd4hep { #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor -Geant4HitDumpAction::Geant4HitDumpAction(Geant4Context* ctxt, const string& nam) +Geant4HitDumpAction::Geant4HitDumpAction(Geant4Context* ctxt, const std::string& nam) : Geant4EventAction(ctxt, nam), m_containers{"*"} { m_needsControl = true; @@ -108,7 +106,7 @@ void Geant4HitDumpAction::begin(const G4Event* /* event */) { /// Dump single container of hits void Geant4HitDumpAction::dumpCollection(G4VHitsCollection* collection) { Geant4HitCollection* coll = dynamic_cast(collection); - string nam = collection->GetName(); + std::string nam = collection->GetName(); if ( coll ) { Geant4DataDump::CalorimeterHits cal_hits; Geant4DataDump::TrackerHits trk_hits; diff --git a/DDG4/plugins/Geant4HitExtractor.cpp b/DDG4/plugins/Geant4HitExtractor.cpp index 4bdb77376..2aa069f3b 100644 --- a/DDG4/plugins/Geant4HitExtractor.cpp +++ b/DDG4/plugins/Geant4HitExtractor.cpp @@ -14,7 +14,6 @@ // Framework include files #include "DDG4/Geant4Data.h" -using namespace dd4hep; using namespace dd4hep::sim; /// Namespace for the AIDA detector description toolkit diff --git a/DDG4/plugins/Geant4HitTruthHandler.cpp b/DDG4/plugins/Geant4HitTruthHandler.cpp index f7d51ddec..a246a296f 100644 --- a/DDG4/plugins/Geant4HitTruthHandler.cpp +++ b/DDG4/plugins/Geant4HitTruthHandler.cpp @@ -14,7 +14,7 @@ #define DD4HEP_DDG4_GEANT4HITTRUTHHANDLER_H // Framework include files -#include "DDG4/Geant4EventAction.h" +#include // Forward declarations class G4VHitsCollection; @@ -72,20 +72,18 @@ namespace dd4hep { //==================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4DataDump.h" -#include "DDG4/Geant4HitCollection.h" +#include +#include +#include // Geant 4 includes -#include "G4HCofThisEvent.hh" -#include "G4Event.hh" +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor -Geant4HitTruthHandler::Geant4HitTruthHandler(Geant4Context* ctxt, const string& nam) +Geant4HitTruthHandler::Geant4HitTruthHandler(Geant4Context* ctxt, const std::string& nam) : Geant4EventAction(ctxt, nam) { m_needsControl = true; @@ -152,6 +150,6 @@ void Geant4HitTruthHandler::end(const G4Event* event) { event->GetEventID()); } -#include "DDG4/Factories.h" +#include DECLARE_GEANT4ACTION(Geant4HitTruthHandler) diff --git a/DDG4/plugins/Geant4MaterialScanner.cpp b/DDG4/plugins/Geant4MaterialScanner.cpp index 76efe6a9f..56b6859f9 100644 --- a/DDG4/plugins/Geant4MaterialScanner.cpp +++ b/DDG4/plugins/Geant4MaterialScanner.cpp @@ -12,9 +12,9 @@ //========================================================================== // Framework include files -#include "DD4hep/Objects.h" -#include "DDG4/Defs.h" -#include "DDG4/Geant4SteppingAction.h" +#include +#include +#include // Forward declarations class G4LogicalVolume; @@ -84,20 +84,19 @@ namespace dd4hep { //==================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DD4hep/Printout.h" -#include "DDG4/Geant4TouchableHandler.h" -#include "DDG4/Geant4StepHandler.h" -#include "DDG4/Geant4EventAction.h" -#include "DDG4/Geant4TrackingAction.h" -#include "CLHEP/Units/SystemOfUnits.h" -#include "G4LogicalVolume.hh" -#include "G4Material.hh" - -using namespace std; +#include +#include +#include +#include +#include +#include +#include +#include +#include + using namespace dd4hep::sim; -#include "DDG4/Factories.h" +#include DECLARE_GEANT4ACTION(Geant4MaterialScanner) /// Initializing constructor @@ -108,7 +107,7 @@ Geant4MaterialScanner::StepInfo::StepInfo(const Position& prePos, const Position /// Copy constructor Geant4MaterialScanner::StepInfo::StepInfo(const StepInfo& c) -: pre(c.pre), post(c.post), volume(c.volume) + : pre(c.pre), post(c.post), volume(c.volume) { } @@ -121,7 +120,7 @@ Geant4MaterialScanner::StepInfo& Geant4MaterialScanner::StepInfo::operator=(cons } /// Standard constructor -Geant4MaterialScanner::Geant4MaterialScanner(Geant4Context* ctxt, const string& nam) +Geant4MaterialScanner::Geant4MaterialScanner(Geant4Context* ctxt, const std::string& nam) : Geant4SteppingAction(ctxt,nam) { m_needsControl = true; @@ -141,9 +140,9 @@ void Geant4MaterialScanner::operator()(const G4Step* step, G4SteppingManager*) { Geant4StepHandler h(step); #if 0 Geant4TouchableHandler pre_handler(step); - string prePath = pre_handler.path(); + std::string prePath = pre_handler.path(); Geant4TouchableHandler post_handler(step); - string postPath = post_handler.path(); + std::string postPath = post_handler.path(); #endif G4LogicalVolume* logVol = h.logvol(h.pre); m_steps.emplace_back(new StepInfo(h.prePos(), h.postPos(), logVol)); diff --git a/DDG4/plugins/Geant4ParticleDumpAction.cpp b/DDG4/plugins/Geant4ParticleDumpAction.cpp index 3b9c4b92d..c70f067d1 100644 --- a/DDG4/plugins/Geant4ParticleDumpAction.cpp +++ b/DDG4/plugins/Geant4ParticleDumpAction.cpp @@ -14,7 +14,7 @@ #define DD4HEP_DDG4_GEANT4PARTICLEDUMPACTION_H // Framework include files -#include "DDG4/Geant4EventAction.h" +#include // Forward declarations class G4VHitsCollection; @@ -67,20 +67,18 @@ namespace dd4hep { //==================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4DataDump.h" -#include "DDG4/Geant4HitCollection.h" +#include +#include +#include // Geant 4 includes -#include "G4HCofThisEvent.hh" -#include "G4Event.hh" +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor -Geant4ParticleDumpAction::Geant4ParticleDumpAction(Geant4Context* ctxt, const string& nam) +Geant4ParticleDumpAction::Geant4ParticleDumpAction(Geant4Context* ctxt, const std::string& nam) : Geant4EventAction(ctxt, nam) { m_needsControl = true; @@ -107,5 +105,5 @@ void Geant4ParticleDumpAction::end(const G4Event* event) { warning("+++ [Event:%d] No particle map available!",event->GetEventID()); } -#include "DDG4/Factories.h" +#include DECLARE_GEANT4ACTION(Geant4ParticleDumpAction) diff --git a/DDG4/plugins/Geant4ROOTDump.cpp b/DDG4/plugins/Geant4ROOTDump.cpp index d88e81468..eb12b5fb5 100644 --- a/DDG4/plugins/Geant4ROOTDump.cpp +++ b/DDG4/plugins/Geant4ROOTDump.cpp @@ -12,28 +12,21 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Factories.h" -#include "DD4hep/Primitives.h" -#include "DDG4/Geant4DataDump.h" -#include "DDG4/Geant4Particle.h" +#include +#include +#include +#include +#include // ROOT include files -#include "TInterpreter.h" -#include "TSystem.h" -#include "TFile.h" -#include "TTree.h" -#include "TROOT.h" - -using namespace std; -using namespace dd4hep; -using namespace dd4hep::sim; - -typedef Geant4DataDump::Particles Particles; -typedef Geant4DataDump::TrackerHits TrackerHits; -typedef Geant4DataDump::CalorimeterHits CalorimeterHits; +#include +#include +#include +#include +#include static long usage() { + using namespace dd4hep; printout(FATAL,"Geant4ROOTDump","usage: Geant4ROOTDump -opt (app-opts) --opt=value (plugin-opts)"); printout(FATAL,"Geant4ROOTDump"," app-opts: "); printout(FATAL,"Geant4ROOTDump"," -print INFO Print container summaries only."); @@ -46,10 +39,10 @@ static long usage() { return 'H'; } -static pair load(TBranch* branch, int entry) { +static std::pair load(TBranch* branch, int entry) { TClass* cl = gROOT->GetClass(branch->GetClassName(),kTRUE); if ( !cl ) { - return pair(0,0); + return std::pair(0,0); } void *obj = cl->New(); branch->SetAddress(&obj); @@ -57,12 +50,13 @@ static pair load(TBranch* branch, int entry) { int nb = branch->GetEntry(entry); if ( nb < 0 ) { cl->Destructor(obj); - return pair(0,0); + return std::pair(0,0); } - return pair(cl,obj); + return std::pair(cl,obj); } -static long dump_root(Detector&, int argc, char** argv) { +static long dump_root(dd4hep::Detector&, int argc, char** argv) { + using namespace dd4hep; std::string input = "", tag="Geant4ROOTDump"; int entry = -1; @@ -76,8 +70,8 @@ static long dump_root(Detector&, int argc, char** argv) { return 1; } if ( idx > 0 ) { - string p1 = a.substr(0,idx); - string p2 = a.substr(idx+1); + std::string p1 = a.substr(0,idx); + std::string p2 = a.substr(idx+1); if ( strncmp(p1.c_str(),"input",3)==0 ) { input = p2; } @@ -101,19 +95,18 @@ static long dump_root(Detector&, int argc, char** argv) { return usage(); } - - Geant4DataDump dump("Geant4Data"); + dd4hep::sim::Geant4DataDump dump("Geant4Data"); TFile* f = TFile::Open(input.c_str()); if ( f && !f->IsZombie() ) { TTree* tree = (TTree*)f->Get("EVENT"); - TClass* cl_calo = gROOT->GetClass(typeid(CalorimeterHits)); - TClass* cl_tracker = gROOT->GetClass(typeid(TrackerHits)); - TClass* cl_particles = gROOT->GetClass(typeid(Particles)); + TClass* cl_calo = gROOT->GetClass(typeid(dd4hep::sim::Geant4DataDump::CalorimeterHits)); + TClass* cl_tracker = gROOT->GetClass(typeid(dd4hep::sim::Geant4DataDump::TrackerHits)); + TClass* cl_particles = gROOT->GetClass(typeid(dd4hep::sim::Geant4DataDump::Particles)); TObjArray* branches = tree->GetListOfBranches(); Int_t nbranches = branches->GetEntriesFast(); - typedef pair ENTRY; - typedef map ENTRIES; + typedef std::pair ENTRY; + typedef std::map ENTRIES; for(Int_t ievt=entry<0 ? 0 : entry, nevt=entry<0 ? tree->GetEntries() : entry+1; ievtUncheckedAt(i); - pair data = load(branch,ievt); + std::pair data = load(branch,ievt); if ( data.first ) event[branch->GetName()] = data; } // Now dump the stuff for(ENTRIES::const_iterator i=event.begin(); i!=event.end(); ++i) { - pair data = (*i).second; + std::pair data = (*i).second; if ( data.first == cl_particles ) { - Particles* parts = (Particles*)data.second; + auto* parts = (dd4hep::sim::Geant4DataDump::Particles*)data.second; dump.print(INFO, (*i).first, parts); - for_each(parts->begin(), parts->end(), detail::DestroyObject()); + for_each(parts->begin(), parts->end(), detail::DestroyObject()); } } for(ENTRIES::const_iterator i=event.begin(); i!=event.end(); ++i) { - pair data = (*i).second; + std::pair data = (*i).second; if ( data.first == cl_particles ) { } else if ( data.first == cl_tracker ) { - TrackerHits* hits = (TrackerHits*)data.second; + auto* hits = (dd4hep::sim::Geant4DataDump::TrackerHits*)data.second; dump.print(INFO, (*i).first, hits); - for_each(hits->begin(), hits->end(), detail::DestroyObject()); + for_each(hits->begin(), hits->end(), detail::DestroyObject()); } else if ( data.first == cl_calo ) { - CalorimeterHits* hits = (CalorimeterHits*)data.second; + auto* hits = (dd4hep::sim::Geant4DataDump::CalorimeterHits*)data.second; dump.print(INFO, (*i).first, hits); - for_each(hits->begin(), hits->end(), detail::DestroyObject()); + for_each(hits->begin(), hits->end(), detail::DestroyObject()); } if ( data.first ) data.first->Destructor(data.second); } diff --git a/DDG4/plugins/Geant4SensDetFilters.cpp b/DDG4/plugins/Geant4SensDetFilters.cpp index 9a5d2dedc..2c4e60a5e 100644 --- a/DDG4/plugins/Geant4SensDetFilters.cpp +++ b/DDG4/plugins/Geant4SensDetFilters.cpp @@ -12,8 +12,8 @@ //========================================================================== /// Framework include files -#include "DDG4/Geant4SensDetAction.h" -#include "DDG4/Geant4FastSimSpot.h" +#include +#include /// Geant4 include files @@ -51,15 +51,15 @@ namespace dd4hep { bool isGeantino(const G4Track* track) const; /// Access to the track from step const G4Track* getTrack(const G4Step* step) const { - return step->GetTrack(); + return step->GetTrack(); } /// Access to the track from step const G4Track* getTrack(const Geant4FastSimSpot* spot) const { - return spot->primary; + return spot->primary; } /// Access originator track from G4 fast track const G4Track* getTrack(const G4FastTrack* fast) const { - return fast->GetPrimaryTrack(); + return fast->GetPrimaryTrack(); } }; @@ -76,11 +76,11 @@ namespace dd4hep { virtual ~ParticleRejectFilter(); /// Filter action. Return true if hits should be processed virtual bool operator()(const G4Step* step) const override final { - return !isSameType(getTrack(step)); + return !isSameType(getTrack(step)); } /// GFlash/FastSim interface: Filter action. Return true if hits should be processed virtual bool operator()(const Geant4FastSimSpot* spot) const override final { - return !isSameType(getTrack(spot)); + return !isSameType(getTrack(spot)); } }; @@ -97,11 +97,11 @@ namespace dd4hep { virtual ~ParticleSelectFilter(); /// Filter action. Return true if hits should be processed virtual bool operator()(const G4Step* step) const override final { - return isSameType(getTrack(step)); + return isSameType(getTrack(step)); } /// GFlash/FastSim interface: Filter action. Return true if hits should be processed virtual bool operator()(const Geant4FastSimSpot* spot) const override final { - return isSameType(getTrack(spot)); + return isSameType(getTrack(spot)); } }; @@ -118,11 +118,11 @@ namespace dd4hep { virtual ~GeantinoRejectFilter(); /// Filter action. Return true if hits should be processed virtual bool operator()(const G4Step* step) const override final { - return !isGeantino(getTrack(step)); + return !isGeantino(getTrack(step)); } /// GFlash/FastSim interface: Filter action. Return true if hits should be processed virtual bool operator()(const Geant4FastSimSpot* spot) const override final { - return !isGeantino(getTrack(spot)); + return !isGeantino(getTrack(spot)); } }; @@ -142,30 +142,28 @@ namespace dd4hep { virtual ~EnergyDepositMinimumCut(); /// Filter action. Return true if hits should be processed virtual bool operator()(const G4Step* step) const override final { - return step->GetTotalEnergyDeposit() > m_energyCut; + return step->GetTotalEnergyDeposit() > m_energyCut; } /// GFlash/FastSim interface: Filter action. Return true if hits should be processed virtual bool operator()(const Geant4FastSimSpot* spot) const override final { - return spot->energy() > m_energyCut; + return spot->energy() > m_energyCut; } }; } } /// Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Factories.h" +#include +#include // Geant4 include files -#include "G4ParticleTable.hh" -#include "G4ChargedGeantino.hh" -#include "G4Geantino.hh" -#include "G4Track.hh" -#include "G4Step.hh" +#include +#include +#include +#include +#include using namespace dd4hep::sim; -using namespace dd4hep; -using namespace std; //DECLARE_GEANT4ACTION() DECLARE_GEANT4ACTION(GeantinoRejectFilter) @@ -191,7 +189,7 @@ const G4ParticleDefinition* ParticleFilter::definition() const { if ( m_definition ) return m_definition; m_definition = G4ParticleTable::GetParticleTable()->FindParticle(m_particle); if ( 0 == m_definition ) { - throw runtime_error("Invalid particle name:'"+m_particle+"' [Not-in-particle-table]"); + throw std::runtime_error("Invalid particle name:'"+m_particle+"' [Not-in-particle-table]"); } return m_definition; } diff --git a/DDG4/plugins/Geant4TrackerWeightedSD.cpp b/DDG4/plugins/Geant4TrackerWeightedSD.cpp index 9f010bfe0..eca4988c3 100644 --- a/DDG4/plugins/Geant4TrackerWeightedSD.cpp +++ b/DDG4/plugins/Geant4TrackerWeightedSD.cpp @@ -12,20 +12,18 @@ //========================================================================== // Framework include files -#include "DD4hep/DD4hepUnits.h" -#include "DDG4/Geant4SensDetAction.inl" -#include "DDG4/Geant4SteppingAction.h" -#include "DDG4/Geant4TrackingAction.h" -#include "DDG4/Geant4EventAction.h" -#include "G4Event.hh" -#include "G4VSolid.hh" +#include +#include +#include +#include +#include +#include +#include #include #include #include -using namespace std; - /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -224,7 +222,7 @@ namespace dd4hep { break; } - if ( ended == kSurface || distance_to_outside < numeric_limits::epsilon() ) + if ( ended == kSurface || distance_to_outside < std::numeric_limits::epsilon() ) hit_flag |= Geant4Tracker::Hit::HIT_ENDED_SURFACE; else if ( ended == kInside ) hit_flag |= Geant4Tracker::Hit::HIT_ENDED_INSIDE; @@ -477,5 +475,5 @@ namespace dd4hep { using namespace dd4hep::sim; -#include "DDG4/Factories.h" +#include DECLARE_GEANT4SENSITIVE(Geant4TrackerWeightedAction) diff --git a/DDG4/plugins/Geant4UserActionInitialization.cpp b/DDG4/plugins/Geant4UserActionInitialization.cpp index ffb7fff1e..a0ebe837e 100644 --- a/DDG4/plugins/Geant4UserActionInitialization.cpp +++ b/DDG4/plugins/Geant4UserActionInitialization.cpp @@ -15,7 +15,7 @@ #define DD4HEP_DDG4_GEANT4USERACTIONINITIALIZATION_H // Framework include files -#include "DDG4/Geant4UserInitialization.h" +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -60,19 +60,16 @@ namespace dd4hep { //========================================================================== // Framework include files -#include "DDG4/Factories.h" -//#include "DDG4/Geant4UserActionInitialization.h" -#include "DDG4/Geant4Context.h" +#include +//#include +#include -// C/C++ include files - -using namespace std; using namespace dd4hep::sim; //DECLARE_GEANT4ACTION(Geant4UserActionInitialization) /// Standard constructor, initializes variables -Geant4UserActionInitialization::Geant4UserActionInitialization(Geant4Context* ctxt, const string& nam) +Geant4UserActionInitialization::Geant4UserActionInitialization(Geant4Context* ctxt, const std::string& nam) : Geant4UserInitialization(ctxt,nam) { } diff --git a/DDG4/plugins/Geant4XMLSetup.cpp b/DDG4/plugins/Geant4XMLSetup.cpp index 9d68abe97..e7227a321 100644 --- a/DDG4/plugins/Geant4XMLSetup.cpp +++ b/DDG4/plugins/Geant4XMLSetup.cpp @@ -12,18 +12,17 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Printout.h" -#include "DD4hep/DetFactoryHelper.h" -#include "XML/Conversions.h" -#include "DDG4/Geant4Config.h" +#include +#include +#include +#include +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { // Forward declarations class ActionSequence; - using namespace std; using namespace dd4hep::sim; using namespace dd4hep::sim::Setup; @@ -47,10 +46,10 @@ namespace dd4hep { template static void _setAttributes(const T& handle, xml_h& e) { xml::Handle_t props(e); // Now we set the object properties - vector attrs = props.attributes(); - for(vector::iterator i=attrs.begin(); i!=attrs.end(); ++i) { + std::vector attrs = props.attributes(); + for(std::vector::iterator i=attrs.begin(); i!=attrs.end(); ++i) { xml::Attribute a = *i; - handle[xml::_toString(props.attr_name(a))].str(props.attr(a)); + handle[xml::_toString(props.attr_name(a))].str(props.attr(a)); } } @@ -63,20 +62,20 @@ namespace dd4hep { _setAttributes(handle, props); } if ( action.hasAttr(_Unicode(Control)) ) { - handle["Control"].str(props.attr(_Unicode(Control))); + handle["Control"].str(props.attr(_Unicode(Control))); } } /// Create/Configure Geant4 sensitive action object from XML - static Action _convertSensitive(Detector& description, xml_h e, const string& detector) { + static Action _convertSensitive(Detector& description, xml_h e, const std::string& detector) { xml_comp_t action(e); Kernel& kernel = Kernel::instance(description); - TypeName tn = TypeName::split(action.attr(_U(name))); + TypeName tn = TypeName::split(action.attr(_U(name))); // Create the object using the factory method - Sensitive handle(kernel,action.attr(_U(name)),detector); + Sensitive handle(kernel,action.attr(_U(name)),detector); _setProperties(Action(handle.get()),e); for(xml_coll_t f(e,_Unicode(filter)); f; ++f) { - string nam = f.attr(_U(name)); + std::string nam = f.attr(_U(name)); Filter filter(kernel.globalFilter(nam,false)); handle->adopt(filter); } @@ -90,15 +89,15 @@ namespace dd4hep { static Action _convertAction(Detector& description, xml_h e) { xml_comp_t action(e); Kernel& kernel = Kernel::instance(description); - TypeName tn = TypeName::split(action.attr(_U(name))); + TypeName tn = TypeName::split(action.attr(_U(name))); // Create the object using the factory method - Action handle(kernel,action.attr(_U(name))); + Action handle(kernel,action.attr(_U(name))); _setProperties(handle,e); printout(INFO,"Geant4Setup","+++ Added action %s of type %s",tn.second.c_str(),tn.first.c_str()); installMessenger(handle); if ( action.hasChild(_Unicode(adopt)) ) { - xml_comp_t child = action.child(_Unicode(adopt)); + xml_comp_t child = action.child(_Unicode(adopt)); Geant4Action* user = kernel.globalAction(child.nameStr()); Geant4ParticleHandler* ph = dynamic_cast(handle.get()); if ( ph ) { @@ -110,8 +109,8 @@ namespace dd4hep { enum { SENSITIVE, ACTION, FILTER }; /// Create/Configure Action object from XML - Action _createAction(Detector& description, xml_h a, const string& seqType, int what) { - string nam = a.attr(_U(name)); + Action _createAction(Detector& description, xml_h a, const std::string& seqType, int what) { + std::string nam = a.attr(_U(name)); TypeName typ = TypeName::split(nam); Kernel& kernel = Kernel::instance(description); Action action((what==FILTER) ? (Geant4Action*)kernel.globalFilter(typ.second,false) @@ -125,366 +124,366 @@ namespace dd4hep { : (what==FILTER) ? _convertAction(description, a) : Action(); if ( !action ) { - throw runtime_error(format("Geant4ActionSequence","DDG4: The action '%s'" - " cannot be created. [Action-Missing]",nam.c_str())); - } + except("Geant4ActionSequence", + "DDG4: The action '%s' cannot be created. [Action-Missing]",nam.c_str()); } - return action; } + return action; } +} - /// Convert Geant4Action objects - /** - * - * - * - * - */ - template <> void Converter::operator()(xml_h e) const { - Action a = _convertAction(description, e); - Kernel::instance(description).registerGlobalAction(a); - } +/// Convert Geant4Action objects +/** + * + * + * + * + */ +template <> void Converter::operator()(xml_h e) const { + Action a = _convertAction(description, e); + Kernel::instance(description).registerGlobalAction(a); +} - /// Convert Sensitive detector filters - /** - * Note: Filters are Geant4Actions and - if global - may also receive properties! - * - * - * - * - * - * - * - */ - template <> void Converter::operator()(xml_h e) const { - Action a = _convertAction(description, e); - Kernel::instance(description).registerGlobalFilter(a); - } +/// Convert Sensitive detector filters +/** + * Note: Filters are Geant4Actions and - if global - may also receive properties! + * + * + * + * + * + * + * + */ +template <> void Converter::operator()(xml_h e) const { + Action a = _convertAction(description, e); + Kernel::instance(description).registerGlobalFilter(a); +} - /// Convert Geant4Phase objects - /** - * - * - * - * - */ - template <> void Converter::operator()(xml_h e) const { - xml_comp_t x_phase(e); - Kernel& kernel = Kernel::instance(description); - string nam = x_phase.attr(_U(type)); - typedef Geant4ActionPhase PH; - Phase p; +/// Convert Geant4Phase objects +/** + * + * + * + * + */ +template <> void Converter::operator()(xml_h e) const { + xml_comp_t x_phase(e); + Kernel& kernel = Kernel::instance(description); + std::string nam = x_phase.attr(_U(type)); + typedef Geant4ActionPhase PH; + Phase p; - if ( nam == "RunAction/begin" ) { - void (Geant4ActionPhase::*func)(const G4Run*) = &Geant4ActionPhase::call; - kernel.runAction().callAtBegin((p=kernel.addPhase(nam)).get(),func); - //&Geant4ActionPhase::call); - } - else if ( nam == "RunAction/end" ) { - void (Geant4ActionPhase::*func)(const G4Run*) = &Geant4ActionPhase::call; - kernel.runAction().callAtEnd((p=kernel.addPhase(nam)).get(),func); - //&PH::call); - } - else if ( nam == "EventAction/begin" ) { - void (Geant4ActionPhase::*func)(const G4Event*) = &Geant4ActionPhase::call; - kernel.eventAction().callAtBegin((p=kernel.addPhase(nam)).get(),func); - //&PH::call); - } - else if ( nam == "EventAction/end" ) { - void (Geant4ActionPhase::*func)(const G4Event*) = &Geant4ActionPhase::call; - kernel.eventAction().callAtEnd((p=kernel.addPhase(nam)).get(),func); - //&PH::call); - } - else if ( nam == "TrackingAction/begin" ) { - void (Geant4ActionPhase::*func)(const G4Track*) = &Geant4ActionPhase::call; - kernel.trackingAction().callAtBegin((p=kernel.addPhase(nam)).get(),func); - //&PH::call); - } - else if ( nam == "TrackingAction/end" ) { - void (Geant4ActionPhase::*func)(const G4Track*) = &Geant4ActionPhase::call; - kernel.trackingAction().callAtEnd((p=kernel.addPhase(nam,false)).get(),func); - //&PH::call); - } - else if ( nam == "StackingAction/newStage" ) { - kernel.stackingAction().callAtNewStage((p=kernel.addPhase(nam,false)).get(),&PH::call); - } - else if ( nam == "StackingAction/prepare" ) { - kernel.stackingAction().callAtPrepare((p=kernel.addPhase(nam,false)).get(),&PH::call); - } - else if ( nam == "SteppingAction" ) { - void (Geant4ActionPhase::*func)(const G4Step*,G4SteppingManager*) = &Geant4ActionPhase::call; - kernel.steppingAction().call((p=kernel.addPhase(nam)).get(),func); - //&PH::call); - } - else if ( nam == "GeneratorAction/primaries" ) { - void (Geant4ActionPhase::*func)(G4Event*) = &Geant4ActionPhase::call; - kernel.generatorAction().call((p=kernel.addPhase(nam)).get(),func); - //&PH::call); + if ( nam == "RunAction/begin" ) { + void (Geant4ActionPhase::*func)(const G4Run*) = &Geant4ActionPhase::call; + kernel.runAction().callAtBegin((p=kernel.addPhase(nam)).get(),func); + //&Geant4ActionPhase::call); + } + else if ( nam == "RunAction/end" ) { + void (Geant4ActionPhase::*func)(const G4Run*) = &Geant4ActionPhase::call; + kernel.runAction().callAtEnd((p=kernel.addPhase(nam)).get(),func); + //&PH::call); + } + else if ( nam == "EventAction/begin" ) { + void (Geant4ActionPhase::*func)(const G4Event*) = &Geant4ActionPhase::call; + kernel.eventAction().callAtBegin((p=kernel.addPhase(nam)).get(),func); + //&PH::call); + } + else if ( nam == "EventAction/end" ) { + void (Geant4ActionPhase::*func)(const G4Event*) = &Geant4ActionPhase::call; + kernel.eventAction().callAtEnd((p=kernel.addPhase(nam)).get(),func); + //&PH::call); + } + else if ( nam == "TrackingAction/begin" ) { + void (Geant4ActionPhase::*func)(const G4Track*) = &Geant4ActionPhase::call; + kernel.trackingAction().callAtBegin((p=kernel.addPhase(nam)).get(),func); + //&PH::call); + } + else if ( nam == "TrackingAction/end" ) { + void (Geant4ActionPhase::*func)(const G4Track*) = &Geant4ActionPhase::call; + kernel.trackingAction().callAtEnd((p=kernel.addPhase(nam,false)).get(),func); + //&PH::call); + } + else if ( nam == "StackingAction/newStage" ) { + kernel.stackingAction().callAtNewStage((p=kernel.addPhase(nam,false)).get(),&PH::call); + } + else if ( nam == "StackingAction/prepare" ) { + kernel.stackingAction().callAtPrepare((p=kernel.addPhase(nam,false)).get(),&PH::call); + } + else if ( nam == "SteppingAction" ) { + void (Geant4ActionPhase::*func)(const G4Step*,G4SteppingManager*) = &Geant4ActionPhase::call; + kernel.steppingAction().call((p=kernel.addPhase(nam)).get(),func); + //&PH::call); + } + else if ( nam == "GeneratorAction/primaries" ) { + void (Geant4ActionPhase::*func)(G4Event*) = &Geant4ActionPhase::call; + kernel.generatorAction().call((p=kernel.addPhase(nam)).get(),func); + //&PH::call); + } + else { + TypeName tn = TypeName::split(nam); + DetElement det = description.detector(tn.first); + if ( !det.isValid() ) { + except("Phase","DDG4: The phase '%s' of type SensitiveSeq" + " cannot be attached to a non-existing detector" + " [Detector-Missing]",nam.c_str()); } - else { - TypeName tn = TypeName::split(nam); - DetElement det = description.detector(tn.first); - if ( !det.isValid() ) { - throw runtime_error(format("Phase","DDG4: The phase '%s' of type SensitiveSeq" - " cannot be attached to a non-existing detector" - " [Detector-Missing]",nam.c_str())); - } - SensitiveDetector sd = description.sensitiveDetector(tn.first); - if ( !sd.isValid() ) { - throw runtime_error(format("Phase","DDG4: The phase '%s' of type SensitiveSeq" - " cannot be attached to a non-existing sensitive detector" - " [Sensitive-Missing]",nam.c_str())); - } - SensitiveSeq sdSeq = SensitiveSeq(kernel,tn.first); - if ( tn.second == "begin" ) - sdSeq->callAtBegin((p=kernel.addPhase(tn.second)).get(), - &PH::call); - else if ( tn.second == "end" ) - sdSeq->callAtEnd((p=kernel.addPhase(tn.second)).get(), - &PH::call); - else if ( tn.second == "clear" ) - sdSeq->callAtClear((p=kernel.addPhase(tn.second)).get(), - &PH::call); - else if ( tn.second == "process" ) - sdSeq->callAtProcess((p=kernel.addPhase(tn.second)).get(), - &PH::call); - else - throw runtime_error(format("Phase","DDG4: The phase '%s' of type SensitiveSeq" - " cannot be attached to the call '%s'." - " [Callback-Missing]",tn.first.c_str(), tn.second.c_str())); + SensitiveDetector sd = description.sensitiveDetector(tn.first); + if ( !sd.isValid() ) { + except("Phase","DDG4: The phase '%s' of type SensitiveSeq" + " cannot be attached to a non-existing sensitive detector" + " [Sensitive-Missing]",nam.c_str()); } + SensitiveSeq sdSeq = SensitiveSeq(kernel,tn.first); + if ( tn.second == "begin" ) + sdSeq->callAtBegin((p=kernel.addPhase(tn.second)).get(), + &PH::call); + else if ( tn.second == "end" ) + sdSeq->callAtEnd((p=kernel.addPhase(tn.second)).get(), + &PH::call); + else if ( tn.second == "clear" ) + sdSeq->callAtClear((p=kernel.addPhase(tn.second)).get(), + &PH::call); + else if ( tn.second == "process" ) + sdSeq->callAtProcess((p=kernel.addPhase(tn.second)).get(), + &PH::call); + else + except("Phase","DDG4: The phase '%s' of type SensitiveSeq" + " cannot be attached to the call '%s'." + " [Callback-Missing]",tn.first.c_str(), tn.second.c_str()); } +} - /// Convert Action sequences into objects - /** - * - * - * - * - * - * - * - * - */ - template <> void Converter::operator()(xml_h e) const { - xml_comp_t seq(e); - SensitiveSeq sdSeq; - string seqNam; - TypeName seqType; - int what = ACTION; - Kernel& kernel = Kernel::instance(description); +/// Convert Action sequences into objects +/** + * + * + * + * + * + * + * + * + */ +template <> void Converter::operator()(xml_h e) const { + xml_comp_t seq(e); + SensitiveSeq sdSeq; + std::string seqNam; + TypeName seqType; + int what = ACTION; + Kernel& kernel = Kernel::instance(description); - if ( seq.hasAttr(_U(sd)) ) { - string sd_nam = seq.attr(_U(sd)); - SensitiveDetector sensitive = description.sensitiveDetector(sd_nam); - seqNam = seq.attr(_U(type))+"/"+sd_nam; - if ( !sensitive.isValid() ) { - printout(ALWAYS,"Geant4Setup","+++ ActionSequence %s is defined, " - "but no sensitive detector present.",seqNam.c_str()); - printout(ALWAYS,"Geant4Setup","+++ ---> Sequence for detector %s IGNORED on popular request!", - sd_nam.c_str()); - return; - } - seqType = TypeName::split(seqNam); - sdSeq = SensitiveSeq(kernel,seqNam); - what = SENSITIVE; - } - else { - seqNam = seq.attr(_U(name)); - seqType = TypeName::split(seqNam); + if ( seq.hasAttr(_U(sd)) ) { + std::string sd_nam = seq.attr(_U(sd)); + SensitiveDetector sensitive = description.sensitiveDetector(sd_nam); + seqNam = seq.attr(_U(type))+"/"+sd_nam; + if ( !sensitive.isValid() ) { + printout(ALWAYS,"Geant4Setup","+++ ActionSequence %s is defined, " + "but no sensitive detector present.",seqNam.c_str()); + printout(ALWAYS,"Geant4Setup","+++ ---> Sequence for detector %s IGNORED on popular request!", + sd_nam.c_str()); + return; } - printout(INFO,"Geant4Setup","+++ ActionSequence %s of type %s added.", - seqType.second.c_str(),seqType.first.c_str()); + seqType = TypeName::split(seqNam); + sdSeq = SensitiveSeq(kernel,seqNam); + what = SENSITIVE; + } + else { + seqNam = seq.attr(_U(name)); + seqType = TypeName::split(seqNam); + } + printout(INFO,"Geant4Setup","+++ ActionSequence %s of type %s added.", + seqType.second.c_str(),seqType.first.c_str()); - if ( seqType.second == "PhysicsList" ) { - PhysicsActionSeq pl(&kernel.physicsList()); - PropertyManager& props = kernel.physicsList().properties(); - props.dump(); - _setAttributes(pl,e); - props.dump(); - } + if ( seqType.second == "PhysicsList" ) { + PhysicsActionSeq pl(&kernel.physicsList()); + PropertyManager& props = kernel.physicsList().properties(); + props.dump(); + _setAttributes(pl,e); + props.dump(); + } - for(xml_coll_t a(seq,_Unicode(action)); a; ++a) { - string nam = a.attr(_U(name)); - Action action(_createAction(description,a,seqType.second,what)); - if ( seqType.second == "RunAction" ) - kernel.runAction().adopt(_action(action.get())); - else if ( seqType.second == "EventAction" ) - kernel.eventAction().adopt(_action(action.get())); - else if ( seqType.second == "GeneratorAction" ) - kernel.generatorAction().adopt(_action(action.get())); - else if ( seqType.second == "TrackingAction" ) - kernel.trackingAction().adopt(_action(action.get())); - else if ( seqType.second == "StackingAction" ) - kernel.stackingAction().adopt(_action(action.get())); - else if ( seqType.second == "SteppingAction" ) - kernel.steppingAction().adopt(_action(action.get())); - else if ( seqType.second == "PhysicsList" ) - kernel.physicsList().adopt(_action(action.get())); - else if ( sdSeq.get() ) - sdSeq->adopt(_action(action.get())); - else { - throw runtime_error(format("ActionSequence","DDG4: The action '%s'" - " cannot be attached to any sequence '%s'." - " [Sequence-Missing]",nam.c_str(), seqNam.c_str())); - } + for(xml_coll_t a(seq,_Unicode(action)); a; ++a) { + std::string nam = a.attr(_U(name)); + Action action(_createAction(description,a,seqType.second,what)); + if ( seqType.second == "RunAction" ) + kernel.runAction().adopt(_action(action.get())); + else if ( seqType.second == "EventAction" ) + kernel.eventAction().adopt(_action(action.get())); + else if ( seqType.second == "GeneratorAction" ) + kernel.generatorAction().adopt(_action(action.get())); + else if ( seqType.second == "TrackingAction" ) + kernel.trackingAction().adopt(_action(action.get())); + else if ( seqType.second == "StackingAction" ) + kernel.stackingAction().adopt(_action(action.get())); + else if ( seqType.second == "SteppingAction" ) + kernel.steppingAction().adopt(_action(action.get())); + else if ( seqType.second == "PhysicsList" ) + kernel.physicsList().adopt(_action(action.get())); + else if ( sdSeq.get() ) + sdSeq->adopt(_action(action.get())); + else { + except("ActionSequence","DDG4: The action '%s'" + " cannot be attached to any sequence '%s'." + " [Sequence-Missing]",nam.c_str(), seqNam.c_str()); + } + printout(INFO,"Geant4Setup","+++ ActionSequence %s added filter object:%s", + seqType.second.c_str(),action->name().c_str()); + } + if ( what == SENSITIVE ) { + for(xml_coll_t a(seq,_Unicode(filter)); a; ++a) { + std::string nam = a.attr(_U(name)); + Action action(_createAction(description,a,"",FILTER)); + installMessenger(action); printout(INFO,"Geant4Setup","+++ ActionSequence %s added filter object:%s", seqType.second.c_str(),action->name().c_str()); - } - if ( what == SENSITIVE ) { - for(xml_coll_t a(seq,_Unicode(filter)); a; ++a) { - string nam = a.attr(_U(name)); - Action action(_createAction(description,a,"",FILTER)); - installMessenger(action); - printout(INFO,"Geant4Setup","+++ ActionSequence %s added filter object:%s", - seqType.second.c_str(),action->name().c_str()); - if ( sdSeq.get() ) - sdSeq->adopt(_action(action.get())); - else { - throw runtime_error(format("ActionSequence","DDG4: The action '%s'" - " cannot be attached to any sequence '%s'." - " [Sequence-Missing]",nam.c_str(), seqNam.c_str())); - } + if ( sdSeq.get() ) + sdSeq->adopt(_action(action.get())); + else { + except("ActionSequence","DDG4: The action '%s'" + " cannot be attached to any sequence '%s'." + " [Sequence-Missing]",nam.c_str(), seqNam.c_str()); } } } +} - /// Create/Configure PhysicsList objects - /** - * - * - * - * - * - * - * - * - */ - template <> void Converter::operator()(xml_h e) const { - xml_comp_t part(e); - string part_name = part.nameStr(); - Geant4PhysicsList::ParticleProcesses& procs = - _object().processes(part_name); - for(xml_coll_t q(part,_Unicode(process)); q; ++q) { - xml_comp_t proc(q); - Geant4PhysicsList::Process p; - p.name = proc.nameStr(); - p.ordAtRestDoIt = proc.attr(_Unicode(ordAtRestDoIt)); - p.ordAlongSteptDoIt = proc.attr(_Unicode(ordAlongSteptDoIt)); - p.ordPostStepDoIt = proc.attr(_Unicode(ordPostStepDoIt)); - procs.emplace_back(p); - printout(INFO,"Geant4Setup","+++ Converter + * + * + * + * + * + * + * + */ +template <> void Converter::operator()(xml_h e) const { + xml_comp_t part(e); + std::string part_name = part.nameStr(); + Geant4PhysicsList::ParticleProcesses& procs = + _object().processes(part_name); + for(xml_coll_t q(part,_Unicode(process)); q; ++q) { + xml_comp_t proc(q); + Geant4PhysicsList::Process p; + p.name = proc.nameStr(); + p.ordAtRestDoIt = proc.attr(_Unicode(ordAtRestDoIt)); + p.ordAlongSteptDoIt = proc.attr(_Unicode(ordAlongSteptDoIt)); + p.ordPostStepDoIt = proc.attr(_Unicode(ordPostStepDoIt)); + procs.emplace_back(p); + printout(INFO,"Geant4Setup","+++ Converter - * - * - * - * - * - * - * - * - */ - template <> void Converter::operator()(xml_h e) const { - Geant4PhysicsList::ParticleConstructors& parts = _object().particles(); - xml_comp_t part(e); - string n = part.nameStr(); - parts.emplace_back(n); - printout(INFO,"Geant4Setup","+++ ParticleConstructor: Add Geant4 particle constructor '%s'",n.c_str()); - } +/// Create/Configure PhysicsList objects: Particle constructors +/** + * + * + * + * + * + * + * + * + * + */ +template <> void Converter::operator()(xml_h e) const { + Geant4PhysicsList::ParticleConstructors& parts = _object().particles(); + xml_comp_t part(e); + std::string n = part.nameStr(); + parts.emplace_back(n); + printout(INFO,"Geant4Setup","+++ ParticleConstructor: Add Geant4 particle constructor '%s'",n.c_str()); +} - /// Create/Configure PhysicsList objects: Physics constructors - /** - * - * - * - * - * - * - */ - template <> void Converter::operator()(xml_h e) const { - Geant4PhysicsList::PhysicsConstructors& parts = _object().physics(); - xml_comp_t part(e); - string n = part.nameStr(); - parts.emplace_back(n); - printout(INFO,"Geant4Setup","+++ PhysicsConstructor: Add Geant4 physics constructor '%s'",n.c_str()); - } +/// Create/Configure PhysicsList objects: Physics constructors +/** + * + * + * + * + * + * + */ +template <> void Converter::operator()(xml_h e) const { + Geant4PhysicsList::PhysicsConstructors& parts = _object().physics(); + xml_comp_t part(e); + std::string n = part.nameStr(); + parts.emplace_back(n); + printout(INFO,"Geant4Setup","+++ PhysicsConstructor: Add Geant4 physics constructor '%s'",n.c_str()); +} - /// Create/Configure PhysicsList extension objects: Predefined Geant4 Physics lists - /** - * - * - * - * Note: list items are Geant4Actions and - if global - may receive properties! - */ - struct PhysicsListExtension; - template <> void Converter::operator()(xml_h e) const { - Kernel& kernel = Kernel::instance(description); - string ext = xml_comp_t(e).nameStr(); - kernel.physicsList().properties()["extends"].str(ext); - printout(INFO,"Geant4Setup","+++ PhysicsListExtension: Set predefined Geant4 physics list to '%s'",ext.c_str()); - } +/// Create/Configure PhysicsList extension objects: Predefined Geant4 Physics lists +/** + * + * + * + * Note: list items are Geant4Actions and - if global - may receive properties! + */ +struct PhysicsListExtension; +template <> void Converter::operator()(xml_h e) const { + Kernel& kernel = Kernel::instance(description); + std::string ext = xml_comp_t(e).nameStr(); + kernel.physicsList().properties()["extends"].str(ext); + printout(INFO,"Geant4Setup","+++ PhysicsListExtension: Set predefined Geant4 physics list to '%s'",ext.c_str()); +} - /// Create/Configure PhysicsList objects: Predefined Geant4 Physics lists - template <> void Converter::operator()(xml_h e) const { - string name = e.attr(_U(name)); - Kernel& kernel = Kernel::instance(description); - PhysicsList handle(kernel,name); - _setAttributes(handle,e); - xml_coll_t(e,_Unicode(particles)).for_each(_Unicode(construct),Converter(description,handle.get())); - xml_coll_t(e,_Unicode(processes)).for_each(_Unicode(particle),Converter(description,handle.get())); - xml_coll_t(e,_Unicode(physics)).for_each(_Unicode(construct),Converter(description,handle.get())); - xml_coll_t(e,_Unicode(extends)).for_each(Converter(description,handle.get())); - kernel.physicsList().adopt(handle); - } +/// Create/Configure PhysicsList objects: Predefined Geant4 Physics lists +template <> void Converter::operator()(xml_h e) const { + std::string name = e.attr(_U(name)); + Kernel& kernel = Kernel::instance(description); + PhysicsList handle(kernel,name); + _setAttributes(handle,e); + xml_coll_t(e,_Unicode(particles)).for_each(_Unicode(construct),Converter(description,handle.get())); + xml_coll_t(e,_Unicode(processes)).for_each(_Unicode(particle),Converter(description,handle.get())); + xml_coll_t(e,_Unicode(physics)).for_each(_Unicode(construct),Converter(description,handle.get())); + xml_coll_t(e,_Unicode(extends)).for_each(Converter(description,handle.get())); + kernel.physicsList().adopt(handle); +} - /// Create/Configure Geant4Kernel objects - template <> void Converter::operator()(xml_h e) const { - Kernel& kernel = Kernel::instance(description); - xml_comp_t k(e); - if ( k.hasAttr(_Unicode(NumEvents)) ) - kernel.property("NumEvents").str(k.attr(_Unicode(NumEvents))); - if ( k.hasAttr(_Unicode(UI)) ) - kernel.property("UI").str(k.attr(_Unicode(UI))); - } +/// Create/Configure Geant4Kernel objects +template <> void Converter::operator()(xml_h e) const { + Kernel& kernel = Kernel::instance(description); + xml_comp_t k(e); + if ( k.hasAttr(_Unicode(NumEvents)) ) + kernel.property("NumEvents").str(k.attr(_Unicode(NumEvents))); + if ( k.hasAttr(_Unicode(UI)) ) + kernel.property("UI").str(k.attr(_Unicode(UI))); +} - /// Main entry point to configure Geant4 with XML - template <> void Converter::operator()(xml_h seq) const { - xml_elt_t compact(seq); - // First execute the basic setup from the plugins module - long result = PluginService::Create("geant4_XML_reader",&description,&seq); - if ( 0 == result ) { - throw runtime_error("dd4hep: Failed to locate plugin to interprete files of type" - " \"" + seq.tag() + "\" - no factory of type geant4_XML_reader."); - } - result = *(long*) result; - if (result != 1) { - throw runtime_error("dd4hep: Failed to parse the XML tag " + seq.tag() + " with the plugin geant4_XML_reader"); - } - xml_coll_t(compact,_Unicode(kernel)).for_each(Converter(description,param)); - // Now deal with the new stuff..... - xml_coll_t(compact,_Unicode(actions) ).for_each(_Unicode(action),Converter(description,param)); - xml_coll_t(compact,_Unicode(filters) ).for_each(_Unicode(filter),Converter(description,param)); - xml_coll_t(compact,_Unicode(sequences) ).for_each(_Unicode(sequence),Converter(description,param)); - xml_coll_t(compact,_Unicode(phases) ).for_each(_Unicode(phase),Converter(description,param)); - xml_coll_t(compact,_Unicode(physicslist)).for_each(Converter(description,param)); +/// Main entry point to configure Geant4 with XML +template <> void Converter::operator()(xml_h seq) const { + xml_elt_t compact(seq); + // First execute the basic setup from the plugins module + long result = PluginService::Create("geant4_XML_reader",&description,&seq); + if ( 0 == result ) { + except("PhysicsList", "dd4hep: Failed to locate plugin to interprete files of type" + " \"" + seq.tag() + "\" - no factory of type geant4_XML_reader."); + } + result = *(long*) result; + if (result != 1) { + except("PhysicsList", "dd4hep: Failed to parse the XML tag %s with the plugin geant4_XML_reader", seq.tag().c_str()); } + xml_coll_t(compact,_Unicode(kernel)).for_each(Converter(description,param)); + // Now deal with the new stuff..... + xml_coll_t(compact,_Unicode(actions) ).for_each(_Unicode(action),Converter(description,param)); + xml_coll_t(compact,_Unicode(filters) ).for_each(_Unicode(filter),Converter(description,param)); + xml_coll_t(compact,_Unicode(sequences) ).for_each(_Unicode(sequence),Converter(description,param)); + xml_coll_t(compact,_Unicode(phases) ).for_each(_Unicode(phase),Converter(description,param)); + xml_coll_t(compact,_Unicode(physicslist)).for_each(Converter(description,param)); +} } /// Factory method diff --git a/DDG4/reco/Geant4SurfaceTest.cpp b/DDG4/reco/Geant4SurfaceTest.cpp index 84b6bb147..a07053a6d 100644 --- a/DDG4/reco/Geant4SurfaceTest.cpp +++ b/DDG4/reco/Geant4SurfaceTest.cpp @@ -15,7 +15,7 @@ // Framework include files //#include "Geant4SurfaceTest.h" -#include "DDG4/Geant4EventAction.h" +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -48,32 +48,31 @@ namespace dd4hep { #endif // DD4HEP_DDG4_GEANT4SURFACETEST_H // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/DD4hepUnits.h" -#include "DD4hep/InstanceCount.h" +#include +#include +#include -#include "DDG4/Factories.h" -#include "DDG4/Geant4Data.h" -#include "DDG4/Geant4Context.h" -#include "DDG4/Geant4SensDetAction.h" -#include "DDG4/Geant4HitCollection.h" +#include +#include +#include +#include +#include -#include "DDRec/Surface.h" -#include "DDRec/DetectorSurfaces.h" -#include "DDRec/SurfaceManager.h" -#include "DDRec/SurfaceHelper.h" +#include +#include +#include +#include // Geant 4 includes -#include "G4VHitsCollection.hh" -#include "G4HCofThisEvent.hh" -#include "G4Event.hh" +#include +#include +#include // C/C++ include files #include #include #include -using namespace std; using namespace dd4hep::DDRec; using namespace dd4hep::detail; using namespace dd4hep::sim; diff --git a/DDG4/src/Geant4Action.cpp b/DDG4/src/Geant4Action.cpp index 9902863e3..c8dbd2327 100644 --- a/DDG4/src/Geant4Action.cpp +++ b/DDG4/src/Geant4Action.cpp @@ -25,7 +25,6 @@ // C/C++ include files #include -using namespace dd4hep; using namespace dd4hep::sim; TypeName TypeName::split(const std::string& type_name, const std::string& delim) { @@ -86,7 +85,7 @@ long Geant4Action::release() { } /// Set the output level; returns previous value -PrintLevel Geant4Action::setOutputLevel(PrintLevel new_level) { +dd4hep::PrintLevel Geant4Action::setOutputLevel(PrintLevel new_level) { int old = m_outputLevel; m_outputLevel = new_level; return (PrintLevel)old; @@ -98,7 +97,7 @@ bool Geant4Action::hasProperty(const std::string& nam) const { } /// Access single property -Property& Geant4Action::property(const std::string& nam) { +dd4hep::Property& Geant4Action::property(const std::string& nam) { return properties()[nam]; } diff --git a/DDG4/src/Geant4Context.cpp b/DDG4/src/Geant4Context.cpp index 95f0f84d4..803d254d8 100644 --- a/DDG4/src/Geant4Context.cpp +++ b/DDG4/src/Geant4Context.cpp @@ -20,7 +20,6 @@ // C/C++ include files #include -using namespace dd4hep; using namespace dd4hep::sim; /// Intializing constructor @@ -89,7 +88,7 @@ Geant4Event& Geant4Context::event() const { } /// Access to detector description -Detector& Geant4Context::detectorDescription() const { +dd4hep::Detector& Geant4Context::detectorDescription() const { return m_kernel->detectorDescription(); } diff --git a/DDG4/src/Geant4Data.cpp b/DDG4/src/Geant4Data.cpp index 4d57b09ca..e4c7efd06 100644 --- a/DDG4/src/Geant4Data.cpp +++ b/DDG4/src/Geant4Data.cpp @@ -24,7 +24,6 @@ #include #include -using namespace dd4hep; using namespace dd4hep::sim; /// Default constructor diff --git a/DDG4/src/Geant4DataDump.cpp b/DDG4/src/Geant4DataDump.cpp index f07fefa7c..21ff02716 100644 --- a/DDG4/src/Geant4DataDump.cpp +++ b/DDG4/src/Geant4DataDump.cpp @@ -15,10 +15,8 @@ #include #include -using namespace dd4hep; using namespace dd4hep::sim; - -typedef detail::ReferenceBitMask PropertyMask; +using PropertyMask = dd4hep::detail::ReferenceBitMask; /// Default constructor Geant4DataDump::Geant4DataDump(const std::string& tag) : m_tag(tag) { diff --git a/DDG4/src/Geant4DetectorConstruction.cpp b/DDG4/src/Geant4DetectorConstruction.cpp index 1eddbf989..2b0efa9ef 100644 --- a/DDG4/src/Geant4DetectorConstruction.cpp +++ b/DDG4/src/Geant4DetectorConstruction.cpp @@ -20,8 +20,6 @@ #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Helper: Assign sensitive detector to logical volume @@ -81,7 +79,7 @@ void Geant4DetectorConstructionSequence::adopt(Geant4DetectorConstruction* actio m_actors.add(action); return; } - except("Geant4RunActionSequence","++ Attempt to add an invalid actor!"); + except("++ Attempt to add an invalid actor!"); } /// Access an actor by name @@ -91,8 +89,8 @@ Geant4DetectorConstruction* Geant4DetectorConstructionSequence::get(const std::s return i; } } - except("Geant4RunActionSequence","++ Attempt to access invalid actor %s!",nam.c_str()); - return 0; + except("++ Attempt to access invalid actor %s!",nam.c_str()); + return nullptr; } /// Geometry construction callback. Called at "Construct()" @@ -111,49 +109,47 @@ void Geant4DetectorConstructionSequence::constructSensitives(Geant4DetectorConst } /// Access to the converted regions -const map& Geant4DetectorConstructionSequence::regions() const { +const std::map& +Geant4DetectorConstructionSequence::regions() const { Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); if ( p ) return p->g4Regions; throw std::runtime_error("+++ Geant4DetectorConstructionSequence::regions: Access not possible. Geometry is not yet converted!"); } -#if 0 -/// Access to the converted sensitive detectors -const Geant4GeometryMaps::SensDetMap& Geant4DetectorConstructionSequence::sensitives() const { - Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); - if ( p ) return p->g4SensDets; - throw std::runtime_error("+++ Geant4DetectorConstructionSequence::sensitives: Access not possible. Geometry is not yet converted!"); -} -#endif + /// Access to the converted volumes -const map& Geant4DetectorConstructionSequence::volumes() const { +const std::map& +Geant4DetectorConstructionSequence::volumes() const { Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); if ( p ) return p->g4Volumes; throw std::runtime_error("+++ Geant4DetectorConstructionSequence::volumes: Access not possible. Geometry is not yet converted!"); } /// Access to the converted shapes -const map& Geant4DetectorConstructionSequence::shapes() const { +const std::map& Geant4DetectorConstructionSequence::shapes() const { Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); if ( p ) return p->g4Solids; throw std::runtime_error("+++ Geant4DetectorConstructionSequence::shapes: Access not possible. Geometry is not yet converted!"); } /// Access to the converted limit sets -const map& Geant4DetectorConstructionSequence::limits() const { +const std::map& +Geant4DetectorConstructionSequence::limits() const { Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); if ( p ) return p->g4Limits; throw std::runtime_error("+++ Geant4DetectorConstructionSequence::limits: Access not possible. Geometry is not yet converted!"); } /// Access to the converted assemblies -const map& Geant4DetectorConstructionSequence::assemblies() const { +const std::map& +Geant4DetectorConstructionSequence::assemblies() const { Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); if ( p ) return p->g4AssemblyVolumes; throw std::runtime_error("+++ Geant4DetectorConstructionSequence::assemblies: Access not possible. Geometry is not yet converted!"); } /// Access to the converted placements -const map& Geant4DetectorConstructionSequence::placements() const { +const std::map& +Geant4DetectorConstructionSequence::placements() const { Geant4GeometryInfo* p = Geant4Mapping::instance().ptr(); if ( p ) return p->g4Placements; throw std::runtime_error("+++ Geant4DetectorConstructionSequence::placements: Access not possible. Geometry is not yet converted!"); diff --git a/DDG4/src/Geant4EventAction.cpp b/DDG4/src/Geant4EventAction.cpp index 5e12acdb0..3974a839b 100644 --- a/DDG4/src/Geant4EventAction.cpp +++ b/DDG4/src/Geant4EventAction.cpp @@ -14,13 +14,11 @@ // Framework include files #include "DD4hep/InstanceCount.h" #include "DDG4/Geant4EventAction.h" + // Geant4 headers #include "G4Threading.hh" #include "G4AutoLock.hh" -// C/C++ include files -#include -using namespace std; using namespace dd4hep::sim; namespace { @@ -28,7 +26,7 @@ namespace { } /// Standard constructor -Geant4EventAction::Geant4EventAction(Geant4Context* ctxt, const string& nam) +Geant4EventAction::Geant4EventAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { InstanceCount::increment(this); @@ -48,7 +46,7 @@ void Geant4EventAction::end(const G4Event* ) { } /// Standard constructor -Geant4SharedEventAction::Geant4SharedEventAction(Geant4Context* ctxt, const string& nam) +Geant4SharedEventAction::Geant4SharedEventAction(Geant4Context* ctxt, const std::string& nam) : Geant4EventAction(ctxt, nam) { InstanceCount::increment(this); @@ -73,7 +71,7 @@ void Geant4SharedEventAction::use(Geant4EventAction* action) { m_action = action; return; } - throw runtime_error("Geant4SharedEventAction: Attempt to use invalid actor!"); + except("Geant4SharedEventAction: Attempt to use invalid actor!"); } /// Begin-of-event callback @@ -97,7 +95,7 @@ void Geant4SharedEventAction::end(const G4Event* event) { } /// Standard constructor -Geant4EventActionSequence::Geant4EventActionSequence(Geant4Context* ctxt, const string& nam) +Geant4EventActionSequence::Geant4EventActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = true; InstanceCount::increment(this); @@ -125,7 +123,7 @@ void Geant4EventActionSequence::configureFiber(Geant4Context* thread_context) } /// Get an action by name -Geant4EventAction* Geant4EventActionSequence::get(const string& nam) const { +Geant4EventAction* Geant4EventActionSequence::get(const std::string& nam) const { return m_actors.get(FindByName(TypeName::split(nam).second)); } @@ -137,7 +135,7 @@ void Geant4EventActionSequence::adopt(Geant4EventAction* action) { m_actors.add(action); return; } - throw runtime_error("Geant4EventActionSequence: Attempt to add invalid actor!"); + except("Geant4EventActionSequence: Attempt to add invalid actor!"); } /// Pre-track action callback diff --git a/DDG4/src/Geant4Exec.cpp b/DDG4/src/Geant4Exec.cpp index 1c7ef0260..e1aa5e6fc 100644 --- a/DDG4/src/Geant4Exec.cpp +++ b/DDG4/src/Geant4Exec.cpp @@ -12,35 +12,35 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/Primitives.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/Handle.h" -#include "DDG4/Geant4RunAction.h" -#include "DDG4/Geant4EventAction.h" -#include "DDG4/Geant4SteppingAction.h" -#include "DDG4/Geant4TrackingAction.h" -#include "DDG4/Geant4StackingAction.h" -#include "DDG4/Geant4GeneratorAction.h" -#include "DDG4/Geant4UserInitialization.h" -#include "DDG4/Geant4DetectorConstruction.h" -#include "DDG4/Geant4PhysicsList.h" -#include "DDG4/Geant4UIManager.h" -#include "DDG4/Geant4Kernel.h" -#include "DDG4/Geant4Random.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Geant4 include files -#include "G4Version.hh" -#include "G4UserRunAction.hh" -#include "G4UserEventAction.hh" -#include "G4UserTrackingAction.hh" -#include "G4UserStackingAction.hh" -#include "G4UserSteppingAction.hh" -#include "G4VUserPhysicsList.hh" -#include "G4VModularPhysicsList.hh" -#include "G4VUserPrimaryGeneratorAction.hh" -#include "G4VUserActionInitialization.hh" -#include "G4VUserDetectorConstruction.hh" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // C/C++ include files #include @@ -56,6 +56,8 @@ namespace dd4hep { /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit namespace sim { + class Geant4DetectorConstructionSequence; + /// Sequence handler implementing common actions to all sequences. /** @class SequenceHdl * @@ -489,38 +491,36 @@ namespace dd4hep { m_sequence->buildMaster(); } } + + /// Compatibility actions for running Geant4 in single threaded mode + /** @class Geant4Compatibility + * + * @author M.Frank + * @version 1.0 + */ + class Geant4Compatibility { + public: + /// Default constructor + Geant4Compatibility() = default; + /// Default destructor + virtual ~Geant4Compatibility() = default; + /// Detector construction invocation in compatibility mode + Geant4DetectorConstructionSequence* buildDefaultDetectorConstruction(Geant4Kernel& kernel); + }; + } } -#include "DD4hep/Detector.h" -#include "DD4hep/Plugins.h" -#include "DDG4/Geant4DetectorConstruction.h" -#include "DDG4/Geant4Kernel.h" +#include +#include +#include +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; // Geant4 include files -#include "G4RunManager.hh" -#include "G4PhysListFactory.hh" - - -/// Compatibility actions for running Geant4 in single threaded mode -/** @class Geant4Compatibility - * - * @author M.Frank - * @version 1.0 - */ -class Geant4Compatibility { -public: - /// Default constructor - Geant4Compatibility() = default; - /// Default destructor - virtual ~Geant4Compatibility() = default; - /// Detector construction invocation in compatibility mode - Geant4DetectorConstructionSequence* buildDefaultDetectorConstruction(Geant4Kernel& kernel); -}; +#include +#include /// Detector construction invocation in compatibility mode Geant4DetectorConstructionSequence* Geant4Compatibility::buildDefaultDetectorConstruction(Geant4Kernel& kernel) { @@ -531,19 +531,19 @@ Geant4DetectorConstructionSequence* Geant4Compatibility::buildDefaultDetectorCon printout(WARNING, "Geant4Exec", "+++ Building default Geant4DetectorConstruction for single threaded compatibility."); /// Attach first the geometry converter from dd4hep to Geant4 - cr = PluginService::Create("Geant4DetectorGeometryConstruction",ctx,string("ConstructGeometry")); + cr = PluginService::Create("Geant4DetectorGeometryConstruction",ctx,std::string("ConstructGeometry")); det_cr = dynamic_cast(cr); if ( det_cr ) seq->adopt(det_cr); else - throw runtime_error("Panic! Failed to build Geant4DetectorGeometryConstruction."); + throw std::runtime_error("Panic! Failed to build Geant4DetectorGeometryConstruction."); /// Attach the sensitive detector manipulator: - cr = PluginService::Create("Geant4DetectorSensitivesConstruction",ctx,string("ConstructSensitives")); + cr = PluginService::Create("Geant4DetectorSensitivesConstruction",ctx,std::string("ConstructSensitives")); det_cr = dynamic_cast(cr); if ( det_cr ) seq->adopt(det_cr); else - throw runtime_error("Panic! Failed to build Geant4DetectorSensitivesConstruction."); + throw std::runtime_error("Panic! Failed to build Geant4DetectorSensitivesConstruction."); return seq; } @@ -574,7 +574,7 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { /// Get the detector constructed Geant4DetectorConstructionSequence* user_det = kernel.detectorConstruction(false); if ( nullptr == user_det && kernel.isMultiThreaded() ) { - throw runtime_error("Panic! No valid detector construction sequencer present. [Mandatory MT]"); + throw std::runtime_error("Panic! No valid detector construction sequencer present. [Mandatory MT]"); } if ( nullptr == user_det && !kernel.isMultiThreaded() ) { user_det = Geant4Compatibility().buildDefaultDetectorConstruction(kernel); @@ -585,13 +585,13 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { /// Get the physics list constructed Geant4PhysicsListActionSequence* phys_seq = kernel.physicsList(false); if ( nullptr == phys_seq ) { - string phys_model = "QGSP_BERT"; + std::string phys_model = "QGSP_BERT"; phys_seq = kernel.physicsList(true); phys_seq->property("extends").set(phys_model); } G4VUserPhysicsList* physics = phys_seq->extensionList(); if (nullptr == physics) { - throw runtime_error("Panic! No valid user physics list present!"); + throw std::runtime_error("Panic! No valid user physics list present!"); } #if 0 /// Not here: Use seperate object to do this! @@ -606,7 +606,7 @@ int Geant4Exec::configure(Geant4Kernel& kernel) { /// Construct the remaining user initialization in multi-threaded mode Geant4UserInitializationSequence* user_init = kernel.userInitialization(false); if ( nullptr == user_init && kernel.isMultiThreaded() ) { - throw runtime_error("Panic! No valid user initialization sequencer present. [Mandatory MT]"); + throw std::runtime_error("Panic! No valid user initialization sequencer present. [Mandatory MT]"); } else if ( nullptr == user_init && !kernel.isMultiThreaded() ) { /// Use default actions registered to the default kernel. Will do the right thing... @@ -632,7 +632,7 @@ int Geant4Exec::initialize(Geant4Kernel& kernel) { /// Run the simulation int Geant4Exec::run(Geant4Kernel& kernel) { Property& p = kernel.property("UI"); - string value = p.value(); + std::string value = p.value(); kernel.executePhase("start",0); if ( !value.empty() ) { @@ -646,7 +646,7 @@ int Geant4Exec::run(Geant4Kernel& kernel) { } ui->except("++ Geant4Exec: Failed to start UI interface."); } - throw runtime_error(format("Geant4Exec","++ Failed to locate UI interface %s.",value.c_str())); + throw std::runtime_error(format("Geant4Exec","++ Failed to locate UI interface %s.",value.c_str())); } long nevt = kernel.property("NumEvents").value(); kernel.runManager().BeamOn(nevt); diff --git a/DDG4/src/Geant4FastSimShowerModel.cpp b/DDG4/src/Geant4FastSimShowerModel.cpp index de30aa2cd..417bd0ec0 100644 --- a/DDG4/src/Geant4FastSimShowerModel.cpp +++ b/DDG4/src/Geant4FastSimShowerModel.cpp @@ -26,7 +26,6 @@ // C/C++ include files #include -using namespace dd4hep; using namespace dd4hep::sim; /// Namespace for the AIDA detector description toolkit diff --git a/DDG4/src/Geant4GDMLDetector.cpp b/DDG4/src/Geant4GDMLDetector.cpp index a24101659..b7634f2cf 100644 --- a/DDG4/src/Geant4GDMLDetector.cpp +++ b/DDG4/src/Geant4GDMLDetector.cpp @@ -12,7 +12,7 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4GDMLDetector.h" +#include // C/C++ include files #include @@ -23,9 +23,6 @@ #include "G4GDMLParser.hh" #endif -using namespace std; -using namespace dd4hep; - dd4hep::sim::Geant4GDMLDetector::Geant4GDMLDetector(const std::string& gdmlFile) : m_fileName(gdmlFile), m_world(0) { } diff --git a/DDG4/src/Geant4GeneratorAction.cpp b/DDG4/src/Geant4GeneratorAction.cpp index 1d9cfce8c..df31ea3d8 100644 --- a/DDG4/src/Geant4GeneratorAction.cpp +++ b/DDG4/src/Geant4GeneratorAction.cpp @@ -12,16 +12,14 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4GeneratorAction.h" -#include "DDG4/Geant4Kernel.h" +#include +#include +#include + // Geant4 headers -#include "G4Threading.hh" -#include "G4AutoLock.hh" -// C/C++ include files -#include +#include +#include -using namespace std; using namespace dd4hep::sim; namespace { @@ -29,7 +27,7 @@ namespace { } /// Standard constructor -Geant4GeneratorAction::Geant4GeneratorAction(Geant4Context* ctxt, const string& nam) +Geant4GeneratorAction::Geant4GeneratorAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { InstanceCount::increment(this); } @@ -40,7 +38,7 @@ Geant4GeneratorAction::~Geant4GeneratorAction() { } /// Standard constructor -Geant4SharedGeneratorAction::Geant4SharedGeneratorAction(Geant4Context* ctxt, const string& nam) +Geant4SharedGeneratorAction::Geant4SharedGeneratorAction(Geant4Context* ctxt, const std::string& nam) : Geant4GeneratorAction(ctxt, nam), m_action(0) { InstanceCount::increment(this); @@ -64,7 +62,7 @@ void Geant4SharedGeneratorAction::use(Geant4GeneratorAction* action) { m_action = action; return; } - throw runtime_error("Geant4SharedGeneratorAction: Attempt to use invalid actor!"); + throw std::runtime_error("Geant4SharedGeneratorAction: Attempt to use invalid actor!"); } /// User generator callback @@ -78,7 +76,7 @@ void Geant4SharedGeneratorAction::operator()(G4Event* event) { } /// Standard constructor -Geant4GeneratorActionSequence::Geant4GeneratorActionSequence(Geant4Context* ctxt, const string& nam) +Geant4GeneratorActionSequence::Geant4GeneratorActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = true; InstanceCount::increment(this); @@ -104,7 +102,7 @@ void Geant4GeneratorActionSequence::configureFiber(Geant4Context* thread_context } /// Get an action by name -Geant4GeneratorAction* Geant4GeneratorActionSequence::get(const string& nam) const { +Geant4GeneratorAction* Geant4GeneratorActionSequence::get(const std::string& nam) const { return m_actors.get(FindByName(TypeName::split(nam).second)); } @@ -116,7 +114,7 @@ void Geant4GeneratorActionSequence::adopt(Geant4GeneratorAction* action) { m_actors.add(action); return; } - throw runtime_error("Geant4GeneratorActionSequence: Attempt to add invalid actor!"); + except("Attempt to add invalid actor!"); } /// Generator callback diff --git a/DDG4/src/Geant4GeneratorWrapper.cpp b/DDG4/src/Geant4GeneratorWrapper.cpp index 858300e5f..a7ab068e0 100644 --- a/DDG4/src/Geant4GeneratorWrapper.cpp +++ b/DDG4/src/Geant4GeneratorWrapper.cpp @@ -12,30 +12,29 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4GeneratorWrapper.h" +#include -#include "DD4hep/InstanceCount.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Printout.h" -#include "DDG4/Geant4Context.h" -#include "DDG4/Geant4Primary.h" -#include "DDG4/Geant4InputHandling.h" +#include +#include +#include +#include +#include +#include // Geant4 include files -#include "G4Event.hh" -#include "G4PrimaryVertex.hh" -#include "G4PrimaryParticle.hh" -#include "G4VPrimaryGenerator.hh" +#include +#include +#include +#include // C/C++ include files #include #include using namespace dd4hep::sim; -using namespace std; /// Standard constructor -Geant4GeneratorWrapper::Geant4GeneratorWrapper(Geant4Context* ctxt, const string& nam) +Geant4GeneratorWrapper::Geant4GeneratorWrapper(Geant4Context* ctxt, const std::string& nam) : Geant4GeneratorAction(ctxt,nam), m_generator(0) { declareProperty("Uses", m_generatorType); @@ -56,8 +55,8 @@ G4VPrimaryGenerator* Geant4GeneratorWrapper::generator() { PluginDebug dbg; m_generator = PluginService::Create(m_generatorType); if ( !m_generator ) { - throw runtime_error("Geant4GeneratorWrapper: FATAL Failed to " - "create G4VPrimaryGenerator of type " + m_generatorType + "."); + except("Geant4GeneratorWrapper: FATAL Failed to create G4VPrimaryGenerator of type %s.", + m_generatorType.c_str()); } } } @@ -68,7 +67,7 @@ G4VPrimaryGenerator* Geant4GeneratorWrapper::generator() { void Geant4GeneratorWrapper::operator()(G4Event* event) { Geant4PrimaryEvent* prim = context()->event().extension(); Geant4PrimaryMap* primaryMap = context()->event().extension(); - set primaries; + std::set primaries; // Now generate the new interaction generator()->GeneratePrimaryVertex(event); diff --git a/DDG4/src/Geant4GeometryInfo.cpp b/DDG4/src/Geant4GeometryInfo.cpp index 84639f29e..666df2fa8 100644 --- a/DDG4/src/Geant4GeometryInfo.cpp +++ b/DDG4/src/Geant4GeometryInfo.cpp @@ -12,21 +12,17 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4GeometryInfo.h" -#include "DDG4/Geant4AssemblyVolume.h" +#include +#include +#include // Geant4 include files -#include "G4VPhysicalVolume.hh" +#include -// C/C++ include files -#include - -using namespace std; using namespace dd4hep::sim; - -string Geant4GeometryInfo::placementPath(const Geant4PlacementPath& path, bool reverse) { - string path_name; +std::string Geant4GeometryInfo::placementPath(const Geant4PlacementPath& path, bool reverse) { + std::string path_name; if ( reverse ) { for (Geant4PlacementPath::const_reverse_iterator pIt = path.rbegin(); pIt != path.rend(); ++pIt) { path_name += "/"; path_name += (*pIt)->GetName(); @@ -55,7 +51,8 @@ Geant4GeometryInfo::~Geant4GeometryInfo() { /// The world placement G4VPhysicalVolume* Geant4GeometryInfo::world() const { if ( m_world ) return m_world; - throw runtime_error("Geant4GeometryInfo: Attempt to access invalid world placement"); + except("Geant4GeometryInfo", "Attempt to access invalid world placement"); + return m_world; } /// Set the world placement @@ -63,7 +60,7 @@ void Geant4GeometryInfo::setWorld(const TGeoNode* node) { Geant4GeometryMaps::PlacementMap::const_iterator g4it = g4Placements.find(node); G4VPhysicalVolume* g4 = (g4it == g4Placements.end()) ? 0 : (*g4it).second; if (!g4) { - throw runtime_error("Geant4GeometryInfo: Attempt to SET invalid world placement"); + except("Geant4GeometryInfo", "Attempt to SET invalid world placement"); } m_world = g4; } diff --git a/DDG4/src/Geant4Handle.cpp b/DDG4/src/Geant4Handle.cpp index caaac4956..25a73c67c 100644 --- a/DDG4/src/Geant4Handle.cpp +++ b/DDG4/src/Geant4Handle.cpp @@ -12,33 +12,28 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Printout.h" - -#include "DDG4/Geant4Handle.h" -#include "DDG4/Geant4Kernel.h" -#include "DDG4/Geant4GeneratorAction.h" -#include "DDG4/Geant4RunAction.h" -#include "DDG4/Geant4EventAction.h" -#include "DDG4/Geant4TrackingAction.h" -#include "DDG4/Geant4SteppingAction.h" -#include "DDG4/Geant4StackingAction.h" -#include "DDG4/Geant4SensDetAction.h" -#include "DDG4/Geant4PhysicsList.h" -#include "DDG4/Geant4ActionPhase.h" -#include "DDG4/Geant4UserInitialization.h" -#include "DDG4/Geant4DetectorConstruction.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Geant4 include files -#include "G4Threading.hh" -#include "G4AutoLock.hh" +#include +#include -// C/C++ include files -#include - -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; namespace { G4Mutex creation_mutex=G4MUTEX_INITIALIZER; @@ -47,7 +42,6 @@ namespace { namespace dd4hep { namespace sim { - template static inline TYPE* checked_value(TYPE* p) { if (p) { return p; @@ -77,14 +71,14 @@ namespace dd4hep { Geant4Context* ctxt = kernel.workerContext(); Geant4Action* object = PluginService::Create(typ.first, ctxt, typ.second); if (!object && typ.first == typ.second) { - string _t = typeName(typeid(TYPE)); + std::string _t = typeName(typeid(TYPE)); printout(DEBUG, "Geant4Handle", "Object factory for %s not found. Try out %s", typ.second.c_str(), _t.c_str()); object = PluginService::Create(_t, ctxt, typ.second); if (!object) { size_t idx = _t.rfind(':'); - if (idx != string::npos) - _t = string(_t.substr(idx + 1)); + if (idx != std::string::npos) + _t = std::string(_t.substr(idx + 1)); printout(DEBUG, "Geant4Handle", "Try out object factory for %s",_t.c_str()); object = PluginService::Create(_t, ctxt, typ.second); } @@ -104,8 +98,8 @@ namespace dd4hep { template TYPE* _create_share(Geant4Kernel& kernel, CONT& (Geant4ActionContainer::*pmf)(), - const string& type_name, - const string& shared_typ, + const std::string& type_name, + const std::string& shared_typ, bool shared, TYPE*) { TypeName typ = TypeName::split(type_name); @@ -135,7 +129,7 @@ namespace dd4hep { } template - Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool /* shared */) { + Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, bool /* shared */) { value = _create_object(kernel,TypeName::split(type_name)); } @@ -164,7 +158,7 @@ namespace dd4hep { value->addRef(); } - template Property& Geant4Handle::operator[](const string& property_name) const { + template Property& Geant4Handle::operator[](const std::string& property_name) const { PropertyManager& pm = checked_value(value)->properties(); return pm[property_name]; } @@ -238,7 +232,7 @@ namespace dd4hep { } template <> - Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared) { + Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, bool shared) { value = _create_share(kernel,&Geant4ActionContainer::runAction, type_name, "Geant4SharedRunAction", shared, null()); } @@ -249,7 +243,7 @@ namespace dd4hep { } template <> - Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared) { + Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, bool shared) { value = _create_share(kernel,&Geant4ActionContainer::eventAction, type_name, "Geant4SharedEventAction", shared, null()); } @@ -260,7 +254,7 @@ namespace dd4hep { } template <> - Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared) { + Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, bool shared) { value = _create_share(kernel,&Geant4ActionContainer::generatorAction, type_name, "Geant4SharedGeneratorAction", shared, null()); } @@ -271,7 +265,7 @@ namespace dd4hep { } template <> - Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared) { + Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, bool shared) { value = _create_share(kernel,&Geant4ActionContainer::trackingAction, type_name, "Geant4SharedTrackingAction", shared, null()); } @@ -282,7 +276,7 @@ namespace dd4hep { } template <> - Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared) { + Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, bool shared) { value = _create_share(kernel,&Geant4ActionContainer::steppingAction, type_name, "Geant4SharedSteppingAction", shared, null()); } @@ -293,7 +287,7 @@ namespace dd4hep { } template <> - Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, bool shared) { + Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, bool shared) { value = _create_share(kernel,&Geant4ActionContainer::stackingAction, type_name, "Geant4SharedStackingAction", shared, null()); } @@ -303,8 +297,8 @@ namespace dd4hep { "Geant4SharedStackingAction", shared, null()); } - template <> Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const string& type_name, - const string& detector, bool /* shared */) { + template <> Geant4Handle::Geant4Handle(Geant4Kernel& kernel, const std::string& type_name, + const std::string& detector, bool /* shared */) { try { Geant4Context* ctxt = kernel.workerContext(); TypeName typ = TypeName::split(type_name); @@ -316,7 +310,7 @@ namespace dd4hep { return; } } - catch (const exception& e) { + catch (const std::exception& e) { printout(ERROR, "Geant4Handle", "Exception: %s", e.what()); } catch (...) { diff --git a/DDG4/src/Geant4HierarchyDump.cpp b/DDG4/src/Geant4HierarchyDump.cpp index 190d3480f..faa790e03 100644 --- a/DDG4/src/Geant4HierarchyDump.cpp +++ b/DDG4/src/Geant4HierarchyDump.cpp @@ -12,47 +12,47 @@ //========================================================================== // Framework include files -#include "DD4hep/Detector.h" -#include "DD4hep/Plugins.h" -#include "DD4hep/Volumes.h" -#include "DD4hep/Printout.h" -#include "DDG4/Geant4HierarchyDump.h" +#include +#include +#include +#include +#include // Geant4 include files -#include "G4Version.hh" -#include "G4VisAttributes.hh" -#include "G4ProductionCuts.hh" -#include "G4VUserRegionInformation.hh" -#include "G4Element.hh" -#include "G4SDManager.hh" +#include +#include +#include +#include +#include +#include -#include "G4AssemblyVolume.hh" -#include "G4Box.hh" -#include "G4Trd.hh" -#include "G4Tubs.hh" -#include "G4Cons.hh" -#include "G4Torus.hh" -#include "G4Sphere.hh" -#include "G4Polycone.hh" -#include "G4Polyhedra.hh" -#include "G4UnionSolid.hh" -#include "G4Paraboloid.hh" -#include "G4SubtractionSolid.hh" -#include "G4IntersectionSolid.hh" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "G4Region.hh" -#include "G4UserLimits.hh" -#include "G4VSensitiveDetector.hh" +#include +#include +#include -#include "G4LogicalVolume.hh" -#include "G4Material.hh" -#include "G4Element.hh" -#include "G4Isotope.hh" -#include "G4Transform3D.hh" -#include "G4ThreeVector.hh" -#include "G4PVPlacement.hh" -#include "G4ElectroMagneticField.hh" -#include "G4FieldManager.hh" +#include +#include +#include +#include +#include +#include +#include +#include +#include // C/C++ include files #include @@ -60,8 +60,6 @@ #include using namespace dd4hep::sim; -using namespace dd4hep; -using namespace std; static const char* _T(const std::string& str) { return str.c_str(); @@ -78,7 +76,7 @@ Geant4HierarchyDump::Geant4HierarchyDump(Detector& description, unsigned long fl Geant4HierarchyDump::~Geant4HierarchyDump() { } -void Geant4HierarchyDump::dump(const string& indent, const G4VPhysicalVolume* v) const { +void Geant4HierarchyDump::dump(const std::string& indent, const G4VPhysicalVolume* v) const { G4LogicalVolume* lv = v->GetLogicalVolume(); G4VSensitiveDetector* sd = lv->GetSensitiveDetector(); G4RotationMatrix* rot = v->GetObjectRotation(); @@ -87,7 +85,7 @@ void Geant4HierarchyDump::dump(const string& indent, const G4VPhysicalVolume* v) G4Region* rg = lv->GetRegion(); G4UserLimits* ul = lv->GetUserLimits(); G4int ndau = lv->GetNoDaughters(); - stringstream str; + std::stringstream str; char text[32]; printout(INFO, "Geant4Hierarchy", "%s -> Placement:%s LV:%s Material:%s Solid:%s # of Daughters:%d CopyNo:%d", diff --git a/DDG4/src/Geant4HitCollection.cpp b/DDG4/src/Geant4HitCollection.cpp index 6c18230d0..0f93da6a1 100644 --- a/DDG4/src/Geant4HitCollection.cpp +++ b/DDG4/src/Geant4HitCollection.cpp @@ -12,12 +12,11 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4HitCollection.h" -#include "DDG4/Geant4Data.h" -#include "G4Allocator.hh" +#include +#include +#include +#include -using namespace dd4hep; using namespace dd4hep::sim; G4ThreadLocal G4Allocator* HitWrapperAllocator = 0; @@ -85,12 +84,12 @@ Geant4HitCollection::~Geant4HitCollection() { } /// Type information of the object stored -const ComponentCast& Geant4HitCollection::type() const { +const dd4hep::ComponentCast& Geant4HitCollection::type() const { return m_manipulator->cast; } /// Type information of the vector type for extracting data -const ComponentCast& Geant4HitCollection::vector_type() const { +const dd4hep::ComponentCast& Geant4HitCollection::vector_type() const { return m_manipulator->vec_type; } diff --git a/DDG4/src/Geant4HitHandler.cpp b/DDG4/src/Geant4HitHandler.cpp index 4cac25dd4..456d5bcb6 100644 --- a/DDG4/src/Geant4HitHandler.cpp +++ b/DDG4/src/Geant4HitHandler.cpp @@ -19,44 +19,43 @@ // Geant4 include files #include -using namespace dd4hep; using namespace dd4hep::sim; /// Coordinate transformation to global coordinate. -Position Geant4HitHandler::localToGlobal(const DDSegmentation::Vector3D& local) const { +dd4hep::Position Geant4HitHandler::localToGlobal(const DDSegmentation::Vector3D& local) const { return localToGlobal(G4ThreeVector(local.X / dd4hep::mm,local.Y / dd4hep::mm,local.Z / dd4hep::mm)); } /// Coordinate transformation to global coordinates. -Position Geant4HitHandler::localToGlobal(const Position& local) const { +dd4hep::Position Geant4HitHandler::localToGlobal(const Position& local) const { return localToGlobal(G4ThreeVector(local.X(),local.Y(),local.Z())); } /// Coordinate transformation to global coordinates -Position Geant4HitHandler::localToGlobal(double x, double y, double z) const { +dd4hep::Position Geant4HitHandler::localToGlobal(double x, double y, double z) const { return localToGlobal(G4ThreeVector(x,y,z)); } /// Coordinate transformation to global coordinates -Position Geant4HitHandler::localToGlobal(const G4ThreeVector& loc) const { +dd4hep::Position Geant4HitHandler::localToGlobal(const G4ThreeVector& loc) const { G4ThreeVector p = touchable_ptr->GetHistory()->GetTopTransform().Inverse().TransformPoint(loc); return Position(p.x(),p.y(),p.z()); } /// Coordinate transformation to local coordinates -Position Geant4HitHandler::globalToLocal(double x, double y, double z) const { +dd4hep::Position Geant4HitHandler::globalToLocal(double x, double y, double z) const { G4ThreeVector p = globalToLocalG4(G4ThreeVector(x,y,z)); return Position(p.x(),p.y(),p.z()); } /// Coordinate transformation to local coordinates -Position Geant4HitHandler::globalToLocal(const Position& global) const { +dd4hep::Position Geant4HitHandler::globalToLocal(const Position& global) const { G4ThreeVector p = globalToLocalG4(G4ThreeVector(global.X(),global.Y(),global.Z())); return Position(p.x(),p.y(),p.z()); } /// Coordinate transformation to local coordinates -Position Geant4HitHandler::globalToLocal(const G4ThreeVector& global) const { +dd4hep::Position Geant4HitHandler::globalToLocal(const G4ThreeVector& global) const { G4ThreeVector p = globalToLocalG4(global); return Position(p.x(),p.y(),p.z()); } diff --git a/DDG4/src/Geant4InputAction.cpp b/DDG4/src/Geant4InputAction.cpp index 05dfd7b5d..04917c45c 100644 --- a/DDG4/src/Geant4InputAction.cpp +++ b/DDG4/src/Geant4InputAction.cpp @@ -13,20 +13,19 @@ //==================================================================== // Framework include files -#include "DD4hep/Memory.h" -#include "DD4hep/Plugins.h" -#include "DDG4/Geant4Primary.h" -#include "DDG4/Geant4Context.h" -#include "DDG4/Geant4Kernel.h" -#include "DDG4/Geant4InputAction.h" -#include "DDG4/Geant4RunAction.h" +#include +#include +#include +#include +#include +#include +#include -#include "G4Event.hh" +#include -using namespace std; using namespace dd4hep::sim; -typedef dd4hep::detail::ReferenceBitMask PropertyMask; -typedef Geant4InputAction::Vertices Vertices ; +using Vertices = Geant4InputAction::Vertices; +using PropertyMask = dd4hep::detail::ReferenceBitMask; /// Initializing constructor @@ -118,7 +117,7 @@ Geant4EventReader::moveToEvent(int /* event_number */) { #endif /// Standard constructor -Geant4InputAction::Geant4InputAction(Geant4Context* ctxt, const string& nam) +Geant4InputAction::Geant4InputAction(Geant4Context* ctxt, const std::string& nam) : Geant4GeneratorAction(ctxt,nam), m_reader(0), m_currentEventNumber(0) { declareProperty("Input", m_input); @@ -148,7 +147,7 @@ void Geant4InputAction::createReader() { if ( m_input.empty() ) { except("InputAction: No input file declared!"); } - string err; + std::string err; TypeName tn = TypeName::split(m_input,"|"); try { m_reader = PluginService::Create(tn.first,tn.second); @@ -163,7 +162,7 @@ void Geant4InputAction::createReader() { m_reader->checkParameters( m_parameters ); m_reader->setInputAction( this ); m_reader->registerRunParameters(); - } catch(const exception& e) { + } catch(const std::exception& e) { err = e.what(); } if ( !err.empty() ) { @@ -173,8 +172,8 @@ void Geant4InputAction::createReader() { /// helper to report Geant4 exceptions -string Geant4InputAction::issue(int i) const { - stringstream str; +std::string Geant4InputAction::issue(int i) const { + std::stringstream str; str << "Geant4InputAction[" << name() << "]: Event " << i << " "; return str.str(); } @@ -197,7 +196,7 @@ int Geant4InputAction::readParticles(int evt_number, } if ( Geant4EventReader::EVENT_READER_OK != status ) { - string msg = issue(evid)+"Error when moving to event - "; + std::string msg = issue(evid)+"Error when moving to event - "; if ( status == Geant4EventReader::EVENT_READER_EOF ) msg += " EOF: [end of file]."; else msg += " Unknown error condition"; if ( m_abort ) { @@ -217,9 +216,8 @@ int Geant4InputAction::readParticles(int evt_number, } } - if ( Geant4EventReader::EVENT_READER_OK != status ) { - string msg = issue(evid)+"Error when moving to event - "; + std::string msg = issue(evid)+"Error when moving to event - "; if ( status == Geant4EventReader::EVENT_READER_EOF ) msg += " EOF: [end of file]."; else msg += " Unknown error condition"; if ( m_abort ) { @@ -234,7 +232,7 @@ int Geant4InputAction::readParticles(int evt_number, /// Callback to generate primary particles void Geant4InputAction::operator()(G4Event* event) { - vector primaries; + std::vector primaries; Geant4Event& evt = context()->event(); Geant4PrimaryEvent* prim = evt.extension(); Vertices vertices ; diff --git a/DDG4/src/Geant4InputHandling.cpp b/DDG4/src/Geant4InputHandling.cpp index 84c1a7a81..61d80dfac 100644 --- a/DDG4/src/Geant4InputHandling.cpp +++ b/DDG4/src/Geant4InputHandling.cpp @@ -30,12 +30,8 @@ #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; - -typedef detail::ReferenceBitMask PropertyMask; - +using PropertyMask = dd4hep::detail::ReferenceBitMask; /// Create a vertex object from the Geant4 primary vertex Geant4Vertex* dd4hep::sim::createPrimary(const G4PrimaryVertex* g4) { @@ -210,8 +206,8 @@ static void rebaseParticles(Geant4PrimaryInteraction::ParticleMap& particles, in static void rebaseVertices(Geant4PrimaryInteraction::VertexMap& vertices, int part_offset) { Geant4PrimaryInteraction::VertexMap::iterator iv, ivend; - set in, out; - set::iterator i; + std::set in, out; + std::set::iterator i; // Now move begin and end-vertex of all primary vertices accordingly for(iv=vertices.begin(), ivend=vertices.end(); iv != ivend; ++iv) { for( Geant4Vertex* v : (*iv).second ){ @@ -229,7 +225,7 @@ int dd4hep::sim::mergeInteractions(const Geant4Action* caller, const Geant4Context* context) { typedef Geant4PrimaryEvent::Interaction Interaction; - typedef vector Interactions; + typedef std::vector Interactions; Geant4Event& event = context->event(); Geant4PrimaryEvent* evt = event.extension(); Interaction* output = event.extension(); @@ -365,14 +361,16 @@ static G4PrimaryParticle* createG4Primary(const Geant4ParticleHandle p) { return g4; } -static vector< pair > -getRelevant(set& visited, - map& prim, +static std::vector< std::pair > +getRelevant(std::set& visited, + std::map& prim, Geant4PrimaryInteraction::ParticleMap& pm, const Geant4PrimaryConfig& primaryConfig, const Geant4ParticleHandle p) { - typedef vector< pair > Primaries; + typedef std::vector< std::pair > Primaries; + using dd4hep::printout; + Primaries res; visited.insert(p->id); PropertyMask status(p->status); @@ -413,13 +411,13 @@ getRelevant(set& visited, // end running simulation if we have a really inconsistent record, that is unrejected stable particle with children bool failStableWithChildren = (not rejectParticle and p.definition()->GetPDGStable()); if (failStableWithChildren) { - printout(FATAL,"Input", + printout(dd4hep::FATAL,"Input", "+++ Stable particle (PDG: %-10d) with daughters! check your MC record, adapt particle.tbl file...", p->pdgID); throw std::runtime_error("Cannot Simmulate this MC Record"); } if (not rejectParticle) { - map::iterator ip4 = prim.find(p->id); + std::map::iterator ip4 = prim.find(p->id); G4PrimaryParticle* p4 = (ip4 == prim.end()) ? 0 : (*ip4).second; if ( !p4 ) { p4 = createG4Primary(p); @@ -454,14 +452,14 @@ int dd4hep::sim::generatePrimaries(const Geant4Action* caller, const Geant4Context* context, G4Event* event) { - typedef vector< pair > Primaries; + typedef std::vector< std::pair > Primaries; typedef Geant4PrimaryInteraction Interaction; Geant4PrimaryMap* primaries = context->event().extension(); Interaction* interaction = context->event().extension(); Interaction::ParticleMap& pm = interaction->particles; Interaction::VertexMap& vm = interaction->vertices; - map prim; - set visited; + std::map prim; + std::set visited; auto const* primHandler = dynamic_cast(caller); auto const& primaryConfig = primHandler ? primHandler->m_primaryConfig : Geant4PrimaryConfig(); @@ -510,9 +508,9 @@ int dd4hep::sim::generatePrimaries(const Geant4Action* caller, } } } - for(map::iterator i=prim.begin(); i!=prim.end(); ++i) { - Geant4ParticleHandle p = pm[(*i).first]; - primaries->insert((*i).second,p); + for( const auto& vtx : prim ) { + Geant4ParticleHandle p = pm[vtx.first]; + primaries->insert(vtx.second, p); } } return 1; diff --git a/DDG4/src/Geant4IsotropeGenerator.cpp b/DDG4/src/Geant4IsotropeGenerator.cpp index b549442f7..84dc9eda9 100644 --- a/DDG4/src/Geant4IsotropeGenerator.cpp +++ b/DDG4/src/Geant4IsotropeGenerator.cpp @@ -12,16 +12,15 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4Random.h" -#include "DDG4/Geant4IsotropeGenerator.h" +#include +#include +#include +#include -using namespace std; using namespace dd4hep::sim; /// Standard constructor -Geant4IsotropeGenerator::Geant4IsotropeGenerator(Geant4Context* ctxt, const string& nam) +Geant4IsotropeGenerator::Geant4IsotropeGenerator(Geant4Context* ctxt, const std::string& nam) : Geant4ParticleGenerator(ctxt, nam) { InstanceCount::increment(this); diff --git a/DDG4/src/Geant4Kernel.cpp b/DDG4/src/Geant4Kernel.cpp index 64c1f2c2b..c2f2e2d09 100644 --- a/DDG4/src/Geant4Kernel.cpp +++ b/DDG4/src/Geant4Kernel.cpp @@ -30,12 +30,10 @@ #include // C/C++ include files -#include #include #include #include -using namespace std; using namespace dd4hep::sim; namespace { @@ -44,16 +42,17 @@ namespace { void description_unexpected() { try { throw; - } catch( exception& e ) { - cout << "\n" + } + catch( std::exception& e ) { + std::cout << "\n" << "**************************************************** \n" << "* A runtime error has occured : \n" - << "* " << e.what() << endl + << "* " << e.what() << std::endl << "* the program will have to be terminated - sorry. \n" << "**************************************************** \n" - << endl ; + << std::endl; // this provokes ROOT seg fault and stack trace (comment out to avoid it) - exit(1) ; + ::exit(1) ; } } } @@ -80,7 +79,7 @@ Geant4Kernel::PhaseSelector& Geant4Kernel::PhaseSelector::operator=(const PhaseS Geant4ActionPhase& Geant4Kernel::PhaseSelector::operator[](const std::string& nam) const { if( Geant4ActionPhase* action_phase = m_kernel->getPhase(nam) ) return *action_phase; - throw runtime_error(format("Geant4Kernel", "Attempt to access the nonexisting phase '%s'", nam.c_str())); + throw except("Geant4Kernel", "Attempt to access the nonexisting phase '%s'", nam.c_str()); } /// Standard constructor @@ -186,7 +185,8 @@ Geant4Kernel& Geant4Kernel::createWorker() { printout(INFO,"Geant4Kernel","+++ Created worker instance id=%ul",identifier); return *w; } - throw runtime_error(format("Geant4Kernel", "DDG4: Only the master instance may create workers.")); + except("Geant4Kernel", "DDG4: Only the master instance may create workers."); + throw std::runtime_error("Geant4Kernel::createWorker"); } /// Access worker instance by its identifier @@ -206,7 +206,8 @@ Geant4Kernel& Geant4Kernel::worker(unsigned long identifier, bool create_if) else if ( create_if ) { return createWorker(); } - throw runtime_error(format("Geant4Kernel", "DDG4: The Kernel object 0x%p does not exists!",(void*)identifier)); + except("Geant4Kernel", "DDG4: The Kernel object 0x%p does not exists!",(void*)identifier); + throw std::runtime_error("Geant4Kernel::worker"); } /// Access number of workers @@ -273,7 +274,7 @@ G4RunManager& Geant4Kernel::runManager() { Geant4Action* mgr = PluginService::Create(m_runManagerType, m_context, - string("Geant4RunManager")); + std::string("Geant4RunManager")); if ( !mgr ) { except("Geant4Kernel", "+++ Invalid Geant4RunManager class: %s. Aborting.", @@ -291,7 +292,7 @@ G4RunManager& Geant4Kernel::runManager() { } except("Geant4Kernel", "+++ Only the master thread may instantiate a G4RunManager object!"); - throw runtime_error("Is never called -- just to satisfy compiler!"); + throw std::runtime_error("Is never called -- just to satisfy compiler!"); } /// Construct detector geometry using description plugin @@ -352,7 +353,7 @@ int Geant4Kernel::run() { G4cout << G4endl; return result; } - catch(const exception& e) { + catch(const std::exception& e) { printout(FATAL,"Geant4Kernel","+++ Exception while simulating:%s",e.what()); } catch(...) { @@ -397,7 +398,7 @@ int Geant4Kernel::terminate() { */ Geant4Kernel& Geant4Kernel::registerGlobalAction(Geant4Action* action) { if( action ) { - const string& nam = action->name(); + const std::string& nam = action->name(); if( auto i=m_globalActions.find(nam); i == m_globalActions.end() ) { action->addRef(); m_globalActions[nam] = action; @@ -419,7 +420,7 @@ Geant4Action* Geant4Kernel::globalAction(const std::string& nam, bool throw_if_n return (*i).second; if( throw_if_not_present ) { except("Geant4Kernel", "DDG4: The action '%s' is not globally " - "registered. [Action-Missing]", nam.c_str()); + "registered. [Action-Missing]", nam.c_str()); } return nullptr; } @@ -431,7 +432,7 @@ Geant4Action* Geant4Kernel::globalAction(const std::string& nam, bool throw_if_n */ Geant4Kernel& Geant4Kernel::registerGlobalFilter(Geant4Action* filter) { if( filter ) { - const string& nam = filter->name(); + const std::string& nam = filter->name(); if( auto i=m_globalFilters.find(nam); i == m_globalFilters.end()) { filter->addRef(); m_globalFilters[nam] = filter; @@ -451,7 +452,7 @@ Geant4Action* Geant4Kernel::globalFilter(const std::string& filter_name, bool th return (*i).second; if (throw_if_not_present) { except("Geant4Kernel", "DDG4: The filter '%s' is not already globally " - "registered. [Filter-Missing]", filter_name.c_str()); + "registered. [Filter-Missing]", filter_name.c_str()); } return nullptr; } @@ -479,8 +480,12 @@ Geant4ActionPhase* Geant4Kernel::addSimplePhase(const std::string& name, bool th } /// Add a new phase -Geant4ActionPhase* Geant4Kernel::addPhase(const std::string& nam, const type_info& arg0, const type_info& arg1, - const type_info& arg2, bool throw_on_exist) { +Geant4ActionPhase* Geant4Kernel::addPhase(const std::string& nam, + const std::type_info& arg0, + const std::type_info& arg1, + const std::type_info& arg2, + bool throw_on_exist) +{ if( auto i=m_phases.find(nam); i == m_phases.end() ) { Geant4ActionPhase* p = new Geant4ActionPhase(workerContext(), nam, arg0, arg1, arg2); m_phases.emplace(nam, p); diff --git a/DDG4/src/Geant4Mapping.cpp b/DDG4/src/Geant4Mapping.cpp index 5582b9b3e..490f8bd71 100644 --- a/DDG4/src/Geant4Mapping.cpp +++ b/DDG4/src/Geant4Mapping.cpp @@ -12,16 +12,12 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4Mapping.h" - -#include "DD4hep/Printout.h" -#include "DD4hep/VolumeManager.h" -#include "G4PVPlacement.hh" -#include +#include +#include +#include +#include using namespace dd4hep::sim; -using namespace dd4hep; -using namespace std; /// Initializing Constructor Geant4Mapping::Geant4Mapping(const Detector& description_ref) @@ -45,7 +41,7 @@ Geant4Mapping& Geant4Mapping::instance() { void Geant4Mapping::checkValidity() const { if (m_dataPtr) return; - throw runtime_error("Geant4Mapping: Attempt to access an invalid data block!"); + except("Geant4Mapping", "Attempt to access an invalid data block!"); } /// Create new data block. Delete old data block if present. @@ -77,11 +73,12 @@ Geant4VolumeManager Geant4Mapping::volumeManager() const { } return Geant4VolumeManager(Handle < Geant4GeometryInfo > (m_dataPtr)); } - throw runtime_error(format("Geant4Mapping", "Cannot create volume manager without Geant4 geometry info [Invalid-Info]")); + except("Geant4Mapping", "Cannot create volume manager without Geant4 geometry info [Invalid-Info]"); + return {}; } /// Accessor to resolve geometry placements -PlacedVolume Geant4Mapping::placement(const G4VPhysicalVolume* node) const { +dd4hep::PlacedVolume Geant4Mapping::placement(const G4VPhysicalVolume* node) const { checkValidity(); const Geant4GeometryMaps::PlacementMap& pm = m_dataPtr->g4Placements; for( const auto& entry : pm ) { diff --git a/DDG4/src/Geant4Output2ROOT.cpp b/DDG4/src/Geant4Output2ROOT.cpp index 9aae89e22..92490ca10 100644 --- a/DDG4/src/Geant4Output2ROOT.cpp +++ b/DDG4/src/Geant4Output2ROOT.cpp @@ -33,11 +33,9 @@ using namespace dd4hep::sim; -using namespace dd4hep; -using namespace std; /// Standard constructor -Geant4Output2ROOT::Geant4Output2ROOT(Geant4Context* ctxt, const string& nam) +Geant4Output2ROOT::Geant4Output2ROOT(Geant4Context* ctxt, const std::string& nam) : Geant4OutputAction(ctxt, nam), m_file(nullptr), m_tree(nullptr) { declareProperty("Section", m_section = "EVENT"); declareProperty("HandleMCTruth", m_handleMCTruth = true); @@ -70,7 +68,7 @@ void Geant4Output2ROOT::closeOutput() { } /// Create/access tree by name -TTree* Geant4Output2ROOT::section(const string& nam) { +TTree* Geant4Output2ROOT::section(const std::string& nam) { Sections::const_iterator i = m_sections.find(nam); if (i == m_sections.end()) { TDirectory::TContext ctxt(m_file); @@ -83,7 +81,7 @@ TTree* Geant4Output2ROOT::section(const string& nam) { /// Callback to store the Geant4 run information void Geant4Output2ROOT::beginRun(const G4Run* run) { - string fname = m_output; + std::string fname = m_output; if ( m_filesByRun ) { size_t idx = m_output.rfind("."); if ( m_file ) { @@ -91,7 +89,7 @@ void Geant4Output2ROOT::beginRun(const G4Run* run) { } fname = m_output.substr(0, idx); fname += _toString(run->GetRunID(), ".run%08d"); - if ( idx != string::npos ) + if ( idx != std::string::npos ) fname += m_output.substr(idx); } if ( !m_file && !fname.empty() ) { @@ -117,7 +115,7 @@ void Geant4Output2ROOT::beginRun(const G4Run* run) { } /// Fill single EVENT branch entry (Geant4 collection data) -int Geant4Output2ROOT::fill(const string& nam, const ComponentCast& type, void* ptr) { +int Geant4Output2ROOT::fill(const std::string& nam, const ComponentCast& type, void* ptr) { if (m_file) { TBranch* b = 0; Branches::const_iterator i = m_branches.find(nam); @@ -130,7 +128,7 @@ int Geant4Output2ROOT::fill(const string& nam, const ComponentCast& type, void* m_branches.emplace(nam, b); } else { - throw runtime_error("No ROOT TClass object availible for object type:" + typeName(typ)); + throw std::runtime_error("No ROOT TClass object availible for object type:" + typeName(typ)); } } else { @@ -147,7 +145,7 @@ int Geant4Output2ROOT::fill(const string& nam, const ComponentCast& type, void* b->SetAddress(&ptr); int nbytes = b->Fill(); if (nbytes < 0) { - throw runtime_error("Failed to write ROOT collection:" + nam + "!"); + throw std::runtime_error("Failed to write ROOT collection:" + nam + "!"); } return nbytes; } @@ -188,12 +186,12 @@ void Geant4Output2ROOT::saveEvent(OutputContext& /* ctxt */) { Manip* manipulator = Geant4HitWrapper::manipulator(); G4ParticleTable* table = G4ParticleTable::GetParticleTable(); const ParticleMap& pm = parts->particles(); - vector particles; + std::vector particles; particles.reserve(pm.size()); for ( const auto& i : pm ) { - auto* p = i.second; - G4ParticleDefinition* def = table->FindParticle(p->pdgID); - p->charge = int(3.0 * (def ? def->GetPDGCharge() : -1.0)); // Assume e-/pi- + auto* p = i.second; + G4ParticleDefinition* def = table->FindParticle(p->pdgID); + p->charge = int(3.0 * (def ? def->GetPDGCharge() : -1.0)); // Assume e-/pi- particles.emplace_back((ParticleMap::mapped_type*)p); } fill("MCParticles",manipulator->vec_type,&particles); @@ -204,14 +202,14 @@ void Geant4Output2ROOT::saveEvent(OutputContext& /* ctxt */) { /// Callback to store each Geant4 hit collection void Geant4Output2ROOT::saveCollection(OutputContext& /* ctxt */, G4VHitsCollection* collection) { Geant4HitCollection* coll = dynamic_cast(collection); - string hc_nam = collection->GetName(); + std::string hc_nam = collection->GetName(); for(const auto& n : m_disabledCollections) { if ( n == hc_nam ) { return; } } if (coll) { - vector hits; + std::vector hits; coll->getHitsUnchecked(hits); size_t nhits = coll->GetSize(); if ( m_handleMCTruth && m_truth && nhits > 0 ) { @@ -237,7 +235,7 @@ void Geant4Output2ROOT::saveCollection(OutputContext& /* ctxt */, G4VHi } } catch(...) { - printout(ERROR,name(),"+++ Exception while saving collection %s.",hc_nam.c_str()); + error("+++ Exception while saving collection %s.",hc_nam.c_str()); } } fill(hc_nam, coll->vector_type(), &hits); diff --git a/DDG4/src/Geant4OutputAction.cpp b/DDG4/src/Geant4OutputAction.cpp index a49bc42f1..12c433a3f 100644 --- a/DDG4/src/Geant4OutputAction.cpp +++ b/DDG4/src/Geant4OutputAction.cpp @@ -12,22 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4Particle.h" -#include "DDG4/Geant4RunAction.h" -#include "DDG4/Geant4OutputAction.h" +#include +#include +#include +#include +#include // Geant 4 includes -#include "G4HCofThisEvent.hh" -#include "G4Event.hh" +#include +#include using namespace dd4hep::sim; -using namespace dd4hep; -using namespace std; /// Standard constructor -Geant4OutputAction::Geant4OutputAction(Geant4Context* ctxt, const string& nam) +Geant4OutputAction::Geant4OutputAction(Geant4Context* ctxt, const std::string& nam) : Geant4EventAction(ctxt, nam), m_truth(0) { InstanceCount::increment(this); @@ -73,7 +71,7 @@ void Geant4OutputAction::end(const G4Event* evt) { saveCollection(ctxt, hc); } } - catch(const exception& e) { + catch(const std::exception& e) { printout(ERROR,name(),"+++ [Event:%d] Exception while saving event:%s", evt->GetEventID(),e.what()); if ( m_errorFatal ) throw; @@ -85,7 +83,7 @@ void Geant4OutputAction::end(const G4Event* evt) { } commit(ctxt); } - catch(const exception& e) { + catch(const std::exception& e) { printout(ERROR,name(),"+++ [Event:%d] Exception while saving event:%s", evt->GetEventID(),e.what()); if ( m_errorFatal ) throw; diff --git a/DDG4/src/Geant4Particle.cpp b/DDG4/src/Geant4Particle.cpp index a23810937..10d86ef9f 100644 --- a/DDG4/src/Geant4Particle.cpp +++ b/DDG4/src/Geant4Particle.cpp @@ -27,13 +27,12 @@ #include #include +// C/C++ include files #include #include #include -using namespace dd4hep; using namespace dd4hep::sim; -typedef detail::ReferenceBitMask PropertyMask; /// Default destructor ParticleExtension::~ParticleExtension() { @@ -385,6 +384,7 @@ void Geant4ParticleHandle::header4(int level, const std::string& src, const char } void Geant4ParticleHandle::dump4(int level, const std::string& src, const char* tag) const { + using PropertyMask = dd4hep::detail::ReferenceBitMask; Geant4ParticleHandle p(*this); //char equiv[32]; PropertyMask mask(p->reason); @@ -495,32 +495,31 @@ void Geant4ParticleMap::clear() { void Geant4ParticleMap::dump() const { int cnt; char text[64]; - using namespace std; const Geant4ParticleMap* m = this; cnt = 0; - cout << "Particle map:" << endl; + std::cout << "Particle map:" << std::endl; for( const auto& p : m->particleMap ) { - ::snprintf(text,sizeof(text)," [%-4d:%p]",p.second->id,(void*)p.second); - cout << text; + std::snprintf(text,sizeof(text)," [%-4d:%p]",p.second->id,(void*)p.second); + std::cout << text; if ( ++cnt == 8 ) { - cout << endl; + std::cout << std::endl; cnt = 0; } } - cout << endl; + std::cout << std::endl; cnt = 0; - cout << "Equivalents:" << endl; + std::cout << "Equivalents:" << std::endl; for( const auto& p : m->equivalentTracks ) { - ::snprintf(text,sizeof(text)," [%-5d : %-5d]",p.first,p.second); - cout << text; + std::snprintf(text,sizeof(text)," [%-5d : %-5d]",p.first,p.second); + std::cout << text; if ( ++cnt == 8 ) { - cout << endl; + std::cout << std::endl; cnt = 0; } } - cout << endl; + std::cout << std::endl; } /// Adopt particle maps diff --git a/DDG4/src/Geant4ParticleGenerator.cpp b/DDG4/src/Geant4ParticleGenerator.cpp index f15ecbfed..2ee1619bc 100644 --- a/DDG4/src/Geant4ParticleGenerator.cpp +++ b/DDG4/src/Geant4ParticleGenerator.cpp @@ -12,27 +12,26 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4Context.h" -#include "DDG4/Geant4Primary.h" -#include "DDG4/Geant4ParticleGenerator.h" -#include "DDG4/Geant4Random.h" -#include "CLHEP/Units/SystemOfUnits.h" +#include +#include +#include +#include +#include +#include +#include // Geant4 include files -#include "G4ParticleTable.hh" -#include "G4ParticleDefinition.hh" +#include +#include // C/C++ include files #include #include -using namespace std; using namespace dd4hep::sim; /// Standard constructor -Geant4ParticleGenerator::Geant4ParticleGenerator(Geant4Context* ctxt, const string& nam) +Geant4ParticleGenerator::Geant4ParticleGenerator(Geant4Context* ctxt, const std::string& nam) : Geant4GeneratorAction(ctxt, nam), m_direction(0,1,0), m_position(0,0,0), m_particle(0) { InstanceCount::increment(this); @@ -125,7 +124,7 @@ void Geant4ParticleGenerator::operator()(G4Event*) { G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); m_particle = particleTable->FindParticle(m_particleName); if (0 == m_particle) { - throw runtime_error("Geant4ParticleGenerator: Bad particle type:"+m_particleName+"!"); + except("Geant4ParticleGenerator: Bad particle type: %s!", m_particleName.c_str()); } } Geant4Event& evt = context()->event(); @@ -177,6 +176,5 @@ void Geant4ParticleGenerator::operator()(G4Event*) { p->id, m_particleName.c_str(), momentum/CLHEP::GeV, vtx->x/CLHEP::mm, vtx->y/CLHEP::mm, vtx->z/CLHEP::mm, direction.X(), direction.Y(), direction.Z()); - } } diff --git a/DDG4/src/Geant4ParticleGun.cpp b/DDG4/src/Geant4ParticleGun.cpp index 2718dd950..ee1d1862e 100644 --- a/DDG4/src/Geant4ParticleGun.cpp +++ b/DDG4/src/Geant4ParticleGun.cpp @@ -12,22 +12,21 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4Context.h" -#include "DDG4/Geant4Primary.h" -#include "DDG4/Geant4ParticleGun.h" -#include "DDG4/Geant4InputHandling.h" -#include "CLHEP/Units/SystemOfUnits.h" +#include +#include +#include +#include +#include +#include +#include // C/C++ include files #include -using namespace std; using namespace dd4hep::sim; /// Standard constructor -Geant4ParticleGun::Geant4ParticleGun(Geant4Context* ctxt, const string& nam) +Geant4ParticleGun::Geant4ParticleGun(Geant4Context* ctxt, const std::string& nam) : Geant4IsotropeGenerator(ctxt,nam), m_shotNo(0) { InstanceCount::increment(this); @@ -59,7 +58,7 @@ void Geant4ParticleGun::getParticleDirection(int num, ROOT::Math::XYZVector& dir /// Callback to generate primary particles void Geant4ParticleGun::operator()(G4Event* event) { - double r = m_direction.R(), eps = numeric_limits::epsilon(); + double r = m_direction.R(), eps = std::numeric_limits::epsilon(); if ( r > eps ) { m_direction.SetXYZ(m_direction.X()/r, m_direction.Y()/r, m_direction.Z()/r); } diff --git a/DDG4/src/Geant4ParticleHandler.cpp b/DDG4/src/Geant4ParticleHandler.cpp index 36e686e69..45ca5ff98 100644 --- a/DDG4/src/Geant4ParticleHandler.cpp +++ b/DDG4/src/Geant4ParticleHandler.cpp @@ -40,14 +40,11 @@ #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; - -typedef detail::ReferenceBitMask PropertyMask; +using PropertyMask = dd4hep::detail::ReferenceBitMask; /// Standard constructor -Geant4ParticleHandler::Geant4ParticleHandler(Geant4Context* ctxt, const string& nam) +Geant4ParticleHandler::Geant4ParticleHandler(Geant4Context* ctxt, const std::string& nam) : Geant4GeneratorAction(ctxt,nam), Geant4MonteCarloTruth(), m_ownsParticles(false), m_userHandler(0), m_primaryMap(0) { @@ -159,7 +156,7 @@ void Geant4ParticleHandler::mark(const G4Track* track) { G4LogicalVolume* vol = track->GetVolume()->GetLogicalVolume(); G4VSensitiveDetector* g4 = vol->GetSensitiveDetector(); Geant4ActionSD* sd = dynamic_cast(g4); - string typ = sd ? sd->sensitiveType() : string(); + std::string typ = sd ? sd->sensitiveType() : std::string(); if ( typ == "calorimeter" ) mask.set(G4PARTICLE_CREATED_CALORIMETER_HIT); else if ( typ == "tracker" ) @@ -184,7 +181,7 @@ void Geant4ParticleHandler::operator()(G4Event* event) { /// User stepping callback void Geant4ParticleHandler::step(const G4Step* step_value, G4SteppingManager* mgr) { - typedef vector _Sec; + typedef std::vector _Sec; ++m_currTrack.steps; if ( (m_currTrack.reason&G4PARTICLE_ABOVE_ENERGY_THRESHOLD) ) { // @@ -428,7 +425,7 @@ void Geant4ParticleHandler::beginEvent(const G4Event* event) { /// Debugging: Dump Geant4 particle map void Geant4ParticleHandler::dumpMap(const char* tag) const { - const string& n = name(); + const std::string& n = name(); Geant4ParticleHandle::header4(INFO,n,tag); for(ParticleMap::const_iterator iend=m_particleMap.end(), i=m_particleMap.begin(); i!=iend; ++i) { Geant4ParticleHandle((*i).second).dump4(INFO,n,tag); @@ -621,7 +618,7 @@ bool Geant4ParticleHandler::defaultKeepParticle(Particle& particle) { /// Clean the monte carlo record. Remove all unwanted stuff. /// This is the core of the object executed at the end of each event action. int Geant4ParticleHandler::recombineParents() { - set remove; + std::set remove; /// Need to start from BACK, to clean first the latest produced stuff. for(ParticleMap::reverse_iterator i=m_particleMap.rbegin(); i!=m_particleMap.rend(); ++i) { @@ -705,7 +702,7 @@ void Geant4ParticleHandler::checkConsistency() const { Geant4ParticleHandle p(particle); PropertyMask mask(p->reason); PropertyMask status(p->status); - set& daughters = p->daughters; + std::set& daughters = p->daughters; ParticleMap::const_iterator j; // For all particles, the set of daughters must be contained in the record. for( int id_dau : daughters ) { diff --git a/DDG4/src/Geant4ParticlePrint.cpp b/DDG4/src/Geant4ParticlePrint.cpp index c7d62afde..ae7a46102 100644 --- a/DDG4/src/Geant4ParticlePrint.cpp +++ b/DDG4/src/Geant4ParticlePrint.cpp @@ -12,24 +12,21 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/Primitives.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4ParticlePrint.h" -#include "DDG4/Geant4Data.h" -#include "DDG4/Geant4HitCollection.h" +#include +#include +#include +#include +#include +#include // Geant4 include files -#include "G4Event.hh" +#include // C/C++ include files #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; - -typedef detail::ReferenceBitMask PropertyMask; +using PropertyMask = dd4hep::detail::ReferenceBitMask; /// Standard constructor Geant4ParticlePrint::Geant4ParticlePrint(Geant4Context* ctxt, const std::string& nam) @@ -80,8 +77,8 @@ void Geant4ParticlePrint::printParticle(const std::string& prefix, const G4Event char equiv[32]; PropertyMask mask(p->reason); PropertyMask status(p->status); - string proc_name = p.processName(); - string proc_type = p.processTypeName(); + std::string proc_name = p.processName(); + std::string proc_type = p.processTypeName(); int parent_id = p->parents.empty() ? -1 : *(p->parents.begin()); equiv[0] = 0; @@ -207,10 +204,8 @@ void Geant4ParticlePrint::printParticleTree(const G4Event* e, } printParticle(txt, e, p); - const set& daughters = p->daughters; // For all particles, the set of daughters must be contained in the record. - for(set::const_iterator id=daughters.begin(); id!=daughters.end(); ++id) { - int id_dau = *id; + for( int id_dau : p->daughters ) { Geant4ParticleHandle dau = (*particles.find(id_dau)).second; printParticleTree(e, particles, level+1, dau); } diff --git a/DDG4/src/Geant4PhysicsConstructor.cpp b/DDG4/src/Geant4PhysicsConstructor.cpp index bd4967336..a17179a30 100644 --- a/DDG4/src/Geant4PhysicsConstructor.cpp +++ b/DDG4/src/Geant4PhysicsConstructor.cpp @@ -12,12 +12,12 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4PhysicsConstructor.h" -#include "G4VModularPhysicsList.hh" +#include +#include +#include // Geant4 include files -#include "G4Version.hh" +#include using namespace dd4hep::sim; @@ -60,7 +60,6 @@ namespace { } - /// Standard action constructor Geant4PhysicsConstructor::Constructor::Constructor() : G4VPhysicsConstructor() diff --git a/DDG4/src/Geant4PhysicsList.cpp b/DDG4/src/Geant4PhysicsList.cpp index a67405b8d..cbe2c48a5 100644 --- a/DDG4/src/Geant4PhysicsList.cpp +++ b/DDG4/src/Geant4PhysicsList.cpp @@ -33,8 +33,6 @@ #include #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; namespace { @@ -44,15 +42,14 @@ namespace { }; struct EmptyPhysics : public G4VModularPhysicsList { - EmptyPhysics() {} - virtual ~EmptyPhysics() {} + EmptyPhysics() = default; + virtual ~EmptyPhysics() = default; }; struct ParticlePhysics : public G4VPhysicsConstructor { Geant4PhysicsListActionSequence* seq; G4VUserPhysicsList* phys; - ParticlePhysics(Geant4PhysicsListActionSequence* s, G4VUserPhysicsList* p) - : seq(s), phys(p) {} - virtual ~ParticlePhysics() {} + ParticlePhysics(Geant4PhysicsListActionSequence* s, G4VUserPhysicsList* p) : seq(s), phys(p) { } + virtual ~ParticlePhysics() = default; virtual void ConstructProcess() { seq->constructProcesses(phys); if ( seq->transportation() ) { @@ -87,7 +84,7 @@ Geant4PhysicsList::Process& Geant4PhysicsList::Process::operator=(const Process& } /// Standard constructor -Geant4PhysicsList::Geant4PhysicsList(Geant4Context* ctxt, const string& nam) +Geant4PhysicsList::Geant4PhysicsList(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { InstanceCount::increment(this); } @@ -168,7 +165,7 @@ void Geant4PhysicsList::addPhysicsConstructor(const std::string& phys_name) { } /// Access processes for one particle type -Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::processes(const string& nam) { +Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::processes(const std::string& nam) { if (auto i = m_processes.find(nam); i != m_processes.end()) return (*i).second; auto ret = m_processes.emplace(nam, ParticleProcesses()); @@ -176,27 +173,27 @@ Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::processes(const string& } /// Access processes for one particle type (CONST) -const Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::processes(const string& nam) const { +const Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::processes(const std::string& nam) const { if (auto i = m_processes.find(nam); i != m_processes.end()) return (*i).second; except("Failed to access the physics process '%s' [Unknown-Process]", nam.c_str()); - throw runtime_error("Failed to access the physics process"); // never called anyway + throw std::runtime_error("Failed to access the physics process"); // never called anyway } /// Access discrete processes for one particle type -Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::discreteProcesses(const string& nam) { +Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::discreteProcesses(const std::string& nam) { if (auto i = m_discreteProcesses.find(nam); i != m_discreteProcesses.end()) return (*i).second; - pair ret = m_discreteProcesses.emplace(nam, ParticleProcesses()); + auto ret = m_discreteProcesses.emplace(nam, ParticleProcesses()); return (*(ret.first)).second; } /// Access discrete processes for one particle type (CONST) -const Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::discreteProcesses(const string& nam) const { +const Geant4PhysicsList::ParticleProcesses& Geant4PhysicsList::discreteProcesses(const std::string& nam) const { if (auto i = m_discreteProcesses.find(nam); i != m_discreteProcesses.end()) return (*i).second; except("Failed to access the physics process '%s' [Unknown-Process]", nam.c_str()); - throw runtime_error("Failed to access the physics process"); // never called anyway + throw std::runtime_error("Failed to access the physics process"); // never called anyway } /// Access physics constructor by name (CONST) @@ -204,12 +201,12 @@ Geant4PhysicsList::PhysicsConstructor Geant4PhysicsList::physics(const std::stri for ( const auto& ctor : m_physics ) { if ( ctor == nam ) { if ( nullptr == ctor.pointer ) - except("Failed to instaniate the physics for constructor '%s'", nam.c_str()); + except("Failed to instaniate the physics for constructor '%s'", nam.c_str()); return ctor; } } except("Failed to access the physics for constructor '%s' [Unknown physics]", nam.c_str()); - throw runtime_error("Failed to access the physics process"); // never called anyway + throw std::runtime_error("Failed to access the physics process"); // never called anyway } /// Add PhysicsConstructor by name @@ -233,9 +230,9 @@ void Geant4PhysicsList::constructPhysics(G4VModularPhysicsList* physics_pointer) for ( auto& ctor : m_physics ) { if ( 0 == ctor.pointer ) { if ( G4VPhysicsConstructor* p = PluginService::Create(ctor) ) - ctor.pointer = p; + ctor.pointer = p; else - except("Failed to create the physics for G4VPhysicsConstructor '%s'", ctor.c_str()); + except("Failed to create the physics for G4VPhysicsConstructor '%s'", ctor.c_str()); } physics_pointer->RegisterPhysics(ctor.pointer); info("Registered Geant4 physics constructor %s to physics list", ctor.c_str()); @@ -272,38 +269,38 @@ void Geant4PhysicsList::constructParticles(G4VUserPhysicsList* physics_pointer) void Geant4PhysicsList::constructProcesses(G4VUserPhysicsList* physics_pointer) { debug("constructProcesses %p", physics_pointer); for ( const auto& [part_name, procs] : m_discreteProcesses ) { - vector defs(Geant4ParticleHandle::g4DefinitionsRegEx(part_name)); + std::vector defs(Geant4ParticleHandle::g4DefinitionsRegEx(part_name)); if ( defs.empty() ) { except("Particle:%s Cannot find the corresponding entry in the particle table.", part_name.c_str()); } for ( const Process& p : procs ) { if ( G4VProcess* g4 = PluginService::Create(p.name) ) { - for ( G4ParticleDefinition* particle : defs ) { - G4ProcessManager* mgr = particle->GetProcessManager(); - mgr->AddDiscreteProcess(g4); - info("Particle:%s -> [%s] added discrete process %s", - part_name.c_str(), particle->GetParticleName().c_str(), p.name.c_str()); - } - continue; + for ( G4ParticleDefinition* particle : defs ) { + G4ProcessManager* mgr = particle->GetProcessManager(); + mgr->AddDiscreteProcess(g4); + info("Particle:%s -> [%s] added discrete process %s", + part_name.c_str(), particle->GetParticleName().c_str(), p.name.c_str()); + } + continue; } except("Cannot create discrete physics process %s", p.name.c_str()); } } for ( const auto& [part_name, procs] : m_processes ) { - vector defs(Geant4ParticleHandle::g4DefinitionsRegEx(part_name)); + std::vector defs(Geant4ParticleHandle::g4DefinitionsRegEx(part_name)); if (defs.empty()) { except("Particle:%s Cannot find the corresponding entry in the particle table.", part_name.c_str()); } for ( const Process& p : procs ) { if ( G4VProcess* g4 = PluginService::Create(p.name) ) { - for ( G4ParticleDefinition* particle : defs ) { - G4ProcessManager* mgr = particle->GetProcessManager(); - mgr->AddProcess(g4, p.ordAtRestDoIt, p.ordAlongSteptDoIt, p.ordPostStepDoIt); - info("Particle:%s -> [%s] added process %s with flags (%d,%d,%d)", - part_name.c_str(), particle->GetParticleName().c_str(), p.name.c_str(), - p.ordAtRestDoIt, p.ordAlongSteptDoIt, p.ordPostStepDoIt); - } - continue; + for ( G4ParticleDefinition* particle : defs ) { + G4ProcessManager* mgr = particle->GetProcessManager(); + mgr->AddProcess(g4, p.ordAtRestDoIt, p.ordAlongSteptDoIt, p.ordPostStepDoIt); + info("Particle:%s -> [%s] added process %s with flags (%d,%d,%d)", + part_name.c_str(), particle->GetParticleName().c_str(), p.name.c_str(), + p.ordAtRestDoIt, p.ordAlongSteptDoIt, p.ordPostStepDoIt); + } + continue; } except("Cannot create physics process %s", p.name.c_str()); } @@ -315,7 +312,7 @@ void Geant4PhysicsList::enable(G4VUserPhysicsList* /* physics */) { } /// Standard constructor -Geant4PhysicsListActionSequence::Geant4PhysicsListActionSequence(Geant4Context* ctxt, const string& nam) +Geant4PhysicsListActionSequence::Geant4PhysicsListActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam), m_transportation(false), m_decays(false), m_rangecut(0.7*CLHEP::mm) { declareProperty("transportation", m_transportation); declareProperty("extends", m_extends); @@ -335,7 +332,6 @@ Geant4PhysicsListActionSequence::~Geant4PhysicsListActionSequence() { #include - /// Extend physics list from factory: G4VUserPhysicsList* Geant4PhysicsListActionSequence::extensionList() { G4VModularPhysicsList* physics = ( m_extends.empty() ) diff --git a/DDG4/src/Geant4Primary.cpp b/DDG4/src/Geant4Primary.cpp index 50be9eb76..ecaf20772 100644 --- a/DDG4/src/Geant4Primary.cpp +++ b/DDG4/src/Geant4Primary.cpp @@ -12,19 +12,18 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/Primitives.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4Primary.h" +#include +#include +#include +#include // Geant4 include files -#include "G4PrimaryParticle.hh" +#include // C/C++ include files #include #include -using namespace dd4hep; using namespace dd4hep::sim; /// Default destructor diff --git a/DDG4/src/Geant4Random.cpp b/DDG4/src/Geant4Random.cpp index 464ff3c13..e1b382e84 100644 --- a/DDG4/src/Geant4Random.cpp +++ b/DDG4/src/Geant4Random.cpp @@ -12,21 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4Random.h" +#include +#include +#include -#include "CLHEP/Random/EngineFactory.h" -#include "CLHEP/Random/RandGamma.h" -#include "CLHEP/Random/Random.h" +#include +#include +#include // ROOT include files -#include "TRandom1.h" +#include // C/C++ include files #include -using namespace std; using namespace dd4hep::sim; namespace CLHEP { @@ -113,7 +112,7 @@ Geant4Random::~Geant4Random() { /// Access the main Geant4 random generator instance. Must be created before used! Geant4Random* Geant4Random::instance(bool throw_exception) { if ( !s_instance && throw_exception ) { - throw runtime_error("No global random number generator defined!"); + dd4hep::except("Geant4Random", "No global random number generator defined!"); } return s_instance; } @@ -125,10 +124,10 @@ Geant4Random* Geant4Random::setMainInstance(Geant4Random* ptr) { } if ( s_instance != ptr ) { if ( !ptr ) { - throw runtime_error("Attempt to declare invalid Geant4Random instance."); + dd4hep::except("Geant4Random","Attempt to declare invalid Geant4Random instance."); } if ( !ptr->m_inited ) { - throw runtime_error("Attempt to declare uninitialized Geant4Random instance."); + dd4hep::except("Geant4Random","Attempt to declare uninitialized Geant4Random instance."); } Geant4Random* old = s_instance; CLHEP::HepRandomEngine* curr = CLHEP::HepRandom::getTheEngine(); @@ -146,19 +145,19 @@ Geant4Random* Geant4Random::setMainInstance(Geant4Random* ptr) { return 0; } -#include "CLHEP/Random/DualRand.h" -#include "CLHEP/Random/JamesRandom.h" -#include "CLHEP/Random/MTwistEngine.h" -#include "CLHEP/Random/RanecuEngine.h" -#include "CLHEP/Random/Ranlux64Engine.h" -#include "CLHEP/Random/RanluxEngine.h" -#include "CLHEP/Random/RanshiEngine.h" -#include "CLHEP/Random/NonRandomEngine.h" +#include +#include +#include +#include +#include +#include +#include +#include /// Initialize the instance. void Geant4Random::initialize() { if ( !m_file.empty() ) { - ifstream in(m_file.c_str(), std::ios::in); + std::ifstream in(m_file.c_str(), std::ios::in); m_engine = CLHEP::EngineFactory::newEngine(in); if ( !m_engine ) { except("Failed to create CLHEP random engine from file:%s.",m_file.c_str()); diff --git a/DDG4/src/Geant4RunAction.cpp b/DDG4/src/Geant4RunAction.cpp index 68169a6b9..6f54ef8e5 100644 --- a/DDG4/src/Geant4RunAction.cpp +++ b/DDG4/src/Geant4RunAction.cpp @@ -12,15 +12,13 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4RunAction.h" +#include +#include + // Geant4 headers -#include "G4Threading.hh" -#include "G4AutoLock.hh" -// C/C++ include files -#include +#include +#include -using namespace std; using namespace dd4hep::sim; namespace { @@ -29,7 +27,7 @@ namespace { } /// Standard constructor -Geant4RunAction::Geant4RunAction(Geant4Context* ctxt, const string& nam) +Geant4RunAction::Geant4RunAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { InstanceCount::increment(this); } @@ -48,7 +46,7 @@ void Geant4RunAction::end(const G4Run*) { } /// Standard constructor -Geant4SharedRunAction::Geant4SharedRunAction(Geant4Context* ctxt, const string& nam) +Geant4SharedRunAction::Geant4SharedRunAction(Geant4Context* ctxt, const std::string& nam) : Geant4RunAction(ctxt, nam) { InstanceCount::increment(this); @@ -73,7 +71,7 @@ void Geant4SharedRunAction::use(Geant4RunAction* action) { m_action = action; return; } - throw runtime_error("Geant4SharedRunAction: Attempt to use invalid actor!"); + except("Geant4SharedRunAction: Attempt to use invalid actor!"); } /// Begin-of-run callback @@ -97,7 +95,7 @@ void Geant4SharedRunAction::end(const G4Run* run) { } /// Standard constructor -Geant4RunActionSequence::Geant4RunActionSequence(Geant4Context* ctxt, const string& nam) +Geant4RunActionSequence::Geant4RunActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = true; InstanceCount::increment(this); @@ -124,7 +122,7 @@ void Geant4RunActionSequence::configureFiber(Geant4Context* thread_context) { } /// Get an action by name -Geant4RunAction* Geant4RunActionSequence::get(const string& nam) const { +Geant4RunAction* Geant4RunActionSequence::get(const std::string& nam) const { return m_actors.get(FindByName(TypeName::split(nam).second)); } @@ -136,7 +134,7 @@ void Geant4RunActionSequence::adopt(Geant4RunAction* action) { m_actors.add(action); return; } - throw runtime_error("Geant4RunActionSequence: Attempt to add invalid actor!"); + except("Geant4RunActionSequence: Attempt to add invalid actor!"); } /// Pre-track action callback diff --git a/DDG4/src/Geant4SensDetAction.cpp b/DDG4/src/Geant4SensDetAction.cpp index 68b1b43dd..a2db05dbd 100644 --- a/DDG4/src/Geant4SensDetAction.cpp +++ b/DDG4/src/Geant4SensDetAction.cpp @@ -15,6 +15,7 @@ #include #include #include + #include #include #include @@ -36,27 +37,24 @@ #define MM_2_CM 0.1 #endif -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; #if 0 namespace { - Geant4ActionSD* _getSensitiveDetector(const string& name) { + Geant4ActionSD* _getSensitiveDetector(const std::string& name) { G4SDManager* mgr = G4SDManager::GetSDMpointer(); G4VSensitiveDetector* sd = mgr->FindSensitiveDetector(name); if (0 == sd) { - throw runtime_error(format("Geant4Sensitive", "DDG4: You requested to configure actions " - "for the sensitive detector %s,\nDDG4: which is not known to Geant4. " - "Are you sure you already converted the geometry?", name.c_str())); + dd4hep::except("Geant4Sensitive", "DDG4: You requested to configure actions " + "for the sensitive detector %s,\nDDG4: which is not known to Geant4. " + "Are you sure you already converted the geometry?", name.c_str()); } Geant4ActionSD* action_sd = dynamic_cast(sd); if (0 == action_sd) { - throw runtime_error( - format("Geant4Sensitive", "DDG4: You may only configure actions " - "for sensitive detectors of type Geant4ActionSD.\n" - "DDG4: The sensitive detector of %s is of type %s, which is incompatible.", name.c_str(), - typeName(typeid(*sd)).c_str())); + throw dd4hep::except("Geant4Sensitive", "DDG4: You may only configure actions " + "for sensitive detectors of type Geant4ActionSD.\n" + "DDG4: The sensitive detector of %s is of type %s, which is incompatible.", name.c_str(), + typeName(typeid(*sd)).c_str()); } return action_sd; } @@ -97,12 +95,12 @@ bool Geant4Filter::operator()(const Geant4FastSimSpot*) const { } /// Constructor. The detector element is identified by the name -Geant4Sensitive::Geant4Sensitive(Geant4Context* ctxt, const string& nam, DetElement det, Detector& det_ref) +Geant4Sensitive::Geant4Sensitive(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& det_ref) : Geant4Action(ctxt, nam), m_detDesc(det_ref), m_detector(det) { InstanceCount::increment(this); if (!det.isValid()) { - throw runtime_error(format("Geant4Sensitive", "DDG4: Detector elemnt for %s is invalid.", nam.c_str())); + except("DDG4: Detector elemnt for %s is invalid.", nam.c_str()); } declareProperty("HitCreationMode", m_hitCreationMode = SIMPLE_MODE); m_sequence = context()->kernel().sensitiveAction(m_detector.name()); @@ -131,7 +129,7 @@ void Geant4Sensitive::adopt(Geant4Filter* filter) { m_filters.add(filter); return; } - throw runtime_error("Geant4Sensitive: Attempt to add invalid sensitive filter!"); + except("Attempt to add invalid sensitive filter!"); } /// Add an actor responding to all callbacks. Sequence takes ownership. @@ -147,7 +145,7 @@ void Geant4Sensitive::adopt_front(Geant4Filter* filter) { m_filters.add_front(filter); return; } - throw runtime_error("Geant4Sensitive: Attempt to add invalid sensitive filter!"); + except("Attempt to add invalid sensitive filter!"); } /// Callback before hit processing starts. Invoke all filters. @@ -175,8 +173,8 @@ Geant4ActionSD& Geant4Sensitive::detector() const { return *m_sensitiveDetector; //m_sensitiveDetector = _getSensitiveDetector(m_detector.name()); //if ( m_sensitiveDetector ) return *m_sensitiveDetector; - throw runtime_error(format("Geant4Sensitive", "DDG4: The sensitive detector for action %s " - "was not properly configured.", name().c_str())); + except("DDG4: The sensitive detector for action %s was not properly configured.", name().c_str()); + throw std::runtime_error("Geant4Sensitive::detector"); } /// Access to the hosting sequence @@ -185,12 +183,12 @@ Geant4SensDetActionSequence& Geant4Sensitive::sequence() const { } /// Access the detector desciption object -Detector& Geant4Sensitive::detectorDescription() const { +dd4hep::Detector& Geant4Sensitive::detectorDescription() const { return m_detDesc; } /// Access HitCollection container names -const string& Geant4Sensitive::hitCollectionName(std::size_t which) const { +const std::string& Geant4Sensitive::hitCollectionName(std::size_t which) const { return sequence().hitCollectionName(which); } @@ -289,7 +287,7 @@ long long int Geant4Sensitive::cellID(const G4VTouchable* touchable, const G4Thr } /// Standard constructor -Geant4SensDetActionSequence::Geant4SensDetActionSequence(Geant4Context* ctxt, const string& nam) +Geant4SensDetActionSequence::Geant4SensDetActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam), m_hce(0), m_detector(0) { m_needsControl = true; @@ -329,7 +327,7 @@ void Geant4SensDetActionSequence::adopt(Geant4Sensitive* sensitive) { m_actors.add(sensitive); return; } - throw runtime_error("Geant4SensDetActionSequence: Attempt to add invalid sensitive actor!"); + except("Attempt to add invalid sensitive actor!"); } /// Add an actor responding to all callbacks. Sequence takes ownership. @@ -339,7 +337,7 @@ void Geant4SensDetActionSequence::adopt(Geant4Filter* filter) { m_filters.add(filter); return; } - throw runtime_error("Geant4SensDetActionSequence: Attempt to add invalid sensitive filter!"); + except("Attempt to add invalid sensitive filter!"); } /// Initialize the usage of a hit collection. Returns the collection identifier @@ -366,7 +364,7 @@ const std::string& Geant4SensDetActionSequence::hitCollectionName(std::size_t wh if (which < m_collections.size()) { return m_collections[which].first; } - static string blank = ""; + static std::string blank = ""; except("The collection name index for subdetector %s is out of range!", c_name()); return blank; } @@ -470,17 +468,18 @@ Geant4SensDetSequences::~Geant4SensDetSequences() { } /// Access sequence member by name -Geant4SensDetActionSequence* Geant4SensDetSequences::operator[](const string& name) const { - string nam = "SD_Seq_" + name; - Members::const_iterator i = m_sequences.find(nam); +Geant4SensDetActionSequence* Geant4SensDetSequences::operator[](const std::string& nam) const { + std::string n = "SD_Seq_" + nam; + Members::const_iterator i = m_sequences.find(n); if (i != m_sequences.end()) return (*i).second; - throw runtime_error("Attempt to access undefined SensDetActionSequence!"); + except("Attempt to access undefined SensDetActionSequence: %s ", nam.c_str()); + return nullptr; } /// Access sequence member by name Geant4SensDetActionSequence* Geant4SensDetSequences::find(const std::string& name) const { - string nam = "SD_Seq_" + name; + std::string nam = "SD_Seq_" + name; Members::const_iterator i = m_sequences.find(nam); if (i != m_sequences.end()) return (*i).second; @@ -488,15 +487,14 @@ Geant4SensDetActionSequence* Geant4SensDetSequences::find(const std::string& nam } /// Insert sequence member -void Geant4SensDetSequences::insert(const string& name, Geant4SensDetActionSequence* seq) { +void Geant4SensDetSequences::insert(const std::string& name, Geant4SensDetActionSequence* seq) { if (seq) { - string nam = "SD_Seq_" + name; + std::string nam = "SD_Seq_" + name; seq->addRef(); m_sequences[nam] = seq; return; } - throw runtime_error(format("Geant4SensDetSequences", "Attempt to add invalid sensitive " - "sequence with name:%s", name.c_str())); + except("Attempt to add invalid sensitive sequence with name:%s", name.c_str()); } /// Clear the sequence list diff --git a/DDG4/src/Geant4StackingAction.cpp b/DDG4/src/Geant4StackingAction.cpp index 985d951cb..e0b771769 100644 --- a/DDG4/src/Geant4StackingAction.cpp +++ b/DDG4/src/Geant4StackingAction.cpp @@ -12,23 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4StackingAction.h" -// Geant4 headers -#include "G4Threading.hh" -#include "G4AutoLock.hh" +#include +#include -// C/C++ include files -#include +// Geant4 headers +#include +#include -using namespace std; using namespace dd4hep::sim; namespace { G4Mutex action_mutex=G4MUTEX_INITIALIZER; } /// Standard constructor -Geant4StackingAction::Geant4StackingAction(Geant4Context* ctxt, const string& nam) +Geant4StackingAction::Geant4StackingAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { InstanceCount::increment(this); } @@ -40,13 +37,12 @@ Geant4StackingAction::~Geant4StackingAction() { /// Classify new track: The first call in the sequence returning non-null pointer wins! TrackClassification -Geant4StackingAction::classifyNewTrack(G4StackManager* /* manager */, - const G4Track* /* track */) { +Geant4StackingAction::classifyNewTrack(G4StackManager* /* manager */, const G4Track* /* track */) { return TrackClassification(); } /// Standard constructor -Geant4SharedStackingAction::Geant4SharedStackingAction(Geant4Context* ctxt, const string& nam) +Geant4SharedStackingAction::Geant4SharedStackingAction(Geant4Context* ctxt, const std::string& nam) : Geant4StackingAction(ctxt, nam), m_action(0) { InstanceCount::increment(this); @@ -71,7 +67,7 @@ void Geant4SharedStackingAction::use(Geant4StackingAction* action) { m_action = action; return; } - throw runtime_error("Geant4SharedStackingAction: Attempt to use invalid actor!"); + except("Attempt to use invalid actor!"); } /// Begin-of-stacking callback @@ -97,7 +93,7 @@ void Geant4SharedStackingAction::prepare(G4StackManager* stackManager) { /// Classify new track with delegation TrackClassification Geant4SharedStackingAction::classifyNewTrack(G4StackManager* stackManager, - const G4Track* track) { + const G4Track* track) { if ( m_action ) { G4AutoLock protection_lock(&action_mutex); { ContextSwap swap(m_action,context()); @@ -108,7 +104,7 @@ Geant4SharedStackingAction::classifyNewTrack(G4StackManager* stackManager, } /// Standard constructor -Geant4StackingActionSequence::Geant4StackingActionSequence(Geant4Context* ctxt, const string& nam) +Geant4StackingActionSequence::Geant4StackingActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = true; InstanceCount::increment(this); @@ -130,7 +126,7 @@ void Geant4StackingActionSequence::adopt(Geant4StackingAction* action) { m_actors.add(action); return; } - throw runtime_error("Geant4StackingActionSequence: Attempt to add invalid actor!"); + except("Attempt to add invalid actor!"); } /// Set or update client context @@ -145,7 +141,7 @@ void Geant4StackingActionSequence::configureFiber(Geant4Context* thread_context) } /// Get an action by name -Geant4StackingAction* Geant4StackingActionSequence::get(const string& nam) const { +Geant4StackingAction* Geant4StackingActionSequence::get(const std::string& nam) const { return m_actors.get(FindByName(TypeName::split(nam).second)); } @@ -164,7 +160,7 @@ void Geant4StackingActionSequence::prepare(G4StackManager* stackManager) { /// Classify new track: The first call in the sequence returning non-null pointer wins! TrackClassification Geant4StackingActionSequence::classifyNewTrack(G4StackManager* stackManager, - const G4Track* track) { + const G4Track* track) { for( auto a : m_actors ) { auto ret = a->classifyNewTrack(stackManager, track); if ( ret.type != NoTrackClassification ) { diff --git a/DDG4/src/Geant4StepHandler.cpp b/DDG4/src/Geant4StepHandler.cpp index ad3385e94..ce0bb5715 100644 --- a/DDG4/src/Geant4StepHandler.cpp +++ b/DDG4/src/Geant4StepHandler.cpp @@ -12,16 +12,15 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4StepHandler.h" -#include "DDSegmentation/Segmentation.h" -#include "DD4hep/DD4hepUnits.h" -#include "CLHEP/Units/SystemOfUnits.h" +#include +#include +#include +#include // Geant4 include files -#include "G4Version.hh" +#include namespace units = dd4hep; -using namespace dd4hep; using namespace dd4hep::sim; /// Returns the step status in form of a string diff --git a/DDG4/src/Geant4SteppingAction.cpp b/DDG4/src/Geant4SteppingAction.cpp index 6899711cd..d023a80c6 100644 --- a/DDG4/src/Geant4SteppingAction.cpp +++ b/DDG4/src/Geant4SteppingAction.cpp @@ -12,22 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4SteppingAction.h" +#include +#include + // Geant4 headers -#include "G4Threading.hh" -#include "G4AutoLock.hh" -// C/C++ include files -#include +#include +#include -using namespace std; using namespace dd4hep::sim; namespace { G4Mutex action_mutex=G4MUTEX_INITIALIZER; } /// Standard constructor -Geant4SteppingAction::Geant4SteppingAction(Geant4Context* ctxt, const string& nam) +Geant4SteppingAction::Geant4SteppingAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { InstanceCount::increment(this); } @@ -42,7 +40,7 @@ void Geant4SteppingAction::operator()(const G4Step*, G4SteppingManager*) { } /// Standard constructor -Geant4SharedSteppingAction::Geant4SharedSteppingAction(Geant4Context* ctxt, const string& nam) +Geant4SharedSteppingAction::Geant4SharedSteppingAction(Geant4Context* ctxt, const std::string& nam) : Geant4SteppingAction(ctxt, nam), m_action(0) { InstanceCount::increment(this); @@ -62,7 +60,7 @@ void Geant4SharedSteppingAction::use(Geant4SteppingAction* action) { m_action = action; return; } - throw runtime_error("Geant4SharedSteppingAction: Attempt to use invalid actor!"); + except("Attempt to use invalid actor!"); } /// Set or update client for the use in a new thread fiber @@ -81,7 +79,7 @@ void Geant4SharedSteppingAction::operator()(const G4Step* s, G4SteppingManager* } /// Standard constructor -Geant4SteppingActionSequence::Geant4SteppingActionSequence(Geant4Context* ctxt, const string& nam) +Geant4SteppingActionSequence::Geant4SteppingActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = true; InstanceCount::increment(this); @@ -107,7 +105,7 @@ void Geant4SteppingActionSequence::updateContext(Geant4Context* ctxt) { } /// Get an action by name -Geant4SteppingAction* Geant4SteppingActionSequence::get(const string& nam) const { +Geant4SteppingAction* Geant4SteppingActionSequence::get(const std::string& nam) const { return m_actors.get(FindByName(TypeName::split(nam).second)); } @@ -125,5 +123,5 @@ void Geant4SteppingActionSequence::adopt(Geant4SteppingAction* action) { m_actors.add(action); return; } - throw runtime_error("Geant4SteppingActionSequence: Attempt to add invalid actor!"); + except("Attempt to add invalid actor!"); } diff --git a/DDG4/src/Geant4TestActions.cpp b/DDG4/src/Geant4TestActions.cpp index c752033de..3a5b1a73c 100644 --- a/DDG4/src/Geant4TestActions.cpp +++ b/DDG4/src/Geant4TestActions.cpp @@ -12,19 +12,17 @@ //========================================================================= // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4TestActions.h" -#include "G4Run.hh" -#include "G4Event.hh" -#include "G4Step.hh" -#include "G4Track.hh" +#include +#include +#include +#include +#include +#include +#include // C/C++ include files #include -using namespace std; -using namespace dd4hep::sim; using namespace dd4hep::sim::Test; namespace { diff --git a/DDG4/src/Geant4TouchableHandler.cpp b/DDG4/src/Geant4TouchableHandler.cpp index b15d568ad..c18367704 100644 --- a/DDG4/src/Geant4TouchableHandler.cpp +++ b/DDG4/src/Geant4TouchableHandler.cpp @@ -12,14 +12,11 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4TouchableHandler.h" -#include "DDG4/Geant4GeometryInfo.h" +#include +#include -#include "G4Step.hh" -#include "G4VTouchable.hh" - -// C/C++ include files -#include +#include +#include using namespace dd4hep::sim; @@ -52,7 +49,7 @@ Geant4TouchableHandler::Geant4PlacementPath Geant4TouchableHandler::placementPat return path_val; } if ( exception ) { - throw std::runtime_error("Attempt to access invalid G4 touchable object."); + except("Geant4TouchableHandler", "Attempt to access invalid G4 touchable object."); } return path_val; } diff --git a/DDG4/src/Geant4TrackInformation.cpp b/DDG4/src/Geant4TrackInformation.cpp index e5ca3f46e..7020efa73 100644 --- a/DDG4/src/Geant4TrackInformation.cpp +++ b/DDG4/src/Geant4TrackInformation.cpp @@ -12,10 +12,8 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4TrackInformation.h" +#include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; /// Default constructor diff --git a/DDG4/src/Geant4TrackingAction.cpp b/DDG4/src/Geant4TrackingAction.cpp index 6b778e850..ca307e617 100644 --- a/DDG4/src/Geant4TrackingAction.cpp +++ b/DDG4/src/Geant4TrackingAction.cpp @@ -12,24 +12,20 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4TrackingAction.h" -#include "DDG4/Geant4MonteCarloTruth.h" -#include "DDG4/Geant4TrackInformation.h" +#include +#include +#include +#include // Geant4 include files -#include "G4Track.hh" -#include "G4Threading.hh" -#include "G4AutoLock.hh" -#include "G4TrackingManager.hh" -#include "G4VUserTrackInformation.hh" +#include +#include +#include +#include +#include -// C/C++ include files -#include - -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; + class G4Step; class G4TouchableHistory; namespace { @@ -37,7 +33,7 @@ namespace { } /// Standard constructor -Geant4TrackingActionSequence::Geant4TrackingActionSequence(Geant4Context* ctxt, const string& nam) +Geant4TrackingActionSequence::Geant4TrackingActionSequence(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = true; InstanceCount::increment(this); @@ -66,7 +62,7 @@ void Geant4TrackingActionSequence::configureFiber(Geant4Context* thread_context) } /// Get an action by name -Geant4TrackingAction* Geant4TrackingActionSequence::get(const string& nam) const { +Geant4TrackingAction* Geant4TrackingActionSequence::get(const std::string& nam) const { return m_actors.get(FindByName(TypeName::split(nam).second)); } @@ -78,7 +74,7 @@ void Geant4TrackingActionSequence::adopt(Geant4TrackingAction* action) { m_actors.add(action); return; } - throw runtime_error("Geant4TrackingActionSequence: Attempt to add invalid actor!"); + throw std::runtime_error("Geant4TrackingActionSequence: Attempt to add invalid actor!"); } /// Pre-track action callback @@ -96,7 +92,7 @@ void Geant4TrackingActionSequence::end(const G4Track* track) { } /// Standard constructor -Geant4TrackingAction::Geant4TrackingAction(Geant4Context* ctxt, const string& nam) +Geant4TrackingAction::Geant4TrackingAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { InstanceCount::increment(this); } @@ -121,7 +117,7 @@ void Geant4TrackingAction::mark(const G4Track* track) const { } /// Standard constructor -Geant4SharedTrackingAction::Geant4SharedTrackingAction(Geant4Context* ctxt, const string& nam) +Geant4SharedTrackingAction::Geant4SharedTrackingAction(Geant4Context* ctxt, const std::string& nam) : Geant4TrackingAction(ctxt, nam), m_action(0) { InstanceCount::increment(this); @@ -146,7 +142,7 @@ void Geant4SharedTrackingAction::use(Geant4TrackingAction* action) { m_action = action; return; } - throw runtime_error("Geant4SharedTrackingAction: Attempt to use invalid actor!"); + except("Attempt to use invalid actor!"); } /// Begin-of-track callback diff --git a/DDG4/src/Geant4TrackingPostAction.cpp b/DDG4/src/Geant4TrackingPostAction.cpp index a19f987ee..196c2ddf0 100644 --- a/DDG4/src/Geant4TrackingPostAction.cpp +++ b/DDG4/src/Geant4TrackingPostAction.cpp @@ -12,17 +12,16 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4TrackingPostAction.h" -#include "DDG4/Geant4TrackHandler.h" +#include +#include +#include // Geant4 include files -#include "G4TrackingManager.hh" +#include // C/C++ include files #include -using namespace std; using namespace dd4hep::sim; /// Helper class to manipulate strings @@ -81,7 +80,7 @@ void Geant4TrackingPostAction::end(const G4Track* tr) { Geant4TrackHandler track(tr); //Geant4TrackInformation* info = track.info(); - const string& proc = track.creatorProcess()->GetProcessName(); + const std::string& proc = track.creatorProcess()->GetProcessName(); StringV::const_iterator trIt = find_if(m_ignoredProcs.begin(), m_ignoredProcs.end(), FindString(proc)); if (trIt != m_ignoredProcs.end()) { warning("Particles created by processes of type %s are not kept!", (*trIt).c_str()); diff --git a/DDG4/src/Geant4TrackingPreAction.cpp b/DDG4/src/Geant4TrackingPreAction.cpp index a75deae26..00b8bd0c0 100644 --- a/DDG4/src/Geant4TrackingPreAction.cpp +++ b/DDG4/src/Geant4TrackingPreAction.cpp @@ -12,11 +12,11 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4TrackingPreAction.h" +#include +#include // Geant4 include files -#include "G4TrackingManager.hh" +#include using namespace dd4hep::sim; diff --git a/DDG4/src/Geant4UIManager.cpp b/DDG4/src/Geant4UIManager.cpp index 763d3877b..b4bb2c3c3 100644 --- a/DDG4/src/Geant4UIManager.cpp +++ b/DDG4/src/Geant4UIManager.cpp @@ -31,16 +31,15 @@ #include using namespace dd4hep::sim; -using namespace std; namespace { - string make_cmd(const string& cmd) { - return string( "/control/execute "+cmd); + std::string make_cmd(const std::string& cmd) { + return std::string( "/control/execute "+cmd); } } /// Initializing constructor -Geant4UIManager::Geant4UIManager(Geant4Context* ctxt, const string& nam) +Geant4UIManager::Geant4UIManager(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt,nam), m_vis(0), m_ui(0) { declareProperty("SetupUI", m_uiSetup=""); @@ -56,9 +55,9 @@ Geant4UIManager::Geant4UIManager(Geant4Context* ctxt, const string& nam) declareProperty("HaveVIS", m_haveVis=false); declareProperty("HaveUI", m_haveUI=true); declareProperty("Prompt", m_prompt); - context()->kernel().register_configure(bind(&Geant4UIManager::configure,this)); - context()->kernel().register_initialize(bind(&Geant4UIManager::initialize,this)); - context()->kernel().register_terminate(bind(&Geant4UIManager::terminate,this)); + context()->kernel().register_configure(std::bind(&Geant4UIManager::configure,this)); + context()->kernel().register_initialize(std::bind(&Geant4UIManager::initialize,this)); + context()->kernel().register_terminate(std::bind(&Geant4UIManager::terminate,this)); enableUI(); } @@ -113,7 +112,7 @@ void Geant4UIManager::terminate() { } /// Apply single command -void Geant4UIManager::applyCommand(const string& command) { +void Geant4UIManager::applyCommand(const std::string& command) { /// Get the pointer to the User Interface manager G4UImanager* mgr = G4UImanager::GetUIpointer(); if ( mgr ) { @@ -248,7 +247,7 @@ void Geant4UIManager::start() { /// No UI. Pure batch mode: Simply execute requested number of events long numEvent = context()->kernel().property("NumEvents").value(); - if(numEvent < 0) numEvent = numeric_limits::max(); + if(numEvent < 0) numEvent = std::numeric_limits::max(); info("++ Start run with %d events.",numEvent); try { context()->kernel().runManager().BeamOn(numEvent); diff --git a/DDG4/src/Geant4UIMessenger.cpp b/DDG4/src/Geant4UIMessenger.cpp index b875f128b..658565d44 100644 --- a/DDG4/src/Geant4UIMessenger.cpp +++ b/DDG4/src/Geant4UIMessenger.cpp @@ -12,19 +12,17 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/Primitives.h" -#include "DDG4/Geant4UIMessenger.h" +#include +#include +#include // Geant4 include files -#include "G4UIcmdWithoutParameter.hh" -#include "G4UIcmdWithAString.hh" +#include +#include // C/C++ include files #include -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; namespace { @@ -35,8 +33,8 @@ namespace { InstallProperties(Geant4UIMessenger::Commands& c, const std::string& p, G4UImessenger* m) : cmds(c), path(p), msg(m) { } - void operator()(const pair& o) { - string n = path + o.first; + void operator()(const std::pair& o) { + std::string n = path + o.first; G4UIcmdWithAString* cmd = new G4UIcmdWithAString(n.c_str(), msg); cmd->SetParameterName(o.first.c_str(), true); cmd->SetGuidance(("Property item of type " + o.second.type()).c_str()); @@ -45,7 +43,7 @@ namespace { }; } -Geant4UIMessenger::Geant4UIMessenger(const string& name, const string& path) +Geant4UIMessenger::Geant4UIMessenger(const std::string& name, const std::string& path) : G4UImessenger(), m_directory(0), m_properties(0), m_name(name), m_path(path) { m_directory = new G4UIdirectory(path.c_str()); printout(INFO, "Geant4UI", "+++ %s> Install Geant4 control directory:%s", name.c_str(), path.c_str()); @@ -89,7 +87,7 @@ void Geant4UIMessenger::exportProperties(PropertyManager& mgr) { G4String Geant4UIMessenger::GetCurrentValue(G4UIcommand * c) { Commands::iterator i = m_propertyCmd.find(c); if (m_properties && i != m_propertyCmd.end()) { - const string& n = (*i).second; + const std::string& n = (*i).second; return (*m_properties)[n].str(); } printout(INFO, "Geant4UI", @@ -101,7 +99,7 @@ G4String Geant4UIMessenger::GetCurrentValue(G4UIcommand * c) { void Geant4UIMessenger::SetNewValue(G4UIcommand *c, G4String v) { Commands::iterator i = m_propertyCmd.find(c); if (m_properties && i != m_propertyCmd.end()) { - const string& n = (*i).second; + const std::string& n = (*i).second; try { if (!v.empty()) { Property& p = (*m_properties)[n]; @@ -111,12 +109,12 @@ void Geant4UIMessenger::SetNewValue(G4UIcommand *c, G4String v) { m_name.c_str(), n.c_str(), v.c_str(), p.str().c_str()); } else { - string value = (*m_properties)[n].str(); + std::string value = (*m_properties)[n].str(); printout(INFO, "Geant4UI", "+++ %s> Unchanged property value %s = %s.", m_name.c_str(), n.c_str(), value.c_str()); } } - catch(const exception& e) { + catch(const std::exception& e) { printout(INFO, "Geant4UI", "+++ %s> Exception: Failed to change property %s = '%s'.", m_name.c_str(), n.c_str(), v.c_str()); printout(INFO, "Geant4UI", "+++ %s> Exception: %s", m_name.c_str(), e.what()); @@ -134,7 +132,7 @@ void Geant4UIMessenger::SetNewValue(G4UIcommand *c, G4String v) { const void* args[] = {v.c_str(), 0}; (*j).second.execute(args); } - catch(const exception& e) { + catch(const std::exception& e) { printout(INFO, "Geant4UI", "+++ %s> Exception: Failed to exec action '%s' [%s].", m_name.c_str(), c->GetCommandName().c_str(), c->GetCommandPath().c_str()); printout(INFO, "Geant4UI", "+++ %s> Exception: %s",e.what()); diff --git a/DDG4/src/Geant4UserInitialization.cpp b/DDG4/src/Geant4UserInitialization.cpp index 69c1357da..73c5920aa 100644 --- a/DDG4/src/Geant4UserInitialization.cpp +++ b/DDG4/src/Geant4UserInitialization.cpp @@ -12,17 +12,13 @@ //========================================================================== // Framework include files -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4UserInitialization.h" +#include +#include -// C/C++ include files -#include - -using namespace std; using namespace dd4hep::sim; /// Standard constructor -Geant4UserInitialization::Geant4UserInitialization(Geant4Context* ctxt, const string& nam) +Geant4UserInitialization::Geant4UserInitialization(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt, nam) { m_needsControl = false; InstanceCount::increment(this); @@ -42,7 +38,7 @@ void Geant4UserInitialization::buildMaster() const { } /// Standard constructor -Geant4UserInitializationSequence::Geant4UserInitializationSequence(Geant4Context* ctxt, const string& nam) +Geant4UserInitializationSequence::Geant4UserInitializationSequence(Geant4Context* ctxt, const std::string& nam) : Geant4UserInitialization(ctxt, nam) { m_needsControl = false; InstanceCount::increment(this); @@ -64,7 +60,7 @@ void Geant4UserInitializationSequence::adopt(Geant4UserInitialization* action) m_actors.add(action); return; } - throw runtime_error("Geant4UserInitializationSequence: Attempt to add invalid actor!"); + except("Attempt to add invalid actor!"); } /// Callback function to build setup for the MT worker thread diff --git a/DDG4/src/Geant4UserLimits.cpp b/DDG4/src/Geant4UserLimits.cpp index 54e6c0602..b6ba4ecbc 100644 --- a/DDG4/src/Geant4UserLimits.cpp +++ b/DDG4/src/Geant4UserLimits.cpp @@ -12,29 +12,25 @@ //========================================================================== // Framework include files -#include "DDG4/Geant4UserLimits.h" -#include "DDG4/Geant4Particle.h" -#include "DD4hep/InstanceCount.h" -#include "DD4hep/DD4hepUnits.h" -#include "DD4hep/Primitives.h" -#include "DD4hep/Printout.h" +#include +#include +#include +#include +#include +#include // Geant 4 include files -#include "G4Track.hh" -#include "G4ParticleDefinition.hh" -#include "CLHEP/Units/SystemOfUnits.h" +#include +#include +#include -// C/C++ include files -#include - -using namespace std; using namespace dd4hep::sim; namespace { bool user_limit_debug = false; } - /// Allow for debugging user limits (very verbose) +/// Allow for debugging user limits (very verbose) bool Geant4UserLimits::enable_debug(bool value) { bool tmp = user_limit_debug; user_limit_debug = value; @@ -48,21 +44,21 @@ double Geant4UserLimits::Handler::value(const G4Track& track) const { auto i = particleLimits.find(track.GetDefinition()); if ( i != particleLimits.end() ) { if ( user_limit_debug ) { - dd4hep::printout(dd4hep::INFO,"Geant4UserLimits", "Apply explicit limit %f to track: %s", - def->GetParticleName().c_str()); + dd4hep::printout(dd4hep::INFO,"Geant4UserLimits", "Apply explicit limit %f to track: %s", + def->GetParticleName().c_str()); } return (*i).second; } } if ( user_limit_debug ) { dd4hep::printout(dd4hep::INFO,"Geant4UserLimits", "Apply default limit %f to track: %s", - def->GetParticleName().c_str()); + def->GetParticleName().c_str()); } return defaultValue; } /// Set the handler value(s) -void Geant4UserLimits::Handler::set(const string& particles, double val) { +void Geant4UserLimits::Handler::set(const std::string& particles, double val) { if ( particles == "*" || particles == ".(.*)" ) { defaultValue = val; return; @@ -108,28 +104,28 @@ void Geant4UserLimits::update(LimitSet limitset) { else if (l.name == "range_min") minRange.set(l.particles, l.value); else - throw runtime_error("Unknown Geant4 user limit: " + l.toString()); + except("Geant4UserLimits", "Unknown Geant4 user limit: %s ", l.toString().c_str()); } } /// Setters may not be called! void Geant4UserLimits::SetMaxAllowedStep(G4double /* ustepMax */) { - dd4hep::notImplemented(string(__PRETTY_FUNCTION__)+" May not be called!"); + dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!"); } void Geant4UserLimits::SetUserMaxTrackLength(G4double /* utrakMax */) { - dd4hep::notImplemented(string(__PRETTY_FUNCTION__)+" May not be called!"); + dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!"); } void Geant4UserLimits::SetUserMaxTime(G4double /* utimeMax */) { - dd4hep::notImplemented(string(__PRETTY_FUNCTION__)+" May not be called!"); + dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!"); } void Geant4UserLimits::SetUserMinEkine(G4double /* uekinMin */) { - dd4hep::notImplemented(string(__PRETTY_FUNCTION__)+" May not be called!"); + dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!"); } void Geant4UserLimits::SetUserMinRange(G4double /* urangMin */) { - dd4hep::notImplemented(string(__PRETTY_FUNCTION__)+" May not be called!"); + dd4hep::notImplemented(std::string(__PRETTY_FUNCTION__)+" May not be called!"); } diff --git a/DDG4/src/Geant4Vertex.cpp b/DDG4/src/Geant4Vertex.cpp index 5ba2de1b6..ca8f158d0 100644 --- a/DDG4/src/Geant4Vertex.cpp +++ b/DDG4/src/Geant4Vertex.cpp @@ -12,11 +12,10 @@ //========================================================================== // Framework include files -#include "DD4hep/Printout.h" -#include "DD4hep/InstanceCount.h" -#include "DDG4/Geant4Vertex.h" +#include +#include +#include -using namespace dd4hep; using namespace dd4hep::sim; /// Default destructor diff --git a/DDG4/src/Geant4VolumeManager.cpp b/DDG4/src/Geant4VolumeManager.cpp index 7449c5a13..34a402e81 100644 --- a/DDG4/src/Geant4VolumeManager.cpp +++ b/DDG4/src/Geant4VolumeManager.cpp @@ -29,20 +29,17 @@ #include using namespace dd4hep::sim::Geant4GeometryMaps; -using namespace dd4hep::detail::tools; -using namespace dd4hep::detail; using namespace dd4hep::sim; using namespace dd4hep; -using namespace std; #include -typedef pair > > VolIDDescriptor; +typedef std::pair > > VolIDDescriptor; namespace { /// Helper class to populate the Geant4 volume manager struct Populator { - typedef vector Chain; - typedef map Registries; + typedef std::vector Chain; + typedef std::map Registries; /// Reference to the Detector instance const Detector& m_detDesc; /// Set of already added entries @@ -74,10 +71,10 @@ namespace { } /// Needed to compute the cellID of parameterized volumes for( const auto& pv : m_geo.g4Placements ) { - if ( pv.second->IsParameterised() ) - m_geo.g4Parameterised[pv.second] = pv.first; - if ( pv.second->IsReplicated() ) - m_geo.g4Replicated[pv.second] = pv.first; + if ( pv.second->IsParameterised() ) + m_geo.g4Parameterised[pv.second] = pv.first; + if ( pv.second->IsReplicated() ) + m_geo.g4Replicated[pv.second] = pv.first; } } @@ -133,14 +130,14 @@ namespace { node = *(k); PlacementMap::const_iterator g4pit = m_geo.g4Placements.find(node); if (g4pit != m_geo.g4Placements.end()) { - G4VPhysicalVolume* phys = (*g4pit).second; - if ( phys->IsParameterised() ) { - PlacedVolume pv(n); - PlacedVolumeExtension* ext = pv.data(); - if ( nullptr == ext->params->field ) { - ext->params->field = iddesc.field(ext->volIDs.at(0).first); - } - } + G4VPhysicalVolume* phys = (*g4pit).second; + if ( phys->IsParameterised() ) { + PlacedVolume pv(n); + PlacedVolumeExtension* ext = pv.data(); + if ( nullptr == ext->params->field ) { + ext->params->field = iddesc.field(ext->volIDs.at(0).first); + } + } path.emplace_back(phys); printout(print_chain, "Geant4VolumeManager", "+++ Chain: Node OK: %s [%s]", node->GetName(), phys->GetName().c_str()); @@ -171,21 +168,21 @@ namespace { printout(print_res, "Geant4VolumeManager", "+++ Map %016X to Geant4 Path:%s", (void*)code, Geant4GeometryInfo::placementPath(path).c_str()); if ( m_geo.g4Paths.find(path) == m_geo.g4Paths.end() ) { - Geant4GeometryInfo::PlacementFlags opt; - for(const auto* phys : path) { - opt.flags.path_has_parametrised = phys->IsParameterised() ? 1 : 0; - opt.flags.path_has_replicated = phys->IsReplicated() ? 1 : 0; - } - opt.flags.parametrised = path.front()->IsParameterised() ? 1 : 0; - opt.flags.replicated = path.front()->IsReplicated() ? 1 : 0; + Geant4GeometryInfo::PlacementFlags opt; + for(const auto* phys : path) { + opt.flags.path_has_parametrised = phys->IsParameterised() ? 1 : 0; + opt.flags.path_has_replicated = phys->IsReplicated() ? 1 : 0; + } + opt.flags.parametrised = path.front()->IsParameterised() ? 1 : 0; + opt.flags.replicated = path.front()->IsReplicated() ? 1 : 0; m_geo.g4Paths[path] = { code, opt.value }; m_entries.emplace(code,path); return; } - /// This is a normal case for parametrized volumes and no error - if ( !path.empty() && (path.front()->IsParameterised() || path.front()->IsReplicated()) ) { - return; - } + /// This is a normal case for parametrized volumes and no error + if ( !path.empty() && (path.front()->IsParameterised() || path.front()->IsReplicated()) ) { + return; + } printout(ERROR, "Geant4VolumeManager", "populate: Severe error: Duplicated Geant4 path!!!! %s %s", " [THIS SHOULD NEVER HAPPEN]",Geant4GeometryInfo::placementPath(path).c_str()); goto Err; @@ -195,10 +192,10 @@ namespace { goto Err; } else { - /// This is a normal case for parametrized volumes and no error - if ( !path.empty() && (path.front()->IsParameterised() || path.front()->IsReplicated()) ) { - return; - } + /// This is a normal case for parametrized volumes and no error + if ( !path.empty() && (path.front()->IsParameterised() || path.front()->IsReplicated()) ) { + return; + } } printout(ERROR, "Geant4VolumeManager", "populate: Severe error: Duplicated Volume entry: 0x%X" " [THIS SHOULD NEVER HAPPEN]", code); @@ -211,7 +208,7 @@ namespace { if ( !nodes.empty() ) printout(ERROR,"Geant4VolumeManager"," TGeo path: %s",detail::tools::placementPath(nodes,false).c_str()); printout(ERROR,"Geant4VolumeManager", " Offend.VolIDs: %s",detail::tools::toString(ro.idSpec(),ids,code).c_str()); - throw runtime_error("Failed to populate Geant4 volume manager!"); + throw std::runtime_error("Failed to populate Geant4 volume manager!"); } }; } @@ -224,11 +221,11 @@ Geant4VolumeManager::Geant4VolumeManager(const Detector& description, Geant4Geom p.populate(description.world()); return; } - throw runtime_error(format("Geant4VolumeManager", "Attempt populate from invalid Geant4 geometry info [Invalid-Info]")); + except("Geant4VolumeManager", "Attempt populate from invalid Geant4 geometry info [Invalid-Info]"); } /// Helper: Generate placement path from touchable object -vector +std::vector Geant4VolumeManager::placementPath(const G4VTouchable* touchable, bool exception) const { Geant4TouchableHandler handler(touchable); return handler.placementPath(exception); @@ -237,17 +234,17 @@ Geant4VolumeManager::placementPath(const G4VTouchable* touchable, bool exception /// Check the validity of the information before accessing it. bool Geant4VolumeManager::checkValidity() const { if (!isValid()) { - throw runtime_error(format("Geant4VolumeManager", "Attempt to use invalid Geant4 volume manager [Invalid-Handle]")); + except("Geant4VolumeManager", "Attempt to use invalid Geant4 volume manager [Invalid-Handle]"); } else if (!ptr()->valid) { - throw runtime_error(format("Geant4VolumeManager", "Attempt to use invalid Geant4 geometry info [Invalid-Info]")); + except("Geant4VolumeManager", "Attempt to use invalid Geant4 geometry info [Invalid-Info]"); } return true; } #if 0 /// Access CELLID by placement path -VolumeID Geant4VolumeManager::volumeID(const vector& path) const { +VolumeID Geant4VolumeManager::volumeID(const std::vector& path) const { if (!path.empty() && checkValidity()) { const auto& mapping = ptr()->g4Paths; auto i = mapping.find(path); @@ -268,7 +265,7 @@ VolumeID Geant4VolumeManager::volumeID(const vector& p /// Access CELLID by Geant4 touchable object VolumeID Geant4VolumeManager::volumeID(const G4VTouchable* touchable) const { Geant4TouchableHandler handler(touchable); - vector path = handler.placementPath(); + std::vector path = handler.placementPath(); if (!path.empty() && checkValidity()) { const auto& mapping = ptr()->g4Paths; auto i = mapping.find(path); @@ -276,36 +273,36 @@ VolumeID Geant4VolumeManager::volumeID(const G4VTouchable* touchable) const { const auto& e = (*i).second; /// No parametrization or replication. if ( e.flags == 0 ) { - return e.volumeID; + return e.volumeID; } VolumeID volid = e.volumeID; const auto& paramterised = ptr()->g4Parameterised; const auto& replicated = ptr()->g4Replicated; /// This is incredibly slow .... but what can I do ? Need a better idea. for ( std::size_t j=0; j < path.size(); ++j ) { - const auto* phys = path[j]; - if ( phys->IsParameterised() ) { - int copy_no = touchable->GetCopyNumber(j); - const auto it = paramterised.find(phys); - if ( it != paramterised.end() ) { - //printout(INFO,"Geant4VolumeManager", - // "Copy number: %ld <--> %ld", copy_no, long(phys->GetCopyNo())); - const auto* field = (*it).second.data()->params->field; - volid |= IDDescriptor::encode(field, copy_no); - continue; - } - except("Geant4VolumeManager","Error Geant4VolumeManager::volumeID(const G4VTouchable* touchable)"); - } - else if ( phys->IsReplicated() ) { - int copy_no = touchable->GetCopyNumber(j); - const auto it = replicated.find(phys); - if ( it != replicated.end() ) { - const auto* field = (*it).second.data()->params->field; - volid |= IDDescriptor::encode(field, copy_no); - continue; - } - except("Geant4VolumeManager","Error Geant4VolumeManager::volumeID(const G4VTouchable* touchable)"); - } + const auto* phys = path[j]; + if ( phys->IsParameterised() ) { + int copy_no = touchable->GetCopyNumber(j); + const auto it = paramterised.find(phys); + if ( it != paramterised.end() ) { + //printout(INFO,"Geant4VolumeManager", + // "Copy number: %ld <--> %ld", copy_no, long(phys->GetCopyNo())); + const auto* field = (*it).second.data()->params->field; + volid |= IDDescriptor::encode(field, copy_no); + continue; + } + except("Geant4VolumeManager","Error Geant4VolumeManager::volumeID(const G4VTouchable* touchable)"); + } + else if ( phys->IsReplicated() ) { + int copy_no = touchable->GetCopyNumber(j); + const auto it = replicated.find(phys); + if ( it != replicated.end() ) { + const auto* field = (*it).second.data()->params->field; + volid |= IDDescriptor::encode(field, copy_no); + continue; + } + except("Geant4VolumeManager","Error Geant4VolumeManager::volumeID(const G4VTouchable* touchable)"); + } } return volid; } @@ -320,7 +317,7 @@ VolumeID Geant4VolumeManager::volumeID(const G4VTouchable* touchable) const { } /// Accessfully decoded volume fields by placement path -void Geant4VolumeManager::volumeDescriptor(const vector& path, +void Geant4VolumeManager::volumeDescriptor(const std::vector& path, VolIDDescriptor& vol_desc) const { vol_desc.second.clear(); diff --git a/DDG4/src/IoStreams.cpp b/DDG4/src/IoStreams.cpp index ff9414f1a..a5b41d514 100644 --- a/DDG4/src/IoStreams.cpp +++ b/DDG4/src/IoStreams.cpp @@ -12,7 +12,10 @@ //========================================================================== // Framework includes -#include "DDG4/IoStreams.h" +#include + +// ROOT include files +#include // C/C++ include files #include @@ -20,11 +23,6 @@ #include #include -// ROOT include files -#include "TFile.h" - -using namespace dd4hep; - namespace { /// Anonymous cast class to get access to protected members of TFile ;-) class MyTFile : public TFile { diff --git a/DDG4/src/python/Geant4PythonAction.cpp b/DDG4/src/python/Geant4PythonAction.cpp index 66b7dc803..a130495ab 100644 --- a/DDG4/src/python/Geant4PythonAction.cpp +++ b/DDG4/src/python/Geant4PythonAction.cpp @@ -13,23 +13,17 @@ //========================================================================== // Framework include files -#include "DDG4/Factories.h" -#include "DDG4/Python/Geant4PythonAction.h" -#include "DDG4/Python/Geant4PythonCall.h" -#include "DDG4/Python/DDPython.h" +#include +#include +#include +#include -// C/C++ include files -#include -#include - -using namespace std; -using namespace dd4hep; using namespace dd4hep::sim; DECLARE_GEANT4ACTION(Geant4PythonAction) /// Standard constructor, initializes variables -Geant4PythonAction::Geant4PythonAction(Geant4Context* ctxt, const string& nam) +Geant4PythonAction::Geant4PythonAction(Geant4Context* ctxt, const std::string& nam) : Geant4Action(ctxt,nam) { m_needsControl = true; diff --git a/DDG4/src/python/Geant4PythonCall.cpp b/DDG4/src/python/Geant4PythonCall.cpp index 60f39683e..7a61eaa29 100644 --- a/DDG4/src/python/Geant4PythonCall.cpp +++ b/DDG4/src/python/Geant4PythonCall.cpp @@ -17,10 +17,6 @@ #include #include -// C/C++ include files -#include - -using namespace dd4hep; using namespace dd4hep::sim; /// Standard constructor, initializes variables diff --git a/DDG4/src/python/Geant4PythonDetectorConstruction.cpp b/DDG4/src/python/Geant4PythonDetectorConstruction.cpp index a8213a221..02056085a 100644 --- a/DDG4/src/python/Geant4PythonDetectorConstruction.cpp +++ b/DDG4/src/python/Geant4PythonDetectorConstruction.cpp @@ -12,21 +12,20 @@ // //========================================================================== // Framework include files -#include "DDG4/Geant4Context.h" -#include "DDG4/Geant4Kernel.h" +#include +#include -#include "DDG4/Python/DDPython.h" -#include "DDG4/Python/Geant4PythonAction.h" -#include "DDG4/Python/Geant4PythonDetectorConstruction.h" +#include +#include +#include -using namespace std; using namespace dd4hep::sim; -#include "DDG4/Factories.h" +#include DECLARE_GEANT4ACTION(Geant4PythonDetectorConstruction) /// Standard constructor, initializes variables -Geant4PythonDetectorConstruction::Geant4PythonDetectorConstruction(Geant4Context* ctxt, const string& nam) +Geant4PythonDetectorConstruction::Geant4PythonDetectorConstruction(Geant4Context* ctxt, const std::string& nam) : Geant4DetectorConstruction(ctxt,nam), m_constructSD(), m_constructFLD(), m_constructGEO() { @@ -49,7 +48,7 @@ void Geant4PythonDetectorConstruction::setConstructSensitives(PyObject* callable } /// Execute command in the python interpreter -void Geant4PythonDetectorConstruction::exec(const string& desc, const Geant4PythonCall& cmd) const { +void Geant4PythonDetectorConstruction::exec(const std::string& desc, const Geant4PythonCall& cmd) const { if ( cmd.isValid() ) { int ret = cmd.execute(); if ( ret != 1 ) { diff --git a/DDG4/src/python/Geant4PythonDetectorConstructionLast.cpp b/DDG4/src/python/Geant4PythonDetectorConstructionLast.cpp index caa699248..48eec5eb9 100644 --- a/DDG4/src/python/Geant4PythonDetectorConstructionLast.cpp +++ b/DDG4/src/python/Geant4PythonDetectorConstructionLast.cpp @@ -15,8 +15,8 @@ #define DD4HEP_DDG4_GEANT4PYTHONDETECTORCONSTRUCTIONLAST_H // Framework include files -#include "DDG4/Geant4DetectorConstruction.h" -#include "DDG4/Python/DDPython.h" +#include +#include /// Namespace for the AIDA detector description toolkit namespace dd4hep { diff --git a/DDG4/src/python/Geant4PythonInitialization.cpp b/DDG4/src/python/Geant4PythonInitialization.cpp index bb751becd..3d3151996 100644 --- a/DDG4/src/python/Geant4PythonInitialization.cpp +++ b/DDG4/src/python/Geant4PythonInitialization.cpp @@ -13,18 +13,17 @@ //========================================================================== // Framework include files -#include "DDG4/Factories.h" -#include "DDG4/Geant4Kernel.h" -#include "DDG4/Python/DDPython.h" -#include "DDG4/Python/Geant4PythonInitialization.h" +#include +#include +#include +#include -using namespace std; using namespace dd4hep::sim; DECLARE_GEANT4ACTION(Geant4PythonInitialization) /// Standard constructor, initializes variables -Geant4PythonInitialization::Geant4PythonInitialization(Geant4Context* ctxt, const string& nam) +Geant4PythonInitialization::Geant4PythonInitialization(Geant4Context* ctxt, const std::string& nam) : Geant4UserInitialization(ctxt,nam), m_masterSetup(), m_workerSetup() { m_needsControl = true; @@ -41,7 +40,7 @@ void Geant4PythonInitialization::setWorkerSetup(PyObject* callable, PyObject* ar } /// Execute command in the python interpreter -void Geant4PythonInitialization::exec(const string& desc, const Geant4PythonCall& cmd) const { +void Geant4PythonInitialization::exec(const std::string& desc, const Geant4PythonCall& cmd) const { if ( cmd.isValid() ) { int ret = cmd.execute(); if ( ret != 1 ) { diff --git a/DDG4/tpython/DDPython.cpp b/DDG4/tpython/DDPython.cpp index 7c02786ec..352ef97ad 100644 --- a/DDG4/tpython/DDPython.cpp +++ b/DDG4/tpython/DDPython.cpp @@ -20,8 +20,8 @@ #include // Framework include files -#include "DD4hep/Printout.h" -#include "DDG4/Python/DDPython.h" +#include +#include #if !defined(__MAKECINT__) && !defined(__CINT__) && !defined(G__DICTIONARY) // ----------------------------------------------------------------------------- @@ -38,13 +38,10 @@ #include "Python.h" #endif -using namespace std; -using namespace dd4hep; - namespace { - string loadScript(const string& fname) { - ifstream file(fname.c_str()); - stringstream str; + std::string loadScript(const std::string& fname) { + std::ifstream file(fname.c_str()); + std::stringstream str; if( file ) { char ch; while( file.get(ch) ) str.put(ch); @@ -54,14 +51,14 @@ namespace { return ""; } + static dd4hep::DDPython* _instance = 0; static int _blockers = 0; static pthread_t _mainThread = 0; static int _refCount = 0; - static DDPython* _instance = 0; static PyObject* _main_dict = 0; static PyThreadState *_save_state = 0; int _execPy(const char* cmd) { - DDPython::GILState state(0); + dd4hep::DDPython::GILState state(0); PyObject* ret = ::PyRun_String((char*)cmd, Py_file_input,_main_dict,_main_dict); if ( ::PyErr_Occurred() ) { ::PyErr_Print(); @@ -80,7 +77,7 @@ namespace { return 0; } int _evalPy(const char* cmd) { - DDPython::GILState state(0); + dd4hep::DDPython::GILState state(0); PyObject* ret = ::PyRun_String((char*)cmd, Py_eval_input,_main_dict,_main_dict); if ( ::PyErr_Occurred() ) { ::PyErr_Print(); @@ -100,44 +97,44 @@ namespace { } } -DDPython::GILState::GILState(int) : state(0) { +dd4hep::DDPython::GILState::GILState(int) : state(0) { if ( ::Py_IsInitialized() ) { PyGILState_STATE st = (PyGILState_STATE)::PyGILState_Ensure(); state = (int)st; } } -DDPython::GILState::~GILState() { +dd4hep::DDPython::GILState::~GILState() { if ( ::Py_IsInitialized() ) { PyGILState_STATE st = (PyGILState_STATE)state; ::PyGILState_Release(st); } } -DDPython::BlockThreads::BlockThreads(int) { +dd4hep::DDPython::BlockThreads::BlockThreads(int) { if ( _blockers == 0 ) { DDPython::restoreThread(); } ++_blockers; } -DDPython::BlockThreads::~BlockThreads() { +dd4hep::DDPython::BlockThreads::~BlockThreads() { --_blockers; if ( _blockers == 0 ) { DDPython::allowThreads(); } } -DDPython::AllowThreads::AllowThreads(int) { +dd4hep::DDPython::AllowThreads::AllowThreads(int) { DDPython::allowThreads(); } -DDPython::AllowThreads::~AllowThreads() { +dd4hep::DDPython::AllowThreads::~AllowThreads() { DDPython::restoreThread(); } /// Standard constructor, initializes variables -DDPython::DDPython() : context(0) { +dd4hep::DDPython::DDPython() : context(0) { ++_refCount; bool inited = ::Py_IsInitialized(); if ( !inited ) { @@ -173,7 +170,7 @@ DDPython::DDPython() : context(0) { } /// Default Destructor -DDPython::~DDPython() { +dd4hep::DDPython::~DDPython() { --_refCount; if ( 0 == _refCount && ::Py_IsInitialized() ) { dd4hep::printout(ALWAYS,"DDPython","+++ Shutdown python interpreter......"); @@ -190,32 +187,32 @@ DDPython::~DDPython() { } -DDPython DDPython::instance() { +dd4hep::DDPython dd4hep::DDPython::instance() { if ( 0 == _instance ) _instance = new DDPython(); return DDPython(); } /// Save thread state -void DDPython::allowThreads() { +void dd4hep::DDPython::allowThreads() { if ( !_save_state && ::Py_IsInitialized() ) { _save_state = ::PyEval_SaveThread(); } } -void DDPython::restoreThread() { +void dd4hep::DDPython::restoreThread() { if ( _save_state ) { ::PyEval_RestoreThread(_save_state); _save_state = 0; } } -int DDPython::setArgs(int argc, char** argv) const { +int dd4hep::DDPython::setArgs(int argc, char** argv) const { // Need to protect against API change from Python 2 to Python 3 #if PY_VERSION_HEX < 0x03000000 ::PySys_SetArgv(argc,argv); #else - vector wargs; - vector wargv; + std::vector wargs; + std::vector wargv; for(int i=0; i("\0")); } -void DDPython::afterFork() const { +void dd4hep::DDPython::afterFork() const { if ( ::Py_IsInitialized() ) { - cout << "[INFO] Re-init python after forking....." << endl; + std::cout << "[INFO] Re-init python after forking....." << std::endl; #if PY_VERSION_HEX < 0x03070000 ::PyOS_AfterFork(); #else @@ -319,21 +316,21 @@ void DDPython::afterFork() const { } } -void DDPython::setMainThread() { +void dd4hep::DDPython::setMainThread() { _mainThread = pthread_self(); } -bool DDPython::isMainThread() { +bool dd4hep::DDPython::isMainThread() { return _mainThread == pthread_self(); } /// Start the interpreter in normal mode without hacks like 'pythopn.exe' does. -int DDPython::run_interpreter(int argc, char** argv) { +int dd4hep::DDPython::run_interpreter(int argc, char** argv) { #if PY_VERSION_HEX < 0x03000000 return ::Py_Main(argc, argv); #else - vector wargs; - vector wargv; + std::vector wargs; + std::vector wargv; for(int i=0; i