diff --git a/DDCore/include/DD4hep/Factories.h b/DDCore/include/DD4hep/Factories.h index 10d8e46eaa393357c17b4d2108c8e51dfe493155..9a83be1c876e06dbb07f151978b7fb5ae02f4c35 100644 --- a/DDCore/include/DD4hep/Factories.h +++ b/DDCore/include/DD4hep/Factories.h @@ -243,13 +243,15 @@ namespace { using DD4hep::Geometry::xml_document_##name;\ PLUGINSVC_FACTORY_WITH_ID(xml_document_##name,std::string(#name "_XML_reader"),long(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*)) -#define DECLARE_XML_PROCESSOR(name,func) \ - namespace DD4hep { namespace Geometry { struct det_element_##name {}; \ - template <> DD4hep::Geometry::Ref_t DetElementFactory< DD4hep::Geometry::det_element_##name >::create(DD4hep::Geometry::LCDD& l,DD4hep::XML::Handle_t e,DD4hep::Geometry::Ref_t h){return func(l,e,h);}}} \ - using DD4hep::Geometry::det_element_##name;\ +#define DECLARE_XML_PROCESSOR_BASIC(name,func,deprecated) \ + namespace DD4hep { namespace Geometry { struct det_element_##name {}; \ + template <> DD4hep::Geometry::Ref_t DetElementFactory< DD4hep::Geometry::det_element_##name >::create(DD4hep::Geometry::LCDD& l,DD4hep::XML::Handle_t e,DD4hep::Geometry::Ref_t h){ if (deprecated) warning_deprecated_xml_factory(#name); return func(l,e,h);}} } \ + using DD4hep::Geometry::det_element_##name; \ PLUGINSVC_FACTORY_WITH_ID(det_element_##name,std::string(#name),DD4hep::NamedObject*(DD4hep::Geometry::LCDD*,DD4hep::XML::Handle_t*,DD4hep::Geometry::Ref_t*)) -#define DECLARE_SUBDETECTOR(name,func) DECLARE_XML_PROCESSOR(name,func) -#define DECLARE_DETELEMENT(name,func) DECLARE_XML_PROCESSOR(name,func) +#define DECLARE_XML_PROCESSOR(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,0) +#define DECLARE_SUBDETECTOR(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,0) +#define DECLARE_DETELEMENT(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,0) +#define DECLARE_DEPRECATED_DETELEMENT(name,func) DECLARE_XML_PROCESSOR_BASIC(name,func,1) #endif // DD4HEP_FACTORIES_H diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h index b0235102785fa98d694cfb459768f7a6f278ff6e..7fc02ee25b9814d563af52ed763520dcc59b57d9 100644 --- a/DDCore/include/DD4hep/Handle.h +++ b/DDCore/include/DD4hep/Handle.h @@ -143,6 +143,9 @@ namespace DD4hep { long num_object_validations(); void increment_object_validations(); + /// Function tp print warning about deprecated factory usage. Used by Plugin mechanism. + void warning_deprecated_xml_factory(const char* name); + /// Access to the magic word, which is protecting some objects against memory corruptions \ingroup DD4HEP_GEOMETRY inline unsigned long long int magic_word() { diff --git a/DDCore/src/Handle.cpp b/DDCore/src/Handle.cpp index 5623982933284d460a2f629fb7037714605d6ec1..9b331b1300c15feb0fc0ae29a1b826072fb76aba 100644 --- a/DDCore/src/Handle.cpp +++ b/DDCore/src/Handle.cpp @@ -11,6 +11,7 @@ #include "DD4hep/Handle.inl" #include "XML/Evaluator.h" #include <iostream> +#include <iomanip> #include <cstring> #include <cstdio> @@ -154,6 +155,15 @@ namespace DD4hep { void increment_object_validations() { ++s_numVerifies; } + void warning_deprecated_xml_factory(const char* name) { + const char* edge = "++++++++++++++++++++++++++++++++++++++++++"; + size_t len = ::strlen(name); + cerr << edge << edge << edge << endl; + cerr << "++ The usage of the factory: \"" << name << "\" is DEPRECATED due to naming conventions." + << setw(53-len) << right << "++" << endl; + cerr << "++ Please use \"DD4hep_" << name << "\" instead." << setw(93-len) << right << "++" << endl; + cerr << edge << edge << edge << endl; + } } } diff --git a/DDCore/src/LCDDLoad.cpp b/DDCore/src/LCDDLoad.cpp index e3a46e017fd64b8d4adf66669e6b89627d8cd05b..72da881b197055b875ecc62e18098878bb82aa74 100644 --- a/DDCore/src/LCDDLoad.cpp +++ b/DDCore/src/LCDDLoad.cpp @@ -75,11 +75,11 @@ void LCDDLoad::processXML(const XML::Handle_t& base, const string& xmlfile) { void LCDDLoad::processXMLElement(const std::string& xmlfile, const XML::Handle_t& xml_root) { string tag = xml_root.tag(); string type = tag + "_XML_reader"; - long result = PluginService::Create<long>(type, m_lcdd, &xml_root); + XML::Handle_t handle = xml_root; + long result = PluginService::Create<long>(type, m_lcdd, &handle); if (0 == result) { PluginDebug dbg; - XML::Handle_t handle = xml_root; - result = PluginService::Create<long>(type, m_lcdd, &handle); + result = PluginService::Create<long>(type, m_lcdd, &xml_root); if ( 0 == result ) { throw runtime_error("DD4hep: Failed to locate plugin to interprete files of type" " \"" + tag + "\" - no factory:" + type + ". " + dbg.missingFactory(type)); diff --git a/DDCore/src/XML/DocumentHandler.cpp b/DDCore/src/XML/DocumentHandler.cpp index 28af8311e2bcac6f87ea943f23fc18aea97c3572..83b7a01522f85ef51c19d68aacb3e6163d4eca29 100644 --- a/DDCore/src/XML/DocumentHandler.cpp +++ b/DDCore/src/XML/DocumentHandler.cpp @@ -177,12 +177,12 @@ Document DocumentHandler::load(Handle_t base, const XMLCh* fname) const { } Document DocumentHandler::load(const string& fname) const { - printout(INFO,"DocumentHandler","+++ Loading document URI: %s",fname.c_str()); + printout(DEBUG,"DocumentHandler","+++ Loading document URI: %s",fname.c_str()); XMLURL xerurl = (const XMLCh*) Strng_t(fname); string path = _toString(xerurl.getPath()); string proto = _toString(xerurl.getProtocolName()); auto_ptr < XercesDOMParser > parser(make_parser(m_errHdlr.get())); - printout(INFO,"DocumentHandler","+++ protocol:%s path:%s",proto.c_str(), path.c_str()); + printout(DEBUG,"DocumentHandler","+++ protocol:%s path:%s",proto.c_str(), path.c_str()); try { parser->parse(path.c_str()); } diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 5e5f5af931e44dfeebc7e1658d680096d1b058fd..8b99d8540f7081dd391383d5e5543897dbb00cb4 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -494,9 +494,9 @@ template <> void Converter<Region>::operator()(xml_h e) const { /** Specialized converter for compact readout objects. * * <readout name="HcalBarrelHits"> - * <segmentation type="RegularNgonCartesianGridXY" gridSizeX="3.0*cm" gridSizeY="3.0*cm" /> - * <id>system:6,barrel:3,module:4,layer:8,slice:5,x:32:-16,y:-16</id> - * </readout> + * <segmentation type="RegularNgonCartesianGridXY" gridSizeX="3.0*cm" gridSizeY="3.0*cm" /> + * <id>system:6,barrel:3,module:4,layer:8,slice:5,x:32:-16,y:-16</id> + * </readout> */ template <> void Converter<Readout>::operator()(xml_h e) const { xml_h id = e.child(_U(id)); @@ -505,6 +505,7 @@ template <> void Converter<Readout>::operator()(xml_h e) const { Readout ro(name); Ref_t idSpec; + printout(DEBUG, "Compact", "++ Creating readout structure: %s.",ro.name()); if (seg) { // Segmentation is not mandatory! string type = seg.attr<string>(_U(type)); Segmentation segment(type, name); @@ -539,7 +540,6 @@ template <> void Converter<Readout>::operator()(xml_h e) const { ro.setIDDescriptor(idSpec); lcdd.addIDSpecification(idSpec); } - printout(DEBUG, "Compact", "++ Registered readout structure: %s.",ro.name()); lcdd.addReadout(ro); } @@ -796,7 +796,7 @@ template <> void Converter<DetElementInclude>::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(); - if ( tag == "lcdd" ) + if ( tag == "lccdd" ) Converter < Compact > (this->lcdd)(node); else if ( tag == "define" ) xml_coll_t(node, _U(constant)).for_each(Converter < Constant > (this->lcdd)); @@ -812,7 +812,6 @@ template <> void Converter<Compact>::operator()(xml_h element) const { char text[32]; xml_elt_t compact(element); xml_coll_t(compact, _U(includes)).for_each(_U(gdmlFile), Converter < GdmlFile > (lcdd)); - xml_coll_t(compact, _U(include)).for_each(Converter < DetElementInclude > (this->lcdd)); if (element.hasChild(_U(info))) (Converter < Header > (lcdd))(xml_h(compact.child(_U(info)))); @@ -832,6 +831,8 @@ template <> void Converter<Compact>::operator()(xml_h element) const { xml_coll_t(compact, _U(detectors)).for_each(_U(include), Converter < DetElementInclude > (lcdd)); printout(DEBUG, "Compact", "++ Converting detector structures..."); xml_coll_t(compact, _U(detectors)).for_each(_U(detector), Converter < DetElement > (lcdd)); + xml_coll_t(compact, _U(include)).for_each(Converter < DetElementInclude > (this->lcdd)); + xml_coll_t(compact, _U(includes)).for_each(_U(alignment), Converter < AlignmentFile > (lcdd)); xml_coll_t(compact, _U(includes)).for_each(_U(xml), Converter < XMLFile > (lcdd)); xml_coll_t(compact, _U(alignments)).for_each(_U(alignment), Converter < AlignmentEntry > (lcdd)); diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp index e58e0aa66ada35e905062987d43a7d5a6c724a98..0450a7533b477044a5a88b95cfcf1e4cbd362623 100644 --- a/DDG4/plugins/Geant4SDActions.cpp +++ b/DDG4/plugins/Geant4SDActions.cpp @@ -124,7 +124,7 @@ namespace DD4hep { // Geant4SensitiveAction<OpticalCalorimeter> // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - /// Helper class to define properti4es of optical calorimeters. UNTESTED + /// Helper class to define properties of optical calorimeters. UNTESTED /** * \author M.Frank * \version 1.0 @@ -172,9 +172,16 @@ namespace DD4hep { } typedef Geant4SensitiveAction<Geant4OpticalCalorimeter> Geant4OpticalCalorimeterAction; - /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - /// Geant4SensitiveAction<TrackerCombine> - /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + /// Geant4 sensitive detector combining all deposits of one G4Track within one sensitive element. + /** + * Geant4SensitiveAction<TrackerCombine> + * + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_SIMULATION + */ struct TrackerCombine { typedef Geant4Tracker::Hit Hit; typedef Geant4HitCollection HitCollection; @@ -189,6 +196,7 @@ namespace DD4hep { TrackerCombine() : pre(), post(), sensitive(0), track(0), e_cut(0.0), current(-1), combined(0) { } + /// Start a new hit void start(G4Step* step, G4StepPoint* point) { pre.storePoint(step,point); current = pre.truth.trackID; @@ -198,12 +206,14 @@ namespace DD4hep { combined = 0; } + /// Update energy and track information during hit info accumulation void update(G4Step* step) { post.storePoint(step,step->GetPostStepPoint()); pre.truth.deposit += post.truth.deposit; ++combined; } + /// Clear collected information and restart for new hit void clear() { post.clear(); pre.clear(); @@ -216,6 +226,7 @@ namespace DD4hep { return track && current != tr->GetTrackID(); } + /// Extract hit information and add the created hit to the collection Hit* extractHit(HitCollection* collection) { if ( current == -1 || !track ) { return 0; @@ -291,7 +302,6 @@ namespace DD4hep { extractHit(coll); } } - }; /// Initialization overload for specialization diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index d7ce891a5be568daab81d9a8d32626162aeb130d..a33e70a70f644e6654da14f2d0fa7825fdf7c464 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -341,7 +341,10 @@ void* Geant4Converter::handleMaterial(const string& name, Material medium) const } } else { - mat = new G4Material(name, m->GetZ(), m->GetA(), density, state, m->GetTemperature(), m->GetPressure()); + double z = m->GetZ(), a = m->GetA(); + if ( z < 1.0000001 ) z = 1.0; + if ( a < 0.5000001 ) a = 1.0; + mat = new G4Material(name, z, a, density, state, m->GetTemperature(), m->GetPressure()); } stringstream str; str << (*mat); diff --git a/doc/Detector_constructor_naming_convention.txt b/doc/Detector_constructor_naming_convention.txt new file mode 100644 index 0000000000000000000000000000000000000000..479dec7f845445257dca1dfd20b78aadb6bc1fd0 --- /dev/null +++ b/doc/Detector_constructor_naming_convention.txt @@ -0,0 +1,36 @@ + +Proposal for detector constructor names +======================================= + +Detector constructors are identified by a unique name. This name is +identical to the name of the creating factory object. +This small writeup is a proposal to properly name these factory +methods in order to avoid nameing clashes. + + +- Experiment specific detector constructors names have the + experiment name as a namespace prefix + examples: CLIC_<detector>, ILD_<detector>, etc. +- Experiment specific detector constructors reside in + experiment specific packages such as ddsim (for ILD). + + +- Generic DD4hep detectors will have the prefix DD4hep_ + +__or__ (to be discussed) + +- Generic DD4hep detectors will have no prefix +- Generic DD4hep detector constructors reside in the package DDDetectors + (to be created) + + +In case a experiment specific detector constructor is sufficiently +generic that it could be applied in several detector designs and +hence the visiblility should be upgraded, the detector constructor +may be imported to DDDetectors. + +- Consequently the detector constructor prefix has to change. +- For some time (e.g. 1 year) the old factory may still be + supported along with some ugly deprecation printout. + +