diff --git a/DDCore/src/DD4hepRootPersistency.cpp b/DDCore/src/DD4hepRootPersistency.cpp index 2c8f6ed04bcf85b31d19193008bdb2bbbe9e6a19..889eaa491786cb2d600330a0cd93d4a7c6f15525 100644 --- a/DDCore/src/DD4hepRootPersistency.cpp +++ b/DDCore/src/DD4hepRootPersistency.cpp @@ -27,50 +27,66 @@ ClassImp(DD4hepRootPersistency) using namespace dd4hep; using namespace std; - int DD4hepRootPersistency::save(Detector& description, const char* fname, const char* instance) { TFile* f = TFile::Open(fname,"RECREATE"); if ( f && !f->IsZombie()) { - TTimeStamp start; - DD4hepRootPersistency* persist = new DD4hepRootPersistency(); - persist->m_data = new dd4hep::DetectorData(); - persist->m_data->adoptData(dynamic_cast<DetectorData&>(description),false); - for( const auto& s : persist->m_data->m_sensitive ) { - dd4hep::SensitiveDetector sd = s.second; - dd4hep::Readout ro = sd.readout(); - if ( ro.isValid() && ro.segmentation().isValid() ) { - persist->m_segments[ro].first = ro.idSpec(); - persist->m_segments[ro].second = ro.segmentation().segmentation(); + try { + TTimeStamp start; + DetectorData::patchRootStreamer(TGeoVolume::Class()); + DetectorData::patchRootStreamer(TGeoNode::Class()); + DD4hepRootPersistency* persist = new DD4hepRootPersistency(); + persist->m_data = new dd4hep::DetectorData(); + persist->m_data->adoptData(dynamic_cast<DetectorData&>(description),false); + for( const auto& s : persist->m_data->m_sensitive ) { + dd4hep::SensitiveDetector sd = s.second; + dd4hep::Readout ro = sd.readout(); + if ( ro.isValid() && ro.segmentation().isValid() ) { + persist->m_segments[ro].first = ro.idSpec(); + persist->m_segments[ro].second = ro.segmentation().segmentation(); + } } - } - if ( persist->volumeManager().isValid() ) { - for( const auto& mgr : persist->m_data->m_volManager->managers ) { - for( const auto& v : mgr.second->volumes ) { - persist->nominals[v.second->element] = v.second->element.nominal(); + if ( persist->volumeManager().isValid() ) { + for( const auto& mgr : persist->m_data->m_volManager->managers ) { + for( const auto& v : mgr.second->volumes ) { + persist->nominals[v.second->element] = v.second->element.nominal(); + } } + printout(ALWAYS,"DD4hepRootPersistency","+++ Saving %ld nominals....",persist->nominals.size()); + } + else { + printout(ALWAYS, + "DD4hepRootPersistency","+++ No valid Volume manager. No nominals saved.", + persist->nominals.size()); } - printout(ALWAYS,"DD4hepRootPersistency","+++ Saving %ld nominals....",persist->nominals.size()); - } - else { - printout(ALWAYS, - "DD4hepRootPersistency","+++ No valid Volume manager. No nominals saved.", - persist->nominals.size()); - } - /// Now we write the object - int nBytes = persist->Write(instance); - f->Close(); - TTimeStamp stop; - printout(ALWAYS,"DD4hepRootPersistency", - "+++ Wrote %d Bytes of geometry data '%s' to '%s' [%8.3f seconds].", - nBytes, instance, fname, stop.AsDouble()-start.AsDouble()); - if ( nBytes > 0 ) { + /// Now we write the object + int nBytes = persist->Write(instance); + f->Close(); + TTimeStamp stop; printout(ALWAYS,"DD4hepRootPersistency", - "+++ Successfully saved geometry data to file."); + "+++ Wrote %d Bytes of geometry data '%s' to '%s' [%8.3f seconds].", + nBytes, instance, fname, stop.AsDouble()-start.AsDouble()); + if ( nBytes > 0 ) { + printout(ALWAYS,"DD4hepRootPersistency", + "+++ Successfully saved geometry data to file."); + } + delete f; + delete persist; + DetectorData::unpatchRootStreamer(TGeoVolume::Class()); + DetectorData::unpatchRootStreamer(TGeoNode::Class()); + return nBytes; + } + catch (const exception& e) { + DetectorData::unpatchRootStreamer(TGeoVolume::Class()); + DetectorData::unpatchRootStreamer(TGeoNode::Class()); + except("DD4hepRootPersistency","Exception %s while saving file %s",e.what(), fname); } - delete f; - delete persist; - return nBytes; + catch (...) { + DetectorData::unpatchRootStreamer(TGeoVolume::Class()); + DetectorData::unpatchRootStreamer(TGeoNode::Class()); + except("DD4hepRootPersistency","UNKNOWN exception while saving file %s", fname); + } + return 0; } printout(ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname); return 0; @@ -79,73 +95,91 @@ int DD4hepRootPersistency::save(Detector& description, const char* fname, const int DD4hepRootPersistency::load(Detector& description, const char* fname, const char* instance) { TFile* f = TFile::Open(fname); if ( f && !f->IsZombie()) { - TTimeStamp start; - unique_ptr<DD4hepRootPersistency> persist((DD4hepRootPersistency*)f->Get(instance)); - if ( persist.get() ) { - DetectorData* source = persist->m_data; + try { + TTimeStamp start; + DetectorData::patchRootStreamer(TGeoVolume::Class()); + DetectorData::patchRootStreamer(TGeoNode::Class()); + unique_ptr<DD4hepRootPersistency> persist((DD4hepRootPersistency*)f->Get(instance)); + if ( persist.get() ) { + DetectorData* source = persist->m_data; #if 0 - const auto& iddesc = persist->idSpecifications(); - for( const auto& s : iddesc ) { - IDDescriptor id = s.second; - id.rebuild(id->description); - } - printout(ALWAYS,"DD4hepRootPersistency", - "+++ Fixed %ld IDDescriptor objects.",iddesc.size()); + const auto& iddesc = persist->idSpecifications(); + for( const auto& s : iddesc ) { + IDDescriptor id = s.second; + id.rebuild(id->description); + } + printout(ALWAYS,"DD4hepRootPersistency", + "+++ Fixed %ld IDDescriptor objects.",iddesc.size()); #endif - for( const auto& s : persist->m_segments ) { - Readout ro = s.first; - IDDescriptor id = s.second.first; - DDSegmentation::Segmentation* seg = s.second.second; - ro.setSegmentation(Segmentation(seg->type(),seg->name(),id.decoder())); - delete seg; - } - printout(ALWAYS,"DD4hepRootPersistency", - "+++ Fixed %ld segmentation objects.",persist->m_segments.size()); - persist->m_segments.clear(); - if ( persist->volumeManager().isValid() ) { - const auto& sdets = persist->volumeManager()->subdetectors; - size_t num[3] = {0,0,0}; - for( const auto& vm : sdets ) { - VolumeManager::Object* obj = vm.second.ptr(); - obj->system = obj->id.field("system"); - if ( 0 != obj->system ) { + for( const auto& s : persist->m_segments ) { + Readout ro = s.first; + IDDescriptor id = s.second.first; + DDSegmentation::Segmentation* seg = s.second.second; + ro.setSegmentation(Segmentation(seg->type(),seg->name(),id.decoder())); + delete seg; + } + printout(ALWAYS,"DD4hepRootPersistency", + "+++ Fixed %ld segmentation objects.",persist->m_segments.size()); + persist->m_segments.clear(); + if ( persist->volumeManager().isValid() ) { + const auto& sdets = persist->volumeManager()->subdetectors; + size_t num[3] = {0,0,0}; + for( const auto& vm : sdets ) { + VolumeManager::Object* obj = vm.second.ptr(); + obj->system = obj->id.field("system"); + if ( 0 != obj->system ) { + printout(ALWAYS,"DD4hepRootPersistency", + "+++ Fixed VolumeManager.system for %-24s %6ld volumes %4ld sdets %4ld mgrs.", + obj->detector.path().c_str(), obj->volumes.size(), + obj->subdetectors.size(), obj->managers.size()); + num[0] += obj->volumes.size(); + num[1] += obj->subdetectors.size(); + num[2] += obj->managers.size(); + continue; + } printout(ALWAYS,"DD4hepRootPersistency", - "+++ Fixed VolumeManager.system for %-24s %6ld volumes %4ld sdets %4ld mgrs.", - obj->detector.path().c_str(), obj->volumes.size(), - obj->subdetectors.size(), obj->managers.size()); - num[0] += obj->volumes.size(); - num[1] += obj->subdetectors.size(); - num[2] += obj->managers.size(); - continue; + "+++ FAILED to fix VolumeManager.system for '%s: %s'.", + obj->detector.path().c_str(), "[No IDDescriptor field 'system']"); } printout(ALWAYS,"DD4hepRootPersistency", - "+++ FAILED to fix VolumeManager.system for '%s: %s'.", - obj->detector.path().c_str(), "[No IDDescriptor field 'system']"); + "+++ Fixed VolumeManager TOTALS %-24s %6ld volumes %4ld sdets %4ld mgrs.","",num[0],num[1],num[2]); + printout(ALWAYS,"DD4hepRootPersistency","+++ loaded %ld nominals....",persist->nominals.size()); } - printout(ALWAYS,"DD4hepRootPersistency", - "+++ Fixed VolumeManager TOTALS %-24s %6ld volumes %4ld sdets %4ld mgrs.","",num[0],num[1],num[2]); - printout(ALWAYS,"DD4hepRootPersistency","+++ loaded %ld nominals....",persist->nominals.size()); - } - else { - printout(ALWAYS,"DD4hepRootPersistency","+++ Volume manager NOT restored. [Was it ever up when saved?]"); - } - DetectorData* tar_data = dynamic_cast<DetectorData*>(&description); - DetectorData* src_data = dynamic_cast<DetectorData*>(source); - if( tar_data != nullptr && src_data != nullptr ){ - tar_data->adoptData(*src_data,false); - TTimeStamp stop; - printout(ALWAYS,"DD4hepRootPersistency", - "+++ Successfully loaded detector description from file:%s [%8.3f seconds]", - fname, stop.AsDouble()-start.AsDouble()); - return 1; + else { + printout(ALWAYS,"DD4hepRootPersistency","+++ Volume manager NOT restored. [Was it ever up when saved?]"); + } + DetectorData* tar_data = dynamic_cast<DetectorData*>(&description); + DetectorData* src_data = dynamic_cast<DetectorData*>(source); + if( tar_data != nullptr && src_data != nullptr ){ + tar_data->adoptData(*src_data,false); + TTimeStamp stop; + printout(ALWAYS,"DD4hepRootPersistency", + "+++ Successfully loaded detector description from file:%s [%8.3f seconds]", + fname, stop.AsDouble()-start.AsDouble()); + DetectorData::unpatchRootStreamer(TGeoVolume::Class()); + DetectorData::unpatchRootStreamer(TGeoNode::Class()); + return 1; + } + DetectorData::unpatchRootStreamer(TGeoVolume::Class()); + DetectorData::unpatchRootStreamer(TGeoNode::Class()); + return 0; } - return 0; + printout(ERROR,"DD4hepRootPersistency", + "+++ Cannot Cannot load instance '%s' from file '%s'.", + instance, fname); + f->ls(); + delete f; + } + catch (const exception& e) { + DetectorData::unpatchRootStreamer(TGeoVolume::Class()); + DetectorData::unpatchRootStreamer(TGeoNode::Class()); + except("DD4hepRootPersistency","Exception %s while loading file %s",e.what(), fname); + } + catch (...) { + DetectorData::unpatchRootStreamer(TGeoVolume::Class()); + DetectorData::unpatchRootStreamer(TGeoNode::Class()); + except("DD4hepRootPersistency","UNKNOWN exception while loading %s", fname); } - printout(ERROR,"DD4hepRootPersistency", - "+++ Cannot Cannot load instance '%s' from file '%s'.", - instance, fname); - f->ls(); - delete f; return 0; } printout(ERROR,"DD4hepRootPersistency","+++ Cannot open file '%s'.",fname); diff --git a/DDCore/src/DetectorData.cpp b/DDCore/src/DetectorData.cpp index 8d299f9adef7089df7f02904f1f0fb9da17fc385..cfba9150fefccdfbd4cc6419de23c9f30e349730 100644 --- a/DDCore/src/DetectorData.cpp +++ b/DDCore/src/DetectorData.cpp @@ -167,8 +167,6 @@ DetectorData::DetectorData() cl->AdoptStreamer(new TClassStreamer(stream_opaque_datablock)); printout(INFO,"PersistencyIO","+++ Set Streamer to %s",cl->GetName()); } - DetectorData::patchRootStreamer(TGeoVolume::Class()); - DetectorData::patchRootStreamer(TGeoNode::Class()); } InstanceCount::increment(this); } diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 6dc66594b9cee2e74aa3acbe3a729bd5b2b02240..e399431d54ce86b367ec6d736700bb656e8a19de 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -266,17 +266,39 @@ template <> void Converter<Plugin>::operator()(xml_h e) const { vector<char*> argv; vector<string> arguments; string name = plugin.nameStr(); - for (xml_coll_t coll(e, _U(arg)); coll; ++coll) { - string val = coll.attr<string>(_U(value)); - arguments.push_back(val); + string type = "default"; + xml_attr_t typ_attr = e.attr_nothrow(_U(type)); + if ( typ_attr ) { + type = e.attr<string>(_U(type)); } - for (xml_coll_t coll(e, _U(argument)); coll; ++coll) { - string val = coll.attr<string>(_U(value)); - arguments.push_back(val); + if ( type == "default" ) { + for (xml_coll_t coll(e, _U(arg)); coll; ++coll) { + string val = coll.attr<string>(_U(value)); + arguments.push_back(val); + } + for (xml_coll_t coll(e, _U(argument)); coll; ++coll) { + string val = coll.attr<string>(_U(value)); + arguments.push_back(val); + } + for(vector<string>::iterator i=arguments.begin(); i!=arguments.end(); ++i) + argv.push_back(&((*i)[0])); + description.apply(name.c_str(),int(argv.size()), &argv[0]); + return; + } + // Call a custom plugin taking the xml element as an argument + long result = PluginService::Create<long>(name, &description, &e); + if (0 == result) { + PluginDebug dbg; + result = PluginService::Create<long>(name, &description, &e); + if ( 0 == result ) { + except("Compact","++ Failed to locate plugin %s - no factory: %s", + name.c_str(), dbg.missingFactory(name).c_str()); + } + } + result = *(long*) result; + if (result != 1) { + except("Compact","++ Failed to execute plugin %s", name.c_str()); } - for(vector<string>::iterator i=arguments.begin(); i!=arguments.end(); ++i) - argv.push_back(&((*i)[0])); - description.apply(name.c_str(),int(argv.size()), &argv[0]); } /** Convert compact constant objects (defines) diff --git a/DDCore/src/plugins/ShapePlugins.cpp b/DDCore/src/plugins/ShapePlugins.cpp index 899805e39a7729778a3b97f58bed1ed1e2a91418..080b7b77903041cf7b2754d55ecefce0480005b9 100644 --- a/DDCore/src/plugins/ShapePlugins.cpp +++ b/DDCore/src/plugins/ShapePlugins.cpp @@ -158,7 +158,9 @@ static Handle<TObject> create_Trap(Detector&, xml_h element) { double x2 = e.x2(); double x3 = (attr=element.attr_nothrow(_U(x3))) ? element.attr<double>(attr) : x1; double x4 = (attr=element.attr_nothrow(_U(x4))) ? element.attr<double>(attr) : x2; - solid = Trap(e.z(0.0),e.theta(0),e.phi(0),e.y1(),x1,x2,e.alpha1(0),e.y2(),x3,x4,e.alpha2(0)); + double y1 = e.y1(); + double y2 = (attr=element.attr_nothrow(_U(y2))) ? element.attr<double>(attr) : y1; + solid = Trap(e.z(0.0),e.theta(0),e.phi(0),y1,x1,x2,e.alpha1(0),y2,x3,x4,e.alpha2(0)); } if ( e.hasAttr(_U(name)) ) solid->SetName(e.attr<string>(_U(name)).c_str()); return solid; diff --git a/DDEve/CMakeLists.txt b/DDEve/CMakeLists.txt index 0d81534ca82c766c54e1a23427546f838dbce2d2..73ae27a7605649e5ae2c0b05c1dbca9b09d56867 100644 --- a/DDEve/CMakeLists.txt +++ b/DDEve/CMakeLists.txt @@ -23,7 +23,7 @@ dd4hep_add_dictionary ( G__DDEve LINKDEF ${DDCore_INCLUDE_DIRS}/include/ROOT/LinkDef.h ) # -dd4hep_add_plugin ( DDEve SOURCES src/*.cpp +dd4hep_add_plugin ( DDEvePlugins SOURCES src/*.cpp GENERATED G__DDEve.cxx OPTIONAL [LCIO EXTERNAL SOURCES lcio/LCIOEventHandler.cpp] ) diff --git a/DDEve/DDEve/DDEve.C b/DDEve/DDEve/DDEve.C index 08f2464d89d8f77a87fc102ac29460fe91cd2090..061f0456dfdf59e9d11b786cdaa41cf756de90d5 100644 --- a/DDEve/DDEve/DDEve.C +++ b/DDEve/DDEve/DDEve.C @@ -52,7 +52,7 @@ void DDEve(const char* xmlConfig=0, const char* evtData=0) { else { Error("DDEve","+++ No DDG4 IO library 'libDDG4IO' present!"); } - result = gSystem->Load("libDDEve"); + result = gSystem->Load("libDDEvePlugins"); if ( 0 != result ) { Error("DDEve","++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Error("DDEve","+++ Your dd4hep installation seems incomplete. FAILED to load the library 'libdd4hepEve'! +++"); diff --git a/examples/DDDB/CMakeLists.txt b/examples/DDDB/CMakeLists.txt index 53edb965589b7c02d3d7a8fa376591af17b04891..169bef78019e71633a06ff28343eb3eca55782d2 100644 --- a/examples/DDDB/CMakeLists.txt +++ b/examples/DDDB/CMakeLists.txt @@ -29,7 +29,6 @@ if (DD4HEP_USE_XERCESC) [ROOT REQUIRED COMPONENTS Geom] [DD4hep REQUIRED COMPONENTS DDCore DDCond] INCLUDE_DIRS include - INSTALL_INCLUDES include/DDDB include/Detector include/Kernel ) #