diff --git a/DDCond/src/ConditionsTest.cpp b/DDCond/src/ConditionsTest.cpp index 6e1f12716260bc9db74e064fa3a686cb4c8df078..9e407f8cdd35f0964cc63e63149a79335212a2d7 100644 --- a/DDCond/src/ConditionsTest.cpp +++ b/DDCond/src/ConditionsTest.cpp @@ -117,18 +117,20 @@ namespace DD4hep { print_bound_value<double>(c,"1.0/hPa"); else if ( type == "whatever" ) print_bound_value<vector<double> >(c); - else if ( type == "short" ) - print_bound_value<short>(c); else if ( type == "integer" ) print_bound_value<int>(c); else if ( type == "long" ) print_bound_value<long>(c); +#if defined(DD4HEP_HAVE_ALL_PARSERS) + else if ( type == "short" ) + print_bound_value<short>(c); else if ( type == "unsigned short" ) print_bound_value<unsigned short>(c); else if ( type == "unsigned integer" ) print_bound_value<unsigned int>(c); else if ( type == "unsigned long" ) print_bound_value<unsigned long>(c); +#endif else if ( type == "float" ) print_bound_value<float>(c); else if ( type == "double" ) diff --git a/DDCore/src/Detector.cpp b/DDCore/src/Detector.cpp index 99559930ad792e3460ee98902d77163b6a4e6fcc..4cd13cfa26f5f5e721a487b2433d562653bc9452 100644 --- a/DDCore/src/Detector.cpp +++ b/DDCore/src/Detector.cpp @@ -199,7 +199,8 @@ DetElement& DetElement::add(DetElement sdet) { sdet.access()->parent = *this; return *this; } - throw runtime_error("DD4hep: DetElement::add: Element " + string(sdet.name()) + " is already present [Double-Insert]"); + throw runtime_error("DD4hep: DetElement::add: Element " + string(sdet.name()) + + " is already present in path " + path() + " [Double-Insert]"); } throw runtime_error("DD4hep: DetElement::add: Self is not defined [Invalid Handle]"); } diff --git a/DDDB/include/DDDB/DDDBConversion.h b/DDDB/include/DDDB/DDDBConversion.h index 22674dddb1a9b229aece8e61cb3f62e4784bde56..f4b37f479f674954fef3e517d0670ad02b8f3a7c 100644 --- a/DDDB/include/DDDB/DDDBConversion.h +++ b/DDDB/include/DDDB/DDDBConversion.h @@ -43,12 +43,11 @@ namespace DD4hep { struct ElementRef {}; struct MaterialRef {}; struct CatalogRef {}; - struct Condition {}; struct ConditionRef {}; struct ConditionInfo {}; struct DetElem {}; struct DetElemRef {}; - struct Param {}; + struct Param {}; struct Parameter {}; struct ParamVector {}; struct GeometryInfo {}; @@ -80,6 +79,26 @@ namespace DD4hep { const char* c_id() const { return id.c_str(); } }; + struct ConditionParam { + std::string type, data; + ConditionParam() : type(), data() {} + ConditionParam(const ConditionParam& c) : type(c.type), data(c.data) {} + ConditionParam& operator=(const ConditionParam& c) { + if ( &c != this ) { + type = c.type; + data = c.data; + } + return *this; + } + }; + struct Condition : public Named { + typedef std::map<std::string, ConditionParam*> Params; + std::string classID; + Params params; + Params paramVectors; + Condition() : Named() {} + }; + /// Intermediate structure representing author's data /** \ingroup DD4HEP_DDDB */ @@ -407,11 +426,11 @@ 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; + 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) { } @@ -454,6 +473,8 @@ namespace DD4hep { std::string path; /// Default constructor Shape(); + /// Default destructor + ~Shape(); }; /// LHCb geometry description interface to the conditions database @@ -472,6 +493,8 @@ namespace DD4hep { typedef std::map<std::string,Element*> Elements; typedef std::map<std::string,Material*> Materials; typedef std::map<std::string,Shape*> Shapes; + typedef std::map<std::string,Condition*> Conditions; + /// Default constructor dddb(); /// Default destructor @@ -479,8 +502,6 @@ namespace DD4hep { /// World dimensions Box world; - /// Inventory of catalogs - Catalogs catalogs, catalogPaths; /// Inventory of isotopes Isotopes isotopes; /// Inventory of elements @@ -493,6 +514,11 @@ namespace DD4hep { Volumes volumes, volumePaths; /// Inventory of volume placements Placements placements, placementPaths; + /// Inventory of conditions + Conditions conditions; + /// Inventory of catalogs + Catalogs catalogs, catalogPaths; + /// Detector element hierarchy Catalog *top, *structure, *geometry; }; diff --git a/DDDB/include/DDDB/DDDBTags.h b/DDDB/include/DDDB/DDDBTags.h index 9b140ee969ef5ebb9128bf092886d360379f112c..39630da831babcc1ece62948dd4f9c1b5ff466b6 100644 --- a/DDDB/include/DDDB/DDDBTags.h +++ b/DDDB/include/DDDB/DDDBTags.h @@ -107,7 +107,7 @@ namespace DD4hep { UNICODE(thetaAngle); UNICODE(startThetaAngle); UNICODE(deltaThetaAngle); - //UNICODE(); + UNICODE(classID); //UNICODE(); } /* End namespace DDDB */ diff --git a/DDDB/src/CondDB2DDDB.cpp b/DDDB/src/CondDB2DDDB.cpp index 887de4cded5d47e904efbfe9f0a26373e23c1478..9cc9d1ec33607f45fde3b78c74a16caf891afa54 100644 --- a/DDDB/src/CondDB2DDDB.cpp +++ b/DDDB/src/CondDB2DDDB.cpp @@ -70,9 +70,10 @@ namespace DD4hep { print_detelem(false), print_detelem_ref(false), print_detelem_xml(false), - print_conditions(false), + print_condition(false), + print_condition_ref(false), print_catalog(false), - print_catalog_ref(false) { + print_catalog_ref(false) { gram_per_cm3 = 1.0;//XML::_toDouble(_Unicode(gram/cm3)); gram_per_mole = 1.0;//XML::_toDouble(_Unicode(gram/mole)); } @@ -87,22 +88,20 @@ namespace DD4hep { 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 _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); } StringSet files; Locals locals; @@ -117,7 +116,8 @@ namespace DD4hep { bool print_detelem; bool print_detelem_ref; bool print_detelem_xml; - bool print_conditions; + bool print_condition; + bool print_condition_ref; bool print_catalog; bool print_catalog_ref; double gram_per_mole, gram_per_cm3; @@ -212,6 +212,7 @@ namespace DD4hep { template <> void DDDBConverter<ParamPhysVol>::convert(xml_h element) const; template <> void DDDBConverter<ParamPhysVol2D>::convert(xml_h element) const; template <> void DDDBConverter<ParamPhysVol3D>::convert(xml_h element) const; + template <> void DDDBConverter<ConditionParam>::convert(xml_h element) const; void build_transformation(LCDD& lcdd, void* context, xml_h element, Transform3D& tr, int which=-1); void extract_transformation(LCDD& lcdd, void* context, xml_coll_t& collection, Transform3D& tr, int which=-1); @@ -345,31 +346,65 @@ namespace DD4hep { if ( element.hasAttr(_U(version)) ) *context = element.attr<string>(_U(version)); } - /// Specialized conversion of <condition/> entities + /// Specialized conversion of <param/> entities template <> void DDDBConverter<Param>::convert(xml_h element) const { - Catalog* det = _option<Catalog>(); - string nam = element.attr<string>(_U(name)); - string typ = element.hasAttr(_U(type)) ? element.attr<string>(_U(type)) : string("int"); - det->params[nam] = typ; + 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; } /// Specialized conversion of <ConditionInfo/> entities template <> void DDDBConverter<ConditionInfo>::convert(xml_h element) const { Catalog* det = _option<Catalog>(); - string nam = element.attr<string>(_U(name)); + string name = element.attr<string>(_U(name)); string cond = element.attr<string>(_LBU(condition)); - det->conditioninfo[nam] = cond; + det->conditioninfo[name] = cond; + } + + /// 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)); + 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)); } /// Specialized conversion of <condition/> entities - template <> void DDDBConverter<Condition>::convert(xml_h ) const { + template <> void DDDBConverter<Condition>::convert(xml_h element) const { + Context* context = _param<Context>(); + 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; + + 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)); + + num_param += int(cond->params.size()); + num_paramVector += int(cond->paramVectors.size()); + if ( (context->geo->conditions.size()%500) == 0 ) { + 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()); + } } /// 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)); - if ( context->print_conditions ) { + if ( context->print_condition_ref ) { printout(INFO,"ConditionRef", "href=%s", href.c_str()); } load_dddb_entity(lcdd, context, element, href); @@ -405,6 +440,7 @@ namespace DD4hep { string path = object_path(context,e->name); context->collectPath(path,e->addRef()); } + /// Specialized conversion of <element/> entities template <> void DDDBConverter<Element>::convert(xml_h element) const { Context* context = _param<Context>(); @@ -449,6 +485,7 @@ namespace DD4hep { c.natoms = x_mat.natoms(1); c.fractionmass = x_mat.fractionmass(1.0); } + /// Specialized conversion of <materialref/> entities template <> void DDDBConverter<MaterialRef>::convert(xml_h element) const { Context* context = _param<Context>(); @@ -463,6 +500,7 @@ namespace DD4hep { string path = object_path(context,m->name); context->collectPath(path,m->addRef()); } + /// Specialized conversion of <material/> entities template <> void DDDBConverter<Material>::convert(xml_h element) const { Context* context = _param<Context>(); @@ -495,6 +533,7 @@ namespace DD4hep { context->logvol = element.attr<string>(_LBU(lvname)); if ( element.hasAttr(_LBU(npath)) ) context->npath = element.attr<string>(_LBU(npath)); if ( element.hasAttr(_LBU(support)) ) context->support = element.attr<string>(_LBU(support)); + if ( element.hasAttr(_LBU(condition)) ) context->condition = element.attr<string>(_LBU(condition)); } /// Specialized conversion of <posXYZ/> entities @@ -552,9 +591,9 @@ namespace DD4hep { ShapeConverter<Shape>(lcdd,param)(element,s); dddb_dim_t dim = element; s->type = to_type::type(); - s->s.box.x = dim.sizeX(0.0); - s->s.box.y = dim.sizeY(0.0); - s->s.box.z = dim.sizeZ(0.0); + s->s.box.x = dim.sizeX(0.0)/2e0; + s->s.box.y = dim.sizeY(0.0)/2e0; + s->s.box.z = dim.sizeZ(0.0)/2e0; } /// Specialized conversion of Cons shapes @@ -566,7 +605,7 @@ namespace DD4hep { s->s.cons.innerRadiusPZ = dim.innerRadiusPZ(0.0); s->s.cons.outerRadiusMZ = dim.outerRadiusMZ(0.0); s->s.cons.outerRadiusPZ = dim.outerRadiusPZ(0.0); - s->s.cons.sizeZ = dim.sizeZ(0.0); + s->s.cons.sizeZ = dim.sizeZ(0.0)/2e0; } /// Specialized conversion of ConeSegment shapes @@ -580,7 +619,7 @@ namespace DD4hep { s->s.coneSegment.innerRadiusPZ = dim.innerRadiusPZ(0.0); s->s.coneSegment.outerRadiusMZ = dim.outerRadiusMZ(0.0); s->s.coneSegment.outerRadiusPZ = dim.outerRadiusPZ(0.0); - s->s.coneSegment.sizeZ = dim.sizeZ(0.0); + s->s.coneSegment.sizeZ = dim.sizeZ(0.0)/2e0; } /// Specialized conversion of Tubs shapes @@ -592,25 +631,28 @@ namespace DD4hep { s->s.tubs.delta = dim.deltaPhiAngle(2.0*M_PI); s->s.tubs.innerRadius = dim.innerRadius(0.0); s->s.tubs.outerRadius = dim.outerRadius(0.0); - s->s.tubs.sizeZ = dim.sizeZ(0.0); + s->s.tubs.sizeZ = dim.sizeZ(0.0)/2e0; } /// Specialized conversion of Trap shapes template <> void ShapeConverter<Trap>::convert(xml_h element, Shape*& s) const { dddb_dim_t dim = element; ShapeConverter<Shape>(lcdd,param)(element,s); + if ( s->name == "Cut_out_right" ) { + s->type = to_type::type(); + } s->type = to_type::type(); - s->s.trap.h1 = dim.sizeY1(0); - s->s.trap.bl1 = dim.sizeX1(0); - s->s.trap.bl2 = dim.sizeX2(0); - s->s.trap.alpha1 = dim.alp1(0); - s->s.trap.h2 = dim.sizeY2(0); - s->s.trap.tl1 = dim.sizeX3(0); - s->s.trap.tl2 = dim.sizeX4(0); - s->s.trap.alpha2 = dim.alp2(0); - s->s.trap.dz = dim.sizeZ(); + s->s.trap.dz = dim.sizeZ()/2e0; s->s.trap.phi = dim.phiAngle(0); s->s.trap.theta = dim.thetaAngle(0); + s->s.trap.h1 = dim.sizeY1(0)/2e0; + s->s.trap.bl1 = dim.sizeX1(0)/2e0; + s->s.trap.tl1 = dim.sizeX2(0)/2e0; + s->s.trap.alpha1 = dim.alp1(0); + s->s.trap.h2 = dim.sizeY2(0)/2e0; + s->s.trap.bl2 = dim.sizeX3(0)/2e0; + s->s.trap.tl2 = dim.sizeX4(0)/2e0; + s->s.trap.alpha2 = dim.alp2(0); } /// Specialized conversion of Polycone shapes @@ -651,11 +693,11 @@ namespace DD4hep { dddb_dim_t dim = element; ShapeConverter<Shape>(lcdd,param)(element,s); s->type = to_type::type(); - s->s.trd.x1 = dim.sizeX1(); - s->s.trd.x2 = dim.sizeX2(); - s->s.trd.y1 = dim.sizeY1(); - s->s.trd.y2 = dim.sizeY2(); - s->s.trd.z = dim.sizeZ(); + s->s.trd.x1 = dim.sizeX1()/2e0; + s->s.trd.x2 = dim.sizeX2()/2e0; + s->s.trd.y1 = dim.sizeY1()/2e0; + s->s.trd.y2 = dim.sizeY2()/2e0; + s->s.trd.z = dim.sizeZ()/2e0; } /// Specialized conversion of EllipticalTube shapes @@ -679,9 +721,6 @@ namespace DD4hep { PreservedLocals locals(context); context->locals.obj_path = id; s->s.boolean.first = 0; - if ( s->name == "VMACAUpStrRfContSingleUnion" || s->name=="VMABKUpStrPipeSub" ) { - s->s.boolean.first = 0; - } for(xml_coll_t p(element,_U(star)); p; ++p) { if ( p.parent() == element ) { // Only next level is processed here if ( 0 == s->s.boolean.first ) { @@ -858,9 +897,6 @@ namespace DD4hep { Context* context = _param<Context>(); pv->name = name; - if ( pv->name == "pvTTaULayerR1Module1T" || pv->name == "pvTTaULayerR2Module1T") { - pv->name = name; - } pv->logvol = x_vol.logvol(); pv->path = object_path(context,name); build_transformation(lcdd, param, element, pv->trafo, -1); @@ -945,6 +981,7 @@ namespace DD4hep { load_dddb_entity(lcdd, context, element, href); cat->catalogrefs[refid] = 0; } + /// Specialized conversion of <detelem/> entities template <> void DDDBConverter<DetElem>::convert(xml_h element) const { Context* context = _param<Context>(); @@ -1053,13 +1090,13 @@ namespace DD4hep { xml_coll_t(e, _U(logvol)).for_each(DDDBConverter<LogVol>(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(condition)).for_each(DDDBConverter<Condition>(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)); xml_coll_t(e, _LBU(logvolref)).for_each(DDDBConverter<LogVolRef>(lcdd,context,c)); 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(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)); } @@ -1084,33 +1121,37 @@ namespace DD4hep { 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)); - //fixDets(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)); } void apply_trafo(int apply, Position& pos, RotationZYX& rot, Transform3D& trafo, Transform3D& tr) { switch(apply) { - case 99: + case 99: { tr *= trafo; trafo = Transform3D(); pos = Position(); rot = RotationZYX(); break; - case 2: - trafo = Transform3D(rot,pos); - tr *= trafo; + } + case 2: { + Transform3D r(rot); + trafo = Transform3D(pos); + trafo = trafo * r; + tr = trafo * tr; trafo = Transform3D(); pos = Position(); rot = RotationZYX(); break; - case 1: + } + case 1: { trafo = Transform3D(pos); tr *= trafo; trafo = Transform3D(); pos = Position(); rot = RotationZYX(); break; + } case 0: default: break; @@ -1125,19 +1166,21 @@ namespace DD4hep { Transform3D trafo; for(xml_h element = p.parent(); p; ++p ) { if ( p.parent() == element ) { // Only next level is processed here + dddb_dim_t dim = p; string tag = p.tag(); if ( tag == "transformation" && (which<0 || count == which) ) { + apply_trafo(apply, pos, rot, trafo, tr); DDDBConverter<Transform3D>(lcdd,context,&trafo)(p); apply = 99; } else if ( tag == "posXYZ" && (which<0 || count == which) ) { apply_trafo(apply, pos, rot, trafo, tr); - DDDBConverter<Position>(lcdd,context,&pos)(p); + pos.SetXYZ(dim.x(0.0), dim.y(0.0), dim.z(0.0)); apply = 1; ++count; } else if ( tag == "rotXYZ" && (which<0 || count == (which+1)) ) { - DDDBConverter<RotationZYX>(lcdd,context,&rot)(p); + rot.SetComponents(dim.rotZ(0.0), dim.rotY(0.0), dim.rotX(0.0)); apply = 2; } else { @@ -1217,11 +1260,11 @@ namespace DD4hep { string doc_path = reference_href(element,ref); hash = doc_path.find('#'); if ( hash != string::npos ) doc_path = doc_path.substr(0,hash); +#if 0 if ( doc_path.find("/Conditions/") != string::npos ) { printout(INFO, "load_dddb", "SKIPPING DOC %s", doc_path.c_str()); return; } -#if 0 if ( doc_path.find("conddb:/TrackfitGeometry") != string::npos ) { printout(INFO, "load_dddb", "SKIPPING DOC %s", doc_path.c_str()); return; @@ -1291,7 +1334,8 @@ namespace DD4hep { context.print_detelem = false; context.print_detelem_ref = false; context.print_detelem_xml = false; - context.print_conditions = false; + context.print_condition = false; + context.print_condition_ref = false; context.print_catalog = false; context.print_catalog_ref = false; } diff --git a/DDDB/src/DDDB2Objects.cpp b/DDDB/src/DDDB2Objects.cpp index a02e630fb5e517621a50cf0541a603ca1b0cd209..e5565b8287e88b230388ca17315aafccd14839e0 100644 --- a/DDDB/src/DDDB2Objects.cpp +++ b/DDDB/src/DDDB2Objects.cpp @@ -25,6 +25,7 @@ #include "DDDB/DDDBConversion.h" #include "DD4hep/DetectorTools.h" #include "DD4hep/objects/DetectorInterna.h" +#include "DD4hep/objects/ConditionsInterna.h" // ROOT include files #include "TROOT.h" @@ -67,12 +68,14 @@ namespace DD4hep { namespace { + typedef Conditions::Interna::ConditionObject GeoCondition; typedef Geometry::PlacedVolume GeoPlacement; typedef Geometry::Volume GeoVolume; typedef Geometry::Material GeoMaterial; typedef Geometry::Solid GeoSolid; typedef Geometry::DetElement DetElement; + const double SMALL = 1e-10; /// Helper class to facilitate conversion. Purely local. @@ -104,35 +107,38 @@ namespace DD4hep { LCDD& lcdd; DDDB::dddb* geo; DDDB::DDDBHelper* helper; - typedef std::map<Isotope*, TGeoIsotope*> Isotopes; - typedef std::map<Element*, TGeoElement*> Elements; - typedef std::map<Material*, TGeoMedium*> Materials; - typedef std::map<Shape*, TGeoShape*> Shapes; - typedef std::map<LogVol*, TGeoVolume*> Volumes; - typedef std::map<PhysVol*, TGeoNode*> Placements; - typedef std::map<std::string, DetElement> DetectorMap; - typedef std::map<std::string, TGeoVolume*> VolumeMap; - typedef std::map<DetElement, Catalog*> DetectorElements; - Isotopes isotopes; - Elements elements; - Materials materials; - Shapes shapes; - Volumes volumes; - VolumeMap volumePaths; - Placements placements; - DetElement detectors; - DetectorMap catalogPaths; + typedef std::map<Isotope*, TGeoIsotope*> Isotopes; + typedef std::map<Element*, TGeoElement*> Elements; + typedef std::map<Material*, TGeoMedium*> Materials; + typedef std::map<Shape*, TGeoShape*> Shapes; + typedef std::map<LogVol*, TGeoVolume*> Volumes; + typedef std::map<PhysVol*, TGeoNode*> Placements; + typedef std::map<std::string, DetElement> DetectorMap; + typedef std::map<std::string, TGeoVolume*> VolumeMap; + typedef std::map<DetElement, Catalog*> DetectorElements; + typedef std::map<Condition*, GeoCondition*> Conditions; + + Isotopes isotopes; + Elements elements; + Materials materials; + Shapes shapes; + Volumes volumes; + VolumeMap volumePaths; + Placements placements; + DetElement detectors; + DetectorMap catalogPaths; DetectorElements detelements; - GeoVolume lvDummy; - int max_volume_depth; - bool print_materials; - bool print_volumes; - bool print_logvol; - bool print_shapes; - bool print_physvol; - bool print_params; - bool print_detelem; - bool print_conditions; + Conditions conditions; + GeoVolume lvDummy; + int max_volume_depth; + bool print_materials; + bool print_volumes; + bool print_logvol; + bool print_shapes; + bool print_physvol; + bool print_params; + bool print_detelem; + bool print_conditions; static GeoPlacement placement(DetElement de) { if ( de.isValid() ) { @@ -213,6 +219,8 @@ namespace DD4hep { } }; + template <> void* CNV<Condition>::convert(Condition *object) const; + template <> void* CNV<Isotope>::convert(Isotope *object) const; template <> void* CNV<Element>::convert(Element *object) const; template <> void* CNV<Material>::convert(Material *object) const; @@ -229,6 +237,17 @@ namespace DD4hep { template <> void* CNV<Catalog>::convert(Catalog *object) const; template <> void* CNV<dddb>::convert(dddb *obj) const; + + /// Convert single condition objects + template <> void* CNV<Condition>::convert(Condition *object) const { + Context* context = _param<Context>(); + GeoCondition* cond = Context::find(context->conditions, object); + if ( !cond ) { + + } + return cond; + } + /// Convert single isotope objects template <> void* CNV<Isotope>::convert(Isotope *object) const { Context* context = _param<Context>(); @@ -475,40 +494,13 @@ namespace DD4hep { else if ( object->type == Trap::type() ) { const Trap& o = object->s.trap; shape = Geometry::Trap(o.dz, o.theta, o.phi, - o.h1, o.bl1, o.bl2, o.alpha1, - o.h2, o.tl1, o.tl2, o.alpha2); + o.h1, o.bl1, o.tl1, o.alpha1, + o.h2, o.bl2, o.tl2, o.alpha2); } else if ( object->type == BooleanUnion::type() || object->type == BooleanSubtraction::type() || object->type == BooleanIntersection::type() ) { shape = context->lvDummy.solid(); - if ( object->path.find("/dd/Geometry/DownstreamRegion/AfterMuon/PipeAfterMuon/BPMSWDownStrMidSectSub")!= string::npos ) { - printout(INFO,"Cnv<Shape>","++ IGNORE Problematic shape %s",object->path.c_str()); - goto Done; - } - if ( object->path.find("/dd/Geometry/UpstreamRegion/PipeUpstream/BPMSWUpStrMidSectSub")!= string::npos ) { - printout(INFO,"Cnv<Shape>","++ IGNORE Problematic shape %s",object->path.c_str()); - goto Done; - } - if ( object->path.find("/dd/Geometry/BeforeMagnetRegion/Rich1/lvRich1MagShTrapBoxH")!= string::npos ) { - printout(INFO,"Cnv<Shape>","++ IGNORE Problematic shape %s",object->path.c_str()); - goto Done; - } - if ( object->path.find("/dd/Geometry/BeforeMagnetRegion/Rich1/Rich1Mirror1")!= string::npos ) { - printout(INFO,"Cnv<Shape>","++ IGNORE Problematic shape %s",object->path.c_str()); - goto Done; - } - if ( object->path.find("/dd/Geometry/AfterMagnetRegion/Rich2/lvRich2SphMirror")!=string::npos) { - printout(INFO,"Cnv<Shape>","++ IGNORE Problematic shape %s",object->path.c_str()); - goto Done; - } - if ( object->path.find("/dd/Geometry/MagnetRegion/Magnet/Coil_Subtraction")!=string::npos) { - printout(INFO,"Cnv<Shape>","++ IGNORE Problematic shape %s",object->path.c_str()); - goto Done; - } - - int cnt = 0; - static int num = 0; Shape::Operations::const_iterator i; Shape* left_shape = object->s.boolean.first; GeoSolid left_solid = (TGeoShape*)convert(left_shape); @@ -519,11 +511,6 @@ namespace DD4hep { shape = left_solid; for(i=object->boolean_ops.begin(); i != object->boolean_ops.end(); ++i) { Shape* right_shape = (*i).shape; - if ( ++cnt >= 4 ) { - ++num; - printout(DEBUG,"Cnv<Shape>","++ USING Problematic shape[%d]: level:%d %s -> %s", - num,cnt,object->path.c_str(), right_shape->path.c_str()); - } GeoSolid right_solid = (TGeoShape*)convert(right_shape); const Geometry::Transform3D& trafo = (*i).trafo; if ( !right_solid.isValid() ) { // Error .... @@ -544,7 +531,6 @@ namespace DD4hep { left_solid = shape; } } - Done: if ( !shape ) { except("Cnv<Shape>","++ Undefined shape conversion %s [id:%d]", object->c_id(), object->type); @@ -1000,6 +986,8 @@ namespace DD4hep { //printout(INFO,"DDDB2Object","++ Converted %d volumes.",int(obj->volumes.size())); //for_each(obj->placements.begin(),obj->placements.end(), cnv<PhysVol>()); //printout(INFO,"DDDB2Object","++ Converted %d placements.",int(obj->placements.size())); + for_each(obj->conditions.begin(),obj->conditions.end(), cnv<Condition>()); + printout(INFO,"DDDB2Object","++ Converted %d conditions.",int(obj->conditions.size())); cnv<Catalog>().convert( obj->top ); if ( 0 == incr.counter() ) { lcdd.endDocument(); @@ -1020,14 +1008,14 @@ static long dddb_2_dd4hep(LCDD& lcdd, int , char** ) { Context context(lcdd, helper->geometry()); context.helper = helper; context.print_materials = false; - context.print_logvol = true; + context.print_logvol = false; context.print_shapes = false; context.print_physvol = false; context.print_volumes = false; context.print_params = false; context.print_detelem = false; context.print_conditions = false; - context.max_volume_depth = 9; + context.max_volume_depth = 15; CNV<dddb> cnv(lcdd,&context); string top = "/dd/Geometry/LHCb/lvLHCb"; @@ -1041,6 +1029,7 @@ static long dddb_2_dd4hep(LCDD& lcdd, int , char** ) { } context.geo->world = s->s.box; cnv(make_pair(string("World"),context.geo)); + helper->setGeometry(0); return 1; } except("DDDB2DD4hep","++ No DDDBHelper instance installed. Geometry conversion failed!"); diff --git a/DDDB/src/DDDBConversion.cpp b/DDDB/src/DDDBConversion.cpp index 504412746b3ca689933d80d3ce10f7bf4dfd9762..8aaa6f26b2e7eb1405ae357c27d5196606790bbb 100644 --- a/DDDB/src/DDDBConversion.cpp +++ b/DDDB/src/DDDBConversion.cpp @@ -47,13 +47,44 @@ namespace DD4hep { /// Default destructor DDDB::dddb::~dddb() { // need to release heare all allocated resources. + destroyObjects(isotopes)(); + destroyObjects(elements)(); + elementPaths.clear(); + + destroyObjects(materials)(); + materialPaths.clear(); + + destroyObjects(shapes)(); + + destroyObjects(volumes)(); + volumePaths.clear(); + + destroyObjects(placements)(); + placementPaths.clear(); + + destroyObjects(conditions)(); destroyObjects(catalogs)(); + catalogPaths.clear(); + printout(INFO,"dddb","++ All intermediate objects deleted!"); } /// Default constructor DDDB::Shape::Shape() : type(0), zplanes(), boolean_ops() { ::memset(&s.box,0,sizeof(s)); } + + /// Default destructor + DDDB::Shape::~Shape() { + if ( type == BooleanUnion::type() || + type == BooleanSubtraction::type() || + type == BooleanIntersection::type() ) { + Shape* shape = s.boolean.first; + if ( shape ) delete shape; + for(Operations::iterator i=boolean_ops.begin(); i!=boolean_ops.end(); ++i) + delete (*i).shape; + boolean_ops.clear(); + } + } pair<const DDDB::Catalog*,string> DDDB::Catalog::parent(const string& nam) const { const Catalog* cat = this;