diff --git a/DDCore/src/XML/DocumentHandler.cpp b/DDCore/src/XML/DocumentHandler.cpp index c4b195ddc5deb0acf89e6c4ae7ee38712d736482..70d311711d00005d091e2545cb8824a151405cb3 100644 --- a/DDCore/src/XML/DocumentHandler.cpp +++ b/DDCore/src/XML/DocumentHandler.cpp @@ -239,6 +239,10 @@ string DocumentHandler::system_path(Handle_t base, const string& fn) { string DocumentHandler::system_path(Handle_t base) { DOMElement* elt = (DOMElement*)base.ptr(); string path = _toString(elt->getBaseURI()); + if ( path[0] == '/' ) { + string tmp = "file:"+path; + return tmp; + } return path; } @@ -287,11 +291,14 @@ 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 std::string& fname, UriReader* reader) const { +Document DocumentHandler::load(const string& fname, UriReader* reader) const { string path; printout(DEBUG,"DocumentHandler","+++ Loading document URI: %s",fname.c_str()); try { - XMLURL xerurl = (const XMLCh*) Strng_t(fname.find(":")==std::string::npos ? "file:"+fname : fname); + 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()); path = _toString(xerurl.getPath()); printout(DEBUG,"DocumentHandler","+++ protocol:%s path:%s",proto.c_str(), path.c_str()); diff --git a/DDDB/include/DDDB/DDDBConversion.h b/DDDB/include/DDDB/DDDBConversion.h index f4b37f479f674954fef3e517d0670ad02b8f3a7c..b5f6f0cdbd38d09ce74e25f35ac19cee53789ec6 100644 --- a/DDDB/include/DDDB/DDDBConversion.h +++ b/DDDB/include/DDDB/DDDBConversion.h @@ -63,11 +63,12 @@ namespace DD4hep { */ struct Named { typedef std::map<std::string, std::string> StringMap; + typedef std::map<std::string, std::pair<std::string,std::string > > StringPairMap; std::string name, id; int refCount; - Named() : refCount(1) {} - Named(const std::string& c) : name(c), id(), refCount(1) {} - Named(const Named& c) : name(c.name), id(c.id), refCount(1) {} + Named() : refCount(0) {} + Named(const std::string& c) : name(c), id(), refCount(0) {} + Named(const Named& c) : name(c.name), id(c.id), refCount(0) {} Named& operator=(const Named& c) { if ( this != &c ) { name=c.name; @@ -75,8 +76,10 @@ namespace DD4hep { } return *this; } + virtual ~Named() {} const char* c_name() const { return name.c_str(); } - const char* c_id() const { return id.c_str(); } + const char* c_id() const { return id.c_str(); } + void release() { if ( --refCount <= 0 ) delete this; } }; struct ConditionParam { @@ -96,7 +99,11 @@ namespace DD4hep { std::string classID; Params params; Params paramVectors; - Condition() : Named() {} + /// Default constructor + Condition(); + /// Default destructor + virtual ~Condition(); + Condition* addRef() { ++refCount; return this; } }; /// Intermediate structure representing author's data @@ -126,7 +133,12 @@ namespace DD4hep { */ struct Isotope : public Named { double A,Z,density; - Isotope() : Named() {} + /// Default constructor + Isotope(); + /// Default destructor + virtual ~Isotope(); + /// Reference count mechanism + Isotope* addRef() { ++refCount; return this; } }; /// Intermediate structure representing data of a Element @@ -140,12 +152,13 @@ namespace DD4hep { double density, ionization; int state; - Element() : density(0), ionization(0), state(UNKNOWN) {} - Element(const Element& e) - : Named(e), isotopes(e.isotopes), path(e.path), symbol(e.symbol), - atom(e.atom), density(e.density), - ionization(e.ionization), state(e.state) - {} + /// Default constructor + Element(); + /// Copy constructor + Element(const Element& e); + /// Default destructor + virtual ~Element(); + /// Reference count mechanism Element* addRef() { ++refCount; return this; } }; @@ -177,7 +190,11 @@ namespace DD4hep { Components components; Properties properties; double density, pressure, temperature, radlen, lambda; - Material() : density(0), pressure(-1), temperature(-1), radlen(0), lambda(0) {} + /// Default constructor + Material(); + /// Default destructor + virtual ~Material(); + /// Reference count mechanism Material* addRef() { ++refCount; return this; } }; @@ -360,8 +377,12 @@ namespace DD4hep { int type; std::string logvol, path; Transform3D trafo; - PhysVol() : type(PHYSVOL_REGULAR), logvol(), path(), trafo() {} - PhysVol(const PhysVol& c) : Named(c), type(c.type), logvol(c.logvol), path(c.path), trafo(c.trafo) {} + /// Default constructor + PhysVol(); + /// Copy constructor + PhysVol(const PhysVol& c); + /// Default destructor + virtual ~PhysVol(); PhysVol& operator=(const PhysVol& c) { if ( this != &c ) { this->Named::operator=(c); @@ -372,6 +393,8 @@ namespace DD4hep { } return *this; } + /// Reference count mechanism + PhysVol* addRef() { ++refCount; return this; } }; /// Structure supporting conversion of parametrized physical volumes @@ -380,7 +403,9 @@ namespace DD4hep { struct ParamPhysVol : public PhysVol { int number1; Transform3D trafo1; + /// Default constructor ParamPhysVol() : PhysVol(), number1(0) { type = PHYSVOL_PARAM1D; } + /// Copy constructor ParamPhysVol(const ParamPhysVol& c) : PhysVol(c), number1(c.number1), trafo1(c.trafo1) {} ParamPhysVol& operator=(const ParamPhysVol& c) { if ( this != &c ) { @@ -398,6 +423,7 @@ namespace DD4hep { struct ParamPhysVol2D : public ParamPhysVol { int number2; Transform3D trafo2; + /// Default constructor ParamPhysVol2D() : ParamPhysVol(), number2(0), trafo2() { type = PHYSVOL_PARAM2D; } }; @@ -407,6 +433,7 @@ namespace DD4hep { struct ParamPhysVol3D : public ParamPhysVol2D { int number3; Transform3D trafo3; + /// Default constructor ParamPhysVol3D() : ParamPhysVol2D(), number3(0), trafo3() { type = PHYSVOL_PARAM3D; } }; @@ -416,7 +443,11 @@ namespace DD4hep { struct LogVol : public Named { std::string material, shape, path; std::vector<PhysVol*> physvols; - LogVol() : Named(), material(), shape(), physvols() { } + /// Default constructor + LogVol(); + /// Default destructor + virtual ~LogVol(); + /// Reference count mechanism LogVol* addRef() { ++refCount; return this; } }; @@ -426,16 +457,21 @@ namespace DD4hep { struct Catalog : public Named { typedef std::map<std::string, Catalog*> CatRefs; typedef std::map<std::string, LogVol*> LvRefs; - LvRefs logvolrefs; - LvRefs logvols; - CatRefs catalogrefs; - CatRefs catalogs; - StringMap params, conditioninfo; - std::string type, path, author, version, logvol, condition, support, npath; - int level; - Catalog() : Named(), level(0) { } - std::pair<const Catalog*,std::string> parent(const std::string& nam) const; + LvRefs logvolrefs; + LvRefs logvols; + CatRefs catalogrefs; + CatRefs catalogs; + StringPairMap params; + StringMap conditioninfo; + std::string type, path, author, version, logvol, condition, support, npath; + int level, typeID; + /// Default constructor + Catalog(); + /// Default destructor + virtual ~Catalog(); + /// Reference count mechanism Catalog* addRef() { ++refCount; return this; } + std::pair<const Catalog*,std::string> parent(const std::string& nam) const; }; /// Structure supporting conversion of any arbitrary shape @@ -475,6 +511,8 @@ namespace DD4hep { Shape(); /// Default destructor ~Shape(); + /// Reference count mechanism + Shape* addRef() { ++refCount; return this; } }; /// LHCb geometry description interface to the conditions database @@ -515,7 +553,7 @@ namespace DD4hep { /// Inventory of volume placements Placements placements, placementPaths; /// Inventory of conditions - Conditions conditions; + Conditions conditions, conditionPaths; /// Inventory of catalogs Catalogs catalogs, catalogPaths; /// Detector element hierarchy diff --git a/DDDB/src/CondDB2DDDB.cpp b/DDDB/src/CondDB2DDDB.cpp index 9cc9d1ec33607f45fde3b78c74a16caf891afa54..0afea1b0cf9338d88ab7bd964bc1ac989c5c05d0 100644 --- a/DDDB/src/CondDB2DDDB.cpp +++ b/DDDB/src/CondDB2DDDB.cpp @@ -83,25 +83,42 @@ namespace DD4hep { } template <typename T,typename Q> void _collect(const string& id, T* object, Q& container) { + typename Q::const_iterator i=container.find(id); + if ( i != container.end() ) { + if ( object == (*i).second ) return; + printout(ERROR,"collect","++ Duplicate ID: %s %p <-> %p", + id.c_str(), object, (*i).second); + } object->id = id; - container[id] = object; + container[id] = object->addRef(); dddb_print(this,object); } template <typename T,typename Q> - void _collectP(const string& path, T* object, Q& container) { container[path] = object; } - void collect(const string& id, Catalog* obj) { _collect(id, obj, geo->catalogs); } - void collect(const string& id, Shape* obj) { _collect(id, obj, geo->shapes); } - void collect(const string& id, PhysVol* obj) { _collect(id, obj, geo->placements); } - void collect(const string& id, LogVol* obj) { _collect(id, obj, geo->volumes); } - void collect(const string& id, Isotope* obj) { _collect(id, obj, geo->isotopes); } - void collect(const string& id, Element* obj) { _collect(id, obj, geo->elements); } - void collect(const string& id, Material* obj) { _collect(id, obj, geo->materials); } - - void collectPath(const string& path, Element* obj) { _collectP(path, obj, geo->elementPaths); } - void collectPath(const string& path, Material* obj) { _collectP(path, obj, geo->materialPaths); } - void collectPath(const string& path, PhysVol* obj) { _collectP(path, obj, geo->placementPaths); } - void collectPath(const string& path, LogVol* obj) { _collectP(path, obj, geo->volumePaths); } - void collectPath(const string& path, Catalog* obj) { _collectP(path, obj, geo->catalogPaths); } + void collect(Q& container, const string& path, T* object) { + typename Q::const_iterator i=container.find(path); + if ( i != container.end() ) { + if ( object == (*i).second ) return; + printout(ERROR,"collectPath","++ Duplicate ID: %s %p <-> %p", + path.c_str(), object, (*i).second); + } + container[path] = object->addRef(); + } + + void collect(const string& id, Catalog* obj) { _collect(id, obj, geo->catalogs); } + void collect(const string& id, Shape* obj) { _collect(id, obj, geo->shapes); } + void collect(const string& id, PhysVol* obj) { _collect(id, obj, geo->placements); } + void collect(const string& id, LogVol* obj) { _collect(id, obj, geo->volumes); } + void collect(const string& id, Isotope* obj) { _collect(id, obj, geo->isotopes); } + void collect(const string& id, Element* obj) { _collect(id, obj, geo->elements); } + void collect(const string& id, Material* obj) { _collect(id, obj, geo->materials); } + void collect(const string& id, Condition* obj) { _collect(id, obj, geo->conditions); } + + void collectPath(const string& path, Element* obj) { collect(geo->elementPaths, path, obj); } + void collectPath(const string& path, Material* obj) { collect(geo->materialPaths, path, obj); } + void collectPath(const string& path, PhysVol* obj) { collect(geo->placementPaths, path, obj); } + void collectPath(const string& path, LogVol* obj) { collect(geo->volumePaths, path, obj); } + void collectPath(const string& path, Catalog* obj) { collect(geo->catalogPaths, path, obj); } + void collectPath(const string& path, Condition* obj) { collect(geo->conditionPaths, path, obj); } StringSet files; Locals locals; @@ -226,13 +243,13 @@ namespace DD4hep { return hash == string::npos ? ref : ref.substr(hash+1); } - void print_ref(const char* desc, Context* context, xml_h element, const string& href) { + void print_ref(const char* desc, Context* context, xml_h element, const string& href, const string& opt="") { string path = reference_path(context,href); string obj = reference_obj(href); string id1 = object_path(context,href); string id2 = reference_href(element,href); - printout(INFO, desc, "** %s --> %s path: %s # %s", - id1.c_str(), id2.c_str(), path.c_str(), obj.c_str()); + printout(INFO, desc, "** %s --> %s path: %s # %s %s", + id1.c_str(), id2.c_str(), path.c_str(), obj.c_str(), opt.c_str()); } void load_dddb_entity(LCDD& lcdd, Context* context, xml_h element, const string& ref); @@ -251,6 +268,8 @@ namespace DD4hep { { if ( context->print_logvol ) DD4hep::dddb_print(obj); } void dddb_print(Context* context, const Catalog* obj) { if ( context->print_catalog ) DD4hep::dddb_print(obj); } + void dddb_print(Context* context, const Condition* obj) + { if ( context->print_condition ) DD4hep::dddb_print(obj); } /// Helper to locate objects in a map using string identifiers template <typename Q> bool find(const string& id, const Q& container) { @@ -348,10 +367,11 @@ namespace DD4hep { /// Specialized conversion of <param/> entities template <> void DDDBConverter<Param>::convert(xml_h element) const { - Catalog* det = _option<Catalog>(); - string name = element.attr<string>(_U(name)); - string type = element.hasAttr(_U(type)) ? element.attr<string>(_U(type)) : string("int"); - det->params[name] = type; + Catalog* det = _option<Catalog>(); + string name = element.attr<string>(_U(name)); + string type = element.hasAttr(_U(type)) ? element.attr<string>(_U(type)) : string("int"); + string value = element.text(); + det->params[name] = make_pair(type,value); } /// Specialized conversion of <ConditionInfo/> entities @@ -365,28 +385,38 @@ namespace DD4hep { /// Specialized conversion of <param/> and <paramVector> entities template <> void DDDBConverter<ConditionParam>::convert(xml_h element) const { Condition::Params* c = _option<Condition::Params>(); - string name = element.attr<string>(_U(name)); + string n = element.attr<string>(_U(name)); ConditionParam* p = new ConditionParam(); p->type = element.hasAttr(_U(type)) ? element.attr<string>(_U(type)) : string("int"); p->data = element.text(); - c->insert(make_pair(name,p)); + c->insert(make_pair(n,p)); } /// Specialized conversion of <condition/> entities template <> void DDDBConverter<Condition>::convert(xml_h element) const { Context* context = _param<Context>(); + Catalog* catalog = _option<Catalog>(); string name = element.attr<string>(_U(name)); string id = object_href(element,name); string path = object_path(context,name); Condition* cond = new Condition(); static int num_param = 0, num_paramVector = 0; - + if ( name == "ScaleUp" ) + cond->id = object_href(element,name); cond->id = id; cond->name = name; cond->classID = element.attr<string>(_LBU(classID)); xml_coll_t(element,_U(param)).for_each(DDDBConverter<ConditionParam>(this->lcdd,context,&cond->params)); xml_coll_t(element,_LBU(paramVector)).for_each(DDDBConverter<ConditionParam>(this->lcdd,context,&cond->paramVectors)); - context->geo->conditions.insert(make_pair(path,cond)); + + context->collect(id, cond); + if ( catalog ) { + path = object_path(context,cond->name); + context->collectPath(path, cond); + } + if ( context->print_condition ) { + printout(INFO,"Condition","++ path:%s id:%s", path.c_str(), id.c_str()); + } num_param += int(cond->params.size()); num_paramVector += int(cond->paramVectors.size()); @@ -394,20 +424,29 @@ namespace DD4hep { printout(INFO,"Condition","++ Processed %d conditions....last:%s #Para: %d %d", int(context->geo->conditions.size()), path.c_str(), num_param, num_paramVector); - } - if ( context->print_condition ) { - printout(INFO,"Condition","++ path:%s id:%s", path.c_str(), id.c_str()); + DD4hep::dddb_print(cond); } } /// Specialized conversion of <conditionref/> entities template <> void DDDBConverter<ConditionRef>::convert(xml_h element) const { Context* context = _param<Context>(); - string href = element.attr<string>(_LBU(href)); + string href = element.attr<string>(_LBU(href)); + string refid = reference_href(element,href); + + load_dddb_entity(lcdd, context, element, href); + dddb::Conditions::const_iterator i=context->geo->conditions.find(refid); + if ( i == context->geo->conditions.end() ) { + string r = reference_href(element,href); + printout(ERROR,"ConditionRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); + load_dddb_entity(lcdd, context, element, href); + } + Condition* cond = (*i).second; + string path = object_path(context,cond->name); + context->collectPath(path, cond); if ( context->print_condition_ref ) { - printout(INFO,"ConditionRef", "href=%s", href.c_str()); + print_ref("ConditionRef", context, element, href, "Path:"+path); } - load_dddb_entity(lcdd, context, element, href); } /// Specialized conversion of <isotope/> entities @@ -438,7 +477,7 @@ namespace DD4hep { } Element* e = (*i).second; string path = object_path(context,e->name); - context->collectPath(path,e->addRef()); + context->collectPath(path, e); } /// Specialized conversion of <element/> entities @@ -489,6 +528,7 @@ namespace DD4hep { /// Specialized conversion of <materialref/> entities template <> void DDDBConverter<MaterialRef>::convert(xml_h element) const { Context* context = _param<Context>(); + Catalog* catalog = _option<Catalog>(); string href = element.attr<string>(_LBU(href)); string refid = reference_href(element,href); load_dddb_entity(lcdd, context, element, href); @@ -496,14 +536,17 @@ namespace DD4hep { if ( i == context->geo->materials.end() ) { printout(ERROR,"MaterialRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); } - Material* m = (*i).second; - string path = object_path(context,m->name); - context->collectPath(path,m->addRef()); + if ( catalog ) { + Material* m = (*i).second; + string path = object_path(context,m->name); + context->collectPath(path, m); + } } /// Specialized conversion of <material/> entities template <> void DDDBConverter<Material>::convert(xml_h element) const { Context* context = _param<Context>(); + Catalog* catalog = _option<Catalog>(); dddb_dim_t x_mat = element; string name = x_mat.nameStr(); string id = object_href(element, name); @@ -522,8 +565,8 @@ namespace DD4hep { xml_coll_t(element, _U(component)).for_each(DDDBConverter<MaterialComponent>(this->lcdd,context,m)); context->collect(m->id, m); // We collect materials by NAME!!! - context->collect(m->name, m->addRef()); - context->collectPath(m->path, m->addRef()); + context->collect(m->name, m); + if ( catalog ) context->collectPath(m->path, m); } } @@ -804,9 +847,6 @@ namespace DD4hep { Catalog* cat = _option<Catalog>(); string href = element.attr<string>(_LBU(href)); string refid = reference_href(element,href); - if ( context->print_logvol ) { - print_ref("LogVolRef", context, element, href); - } load_dddb_entity(lcdd, context, element, href); dddb::Volumes::const_iterator i=context->geo->volumes.find(refid); if ( i == context->geo->volumes.end() ) { @@ -814,11 +854,12 @@ namespace DD4hep { printout(ERROR,"LogVolRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); } LogVol* vol = (*i).second; - //vol->used = true; - string path = object_path(context,vol->name); cat->logvolrefs[vol->id] = vol; - context->collect(refid,vol->addRef()); - context->collectPath(path,vol->addRef()); + string path = object_path(context,vol->name); + context->collectPath(path, vol); + if ( context->print_logvol ) { + print_ref("LogVolRef", context, element, href, "Path:"+path); + } } /// Specialized conversion of <logvol/> entities @@ -827,10 +868,10 @@ namespace DD4hep { string name = element.attr<string>(_U(name)); string id = object_href(element, name); if ( !find(id, context->geo->volumes) ) { + Catalog* catalog = _option<Catalog>(); string material; LogVol* vol = new LogVol; xml_h elt; - //vol->used = false; vol->name = name; vol->path = object_path(context,name); if ( element.hasAttr(_U(material)) ) { @@ -878,7 +919,7 @@ namespace DD4hep { vol->shape = id; context->collect(id, s); context->collect(id, vol); - context->collectPath(vol->path,vol); + if ( catalog ) context->collectPath(vol->path, vol); { PreservedLocals locals(context); context->locals.obj_path = id; @@ -1013,13 +1054,12 @@ namespace DD4hep { name.c_str() ); } + det->typeID = 1; det->name = name; det->type = type; det->path = path; det->id = id; det->support = parent; - context->collect(id, det); - context->collectPath(det->path, det); // Now extract all availible information from the xml if ( (elt=x_det.child(_U(author),false)) ) @@ -1035,6 +1075,9 @@ namespace DD4hep { xml_coll_t(element, _LBU(geometryinfo)).for_each(DDDBConverter<GeometryInfo>(lcdd,context,det)); xml_coll_t(element, _LBU(detelemref)).for_each(DDDBConverter<DetElemRef>(lcdd,context,det)); } + det->path = det->support + "/" + name; + context->collect(id, det); + context->collectPath(det->path, det); dddb_print(context, det); } @@ -1088,9 +1131,10 @@ namespace DD4hep { xml_coll_t(e, _U(element)).for_each(DDDBConverter<Element>(lcdd,context,c)); xml_coll_t(e, _U(material)).for_each(DDDBConverter<Material>(lcdd,context,c)); xml_coll_t(e, _U(logvol)).for_each(DDDBConverter<LogVol>(lcdd,context,c)); + xml_coll_t(e, _LBU(condition)).for_each(DDDBConverter<Condition>(lcdd,context,c)); xml_coll_t(e, _LBU(detelem)).for_each(DDDBConverter<DetElem>(lcdd,context,c)); - xml_coll_t(e, _LBU(condition)).for_each(DDDBConverter<Condition>(lcdd,context,c)); + xml_coll_t(e, _LBU(catalog)).for_each(DDDBConverter<Catalog>(lcdd,context,c)); xml_coll_t(e, _LBU(elementref)).for_each(DDDBConverter<ElementRef>(lcdd,context,c)); xml_coll_t(e, _LBU(materialref)).for_each(DDDBConverter<MaterialRef>(lcdd,context,c)); @@ -1098,7 +1142,6 @@ namespace DD4hep { xml_coll_t(e, _LBU(detelemref)).for_each(DDDBConverter<DetElemRef>(lcdd,context,c)); xml_coll_t(e, _LBU(conditionref)).for_each(DDDBConverter<ConditionRef>(lcdd,context,c)); xml_coll_t(e, _LBU(catalogref)).for_each(DDDBConverter<CatalogRef>(lcdd,context,c)); - xml_coll_t(e, _LBU(catalog)).for_each(DDDBConverter<Catalog>(lcdd,context,c)); } } @@ -1111,6 +1154,8 @@ namespace DD4hep { xml_coll_t(element, _U(element)).for_each(DDDBConverter<Element>(lcdd,context)); xml_coll_t(element, _U(material)).for_each(DDDBConverter<Material>(lcdd,context)); xml_coll_t(element, _U(logvol)).for_each(DDDBConverter<LogVol>(lcdd,context)); + xml_coll_t(element, _LBU(condition)).for_each(DDDBConverter<Condition>(lcdd,context)); + xml_coll_t(element, _LBU(detelem)).for_each(DDDBConverter<DetElem>(lcdd,context)); xml_coll_t(element, _LBU(catalog)).for_each(DDDBConverter<Catalog>(lcdd,context)); @@ -1118,11 +1163,9 @@ namespace DD4hep { xml_coll_t(element, _LBU(elementref)).for_each(DDDBConverter<ElementRef>(lcdd,context)); xml_coll_t(element, _LBU(materialref)).for_each(DDDBConverter<MaterialRef>(lcdd,context)); xml_coll_t(element, _LBU(logvolref)).for_each(DDDBConverter<LogVolRef>(lcdd,context)); - xml_coll_t(element, _LBU(catalogref)).for_each(DDDBConverter<CatalogRef>(lcdd,context)); - - //xml_coll_t(element, _LBU(detelemref)).for_each(DDDBConverter<DetElemRef>(lcdd,context)); - xml_coll_t(element, _LBU(condition)).for_each(DDDBConverter<Condition>(lcdd,context)); xml_coll_t(element, _LBU(conditionref)).for_each(DDDBConverter<ConditionRef>(lcdd,context)); + xml_coll_t(element, _LBU(catalogref)).for_each(DDDBConverter<CatalogRef>(lcdd,context)); + xml_coll_t(element, _LBU(detelemref)).for_each(DDDBConverter<DetElemRef>(lcdd,context)); } void apply_trafo(int apply, Position& pos, RotationZYX& rot, Transform3D& trafo, Transform3D& tr) { diff --git a/DDDB/src/DDDB2Objects.cpp b/DDDB/src/DDDB2Objects.cpp index e5565b8287e88b230388ca17315aafccd14839e0..b8bf7794219102a0cb7f21c8729ebd077db412e0 100644 --- a/DDDB/src/DDDB2Objects.cpp +++ b/DDDB/src/DDDB2Objects.cpp @@ -91,7 +91,8 @@ namespace DD4hep { print_physvol(false), print_params(false), print_detelem(false), - print_conditions(false) + print_conditions(false), + print_vis(false) { } ~Context() { @@ -139,7 +140,7 @@ namespace DD4hep { bool print_params; bool print_detelem; bool print_conditions; - + bool print_vis; static GeoPlacement placement(DetElement de) { if ( de.isValid() ) { GeoPlacement p = de.placement(); @@ -243,7 +244,10 @@ namespace DD4hep { Context* context = _param<Context>(); GeoCondition* cond = Context::find(context->conditions, object); if ( !cond ) { - + cond = new GeoCondition(); + cond->value = "";//object->data; + cond->address = object->id; + context->conditions.insert(make_pair(object, cond)); } return cond; } @@ -593,7 +597,9 @@ namespace DD4hep { mother->SetTitle(object->path.c_str()); VisAttr vis = context->helper->visAttr(object->path); if ( vis.isValid() ) { - printout(INFO,"Cnv<LogVol>","++ Vol:%s Vis:%s",mother->GetTitle(), vis.name()); + if ( context->print_vis ) { + printout(INFO,"Cnv<LogVol>","++ Vol:%s Vis:%s",mother->GetTitle(), vis.name()); + } mother.setVisAttributes(vis); } else { @@ -973,8 +979,8 @@ namespace DD4hep { printout(INFO,"DDDB2Object","++ Converted %d isotopes.",int(obj->isotopes.size())); for_each(obj->elements.begin(), obj->elements.end(), cnv<Element>()); printout(INFO,"DDDB2Object","++ Converted %d elements.",int(obj->elements.size())); - for_each(obj->materials.begin(), obj->materials.end(), cnv<Material>()); - printout(INFO,"DDDB2Object","++ Converted %d materials.",int(obj->materials.size())); + //for_each(obj->materials.begin(), obj->materials.end(), cnv<Material>()); + //printout(INFO,"DDDB2Object","++ Converted %d materials.",int(obj->materials.size())); if ( !context->lvDummy.isValid() ) { lcdd.manager().SetVisLevel(context->max_volume_depth); context->lvDummy = GeoVolume("Dummy",Geometry::Box(0.0001,0.0001, 0.0001),lcdd.vacuum()); @@ -1015,7 +1021,8 @@ static long dddb_2_dd4hep(LCDD& lcdd, int , char** ) { context.print_params = false; context.print_detelem = false; context.print_conditions = false; - context.max_volume_depth = 15; + context.print_vis = false; + context.max_volume_depth = 9; CNV<dddb> cnv(lcdd,&context); string top = "/dd/Geometry/LHCb/lvLHCb"; @@ -1029,6 +1036,14 @@ static long dddb_2_dd4hep(LCDD& lcdd, int , char** ) { } context.geo->world = s->s.box; cnv(make_pair(string("World"),context.geo)); + printout(INFO,"DDDB2DD4hep","++ Converted %8d isotopes.", int(context.isotopes.size())); + printout(INFO,"DDDB2DD4hep","++ Converted %8d elements.", int(context.elements.size())); + printout(INFO,"DDDB2DD4hep","++ Converted %8d materials.", int(context.materials.size())); + printout(INFO,"DDDB2DD4hep","++ Converted %8d shapes.", int(context.shapes.size())); + printout(INFO,"DDDB2DD4hep","++ Converted %8d logical volumes.", int(context.volumes.size())); + printout(INFO,"DDDB2DD4hep","++ Converted %8d placements.", int(context.placements.size())); + printout(INFO,"DDDB2DD4hep","++ Converted %8d detector elements.",int(context.detelements.size())); + printout(INFO,"DDDB2DD4hep","++ Converted %8d conditions.", int(context.conditions.size())); helper->setGeometry(0); return 1; } diff --git a/DDDB/src/DDDBConversion.cpp b/DDDB/src/DDDBConversion.cpp index 8aaa6f26b2e7eb1405ae357c27d5196606790bbb..3ee91cc30ca5f6c71775e45acc56e9f6a83d6c80 100644 --- a/DDDB/src/DDDBConversion.cpp +++ b/DDDB/src/DDDBConversion.cpp @@ -20,6 +20,7 @@ // Framework includes #include "DDDB/DDDBConversion.h" +#include "DD4hep/InstanceCount.h" #include "DD4hep/Primitives.h" #include "DD4hep/Printout.h" #include "DD4hep/LCDD.h" @@ -42,35 +43,113 @@ namespace DD4hep { /// Default constructor DDDB::dddb::dddb() : top(0), structure(0), geometry(0) { + InstanceCount::increment(this); } /// Default destructor DDDB::dddb::~dddb() { // need to release heare all allocated resources. - destroyObjects(isotopes)(); - destroyObjects(elements)(); - elementPaths.clear(); + releaseObjects(isotopes)(); + releaseObjects(elements)(); + releaseObjects(elementPaths)(); - destroyObjects(materials)(); - materialPaths.clear(); + releaseObjects(materials)(); + releaseObjects(materialPaths)(); - destroyObjects(shapes)(); + releaseObjects(shapes)(); - destroyObjects(volumes)(); - volumePaths.clear(); + releaseObjects(volumes)(); + releaseObjects(volumePaths)(); - destroyObjects(placements)(); - placementPaths.clear(); + releaseObjects(placements)(); + releaseObjects(placementPaths)(); - destroyObjects(conditions)(); - destroyObjects(catalogs)(); - catalogPaths.clear(); + releaseObjects(conditions)(); + releaseObjects(catalogs)(); + releaseObjects(catalogPaths)(); printout(INFO,"dddb","++ All intermediate objects deleted!"); + InstanceCount::decrement(this); + } + + /// Default constructor + DDDB::Isotope::Isotope() : Named() { + InstanceCount::increment(this); + } + + /// Default destructor + DDDB::Isotope::~Isotope() { + InstanceCount::decrement(this); + } + + /// Default constructor + DDDB::Element::Element() : Named(), density(0), ionization(0), state(UNKNOWN) { + InstanceCount::increment(this); + } + + /// Copy constructor + DDDB::Element::Element(const Element& e) + : Named(e), isotopes(e.isotopes), path(e.path), symbol(e.symbol), + atom(e.atom), density(e.density), + ionization(e.ionization), state(e.state) + { + InstanceCount::increment(this); + } + + /// Default destructor + DDDB::Element::~Element() { + InstanceCount::decrement(this); + } + + /// Default constructor + DDDB::Material::Material() : density(0), pressure(-1), temperature(-1), radlen(0), lambda(0) { + InstanceCount::increment(this); + } + + /// Default destructor + DDDB::Material::~Material() { + InstanceCount::decrement(this); + } + + /// Default constructor + DDDB::LogVol::LogVol() : Named(), material(), shape(), physvols() { + InstanceCount::increment(this); + } + + /// Default destructor + DDDB::LogVol::~LogVol() { + InstanceCount::decrement(this); + } + + /// Default constructor + DDDB::PhysVol::PhysVol() : type(PHYSVOL_REGULAR), logvol(), path(), trafo() { + InstanceCount::increment(this); + } + + /// Copy constructor + DDDB::PhysVol::PhysVol(const PhysVol& c) + : Named(c), type(c.type), logvol(c.logvol), path(c.path), trafo(c.trafo) { + InstanceCount::increment(this); + } + + /// Default destructor + DDDB::PhysVol::~PhysVol() { + InstanceCount::decrement(this); + } + + /// Default constructor + DDDB::Condition::Condition() : Named() { + InstanceCount::increment(this); + } + + /// Default destructor + DDDB::Condition::~Condition() { + InstanceCount::decrement(this); } /// Default constructor DDDB::Shape::Shape() : type(0), zplanes(), boolean_ops() { ::memset(&s.box,0,sizeof(s)); + InstanceCount::increment(this); } /// Default destructor @@ -84,6 +163,17 @@ namespace DD4hep { delete (*i).shape; boolean_ops.clear(); } + InstanceCount::decrement(this); + } + + /// Default constructor + DDDB::Catalog::Catalog() : Named(), level(0), typeID(0) { + InstanceCount::increment(this); + } + + /// Default destructor + DDDB::Catalog::~Catalog() { + InstanceCount::decrement(this); } pair<const DDDB::Catalog*,string> DDDB::Catalog::parent(const string& nam) const { @@ -153,7 +243,7 @@ namespace DD4hep { template <> void dddb_print(const DDDB::Material* m) { CHECK_OBJECT(m); printout(INFO,"Material","++ %-20s Density=%8g P=%f T=%f %d components id:%s", - ("'"+m->name+"'").c_str(), m->density, m->pressure, m->temperature, + ("'"+m->path+"'").c_str(), m->density, m->pressure, m->temperature, int(m->components.size()),m->c_id()); } @@ -203,7 +293,7 @@ namespace DD4hep { s->type,s->path.c_str(),int(s->boolean_ops.size())); } printout(INFO,"Shape","++ %-15s name:%s id:%s", - "",s->c_name(),s->c_id()); + "", s->path.c_str(), s->c_id()); } template <> void dddb_print(const DDDB::PhysVol* obj) { @@ -231,4 +321,17 @@ namespace DD4hep { printout(INFO,"Detector", "++ %-12s name:%s id:%s", "",obj->c_name(),obj->c_id()); } + template <> void dddb_print(const DDDB::Condition* obj) { + stringstream p; + p << "Par [" << obj->params.size() << "]: "; + for(auto i=obj->params.begin(); i != obj->params.end(); ++i) + p << (*i).first << "[" << (*i).second->type << "] "; + p << "Vec [" << obj->paramVectors.size() << "]: "; + for(auto i=obj->paramVectors.begin(); i != obj->paramVectors.end(); ++i) + p << (*i).first << "[" << (*i).second->type << "] "; + + CHECK_OBJECT(obj); + printout(INFO,"Condition", "++ %-12s: [%s] id:%s %s", + obj->name.c_str(), obj->classID.c_str(), obj->c_id(), p.str().c_str()); + } } diff --git a/cmake/thisdd4hep.sh b/cmake/thisdd4hep.sh index 569689f6436c4920c04f60d659ff0760044bd7f0..74344f14bc345786def4a81a42fe9c36063c4111 100644 --- a/cmake/thisdd4hep.sh +++ b/cmake/thisdd4hep.sh @@ -8,6 +8,7 @@ # #echo " ### thisdd4hep.sh: initialize the environment for DD4hep ! " # +#----------------------------------------------------------------------------- dd4hep_parse_this() { package=${2}; if [ "x${1}" = "x" ]; then @@ -25,7 +26,7 @@ dd4hep_parse_this() { fi; THIS=$(cd ${THIS} > /dev/null; pwd); } - +#----------------------------------------------------------------------------- dd4hep_add_path() { path_name=${1}; path_prefix=${2}; @@ -38,7 +39,7 @@ dd4hep_add_path() { eval export ${path_name}=${path_value}; ## echo "dd4hep_add_path: ${path_name}=${path_value}"; } - +#----------------------------------------------------------------------------- dd4hep_add_library_path() { path_prefix=${1}; if [ @USE_DYLD@ ]; @@ -56,6 +57,7 @@ dd4hep_add_library_path() { fi; fi; } +#----------------------------------------------------------------------------- # dd4hep_parse_this ${BASH_ARGV[0]} DD4hep; # @@ -103,6 +105,9 @@ dd4hep_add_path PATH ${THIS}/bin; dd4hep_add_library_path ${THIS}/lib; #----PYTHONPATH--------------------------------------------------------------- dd4hep_add_path PYTHONPATH ${THIS}/python; +#----ROOT_INCLUDE_PATH-------------------------------------------------------- +dd4hep_add_path ROOT_INCLUDE_PATH ${THIS}/include; +#----------------------------------------------------------------------------- # unset ROOTENV_INIT; unset THIS; diff --git a/cmake/thisdd4hep_package.sh.in b/cmake/thisdd4hep_package.sh.in index 6833ca902054675fe799fa3c661b47607d690904..5739b045db938533af8e3ce3c82ebc4013fdeac2 100644 --- a/cmake/thisdd4hep_package.sh.in +++ b/cmake/thisdd4hep_package.sh.in @@ -19,8 +19,13 @@ source ${DD4hep_DIR}/bin/thisdd4hep.sh; # dd4hep_parse_this ${BASH_ARGV[0]} @PackageName@; # +#----PATH--------------------------------------------------------------------- dd4hep_add_path PATH ${THIS}/bin; -dd4hep_add_path PYTHONPATH ${THIS}/lib/python +#----PYTHONPATH--------------------------------------------------------------- +dd4hep_add_path PYTHONPATH ${THIS}/lib/python; +#----ROOT_INCLUDE_PATH-------------------------------------------------------- +dd4hep_add_path ROOT_INCLUDE_PATH ${THIS}/include; +#----LIBRARY_PATH------------------------------------------------------------- dd4hep_add_library_path ${THIS}/lib; # -- need to extend dynamic search path for all external libraries: if [ @External_LIBRARY_DIRS@ ]; then