diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index afc76e70a1d6c3484bd1faeb7b9ec62dc6cd6a2c..4590b7745ef3f4aed496d524c51801c66bf1d4ee 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -262,7 +262,7 @@ static int ddcond_detelement_dump(Detector& description, int argc, char** argv) Actor actor(printer); int ret = actor.process(description.world(),0,true); slice->manager.clean(pool->validity().iovType, 20); - return ret; + return ret > 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump) @@ -324,7 +324,7 @@ static int ddcond_detelement_processor(Detector& description, int argc, char** a processor->setPool(pool); int ret = Actor(processor).process(description.world(),0,true); slice->manager.clean(pool->validity().iovType, 20); - return ret; + return ret > 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_DetElementConditionsProcessor,ddcond_detelement_processor) #endif diff --git a/DDCore/include/DD4hep/DD4hepRootPersistency.h b/DDCore/include/DD4hep/DD4hepRootPersistency.h index edf04cd34c0f5d3d59b9310462aec3f262addc33..9f5e0ecad0a7cf6f5d8c3535c0952a6a07b223a7 100644 --- a/DDCore/include/DD4hep/DD4hepRootPersistency.h +++ b/DDCore/include/DD4hep/DD4hepRootPersistency.h @@ -120,23 +120,23 @@ public: /// Call to theck the DD4hep fields size_t checkFields() const; /// Call to check a Region object - size_t checkRegions() const; + std::pair<std::size_t, std::size_t> checkRegions() const; /// Call to check a Readout object - size_t checkReadouts() const; + std::pair<std::size_t, std::size_t> checkReadouts() const; /// Call to check an ID specification - size_t checkIdSpecs() const; + std::pair<std::size_t, std::size_t> checkIdSpecs() const; /// Call to check a sensitive detector - size_t checkSensitives() const; + std::pair<std::size_t, std::size_t> checkSensitives() const; /// Call to check a limit-set object - size_t checkLimitSets() const; + std::pair<std::size_t, std::size_t> checkLimitSets() const; /// Call to check the volume manager hierarchy - size_t checkVolManager() const; + std::pair<std::size_t, std::size_t> checkVolManager() const; /// Call to check the nominal alignments in the DetElement hierarchy - size_t checkNominals() const; + std::pair<std::size_t, std::size_t> checkNominals() const; /// Call to check a top level Detector element (subdetector) - size_t checkDetectors() const; + std::pair<std::size_t, std::size_t> checkDetectors() const; /// Call to check segmentations starting from the top level Detector element - size_t checkSegmentations() const; + std::pair<std::size_t, std::size_t> checkSegmentations() const; /// Check all of the above size_t checkAll() const; }; diff --git a/DDCore/include/DD4hep/Factories.h b/DDCore/include/DD4hep/Factories.h index 8caf059b00617b91f5150bd6cad16bc932675bdc..e70b9aff44af4c39cd3b199052002a1dc57235b7 100644 --- a/DDCore/include/DD4hep/Factories.h +++ b/DDCore/include/DD4hep/Factories.h @@ -218,8 +218,12 @@ namespace { DD4HEP_PLUGIN_FACTORY_ARGS_3(void*,dd4hep::Detector*,int,char**) { return dd4hep::DetectorConstructionFactory<P>::create(*a0,a1,a2); } - DD4HEP_PLUGIN_FACTORY_ARGS_3(long,dd4hep::Detector*,int,char**) - { return make_return<long>(dd4hep::ApplyFactory<P>::create(*a0,a1,a2)); } + DD4HEP_PLUGIN_FACTORY_ARGS_3(long,dd4hep::Detector*,int,char**) { + static long ret; + ret = dd4hep::ApplyFactory<P>::create(*a0,a1,a2); + //return dd4hep::PluginFactoryBase::make_return<long>(ret); + return (long)&ret; + } DD4HEP_PLUGIN_FACTORY_ARGS_2(ns::Named*,dd4hep::Detector*,ns::xml_h*) { return dd4hep::XMLElementFactory<P>::create(*a0,*a1).ptr(); } @@ -227,8 +231,12 @@ namespace { DD4HEP_PLUGIN_FACTORY_ARGS_2(TObject*,dd4hep::Detector*,ns::xml_h*) { return dd4hep::XMLObjectFactory<P>::create(*a0,*a1).ptr(); } - DD4HEP_PLUGIN_FACTORY_ARGS_2(long,dd4hep::Detector*,ns::xml_h*) - { return make_return<long>(dd4hep::XMLDocumentReaderFactory<P>::create(*a0,*a1)); } + DD4HEP_PLUGIN_FACTORY_ARGS_2(long,dd4hep::Detector*,ns::xml_h*) { + static long ret; + ret = dd4hep::XMLDocumentReaderFactory<P>::create(*a0,*a1); + //return dd4hep::PluginFactoryBase::make_return<long>(ret); + return long(&ret); + } DD4HEP_PLUGIN_FACTORY_ARGS_3(ns::Named*,dd4hep::Detector*,ns::xml_h*,ns::ref_t*) { return dd4hep::XmlDetElementFactory<P>::create(*a0,*a1,*a2).ptr(); } diff --git a/DDCore/include/DD4hep/Plugins.h b/DDCore/include/DD4hep/Plugins.h index fcb9a53f647c7a4b0c2de88f87f482be64acd2fa..e071c75d5a07cb4d861ec56b8fe7ce6e13f14d8f 100644 --- a/DDCore/include/DD4hep/Plugins.h +++ b/DDCore/include/DD4hep/Plugins.h @@ -55,7 +55,7 @@ namespace dd4hep { template <typename T> static T val(const T* _p) { return T(*_p); } template <typename T> static T value(const void* _p) { return (T)_p; } static const char* value(const void* _p) { return (const char*)(_p); } - template <typename T> static T make_return(const T& _p) { return _p; } + //template <typename T> static T make_return(const T& _p);// { return _p; } }; template <> inline int PluginFactoryBase::value<int>(const void* _p) { return *(int*)(_p); } template <> inline long PluginFactoryBase::value<long>(const void* _p) { return *(long*)(_p); } @@ -99,7 +99,8 @@ namespace dd4hep { return (*fptr.fcn)(std::forward<Args>(args)...); #elif DD4HEP_PLUGINSVC_VERSION==2 f = getCreator(id,typeid(R(Args...))); - return std::any_cast<func>(f)(std::forward<Args>(args)...); + if ( std::any_cast<func>(f) ) + return std::any_cast<func>(f)(std::forward<Args>(args)...); #endif } catch(const std::bad_any_cast& e) { @@ -141,11 +142,13 @@ namespace { /// Base factory template template <typename P, typename S> class Factory {}; } - +#if 0 namespace dd4hep { template <> inline long PluginFactoryBase::make_return(const long& value) { static long stored=value; return (long)&stored; } } +#endif + #define DD4HEP_FACTORY_CALL(type,name,signature) dd4hep::PluginRegistry<signature>::add(name,Factory<type,signature>::call) #define DD4HEP_IMPLEMENT_PLUGIN_REGISTRY(X,Y) diff --git a/DDCore/src/DD4hepRootPersistency.cpp b/DDCore/src/DD4hepRootPersistency.cpp index ef37f2df3f242cac51eb932525d2a31a07531c02..1926a6e7bd79c4fd2f6f82194d3c2641a8d31181 100644 --- a/DDCore/src/DD4hepRootPersistency.cpp +++ b/DDCore/src/DD4hepRootPersistency.cpp @@ -27,6 +27,16 @@ ClassImp(DD4hepRootPersistency) using namespace dd4hep; using namespace std; +namespace { + /// Ensure nominal alignments are loaded before saving + void load_nominal_alignments(DetElement de) { + de.nominal(); + de.survey(); + for(const auto& c : de.children()) + load_nominal_alignments(c.second); + } +} + /// Default constructor DD4hepRootPersistency::DD4hepRootPersistency() : TNamed() { } @@ -42,6 +52,7 @@ int DD4hepRootPersistency::save(Detector& description, const char* fname, const TTimeStamp start; DetectorData::patchRootStreamer(TGeoVolume::Class()); DetectorData::patchRootStreamer(TGeoNode::Class()); + load_nominal_alignments(description.world()); DD4hepRootPersistency* persist = new DD4hepRootPersistency(); persist->m_data = new dd4hep::DetectorData(); persist->m_data->adoptData(dynamic_cast<DetectorData&>(description),false); @@ -470,7 +481,7 @@ size_t DD4hepRootCheck::checkMaterials() const { } /// Call to check a Readout object -size_t DD4hepRootCheck::checkReadouts() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkReadouts() const { size_t count = 0; PersistencyChecks checks; for( const auto& obj : object->readouts() ) @@ -484,7 +495,7 @@ size_t DD4hepRootCheck::checkReadouts() const { } printout(ALWAYS,"chkNominals","+++ %s Checked %ld readout objects. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return count; + return { count, checks.errors }; } /// Call to theck the DD4hep fields @@ -499,71 +510,71 @@ size_t DD4hepRootCheck::checkFields() const { } /// Call to check a Region object -size_t DD4hepRootCheck::checkRegions() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkRegions() const { size_t count = 0; PersistencyChecks checks; for( const auto& obj : object->regions() ) count += checks.checkRegion(obj.second); printout(ALWAYS,"chkRegions","+++ %s Checked %ld Region objects. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return checks.errors; + return { count, checks.errors }; } /// Call to check an ID specification -size_t DD4hepRootCheck::checkIdSpecs() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkIdSpecs() const { size_t count = 0; PersistencyChecks checks; for( const auto& obj : object->idSpecifications() ) count += checks.checkIDDescriptor(obj.second); printout(ALWAYS,"chkReadouts","+++ %s Checked %ld Readout objects. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return checks.errors; + return { count, checks.errors }; } /// Call to check a top level Detector element (subdetector) -size_t DD4hepRootCheck::checkDetectors() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkDetectors() const { size_t count = 0; PersistencyChecks checks; for( const auto& obj : object->detectors() ) count += checks.checkDetector(obj.second); printout(ALWAYS,"chkDetectors","+++ %s Checked %ld DetElement objects. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return checks.errors; + return { count, checks.errors }; } /// Call to check a sensitive detector -size_t DD4hepRootCheck::checkSensitives() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkSensitives() const { size_t count = 0; PersistencyChecks checks; for( const auto& obj : object->sensitiveDetectors() ) count += checks.checkSensitive(obj.second); printout(ALWAYS,"chkSensitives","+++ %s Checked %ld SensitiveDetector objects. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return checks.errors; + return { count, checks.errors }; } /// Call to check a limit-set object -size_t DD4hepRootCheck::checkLimitSets() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkLimitSets() const { PersistencyChecks checks; size_t count = 0; for( const auto& obj : object->limitsets() ) count += checks.checkLimitset(obj.second); printout(ALWAYS,"chkSensitives","+++ %s Checked %ld SensitiveDetector objects. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return checks.errors; + return { count, checks.errors }; } /// Call to check the volume manager hierarchy -size_t DD4hepRootCheck::checkVolManager() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkVolManager() const { PersistencyChecks checks; size_t count = checks.checkNominals(object->volumeManager()); printout(ALWAYS,"chkNominals","+++ %s Checked %ld VolumeManager contexts. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return count; + return { count , checks.errors }; } /// Call to check the nominal alignments in the detector hierarchy (for sensitive detectors) -size_t DD4hepRootCheck::checkNominals() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkNominals() const { size_t count = 0; PersistencyChecks checks; const auto& dets = object->sensitiveDetectors(); @@ -571,11 +582,11 @@ size_t DD4hepRootCheck::checkNominals() const { count += checks.checkDetectorNominals(object->detector(d.first)); printout(ALWAYS,"chkNominals","+++ %s Checked %ld DetElements. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return count; + return { count, checks.errors }; } /// Call to check the segmentations starting from the top level detector -size_t DD4hepRootCheck::checkSegmentations() const { +std::pair<std::size_t, std::size_t> DD4hepRootCheck::checkSegmentations() const { size_t count = 0; PersistencyChecks checks; const auto& dets = object->sensitiveDetectors(); @@ -585,7 +596,7 @@ size_t DD4hepRootCheck::checkSegmentations() const { } printout(ALWAYS,"chkNominals","+++ %s Checked %ld readout segmentations. Num.Errors: %ld", checks.errors==0 ? "PASSED" : "FAILED", count, checks.errors); - return count; + return { count, checks.errors }; } size_t DD4hepRootCheck::checkAll() const { @@ -610,7 +621,7 @@ size_t DD4hepRootCheck::checkAll() const { for( const auto& obj : object->sensitiveDetectors() ) count += checks.checkSensitive(obj.second); - count += checkVolManager(); + count += checkVolManager().first; printout(ALWAYS,"chkAll","+++ Checked %ld objects. Num.Errors:%ld", count, checks.errors); return count; diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index ffd0d15cd76108d67d5beec458340512e3875f02..fa6690c90cb9f2fd6ba52bd46f1ee3794b53eb8f 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -872,7 +872,8 @@ DECLARE_APPLY(DD4hep_RootLoader,load_geometryFromroot) */ static long check_detectors(Detector& description, int /* argc */, char** /* argv */) { DD4hepRootCheck check(&description); - return check.checkDetectors(); + auto ret = check.checkDetectors(); + return ret.first > 0 && ret.second == 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_CheckDetectors,check_detectors) @@ -886,7 +887,8 @@ DECLARE_APPLY(DD4hep_CheckDetectors,check_detectors) */ static long check_sensitives(Detector& description, int /* argc */, char** /* argv */) { DD4hepRootCheck check(&description); - return check.checkSensitives(); + auto ret = check.checkSensitives(); + return ret.first > 0 && ret.second == 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_CheckSensitives,check_sensitives) @@ -900,7 +902,8 @@ DECLARE_APPLY(DD4hep_CheckSensitives,check_sensitives) */ static long check_segmentations(Detector& description, int /* argc */, char** /* argv */) { DD4hepRootCheck check(&description); - return check.checkSegmentations(); + auto ret = check.checkSegmentations(); + return ret.first > 0 && ret.second == 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_CheckSegmentations,check_segmentations) @@ -914,7 +917,8 @@ DECLARE_APPLY(DD4hep_CheckSegmentations,check_segmentations) */ static long check_readouts(Detector& description, int /* argc */, char** /* argv */) { DD4hepRootCheck check(&description); - return check.checkReadouts(); + auto ret = check.checkReadouts(); + return ret.first > 0 && ret.second == 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_CheckReadouts,check_readouts) @@ -928,7 +932,8 @@ DECLARE_APPLY(DD4hep_CheckReadouts,check_readouts) */ static long check_idspecs(Detector& description, int /* argc */, char** /* argv */) { DD4hepRootCheck check(&description); - return check.checkIdSpecs(); + auto ret = check.checkIdSpecs(); + return ret.first > 0 && ret.second == 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_CheckIdspecs,check_idspecs) @@ -942,7 +947,8 @@ DECLARE_APPLY(DD4hep_CheckIdspecs,check_idspecs) */ static long check_volumemanager(Detector& description, int /* argc */, char** /* argv */) { DD4hepRootCheck check(&description); - return check.checkVolManager(); + auto ret = check.checkVolManager(); + return ret.first > 0 && ret.second == 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_CheckVolumeManager,check_volumemanager) @@ -956,7 +962,8 @@ DECLARE_APPLY(DD4hep_CheckVolumeManager,check_volumemanager) */ static long check_nominals(Detector& description, int /* argc */, char** /* argv */) { DD4hepRootCheck check(&description); - return check.checkNominals(); + auto ret = check.checkNominals(); + return ret.first > 0 && ret.second == 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_CheckNominals,check_nominals) @@ -1269,7 +1276,7 @@ static int detelement_processor(Detector& description, int argc, char** argv) except("DetElementProcessor","++ Unknown plugin argument: %s",argv[i]); } } - return DetectorScanner().scan(*proc, det, 0, recursive); + return DetectorScanner().scan(*proc, det, 0, recursive) > 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_DetElementProcessor,detelement_processor) @@ -1319,7 +1326,7 @@ static int placed_volume_processor(Detector& description, int argc, char** argv) except("PlacedVolumeProcessor","++ Unknown plugin argument: %s",argv[i]); } } - return PlacedVolumeScanner().scanPlacements(*proc, pv, 0, recursive); + return PlacedVolumeScanner().scanPlacements(*proc, pv, 0, recursive) > 0 ? 1 : 0; } DECLARE_APPLY(DD4hep_PlacedVolumeProcessor,placed_volume_processor) diff --git a/DDG4/include/DDG4/Factories.h b/DDG4/include/DDG4/Factories.h index 75838c0f48ca70df55c2c2c6a40ff96f03756f45..681e2ad4232371f30670ca822a9ba1509d92dbfd 100644 --- a/DDG4/include/DDG4/Factories.h +++ b/DDG4/include/DDG4/Factories.h @@ -17,6 +17,7 @@ #include "DDG4/Defs.h" #include "DD4hep/Plugins.h" #include "DD4hep/Printout.h" +#include "DD4hep/Factories.h" #include "DD4hep/Primitives.h" // C/C++ include files @@ -82,9 +83,11 @@ namespace { typedef G4MagIntegratorStepper Stepper; }; - DD4HEP_PLUGIN_FACTORY_ARGS_3(long, dd4hep::Detector*, const _ns::GH*, const _ns::STRM*) - { return make_return<long>(dd4hep::Geant4SetupAction<P>::create(*a0, *a1, *a2)); } - + DD4HEP_PLUGIN_FACTORY_ARGS_3(long, dd4hep::Detector*, const _ns::GH*, const _ns::STRM*) { + static long ret; + ret = dd4hep::Geant4SetupAction<P>::create(*a0, *a1, *a2); + return long(&ret); + } /// Factory to create Geant4 sensitive detectors DD4HEP_PLUGIN_FACTORY_ARGS_2(G4VSensitiveDetector*,std::string,dd4hep::Detector*) { return dd4hep::Geant4SensitiveDetectorFactory<P>::create(a0,*a1); } @@ -128,7 +131,9 @@ namespace { /// Generic particle constructor DD4HEP_PLUGIN_FACTORY_ARGS_0(long) { P::ConstructParticle(); - return make_return<long>(1L); + static long ret; + ret = 1L; + return long(&ret); } /// Factory to create Geant4 physics constructions diff --git a/examples/DDCMS/src/plugins/DDCMSDetElementCreator.cpp b/examples/DDCMS/src/plugins/DDCMSDetElementCreator.cpp index 08e351fa2a25d19354e2b06e6a1485ffaaf75252..c71eb2046e04dcf50285f8948c99f9bf585b5e3c 100644 --- a/examples/DDCMS/src/plugins/DDCMSDetElementCreator.cpp +++ b/examples/DDCMS/src/plugins/DDCMSDetElementCreator.cpp @@ -344,7 +344,6 @@ int DDCMSDetElementCreator::process(PlacedVolume pv, int level, bool recursive) if ( stack.size() == 3 ) { current_sensitive = SensitiveDetector(); current_detector = DetElement(); - ret = 0; } stack.pop_back(); return ret; diff --git a/examples/Persistency/CMakeLists.txt b/examples/Persistency/CMakeLists.txt index 67b35b0518e09bfd8deeab55143c4296603b228c..c86fcdf759cbed23787edae3d4f809aba9a6f99c 100644 --- a/examples/Persistency/CMakeLists.txt +++ b/examples/Persistency/CMakeLists.txt @@ -177,7 +177,7 @@ dd4hep_add_test_reg( Persist_CLICSiD_Restore_Nominal_LONGTEST -plugin DD4hep_RootLoader CLICSiD_geometry.root -plugin DD4hep_CheckNominals DEPENDS Persist_CLICSiD_Save_LONGTEST - REGEX_PASS "\\+\\+\\+ FAILED Checked 15994 DetElements. Num.Errors: 50" + REGEX_PASS "\\+\\+\\+ PASSED Checked 16044 DetElements. Num.Errors: 0" REGEX_FAIL "EXCEPTION;Exception;TStreamerInfo" ) #