diff --git a/DDAlign/include/DDAlign/AlignmentCache.h b/DDAlign/include/DDAlign/AlignmentCache.h index a85d260e6f5451ba907c81ed8bc7e09e36e73475..a10fb19b91eaac4f802590aa3ce9d66456899aed 100644 --- a/DDAlign/include/DDAlign/AlignmentCache.h +++ b/DDAlign/include/DDAlign/AlignmentCache.h @@ -15,20 +15,19 @@ #define DD4HEP_ALIGNMENT_ALIGNMENTCACHE_H // Framework include files -#include "DD4hep/Alignment.h" +#include "DD4hep/GlobalAlignment.h" #include "DDAlign/AlignmentStack.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { + namespace Alignments { /// Forward declarations class AlignmentOperator; class AlignmentCache; class AlignmentStack; - class LCDD; /// Class caching all known alignment operations for one LCDD instance. /** @@ -76,7 +75,7 @@ namespace DD4hep { /// Apply a vector of SD entries of ordered alignments to the geometry structure void apply(const std::vector<Entry*> &changes); /// Add a new entry to the cache. The key is the placement path - bool insert(Alignment alignment); + bool insert(GlobalAlignment alignment); public: /// Create and install a new instance tree @@ -97,11 +96,11 @@ namespace DD4hep { /// Retrieve the cache section corresponding to the path of an entry. AlignmentCache* section(const std::string& path_name) const; /// Retrieve an alignment entry by its lacement path - Alignment get(const std::string& path) const; + GlobalAlignment get(const std::string& path) const; /// Return all entries matching a given path. Careful: Expensive operaton! - std::vector<Alignment> matches(const std::string& path_match, bool exclude_exact=false) const; + std::vector<GlobalAlignment> matches(const std::string& path_match, bool exclude_exact=false) const; }; - } /* End namespace Geometry */ -} /* End namespace DD4hep */ + } /* End namespace Alignments */ +} /* End namespace DD4hep */ #endif /* DD4HEP_ALIGNMENT_ALIGNMENTCACHE_H */ diff --git a/DDAlign/include/DDAlign/AlignmentOperators.h b/DDAlign/include/DDAlign/AlignmentOperators.h index 89edb3dc96aa6f6b4197880ba1494a8a5a257908..596e108abed8bd5a4179d33ef9a258abb6088e76 100644 --- a/DDAlign/include/DDAlign/AlignmentOperators.h +++ b/DDAlign/include/DDAlign/AlignmentOperators.h @@ -15,18 +15,15 @@ #define DD4HEP_ALIGNMENT_ALIGNMENTOPERATORS_H // Framework include files -#include "DD4hep/Alignment.h" +#include "DD4hep/Alignments.h" +#include "DD4hep/GlobalAlignment.h" #include "DDAlign/AlignmentCache.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { - - /// Forward declarations - class LCDD; - + namespace Alignments { /// Base class for alignment functors /** diff --git a/DDAlign/include/DDAlign/AlignmentStack.h b/DDAlign/include/DDAlign/AlignmentStack.h index 72dc476ff099bfb3e3c69c7864e32a05fd2964c4..87be8a206adb7576c2cabb6d0829f77205659981 100644 --- a/DDAlign/include/DDAlign/AlignmentStack.h +++ b/DDAlign/include/DDAlign/AlignmentStack.h @@ -24,7 +24,7 @@ namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { + namespace Alignments { /// Alignment Stack object definition /** diff --git a/DDAlign/include/DDAlign/AlignmentTags.h b/DDAlign/include/DDAlign/AlignmentTags.h index 78ce944f8c27f15a86b00cd147ff9ee034bdeaba..44d295b8e0baa5fcc55f32eefd41477fdfe87980 100644 --- a/DDAlign/include/DDAlign/AlignmentTags.h +++ b/DDAlign/include/DDAlign/AlignmentTags.h @@ -17,13 +17,13 @@ // Framework include files #include "XML/XMLElements.h" #ifndef UNICODE -#define UNICODE(x) extern const Tag_t Unicode_##x +#define UNICODE(x) extern const ::DD4hep::XML::Tag_t Unicode_##x #endif // Unicode tags known to the alignment section namespace DD4hep { /// Namespace for the AIDA detector description toolkit supporting XML utilities - namespace XML { + namespace DDAlign { // Alignment tags @@ -36,6 +36,7 @@ namespace DD4hep { UNICODE(path); UNICODE(pivot); UNICODE(reset); + UNICODE(overlap); UNICODE(placement); UNICODE(reset_children); UNICODE(open_transaction); @@ -45,7 +46,8 @@ namespace DD4hep { } #undef UNICODE // Do not miss this one! - #include "XML/XMLTags.h" +#define _ALU(a) ::DD4hep::DDAlign::Unicode_##a + #endif /* DD4HEP_ALIGNMENT_ALIGNMENT_TAGS_H */ diff --git a/DDAlign/include/DDAlign/AlignmentTransaction.h b/DDAlign/include/DDAlign/AlignmentTransaction.h index 515195eee089d7362ff1058780d006e9eaf2e603..bb525291cb1d6cf8e1b51442cad891dae6846679 100644 --- a/DDAlign/include/DDAlign/AlignmentTransaction.h +++ b/DDAlign/include/DDAlign/AlignmentTransaction.h @@ -15,7 +15,7 @@ #define DD4HEP_ALIGNMENT_ALIGNMENTTRANSACTION_H // Framework include files -#include "DD4hep/Primitives.h" +#include "DD4hep/Alignments.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -23,10 +23,9 @@ namespace DD4hep { namespace XML { class Handle_t; } /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { + namespace Alignments { // Forward declarations - class LCDD; class AlignmentCache; /// Manage alignment transaction to the cache for a given LCDD instance diff --git a/DDAlign/include/DDAlign/AlignmentWriter.h b/DDAlign/include/DDAlign/AlignmentWriter.h index f8c1cd85a3e7e88000cac5c74878bc099ddf1f2c..43d36dc125c091b4b4c58a4d8df76534bddfa80b 100644 --- a/DDAlign/include/DDAlign/AlignmentWriter.h +++ b/DDAlign/include/DDAlign/AlignmentWriter.h @@ -17,15 +17,15 @@ // Framework include files #include "XML/XMLElements.h" #include "DD4hep/Detector.h" +#include "DD4hep/GlobalAlignment.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { + namespace Alignments { // Forward declarations - class LCDD; class AlignmentCache; /// Write aligment data to XML data file @@ -42,7 +42,7 @@ namespace DD4hep { AlignmentCache* m_cache; /// Add single alignment node to the XML document - void addNode(XML::Element elt, Alignment a) const; + void addNode(XML::Element elt, GlobalAlignment a) const; public: /// Initializing Constructor diff --git a/DDAlign/include/DDAlign/DetectorAlignment.h b/DDAlign/include/DDAlign/DetectorAlignment.h index 906c07771429491f0b46683688732baa013d9527..66ad04f5eca58446da93c1b5f6789bd6c0afe7ae 100644 --- a/DDAlign/include/DDAlign/DetectorAlignment.h +++ b/DDAlign/include/DDAlign/DetectorAlignment.h @@ -16,6 +16,7 @@ // Framework include files #include "DD4hep/Detector.h" +#include "DD4hep/GlobalAlignment.h" // Forward declarations class TGeoHMatrix; @@ -24,7 +25,7 @@ class TGeoHMatrix; namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { + namespace Alignments { // Forward declarations class DetElement; @@ -43,37 +44,37 @@ namespace DD4hep { /// Collect all placements from the detector element up to the world volume void collectNodes(std::vector<PlacedVolume>& nodes); /// Access to the alignment block - Alignment alignment() const; + GlobalAlignment alignment() const; /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements - std::vector<Alignment>& volumeAlignments(); + std::vector<GlobalAlignment>& volumeAlignments(); /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements - const std::vector<Alignment>& volumeAlignments() const; + const std::vector<GlobalAlignment>& volumeAlignments() const; /** @DetElement alignment: Calls to align the detector element itself */ /// Align the PhysicalNode of the placement of the detector element (translation only) - Alignment align(const Position& pos, bool check = false, double overlap = 0.001); + GlobalAlignment align(const Position& pos, bool check = false, double overlap = 0.001); /// Align the PhysicalNode of the placement of the detector element (rotation only) - Alignment align(const RotationZYX& rot, bool check = false, double overlap = 0.001); + GlobalAlignment align(const RotationZYX& rot, bool check = false, double overlap = 0.001); /// Align the PhysicalNode of the placement of the detector element (translation + rotation) - Alignment align(const Position& pos, const RotationZYX& rot, bool check = false, double overlap = 0.001); + GlobalAlignment align(const Position& pos, const RotationZYX& rot, bool check = false, double overlap = 0.001); /// Align the physical node according to a generic Transform3D - Alignment align(const Transform3D& tr, bool check = false, double overlap = 0.001); + GlobalAlignment align(const Transform3D& tr, bool check = false, double overlap = 0.001); /// Align the physical node according to a generic TGeo matrix - Alignment align(TGeoHMatrix* matrix, bool check = false, double overlap = 0.001); + GlobalAlignment align(TGeoHMatrix* matrix, bool check = false, double overlap = 0.001); /** @Volume alignment: Calls to align the volumes within on detector element */ /// Align the PhysicalNode of the placement of the detector element (translation only) - Alignment align(const std::string& volume_path, const Position& pos, bool check = false, double overlap = 0.001); + GlobalAlignment align(const std::string& volume_path, const Position& pos, bool check = false, double overlap = 0.001); /// Align the PhysicalNode of the placement of the detector element (rotation only) - Alignment align(const std::string& volume_path, const RotationZYX& rot, bool check = false, double overlap = 0.001); + GlobalAlignment align(const std::string& volume_path, const RotationZYX& rot, bool check = false, double overlap = 0.001); /// Align the PhysicalNode of the placement of the detector element (translation + rotation) - Alignment align(const std::string& volume_path, const Position& pos, const RotationZYX& rot, bool check = false, double overlap = 0.001); + GlobalAlignment align(const std::string& volume_path, const Position& pos, const RotationZYX& rot, bool check = false, double overlap = 0.001); /// Align the physical node according to a generic Transform3D - Alignment align(const std::string& volume_path, const Transform3D& tr, bool check = false, double overlap = 0.001); + GlobalAlignment align(const std::string& volume_path, const Transform3D& tr, bool check = false, double overlap = 0.001); /// Align the physical node according to a generic TGeo matrix - Alignment align(const std::string& volume_path, TGeoHMatrix* matrix, bool check = false, double overlap = 0.001); + GlobalAlignment align(const std::string& volume_path, TGeoHMatrix* matrix, bool check = false, double overlap = 0.001); }; - } /* End namespace Geometry */ + } /* End namespace Alignments */ } /* End namespace DD4hep */ #endif /* DD4HEP_GEOMETRY_DETECTORALIGNMENT_H */ diff --git a/DDAlign/src/AlignmentCache.cpp b/DDAlign/src/AlignmentCache.cpp index 3694b2798df0508df21cabd1611c473a77694e0c..c18165ebc76349f452941975ad474d791f53170d 100644 --- a/DDAlign/src/AlignmentCache.cpp +++ b/DDAlign/src/AlignmentCache.cpp @@ -26,8 +26,8 @@ using namespace std; using namespace DD4hep; -using namespace DD4hep::Geometry; -using namespace DD4hep::Geometry::DDAlign_standard_operations; +using namespace DD4hep::Alignments; +using namespace DD4hep::Alignments::DDAlign_standard_operations; typedef AlignmentStack::StackEntry Entry; DetElement _detector(DetElement child) { @@ -74,7 +74,7 @@ int AlignmentCache::release() { } /// Add a new entry to the cache. The key is the placement path -bool AlignmentCache::insert(Alignment alignment) { +bool AlignmentCache::insert(GlobalAlignment alignment) { TGeoPhysicalNode* pn = alignment.ptr(); unsigned int index = hash32(pn->GetName()+m_sdPathLen); Cache::const_iterator i = m_cache.find(index); @@ -106,33 +106,33 @@ AlignmentCache* AlignmentCache::section(const string& path_name) const { } /// Retrieve an alignment entry by its placement path -Alignment AlignmentCache::get(const string& path_name) const { +GlobalAlignment AlignmentCache::get(const string& path_name) const { size_t idx, idq; unsigned int index = hash32(path_name.c_str()+m_sdPathLen); Cache::const_iterator i = m_cache.find(index); if ( i != m_cache.end() ) { - return Alignment((*i).second); + return GlobalAlignment((*i).second); } else if ( m_detectors.empty() ) { - return Alignment(0); + return GlobalAlignment(0); } else if ( path_name[0] != '/' ) { return get(m_lcdd.world().placementPath()+'/'+path_name); } else if ( (idx=path_name.find('/',1)) == string::npos ) { // Escape: World volume and not found in cache --> not present - return Alignment(0); + return GlobalAlignment(0); } if ( (idq=path_name.find('/',idx+1)) != string::npos ) --idq; string path = path_name.substr(idx+1,idq-idx); SubdetectorAlignments::const_iterator j = m_detectors.find(path); if ( j != m_detectors.end() ) return (*j).second->get(path_name); - return Alignment(0); + return GlobalAlignment(0); } /// Return all entries matching a given path. -vector<Alignment> AlignmentCache::matches(const string& match, bool exclude_exact) const { - vector<Alignment> result; +vector<GlobalAlignment> AlignmentCache::matches(const string& match, bool exclude_exact) const { + vector<GlobalAlignment> result; AlignmentCache* c = section(match); if ( c ) { size_t len = match.length(); @@ -142,7 +142,7 @@ vector<Alignment> AlignmentCache::matches(const string& match, bool exclude_exac const char* n = v.second->GetName(); if ( 0 == ::strncmp(n,match.c_str(),len) ) { if ( exclude_exact && len == ::strlen(n) ) continue; - result.push_back(Alignment(v.second)); + result.push_back(GlobalAlignment(v.second)); } } } diff --git a/DDAlign/src/AlignmentOperators.cpp b/DDAlign/src/AlignmentOperators.cpp index adc758b2ad2c8b6b1fcd821e37e2d24f9cc1c170..a331152eb3135a9be07d22b4997054b191cdbc29 100644 --- a/DDAlign/src/AlignmentOperators.cpp +++ b/DDAlign/src/AlignmentOperators.cpp @@ -15,6 +15,7 @@ // Framework include files #include "DD4hep/LCDD.h" #include "DD4hep/Printout.h" +#include "DD4hep/objects/DetectorInterna.h" #include "DDAlign/AlignmentOperators.h" #include "DDAlign/DetectorAlignment.h" @@ -23,7 +24,7 @@ using namespace std; using namespace DD4hep; -using namespace DD4hep::Geometry; +using namespace DD4hep::Alignments; void AlignmentOperator::insert(Alignment alignment) const { if ( !cache.insert(alignment) ) { @@ -81,7 +82,7 @@ template <> void AlignmentActor<DDAlign_standard_operations::node_reset>::operat TGeoMatrix* mm = node->GetMatrix(); // Node's relative matrix np += string("/")+node->GetName(); if ( !mm->IsIdentity() && i > 0 ) { // Ignore the 'world', is identity anyhow - Alignment a = cache.get(np); + GlobalAlignment a = cache.get(np); if ( a.isValid() ) { printout(ALWAYS,"AlignmentActor<reset>","Correct path:%s leaf:%s",p->GetName(),np.c_str()); TGeoHMatrix* glob = p->GetMatrix(i-1); @@ -103,12 +104,12 @@ template <> void AlignmentActor<DDAlign_standard_operations::node_reset>::operat template <> void AlignmentActor<DDAlign_standard_operations::node_align>::operator()(Nodes::value_type& n) const { Entry& e = *n.second.second; - bool check = e.checkOverlap(); - bool overlap = e.overlapDefined(); - bool has_matrix = e.hasMatrix(); + bool check = e.checkOverlap(); + bool overlap = e.overlapDefined(); + bool has_matrix = e.hasMatrix(); DetElement det = e.detector; - bool valid = det.alignment().isValid(); - string det_placement = det.placementPath(); + bool valid = det->global_alignment.isValid(); + string det_placement = det.placementPath(); if ( !valid && !has_matrix ) { cout << "++++ SKIP ALIGNMENT: ++++ " << e.path diff --git a/DDAlign/src/AlignmentParser.cpp b/DDAlign/src/AlignmentParser.cpp index 0e0dc8e2db9cb0fbea118a45de10affe774fc819..b1855fd2f371bd60ba7fdc2c2e838ee759e9ec01 100644 --- a/DDAlign/src/AlignmentParser.cpp +++ b/DDAlign/src/AlignmentParser.cpp @@ -58,7 +58,7 @@ namespace DD4hep { using namespace std; using namespace DD4hep; -using namespace DD4hep::Geometry; +using namespace DD4hep::Alignments; /** Convert rotation objects * @@ -183,13 +183,13 @@ typedef AlignmentStack::StackEntry StackEntry; template <> void Converter<volume>::operator()(xml_h e) const { pair<bool,Transform3D> trafo; pair<DetElement,string>* elt = (pair<DetElement,string>*)param; - string subpath = e.attr<string>(_U(path)); - bool reset = e.hasAttr(_U(reset)) ? e.attr<bool>(_U(reset)) : true; - bool reset_dau = e.hasAttr(_U(reset_children)) ? e.attr<bool>(_U(reset_children)) : true; - bool check = e.hasAttr(_U(check_overlaps)); - bool check_val = check ? e.attr<bool>(_U(check_overlaps)) : false; - bool overlap = e.hasAttr(_U(overlap)); - double ovl = overlap ? e.attr<double>(_U(overlap)) : 0.001; + string subpath = e.attr<string>(_ALU(path)); + bool reset = e.hasAttr(_ALU(reset)) ? e.attr<bool>(_ALU(reset)) : true; + bool reset_dau = e.hasAttr(_ALU(reset_children)) ? e.attr<bool>(_ALU(reset_children)) : true; + bool check = e.hasAttr(_ALU(check_overlaps)); + bool check_val = check ? e.attr<bool>(_ALU(check_overlaps)) : false; + bool overlap = e.hasAttr(_ALU(overlap)); + double ovl = overlap ? e.attr<double>(_ALU(overlap)) : 0.001; string eltPlacement = elt->first.placementPath(); string placementPath = subpath[0]=='/' ? subpath : eltPlacement + "/" + subpath; @@ -229,13 +229,13 @@ template <> void Converter<volume>::operator()(xml_h e) const { */ template <> void Converter<detelement>::operator()(xml_h e) const { DetElement det = param ? *(DetElement*)param : DetElement(); - string path = e.attr<string>(_U(path)); - bool check = e.hasAttr(_U(check_overlaps)); - bool check_val = check ? e.attr<bool>(_U(check_overlaps)) : false; - bool reset = e.hasAttr(_U(reset)) ? e.attr<bool>(_U(reset)) : false; - bool reset_dau = e.hasAttr(_U(reset_children)) ? e.attr<bool>(_U(reset_children)) : false; - bool overlap = e.hasAttr(_U(overlap)); - double ovl = overlap ? e.attr<double>(_U(overlap)) : 0.001; + string path = e.attr<string>(_ALU(path)); + bool check = e.hasAttr(_ALU(check_overlaps)); + bool check_val = check ? e.attr<bool>(_ALU(check_overlaps)) : false; + bool reset = e.hasAttr(_ALU(reset)) ? e.attr<bool>(_ALU(reset)) : false; + bool reset_dau = e.hasAttr(_ALU(reset_children)) ? e.attr<bool>(_ALU(reset_children)) : false; + bool overlap = e.hasAttr(_ALU(overlap)); + double ovl = overlap ? e.attr<double>(_ALU(overlap)) : 0.001; DetElement elt = Geometry::DetectorTools::findDaughterElement(det,path); string placementPath = elt.isValid() ? elt.placementPath() : string("-----"); @@ -268,7 +268,7 @@ template <> void Converter<detelement>::operator()(xml_h e) const { pair<DetElement,string> vol_param(elt,""); xml_coll_t(e,_U(volume)).for_each(Converter<volume>(lcdd,&vol_param)); - xml_coll_t(e,_U(detelement)).for_each(Converter<detelement>(lcdd,&elt)); + xml_coll_t(e,_ALU(detelement)).for_each(Converter<detelement>(lcdd,&elt)); xml_coll_t(e,_U(include)).for_each(Converter<include_file>(lcdd,&elt)); } @@ -292,7 +292,7 @@ template <> void Converter<include_file>::operator()(xml_h element) const { else if ( tag == "detelement" ) Converter<detelement>(lcdd,param)(node); else if ( tag == "subdetectors" || tag == "detelements" ) - xml_coll_t(node,_U(detelements)).for_each(Converter<detelement>(lcdd,param)); + xml_coll_t(node,_ALU(detelements)).for_each(Converter<detelement>(lcdd,param)); else throw runtime_error("Undefined tag name in XML structure:"+tag+" XML parsing abandoned."); } @@ -314,9 +314,9 @@ template <> void Converter<alignment>::operator()(xml_h e) const { /// Now we process all allowed elements within the alignment tag: /// <detelement/>, <detelements/>, <subdetectors/> and <include/> - xml_coll_t(e,_U(detelement)).for_each(Converter<detelement>(lcdd,&top)); - xml_coll_t(e,_U(detelements)).for_each(_U(detelement),Converter<detelement>(lcdd,&top)); - xml_coll_t(e,_U(subdetectors)).for_each(_U(detelement),Converter<detelement>(lcdd,&top)); + xml_coll_t(e,_ALU(detelement)).for_each(Converter<detelement>(lcdd,&top)); + xml_coll_t(e,_ALU(detelements)).for_each(_ALU(detelement),Converter<detelement>(lcdd,&top)); + xml_coll_t(e,_ALU(subdetectors)).for_each(_ALU(detelement),Converter<detelement>(lcdd,&top)); xml_coll_t(e,_U(include)).for_each(Converter<include_file>(lcdd,&top)); } diff --git a/DDAlign/src/AlignmentStack.cpp b/DDAlign/src/AlignmentStack.cpp index a48418516f4a13eb9757cbf9586e99f4138b2e33..98a67a47610cba0a0561f50548e8e7c1162742b7 100644 --- a/DDAlign/src/AlignmentStack.cpp +++ b/DDAlign/src/AlignmentStack.cpp @@ -21,7 +21,7 @@ using namespace std; using namespace DD4hep; -using namespace DD4hep::Geometry; +using namespace DD4hep::Alignments; static dd4hep_ptr<AlignmentStack>& _stack() { static dd4hep_ptr<AlignmentStack> s; @@ -29,8 +29,7 @@ static dd4hep_ptr<AlignmentStack>& _stack() { } static dd4hep_ptr<AlignmentStack>& _stack(AlignmentStack* obj) { dd4hep_ptr<AlignmentStack>& s = _stack(); - dd4hep_ptr<AlignmentStack> n(obj); - s = n; + s.adopt(obj); return s; } diff --git a/DDAlign/src/AlignmentTags.cpp b/DDAlign/src/AlignmentTags.cpp index c819d014689b08b32a55d4061637d8e9ef22ac96..0f209765dc28beee45381de76ab07f1be5e27fb7 100644 --- a/DDAlign/src/AlignmentTags.cpp +++ b/DDAlign/src/AlignmentTags.cpp @@ -16,5 +16,7 @@ #include "XML/XMLTags.h" // Define unicode tags +#ifndef UNICODE #define UNICODE(x) DECLARE_UNICODE_TAG(x) +#endif #include "DDAlign/AlignmentTags.h" diff --git a/DDAlign/src/AlignmentTransaction.cpp b/DDAlign/src/AlignmentTransaction.cpp index 7bdddd43ba471db966d1efc4fe487594ec629edd..0a3cd82c4ea8384ad4645715c604a06fddefbf26 100644 --- a/DDAlign/src/AlignmentTransaction.cpp +++ b/DDAlign/src/AlignmentTransaction.cpp @@ -19,15 +19,15 @@ #include "DDAlign/AlignmentTransaction.h" using namespace DD4hep; -using namespace DD4hep::Geometry; +using namespace DD4hep::Alignments; /// Default constructor AlignmentTransaction::AlignmentTransaction(LCDD& l, const XML::Handle_t& e) : lcdd(l) { - flag = e.hasChild(_U(close_transaction)); + flag = e.hasChild(_ALU(close_transaction)); /// First check if a transaction is to be opened - m_cache = lcdd.extension<Geometry::AlignmentCache>(); + m_cache = lcdd.extension<Alignments::AlignmentCache>(); m_cache->addRef(); - if ( e.hasChild(_U(open_transaction)) ) { + if ( e.hasChild(_ALU(open_transaction)) ) { m_cache->openTransaction(); } } @@ -35,7 +35,7 @@ AlignmentTransaction::AlignmentTransaction(LCDD& l, const XML::Handle_t& e) : lc AlignmentTransaction::~AlignmentTransaction() { /// Last check if a transaction is to be closed if ( flag ) { - lcdd.extension<Geometry::AlignmentCache>()->closeTransaction(); + lcdd.extension<Alignments::AlignmentCache>()->closeTransaction(); } m_cache->release(); } diff --git a/DDAlign/src/AlignmentWriter.cpp b/DDAlign/src/AlignmentWriter.cpp index 26e9ec4aee48fdf29e1fcefc720d88d9b16135d9..a3af11a8b3da43681c4c1bfbb2a5e916f2f79968 100644 --- a/DDAlign/src/AlignmentWriter.cpp +++ b/DDAlign/src/AlignmentWriter.cpp @@ -18,6 +18,7 @@ #include "DD4hep/Printout.h" #include "DD4hep/MatrixHelpers.h" #include "DD4hep/DetectorTools.h" +#include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/DetFactoryHelper.h" #include "XML/DocumentHandler.h" #include "DDAlign/AlignmentTags.h" @@ -29,7 +30,8 @@ // C/C++ include files #include <stdexcept> -using namespace DD4hep::Geometry; +namespace DetectorTools = DD4hep::Geometry::DetectorTools; +using namespace DD4hep::Alignments; using namespace DD4hep; using namespace std; @@ -37,7 +39,7 @@ using namespace std; AlignmentWriter::AlignmentWriter(LCDD& lcdd) : m_lcdd(lcdd) { - m_cache = lcdd.extension<Geometry::AlignmentCache>(); + m_cache = lcdd.extension<Alignments::AlignmentCache>(); } /// Standard destructor @@ -47,19 +49,19 @@ AlignmentWriter::~AlignmentWriter() { /// Create the element corresponding to one single detector element without children XML::Element AlignmentWriter::createElement(XML::Document doc, DetElement element) const { - XML::Element e(0), placement(0), elt = XML::Element(doc,_U(detelement)); + XML::Element e(0), placement(0), elt = XML::Element(doc,_ALU(detelement)); string path = element.placementPath(); - Alignment a = element.alignment(); + GlobalAlignment a = element->global_alignment; DetectorAlignment det(element); - const vector<Alignment>& va = det.volumeAlignments(); + const vector<GlobalAlignment>& va = det.volumeAlignments(); - elt.setAttr(_U(path),element.path()); + elt.setAttr(_ALU(path),element.path()); if ( a.isValid() ) { addNode(elt,a); } - for(vector<Alignment>::const_iterator i=va.begin(); i!=va.end();++i) { + for(vector<GlobalAlignment>::const_iterator i=va.begin(); i!=va.end();++i) { e = XML::Element(doc,_U(volume)); - e.setAttr(_U(path),(*i)->GetName()); + e.setAttr(_ALU(path),(*i)->GetName()); addNode(e,*i); elt.append(e); } @@ -67,13 +69,13 @@ XML::Element AlignmentWriter::createElement(XML::Document doc, DetElement elemen } /// Add single alignment node to the XML document -void AlignmentWriter::addNode(XML::Element elt, Alignment a) const { +void AlignmentWriter::addNode(XML::Element elt, GlobalAlignment a) const { TGeoNode* n = a->GetNode(); TGeoHMatrix mat(a->GetOriginalMatrix()->Inverse()); mat.Multiply(n->GetMatrix()); const Double_t* t = mat.GetTranslation(); XML::Element placement = XML::Element(elt.document(),_U(comment)); - placement.setAttr(_U(placement),a->GetName()); + placement.setAttr(_ALU(placement),a->GetName()); elt.append(placement); printout(INFO,"AlignmentWriter","Write Delta constants for %s",a->GetName()); @@ -109,7 +111,7 @@ XML::Element AlignmentWriter::scan(XML::Document doc, DetElement element) const XML::Element elt(0); if ( element.isValid() ) { const DetElement::Children& c = element.children(); - Alignment alignment = element.alignment(); + GlobalAlignment alignment = element->global_alignment; if ( alignment.isValid() ) elt = createElement(doc,element); for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) { XML::Element daughter = scan(doc, (*i).second); @@ -137,10 +139,10 @@ XML::Document AlignmentWriter::dump(DetElement top, bool enable_transactions) c XML::DocumentHandler docH; XML::Document doc = docH.create("alignment", comment); XML::Element elt(0), elements(0), root = doc.root(); - root.append(elements = XML::Element(doc, _U(detelements))); - if ( enable_transactions ) root.append(XML::Element(doc,_U(open_transaction))); + root.append(elements = XML::Element(doc, _ALU(detelements))); + if ( enable_transactions ) root.append(XML::Element(doc,_ALU(open_transaction))); if ( (elt=scan(doc,top)) ) elements.append(elt); - if ( enable_transactions ) root.append(XML::Element(doc,_U(close_transaction))); + if ( enable_transactions ) root.append(XML::Element(doc,_ALU(close_transaction))); return doc; } diff --git a/DDAlign/src/DetectorAlignment.cpp b/DDAlign/src/DetectorAlignment.cpp index e0630684d98ec3fcdcad80316587e2f5004c5879..c14b778bd4a125591689206ad77ee27f184791a6 100644 --- a/DDAlign/src/DetectorAlignment.cpp +++ b/DDAlign/src/DetectorAlignment.cpp @@ -19,21 +19,40 @@ #include "DD4hep/MatrixHelpers.h" #include "DD4hep/Printout.h" #include "DD4hep/objects/DetectorInterna.h" +#include "DD4hep/Handle.inl" // ROOT include files #include "TGeoMatrix.h" #include "TGeoManager.h" +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the alignment part of the AIDA detector description toolkit + namespace Alignments { + + class GlobalAlignmentData : public NamedObject { + public: + GlobalAlignment global; + std::vector<GlobalAlignment> volume_alignments; + public: + GlobalAlignmentData() : NamedObject("","global-alignment") {} + virtual ~GlobalAlignmentData() {} + }; + } /* End namespace Aligments */ +} /* End namespace DD4hep */ + + using namespace std; using namespace DD4hep; -using namespace DD4hep::Geometry; +using namespace DD4hep::Alignments; -typedef DetectorTools::ElementPath ElementPath; -typedef DetectorTools::PlacementPath PlacementPath; +namespace DetectorTools = DD4hep::Geometry::DetectorTools; typedef vector<pair<int,DetElement> > LevelElements; + namespace { - Alignment _align(const Alignment& a, TGeoHMatrix* transform, bool check, double overlap) { + GlobalAlignment _align(const GlobalAlignment& a, TGeoHMatrix* transform, bool check, double overlap) { TGeoPhysicalNode* n = a.ptr(); if ( n ) { TGeoMatrix* mm = n->GetNode()->GetMatrix(); @@ -59,29 +78,38 @@ namespace { cout << "Local:" << local << " Global: " << global << " and back:" << a.globalToLocal(global) << endl; */ - return Alignment(n); + return GlobalAlignment(n); } throw runtime_error("DD4hep: Cannot align non existing physical node. [Invalid Handle]"); } - Alignment& _alignment(const DetectorAlignment& det) { + GlobalAlignment _alignment(const DetectorAlignment& det) { + Ref_t gbl = det._data().global_alignment; + if ( gbl.isValid() ) { + Handle<GlobalAlignmentData> h(gbl); + return h->global; + } + throw runtime_error("DD4hep: Cannot access global alignment data. [Invalid Handle]"); +#if 0 DetElement::Object& e = det._data(); if ( !e.alignment.isValid() ) { string path = DetectorTools::placementPath(det); //cout << "Align path:" << path << endl; - e.alignment = Alignment(path); + e.alignment = GlobalAlignment(path); } return e.alignment; +#endif } + void _dumpParentElements(DetectorAlignment& det, LevelElements& elements) { - PlacementPath nodes; - ElementPath det_nodes; + int level = 0; + DetectorTools::PlacementPath nodes; + DetectorTools::ElementPath det_nodes; DetectorTools::placementPath(det,nodes); DetectorTools::elementPath(det,det_nodes); /// cout << "Placement path:"; - int level = 0; - PlacementPath::const_reverse_iterator j=nodes.rbegin(); - ElementPath::const_reverse_iterator k=det_nodes.rbegin(); + DetectorTools::PlacementPath::const_reverse_iterator j=nodes.rbegin(); + DetectorTools::ElementPath::const_reverse_iterator k=det_nodes.rbegin(); for(; j!=nodes.rend(); ++j, ++level) { //cout << "(" << level << ") " << (void*)((*j).ptr()) // << " " << string((*j)->GetName()) << " "; @@ -99,91 +127,94 @@ namespace { } } +DD4HEP_INSTANTIATE_HANDLE_NAMED(GlobalAlignmentData); + /// Initializing constructor DetectorAlignment::DetectorAlignment(DetElement e) : DetElement(e) { } - /// Collect all placements from the detector element up to the world volume void DetectorAlignment::collectNodes(vector<PlacedVolume>& nodes) { DetectorTools::placementPath(*this,nodes); } /// Access to the alignment block -Alignment DetectorAlignment::alignment() const { +GlobalAlignment DetectorAlignment::alignment() const { return _alignment(*this); } /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements -vector<Alignment>& DetectorAlignment::volumeAlignments() { - return _data().volume_alignments; +vector<GlobalAlignment>& DetectorAlignment::volumeAlignments() { + Handle<GlobalAlignmentData> h(_data().global_alignment); + return h->volume_alignments; } /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements -const vector<Alignment>& DetectorAlignment::volumeAlignments() const { - return _data().volume_alignments; +const vector<GlobalAlignment>& DetectorAlignment::volumeAlignments() const { + Handle<GlobalAlignmentData> h(_data().global_alignment); + return h->volume_alignments; } /// Align the PhysicalNode of the placement of the detector element (translation only) -Alignment DetectorAlignment::align(const Position& pos, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const Position& pos, bool chk, double overlap) { return align(_transform(pos),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (rotation only) -Alignment DetectorAlignment::align(const RotationZYX& rot, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const RotationZYX& rot, bool chk, double overlap) { return align(_transform(rot),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (translation + rotation) -Alignment DetectorAlignment::align(const Position& pos, const RotationZYX& rot, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const Position& pos, const RotationZYX& rot, bool chk, double overlap) { return align(_transform(pos,rot),chk,overlap); } /// Align the physical node according to a generic Transform3D -Alignment DetectorAlignment::align(const Transform3D& transform, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const Transform3D& transform, bool chk, double overlap) { return align(_transform(transform),chk,overlap); } /// Align the physical node according to a generic TGeo matrix -Alignment DetectorAlignment::align(TGeoHMatrix* matrix, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(TGeoHMatrix* matrix, bool chk, double overlap) { return _align(_alignment(*this),matrix,chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (translation only) -Alignment DetectorAlignment::align(const string& elt_path, const Position& pos, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const string& elt_path, const Position& pos, bool chk, double overlap) { return align(elt_path,_transform(pos),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (rotation only) -Alignment DetectorAlignment::align(const string& elt_path, const RotationZYX& rot, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const string& elt_path, const RotationZYX& rot, bool chk, double overlap) { return align(elt_path,_transform(rot),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (translation + rotation) -Alignment +GlobalAlignment DetectorAlignment::align(const string& elt_path, const Position& pos, const RotationZYX& rot, bool chk, double overlap) { return align(elt_path,_transform(pos,rot),chk,overlap); } /// Align the physical node according to a generic Transform3D -Alignment DetectorAlignment::align(const string& elt_path, const Transform3D& transform, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const string& elt_path, const Transform3D& transform, bool chk, double overlap) { return align(elt_path,_transform(transform),chk,overlap); } /// Align the physical node according to a generic TGeo matrix -Alignment DetectorAlignment::align(const string& elt_path, TGeoHMatrix* matrix, bool chk, double overlap) { +GlobalAlignment DetectorAlignment::align(const string& elt_path, TGeoHMatrix* matrix, bool chk, double overlap) { if ( elt_path.empty() ) return _align(_alignment(*this),matrix,chk,overlap); else if ( elt_path == placementPath() ) return _align(_alignment(*this),matrix,chk,overlap); else if ( elt_path[0] == '/' ) { - Alignment a(elt_path); + GlobalAlignment a(elt_path); volumeAlignments().push_back(a); return _align(a,matrix,chk,overlap); } - Alignment a(placementPath()+'/'+elt_path); + GlobalAlignment a(placementPath()+'/'+elt_path); volumeAlignments().push_back(a); return _align(a,matrix,chk,overlap); } diff --git a/DDCond/include/DDCond/ConditionsListener.h b/DDCond/include/DDCond/ConditionsListener.h index 13fc81772d40e999d57c32ba2844edba3786945d..e2fd91a090b3d352d1dfed69ff84e03f9514f615 100644 --- a/DDCond/include/DDCond/ConditionsListener.h +++ b/DDCond/include/DDCond/ConditionsListener.h @@ -22,12 +22,14 @@ /// Namespace for the AIDA detector description toolkit namespace DD4hep { + /// Forward declarations + class IOV; + class IOVType; + /// Namespace for the geometry part of the AIDA detector description toolkit namespace Conditions { /// Forward declarations - class IOV; - class IOVType; class ConditionsPool; /// Base class to be implemented by objects to listen on condition callbacks diff --git a/DDCond/include/DDCond/ConditionsTest.h b/DDCond/include/DDCond/ConditionsTest.h index a2153ad7112be0fb97169fd801bde74ca8b4d071..c4e43fd4a6499e143939073fb2af59621ccdc4a8 100644 --- a/DDCond/include/DDCond/ConditionsTest.h +++ b/DDCond/include/DDCond/ConditionsTest.h @@ -37,7 +37,6 @@ namespace DD4hep { namespace Test { using Geometry::LCDD; - using Geometry::Position; using Geometry::DetElement; struct TestEnv { diff --git a/DDCond/src/ConditionsTest.cpp b/DDCond/src/ConditionsTest.cpp index 93f0e2e0b1b046f4d61faf35a8de9f21b07aa735..e9e8c71890af946a9613c339d72b13bdec196b16 100644 --- a/DDCond/src/ConditionsTest.cpp +++ b/DDCond/src/ConditionsTest.cpp @@ -65,7 +65,7 @@ namespace DD4hep { template <typename T> void __print_bound_container(Condition c, const char*) { const T& v = access_val<T>(c); printout(INFO,"Cond_Value"," Bound value %s : size:%d = %s Type: %s Ptr:%016X", - c.name().c_str(), int(v.size()), c.block().str().c_str(), + c.name().c_str(), int(v.size()), c.data().str().c_str(), typeName(c.typeInfo()).c_str(), (void*)&v); } diff --git a/DDCond/src/plugins/ConditionsExample.cpp b/DDCond/src/plugins/ConditionsExample.cpp index cbd8a38eabd9b9e8b5ab77ca6062400c0403fdb6..c6702911593668d4bab8e94ee61399546759af98 100644 --- a/DDCond/src/plugins/ConditionsExample.cpp +++ b/DDCond/src/plugins/ConditionsExample.cpp @@ -19,7 +19,6 @@ using namespace std; using namespace DD4hep; using namespace DD4hep::Conditions; using Geometry::LCDD; -using Geometry::Position; using Geometry::DetElement; namespace { diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index b0f146833c7e4474b4301833ea6d1373f2d26840..97ab9f6994ef9a2db8916f30a29163049e78d532 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -27,13 +27,8 @@ using namespace std; using namespace DD4hep; using namespace DD4hep::Conditions; -using Geometry::LCDD; -using Geometry::Position; -using Geometry::DetElement; namespace { - using namespace DD4hep; - using namespace DD4hep::Conditions; int ddcond_install_cond_mgr (LCDD& lcdd, int /* argc */, char** /* argv */) { Handle<ConditionsManagerObject> mgr(lcdd.extension<ConditionsManagerObject>(false)); diff --git a/DDCore/include/DD4hep/AlignmentData.h b/DDCore/include/DD4hep/AlignmentData.h new file mode 100644 index 0000000000000000000000000000000000000000..655ce30356e19f44d86ab9c9f2bb2b6165a2ac81 --- /dev/null +++ b/DDCore/include/DD4hep/AlignmentData.h @@ -0,0 +1,318 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_ALIGMENTS_ALIGNMENTDATA_H +#define DD4HEP_ALIGMENTS_ALIGNMENTDATA_H + +// Framework include files +#include "DD4hep/NamedObject.h" +#include "DD4hep/Detector.h" +#include "DD4hep/Volumes.h" + +// ROOT include files +#include "TGeoMatrix.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the alignment part of the AIDA detector description toolkit + namespace Alignments { + + // The DetElement is a central object. We alias it here. + using Geometry::DetElement; + using Geometry::LCDD; + + // Forward declarations + class Alignment; + + /// Class describing an condition to re-adjust an alignment + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class Delta { + public: + typedef Position Pivot; + Pivot pivot; + Position translation; + RotationZYX rotation; + /// Default constructor + Delta(); + /// Copy constructor + Delta(const Delta& c); + /// Default destructor + ~Delta(); + /// Assignment operator + Delta& operator=(const Delta& c); + /// Reset information to identity + void clear(); + }; + + /// Derived condition data-object definition + /** + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class AlignmentData { + public: + + /// Forward definition of the geometry placement + typedef Geometry::PlacedVolume PlacedVolume; + /// Forward definition of the nodelist leading to the world + typedef std::vector<PlacedVolume> NodeList; + /// Forward definition of the alignment delta data + typedef Alignments::Delta Delta; + /// Forward declaration of the utility bit mask + typedef unsigned int BitMask; + /// Forward declaration of the utility mask manipulator + typedef ReferenceBitMask<BitMask> MaskManipulator; + + + enum AlignmentFlags { + HAVE_NONE = 0, + HAVE_WORLD_TRAFO = 1<<0, + HAVE_PARENT_TRAFO = 1<<1, + HAVE_OTHER = 1<<31 + }; + enum DataType { + IDEAL = 1<<10, + SURVEY = 1<<11, + TIME_STAMPED = 1<<12 + }; + + /// Alignment changes + Delta delta; + /// Intermediate buffer to store the transformation to the world coordination system + mutable TGeoHMatrix worldTrafo; + /// Intermediate buffer to store the transformation to the parent detector element + mutable TGeoHMatrix detectorTrafo; + /// The list of TGeoNodes (physical placements) + NodeList nodes; + /// Transformation from volume to the world + Transform3D trToWorld; + /// Reference to the next hosting detector element + DetElement detector; + /// The subdetector placement corresponding to the actual detector element's volume + PlacedVolume placement; + /// Flag to remember internally calculated quatities + mutable BitMask flag; + /// Magic word to verify object if necessary + unsigned int magic; + + public: + /// Standard constructor + AlignmentData(); + /// Default destructor + virtual ~AlignmentData(); + /// Data accessor for decorator + inline AlignmentData& alignmentData() { return *this; } + + /// Access the ideal/nominal alignment/placement matrix + Alignment nominal() const; + /// Create cached matrix to transform to world coordinates + const TGeoHMatrix& worldTransformation() const + { return worldTrafo; } + /// Access the alignment/placement matrix with respect to the world + const TGeoHMatrix& detectorTransformation() const + { return detectorTrafo; } + /// Access the currently applied alignment/placement matrix + const Transform3D& localToWorld() const + { return trToWorld; } + + /** Aliases for the transformation from local coordinates to the world system */ + /// Transformation from local coordinates of the placed volume to the world system + void localToWorld(const Position& local, Position& global) const; + /// Transformation from local coordinates of the placed volume to the world system + void localToWorld(const Double_t local[3], Double_t global[3]) const; + /// Transformation from local coordinates of the placed volume to the world system + Position localToWorld(const Position& local) const; + /// Transformation from local coordinates of the placed volume to the world system + Position localToWorld(const Double_t local[3]) const + { return localToWorld(Position(local[0],local[1],local[2])); } + + /** Aliases for the transformation from world coordinates to the local volume */ + /// Transformation from world coordinates of the local placed volume coordinates + void worldToLocal(const Position& global, Position& local) const; + /// Transformation from world coordinates of the local placed volume coordinates + void worldToLocal(const Double_t global[3], Double_t local[3]) const; + /// Transformation from local coordinates of the placed volume to the world system + Position worldToLocal(const Position& global) const; + /// Transformation from local coordinates of the placed volume to the world system + Position worldToLocal(const Double_t global[3]) const + { return worldToLocal(Position(global[0],global[1],global[2])); } + + /** Aliases for the transformation from local coordinates to the next DetElement system */ + /// Transformation from local coordinates of the placed volume to the detector system + void localToDetector(const Position& local, Position& detector) const; + /// Transformation from local coordinates of the placed volume to the detector system + void localToDetector(const Double_t local[3], Double_t detector[3]) const; + /// Transformation from local coordinates of the placed volume to the world system + Position localToDetector(const Position& local) const; + /// Transformation from local coordinates of the placed volume to the world system + Position localToDetector(const Double_t local[3]) const + { return localToDetector(Position(local[0],local[1],local[2])); } + + /** Aliases for the transformation from the next DetElement to local coordinates */ + /// Transformation from detector element coordinates to the local placed volume coordinates + void detectorToLocal(const Position& detector, Position& local) const; + /// Transformation from detector element coordinates to the local placed volume coordinates + void detectorToLocal(const Double_t detector[3], Double_t local[3]) const; + /// Transformation from detector element coordinates to the local placed volume coordinates + Position detectorToLocal(const Position& detector) const; + /// Transformation from detector element coordinates to the local placed volume coordinates + Position detectorToLocal(const Double_t det[3]) const + { return detectorToLocal(Position(det[0],det[1],det[2])); } + }; + + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + template <typename T> class AlignmentDecorator : public T { + public: + /// Forward definition of the geometry placement + typedef AlignmentData::PlacedVolume PlacedVolume; + /// Forward definition of the nodelist leading to the world + typedef AlignmentData::NodeList NodeList; + /// Forward definition of the alignment delta data + typedef AlignmentData::Delta Delta; + + /// Default constructor + AlignmentDecorator(); + /// Copy constructor + AlignmentDecorator(const AlignmentDecorator& c); + /// Special constructors + template <typename Q> AlignmentDecorator(Q q) : T(q) {} + /// Default destructor + ~AlignmentDecorator() { } + + /// Data accessor + const AlignmentData& data() const + { return T::alignmentData(); } + /// Access to the DetElement node + DetElement detector() const + { return data().detector; } + /// Access the placement of this node + PlacedVolume placement() const + { return data().placement; } + /// Access the placement of the DetElement node + PlacedVolume detectorPlacement() const + { return data().detector.placement(); } + + /// Access the alignment/placement matrix with respect to the world + const Transform3D& localToWorld() const + { return data().trToWorld; } + /// Create cached matrix to transform to world coordinates + const TGeoHMatrix& worldTransformation() const + { return data().worldTransformation(); } + /// Create cached matrix to transform to detector coordinates + const TGeoHMatrix& detectorTransformation() const + { return data().detectorTransformation(); } + + /// Transformation from local coordinates of the placed volume to the world system + void localToWorld(const Position& local, Position& global) const + { return data().localToWorld(local, global); } + /// Transformation from local coordinates of the placed volume to the world system + void localToWorld(const Double_t local[3], Double_t global[3]) const + { return data().localToWorld(local, global); } + + /// Transformation from local coordinates of the placed volume to the detector system + void localToDetector(const Position& local, Position& det) const + { return data().localToDetector(local, det); } + /// Transformation from local coordinates of the placed volume to the detector system + void localToDetector(const Double_t local[3], Double_t det[3]) const + { return data().localToDetector(local, det); } + + /// Transformation from world coordinates of the local placed volume coordinates + void worldToLocal(const Position& global, Position& local) const + { return data().worldToLocal(global, local); } + /// Transformation from world coordinates of the local placed volume coordinates + void worldToLocal(const Double_t global[3], Double_t local[3]) const + { return data().worldToLocal(global, local); } + + /// Transformation from world coordinates of the local placed volume coordinates + void detectorToLocal(const Position& det, Position& local) const + { return data().detectorToLocal(det, local); } + /// Transformation from world coordinates of the local placed volume coordinates + void detectorToLocal(const Double_t det[3], Double_t local[3]) const + { return data().detectorToLocal(det, local); } + + /// Access the currently applied alignment/placement matrix (mother to daughter) + const Alignment& nominal() const + { return data().detector.ideal(); } + /// Access the currently applied correction matrix (delta) (mother to daughter) + const Delta& delta() const + { return data().delta; } + + /// Set the delta alignment information + void setDelta(const Delta& del) + { data().delta = del; } + /// Set the delta alignment if only a single translation + void setDelta(const Position& translation) + { data().delta.translation = translation; } + /// Set the delta alignment if only a single rotation + void setDelta(const RotationZYX& rotation) + { data().delta.rotation = rotation; } + /// Set the delta alignment as a composite of a translation and a rotation + void setDelta(const Position& translation, RotationZYX& rotation) { + AlignmentData& d = data(); + d.delta.rotation = rotation; + d.delta.translation = translation; + } + /// Set the delta alignment if only a single rotation around a pivot point + void setDeltaPivot(const Position& pivot, const RotationZYX& rotation) { + AlignmentData& d = data(); + d.delta.pivot = pivot; + d.delta.rotation = rotation; + } + /// Set the delta alignment if a translation and a rotation around pivot + void setDeltaPivot(const Position& translation, const Position& pivot, const RotationZYX& rotation) { + AlignmentData& d = data(); + d.delta.pivot = pivot; + d.delta.rotation = rotation; + d.delta.translation = translation; + } + }; + + /// Default constructor + template <typename T> inline + AlignmentDecorator<T>::AlignmentDecorator() : T() {} + + /// Copy constructor + template <typename T> inline + AlignmentDecorator<T>::AlignmentDecorator(const AlignmentDecorator& c) : T(c) {} + + + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class NamedAlignmentObject : public NamedObject, public AlignmentData { + public: + /// Default constructor + NamedAlignmentObject(const std::string& nam, const std::string& tit="") + : NamedObject(nam,tit), AlignmentData() {} + /// Default destructor + virtual ~NamedAlignmentObject(); + }; + + } /* End namespace Aligments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_ALIGMENTS_ALIGNMENTDATA_H */ diff --git a/DDCore/include/DD4hep/AlignmentTools.h b/DDCore/include/DD4hep/AlignmentTools.h new file mode 100644 index 0000000000000000000000000000000000000000..e5e4eebebe8b2bd66af19c0af572238be921d64a --- /dev/null +++ b/DDCore/include/DD4hep/AlignmentTools.h @@ -0,0 +1,54 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_ALIGMENTS_ALIGNMENTTOOLS_H +#define DD4HEP_ALIGMENTS_ALIGNMENTTOOLS_H + +// Framework include files +#include "DD4hep/Alignments.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the alignment part of the AIDA detector description toolkit + namespace Alignments { + + namespace AlignmentTools { + + /// Compute the ideal/nominal to-world transformation from the detector element placement + /** + * Note: Detector information of the alignment data is filled by the caller! + */ + void computeIdeal(Alignment alignment); + + /// Compute the ideal/nominal to-world transformation from the detector element placement + /** + * Note: Detector information of the alignment data is filled by the caller! + */ + void computeIdeal(Alignment alignment, const Alignment::NodeList& node_list); + + /// Compute the survey to-world transformation. + /** Compute the survey to-world transformation from + * the detector element placement with respect to + * the survey constants + * + * Note: Detector information of the alignment data is filled by the caller! + */ + void computeSurvey(Alignment alignment); + + + } + + } /* End namespace Aligments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_ALIGMENTS_ALIGNMENTTOOLS_H */ diff --git a/DDCore/include/DD4hep/Alignments.h b/DDCore/include/DD4hep/Alignments.h new file mode 100644 index 0000000000000000000000000000000000000000..efe10d2c4926dcba2f865c4c8e9e017c59b40b21 --- /dev/null +++ b/DDCore/include/DD4hep/Alignments.h @@ -0,0 +1,168 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_ALIGMENTS_ALIGNMENTS_H +#define DD4HEP_ALIGMENTS_ALIGNMENTS_H + +// Framework include files +#include "DD4hep/Volumes.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + class IOV; + + /// Namespace for the alignment part of the AIDA detector description toolkit + namespace Alignments { + + using Geometry::LCDD; + using Geometry::DetElement; + using Geometry::PlacedVolume; + + /// Alignments internal namespace + namespace Interna { + /// Forward declarations + class AlignmentContainer; + class AlignmentObject; + } + class AlignmentsManagerObject; + class AlignmentsLoader; + class AlignmentData; + class Alignment; + class UserPool; + class Delta; + + /// Main handle class to hold a TGeo alignment object of type TGeoPhysicalNode + /** + * See the ROOT documentation about the TGeoPhysicalNode for further details: + * @see http://root.cern.ch/root/html/TGeoPhysicalNode.html + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_GEOMETRY + * \ingroup DD4HEP_ALIGN + */ + class Alignment : public Handle<AlignmentData> { + public: + /// Forward definition of the base data object containing alignment data + typedef AlignmentData Object; + /// Forward definition of the geometry placement + typedef Geometry::PlacedVolume PlacedVolume; + /// Forward definition of the nodelist leading to the world + typedef std::vector<PlacedVolume> NodeList; + /// Forward definition of the alignment delta data + typedef Alignments::Delta Delta; + /// Forward definition of the key type + typedef unsigned int key_type; + /// Forward definition of the iov type + typedef IOV iov_type; + + public: + /// Default constructor + Alignment(); + /// Default constructor + Alignment(Object* p); + /// Copy constructor + Alignment(const Alignment& c); + /// Constructor to be used when reading the already parsed object + template <typename Q> Alignment(const Handle<Q>& e) : Handle<Object>(e) {} + /// Object constructor for pure alignment objects + Alignment(const std::string& name); + + /// Hash code generation from input string + static key_type hashCode(const char* value); + /// Hash code generation from input string + static key_type hashCode(const std::string& value); + + /// Assignment operator + Alignment& operator=(const Alignment& c); + /// Data accessor for the use of decorators + AlignmentData& alignmentData() { return (*access()); } + /// Data accessor for the use of decorators + const AlignmentData& alignmentData() const { return (*access()); } + }; + + /// Default constructor + inline Alignment::Alignment(Object* p) : Handle<Object>(p) {} + + /// Copy constructor + inline Alignment::Alignment(const Alignment& c) : Handle<Object>(c.ptr()) {} + + /// Assignment operator + inline Alignment& Alignment::operator=(const Alignment& c) { + if ( &c != this ) { + m_element = c.ptr(); + } + return *this; + } + + /// Hash code generation from input string + inline Alignment::key_type Alignment::hashCode(const char* value) + { return hash32(value); } + + /// Hash code generation from input string + inline Alignment::key_type Alignment::hashCode(const std::string& value) + { return hash32(value); } + + /// Container class for alignment handles aggregated by a detector element + /** + * Note: The alignments container is owner by the detector element + * On deletion the detector element will destroy the container + * and all associated entries. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_ALIGNMENTS + */ + class Container : public Handle<Interna::AlignmentContainer> { + public: + /// Standard object type + typedef Interna::AlignmentContainer Object; + /// Forward definition of the key type + typedef Alignment::key_type key_type; + /// Forward definition of the iov type + typedef Alignment::iov_type iov_type; + + public: + /// Default constructor + Container(); + + /// Constructor to be used when reading the already parsed object + template <typename Q> Container(const Container& c) : Handle<Object>(c) {} + + /// Constructor to be used when reading the already parsed object + template <typename Q> Container(const Handle<Q>& e) : Handle<Object>(e) {} + + /// Access the number of conditons keys available for this detector element + size_t numKeys() const; + + /// Access to alignment objects by key and IOV. + Alignment get(const std::string& alignment_key, const iov_type& iov); + + /// Access to alignment objects directly by their hash key. + Alignment get(key_type alignment_key, const iov_type& iov); + + /// Access to alignment objects. Only alignments in the pool are accessed. + Alignment get(const std::string& alignment_key, const UserPool& iov); + + /// Access to alignment objects. Only alignments in the pool are accessed. + Alignment get(key_type alignment_key, const UserPool& iov); + }; + + /// Default constructor + inline Container::Container() : Handle<Object>() { + } + + } /* End namespace Aligments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_ALIGMENTS_ALIGNMENTS_H */ diff --git a/DDCore/include/DD4hep/ConditionDerived.h b/DDCore/include/DD4hep/ConditionDerived.h index 95b05fa484e1a229eabf381988a850425c618ece..470c88ccb27c70a9faf7403c00759cb260845276 100644 --- a/DDCore/include/DD4hep/ConditionDerived.h +++ b/DDCore/include/DD4hep/ConditionDerived.h @@ -63,51 +63,56 @@ namespace DD4hep { */ class ConditionUpdateCall { public: + /** + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ struct Context { - const ConditionResolver& resolver; - const ConditionDependency& dependency; - Condition::iov_type* iov; + const ConditionResolver& resolver; + const ConditionDependency& dependency; + Condition::iov_type* iov; - /// Initializing constructor + /// Initializing constructor Context(const ConditionResolver& r, const ConditionDependency& d, Condition::iov_type& iov); - /// Access to dependency keys - const ConditionKey& key(size_t which) const; - /// Access to condition object by dependency index - Condition condition(size_t which) const; - /// Access to condition object by dependency key - Condition condition(const ConditionKey& key_value) const; - /// Access of other conditions data from the resolver - template<typename T> T& get(const ConditionKey& key_value) { - Condition cond = resolver.get(key_value); - if ( cond.isValid() ) { - T& data = cond.get<T>(); /// Bind data to wanted type - /// Update result IOV according by and'ing the new iov structure - iov->iov_intersection(cond.iov()); - return data; - } - throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing item:"+key_value.name); - } - /// Access of other conditions data from the resolver - template<typename T> const T& get(const ConditionKey& key_value) const { - Condition cond = resolver.get(key_value); - if ( cond.isValid() ) { - const T& data = cond.get<T>(); /// Bind data to wanted type - /// Update result IOV according by and'ing the new iov structure - iov->iov_intersection(cond.iov()); - return data; - } - throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing item:"+key_value.name); - } - /// Access of other conditions data from the resolver - template<typename T> T& get(size_t key_id) { - const ConditionKey& key_value = this->key(key_id); - return this->get<T>(key_value); - } - /// Access of other conditions data from the resolver - template<typename T> const T& get(size_t key_id) const { - const ConditionKey& key_value = this->key(key_id); - return this->get<T>(key_value); - } + /// Access to dependency keys + const ConditionKey& key(size_t which) const; + /// Access to condition object by dependency index + Condition condition(size_t which) const; + /// Access to condition object by dependency key + Condition condition(const ConditionKey& key_value) const; + /// Access of other conditions data from the resolver + template<typename T> T& get(const ConditionKey& key_value) { + Condition cond = resolver.get(key_value); + if ( cond.isValid() ) { + T& data = cond.get<T>(); /// Bind data to wanted type + /// Update result IOV according by and'ing the new iov structure + iov->iov_intersection(cond.iov()); + return data; + } + throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing item:"+key_value.name); + } + /// Access of other conditions data from the resolver + template<typename T> const T& get(const ConditionKey& key_value) const { + Condition cond = resolver.get(key_value); + if ( cond.isValid() ) { + const T& data = cond.get<T>(); /// Bind data to wanted type + /// Update result IOV according by and'ing the new iov structure + iov->iov_intersection(cond.iov()); + return data; + } + throw std::runtime_error("ConditionUpdateCall: Failed to access non-existing item:"+key_value.name); + } + /// Access of other conditions data from the resolver + template<typename T> T& get(size_t key_id) { + const ConditionKey& key_value = this->key(key_id); + return this->get<T>(key_value); + } + /// Access of other conditions data from the resolver + template<typename T> const T& get(size_t key_id) const { + const ConditionKey& key_value = this->key(key_id); + return this->get<T>(key_value); + } }; /// Standard destructor virtual ~ConditionUpdateCall(); @@ -177,8 +182,8 @@ namespace DD4hep { /// Initializing constructor inline ConditionUpdateCall::Context::Context(const ConditionResolver& resolv, - const ConditionDependency& dep, - Condition::iov_type& iov_ref) + const ConditionDependency& dep, + Condition::iov_type& iov_ref) : resolver(resolv), dependency(dep), iov(&iov_ref) { } @@ -201,6 +206,6 @@ namespace DD4hep { return this->condition(key_value); } - } /* End namespace Conditions */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_GEOMETRY_CONDITIONDERIVED_H */ + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_GEOMETRY_CONDITIONDERIVED_H */ diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index 7ee5e617c5714852a612203ad599ae23ae366c5c..3ffe85313621b3f203b8154018088526d259d131 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -11,11 +11,13 @@ // Author : M.Frank // //========================================================================== -#ifndef DD4HEP_GEOMETRY_CONDITION_H -#define DD4HEP_GEOMETRY_CONDITION_H +#ifndef DD4HEP_CONDITIONS_CONDITIONS_H +#define DD4HEP_CONDITIONS_CONDITIONS_H // Framework include files +#include "DD4hep/OpaqueData.h" #include "DD4hep/Handle.h" +#include "DD4hep/IOV.h" // C/C++ include files #include <vector> @@ -45,260 +47,13 @@ namespace DD4hep { class ConditionsManager; class ConditionsLoader; class UserPool; - class IOVType; - class IOV; - /// Conditions intrnal namespace + /// Conditions internal namespace namespace Interna { class ConditionContainer; class ConditionObject; } - class IOVType { - public: - enum { UNKNOWN_IOV = ~0x0 } _IOVTypes; - - unsigned int type; - std::string name; - IOVType() : type(UNKNOWN_IOV), name() {} - ~IOVType() {} - std::string str() const; - }; - - /// Class describing the interval of validty - /** - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class IOV { - friend class Condition; - private: - /// Initializing constructor: Does not set reference to IOVType ! - explicit IOV(); - public: - /// Key definition - typedef long Key_first_type; - typedef long Key_second_type; - typedef std::pair<Key_first_type,Key_second_type> Key; - - const IOVType* iovType; - Key keyData; - int optData; - /// IOV buffer type: Must be a bitmap! - unsigned int type; - - /// Initializing constructor - explicit IOV(const IOVType* typ); - /// Specialized copy constructor - explicit IOV(const IOVType* typ, const Key& key); - /// Copy constructor - IOV(const IOV& copy); - - /// Standard Destructor - ~IOV(); - /// Move the data content: 'from' will be reset to NULL - void move(IOV& from); - /// Create string representation of the IOV - std::string str() const; - /// Check if the IOV corresponds to a range - bool has_range() const { return keyData.first != keyData.second; } - /// Check if the IOV corresponds to a range - bool is_discrete() const { return keyData.first == keyData.second; } - /// Get the local key of the IOV - Key key() const { return keyData; } - - /// Set discrete IOV value - void set(const Key& value); - /// Set discrete IOV value - void set(Key_first_type value); - /// Set range IOV value - void set(Key_first_type val_1, Key_second_type val_2); - /// Set keys to unphysical values (LONG_MAX, LONG_MIN) - IOV& reset(); - /// Invert the key values (first=second and second=first) - IOV& invert(); - /// Set the intersection of this IOV with the argument IOV - void iov_intersection(const IOV& comparator); - /// Set the intersection of this IOV with the argument IOV - void iov_intersection(const IOV::Key& comparator); - /// Set the union of this IOV with the argument IOV - void iov_union(const IOV& comparator); - /// Set the union of this IOV with the argument IOV - void iov_union(const IOV::Key& comparator); - - /// Check for validity containment - /** Check if the caller 'iov' is of the same type and the range - * is fully conained by the caller. - */ - bool contains(const IOV& iov) const; - /// Check if 2 IOV objects are of the same type - static bool same_type(const IOV& iov, const IOV& test) { - unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type; - unsigned int typ2 = test.iovType ? test.iovType->type : test.type; - return typ1 == typ2; - } - /// Check if IOV 'test' is fully contained in IOV 'key' - static bool key_is_contained(const Key& key, const Key& test) - { return key.first >= test.first && key.second <= test.second; } - /// Same as above, but reverse logic. Gives sometimes more understandable logic. - static bool key_contains_range(const Key& key, const Key& test) - { return key.first <= test.first && key.second >= test.second; } - /// Check if IOV 'test' has an overlap on the lower interval edge with IOV 'key' - static bool key_overlaps_lower_end(const Key& key, const Key& test) - { return key.first <= test.second && key.first >= test.first; } - /// Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key' - static bool key_overlaps_higher_end(const Key& key, const Key& test) - { return key.second >= test.first && key.second <= test.second; } - /// Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key' - static bool key_partially_contained(const Key& key, const Key& test) - { - return - (test.first <= key.first && key.second >= test.second) || // test fully contained in key - (test.first <= key.first && key.first <= test.second) || // test overlaps left edge of key - (test.first <= key.second && key.second <= test.second); // test overlaps right edge of key - } - /// Check if IOV 'test' is of same type and is fully contained in iov - static bool full_match(const IOV& iov, const IOV& test) - { return same_type(iov,test) && key_is_contained(iov.keyData,test.keyData); } - /// Check if IOV 'test' is of same type and is at least partially contained in iov - static bool partial_match(const IOV& iov, const IOV& test) - { return same_type(iov,test) && key_partially_contained(iov.keyData,test.keyData); } - }; - - - /// Class describing an opaque conditions data block - /** - * Access methods are templated. Once the access is fixed - * on the first call, the data type may not be changed anymore. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class Block { - /// Access only through the conditions class! - friend class Condition; - - private: - protected: - /// Standard initializing constructor - Block(); - /// Standard Destructor - virtual ~Block(); - - public: - /// Data type - const BasicGrammar* grammar; - protected: - /// Pointer to object data - void* pointer; - - public: - /// Create data block from string representation - bool fromString(const std::string& rep); - /// Create string representation of the data block - std::string str() const; - /// Access type id of the condition - const std::type_info& typeInfo() const; - /// Access type name of the condition data block - const std::string& dataType() const; - /// Check if object is already bound.... - bool is_bound() const { return 0 != pointer; } - /// Generic getter. Specify the exact type, not a polymorph type - template <typename T> inline T& get(); - /// Generic getter (const version). Specify the exact type, not a polymorph type - template <typename T> inline const T& get() const; - }; - - /// Kaykey definition to optimize the access to conditions entities - /** - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class ConditionKey { - public: - typedef unsigned int key_type; - /// String representation of the key object - std::string name; - /// Hashed key representation - key_type hash; - - public: - /// Default constructor - ConditionKey() : hash(0) {} - /// Constructor from string - ConditionKey(const std::string& compare); - /// Constructor from string - ConditionKey(const std::string& s, key_type h) : name(s), hash(h) {} - /// Copy constructor - ConditionKey(const ConditionKey& c) : name(c.name), hash(c.hash) {} - - /// Hash code generation from input string - static key_type hashCode(const char* value); - /// Hash code generation from input string - static key_type hashCode(const std::string& value); - - /// Assignment operator from the string representation - ConditionKey& operator=(const std::string& value); - /// Assignment operator from object copy - ConditionKey& operator=(const ConditionKey& key); - /// Equality operator using key object - bool operator==(const ConditionKey& compare) const; - /// Equality operator using hash value - bool operator==(const key_type compare) const; - /// Equality operator using the string representation - bool operator==(const std::string& compare) const; - - /// Operator less (for map insertions) using key object - bool operator<(const ConditionKey& compare) const; - /// Operator less (for map insertions) using hash value - bool operator<(const key_type compare) const; - /// Operator less (for map insertions) using the string representation - bool operator<(const std::string& compare) const; - - /// Automatic conversion to the string representation of the key object - operator const std::string& () const { return name; } - /// Automatic conversion to the hashed representation of the key object - operator key_type () const { return hash; } - }; - - /// Hash code generation from input string - inline ConditionKey::key_type ConditionKey::hashCode(const char* value) - { return hash32(value); } - - /// Hash code generation from input string - inline ConditionKey::key_type ConditionKey::hashCode(const std::string& value) - { return hash32(value); } - - /// Assignment operator from object copy - inline ConditionKey& ConditionKey::operator=(const ConditionKey& key) { - if ( this != &key ) { - hash = key.hash; - name = key.name; - } - return *this; - } - - /// Equality operator using key object - inline bool ConditionKey::operator==(const ConditionKey& compare) const - { return hash == compare.hash; } - - /// Equality operator using hash value - inline bool ConditionKey::operator==(const key_type compare) const - { return hash == compare; } - - /// Operator less (for map insertions) using key object - inline bool ConditionKey::operator<(const ConditionKey& compare) const - { return hash < compare.hash; } - - /// Operator less (for map insertions) using hash value - inline bool ConditionKey::operator<(const key_type compare) const - { return hash < compare; } - - /// Main condition object handle. /** * This objects allows access to the data block and @@ -315,25 +70,30 @@ namespace DD4hep { */ class Condition: public Handle<Interna::ConditionObject> { public: - typedef Interna::ConditionObject Object; - typedef ConditionKey::key_type key_type; - typedef IOV iov_type; + /// Standard object type + typedef Interna::ConditionObject Object; + /// Forward definition of the key type + typedef unsigned int key_type; + /// Forward definition of the iov type + typedef IOV iov_type; + public: enum StringFlags { - WITH_IOV = 1<<0, - WITH_ADDRESS = 1<<1, - WITH_TYPE = 1<<2, - WITH_COMMENT = 1<<4, - WITH_DATATYPE = 1<<5, - WITH_DATA = 1<<6, - NO_NAME = 1<<20, - NONE + WITH_IOV = 1<<0, + WITH_ADDRESS = 1<<1, + WITH_TYPE = 1<<2, + WITH_COMMENT = 1<<4, + WITH_DATATYPE = 1<<5, + WITH_DATA = 1<<6, + NO_NAME = 1<<20, + NONE }; enum ConditionState { - INACTIVE = 0, - ACTIVE = 1<<0, - CHECKED = 1<<2, - DERIVED = 1<<3 + INACTIVE = 0, + ACTIVE = 1<<0, + CHECKED = 1<<2, + DERIVED = 1<<3, + USER_FLAGS_FIRST = 1<<10 }; /// Abstract base for processing callbacks @@ -344,7 +104,7 @@ namespace DD4hep { */ class Processor { public: - virtual int operator()(Condition c) = 0; + virtual int operator()(Condition c) = 0; }; /// Default constructor @@ -369,7 +129,7 @@ namespace DD4hep { /// Access the data type int dataType() const; /// Access the IOV block - Block& block() const; + OpaqueData& data() const; /** Interval of validity */ /// Access the IOV type @@ -388,8 +148,6 @@ namespace DD4hep { const std::string& value() const; /// Access the address string [e.g. database identifier] const std::string& address() const; - /// Access the key of the condition - ConditionKey key() const; /** Conditions meta-data */ /// Access to the type information @@ -440,8 +198,10 @@ namespace DD4hep { public: /// Standard object type typedef Interna::ConditionContainer Object; - typedef Condition::key_type key_type; - typedef Condition::iov_type iov_type; + /// Forward definition of the key type + typedef Condition::key_type key_type; + /// Forward definition of the iov type + typedef Condition::iov_type iov_type; public: /// Default constructor @@ -473,10 +233,102 @@ namespace DD4hep { inline Container::Container() : Handle<Object>() { } + + /// Key definition to optimize ans simplyfy the access to conditions entities + /** + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionKey { + public: + /// Forward definition of the key type + typedef Condition::key_type key_type; + + /// String representation of the key object + std::string name; + /// Hashed key representation + key_type hash; + + public: + /// Default constructor + ConditionKey() : hash(0) {} + /// Constructor from string + ConditionKey(const std::string& compare); + /// Constructor from string + ConditionKey(const std::string& s, key_type h) : name(s), hash(h) {} + /// Copy constructor + ConditionKey(const ConditionKey& c) : name(c.name), hash(c.hash) {} + + /// Hash code generation from input string + static key_type hashCode(const char* value); + /// Hash code generation from input string + static key_type hashCode(const std::string& value); + + /// Assignment operator from the string representation + ConditionKey& operator=(const std::string& value); + /// Assignment operator from object copy + ConditionKey& operator=(const ConditionKey& key); + /// Equality operator using key object + bool operator==(const ConditionKey& compare) const; + /// Equality operator using hash value + bool operator==(const key_type compare) const; + /// Equality operator using the string representation + bool operator==(const std::string& compare) const; + + /// Operator less (for map insertions) using key object + bool operator<(const ConditionKey& compare) const; + /// Operator less (for map insertions) using hash value + bool operator<(const key_type compare) const; + /// Operator less (for map insertions) using the string representation + bool operator<(const std::string& compare) const; + + /// Automatic conversion to the string representation of the key object + operator const std::string& () const { return name; } + /// Automatic conversion to the hashed representation of the key object + operator key_type () const { return hash; } + }; + + /// Hash code generation from input string + inline ConditionKey::key_type ConditionKey::hashCode(const char* value) + { return hash32(value); } + + /// Hash code generation from input string + inline ConditionKey::key_type ConditionKey::hashCode(const std::string& value) + { return hash32(value); } + + /// Assignment operator from object copy + inline ConditionKey& ConditionKey::operator=(const ConditionKey& key) { + if ( this != &key ) { + hash = key.hash; + name = key.name; + } + return *this; + } + + /// Equality operator using key object + inline bool ConditionKey::operator==(const ConditionKey& compare) const + { return hash == compare.hash; } + + /// Equality operator using hash value + inline bool ConditionKey::operator==(const key_type compare) const + { return hash == compare; } + + /// Operator less (for map insertions) using key object + inline bool ConditionKey::operator<(const ConditionKey& compare) const + { return hash < compare.hash; } + + /// Operator less (for map insertions) using hash value + inline bool ConditionKey::operator<(const key_type compare) const + { return hash < compare; } + + /// Access the key of the condition + ConditionKey make_key(Condition c); + // Utility type definitions - typedef std::vector<Condition> RangeConditions; + typedef std::vector<Condition> RangeConditions; typedef std::pair<RangeConditions,bool> RangeStatus; } /* End namespace Conditions */ } /* End namespace DD4hep */ -#endif /* DD4HEP_GEOMETRY_CONDITION_H */ +#endif /* DD4HEP_CONDITIONS_CONDITIONS_H */ diff --git a/DDCore/include/DD4hep/ConditionsData.h b/DDCore/include/DD4hep/ConditionsData.h index b06a0a688c10b5fc60153a6ad63c162797f71f9d..9d626f79599d324c69dd54258cd7928d8e67dad7 100644 --- a/DDCore/include/DD4hep/ConditionsData.h +++ b/DDCore/include/DD4hep/ConditionsData.h @@ -41,31 +41,6 @@ namespace DD4hep { virtual void release() = 0; }; - /// Class describing an condition to re-adjust an alignment - /** - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class AlignmentDelta { - public: - typedef Geometry::Position Position; - typedef Geometry::Position Pivot; - typedef Geometry::RotationZYX Rotation; - Pivot pivot; - Position position; - Rotation rotation; - /// Default constructor - AlignmentDelta(); - /// Copy constructor - AlignmentDelta(const AlignmentDelta& c); - /// Default destructor - ~AlignmentDelta(); - /// Assignment operator - AlignmentDelta& operator=(const AlignmentDelta& c); - }; - /// Conditions data block. Internally maps other objects to abstract data blocks /** * \author M.Frank @@ -77,10 +52,10 @@ namespace DD4hep { private: public: enum { - REGULAR = 0, - ALIGNMENT = 6 + REGULAR = 0, + ALIGNMENT = 6 }; - typedef std::map<std::string, BlockData> Params; + typedef std::map<std::string, OpaqueDataBlock> Params; ClientData* clientData; Params params; int classID; @@ -94,43 +69,43 @@ namespace DD4hep { AbstractMap& operator=(const AbstractMap& c); /// Simplify access to client data template <typename T> T* option() const { - return static_cast<T*>(clientData); + return static_cast<T*>(clientData); } /// Simplify access to first item of the parameter list (const access) const Params::value_type& firstParam() const { - Params::const_iterator i=params.begin(); - if ( i != params.end() ) return (*i); - throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter"); + Params::const_iterator i=params.begin(); + if ( i != params.end() ) return (*i); + throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter"); } /// Simplify access to first item of the parameter list Params::value_type& firstParam() { - Params::iterator i=params.begin(); - if ( i != params.end() ) return (*i); - throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter"); + Params::iterator i=params.begin(); + if ( i != params.end() ) return (*i); + throw std::runtime_error("AbstractMap: Failed to access non-existing first parameter"); } /// Simplify access to first item of the parameter list (const access) template <typename T> const T& first() const { - Params::const_iterator i=params.begin(); - if ( i != params.end() ) return (*i).second.get<T>(); - throw std::runtime_error("AbstractMap: Failed to access non-existing first item"); + Params::const_iterator i=params.begin(); + if ( i != params.end() ) return (*i).second.get<T>(); + throw std::runtime_error("AbstractMap: Failed to access non-existing first item"); } /// Simplify access to first item of the parameter list template <typename T> T& first() { - Params::iterator i=params.begin(); - if ( i != params.end() ) return (*i).second.get<T>(); - throw std::runtime_error("AbstractMap: Failed to access non-existing first item"); + Params::iterator i=params.begin(); + if ( i != params.end() ) return (*i).second.get<T>(); + throw std::runtime_error("AbstractMap: Failed to access non-existing first item"); } /// Simplify access to mapped item of the parameter list (const access) template <typename T> const T& operator[](const std::string& item) const { - Params::const_iterator i=params.find(item); - if ( i != params.end() ) return (*i).second.get<T>(); - throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item); + Params::const_iterator i=params.find(item); + if ( i != params.end() ) return (*i).second.get<T>(); + throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item); } /// Simplify access to mapped item of the parameter list template <typename T> T& operator[](const std::string& item) { - Params::iterator i=params.find(item); - if ( i != params.end() ) return (*i).second.get<T>(); - throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item); + Params::iterator i=params.find(item); + if ( i != params.end() ) return (*i).second.get<T>(); + throw std::runtime_error("AbstractMap: Failed to access non-existing item:"+item); } }; diff --git a/DDCore/include/DD4hep/DetAlign.h b/DDCore/include/DD4hep/DetAlign.h new file mode 100644 index 0000000000000000000000000000000000000000..a07228023bebba8940c945570a9ecc9679066cfc --- /dev/null +++ b/DDCore/include/DD4hep/DetAlign.h @@ -0,0 +1,102 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_DETALIGNMENTS_H +#define DD4HEP_DETALIGNMENTS_H + +// Framework include files +#include "DD4hep/Detector.h" +#include "DD4hep/Alignments.h" + +// C/C++ include files + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Geometry { + // Forward declarations + class DetElementObject; + } /* End namespace Geometry */ + + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Alignments { + + /// Handle class describing the access to DetElement dependent alignments. + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_GEOMETRY + */ + class DetAlign: public Handle<Geometry::DetElementObject> { + public: + /// Internal object type + typedef Geometry::DetElementObject Object; + /// Definition of the base handle type + typedef Handle<Object> RefObject; + + public: + + /// Default constructor + DetAlign() : RefObject() { } + + /// Constructor to hold handled object + DetAlign(Object* object_ptr) : RefObject(object_ptr) { } + + /// Templated constructor for handle conversions + template <typename Q> DetAlign(const Handle<Q>& e) : RefObject(e) {} + + /// Constructor to copy handle + DetAlign(const DetAlign& e) : RefObject(e) { } + + /// Constructor to copy handle + DetAlign(const Geometry::DetElement& e) : RefObject(e) { } + +#ifdef __MAKECINT__ + /// Constructor to copy handle + DetAlign(const Ref_t& e) + : RefObject(e) { + } +#endif + /// Additional data accessor + Object& _data() const { + return object<Object>(); + } + /// Assignment operator + DetAlign& operator=(const DetAlign& e) { + m_element = e.m_element; + return *this; + } + /// Access to the constant nominal alignment information + Alignment nominal() const; + /// Access to the constant survey alignment information + Alignment survey() const; + /// Check if alignments are at all present + bool hasAlignments() const; + /// Access to the alignments information + Container alignments() const; + /// Access to alignment objects from a given pool + Alignment get(const std::string& key, const UserPool& pool); + /// Access to alignment objects from a given pool + Alignment get(Alignment::key_type key, const UserPool& pool); + /// Access to alignment objects. Only alignments in the pool are accessed. + Alignment get(const std::string& key, const Alignment::iov_type& iov); + /// Access to alignment objects. Only alignments in the pool are accessed. + Alignment get(Alignment::key_type key, const Alignment::iov_type& iov); + }; + + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DETALIGNMENTS_H */ diff --git a/DDCore/include/DD4hep/Detector.h b/DDCore/include/DD4hep/Detector.h index d03aa08a5769cccac957e25ee306454ed11c00d7..74cd9e29abd9a64112784a853804a51c84dc7622 100644 --- a/DDCore/include/DD4hep/Detector.h +++ b/DDCore/include/DD4hep/Detector.h @@ -21,7 +21,7 @@ #include "DD4hep/Objects.h" #include "DD4hep/Volumes.h" #include "DD4hep/Readout.h" -#include "DD4hep/Alignment.h" +#include "DD4hep/Alignments.h" #include "DD4hep/Segmentations.h" // C/C++ include files @@ -187,10 +187,11 @@ namespace DD4hep { class DetElement: public Handle<DetElementObject> { public: /// Internal object type - typedef DetElementObject Object; + typedef DetElementObject Object; /// Definition of the base handle type typedef Handle<DetElementObject> RefObject; - typedef DetElement Parent; + typedef DetElement Parent; + typedef Alignments::Alignment Alignment; /// Extensions copy constructor type typedef void* (*copy_t)(const void*, DetElement); @@ -370,40 +371,47 @@ namespace DD4hep { DetElement parent() const; /// Access to the world object. Only possible once the geometry is closed. DetElement world() const; - /// Check if this DetElement has Conditions attached + + /// Check if this DetElement has time dependent Conditions attached bool hasConditions() const; + /// Check if this DetElement has time dependent Alignments attached + bool hasAlignments() const; + + /// Access to the constant ideal (nominal) alignment information + Alignment nominal() const; + /// Access to the constant survey alignment information + Alignment survey() const; - /// Access to the actual alignment information - Alignment alignment() const; - /// Access to the survey alignment information - Alignment surveyAlignment() const; + // Deprecated functions to be removed soon: /// Set detector element for reference transformations. Will delete existing reference trafo. - DetElement& setReference(DetElement reference); + //DetElement& setReference(DetElement reference); /// Create cached matrix to transform to world coordinates const TGeoHMatrix& worldTransformation() const; /// Create cached matrix to transform to parent coordinates const TGeoHMatrix& parentTransformation() const; /// Create cached matrix to transform to reference coordinates - const TGeoHMatrix& referenceTransformation() const; + //const TGeoHMatrix& referenceTransformation() const; /// Transformation from local coordinates of the placed volume to the world system bool localToWorld(const Position& local, Position& global) const; /// Transformation from local coordinates of the placed volume to the parent system bool localToParent(const Position& local, Position& parent) const; /// Transformation from local coordinates of the placed volume to arbitrary parent system set as reference - bool localToReference(const Position& local, Position& reference) const; + //bool localToReference(const Position& local, Position& reference) const; /// Transformation from world coordinates of the local placed volume coordinates bool worldToLocal(const Position& global, Position& local) const; /// Transformation from world coordinates of the local placed volume coordinates bool parentToLocal(const Position& parent, Position& local) const; /// Transformation from world coordinates of the local placed volume coordinates - bool referenceToLocal(const Position& reference, Position& local) const; + //bool referenceToLocal(const Position& reference, Position& local) const; }; } /* End namespace Geometry */ } /* End namespace DD4hep */ +#include "DD4hep/AlignmentData.h" + #endif /* DD4HEP_DETECTOR_H */ diff --git a/DDCore/include/DD4hep/Dictionary.h b/DDCore/include/DD4hep/Dictionary.h index 6956a45e4e543e053a8922a15a4dc1e4c6985b85..b71153ac9acb6e15ed5591e1dbbd8b5f57293b5e 100644 --- a/DDCore/include/DD4hep/Dictionary.h +++ b/DDCore/include/DD4hep/Dictionary.h @@ -20,10 +20,12 @@ #define DD4HEP_GEOMETRY_DICTIONARY_H #include "XML/Evaluator.h" +#include "DD4hep/DetAlign.h" #include "DD4hep/DD4hepRootPersistency.h" #include "DD4hep/objects/ObjectsInterna.h" #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/objects/AlignmentsInterna.h" #include "DD4hep/objects/VolumeManagerInterna.h" #include "DD4hep/World.h" @@ -98,6 +100,11 @@ template class pair<DD4hep::Callback,unsigned long>; template class DD4hep::Handle<TNamed>; #pragma link C++ class DD4hep::Handle<TNamed>+; +#pragma link C++ class DD4hep::IOV+; +#pragma link C++ class DD4hep::IOVType+; +#pragma link C++ class DD4hep::OpaqueData+; +#pragma link C++ class DD4hep::OpaqueDataBlock+; + #pragma link C++ class DD4hep::Geometry::LCDD+; #pragma link C++ class DD4hep::Geometry::LCDDData+; #pragma link C++ class DD4hep::Geometry::LCDDData::ObjectHandleMap+; @@ -191,9 +198,23 @@ template class DD4hep::Handle<TNamed>; #pragma link C++ class vector<const DD4hep::Geometry::HitCollection*>+; #pragma link C++ class vector<DD4hep::Geometry::IDDescriptor>+; -#pragma link C++ class DD4hep::Geometry::Alignment+; +// Alignment stuff +#pragma link C++ class DD4hep::Alignments::Delta+; +#pragma link C++ class DD4hep::Alignments::Alignment+; +#pragma link C++ class DD4hep::Alignments::Container+; +#pragma link C++ class DD4hep::Alignments::AlignmentData+; + +#pragma link C++ class DD4hep::Alignments::DetAlign+; +#pragma link C++ class DD4hep::Alignments::AlignmentsLoader+; +#pragma link C++ class DD4hep::Alignments::Interna::AlignmentConditionObject+; +#pragma link C++ class DD4hep::Alignments::Interna::AlignmentContainer+; +#pragma link C++ class DD4hep::Alignments::GlobalAlignment+; +#pragma link C++ class DD4hep::Alignments::AlignmentDecorator<AlignmentData>+; +#pragma link C++ class DD4hep::Handle<DD4hep::Alignments::AlignmentData>+; #pragma link C++ class DD4hep::Handle<TGeoPhysicalNode>+; + + #pragma link C++ class DD4hep::Conditions::Condition+; #pragma link C++ class vector<DD4hep::Conditions::Condition>+; #pragma link C++ class DD4hep::Conditions::Interna::ConditionObject+; @@ -202,6 +223,9 @@ template class DD4hep::Handle<TNamed>; #pragma link C++ class DD4hep::Conditions::Container+; #pragma link C++ class DD4hep::Conditions::Interna::ConditionContainer+; #pragma link C++ class DD4hep::Handle<DD4hep::Conditions::Interna::ConditionContainer>+; +#pragma link C++ class DD4hep::Conditions::ConditionsPool+; + +#pragma link C++ class DD4hep::Alignments::DetConditions+; // DetElement.h #pragma link C++ class DD4hep::Geometry::World+; diff --git a/DDCore/include/DD4hep/Alignment.h b/DDCore/include/DD4hep/GlobalAlignment.h similarity index 83% rename from DDCore/include/DD4hep/Alignment.h rename to DDCore/include/DD4hep/GlobalAlignment.h index 08a59d653155a628b50ee00683b05658489e4776..7036e777fc80e989514dc4aaa3470a10c26ed6e8 100644 --- a/DDCore/include/DD4hep/Alignment.h +++ b/DDCore/include/DD4hep/GlobalAlignment.h @@ -1,4 +1,4 @@ -// $Id:$ +// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -11,22 +11,20 @@ // Author : M.Frank // //========================================================================== -#ifndef DD4HEP_GEOMETRY_ALIGNMENT_H -#define DD4HEP_GEOMETRY_ALIGNMENT_H +#ifndef DD4HEP_ALIGNMENT_GLOBALALIGNMENT_H +#define DD4HEP_ALIGNMENT_GLOBALALIGNMENT_H // Framework include files #include "DD4hep/Objects.h" #include "DD4hep/Volumes.h" +#include "DD4hep/Alignments.h" #include "TGeoPhysicalNode.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { - - // Forward declarations - class DetElement; + namespace Alignments { /// Main handle class to hold a TGeo alignment object of type TGeoPhysicalNode /** @@ -38,24 +36,24 @@ namespace DD4hep { * \ingroup DD4HEP_GEOMETRY * \ingroup DD4HEP_ALIGN */ - class Alignment: public Handle<TGeoPhysicalNode> { + class GlobalAlignment: public Handle<TGeoPhysicalNode> { public: /// Default constructor - Alignment(); + GlobalAlignment(); /// Default constructor - Alignment(TGeoPhysicalNode* p) + GlobalAlignment(TGeoPhysicalNode* p) : Handle<TGeoPhysicalNode>(p) { } /// Copy constructor - Alignment(const Alignment& c); + GlobalAlignment(const GlobalAlignment& c); /// Constructor to be used when reading the already parsed object - template <typename Q> Alignment(const Handle<Q>& e) + template <typename Q> GlobalAlignment(const Handle<Q>& e) : Handle<TGeoPhysicalNode>(e) { } /// Initializing constructor - Alignment(const std::string& path); + GlobalAlignment(const std::string& path); /// Assignment operator - Alignment& operator=(const Alignment& c); + GlobalAlignment& operator=(const GlobalAlignment& c); /// Number of nodes in this branch (=depth of the placement hierarchy from the top level volume) int numNodes() const; /// Access the placement of this node @@ -88,6 +86,6 @@ namespace DD4hep { }; - } /* End namespace Geometry */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_GEOMETRY_ALIGNMENT_H */ + } /* End namespace Alignments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_ALIGNMENT_GLOBALALIGNMENT_H */ diff --git a/DDCore/include/DD4hep/IOV.h b/DDCore/include/DD4hep/IOV.h new file mode 100644 index 0000000000000000000000000000000000000000..58e80fe964f22cfc1d1c917f9d1f6b88f6132828 --- /dev/null +++ b/DDCore/include/DD4hep/IOV.h @@ -0,0 +1,147 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_CONDITIONS_IOV_H +#define DD4HEP_CONDITIONS_IOV_H + +// C/C++ include files +#include <string> +#include <algorithm> + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + class IOVType; + class IOV; + + /// Class describing the interval of validty type + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class IOVType { + public: + enum { UNKNOWN_IOV = ~0x0 } _IOVTypes; + + unsigned int type; + std::string name; + IOVType() : type(UNKNOWN_IOV), name() {} + ~IOVType() {} + std::string str() const; + }; + + /// Class describing the interval of validty + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class IOV { + private: + /// Initializing constructor: Does not set reference to IOVType ! + explicit IOV(); + public: + /// Key definition + typedef long Key_first_type; + typedef long Key_second_type; + typedef std::pair<Key_first_type,Key_second_type> Key; + + const IOVType* iovType; + Key keyData; + int optData; + /// IOV buffer type: Must be a bitmap! + unsigned int type; + + /// Initializing constructor + explicit IOV(const IOVType* typ); + /// Specialized copy constructor + explicit IOV(const IOVType* typ, const Key& key); + /// Copy constructor + IOV(const IOV& copy); + + /// Standard Destructor + ~IOV(); + /// Move the data content: 'from' will be reset to NULL + void move(IOV& from); + /// Create string representation of the IOV + std::string str() const; + /// Check if the IOV corresponds to a range + bool has_range() const { return keyData.first != keyData.second; } + /// Check if the IOV corresponds to a range + bool is_discrete() const { return keyData.first == keyData.second; } + /// Get the local key of the IOV + Key key() const { return keyData; } + + /// Set discrete IOV value + void set(const Key& value); + /// Set discrete IOV value + void set(Key_first_type value); + /// Set range IOV value + void set(Key_first_type val_1, Key_second_type val_2); + /// Set keys to unphysical values (LONG_MAX, LONG_MIN) + IOV& reset(); + /// Invert the key values (first=second and second=first) + IOV& invert(); + /// Set the intersection of this IOV with the argument IOV + void iov_intersection(const IOV& comparator); + /// Set the intersection of this IOV with the argument IOV + void iov_intersection(const IOV::Key& comparator); + /// Set the union of this IOV with the argument IOV + void iov_union(const IOV& comparator); + /// Set the union of this IOV with the argument IOV + void iov_union(const IOV::Key& comparator); + + /// Check for validity containment + /** Check if the caller 'iov' is of the same type and the range + * is fully conained by the caller. + */ + bool contains(const IOV& iov) const; + /// Check if 2 IOV objects are of the same type + static bool same_type(const IOV& iov, const IOV& test) { + unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type; + unsigned int typ2 = test.iovType ? test.iovType->type : test.type; + return typ1 == typ2; + } + /// Check if IOV 'test' is fully contained in IOV 'key' + static bool key_is_contained(const Key& key, const Key& test) + { return key.first >= test.first && key.second <= test.second; } + /// Same as above, but reverse logic. Gives sometimes more understandable logic. + static bool key_contains_range(const Key& key, const Key& test) + { return key.first <= test.first && key.second >= test.second; } + /// Check if IOV 'test' has an overlap on the lower interval edge with IOV 'key' + static bool key_overlaps_lower_end(const Key& key, const Key& test) + { return key.first <= test.second && key.first >= test.first; } + /// Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key' + static bool key_overlaps_higher_end(const Key& key, const Key& test) + { return key.second >= test.first && key.second <= test.second; } + /// Check if IOV 'test' has an overlap on the upper interval edge with IOV 'key' + static bool key_partially_contained(const Key& key, const Key& test) + { + return + (test.first <= key.first && key.second >= test.second) || // test fully contained in key + (test.first <= key.first && key.first <= test.second) || // test overlaps left edge of key + (test.first <= key.second && key.second <= test.second); // test overlaps right edge of key + } + /// Check if IOV 'test' is of same type and is fully contained in iov + static bool full_match(const IOV& iov, const IOV& test) + { return same_type(iov,test) && key_is_contained(iov.keyData,test.keyData); } + /// Check if IOV 'test' is of same type and is at least partially contained in iov + static bool partial_match(const IOV& iov, const IOV& test) + { return same_type(iov,test) && key_partially_contained(iov.keyData,test.keyData); } + }; + +} /* End namespace DD4hep */ +#endif /* DD4HEP_CONDITIONS_IOV_H */ diff --git a/DDCore/include/DD4hep/MatrixHelpers.h b/DDCore/include/DD4hep/MatrixHelpers.h index dae1e97dec4aa3a13085193d7ea4b1007c03082a..15658c18d76047619ff967cae7635e5441d59439 100644 --- a/DDCore/include/DD4hep/MatrixHelpers.h +++ b/DDCore/include/DD4hep/MatrixHelpers.h @@ -27,47 +27,43 @@ class TGeoMatrix; /// Namespace for the AIDA detector description toolkit namespace DD4hep { - /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Geometry { + typedef Position XYZAngles; + /// Access the TGeo identity transformation \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoIdentity* identityTransform(); + /// Convert a Position object to a TGeoTranslation \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoTranslation* _translation(const Position& pos); + /// Convert a RotationZYX object to a TGeoRotation \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoRotation* _rotationZYX(const RotationZYX& rot); + /// Convert a Rotation3D object to a TGeoRotation \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoRotation* _rotation3D(const Rotation3D& rot); + /// Convert a Transform3D object to a TGeoHMatrix \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoHMatrix* _transform(const Transform3D& trans); + /// Convert a Position object to a TGeoHMatrix \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoHMatrix* _transform(const Position& pos); + /// Convert a RotationZYX object to a TGeoHMatrix \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoHMatrix* _transform(const RotationZYX& rot); + /// Convert a Rotation3D object to a TGeoHMatrix \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoHMatrix* _transform(const Rotation3D& rot3D); + /// Convert a Position followed by a RotationZYX to a TGeoHMatrix \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + TGeoHMatrix* _transform(const Position& pos, const RotationZYX& rot); - typedef Position XYZAngles; - /// Access the TGeo identity transformation \ingroup DD4HEP_GEOMETRY - TGeoIdentity* identityTransform(); - /// Convert a Position object to a TGeoTranslation \ingroup DD4HEP_GEOMETRY - TGeoTranslation* _translation(const Position& pos); - /// Convert a RotationZYX object to a TGeoRotation \ingroup DD4HEP_GEOMETRY - TGeoRotation* _rotationZYX(const RotationZYX& rot); - /// Convert a Rotation3D object to a TGeoRotation \ingroup DD4HEP_GEOMETRY - TGeoRotation* _rotation3D(const Rotation3D& rot); - /// Convert a Transform3D object to a TGeoHMatrix \ingroup DD4HEP_GEOMETRY - TGeoHMatrix* _transform(const Transform3D& trans); - /// Convert a Position object to a TGeoHMatrix \ingroup DD4HEP_GEOMETRY - TGeoHMatrix* _transform(const Position& pos); - /// Convert a RotationZYX object to a TGeoHMatrix \ingroup DD4HEP_GEOMETRY - TGeoHMatrix* _transform(const RotationZYX& rot); - /// Convert a Rotation3D object to a TGeoHMatrix \ingroup DD4HEP_GEOMETRY - TGeoHMatrix* _transform(const Rotation3D& rot3D); - /// Convert a Position followed by a RotationZYX to a TGeoHMatrix \ingroup DD4HEP_GEOMETRY - TGeoHMatrix* _transform(const Position& pos, const RotationZYX& rot); + /// Convert a TGeoMatrix object to a generic Transform3D \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + Transform3D _transform(const TGeoMatrix* matrix); - /// Convert a TGeoMatrix object to a generic Transform3D \ingroup DD4HEP_GEOMETRY - Transform3D _transform(const TGeoMatrix* matrix); + /// Decompose a generic Transform3D into a translation (Position) and a RotationZYX \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + void _decompose(const Transform3D& trafo, Position& pos, RotationZYX& rot); + /// Decompose a generic Transform3D into a translation (Position) and XYZAngles \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + void _decompose(const Transform3D& trafo, Position& pos, XYZAngles& rot); + /// Decompose a generic Transform3D into a translation (Translation3D) and a RotationZYX \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + void _decompose(const Transform3D& trafo, Translation3D& pos, RotationZYX& rot); + /// Decompose a generic Transform3D into a translation (Translation3D) and XYZAngles \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + void _decompose(const Transform3D& trafo, Translation3D& pos, XYZAngles& rot); - /// Decompose a generic Transform3D into a translation (Position) and a RotationZYX \ingroup DD4HEP_GEOMETRY - void _decompose(const Transform3D& trafo, Position& pos, RotationZYX& rot); - /// Decompose a generic Transform3D into a translation (Position) and XYZAngles \ingroup DD4HEP_GEOMETRY - void _decompose(const Transform3D& trafo, Position& pos, XYZAngles& rot); - /// Decompose a generic Transform3D into a translation (Translation3D) and a RotationZYX \ingroup DD4HEP_GEOMETRY - void _decompose(const Transform3D& trafo, Translation3D& pos, RotationZYX& rot); - /// Decompose a generic Transform3D into a translation (Translation3D) and XYZAngles \ingroup DD4HEP_GEOMETRY - void _decompose(const Transform3D& trafo, Translation3D& pos, XYZAngles& rot); + /// Convert a 3x3 rotation matrix to XYZAngles \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + XYZAngles _XYZangles(const double* matrix); + /// Convert a the rotation part of a TGeoMatrix to XYZAngles \ingroup DD4HEP \ingroup DD4HEP_GEOMETRY + XYZAngles _XYZangles(const TGeoMatrix* matrix); - /// Convert a 3x3 rotation matrix to XYZAngles \ingroup DD4HEP_GEOMETRY - XYZAngles _XYZangles(const double* matrix); - /// Convert a the rotation part of a TGeoMatrix to XYZAngles \ingroup DD4HEP_GEOMETRY - XYZAngles _XYZangles(const TGeoMatrix* matrix); - - } /* End namespace Geometry */ } /* End namespace DD4hep */ #endif // DD4HEP_IMP_MATRIXHELPERS_H diff --git a/DDCore/include/DD4hep/Memory.h b/DDCore/include/DD4hep/Memory.h index f920d142885a875c42f36ec013854305d5fa1f19..6650983eba723bff395eb44fe1acbb1515eac739 100644 --- a/DDCore/include/DD4hep/Memory.h +++ b/DDCore/include/DD4hep/Memory.h @@ -21,6 +21,9 @@ // C/C++ include files #include <memory> +// Use std::auto_ptr<T> instead of std::unique_ptr<T> +#define DD4HEP_DD4HEP_PTR_AUTO + /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -34,7 +37,8 @@ namespace DD4hep { * \ingroup DD4HEP_GEOMETRY */ template <typename T> class dd4hep_ptr -#if defined(DD4HEP_NEVER) && __cplusplus >= 201103L && ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) + //#if defined(DD4HEP_NEVER) && __cplusplus >= 201103L && ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) +#if !defined(DD4HEP_DD4HEP_PTR_AUTO) && __cplusplus >= 201103L && ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0) : public std::unique_ptr<T> { public: typedef std::unique_ptr<T> base_t; diff --git a/DDCore/include/DD4hep/Objects.h b/DDCore/include/DD4hep/Objects.h index 86280e7a72ae62eb2f952babb22d206b30ec97f2..dacc3086c693360da7c2aca146b3f52244832b5c 100644 --- a/DDCore/include/DD4hep/Objects.h +++ b/DDCore/include/DD4hep/Objects.h @@ -57,6 +57,46 @@ class TGeoIdentity; /// Namespace for the AIDA detector description toolkit namespace DD4hep { + typedef ROOT::Math::XYZVector Position; + template <class V> V RotateX(const V& v, double a) { + return ROOT::Math::VectorUtil::RotateX(v, a); + } + template <class V> V RotateY(const V& v, double a) { + return ROOT::Math::VectorUtil::RotateY(v, a); + } + template <class V> V RotateZ(const V& v, double a) { + return ROOT::Math::VectorUtil::RotateZ(v, a); + } + + /** Rotation class with the (3D) rotation represented by + * angles describing first a rotation of + * an angle phi (yaw) about the Z axis, + * followed by a rotation of an angle theta (pitch) about the new Y' axis, + * followed by a third rotation of an angle psi (roll) about the final X'' axis. + * This is sometimes referred to as the Euler 321 sequence. + * It has not to be confused with the typical Goldstein definition of the Euler Angles + * (Z-X-Z or 313 sequence) which is used by the ROOT::Math::EulerAngles class. + * \see http://root.cern.ch/root/html/ROOT__Math__RotationZYX.html + */ + typedef ROOT::Math::RotationZYX RotationZYX; + /** \see http://root.cern.ch/root/html/ROOT__Math__RotationZ.html */ + typedef ROOT::Math::RotationZ RotationZ; + /** \see http://root.cern.ch/root/html/ROOT__Math__RotationY.html */ + typedef ROOT::Math::RotationY RotationY; + /** \see http://root.cern.ch/root/html/ROOT__Math__RotationX.html */ + typedef ROOT::Math::RotationX RotationX; + /** \see http://root.cern.ch/root/html/ROOT__Math__Rotation3D.html */ + typedef ROOT::Math::Rotation3D Rotation3D; + /** \see http://root.cern.ch/root/html/ROOT__Math__EulerAngels.html */ + typedef ROOT::Math::EulerAngles EulerAngles; + /** \see http://root.cern.ch/root/html/ROOT__Math__Transform3D.html */ + typedef ROOT::Math::Transform3D Transform3D; + /** \see http://root.cern.ch/root/html/ROOT__Math__Translations3D.html */ + typedef ROOT::Math::Translation3D Translation3D; + + /** Access to identity transformation */ + TGeoIdentity* identityTransform(); + /// Namespace for the geometry part of the AIDA detector description toolkit namespace Geometry { @@ -69,9 +109,6 @@ namespace DD4hep { class RegionObject; class LimitSetObject; - /** Access to identity transformation */ - TGeoIdentity* identityTransform(); - /// Handle class describing an author entity /** * \author M.Frank @@ -212,43 +249,6 @@ namespace DD4hep { std::string toString() const; }; - typedef ROOT::Math::XYZVector Position; - template <class V> V RotateX(const V& v, double a) { - return ROOT::Math::VectorUtil::RotateX(v, a); - } - template <class V> V RotateY(const V& v, double a) { - return ROOT::Math::VectorUtil::RotateY(v, a); - } - template <class V> V RotateZ(const V& v, double a) { - return ROOT::Math::VectorUtil::RotateZ(v, a); - } - - /** Rotation class with the (3D) rotation represented by - * angles describing first a rotation of - * an angle phi (yaw) about the Z axis, - * followed by a rotation of an angle theta (pitch) about the new Y' axis, - * followed by a third rotation of an angle psi (roll) about the final X'' axis. - * This is sometimes referred to as the Euler 321 sequence. - * It has not to be confused with the typical Goldstein definition of the Euler Angles - * (Z-X-Z or 313 sequence) which is used by the ROOT::Math::EulerAngles class. - * \see http://root.cern.ch/root/html/ROOT__Math__RotationZYX.html - */ - typedef ROOT::Math::RotationZYX RotationZYX; - /** \see http://root.cern.ch/root/html/ROOT__Math__RotationZ.html */ - typedef ROOT::Math::RotationZ RotationZ; - /** \see http://root.cern.ch/root/html/ROOT__Math__RotationY.html */ - typedef ROOT::Math::RotationY RotationY; - /** \see http://root.cern.ch/root/html/ROOT__Math__RotationX.html */ - typedef ROOT::Math::RotationX RotationX; - /** \see http://root.cern.ch/root/html/ROOT__Math__Rotation3D.html */ - typedef ROOT::Math::Rotation3D Rotation3D; - /** \see http://root.cern.ch/root/html/ROOT__Math__EulerAngels.html */ - typedef ROOT::Math::EulerAngles EulerAngles; - /** \see http://root.cern.ch/root/html/ROOT__Math__Transform3D.html */ - typedef ROOT::Math::Transform3D Transform3D; - /** \see http://root.cern.ch/root/html/ROOT__Math__Translations3D.html */ - typedef ROOT::Math::Translation3D Translation3D; - /// Handle class describing an element in the periodic table /** * For details please see the ROOT TGeo information: @@ -548,7 +548,7 @@ namespace DD4hep { namespace ROOT { namespace Math { - typedef DD4hep::Geometry::Position Position; + typedef DD4hep::Position Position; /// Dot product of 3-vectors. inline double operator *(const Position& l, const Position& r) { return std::sqrt(l.X() * r.X() + l.Y() * r.Y() + l.Z() * r.Z()); diff --git a/DDCore/include/DD4hep/OpaqueData.h b/DDCore/include/DD4hep/OpaqueData.h new file mode 100644 index 0000000000000000000000000000000000000000..aa56800571628f9b409ccd9c05d6508bf75b9052 --- /dev/null +++ b/DDCore/include/DD4hep/OpaqueData.h @@ -0,0 +1,118 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DD4HEP_OPAQUEDATA_H +#define DD4HEP_OPAQUEDATA_H + +// C/C++ include files +#include <typeinfo> +#include <vector> +#include <string> + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + // Forward declarations + class BasicGrammar; + + /// Class describing an opaque data block + /** + * Access methods are templated. Once the access is fixed + * on the first call, the data type may not be changed anymore. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class OpaqueData { + private: + protected: + /// Standard initializing constructor + OpaqueData(); + /// Standard Destructor + virtual ~OpaqueData(); + + public: + /// Data type + const BasicGrammar* grammar; + protected: + /// Pointer to object data + void* pointer; + + public: + /// Create data block from string representation + bool fromString(const std::string& rep); + /// Create string representation of the data block + std::string str() const; + /// Access type id of the condition + const std::type_info& typeInfo() const; + /// Access type name of the condition data block + const std::string& dataType() const; + /// Check if object is already bound.... + bool is_bound() const { return 0 != pointer; } + /// Generic getter. Specify the exact type, not a polymorph type + template <typename T> T& get(); + /// Generic getter (const version). Specify the exact type, not a polymorph type + template <typename T> const T& get() const; + }; + + + /// Class describing an opaque conditions data block + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class OpaqueDataBlock : public OpaqueData { + private: + enum { + PLAIN_DATA = 1<<0, + ALLOC_DATA = 1<<1, + BOUND_DATA = 1<<2 + } _DataTypes; + /// Data buffer: plain data are allocated directly on this buffer + /** Internal data buffer is sufficient to store any vector */ + unsigned char data[sizeof(std::vector<void*>)]; + /// Destructor function -- only set if the object is valid + void (*destruct)(void*); + /// Constructor function -- only set if the object is valid + void (*copy)(void*,const void*); + + public: + /// Data buffer type: Must be a bitmap! + unsigned int type; + /// Standard initializing constructor + OpaqueDataBlock(); + /// Copy constructor + OpaqueDataBlock(const OpaqueDataBlock& data); + /// Standard Destructor + ~OpaqueDataBlock(); + /// Assignment operator + OpaqueDataBlock& operator=(const OpaqueDataBlock& clone); + /// Move the data content: 'from' will be reset to NULL + bool move(OpaqueDataBlock& from); + /// Bind data value + bool bind(const BasicGrammar* grammar, + void (*ctor)(void*,const void*), + void (*dtor)(void*)); + /// Bind data value + template <typename T> T& bind(); + /// Set data value + void assign(const void* ptr,const std::type_info& typ); + /// Bind grammar and assign value + template<typename T> T& set(const std::string& value); + }; + +} /* End namespace DD4hep */ +#endif /* DD4HEP_OPAQUEDATA_H */ diff --git a/DDCore/include/DD4hep/World.h b/DDCore/include/DD4hep/World.h index 789c718dfaf01dc51bedb6dd5938111d9c46056e..990e4ddf3684291af1ef330dadb32d449e48b63c 100644 --- a/DDCore/include/DD4hep/World.h +++ b/DDCore/include/DD4hep/World.h @@ -16,8 +16,8 @@ #define DD4HEP_WORLD_H // Framework include files -#include "DD4hep/Detector.h" #include "DD4hep/Conditions.h" +#include "DD4hep/Alignments.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -37,13 +37,13 @@ namespace DD4hep { class World : public Handle<WorldObject> { public: /// Internal object type - typedef WorldObject Object; + typedef WorldObject Object; /// Definition of the base handle type - typedef Handle<Object> RefObject; + typedef Handle<Object> RefObject; /// Conditions stuff - typedef Conditions::IOV IOV; - typedef Conditions::UserPool UserPool; - typedef Conditions::Condition Condition; + typedef Conditions::ConditionsLoader ConditionsLoader; + /// Alignment stuff + typedef Alignments::AlignmentsLoader AlignmentsLoader; public: /// Default constructor @@ -70,9 +70,9 @@ namespace DD4hep { LCDD& lcdd() const; #endif /// Access the conditions loading - Condition getCondition(Condition::key_type key, const IOV& iov) const; - /// Access the conditions loading. Only conditions in the pool are accessed. - Condition getCondition(Condition::key_type key, const UserPool& pool) const; + ConditionsLoader& conditionsLoader() const; + /// Access to the alignment loading + AlignmentsLoader& alignmentsLoader() const; }; } /* End namespace Conditions */ diff --git a/DDCore/include/DD4hep/objects/AlignmentsInterna.h b/DDCore/include/DD4hep/objects/AlignmentsInterna.h new file mode 100644 index 0000000000000000000000000000000000000000..f13a7afcbf76f530928262534ca3082600f9fc6f --- /dev/null +++ b/DDCore/include/DD4hep/objects/AlignmentsInterna.h @@ -0,0 +1,163 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// NOTE: +// +// This is an internal include file. It should only be included to +// instantiate code. Otherwise the Alignments include file should be +// sufficient for all practical purposes. +// +//========================================================================== +#ifndef DD4HEP_ALIGNMENTS_ALIGNMENTSINTERNA_H +#define DD4HEP_ALIGNMENTS_ALIGNMENTSINTERNA_H + +// Framework include files +#include "DD4hep/IOV.h" +#include "DD4hep/Alignments.h" +#include "DD4hep/objects/ConditionsInterna.h" + +// C/C++ include files +#include <map> + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the alignments part of the AIDA detector description toolkit + namespace Alignments { + + // Forward declarations + class AlignmentsPool; + class Alignment; + + /// The data class behind a alignments container handle. + /** + * See AlignmentsInterna.cpp for the implementation. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_ALIGNMENTS + */ + class AlignmentsLoader { + protected: + /// Forward defintion of the key type + typedef Alignment::key_type key_type; + /// Forward definition of the iov type + typedef Alignment::iov_type iov_type; + /// Protected destructor + virtual ~AlignmentsLoader(); + public: + /// Addreference count. Use object + virtual void addRef() = 0; + /// Release object. The client may not use any reference any further. + virtual void release() = 0; + /// Access the alignments loading mechanism + virtual Alignment get(key_type key, const iov_type& iov) = 0; + /// Access the alignments loading mechanism. Only alignments in the user pool will be accessed. + virtual Alignment get(key_type key, const UserPool& pool) = 0; + }; + + /// Alignments internal namespace declaration + /** Internally defined datastructures are not presented to the + * user directly, but are used by dedicated views. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_ALIGNMENTS + */ + namespace Interna { + + // Forward declarations + class AlignmentContainer; + class AlignmentConditionObject; + + /// The data class behind a alignments handle. + /** + * See AlignmentsInterna.cpp for the implementation. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_ALIGNMENTS + */ + class AlignmentConditionObject + : public Conditions::Interna::ConditionObject, public AlignmentData + { + public: + // Make the conditions object type local! + typedef Conditions::Interna::ConditionObject ConditionObject; + /// Standard constructor + AlignmentConditionObject(const std::string& nam,const std::string& tit=""); + /// Standard Destructor + virtual ~AlignmentConditionObject(); + /// Clear data + void clear(); + }; + + /// The data class behind a alignments container handle. + /** + * See AlignmentsInterna.cpp for the implementation. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_ALIGNMENTS + */ + class AlignmentContainer : public NamedObject { + public: + /// Forward defintion of the key type + typedef Alignment::key_type key_type; + /// Forward definition of the iov type + typedef Alignment::iov_type iov_type; + /// Forward definition of the mapping type + typedef std::pair<key_type, std::string> key_value; + /// Definition of the keys + typedef std::map<key_type, key_value> Keys; + + public: + /// Standard constructor + AlignmentContainer(Geometry::DetElementObject* parent); + /// Default destructor + virtual ~AlignmentContainer(); + +#ifdef __CINT__ + Handle<NamedObject> detector; +#else + /// The hosting detector element + DetElement detector; + + /// Access to alignment objects by key and IOV. + Alignment get(const std::string& alignment_key, const iov_type& iov); + + /// Access to alignment objects directly by their hash key. + Alignment get(key_type hash_key, const iov_type& iov); + + /// Access to alignment objects. Only alignments in the pool are accessed. + Alignment get(const std::string& alignment_key, const UserPool& iov); + + /// Access to alignment objects. Only alignments in the pool are accessed. + Alignment get(key_type alignment_key, const UserPool& iov); +#endif + public: + /// Known keys of alignments in this container + Keys keys; + /// Add a new key to the alignments access map + void addKey(const std::string& key_value); + /// Add a new key to the alignments access map: Allow for alias if key_val != data_val + void addKey(const std::string& key_value, const std::string& data_value); + }; + + } /* End namespace Interna */ + + } /* End namespace Alignments */ +} /* End namespace DD4hep */ + +#endif /* DD4HEP_ALIGNMENTS_ALIGNMENTSINTERNA_H */ diff --git a/DDCore/include/DD4hep/objects/BasicGrammar_inl.h b/DDCore/include/DD4hep/objects/BasicGrammar_inl.h index b15eb53a392ad7f6735f617a4332e01f2b80d796..6ba6274fda52cec6c1bdd4621a96444dcbb58c2d 100644 --- a/DDCore/include/DD4hep/objects/BasicGrammar_inl.h +++ b/DDCore/include/DD4hep/objects/BasicGrammar_inl.h @@ -11,6 +11,14 @@ // Author : M.Frank // //========================================================================== +// +// NOTE: +// +// This is an internal include file. It should only be included to +// instantiate code. Otherwise the BasicGrammar include file should be +// sufficient for all practical purposes. +// +//========================================================================== #ifndef DD4HEP_DDCORE_BASICGRAMMAR_INL_H #define DD4HEP_DDCORE_BASICGRAMMAR_INL_H @@ -302,59 +310,59 @@ namespace DD4hep { } // End namespace DD4hep -#define DD4HEP_DEFINE_PARSER_GRAMMAR_TYPE(x) \ -namespace DD4hep { \ - template<> const BasicGrammar& BasicGrammar::instance<x>() { static Grammar<x> s; return s;}} +#define DD4HEP_DEFINE_PARSER_GRAMMAR_TYPE(x) \ + namespace DD4hep { \ + template<> const BasicGrammar& BasicGrammar::instance<x>() { static Grammar<x> s; return s;}} -#define DD4HEP_DEFINE_PARSER_GRAMMAR_EVAL(x,func) \ - namespace DD4hep { \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR_EVAL(x,func) \ + namespace DD4hep { \ template<> int Grammar<x >::evaluate(void* p, const std::string& v) const { return func ((x*)p,v); }} -#define DD4HEP_DEFINE_PARSER_GRAMMAR(x,func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR_TYPE(x) \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR(x,func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR_TYPE(x) \ DD4HEP_DEFINE_PARSER_GRAMMAR_EVAL(x,func) #if defined(DD4HEP_HAVE_ALL_PARSERS) -#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::list<x>, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::set<x>, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::deque<x>, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_map_t, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::ulong_map_t, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::string_map_t, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_pair_t, eval_pair) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::ulong_pair_t, eval_pair) \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::list<x>, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::set<x>, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::deque<x>, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_map_t, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::ulong_map_t, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::string_map_t, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_pair_t, eval_pair) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::ulong_pair_t, eval_pair) \ DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::string_pair_t, eval_pair) -#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT_VL(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>,eval_container) \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT_VL(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>,eval_container) \ DD4HEP_DEFINE_PARSER_GRAMMAR(std::list<x>,eval_container) -#define DD4HEP_DEFINE_PARSER_GRAMMAR_U_CONT(x) \ - DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(x,eval_item) \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR_U_CONT(x) \ + DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(x,eval_item) \ DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(unsigned x,eval_item) #else -#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::list<x>, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::set<x>, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_map_t, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::string_map_t, eval_container) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_pair_t, eval_pair) \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::list<x>, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::set<x>, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_map_t, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::string_map_t, eval_container) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::int_pair_t, eval_pair) \ DD4HEP_DEFINE_PARSER_GRAMMAR(DD4hep::Primitive<x>::string_pair_t, eval_pair) -#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT_VL(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ - DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>,eval_container) \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR_CONT_VL(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(x,eval_func) \ + DD4HEP_DEFINE_PARSER_GRAMMAR(std::vector<x>,eval_container) \ DD4HEP_DEFINE_PARSER_GRAMMAR(std::list<x>,eval_container) -#define DD4HEP_DEFINE_PARSER_GRAMMAR_U_CONT(x) \ +#define DD4HEP_DEFINE_PARSER_GRAMMAR_U_CONT(x) \ DD4HEP_DEFINE_PARSER_GRAMMAR_CONT(x,eval_item) #endif diff --git a/DDCore/include/DD4hep/objects/ConditionsInterna.h b/DDCore/include/DD4hep/objects/ConditionsInterna.h index c85b8ddb4586251e20ad7712b434c764aa3daae2..6bfa3d01993b4b72d6b1be4c68efe4c9486bb237 100644 --- a/DDCore/include/DD4hep/objects/ConditionsInterna.h +++ b/DDCore/include/DD4hep/objects/ConditionsInterna.h @@ -11,14 +11,23 @@ // Author : M.Frank // //========================================================================== -#ifndef DD4HEP_GEOMETRY_CONDITIONINTERNA_H -#define DD4HEP_GEOMETRY_CONDITIONINTERNA_H +// +// NOTE: +// +// This is an internal include file. It should only be included to +// instantiate code. Otherwise the Conditions include file should be +// sufficient for all practical purposes. +// +//========================================================================== +#ifndef DD4HEP_CONDITIONS_CONDITIONINTERNA_H +#define DD4HEP_CONDITIONS_CONDITIONINTERNA_H // Framework include files #include "DD4hep/Detector.h" #include "DD4hep/Conditions.h" #include "DD4hep/BasicGrammar.h" #include "DD4hep/NamedObject.h" +#include "DD4hep/objects/OpaqueData_inl.h" // C/C++ include files #include <map> @@ -30,60 +39,31 @@ namespace DD4hep { namespace Conditions { // Forward declarations - class ConditionsLoader; class ConditionsPool; - class Condition; - class IOVType; - class IOV; - /// Class describing an opaque conditions data block + /// The data class behind a conditions container handle. /** + * See ConditionsInterna.cpp for the implementation. * * \author M.Frank * \version 1.0 * \ingroup DD4HEP_CONDITIONS */ - class BlockData : public Block { - friend class Condition; - friend class Object; - - private: - enum { - PLAIN_DATA = 1<<0, - ALLOC_DATA = 1<<1, - BOUND_DATA = 1<<2 - } _DataTypes; - /// Data buffer: plain data are allocated directly on this buffer - /** Internal data buffer is sufficient to store any vector */ - unsigned char data[sizeof(std::vector<void*>)]; - /// Destructor function -- only set if the object is valid - void (*destruct)(void*); - /// Constructor function -- only set if the object is valid - void (*copy)(void*,const void*); - + class ConditionsLoader { + protected: + typedef Condition::key_type key_type; + typedef Condition::iov_type iov_type; + /// Protected destructor + virtual ~ConditionsLoader(); public: - /// Data buffer type: Must be a bitmap! - int type; - /// Standard initializing constructor - BlockData(); - /// Copy constructor - BlockData(const BlockData& data); - /// Standard Destructor - ~BlockData(); - /// Assignment operator - BlockData& operator=(const BlockData& clone); - /// Move the data content: 'from' will be reset to NULL - bool move(BlockData& from); - /// Bind data value - bool bind(const BasicGrammar* grammar, - void (*ctor)(void*,const void*), - void (*dtor)(void*)); - /// Bind data value - template <typename T> T& bind(); - /// Set data value - void assign(const void* ptr,const std::type_info& typ); - /// Bind grammar and assign value - template<typename T> T& set(const std::string& value); + /// Addreference count. Use object + virtual void addRef() = 0; + /// Release object. The client may not use any reference any further. + virtual void release() = 0; + /// Access the conditions loading mechanism + virtual Condition get(key_type key, const iov_type& iov) = 0; + /// Access the conditions loading mechanism. Only conditions in the user pool will be accessed. + virtual Condition get(key_type key, const UserPool& pool) = 0; }; /// Conditions internal namespace declaration @@ -110,31 +90,37 @@ namespace DD4hep { */ class ConditionObject : public NamedObject { public: - /// Forward definition of the key type - typedef Condition::key_type key_type; - typedef Condition::iov_type iov_type; + /// Forward definition of the key type + typedef Condition::key_type key_type; + /// Forward definition of the iov type + typedef Condition::iov_type iov_type; + /// Forward definition of the object properties + typedef unsigned int BitMask; + /// Forward definition of the object mask manipulator + typedef ReferenceBitMask<BitMask> MaskManip; + /// Condition value (in string form) - std::string value; + std::string value; /// Condition validity (in string form) - std::string validity; + std::string validity; /// Condition address - std::string address; + std::string address; /// Comment string - std::string comment; + std::string comment; /// Data block - BlockData data; + OpaqueDataBlock data; /// Reference to conditions pool ConditionsPool* pool; /// Interval of validity const iov_type* iov; /// Hash value of the name - key_type hash; + key_type hash; /// Flags - int flags; + BitMask flags; /// Reference count - int refCount; + int refCount; /// Standard constructor - ConditionObject(); + ConditionObject(const std::string& nam="",const std::string& tit=""); /// Standard Destructor virtual ~ConditionObject(); /// Move data content: 'from' will be reset to NULL @@ -145,9 +131,9 @@ namespace DD4hep { const IOVType* iovType() const; /// Check if object is already bound.... bool is_bound() const { return data.is_bound(); } - bool is_traced() const { return true; } - void setFlag(int option) { flags |= option; } - void unFlag(int option) { flags &= ~option; } + bool is_traced() const { return true; } + void setFlag(int option) { flags |= option; } + void unFlag(int option) { flags &= ~option; } }; /// The data class behind a conditions container handle. @@ -160,12 +146,14 @@ namespace DD4hep { */ class ConditionContainer : public NamedObject { public: - /// Forward defintion of the key type - typedef Condition::key_type key_type; - typedef Condition::iov_type iov_type; - typedef std::pair<key_type, std::string> key_value; - /// Definition of the keys - typedef std::map<key_type, key_value> Keys; + /// Forward defintion of the key type + typedef Condition::key_type key_type; + /// Forward definition of the iov type + typedef Condition::iov_type iov_type; + /// Forward definition of the mapping type + typedef std::pair<key_type, std::string> key_value; + /// Definition of the keys + typedef std::map<key_type, key_value> Keys; public: /// Standard constructor @@ -179,87 +167,30 @@ namespace DD4hep { /// The hosting detector element DetElement detector; - /// Access to condition objects by key and IOV. - Condition get(const std::string& condition_key, const iov_type& iov); + /// Access to condition objects by key and IOV. + Condition get(const std::string& condition_key, const iov_type& iov); - /// Access to condition objects directly by their hash key. - Condition get(key_type hash_key, const iov_type& iov); + /// Access to condition objects directly by their hash key. + Condition get(key_type hash_key, const iov_type& iov); - /// Access to condition objects. Only conditions in the pool are accessed. - Condition get(const std::string& condition_key, const UserPool& iov); + /// Access to condition objects. Only conditions in the pool are accessed. + Condition get(const std::string& condition_key, const UserPool& iov); - /// Access to condition objects. Only conditions in the pool are accessed. - Condition get(key_type condition_key, const UserPool& iov); + /// Access to condition objects. Only conditions in the pool are accessed. + Condition get(key_type condition_key, const UserPool& iov); #endif public: - /// Known keys of conditions in this container - Keys keys; + /// Known keys of conditions in this container + Keys keys; - /// Add a new key to the conditions access map - void addKey(const std::string& key_value); - /// Add a new key to the conditions access map: Allow for alias if key_val != data_val - void addKey(const std::string& key_value, const std::string& data_value); + /// Add a new key to the conditions access map + void addKey(const std::string& key_value); + /// Add a new key to the conditions access map: Allow for alias if key_val != data_val + void addKey(const std::string& key_value, const std::string& data_value); }; } /* End namespace Interna */ - /// The data class behind a conditions container handle. - /** - * See ConditionsInterna.cpp for the implementation. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class ConditionsLoader { - protected: - typedef Condition::key_type key_type; - typedef Condition::iov_type iov_type; - /// Protected destructor - virtual ~ConditionsLoader(); - public: - /// Addreference count. Use object - virtual void addRef() = 0; - /// Release object. The client may not use any reference any further. - virtual void release() = 0; - /// Access the conditions loading mechanism - virtual Condition get(key_type key, const iov_type& iov) = 0; - /// Access the conditions loading mechanism. Only conditions in the user pool will be accessed. - virtual Condition get(key_type key, const UserPool& pool) = 0; - }; - - - template <typename T> static void copyObject(void* t, const void* s) { - new(t) T(*(const T*)s); - } - template <typename T> static void destructObject(void* p) { - T* t = (T*)p; - t->~T(); - } - /// Generic getter. Specify the exact type, not a polymorph type - template <typename T> T& Block::get() { - if (!grammar || (grammar->type() != typeid(T))) { throw std::bad_cast(); } - return *(T*)pointer; - } - /// Generic getter (const version). Specify the exact type, not a polymorph type - template <typename T> const T& Block::get() const { - if (!grammar || (grammar->type() != typeid(T))) { throw std::bad_cast(); } - return *(T*)pointer; - } - /// Bind data value - template <typename T> T& BlockData::bind() { - this->bind(&BasicGrammar::instance<T>(),copyObject<T>,destructObject<T>); - return *(new(this->pointer) T()); - } - /// Bind grammar and assign value - template <typename T> T& BlockData::set(const std::string& value) { - T& ret = this->bind<T>(); - if ( !value.empty() && !this->fromString(value) ) { - throw std::runtime_error("BlockData::set> Failed to bind type "+ - ::DD4hep::typeName(typeid(T))+" to condition data block."); - } - return ret; - } /// Bind the data of the conditions object to a given format. template <typename T> T& Condition::bind() { Object* o = access(); @@ -277,50 +208,50 @@ namespace DD4hep { } /* End namespace Conditions */ } /* End namespace DD4hep */ -#define DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - namespace DD4hep { namespace Conditions { \ - template x& Condition::bind<x>(); \ - template x& Condition::get<x>(); \ - template const x& Condition::get<x>() const; \ +#define DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ + namespace DD4hep { namespace Conditions { \ + template x& Condition::bind<x>(); \ + template x& Condition::get<x>(); \ + template const x& Condition::get<x>() const; \ }} -#define DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(x) \ +#define DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(x) \ namespace DD4hep{namespace Parsers{int parse(x&, const std::string&){return 1;}}} \ DD4HEP_DEFINE_CONDITIONS_TYPE(x) -#define DD4HEP_DEFINE_EXTERNAL_CONDITIONS_TYPE(x) \ - namespace DD4hep { namespace Conditions { \ - template <> x& Condition::bind<x>(); \ - template <> x& Condition::get<x>(); \ - template <> const x& Condition::get<x>() const; \ +#define DD4HEP_DEFINE_EXTERNAL_CONDITIONS_TYPE(x) \ + namespace DD4hep { namespace Conditions { \ + template <> x& Condition::bind<x>(); \ + template <> x& Condition::get<x>(); \ + template <> const x& Condition::get<x>() const; \ }} #if defined(DD4HEP_HAVE_ALL_PARSERS) -#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::deque<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::ulong_map_t) \ +#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::deque<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::ulong_map_t) \ DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::string_map_t) -#define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_CONT(x) \ +#define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) \ + DD4HEP_DEFINE_CONDITIONS_CONT(x) \ DD4HEP_DEFINE_CONDITIONS_CONT(unsigned x) #else -#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ +#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ + DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::int_map_t) \ DD4HEP_DEFINE_CONDITIONS_TYPE(DD4hep::Primitive<x>::string_map_t) #define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) DD4HEP_DEFINE_CONDITIONS_CONT(x) #endif // DD4HEP_HAVE_ALL_PARSERS -#endif /* DD4HEP_GEOMETRY_CONDITIONINTERNA_H */ +#endif /* DD4HEP_CONDITIONS_CONDITIONINTERNA_H */ diff --git a/DDCore/include/DD4hep/objects/DetectorInterna.h b/DDCore/include/DD4hep/objects/DetectorInterna.h index 0dfafe558a8aa12e5f9ab2d32cee9cbd64976058..04b90a83f3dbc414531757f1a4426798ac424010 100644 --- a/DDCore/include/DD4hep/objects/DetectorInterna.h +++ b/DDCore/include/DD4hep/objects/DetectorInterna.h @@ -11,6 +11,14 @@ // Author : M.Frank // //========================================================================== +// +// NOTE: +// +// This is an internal include file. It should only be included to +// instantiate code. Otherwise the Detector include file should be +// sufficient for all practical purposes. +// +//========================================================================== #ifndef DD4HEP_GEOMETRY_DETECTORINTERNA_H #define DD4HEP_GEOMETRY_DETECTORINTERNA_H @@ -20,7 +28,7 @@ #include "DD4hep/World.h" #include "DD4hep/Objects.h" #include "DD4hep/Detector.h" -#include "DD4hep/Alignment.h" +#include "DD4hep/Alignments.h" #include "DD4hep/Conditions.h" #include "DD4hep/Segmentations.h" #include "DD4hep/ObjectExtensions.h" @@ -87,7 +95,8 @@ namespace DD4hep { typedef std::vector<UpdateCall> UpdateCallbacks; typedef Conditions::Container ConditionsContainer; typedef Conditions::Condition Condition; - typedef Conditions::IOV IOV; + typedef Alignments::Alignment Alignment; + typedef Alignments::Container AlignmentsContainer; enum DetFlags { HAVE_WORLD_TRAFO = 1<<0, @@ -135,16 +144,23 @@ namespace DD4hep { UpdateCallbacks updateCalls; //@{ Additional information set externally to facilitate the processing of event data */ - /// Basic detector element alignment entry - Alignment alignment; + /// Basic ideal/nominal detector element alignment entry + Alignment nominal; /// Basic detector element alignment entry containing the survey data Alignment survey; + /// The detector elements alignments access + AlignmentsContainer alignments; + /// The detector elements conditions access + ConditionsContainer conditions; + + /// Global alignment data + Ref_t global_alignment; + + // To be removed! /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements std::vector<Alignment> volume_alignments; /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements std::vector<Alignment> volume_surveys; - /// The detector elements condition entry - ConditionsContainer conditions; //@} //@{ Cached information of the detector element /// Intermediate buffer to store the transformation to the world coordination system @@ -154,10 +170,11 @@ namespace DD4hep { /// Intermediate buffer for the transformation to an arbitrary DetElement TGeoHMatrix* referenceTrafo; //@} + private: //@{ Private methods used internally by the object itself. */ /// Resolve the world object. Internal use ONLY. - WorldObject* i_access_world(); + World i_access_world(); public: //@{ Public methods to ease the usage of the data. */ @@ -170,8 +187,8 @@ namespace DD4hep { /// Deep object copy to replicate DetElement trees e.g. for reflection virtual DetElementObject* clone(int new_id, int flag) const; /// Access to the world object. Only possible once the geometry is closed. - WorldObject* world() - { return privateWorld.isValid() ? privateWorld.ptr() : i_access_world(); } + World world() + { return privateWorld.isValid() ? privateWorld : i_access_world(); } ConditionsContainer assign_conditions(); //@} /// Create cached matrix to transform to world coordinates @@ -198,36 +215,49 @@ namespace DD4hep { */ class WorldObject: public DetElementObject { public: - typedef Conditions::UserPool UserPool; - typedef Conditions::Condition Condition; + /// Forward type definition of the ConditionsLoader type typedef Conditions::ConditionsLoader ConditionsLoader; + /// Forward type definition of the ConditionsManagerObject type typedef Conditions::ConditionsManagerObject ConditionsManagerObject; + /// Forward type definition of the AlignmentsLoader type + typedef Alignments::AlignmentsLoader AlignmentsLoader; + /// Forward type definition of the AlignmentsManagerObject type + typedef Alignments::AlignmentsManagerObject AlignmentsManagerObject; /// Reference to the LCDD instance object LCDD* lcdd; /// Conditions loader for this LCDD instance - ConditionsLoader* conditionsLoader; + ConditionsLoader* conditionsLoader; /// Reference to the conditions manager object ConditionsManagerObject* conditionsManager; + /// Alignments loader for this LCDD instance + AlignmentsLoader* alignmentsLoader; + + /// Reference to the alignments manager object + AlignmentsManagerObject* alignmentsManager; + public: //@{ Public methods to ease the usage of the data. */ /// Default constructor - WorldObject() : DetElementObject(), lcdd(0), conditionsLoader(0), conditionsManager(0) {} + WorldObject(); #ifndef __CINT__ /// Initializing constructor WorldObject(LCDD& lcdd, const std::string& nam); #endif /// Internal object destructor: release extension object(s) virtual ~WorldObject(); - /// Access the conditions loading - Condition getCondition(Condition::key_type key, const Condition::iov_type& iov) const; - /// Access the conditions loading. Only conditions in the pool are accessed. - Condition getCondition(Condition::key_type key, const UserPool& pool) const; }; + /// Default constructor + inline WorldObject::WorldObject() + : DetElementObject(), lcdd(0), + conditionsLoader(0), conditionsManager(0), alignmentsLoader(0), alignmentsManager(0) + { + } + } /* End namespace Geometry */ } /* End namespace DD4hep */ #endif /* DD4HEP_GEOMETRY_DETECTORINTERNA_H */ diff --git a/DDCore/include/DD4hep/objects/OpaqueData_inl.h b/DDCore/include/DD4hep/objects/OpaqueData_inl.h new file mode 100644 index 0000000000000000000000000000000000000000..bf985da7817814ad5fb99ebe656cb87f51e9ac71 --- /dev/null +++ b/DDCore/include/DD4hep/objects/OpaqueData_inl.h @@ -0,0 +1,67 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// NOTE: +// +// This is an internal include file. It should only be included to +// instantiate code. Otherwise the OpaqueData include file should be +// sufficient for all practical purposes. +// +//========================================================================== +#ifndef DD4HEP_OPAQUEDATA_INL_H +#define DD4HEP_OPAQUEDATA_INL_H + +// Framework include files +#include "DD4hep/OpaqueData.h" +#include "DD4hep/BasicGrammar.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + namespace { + template <typename T> static void opaqueCopyObject(void* t, const void* s) { + new(t) T(*(const T*)s); + } + template <typename T> static void opaqueDestructObject(void* p) { + T* t = (T*)p; + t->~T(); + } + } + /// Generic getter. Specify the exact type, not a polymorph type + template <typename T> T& OpaqueData::get() { + if (!grammar || (grammar->type() != typeid(T))) { throw std::bad_cast(); } + return *(T*)pointer; + } + /// Generic getter (const version). Specify the exact type, not a polymorph type + template <typename T> const T& OpaqueData::get() const { + if (!grammar || (grammar->type() != typeid(T))) { throw std::bad_cast(); } + return *(T*)pointer; + } + /// Bind data value + template <typename T> T& OpaqueDataBlock::bind() { + this->bind(&BasicGrammar::instance<T>(),opaqueCopyObject<T>,opaqueDestructObject<T>); + return *(new(this->pointer) T()); + } + /// Bind grammar and assign value + template <typename T> T& OpaqueDataBlock::set(const std::string& value) { + T& ret = this->bind<T>(); + if ( !value.empty() && !this->fromString(value) ) { + throw std::runtime_error("OpaqueDataBlock::set> Failed to bind type "+ + typeName(typeid(T))+" to condition data block."); + } + return ret; + } + +} /* End namespace DD4hep */ +#endif /* DD4HEP_OPAQUEDATA_INL_H */ diff --git a/DDCore/include/DD4hep/objects/VolumeManagerInterna.h b/DDCore/include/DD4hep/objects/VolumeManagerInterna.h index 92fa27edd46fe89bbbc4ecce75a1e64473ad3ec8..83fdbeab2c19cd91ca133c90cfec02c725b96dd2 100644 --- a/DDCore/include/DD4hep/objects/VolumeManagerInterna.h +++ b/DDCore/include/DD4hep/objects/VolumeManagerInterna.h @@ -11,6 +11,14 @@ // Author : M.Frank // //========================================================================== +// +// NOTE: +// +// This is an internal include file. It should only be included to +// instantiate code. Otherwise the VolumeManager include file should be +// sufficient for all practical purposes. +// +//========================================================================== #ifndef DD4HEP_GEOMETRY_VOLUMEMANAGERINTERNA_H #define DD4HEP_GEOMETRY_VOLUMEMANAGERINTERNA_H diff --git a/DDCore/include/XML/UnicodeValues.h b/DDCore/include/XML/UnicodeValues.h index 70a40dcd848e91d07e9239914e9e83a248ec805c..0d20489c964b4b9e97474fbc474fc3e968adb501 100644 --- a/DDCore/include/XML/UnicodeValues.h +++ b/DDCore/include/XML/UnicodeValues.h @@ -295,6 +295,7 @@ namespace DD4hep { UNICODE (params); UNICODE (parent); UNICODE (particles); + UNICODE (path); UNICODE (phi); UNICODE (phi0); UNICODE (phi0_offset); @@ -304,6 +305,8 @@ namespace DD4hep { UNICODE (phi_size_max); UNICODE (physvol); UNICODE (physvolid); + UNICODE (pivot); + UNICODE (pivot_point); UNICODE (plugin); UNICODE (plugins); UNICODE (point); diff --git a/DDCore/src/AlignmentData.cpp b/DDCore/src/AlignmentData.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec91e71b111d7cfca89cdf374c2e80d0056d3cb0 --- /dev/null +++ b/DDCore/src/AlignmentData.cpp @@ -0,0 +1,196 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/AlignmentData.h" +#include "DD4hep/MatrixHelpers.h" +#include "DD4hep/InstanceCount.h" + +// ROOT include files +#include "TGeoMatrix.h" +#include <sstream> + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Alignments; + +/// Default constructor +Delta::Delta() { +} + +/// Copy constructor +Delta::Delta(const Delta& c) + : pivot(c.pivot), translation(c.translation), rotation(c.rotation) +{ +} + +/// Default destructor +Delta::~Delta() { +} + +/// Assignment operator +Delta& Delta::operator=(const Delta& c) { + if ( &c != this ) { + pivot = c.pivot; + translation = c.translation; + rotation = c.rotation; + } + return *this; +} + +/// Reset information to identity +void Delta::clear() { + pivot = Pivot(); + translation = Position(); + rotation = RotationZYX(); +} + +/// print Conditions object +ostream& operator << (ostream& s, const Delta& data) { + string res; + stringstream str; + str << "[" << data.translation << "," << data.rotation << "," << data.pivot << "]"; + res = str.str(); + for(size_t i=0; i<res.length(); ++i) + if ( res[i]=='\n' ) res[i] = ' '; + return s << res; +} + +/// Standard constructor +AlignmentData::AlignmentData() + : flag(0), magic(magic_word()) +{ + InstanceCount::increment(this); +} + +/// Default destructor +AlignmentData::~AlignmentData() { + InstanceCount::decrement(this); +} + +/// print Conditions object +ostream& operator << (ostream& s, const AlignmentData& data) { + stringstream str; + str << data.delta; + return s << str.str(); +} + +/// Transform a point from local coordinates of a given level to global coordinates +Position AlignmentData::localToWorld(const Position& local) const { + Position global; + Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; + worldTrafo.LocalToMaster(local_point, master_point); + global.SetCoordinates(master_point); + return global; +} + +/// Transformation from local coordinates of the placed volume to the world system +void AlignmentData::localToWorld(const Position& local, Position& global) const { + Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; + worldTrafo.LocalToMaster(local_point, master_point); + global.SetCoordinates(master_point); +} + +/// Transformation from local coordinates of the placed volume to the world system +void AlignmentData::localToWorld(const Double_t local[3], Double_t global[3]) const { + worldTrafo.LocalToMaster(local, global); +} + +/// Transform a point from local coordinates of a given level to global coordinates +Position AlignmentData::worldToLocal(const Position& global) const { + Position local; + // If the path is unknown an exception will be thrown inside worldTransformation() ! + Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 }; + worldTrafo.MasterToLocal(master_point, local_point); + local.SetCoordinates(local_point); + return local; +} + +/// Transformation from world coordinates of the local placed volume coordinates +void AlignmentData::worldToLocal(const Position& global, Position& local) const { + Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 }; + worldTrafo.MasterToLocal(master_point, local_point); + local.SetCoordinates(local_point); +} + +/// Transformation from world coordinates of the local placed volume coordinates +void AlignmentData::worldToLocal(const Double_t global[3], Double_t local[3]) const { + worldTrafo.MasterToLocal(global, local); +} + +/// Transform a point from local coordinates to the coordinates of the DetElement +Position AlignmentData::localToDetector(const Position& local) const { + Position global; + Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; + detectorTrafo.LocalToMaster(local_point, master_point); + global.SetCoordinates(master_point); + return global; +} + +/// Transformation from local coordinates of the placed volume to the detector system +void AlignmentData::localToDetector(const Position& local, Position& global) const { + Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; + detectorTrafo.LocalToMaster(local_point, master_point); + global.SetCoordinates(master_point); +} + +/// Transformation from local coordinates of the placed volume to the detector system +void AlignmentData::localToDetector(const Double_t local[3], Double_t global[3]) const { + detectorTrafo.LocalToMaster(local, global); +} + +/// Transform a point from local coordinates of the DetElement to global coordinates +Position AlignmentData::detectorToLocal(const Position& global) const { + Position local; + // If the path is unknown an exception will be thrown inside worldTransformation() ! + Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 }; + detectorTrafo.MasterToLocal(master_point, local_point); + local.SetCoordinates(local_point); + return local; +} + +/// Transformation from detector element coordinates to the local placed volume coordinates +void AlignmentData::detectorToLocal(const Position& global, Position& local) const { + // If the path is unknown an exception will be thrown inside worldTransformation() ! + Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 }; + detectorTrafo.MasterToLocal(master_point, local_point); + local.SetCoordinates(local_point); +} + +/// Transformation from detector element coordinates to the local placed volume coordinates +void AlignmentData::detectorToLocal(const Double_t global[3], Double_t local[3]) const { + detectorTrafo.MasterToLocal(global, local); +} + +/// Access the ideal/nominal alignment/placement matrix +Alignment AlignmentData::nominal() const { + return detector.nominal(); +} + +/// Default destructor +NamedAlignmentObject::~NamedAlignmentObject() { +} + +#include "DD4hep/Handle.inl" +DD4HEP_INSTANTIATE_HANDLE_NAMED(NamedAlignmentObject); +DD4HEP_INSTANTIATE_HANDLE_UNNAMED(AlignmentData); + +#include "DD4hep/ToStream.h" +#include "DD4hep/objects/ConditionsInterna.h" +DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(Delta) +DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(AlignmentData) + +#include "DD4hep/objects/BasicGrammar_inl.h" +DD4HEP_DEFINE_PARSER_GRAMMAR(Delta,eval_none<Delta>) +DD4HEP_DEFINE_PARSER_GRAMMAR(AlignmentData,eval_none<AlignmentData>) diff --git a/DDCore/src/AlignmentTools.cpp b/DDCore/src/AlignmentTools.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e5e149a36f91738038683926676d520910ff6a39 --- /dev/null +++ b/DDCore/src/AlignmentTools.cpp @@ -0,0 +1,104 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/IOV.h" +#include "DD4hep/Printout.h" +#include "DD4hep/MatrixHelpers.h" +#include "DD4hep/AlignmentTools.h" +#include "DD4hep/DetectorTools.h" +#include "DD4hep/objects/DetectorInterna.h" + +// ROOT include files +#include "TGeoMatrix.h" + +using DD4hep::Geometry::DetElement; +using DD4hep::Geometry::PlacedVolume; +using DD4hep::Alignments::Alignment; +using DD4hep::Alignments::AlignmentData; +namespace DetectorTools = DD4hep::Geometry::DetectorTools; +typedef AlignmentData::MaskManipulator MaskManipulator; + +/// Compute the ideal/nominal to-world transformation from the detector element placement +void DD4hep::Alignments::AlignmentTools::computeIdeal(Alignment alignment) { + Alignment::Object* a = alignment.ptr(); + MaskManipulator mask(a->flag); + DetElement parent = a->detector.parent(); + if ( parent.isValid() ) { + DetectorTools::PlacementPath path; + DetectorTools::placementPath(parent, a->detector, path); + for (size_t i = 0, n=path.size(); n>0 && i < n-1; ++i) { + const PlacedVolume& p = path[i]; + a->detectorTrafo.MultiplyLeft(p->GetMatrix()); + } + a->worldTrafo = parent.nominal()->worldTrafo; + a->worldTrafo.MultiplyLeft(&a->detectorTrafo); + a->trToWorld = _transform(&a->worldTrafo); + a->placement = a->detector.placement(); + mask.set(AlignmentData::IDEAL); + } +} + +/// Compute the ideal/nominal to-world transformation from the detector element placement +void DD4hep::Alignments::AlignmentTools::computeIdeal(Alignment alignment, + const Alignment::NodeList& node_list) +{ + Alignment::Object* a = alignment.ptr(); + MaskManipulator mask(a->flag); + a->nodes = node_list; + for (size_t i = a->nodes.size(); i > 1; --i) { // Omit the placement of the parent DetElement + TGeoMatrix* m = a->nodes[i - 1]->GetMatrix(); + a->worldTrafo.MultiplyLeft(m); + } + DetElement::Object* det = a->detector.ptr(); + if ( !a->nodes.empty() ) { + a->detectorTrafo = a->worldTrafo; + a->detectorTrafo.MultiplyLeft(a->nodes[0]->GetMatrix()); + a->placement = node_list.back(); + } + else { + a->placement = det->placement; + } + a->worldTrafo.MultiplyLeft(&(a->detector.nominal()->worldTrafo)); + a->trToWorld = _transform(&a->worldTrafo); + mask.set(AlignmentData::IDEAL); +} + + +/// Compute the survey to-world transformation from the detector element placement with respect to the survey constants +void DD4hep::Alignments::AlignmentTools::computeSurvey(Alignment alignment) +{ + Alignment::Object* a = alignment.ptr(); + DetElement parent = a->detector.parent(); + MaskManipulator mask(a->flag); + + if ( parent.isValid() ) { + DetectorTools::PlacementPath path; + DetectorTools::placementPath(parent, a->detector, path); + + // TODO: need to take survey corrections into account! + + for (size_t i = 0, n=path.size(); n>0 && i < n-1; ++i) { + const PlacedVolume& p = path[i]; + a->detectorTrafo.MultiplyLeft(p->GetMatrix()); + } + a->worldTrafo = parent.survey()->worldTrafo; + a->worldTrafo.MultiplyLeft(&a->detectorTrafo); + a->trToWorld = _transform(&a->worldTrafo); + a->placement = a->detector.placement(); + } + mask.set(AlignmentData::SURVEY); + //mask.clear(AlignmentData::INVALID|AlignmentData::DIRTY); + //mask.set(AlignmentData::VALID|AlignmentData::IDEAL); +} diff --git a/DDCore/src/Alignments.cpp b/DDCore/src/Alignments.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69288f595230d004083d875e2ffa730995857dd0 --- /dev/null +++ b/DDCore/src/Alignments.cpp @@ -0,0 +1,93 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/AlignmentData.h" +#include "DD4hep/objects/AlignmentsInterna.h" + +// C/C++ include files +#include <sstream> + +using namespace std; +using namespace DD4hep::Alignments; + +/// Default constructor +Alignment::Alignment() : Handle<Object>() { +} + +/// Initializing constructor to create a new object +Alignment::Alignment(const string& nam) { + m_element = new NamedAlignmentObject(nam, "alignment"); +} + +/// Access the number of conditons keys available for this detector element +size_t Container::numKeys() const { + return access()->keys.size(); +} + +/// Access to alignment objects +Alignment Container::get(const string& alignment_key, const iov_type& iov) { + Object* o = ptr(); + if ( o ) { + Alignment c = o->get(alignment_key, iov); + if ( c.isValid() ) { + return c; + } + invalidHandleError<Alignment>(); + } + invalidHandleError<Container>(); + return Alignment(); +} + +/// Access to alignment objects +Alignment Container::get(key_type alignment_key, const iov_type& iov) { + Object* o = ptr(); + if ( o ) { + Alignment c = o->get(alignment_key, iov); + if ( c.isValid() ) { + return c; + } + invalidHandleError<Alignment>(); + } + invalidHandleError<Container>(); + return Alignment(); +} + +/// Access to alignment objects +Alignment Container::get(const string& alignment_key, const UserPool& pool) { + Object* o = ptr(); + if ( o ) { + Alignment c = o->get(alignment_key, pool); + if ( c.isValid() ) { + return c; + } + invalidHandleError<Alignment>(); + } + invalidHandleError<Container>(); + return Alignment(); +} + +/// Access to alignment objects +Alignment Container::get(key_type alignment_key, const UserPool& pool) { + Object* o = ptr(); + if ( o ) { + Alignment c = o->get(alignment_key, pool); + if ( c.isValid() ) { + return c; + } + invalidHandleError<Alignment>(); + } + invalidHandleError<Container>(); + return Alignment(); +} diff --git a/DDCore/src/AlignmentsInterna.cpp b/DDCore/src/AlignmentsInterna.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8683623f3e78d5e32ceb86be62fcb02a3866bd09 --- /dev/null +++ b/DDCore/src/AlignmentsInterna.cpp @@ -0,0 +1,136 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework includes +#include "DD4hep/IOV.h" +#include "DD4hep/Handle.inl" + +#include "DD4hep/World.h" +#include "DD4hep/Printout.h" +#include "DD4hep/InstanceCount.h" +#include "DD4hep/objects/DetectorInterna.h" +#include "DD4hep/objects/AlignmentsInterna.h" + +using namespace std; +using namespace DD4hep::Alignments; +using namespace DD4hep::Alignments::Interna; + +DD4HEP_INSTANTIATE_HANDLE_NAMED(AlignmentConditionObject); +DD4HEP_INSTANTIATE_HANDLE_NAMED(AlignmentContainer); + +/// Standard constructor +AlignmentConditionObject::AlignmentConditionObject(const string& nam, const string& tit) + : ConditionObject(nam, tit), AlignmentData() +{ + InstanceCount::increment(this); +} + +/// Standard Destructor +AlignmentConditionObject::~AlignmentConditionObject() { + InstanceCount::decrement(this); +} + +/// Clear data content on demand. +void AlignmentConditionObject::clear() { + trToWorld = Transform3D(); + detectorTrafo.Clear(); + worldTrafo.Clear(); + nodes.clear(); + flags = 0; +} + +/// Standard constructor +AlignmentContainer::AlignmentContainer(Geometry::DetElementObject* par) + : NamedObject(), detector(par), keys() +{ + InstanceCount::increment(this); +} + +/// Default destructor +AlignmentContainer::~AlignmentContainer() { + InstanceCount::decrement(this); +} + +/// Add a new key to the alignments access map +void AlignmentContainer::addKey(const string& key_val) { + key_type hash = Alignment::hashCode(key_val); + if ( !keys.insert(make_pair(hash,make_pair(hash,key_val))).second ) { + except("AlignmentContainer","++ Key[%08X]: %s already present. " + "Duplicate insertions inhibited!",hash, key_val.c_str()); + } +} + +/// Add a new key to the alignments access map: Allow for alias if key_val != data_val +void AlignmentContainer::addKey(const string& key_val, const string& data_val) { + key_type key_hash = Alignment::hashCode(key_val); + key_type val_hash = Alignment::hashCode(data_val); + if ( !keys.insert(make_pair(key_hash,make_pair(val_hash,data_val))).second ) { + except("AlignmentContainer","++ Key[%08X]: %s already present. " + "Duplicate insertions inhibited!",key_hash, key_val.c_str()); + } +} + +/// Access to alignment objects directly by their hash key. +Alignment AlignmentContainer::get(const string& key_val, const iov_type& iov) { + AlignmentsLoader& loader = detector->world().alignmentsLoader(); + key_type hash = Alignment::hashCode(key_val); + Keys::const_iterator i=keys.find(hash); + if ( i != keys.end() ) { + const key_value& k = (*i).second; + return loader.get(k.first, iov); + } + /// Last resort: Assume the key value is globally known: + return loader.get(hash, iov); +} + +/// Access to alignment objects directly by their hash key. +Alignment AlignmentContainer::get(key_type hash_key, const iov_type& iov) { + AlignmentsLoader& loader = detector->world().alignmentsLoader(); + Keys::const_iterator i=keys.find(hash_key); + if ( i != keys.end() ) { + const key_value& k = (*i).second; + return loader.get(k.first, iov); + } + /// Last resort: Assume the key value is globally known: + return loader.get(hash_key, iov); +} + +/// Access to alignment objects directly by their hash key. +Alignment AlignmentContainer::get(const string& key_val, const UserPool& pool) { + AlignmentsLoader& loader = detector->world().alignmentsLoader(); + key_type hash = Alignment::hashCode(key_val); + Keys::const_iterator i=keys.find(hash); + if ( i != keys.end() ) { + const key_value& k = (*i).second; + return loader.get(k.first, pool); + } + /// Last resort: Assume the key value is globally known: + return loader.get(hash, pool); +} + +/// Access to alignment objects directly by their hash key. +Alignment AlignmentContainer::get(key_type hash_key, const UserPool& pool) { + AlignmentsLoader& loader = detector->world().alignmentsLoader(); + Keys::const_iterator i=keys.find(hash_key); + if ( i != keys.end() ) { + const key_value& k = (*i).second; + return loader.get(k.first, pool); + } + /// Last resort: Assume the key value is globally known: + return loader.get(hash_key, pool); +} + +/// Protected destructor +AlignmentsLoader::~AlignmentsLoader() { +} diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp index 879cc8a84bfedf227eebaa5e8bda971332cbb81f..7232965191113d843043cf0b73ba11bc045c9ea9 100644 --- a/DDCore/src/ConditionDerived.cpp +++ b/DDCore/src/ConditionDerived.cpp @@ -31,15 +31,15 @@ ConditionResolver::~ConditionResolver() { /// Default constructor ConditionDependency::ConditionDependency(const ConditionKey& tar, - const Dependencies deps, - ConditionUpdateCall* call) + const Dependencies deps, + ConditionUpdateCall* call) : target(tar), dependencies(deps), callback(call) { } /// Default constructor ConditionDependency::ConditionDependency(const ConditionKey& tar, - ConditionUpdateCall* call) + ConditionUpdateCall* call) : target(tar), callback(call) { } @@ -53,8 +53,8 @@ ConditionDependency::ConditionDependency(const ConditionDependency& c) : target(c.target), dependencies(c.dependencies) { except("Dependency", - "++ Condition: %s. Dependencies may not be assigned or copied!", - target.name.c_str()); + "++ Condition: %s. Dependencies may not be assigned or copied!", + target.name.c_str()); } /// Default destructor @@ -64,8 +64,8 @@ ConditionDependency::~ConditionDependency() { /// Assignment operator ConditionDependency& ConditionDependency::operator=(const ConditionDependency& ) { except("Dependency", - "++ Condition: %s. Dependencies may not be assigned or copied!", - target.name.c_str()); + "++ Condition: %s. Dependencies may not be assigned or copied!", + target.name.c_str()); return *this; } diff --git a/DDCore/src/Conditions.cpp b/DDCore/src/Conditions.cpp index 6a55438cffaa729f6cfac00d2304d3a219851f37..7afea27432620db310af7b18f2d806d0740ab0af 100644 --- a/DDCore/src/Conditions.cpp +++ b/DDCore/src/Conditions.cpp @@ -24,198 +24,22 @@ using namespace std; using namespace DD4hep::Conditions; -std::string IOVType::str() const { - char text[256]; - ::snprintf(text,sizeof(text),"%s(%d)",name.c_str(),int(type)); - return text; -} - -/// Initializing constructor: Does not set reference to IOVType ! -IOV::IOV() : iovType(0), keyData(0,0), optData(0) { - type = int(IOVType::UNKNOWN_IOV); -} - -/// Initializing constructor -IOV::IOV(const IOVType* t) : iovType(t), keyData(0,0), optData(0) { - type = t ? t->type : int(IOVType::UNKNOWN_IOV); -} - -/// Copy constructor -IOV::IOV(const IOV& c) - : iovType(c.iovType), keyData(c.keyData), optData(c.optData), type(c.type) -{ -} - -/// Copy constructor -IOV::IOV(const IOVType* t, const Key& k) - : iovType(t), keyData(k), optData(0) -{ - type = t ? t->type : int(IOVType::UNKNOWN_IOV); -} - -/// Standard Destructor -IOV::~IOV() { -} - -/// Set discrete IOV value -void IOV::set(const Key& value) { - keyData = value; -} - -/// Set discrete IOV value -void IOV::set(Key::first_type value) { - keyData.first = keyData.second = value; -} - -/// Set range IOV value -void IOV::set(Key::first_type val_1, Key::second_type val_2) { - keyData.first = val_1; - keyData.second = val_2; -} - -/// Set keys to unphysical values (LONG_MAX, LONG_MIN) -IOV& IOV::reset() { - keyData.first = LONG_MAX; - keyData.second = LONG_MIN; - return *this; -} - -/// Set keys to unphysical values (LONG_MAX, LONG_MIN) -IOV& IOV::invert() { - Key::first_type tmp = keyData.first; - keyData.first = keyData.second; - keyData.second = tmp; - return *this; -} - -void IOV::iov_intersection(const IOV& validity) { - if ( !iovType ) - *this = validity; - else if ( validity.keyData.first > keyData.first ) - keyData.first = validity.keyData.first; - if ( validity.keyData.second < keyData.second ) - keyData.second = validity.keyData.second; -} - -void IOV::iov_intersection(const IOV::Key& validity) { - if ( validity.first > keyData.first ) - keyData.first = validity.first; - if ( validity.second < keyData.second ) - keyData.second = validity.second; -} - -void IOV::iov_union(const IOV& validity) { - if ( !iovType ) - *this = validity; - else if ( validity.keyData.first < keyData.first ) - keyData.first = validity.keyData.first; - if ( validity.keyData.second > keyData.second ) - keyData.second = validity.keyData.second; -} - -void IOV::iov_union(const IOV::Key& validity) { - if ( validity.first < keyData.first ) - keyData.first = validity.first; - if ( validity.second > keyData.second ) - keyData.second = validity.second; -} - -/// Move the data content: 'from' will be reset to NULL -void IOV::move(IOV& from) { - ::memcpy(this,&from,sizeof(IOV)); - from.keyData.first = from.keyData.second = from.optData = 0; - from.type = int(IOVType::UNKNOWN_IOV); - from.iovType = 0; -} - -/// Create string representation of the IOV -string IOV::str() const { - char text[256]; - if ( iovType ) { - if ( iovType->name[0] != 'e' ) { - ::snprintf(text,sizeof(text),"%s(%d):[%ld-%ld]", - iovType->name.c_str(),int(iovType->type),keyData.first, keyData.second); - } - else if ( iovType->name == "epoch" ) { - time_t since = keyData.first; - time_t until = keyData.second; - char c_since[64], c_until[64]; - struct tm time_buff; - ::strftime(c_since,sizeof(c_since),"%d-%m-%Y %H:%M:%S",::gmtime_r(&since,&time_buff)); - ::strftime(c_until,sizeof(c_until),"%d-%m-%Y %H:%M:%S",::gmtime_r(&until,&time_buff)); - ::snprintf(text,sizeof(text),"%s(%d):[%s-%s]", - iovType->name.c_str(),iovType->type, - c_since, c_until); - } - else { - ::snprintf(text,sizeof(text),"%s(%d):[%ld-%ld]", - iovType->name.c_str(),int(iovType->type),keyData.first, keyData.second); - } - } - else { - ::snprintf(text,sizeof(text),"%d:[%ld-%ld]",type,keyData.first, keyData.second); - } - return text; -} - -/// Check for validity containment -bool IOV::contains(const IOV& iov) const { - if ( key_is_contained(iov.keyData,keyData) ) { - unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type; - unsigned int typ2 = iovType ? iovType->type : type; - return typ1 == typ2; - } - return false; -} - -/// Standard initializing constructor -Block::Block() : grammar(0), pointer(0) { -} - -/// Standard Destructor -Block::~Block() { -} - -/// Create data block from string representation -bool Block::fromString(const string& rep) { - if ( pointer && grammar ) { - return grammar->fromString(pointer,rep); - } - throw runtime_error("Conditions data block is unbound. Cannot parse string representation."); -} - -/// Create string representation of the data block -string Block::str() const { - if ( pointer && grammar ) { - return grammar->str(pointer); - } - throw runtime_error("Conditions data block is unbound. Cannot create string representation."); -} - -/// Access type id of the condition -const std::type_info& Block::typeInfo() const { - if ( pointer && grammar ) { - return grammar->type(); - } - throw runtime_error("Conditions data block is unbound. Cannot determine type information!"); -} - -/// Access type name of the condition data block -const std::string& Block::dataType() const { - if ( pointer && grammar ) { - return grammar->type_name(); - } - throw runtime_error("Conditions data block is unbound. Cannot determine type information!"); +/// Access the key of the condition +ConditionKey DD4hep::Conditions::make_key(Condition c) { + Condition::Object* p = c.ptr(); + if ( p ) return ConditionKey(p->name,p->hash); + invalidHandleError<Condition>(); + return ConditionKey(); } /// Constructor from string -ConditionKey::ConditionKey(const std::string& value) +ConditionKey::ConditionKey(const string& value) : name(value), hash(hashCode(value)) { } /// Assignment operator from the string representation -ConditionKey& ConditionKey::operator=(const std::string& value) { +ConditionKey& ConditionKey::operator=(const string& value) { ConditionKey key(value); hash = hashCode(value); name = value; @@ -223,7 +47,7 @@ ConditionKey& ConditionKey::operator=(const std::string& value) { } /// Operator less (for map insertions) using the string representation -bool ConditionKey::operator<(const std::string& compare) const { +bool ConditionKey::operator<(const string& compare) const { return hash < hashCode(compare); } @@ -241,7 +65,7 @@ Condition& Condition::operator=(const Condition& c) { } /// Output method -std::string Condition::str(int flags) const { +string Condition::str(int flags) const { stringstream output; Object* o = access(); const IOV* ptr_iov = o->iovData(); @@ -268,17 +92,17 @@ int Condition::dataType() const { } /// Access the IOV block -Block& Condition::block() const { +DD4hep::OpaqueData& Condition::data() const { return access()->data; } /// Access the IOV type -const IOVType& Condition::iovType() const { +const DD4hep::IOVType& Condition::iovType() const { return *(access()->iovType()); } /// Access the IOV block -const IOV& Condition::iov() const { +const DD4hep::IOV& Condition::iov() const { return *(access()->iovData()); } @@ -307,12 +131,6 @@ const string& Condition::address() const { return access()->address; } -/// Access the key of the condition -ConditionKey Condition::key() const { - Object* o = access(); - return ConditionKey(o->name,o->hash); -} - /// Access to the type information const type_info& Condition::typeInfo() const { return descriptor().type(); @@ -358,7 +176,7 @@ size_t Container::numKeys() const { } /// Access to condition objects -Condition Container::get(const std::string& condition_key, const iov_type& iov) { +Condition Container::get(const string& condition_key, const iov_type& iov) { Object* o = ptr(); if ( o ) { Condition c = o->get(condition_key, iov); @@ -386,7 +204,7 @@ Condition Container::get(key_type condition_key, const iov_type& iov) { } /// Access to condition objects -Condition Container::get(const std::string& condition_key, const UserPool& pool) { +Condition Container::get(const string& condition_key, const UserPool& pool) { Object* o = ptr(); if ( o ) { Condition c = o->get(condition_key, pool); diff --git a/DDCore/src/ConditionsData.cpp b/DDCore/src/ConditionsData.cpp index 93138174191f8e125ab30da6cac87ea732548fc3..d0e2d5207cd1b0b8d480a6218b79e9a3ab486ef9 100644 --- a/DDCore/src/ConditionsData.cpp +++ b/DDCore/src/ConditionsData.cpp @@ -20,53 +20,15 @@ using namespace DD4hep::Conditions; -/// print Conditions object -std::ostream& operator << (std::ostream& s, const AlignmentDelta& data) { - std::string res; - std::stringstream str; - str << "[" << data.position << "," << data.rotation << "," << data.pivot << "]"; - res = str.str(); - for(size_t i=0; i<res.length(); ++i) - if ( res[i]=='\n' ) res[i] = ' '; - return s << res; -} - -/// Default constructor -AlignmentDelta::AlignmentDelta() { - InstanceCount::increment(this); -} - -/// Copy constructor -AlignmentDelta::AlignmentDelta(const AlignmentDelta& c) - : pivot(c.pivot), position(c.position), rotation(c.rotation) -{ - InstanceCount::increment(this); -} - -/// Default destructor -AlignmentDelta::~AlignmentDelta() { - InstanceCount::decrement(this); -} - -/// Assignment operator -AlignmentDelta& AlignmentDelta::operator=(const AlignmentDelta& c) { - if ( &c != this ) { - pivot = c.pivot; - position = c.position; - rotation = c.rotation; - } - return *this; -} - /// print Conditions object std::ostream& operator << (std::ostream& s, const AbstractMap& data) { struct _Print { void operator()(const AbstractMap::Params::value_type& obj) const { const AbstractMap& d= obj.second.get<AbstractMap>(); DD4hep::printout(DD4hep::INFO,"Condition","++ %-16s [%d] %-8s -> %s", - obj.first.c_str(), d.classID, - obj.second.dataType().c_str(), - obj.second.str().c_str()); + obj.first.c_str(), d.classID, + obj.second.dataType().c_str(), + obj.second.str().c_str()); } }; if ( !data.params.empty() ) { @@ -111,8 +73,7 @@ AbstractMap& AbstractMap::operator=(const AbstractMap& c) { #include "DD4hep/ToStream.h" #include "DD4hep/objects/ConditionsInterna.h" DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(AbstractMap) -DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(AlignmentDelta) #include "DD4hep/objects/BasicGrammar_inl.h" DD4HEP_DEFINE_PARSER_GRAMMAR(AbstractMap,eval_none<AbstractMap>) -DD4HEP_DEFINE_PARSER_GRAMMAR(AlignmentDelta,eval_none<AlignmentDelta>) + diff --git a/DDCore/src/ConditionsInterna.cpp b/DDCore/src/ConditionsInterna.cpp index a120b3e2f8088810226b221aed76c094c6e1aecb..3e551ba6908e290e93a31c75bf77663595eea617 100644 --- a/DDCore/src/ConditionsInterna.cpp +++ b/DDCore/src/ConditionsInterna.cpp @@ -13,6 +13,7 @@ //========================================================================== // Framework includes +#include "DD4hep/IOV.h" #include "DD4hep/Handle.inl" #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" @@ -25,110 +26,9 @@ using namespace DD4hep::Conditions; DD4HEP_INSTANTIATE_HANDLE_NAMED(Interna::ConditionObject); DD4HEP_INSTANTIATE_HANDLE_NAMED(Interna::ConditionContainer); -/// Standard initializing constructor -BlockData::BlockData() : Block(), destruct(0), copy(0), type(0) { - InstanceCount::increment(this); -} - -/// Copy constructor -BlockData::BlockData(const BlockData& c) - : Block(c), destruct(c.destruct), copy(c.copy), type(c.type) { - grammar = 0; - pointer = 0; - this->bind(c.grammar,c.copy,c.destruct); - this->copy(pointer,c.pointer); - InstanceCount::increment(this); -} - -/// Standard Destructor -BlockData::~BlockData() { - if ( destruct ) { - (*destruct)(pointer); - if ( (type&ALLOC_DATA) == ALLOC_DATA ) ::operator delete(pointer); - } - pointer = 0; - grammar = 0; - InstanceCount::decrement(this); -} - -/// Move the data content: 'from' will be reset to NULL -bool BlockData::move(BlockData& from) { - pointer = from.pointer; - grammar = from.grammar; - ::memcpy(data,from.data,sizeof(data)); - destruct = from.destruct; - copy = from.copy; - type = from.type; - ::memset(from.data,0,sizeof(data)); - from.type = PLAIN_DATA; - from.destruct = 0; - from.copy = 0; - from.pointer = 0; - from.grammar = 0; - return true; -} - -/// Copy constructor -BlockData& BlockData::operator=(const BlockData& c) { - if ( this != &c ) { - if ( this->grammar == c.grammar ) { - if ( destruct ) { - (*destruct)(pointer); - if ( (type&ALLOC_DATA) == ALLOC_DATA ) ::operator delete(pointer); - } - pointer = 0; - grammar = 0; - } - if ( this->grammar == 0 ) { - this->Block::operator=(c); - this->destruct = c.destruct; - this->copy = c.copy; - this->type = c.type; - this->grammar = 0; - this->bind(c.grammar,c.copy,c.destruct); - this->copy(pointer,c.pointer); - return *this; - } - except("Conditions","You may not bind condition data multiple times!"); - } - return *this; -} - -/// Set data value -bool BlockData::bind(const BasicGrammar* g, void (*ctor)(void*,const void*), void (*dtor)(void*)) { - if ( !grammar ) { - size_t len = g->sizeOf(); - grammar = g; - destruct = dtor; - copy = ctor; - (len > sizeof(data)) - ? (pointer=::operator new(len),type=ALLOC_DATA) - : (pointer=data,type=PLAIN_DATA); - return true; - } - else if ( grammar == g ) { - // We cannot ingore secondary requests for data bindings. - // This leads to memory leaks in the caller! - except("Conditions","You may not bind conditions multiple times!"); - } - typeinfoCheck(grammar->type(),g->type(),"Conditions data blocks may not be assigned."); - return false; -} - -/// Set data value -void BlockData::assign(const void* ptr, const type_info& typ) { - if ( !grammar ) { - throw runtime_error("Conditions data block is unbound. Cannot copy data."); - } - else if ( grammar->type() != typ ) { - throw runtime_error("bad binding"); - } - (*copy)(pointer,ptr); -} - /// Standard constructor -Interna::ConditionObject::ConditionObject() - : NamedObject(), value(), validity(), address(), comment(), +Interna::ConditionObject::ConditionObject(const string& nam,const string& tit) + : NamedObject(nam, tit), value(), validity(), address(), comment(), data(), pool(0), iov(0), hash(0), flags(0), refCount(0) { @@ -153,7 +53,7 @@ const Condition::iov_type* Interna::ConditionObject::iovData() const { } /// Access safely the IOV-type -const IOVType* Interna::ConditionObject::iovType() const { +const DD4hep::IOVType* Interna::ConditionObject::iovType() const { if ( iov && iov->iovType ) return iov->iovType; invalidHandleError<IOVType>(); return 0; @@ -190,48 +90,52 @@ void Interna::ConditionContainer::addKey(const string& key_val, const string& da /// Access to condition objects directly by their hash key. Condition Interna::ConditionContainer::get(const string& key_val, const iov_type& iov) { + ConditionsLoader& loader = detector->world().conditionsLoader(); key_type hash = ConditionKey::hashCode(key_val); Keys::const_iterator i=keys.find(hash); if ( i != keys.end() ) { const key_value& k = (*i).second; - return detector->world()->getCondition(k.first, iov); + return loader.get(k.first, iov); } /// Last resort: Assume the key value is globally known: - return detector->world()->getCondition(hash, iov); + return loader.get(hash, iov); } /// Access to condition objects directly by their hash key. Condition Interna::ConditionContainer::get(key_type hash_key, const iov_type& iov) { + ConditionsLoader& loader = detector->world().conditionsLoader(); Keys::const_iterator i=keys.find(hash_key); if ( i != keys.end() ) { const key_value& k = (*i).second; - return detector->world()->getCondition(k.first, iov); + return loader.get(k.first, iov); } /// Last resort: Assume the key value is globally known: - return detector->world()->getCondition(hash_key, iov); + return loader.get(hash_key, iov); } /// Access to condition objects directly by their hash key. Condition Interna::ConditionContainer::get(const string& key_val, const UserPool& pool) { + ConditionsLoader& loader = detector->world().conditionsLoader(); key_type hash = ConditionKey::hashCode(key_val); Keys::const_iterator i=keys.find(hash); if ( i != keys.end() ) { const key_value& k = (*i).second; - return detector->world()->getCondition(k.first, pool); + return loader.get(k.first, pool); } /// Last resort: Assume the key value is globally known: - return detector->world()->getCondition(hash, pool); + return loader.get(hash, pool); } /// Access to condition objects directly by their hash key. Condition Interna::ConditionContainer::get(key_type hash_key, const UserPool& pool) { + ConditionsLoader& loader = detector->world().conditionsLoader(); Keys::const_iterator i=keys.find(hash_key); if ( i != keys.end() ) { const key_value& k = (*i).second; - return detector->world()->getCondition(k.first, pool); + return loader.get(k.first, pool); } /// Last resort: Assume the key value is globally known: - return detector->world()->getCondition(hash_key, pool); + return loader.get(hash_key, pool); } /// Protected destructor diff --git a/DDCore/src/DetAlign.cpp b/DDCore/src/DetAlign.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc9b9f9286d5cf7e8387913671ed81b72b67e106 --- /dev/null +++ b/DDCore/src/DetAlign.cpp @@ -0,0 +1,71 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DD4hep/objects/DetectorInterna.h" +#include "DD4hep/objects/AlignmentsInterna.h" +#include "DD4hep/DetAlign.h" +#include "DD4hep/World.h" +#include "DD4hep/LCDD.h" + +using namespace std; +using namespace DD4hep::Alignments; + + +/// Access to the alignment information +Alignment DetAlign::nominal() const { + return access()->nominal; +} + +/// Access to the survey alignment information +Alignment DetAlign::survey() const { + return access()->survey; +} + +/// Check if alignments are at all present +bool DetAlign::hasAlignments() const { + Object* o = access(); + if ( o->alignments.isValid() && !o->alignments->keys.empty() ) + return true; + return false; +} + +/// Access to the alignments information +Container DetAlign::alignments() const { + Object* o = access(); + if ( o->alignments.isValid() ) return o->alignments; + o->alignments.assign(new Container::Object(o),"alignments",""); + return o->alignments; +} + +/// Access to alignment objects. +Alignment DetAlign::get(const std::string& key, const Alignment::iov_type& iov) { + return alignments().get(key, iov); +} + +/// Access to alignment objects. +Alignment DetAlign::get(Alignment::key_type key, const Alignment::iov_type& iov) { + return alignments().get(key, iov); +} + +/// Access to alignment objects from a given pool. Only alignments in the pool are accessed. +Alignment DetAlign::get(const std::string& key, const UserPool& pool) { + return alignments().get(key, pool); +} + +/// Access to alignment objects from a given pool. Only alignments in the pool are accessed. +Alignment DetAlign::get(Alignment::key_type key, const UserPool& pool) { + return alignments().get(key, pool); +} + diff --git a/DDCore/src/Detector.cpp b/DDCore/src/Detector.cpp index 59faaaa6262fc6aa444bbf5f31c2c79fc528fa86..b70db92afc09aead0c1f6dfbe73d6e5a368cb9e0 100644 --- a/DDCore/src/Detector.cpp +++ b/DDCore/src/Detector.cpp @@ -15,12 +15,14 @@ // Framework include files #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/AlignmentTools.h" #include "DD4hep/DetectorTools.h" #include "DD4hep/World.h" #include "DD4hep/LCDD.h" using namespace std; using namespace DD4hep::Geometry; +using DD4hep::Alignments::Alignment; /// Clone constructor DetElement::DetElement(Object* det_data, const string& det_name, const string& det_type) @@ -131,13 +133,21 @@ DetElement& DetElement::setCombineHits(bool value, SensitiveDetector& sens) { } /// Access to the alignment information -Alignment DetElement::alignment() const { - return access()->alignment; +Alignment DetElement::nominal() const { + Object* o = access(); + if ( !o->nominal.isValid() ) { + o->nominal = Alignment("nominal"); + o->nominal->detector = *this; + DD4hep::Alignments::AlignmentTools::computeIdeal(o->nominal); + } + return o->nominal; } /// Access to the survey alignment information -Alignment DetElement::surveyAlignment() const { - return access()->survey; +Alignment DetElement::survey() const { + Object* o = access(); + if ( !o->survey.isValid() ) return nominal(); + return o->survey; } const DetElement::Children& DetElement::children() const { @@ -263,7 +273,7 @@ DetElement& DetElement::setAttributes(const LCDD& lcdd, const Volume& vol, const const string& vis) { return setRegion(lcdd, region, vol).setLimitSet(lcdd, limits, vol).setVisAttributes(lcdd, vis, vol); } - +#if 0 /// Set detector element for reference transformations. Will delete existing reference trafo. DetElement& DetElement::setReference(DetElement reference) { Object& o = object<Object>(); @@ -275,6 +285,30 @@ DetElement& DetElement::setReference(DetElement reference) { return *this; } +/// Create cached matrix to transform to reference coordinates +const TGeoHMatrix& DetElement::referenceTransformation() const { + return access()->referenceTransformation(); +} + +/// Transformation from local coordinates of the placed volume to arbitrary parent system set as reference +bool DetElement::localToReference(const Position& local, Position& global) const { + // If the path is unknown an exception will be thrown inside referenceTransformation() ! + Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; + referenceTransformation().LocalToMaster(local_point, master_point); + global.SetCoordinates(master_point); + return true; +} + +/// Transformation from arbitrary parent system coordinates of the local placed volume coordinates +bool DetElement::referenceToLocal(const Position& global, Position& local) const { + // If the path is unknown an exception will be thrown inside referenceTransformation() ! + Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 }; + referenceTransformation().MasterToLocal(master_point, local_point); + local.SetCoordinates(local_point); + return true; +} +#endif + /// Create cached matrix to transform to world coordinates const TGeoHMatrix& DetElement::worldTransformation() const { return access()->worldTransformation(); @@ -285,11 +319,6 @@ const TGeoHMatrix& DetElement::parentTransformation() const { return access()->parentTransformation(); } -/// Create cached matrix to transform to reference coordinates -const TGeoHMatrix& DetElement::referenceTransformation() const { - return access()->referenceTransformation(); -} - /// Transformation from local coordinates of the placed volume to the world system bool DetElement::localToWorld(const Position& local, Position& global) const { Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; @@ -308,15 +337,6 @@ bool DetElement::localToParent(const Position& local, Position& global) const { return true; } -/// Transformation from local coordinates of the placed volume to arbitrary parent system set as reference -bool DetElement::localToReference(const Position& local, Position& global) const { - // If the path is unknown an exception will be thrown inside referenceTransformation() ! - Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; - referenceTransformation().LocalToMaster(local_point, master_point); - global.SetCoordinates(master_point); - return true; -} - /// Transformation from world coordinates of the local placed volume coordinates bool DetElement::worldToLocal(const Position& global, Position& local) const { // If the path is unknown an exception will be thrown inside worldTransformation() ! @@ -335,15 +355,6 @@ bool DetElement::parentToLocal(const Position& global, Position& local) const { return true; } -/// Transformation from arbitrary parent system coordinates of the local placed volume coordinates -bool DetElement::referenceToLocal(const Position& global, Position& local) const { - // If the path is unknown an exception will be thrown inside referenceTransformation() ! - Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 }; - referenceTransformation().MasterToLocal(master_point, local_point); - local.SetCoordinates(local_point); - return true; -} - /// Constructor SensitiveDetector::SensitiveDetector(const string& nam, const string& typ) { /* diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp index 220d21b50392ae7e9cbcc8165f39db8662d7ccbc..3eb4605915073c12dc6452930e7ddd2498b335a1 100644 --- a/DDCore/src/DetectorInterna.cpp +++ b/DDCore/src/DetectorInterna.cpp @@ -14,6 +14,7 @@ // Framework include files #include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/objects/AlignmentsInterna.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/DetectorTools.h" #include "DD4hep/Handle.inl" @@ -22,14 +23,6 @@ #include "TGeoMatrix.h" #include "TGeoManager.h" #include "DD4hep/objects/DetectorInterna.h" -/// Namespace for the AIDA detector description toolkit -namespace DD4hep { - /// Namespace for the conditions part of the AIDA detector description toolkit - namespace Conditions { - // Forward declarations - class ConditionsManager; - } -} using namespace std; using namespace DD4hep; @@ -72,7 +65,7 @@ DetElementObject::DetElementObject() : NamedObject(), ObjectExtensions(typeid(DetElementObject)), magic(magic_word()), flag(0), id(0), combineHits(0), typeFlag(0), path(), placementPath(), idealPlace(), placement(), volumeID(0), parent(), reference(), children(), - alignment(), volume_alignments(), conditions(), + nominal(), survey(), alignments(), conditions(), worldTrafo(), parentTrafo(), referenceTrafo(0) { printout(VERBOSE,"DetElementObject","+++ Created new anonymous DetElementObject()"); InstanceCount::increment(this); @@ -83,7 +76,7 @@ DetElementObject::DetElementObject(const std::string& nam, int ident) : NamedObject(), ObjectExtensions(typeid(DetElementObject)), magic(magic_word()), flag(0), id(ident), combineHits(0), typeFlag(0), path(), placementPath(), idealPlace(), placement(), volumeID(0), parent(), reference(), children(), - alignment(), volume_alignments(), conditions(), + nominal(), survey(), alignments(), conditions(), worldTrafo(), parentTrafo(), referenceTrafo(0) { SetName(nam.c_str()); printout(VERBOSE,"DetElementObject","+++ Created new DetElementObject('%s', %d)",nam.c_str(),id); @@ -96,7 +89,8 @@ DetElementObject::~DetElementObject() { deletePtr (referenceTrafo); if ( conditions.isValid() ) delete conditions.ptr(); conditions = ConditionsContainer(); - alignment.clear(); + if ( alignments.isValid() ) delete alignments.ptr(); + alignments = AlignmentsContainer(); placement.clear(); idealPlace.clear(); parent.clear(); @@ -111,8 +105,10 @@ DetElementObject* DetElementObject::clone(int new_id, int flg) const { obj->typeFlag = typeFlag; obj->flag = 0; obj->combineHits = combineHits; - obj->alignment = Alignment(); - obj->conditions = ConditionsContainer(); + obj->nominal = Alignment(); + obj->survey = Alignment(); + obj->conditions = ConditionsContainer(); + obj->alignments = AlignmentsContainer(); obj->parent = DetElement(); if ( (flg & DetElement::COPY_PLACEMENT) == DetElement::COPY_PLACEMENT ) { obj->placement = placement; @@ -142,16 +138,16 @@ DetElementObject* DetElementObject::clone(int new_id, int flg) const { } /// Access to the world object. Only possible once the geometry is closed. -WorldObject* DetElementObject::i_access_world() { +World DetElementObject::i_access_world() { if ( !privateWorld.isValid() ) { DetElementObject* p = parent.ptr(); if ( 0 == p ) { privateWorld = (WorldObject*)this; - return privateWorld.ptr(); + return privateWorld; } return p->world(); } - return privateWorld.ptr(); + return privateWorld; } /// Create cached matrix to transform to world coordinates @@ -297,32 +293,11 @@ Conditions::Container DetElementObject::assign_conditions() { /// Initializing constructor WorldObject::WorldObject(LCDD& _lcdd, const string& nam) - : DetElementObject(nam,0), lcdd(&_lcdd), conditionsLoader(0), conditionsManager(0) + : DetElementObject(nam,0), lcdd(&_lcdd), + conditionsLoader(0), conditionsManager(0), alignmentsLoader(0), alignmentsManager(0) { } /// Internal object destructor: release extension object(s) WorldObject::~WorldObject() { } - -/// Access the conditions loading -WorldObject::Condition -WorldObject::getCondition(Condition::key_type key, const Condition::iov_type& iov) const { - if ( conditionsLoader ) { - return conditionsLoader->get(key, iov); - } - - except("Conditions","+++ No ConditionsLoader registered to this LCDD instance!"); - return WorldObject::Condition(); -} - -/// Access the conditions loading -WorldObject::Condition -WorldObject::getCondition(Condition::key_type key, const UserPool& pool) const { - if ( conditionsLoader ) { - return conditionsLoader->get(key, pool); - } - - except("Conditions","+++ No ConditionsLoader registered to this LCDD instance!"); - return WorldObject::Condition(); -} diff --git a/DDCore/src/ExpressionEvaluator.cpp b/DDCore/src/ExpressionEvaluator.cpp index 67e3966fd000c7e6b8eb3bf06da64c216d67314f..615e9c2625281659af45939d71e8358575085aa0 100644 --- a/DDCore/src/ExpressionEvaluator.cpp +++ b/DDCore/src/ExpressionEvaluator.cpp @@ -69,5 +69,17 @@ namespace DD4hep { } return *e; } + + /// Access to G4 evaluator. Note: Uses cgs units! + XmlTools::Evaluator& cgsEvaluator() { + static XmlTools::Evaluator* e = 0; + if ( !e ) { + static XmlTools::Evaluator ev; + _init(ev); + _cgsUnits(ev); + e = &ev; + } + return *e; + } } diff --git a/DDCore/src/Alignment.cpp b/DDCore/src/GlobalAlignment.cpp similarity index 75% rename from DDCore/src/Alignment.cpp rename to DDCore/src/GlobalAlignment.cpp index bee529ca99238400f2889669cdf9aa034fa3c12a..44595a456190634dec7b24db3b7af8f1cdf0fa41 100644 --- a/DDCore/src/Alignment.cpp +++ b/DDCore/src/GlobalAlignment.cpp @@ -1,4 +1,4 @@ -// $Id: $ +// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -13,7 +13,7 @@ //========================================================================== // Framework include files -#include "DD4hep/Alignment.h" +#include "DD4hep/GlobalAlignment.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/MatrixHelpers.h" #include "DD4hep/Printout.h" @@ -25,32 +25,30 @@ using namespace std; using namespace DD4hep; -using namespace DD4hep::Geometry; - - +using namespace DD4hep::Alignments; namespace { - int _align(const Alignment& a, TGeoHMatrix* transform, bool check, double overlap) { + int _align(const GlobalAlignment& a, TGeoHMatrix* transform, bool check, double overlap) { TGeoPhysicalNode* n = a.ptr(); if ( n ) { TGeoMatrix* mm = n->GetNode()->GetMatrix(); transform->MultiplyLeft(mm); // orig * delta n->Align(transform, 0, check, overlap); /* - printout(INFO,"Alignment","OLD matrix...."); + printout(INFO,"GlobalAlignment","OLD matrix...."); mm->Print(); - printout(INFO,"Alignment","Apply new relative matrix mother to daughter:"); + printout(INFO,"GlobalAlignment","Apply new relative matrix mother to daughter:"); transform->Print(); transform->MultiplyLeft(mm); // orig * delta - printout(INFO,"Alignment","With deltas...."); + printout(INFO,"GlobalAlignment","With deltas...."); transform->Print(); n->Align(transform, 0, check, overlap); - printout(INFO,"Alignment","NEW matrix...."); + printout(INFO,"GlobalAlignment","NEW matrix...."); n->GetNode()->GetMatrix()->Print(); */ /* */ - printout(INFO,"Alignment","NEW matrix...."); + printout(INFO,"GlobalAlignment","NEW matrix...."); n->GetNode()->GetMatrix()->Print(); Position local, global = a.toGlobal(local); cout << "Local:" << local << " Global: " << global @@ -61,7 +59,7 @@ namespace { throw runtime_error("DD4hep: Cannot align non existing physical node. [Invalid Handle]"); } struct CheckHandle { - CheckHandle(const Alignment& a) { + CheckHandle(const GlobalAlignment& a) { if ( a.isValid() ) return; throw runtime_error("DD4hep: Attempt to access invalid alignment object. [Invalid Handle]"); } @@ -70,22 +68,22 @@ namespace { } /// Default constructor -Alignment::Alignment() : Handle<TGeoPhysicalNode>() { +GlobalAlignment::GlobalAlignment() : Handle<TGeoPhysicalNode>() { } /// Copy constructor -Alignment::Alignment(const Alignment& c) : Handle<TGeoPhysicalNode>(c) { +GlobalAlignment::GlobalAlignment(const GlobalAlignment& c) : Handle<TGeoPhysicalNode>(c) { } /// Initializing constructor to create a new object -Alignment::Alignment(const string& path) { - //cout << "Alignment: path=" << path << endl; +GlobalAlignment::GlobalAlignment(const string& path) { + //cout << "GlobalAlignment: path=" << path << endl; //m_element = gGeoManager->MakePhysicalNode(path.c_str()); m_element = new TGeoPhysicalNode(path.c_str()); } /// Assignment operator -Alignment& Alignment::operator=(const Alignment& c) { +GlobalAlignment& GlobalAlignment::operator=(const GlobalAlignment& c) { if ( &c != this ) { m_element = c.ptr(); } @@ -93,19 +91,19 @@ Alignment& Alignment::operator=(const Alignment& c) { } /// Number of nodes in this branch -int Alignment::numNodes() const { +int GlobalAlignment::numNodes() const { CheckHandle verify_handle(*this); return ptr()->GetLevel(); } /// Access the placement of this node -PlacedVolume Alignment::placement() const { +PlacedVolume GlobalAlignment::placement() const { CheckHandle verify_handle(*this); return PlacedVolume(ptr()->GetNode(0)); } /// Access the placement of a node in the chain of placements for this branch -PlacedVolume Alignment::nodePlacement(int level) const { +PlacedVolume GlobalAlignment::nodePlacement(int level) const { CheckHandle verify_handle(*this); PlacedVolume pv = PlacedVolume(ptr()->GetNode(level)); if ( pv.isValid() ) return pv; @@ -114,7 +112,7 @@ PlacedVolume Alignment::nodePlacement(int level) const { } /// Access the placement of the mother of this node -PlacedVolume Alignment::motherPlacement(int level_up) const { +PlacedVolume GlobalAlignment::motherPlacement(int level_up) const { CheckHandle verify_handle(*this); Int_t ind = ptr()->GetLevel()-level_up; if ( ind >= 0 ) { @@ -124,13 +122,13 @@ PlacedVolume Alignment::motherPlacement(int level_up) const { } /// Access the currently applied alignment/placement matrix -Transform3D Alignment::toGlobal(int level) const { +Transform3D GlobalAlignment::toGlobal(int level) const { CheckHandle verify_handle(*this); return _transform(ptr()->GetMatrix(level)); } /// Transform a point from local coordinates of a given level to global coordinates -Position Alignment::toGlobal(const Position& localPoint, int level) const { +Position GlobalAlignment::toGlobal(const Position& localPoint, int level) const { CheckHandle verify_handle(*this); Position result; TGeoHMatrix* m = ptr()->GetMatrix(level); @@ -139,7 +137,7 @@ Position Alignment::toGlobal(const Position& localPoint, int level) const { } /// Transform a point from local coordinates of a given level to global coordinates -Position Alignment::globalToLocal(const Position& globalPoint, int level) const { +Position GlobalAlignment::globalToLocal(const Position& globalPoint, int level) const { CheckHandle verify_handle(*this); Position result; TGeoHMatrix* m = ptr()->GetMatrix(level); @@ -148,19 +146,19 @@ Position Alignment::globalToLocal(const Position& globalPoint, int level) const } /// Access the currently applied alignment/placement matrix -Transform3D Alignment::toMother(int level) const { +Transform3D GlobalAlignment::toMother(int level) const { CheckHandle verify_handle(*this); return _transform(ptr()->GetNode(level)->GetMatrix()); } /// Access the currently applied alignment/placement matrix -Transform3D Alignment::nominal() const { +Transform3D GlobalAlignment::nominal() const { CheckHandle verify_handle(*this); return _transform(ptr()->GetOriginalMatrix()); } /// Access the currently applied correction matrix (delta) -Transform3D Alignment::delta() const { +Transform3D GlobalAlignment::delta() const { // It may be useful at some point to cache some of these matrices.... CheckHandle verify_handle(*this); TGeoPhysicalNode* n = ptr(); @@ -171,7 +169,7 @@ Transform3D Alignment::delta() const { } /// Access the inverse of the currently applied correction matrix (delta) (mother to daughter) -Transform3D Alignment::invDelta() const { +Transform3D GlobalAlignment::invDelta() const { // It may be useful at some point to cache some of these matrices.... CheckHandle verify_handle(*this); TGeoPhysicalNode* n = ptr(); diff --git a/DDCore/src/IOV.cpp b/DDCore/src/IOV.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d2b4504e9d4bb6892a1d539cac820614b8fffce3 --- /dev/null +++ b/DDCore/src/IOV.cpp @@ -0,0 +1,168 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework includes +#include "DD4hep/IOV.h" + +// C/C++ include files +#include <climits> +#include <iomanip> +#include <cstring> + +using namespace std; +using namespace DD4hep; + +std::string IOVType::str() const { + char text[256]; + ::snprintf(text,sizeof(text),"%s(%d)",name.c_str(),int(type)); + return text; +} + +/// Initializing constructor: Does not set reference to IOVType ! +IOV::IOV() : iovType(0), keyData(0,0), optData(0) { + type = int(IOVType::UNKNOWN_IOV); +} + +/// Initializing constructor +IOV::IOV(const IOVType* t) : iovType(t), keyData(0,0), optData(0) { + type = t ? t->type : int(IOVType::UNKNOWN_IOV); +} + +/// Copy constructor +IOV::IOV(const IOV& c) + : iovType(c.iovType), keyData(c.keyData), optData(c.optData), type(c.type) +{ +} + +/// Copy constructor +IOV::IOV(const IOVType* t, const Key& k) + : iovType(t), keyData(k), optData(0) +{ + type = t ? t->type : int(IOVType::UNKNOWN_IOV); +} + +/// Standard Destructor +IOV::~IOV() { +} + +/// Set discrete IOV value +void IOV::set(const Key& value) { + keyData = value; +} + +/// Set discrete IOV value +void IOV::set(Key::first_type value) { + keyData.first = keyData.second = value; +} + +/// Set range IOV value +void IOV::set(Key::first_type val_1, Key::second_type val_2) { + keyData.first = val_1; + keyData.second = val_2; +} + +/// Set keys to unphysical values (LONG_MAX, LONG_MIN) +IOV& IOV::reset() { + keyData.first = LONG_MAX; + keyData.second = LONG_MIN; + return *this; +} + +/// Set keys to unphysical values (LONG_MAX, LONG_MIN) +IOV& IOV::invert() { + Key::first_type tmp = keyData.first; + keyData.first = keyData.second; + keyData.second = tmp; + return *this; +} + +void IOV::iov_intersection(const IOV& validity) { + if ( !iovType ) + *this = validity; + else if ( validity.keyData.first > keyData.first ) + keyData.first = validity.keyData.first; + if ( validity.keyData.second < keyData.second ) + keyData.second = validity.keyData.second; +} + +void IOV::iov_intersection(const IOV::Key& validity) { + if ( validity.first > keyData.first ) + keyData.first = validity.first; + if ( validity.second < keyData.second ) + keyData.second = validity.second; +} + +void IOV::iov_union(const IOV& validity) { + if ( !iovType ) + *this = validity; + else if ( validity.keyData.first < keyData.first ) + keyData.first = validity.keyData.first; + if ( validity.keyData.second > keyData.second ) + keyData.second = validity.keyData.second; +} + +void IOV::iov_union(const IOV::Key& validity) { + if ( validity.first < keyData.first ) + keyData.first = validity.first; + if ( validity.second > keyData.second ) + keyData.second = validity.second; +} + +/// Move the data content: 'from' will be reset to NULL +void IOV::move(IOV& from) { + ::memcpy(this,&from,sizeof(IOV)); + from.keyData.first = from.keyData.second = from.optData = 0; + from.type = int(IOVType::UNKNOWN_IOV); + from.iovType = 0; +} + +/// Create string representation of the IOV +string IOV::str() const { + char text[256]; + if ( iovType ) { + if ( iovType->name[0] != 'e' ) { + ::snprintf(text,sizeof(text),"%s(%d):[%ld-%ld]", + iovType->name.c_str(),int(iovType->type),keyData.first, keyData.second); + } + else if ( iovType->name == "epoch" ) { + time_t since = keyData.first; + time_t until = keyData.second; + char c_since[64], c_until[64]; + struct tm time_buff; + ::strftime(c_since,sizeof(c_since),"%d-%m-%Y %H:%M:%S",::gmtime_r(&since,&time_buff)); + ::strftime(c_until,sizeof(c_until),"%d-%m-%Y %H:%M:%S",::gmtime_r(&until,&time_buff)); + ::snprintf(text,sizeof(text),"%s(%d):[%s-%s]", + iovType->name.c_str(),iovType->type, + c_since, c_until); + } + else { + ::snprintf(text,sizeof(text),"%s(%d):[%ld-%ld]", + iovType->name.c_str(),int(iovType->type),keyData.first, keyData.second); + } + } + else { + ::snprintf(text,sizeof(text),"%d:[%ld-%ld]",type,keyData.first, keyData.second); + } + return text; +} + +/// Check for validity containment +bool IOV::contains(const IOV& iov) const { + if ( key_is_contained(iov.keyData,keyData) ) { + unsigned int typ1 = iov.iovType ? iov.iovType->type : iov.type; + unsigned int typ2 = iovType ? iovType->type : type; + return typ1 == typ2; + } + return false; +} diff --git a/DDCore/src/MatrixHelpers.cpp b/DDCore/src/MatrixHelpers.cpp index cd4c9c90da5cfda69df0c7a3d12b4aaf292e1fa9..57b13090234d8c3c3aaa01b412e2aafaa3876edf 100644 --- a/DDCore/src/MatrixHelpers.cpp +++ b/DDCore/src/MatrixHelpers.cpp @@ -18,24 +18,24 @@ // ROOT includes #include "TGeoMatrix.h" -TGeoIdentity* DD4hep::Geometry::identityTransform() { +TGeoIdentity* DD4hep::identityTransform() { return gGeoIdentity; } -TGeoTranslation* DD4hep::Geometry::_translation(const Position& pos) { +TGeoTranslation* DD4hep::_translation(const Position& pos) { return new TGeoTranslation("", pos.X(), pos.Y(), pos.Z()); } -TGeoRotation* DD4hep::Geometry::_rotationZYX(const RotationZYX& rot) { +TGeoRotation* DD4hep::_rotationZYX(const RotationZYX& rot) { return new TGeoRotation("", rot.Phi() * RAD_2_DEGREE, rot.Theta() * RAD_2_DEGREE, rot.Psi() * RAD_2_DEGREE); } -TGeoRotation* DD4hep::Geometry::_rotation3D(const Rotation3D& rot3D) { +TGeoRotation* DD4hep::_rotation3D(const Rotation3D& rot3D) { EulerAngles rot(rot3D); return new TGeoRotation("", rot.Phi() * RAD_2_DEGREE, rot.Theta() * RAD_2_DEGREE, rot.Psi() * RAD_2_DEGREE); } -TGeoHMatrix* DD4hep::Geometry::_transform(const Position& pos) { +TGeoHMatrix* DD4hep::_transform(const Position& pos) { double t[3]; TGeoHMatrix *tr = new TGeoHMatrix(); pos.GetCoordinates(t); @@ -45,7 +45,7 @@ TGeoHMatrix* DD4hep::Geometry::_transform(const Position& pos) { return tr; } -TGeoHMatrix* DD4hep::Geometry::_transform(const RotationZYX& rot) { +TGeoHMatrix* DD4hep::_transform(const RotationZYX& rot) { TGeoHMatrix *tr = new TGeoHMatrix(); tr->RotateZ(rot.Phi() * RAD_2_DEGREE); tr->RotateY(rot.Theta() * RAD_2_DEGREE); @@ -53,21 +53,21 @@ TGeoHMatrix* DD4hep::Geometry::_transform(const RotationZYX& rot) { return tr; } -TGeoHMatrix* DD4hep::Geometry::_transform(const Rotation3D& rot) { +TGeoHMatrix* DD4hep::_transform(const Rotation3D& rot) { TGeoHMatrix *tr = new TGeoHMatrix(); Double_t* r = tr->GetRotationMatrix(); rot.GetComponents(r); return tr; } -TGeoHMatrix* DD4hep::Geometry::_transform(const Transform3D& trans) { +TGeoHMatrix* DD4hep::_transform(const Transform3D& trans) { Position pos; RotationZYX rot; trans.GetDecomposition(rot, pos); return _transform(pos,rot); } -TGeoHMatrix* DD4hep::Geometry::_transform(const Position& pos, const RotationZYX& rot) { +TGeoHMatrix* DD4hep::_transform(const Position& pos, const RotationZYX& rot) { double t[3]; TGeoHMatrix *tr = _transform(rot); pos.GetCoordinates(t); @@ -77,7 +77,7 @@ TGeoHMatrix* DD4hep::Geometry::_transform(const Position& pos, const RotationZYX return tr; } -DD4hep::Geometry::Transform3D DD4hep::Geometry::_transform(const TGeoMatrix* matrix) { +DD4hep::Transform3D DD4hep::_transform(const TGeoMatrix* matrix) { const Double_t* t = matrix->GetTranslation(); if ( matrix->IsRotation() ) { const Double_t* r = matrix->GetRotationMatrix(); @@ -95,11 +95,11 @@ DD4hep::Geometry::Transform3D DD4hep::Geometry::_transform(const TGeoMatrix* mat 0e0,0e0,0e0,t[2]*MM_2_CM); } -DD4hep::Geometry::XYZAngles DD4hep::Geometry::_XYZangles(const TGeoMatrix* m) { +DD4hep::XYZAngles DD4hep::_XYZangles(const TGeoMatrix* m) { return m->IsRotation() ? _XYZangles(m->GetRotationMatrix()) : XYZAngles(0,0,0); } -DD4hep::Geometry::XYZAngles DD4hep::Geometry::_XYZangles(const double* r) { +DD4hep::XYZAngles DD4hep::_XYZangles(const double* r) { Double_t cosb = std::sqrt(r[0]*r[0] + r[1]*r[1]); if (cosb > 0.00001) { return XYZAngles(atan2(r[5], r[8]), atan2(-r[2], cosb), atan2(r[1], r[0])); @@ -107,21 +107,21 @@ DD4hep::Geometry::XYZAngles DD4hep::Geometry::_XYZangles(const double* r) { return XYZAngles(atan2(-r[7], r[4]),atan2(-r[2], cosb),0); } -void DD4hep::Geometry::_decompose(const Transform3D& trafo, Translation3D& pos, RotationZYX& rot) { +void DD4hep::_decompose(const Transform3D& trafo, Translation3D& pos, RotationZYX& rot) { trafo.GetDecomposition(rot,pos); } -void DD4hep::Geometry::_decompose(const Transform3D& trafo, Translation3D& pos, XYZAngles& rot) { +void DD4hep::_decompose(const Transform3D& trafo, Translation3D& pos, XYZAngles& rot) { EulerAngles r; trafo.GetDecomposition(r,pos); rot.SetXYZ(r.Psi(),r.Theta(),r.Phi()); } -void DD4hep::Geometry::_decompose(const Transform3D& trafo, Position& pos, RotationZYX& rot) { +void DD4hep::_decompose(const Transform3D& trafo, Position& pos, RotationZYX& rot) { trafo.GetDecomposition(rot,pos); } -void DD4hep::Geometry::_decompose(const Transform3D& trafo, Position& pos, XYZAngles& rot) { +void DD4hep::_decompose(const Transform3D& trafo, Position& pos, XYZAngles& rot) { EulerAngles r; trafo.GetDecomposition(r,pos); rot.SetXYZ(r.Psi(),r.Theta(),r.Phi()); diff --git a/DDCore/src/OpaqueData.cpp b/DDCore/src/OpaqueData.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76dce8536168171098a37f1a768e6e2b26c7f137 --- /dev/null +++ b/DDCore/src/OpaqueData.cpp @@ -0,0 +1,167 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework includes +#include "DD4hep/Printout.h" +#include "DD4hep/Primitives.h" +#include "DD4hep/OpaqueData.h" +#include "DD4hep/InstanceCount.h" +#include "DD4hep/objects/OpaqueData_inl.h" + +// C/C++ header files +#include <cstring> + +using namespace std; +using namespace DD4hep; + +/// Standard initializing constructor +OpaqueData::OpaqueData() : grammar(0), pointer(0) { +} + +/// Standard Destructor +OpaqueData::~OpaqueData() { +} + +/// Create data block from string representation +bool OpaqueData::fromString(const string& rep) { + if ( pointer && grammar ) { + return grammar->fromString(pointer,rep); + } + throw runtime_error("Opaque data block is unbound. Cannot parse string representation."); +} + +/// Create string representation of the data block +string OpaqueData::str() const { + if ( pointer && grammar ) { + return grammar->str(pointer); + } + throw runtime_error("Opaque data block is unbound. Cannot create string representation."); +} + +/// Access type id of the condition +const type_info& OpaqueData::typeInfo() const { + if ( pointer && grammar ) { + return grammar->type(); + } + throw runtime_error("Opaque data block is unbound. Cannot determine type information!"); +} + +/// Access type name of the condition data block +const string& OpaqueData::dataType() const { + if ( pointer && grammar ) { + return grammar->type_name(); + } + throw runtime_error("Opaque data block is unbound. Cannot determine type information!"); +} + +/// Standard initializing constructor +OpaqueDataBlock::OpaqueDataBlock() : OpaqueData(), destruct(0), copy(0), type(0) { + InstanceCount::increment(this); +} + +/// Copy constructor +OpaqueDataBlock::OpaqueDataBlock(const OpaqueDataBlock& c) + : OpaqueData(c), destruct(c.destruct), copy(c.copy), type(c.type) { + grammar = 0; + pointer = 0; + this->bind(c.grammar,c.copy,c.destruct); + this->copy(pointer,c.pointer); + InstanceCount::increment(this); +} + +/// Standard Destructor +OpaqueDataBlock::~OpaqueDataBlock() { + if ( destruct ) { + (*destruct)(pointer); + if ( (type&ALLOC_DATA) == ALLOC_DATA ) ::operator delete(pointer); + } + pointer = 0; + grammar = 0; + InstanceCount::decrement(this); +} + +/// Move the data content: 'from' will be reset to NULL +bool OpaqueDataBlock::move(OpaqueDataBlock& from) { + pointer = from.pointer; + grammar = from.grammar; + ::memcpy(data,from.data,sizeof(data)); + destruct = from.destruct; + copy = from.copy; + type = from.type; + ::memset(from.data,0,sizeof(data)); + from.type = PLAIN_DATA; + from.destruct = 0; + from.copy = 0; + from.pointer = 0; + from.grammar = 0; + return true; +} + +/// Copy constructor +OpaqueDataBlock& OpaqueDataBlock::operator=(const OpaqueDataBlock& c) { + if ( this != &c ) { + if ( this->grammar == c.grammar ) { + if ( destruct ) { + (*destruct)(pointer); + if ( (type&ALLOC_DATA) == ALLOC_DATA ) ::operator delete(pointer); + } + pointer = 0; + grammar = 0; + } + if ( this->grammar == 0 ) { + this->OpaqueData::operator=(c); + this->destruct = c.destruct; + this->copy = c.copy; + this->type = c.type; + this->grammar = 0; + this->bind(c.grammar,c.copy,c.destruct); + this->copy(pointer,c.pointer); + return *this; + } + except("OpaqueData","You may not bind opaque data multiple times!"); + } + return *this; +} + +/// Set data value +bool OpaqueDataBlock::bind(const BasicGrammar* g, void (*ctor)(void*,const void*), void (*dtor)(void*)) { + if ( !grammar ) { + size_t len = g->sizeOf(); + grammar = g; + destruct = dtor; + copy = ctor; + (len > sizeof(data)) + ? (pointer=::operator new(len),type=ALLOC_DATA) + : (pointer=data,type=PLAIN_DATA); + return true; + } + else if ( grammar == g ) { + // We cannot ingore secondary requests for data bindings. + // This leads to memory leaks in the caller! + except("OpaqueData","You may not bind opaque multiple times!"); + } + typeinfoCheck(grammar->type(),g->type(),"Opaque data blocks may not be assigned."); + return false; +} + +/// Set data value +void OpaqueDataBlock::assign(const void* ptr, const type_info& typ) { + if ( !grammar ) { + except("OpaqueData","Opaque data block is unbound. Cannot copy data."); + } + else if ( grammar->type() != typ ) { + except("OpaqueData","Bad data binding binding"); + } + (*copy)(pointer,ptr); +} diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index 35d4b5359f661c007b80f55e69dedfe750f13f46..487cb3a86f231d2f1570be4f23bd5d527c35edf0 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -47,7 +47,7 @@ namespace { /// Populate the Volume manager void populate(DetElement e) { - const char* typ = 0;//::getenv("VOLMGR_NEW"); + //const char* typ = 0;//::getenv("VOLMGR_NEW"); const DetElement::Children& c = e.children(); SensitiveDetector parent_sd; if ( e->flag&DetElement::Object::HAVE_SENSITIVE_DETECTOR ) { @@ -106,14 +106,14 @@ namespace { if (node) { Volume vol = pv.volume(); const VolIDs& pv_ids = pv.volIDs(); - Encoding encoding = parent_encoding; + Encoding vol_encoding = parent_encoding; bool is_sensitive = vol.isSensitive(); bool have_encoding = pv_ids.empty(); bool compound = e.type() == "compound"; if ( compound ) { sd = SensitiveDetector(0); - encoding = Encoding(); + vol_encoding = Encoding(); } else if ( !sd.isValid() ) { if ( is_sensitive ) @@ -127,7 +127,7 @@ namespace { if ( sd.isValid() && !pv_ids.empty() ) { Readout ro = sd.readout(); if ( ro.isValid() ) { - encoding = update_encoding(ro.idSpec(), pv_ids, parent_encoding); + vol_encoding = update_encoding(ro.idSpec(), pv_ids, parent_encoding); have_encoding = true; } else { @@ -144,10 +144,10 @@ namespace { DetElement de_dau = findElt(e, daughter); if ( de_dau.isValid() ) { Chain dau_chain; - count += scanPhysicalVolume(parent, de_dau, pv_dau, encoding, sd, dau_chain); + count += scanPhysicalVolume(parent, de_dau, pv_dau, vol_encoding, sd, dau_chain); } else { - count += scanPhysicalVolume(parent, e, pv_dau, encoding, sd, chain); + count += scanPhysicalVolume(parent, e, pv_dau, vol_encoding, sd, chain); } } else { @@ -178,11 +178,11 @@ namespace { // printout(VERBOSE,"VolumeManager","++++ %-11s SD:%s VolID=%p Mask=%p",e.path().c_str(), have_encoding ? "RECUPERATED" : "REGULAR", sd.name(), - (void*)encoding.first, (void*)encoding.second); - e.object<DetElement::Object>().volumeID = encoding.first; + (void*)vol_encoding.first, (void*)vol_encoding.second); + e.object<DetElement::Object>().volumeID = vol_encoding.first; } if ( is_sensitive || add_det_vol_id ) { - add_entry(sd, parent, e, node, encoding, chain); + add_entry(sd, parent, e, node, vol_encoding, chain); ++count; } } diff --git a/DDCore/src/Volumes.cpp b/DDCore/src/Volumes.cpp index 6ff311e07c82cbb0045e235f3ed8caa84bb3f7b0..87c6c4d86b1910657184c7d0100bbcfa5a8899ed 100644 --- a/DDCore/src/Volumes.cpp +++ b/DDCore/src/Volumes.cpp @@ -495,7 +495,7 @@ static PlacedVolume _addNode(TGeoVolume* par, TGeoVolume* daughter, TGeoMatrix* TGeoVolume* parent = par; TObjArray* a = parent->GetNodes(); Int_t id = a ? a->GetEntries() : 0; - if (transform && transform != identityTransform()) { + if (transform && transform != DD4hep::identityTransform()) { string nam = string(daughter->GetName()) + "_placement"; transform->SetName(nam.c_str()); } @@ -523,7 +523,7 @@ PlacedVolume Volume::placeVolume(const Volume& volume, const Transform3D& trans) /// Place daughter volume. The position and rotation are the identity PlacedVolume Volume::placeVolume(const Volume& volume) const { - return _addNode(m_element, volume, identityTransform()); + return _addNode(m_element, volume, DD4hep::identityTransform()); } /// Place un-rotated daughter volume at the given position. diff --git a/DDCore/src/World.cpp b/DDCore/src/World.cpp index 27cff9b8d51b8f70d1c87eee92fcbe8d188384b3..f0e42fa8b1cc4ac2ea0f39bd2881878145dd99ff 100644 --- a/DDCore/src/World.cpp +++ b/DDCore/src/World.cpp @@ -13,20 +13,28 @@ //========================================================================== // Framework include files -#include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/World.h" +#include "DD4hep/Printout.h" +#include "DD4hep/objects/DetectorInterna.h" -using std::string; using namespace DD4hep::Geometry; /// Access the conditions loading -World::Condition World::getCondition(Condition::key_type key, const Condition::iov_type& iov) const { - return access()->getCondition(key, iov); +World::ConditionsLoader& World::conditionsLoader() const { + ConditionsLoader* loader = access()->conditionsLoader; + if ( !loader ) { + except("Conditions","+++ No ConditionsLoader registered to this World instance!"); + } + return *loader; } -/// Access the conditions loading -World::Condition World::getCondition(Condition::key_type key, const UserPool& pool) const { - return access()->getCondition(key, pool); +/// Access to the alignment loading +World::AlignmentsLoader& World::alignmentsLoader() const { + AlignmentsLoader* loader = access()->alignmentsLoader; + if ( !loader ) { + except("Alignments","+++ No AlignmentsLoader registered to this World instance!"); + } + return *loader; } /// Access the detector descrion tree diff --git a/DDDB/CMakeLists.txt b/DDDB/CMakeLists.txt index ea2b727bf03a28c560e9affd2ed0d85a9870a53e..ed115dfa0f68f03a42e691c4a9eb6dae070d42d7 100644 --- a/DDDB/CMakeLists.txt +++ b/DDDB/CMakeLists.txt @@ -15,5 +15,7 @@ dd4hep_package( DDDB INCLUDE_DIRS include INSTALL_INCLUDES include/DDDB) -#---DDDB library -------------------------------------------------------------- +#---DDDB plugin library ------------------------------------------------------- dd4hep_add_plugin ( DDDB SOURCES src/*.cpp ) +#---Package installation procedure(s) ----------------------------------------- +install ( PROGRAMS scripts/run_dddb.sh DESTINATION bin) diff --git a/DDDB/include/DDDB/DDDBConversion.h b/DDDB/include/DDDB/DDDBConversion.h index edcdb316e9e5c797eb9b09fb95a2260db4b71e85..d793eaa7717551aeea2aa252002086d8d96fd806 100644 --- a/DDDB/include/DDDB/DDDBConversion.h +++ b/DDDB/include/DDDB/DDDBConversion.h @@ -44,11 +44,7 @@ namespace DD4hep { class Document; using Geometry::DetElement; - using Geometry::VisAttr; - using Geometry::Position; - using Geometry::RotationZYX; - using Geometry::Transform3D; - using ROOT::Math::Rotation3D; + using Geometry::LCDD; /// Basic named object /** \ingroup DD4HEP_DDDB diff --git a/DDDB/include/DDDB/DDDBFileReader.h b/DDDB/include/DDDB/DDDBReader.h similarity index 76% rename from DDDB/include/DDDB/DDDBFileReader.h rename to DDDB/include/DDDB/DDDBReader.h index bd3be452ba1da46dee04dc48ac1b5c53213a777f..c6e7d7815fc48ff69263f4b981ad899f9f763306 100644 --- a/DDDB/include/DDDB/DDDBFileReader.h +++ b/DDDB/include/DDDB/DDDBReader.h @@ -22,6 +22,8 @@ // Framework includes #include "XML/UriReader.h" +#include "DDDB/DDDBReaderContext.h" + /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -36,12 +38,12 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP_XML */ - class DDDBFileReader : public DD4hep::XML::UriReader { + class DDDBReader : public DD4hep::XML::UriReader { public: /// Standard constructor - DDDBFileReader(const std::string& dir="") : m_directory(dir) {} + DDDBReader(const std::string& dir=""); /// Default destructor - virtual ~DDDBFileReader() {} + virtual ~DDDBReader() {} /// Set data directory void setDirectory(const std::string& dir) { m_directory = dir; } /// Access data directory @@ -50,14 +52,22 @@ namespace DD4hep { void setMatch(const std::string& dir) { m_match = dir; } /// Access data match const std::string& match() const { return m_match; } + /// Create time from ingredients + static long long int makeTime(int year, int month, int day, int hour=0, int minutes=0, int seconds=0); + + /// Access to local context + virtual UserContext* context() { return &m_context; } + /// Resolve a given URI to a string containing the data + virtual bool load(const std::string& system_id, std::string& buffer); /// Resolve a given URI to a string containing the data virtual bool load(const std::string& system_id, UserContext* ctxt, std::string& buffer); /// Read raw XML object from the database / file virtual int getObject(const std::string& system_id, UserContext* ctxt, std::string& data); protected: - std::string m_directory; - std::string m_match; + std::string m_directory; + std::string m_match; + DDDBReaderContext m_context; }; } /* End namespace DDDB */ } /* End namespace DD4hep */ diff --git a/DDDB/include/DDDB/DDDBReaderContext.h b/DDDB/include/DDDB/DDDBReaderContext.h index 859b43406bc536cf40067e27540871d3fda7d9e7..66e8e5550d9a76e9afe34bd6a3681b822708ee6b 100644 --- a/DDDB/include/DDDB/DDDBReaderContext.h +++ b/DDDB/include/DDDB/DDDBReaderContext.h @@ -46,10 +46,10 @@ namespace DD4hep { /// Copy constructor DDDBReaderContext(const DDDBReaderContext& c) : XML::UriReader::UserContext(c), - event_time(c.event_time), - valid_since(c.valid_since), - valid_until(c.valid_until), - channel(c.channel) {} + event_time(c.event_time), + valid_since(c.valid_since), + valid_until(c.valid_until), + channel(c.channel) {} }; } /* End namespace DDDB */ } /* End namespace DD4hep */ diff --git a/DDDB/src/AlignmentCondition.cpp b/DDDB/src/AlignmentCondition.cpp deleted file mode 100644 index b7385ab374d4e6a12f08d4f13abe7f469e6314a7..0000000000000000000000000000000000000000 --- a/DDDB/src/AlignmentCondition.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// $Id$ -//========================================================================== -// AIDA Detector description implementation for LCD -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see $DD4hepINSTALL/LICENSE. -// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. -// -// Author : M.Frank -// -//========================================================================== - -// Framework includes -#include "DD4hep/DetectorTools.h" -//#include "DDCond/AlignmentCondition.h" -#include "AlignmentCondition.h" - -// C/C++ include files -#include <iostream> -#include <stdexcept> - -using namespace DD4hep::Conditions; -using DD4hep::Geometry::DetectorTools::ElementPath; -using DD4hep::Geometry::DetectorTools::PlacementPath; - -/// Standard constructor -AlignmentConditionData::AlignmentConditionData() - : flag(0), magic(magic_word()) -{ -} - -/// Default destructor -AlignmentConditionData::~AlignmentConditionData() { -} - -/// Create cached matrix to transform to world coordinates -const TGeoHMatrix& AlignmentConditionData::worldTransformation() const { - if ( (flag&HAVE_WORLD_TRAFO) == 0 ) { - PlacementPath nodes; - flag |= HAVE_WORLD_TRAFO; - //Geometry::DetectorTools::placementPath(condition->detector, nodes); - //Geometry::DetectorTools::placementTrafo(nodes,false,worldTrafo); - throw std::runtime_error("not implemented"); - } - return worldTrafo; -} - -/// Create cached matrix to transform to parent coordinates -const TGeoHMatrix& AlignmentConditionData::parentTransformation() const { - if ( (flag&HAVE_PARENT_TRAFO) == 0 ) { - PlacementPath nodes; - DetElement det;// = condition->detector; - flag |= HAVE_PARENT_TRAFO; - Geometry::DetectorTools::placementPath(det.parent(), det, nodes); - Geometry::DetectorTools::placementTrafo(nodes,false,parentTrafo); - } - return parentTrafo; -} - -/// Default constructor -AlignmentCondition::AlignmentCondition() : Condition() { -} - -/// Copy constructor -AlignmentCondition::AlignmentCondition(const Condition& c) : Condition(c) { -} - -/// Copy constructor -AlignmentCondition::AlignmentCondition(const AlignmentCondition& c) : Condition(c) { -} - -/// Initializing constructor -AlignmentCondition::AlignmentCondition(Object* p) : Condition(p) { -} - -/// Assignment operator -AlignmentCondition& AlignmentCondition::operator=(const AlignmentCondition& c) { - if ( this != &c ) this->m_element = c.m_element; - return *this; -} - -/// Create cached matrix to transform to world coordinates -const TGeoHMatrix& AlignmentCondition::worldTransformation() const { - return get<AlignmentConditionData>().worldTransformation(); -} - -/// Create cached matrix to transform to parent coordinates -const TGeoHMatrix& AlignmentCondition::parentTransformation() const { - return get<AlignmentConditionData>().parentTransformation(); -} - -/// Transformation from local coordinates of the placed volume to the world system -bool AlignmentCondition::localToWorld(const Position& local, Position& global) const { - Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; - // If the path is unknown an exception will be thrown inside worldTransformation() ! - worldTransformation().LocalToMaster(local_point, master_point); - global.SetCoordinates(master_point); - return true; -} - -/// Transformation from local coordinates of the placed volume to the parent system -bool AlignmentCondition::localToParent(const Position& local, Position& parent) const { - // If the path is unknown an exception will be thrown inside parentTransformation() ! - Double_t master_point[3] = { 0, 0, 0 }, local_point[3] = { local.X(), local.Y(), local.Z() }; - parentTransformation().LocalToMaster(local_point, master_point); - parent.SetCoordinates(master_point); - return true; -} - -/// Transformation from world coordinates of the local placed volume coordinates -bool AlignmentCondition::worldToLocal(const Position& global, Position& local) const { - // If the path is unknown an exception will be thrown inside worldTransformation() ! - Double_t master_point[3] = { global.X(), global.Y(), global.Z() }, local_point[3] = { 0, 0, 0 }; - worldTransformation().MasterToLocal(master_point, local_point); - local.SetCoordinates(local_point); - return true; -} - -/// Transformation from world coordinates of the local placed volume coordinates -bool AlignmentCondition::parentToLocal(const Position& parent, Position& local) const { - // If the path is unknown an exception will be thrown inside parentTransformation() ! - Double_t master_point[3] = { parent.X(), parent.Y(), parent.Z() }, local_point[3] = { 0, 0, 0 }; - parentTransformation().MasterToLocal(master_point, local_point); - local.SetCoordinates(local_point); - return true; -} - -std::ostream& operator<<(std::ostream& s, const AlignmentConditionData&) { - return s; -} - -#include "DD4hep/ToStream.h" -#include "DD4hep/objects/ConditionsInterna.h" -DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(AlignmentConditionData) - -#include "DD4hep/objects/BasicGrammar_inl.h" -DD4HEP_DEFINE_PARSER_GRAMMAR(AlignmentConditionData,eval_none<AlignmentConditionData>) - diff --git a/DDDB/src/AlignmentCondition.h b/DDDB/src/AlignmentCondition.h deleted file mode 100644 index 83ad2b4c52566b3cca833f2e09dd81431abf84eb..0000000000000000000000000000000000000000 --- a/DDDB/src/AlignmentCondition.h +++ /dev/null @@ -1,131 +0,0 @@ -// $Id$ -//========================================================================== -// AIDA Detector description implementation for LCD -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see $DD4hepINSTALL/LICENSE. -// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. -// -// Author : M.Frank -// -//========================================================================== -#ifndef DD4HEP_GEOMETRY_ALIGNMENTCONDITION_H -#define DD4HEP_GEOMETRY_ALIGNMENTCONDITION_H - -// Framework include files -#include "DD4hep/ConditionsData.h" -#include "DD4hep/ConditionDerived.h" - -// ROOT include files -#include "TGeoMatrix.h" - -/// Namespace for the AIDA detector description toolkit -namespace DD4hep { - - /// Namespace for the conditions part of the AIDA detector description toolkit - namespace Conditions { - - /// Derived condition data-object definition - /** - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class AlignmentConditionData { - public: - typedef Geometry::PlacedVolume PlacedVolume; - typedef Geometry::DetElement DetElement; - typedef Geometry::Position Position; - typedef Geometry::Position Pivot; - typedef Geometry::RotationZYX Rotation; - - enum AlignmentFlags { - HAVE_NONE = 0, - HAVE_WORLD_TRAFO = 1<<0, - HAVE_PARENT_TRAFO = 1<<1, - HAVE_OTHER = 1<<31 - }; - - AlignmentDelta delta; - /// Intermediate buffer to store the transformation to the world coordination system - mutable TGeoHMatrix worldTrafo; - /// Intermediate buffer to store the transformation to the parent detector element - mutable TGeoHMatrix parentTrafo; - /// The subdetector placement corresponding to the actual detector element's volume - PlacedVolume placement; - /// Parent condition reference - Condition condition; - /// Flag to remember internally calculated quatities - mutable unsigned int flag; - /// Magic word to verify object if necessary - unsigned int magic; - - public: - /// Standard constructor - AlignmentConditionData(); - /// Default destructor - virtual ~AlignmentConditionData(); - /// Create cached matrix to transform to world coordinates - const TGeoHMatrix& worldTransformation() const; - /// Create cached matrix to transform to parent coordinates - const TGeoHMatrix& parentTransformation() const; - }; - - /// Class describing an alignment condition - /** - * The Alignment condition describes an alignment delta applied - * to a given volume. An instance contains all necessary - * alignment data and the corresponding transformations. - * - * Typically this object is derived condition ie. the raw conditions data - * are stored as a 'delta' and then get reformatted and re-computed - * in the derived quantity. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class AlignmentCondition : public Condition { - public: - typedef Geometry::PlacedVolume PlacedVolume; - typedef Geometry::DetElement DetElement; - typedef Geometry::Position Position; - typedef Geometry::Position Pivot; - typedef Geometry::RotationZYX Rotation; - - public: - /// Default constructor - AlignmentCondition(); - /// Copy constructor - AlignmentCondition(const Condition& c); - /// Copy constructor - AlignmentCondition(const AlignmentCondition& c); - /// Initializing constructor - AlignmentCondition(Object* p); - /// Constructor to be used when reading the already parsed object - template <typename Q> AlignmentCondition(const Handle<Q>& e) - : Condition(e) { - } - /// Assignment operator - AlignmentCondition& operator=(const AlignmentCondition& c); - /// Create cached matrix to transform to world coordinates - const TGeoHMatrix& worldTransformation() const; - /// Create cached matrix to transform to parent coordinates - const TGeoHMatrix& parentTransformation() const; - - /// Transformation from local coordinates of the placed volume to the world system - bool localToWorld(const Position& local, Position& global) const; - /// Transformation from local coordinates of the placed volume to the parent system - bool localToParent(const Position& local, Position& parent) const; - - /// Transformation from world coordinates of the local placed volume coordinates - bool worldToLocal(const Position& global, Position& local) const; - /// Transformation from world coordinates of the local placed volume coordinates - bool parentToLocal(const Position& parent, Position& local) const; - }; - - } /* End namespace Conditions */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_GEOMETRY_ALIGNMENTCONDITION_H */ diff --git a/DDDB/src/CondDB2DDDB.cpp b/DDDB/src/CondDB2DDDB.cpp index f2e8c7c54050798119c504d45779723ef84e34b7..78d27ea75c4d9caead77a4df9690cc71ed262d80 100644 --- a/DDDB/src/CondDB2DDDB.cpp +++ b/DDDB/src/CondDB2DDDB.cpp @@ -23,6 +23,7 @@ #include "DDDB/DDDBDimension.h" #include "DDDB/DDDBHelper.h" #include "DDDB/DDDBConversion.h" +#include "DD4hep/Alignments.h" // C/C++ include files #include "boost/filesystem/path.hpp" @@ -38,12 +39,12 @@ namespace DD4hep { namespace { static int preserv_level = 0; - using Conditions::BlockData; using Conditions::Condition; using Conditions::AbstractMap; - using Conditions::AlignmentDelta; + typedef Alignments::Delta AlignmentDelta; typedef AbstractMap::Params ConditionParams; + struct LogVolRef {}; struct ElementRef {}; struct MaterialRef {}; @@ -98,39 +99,39 @@ namespace DD4hep { */ class Locals { public: - string obj_path; - Document* xml_doc; - Locals() : obj_path(), xml_doc(0) {} - Locals(const Locals& c) : obj_path(c.obj_path), xml_doc(c.xml_doc) {} - Locals& operator=(const Locals& c) { - obj_path = c.obj_path; - xml_doc = c.xml_doc; - return *this; - } + string obj_path; + Document* xml_doc; + Locals() : obj_path(), xml_doc(0) {} + Locals(const Locals& c) : obj_path(c.obj_path), xml_doc(c.xml_doc) {} + Locals& operator=(const Locals& c) { + obj_path = c.obj_path; + xml_doc = c.xml_doc; + return *this; + } }; /// Helper class to preserve local processing environment /** \ingroup DD4HEP_DDDB */ class PreservedLocals : public Locals { public: - Context* context; - PreservedLocals(Context* c) : Locals(c->locals), context(c) { + Context* context; + PreservedLocals(Context* c) : Locals(c->locals), context(c) { #ifdef __DEBUG_LOCALS - if ( xml_doc ) - printout(INFO,"Locals","PUSH[%d]: %s [%s]", preserv_level++, obj_path.c_str(), xml_doc->id.c_str()); - else - printout(INFO,"Locals","PUSH[%d]: %s ", preserv_level++, obj_path.c_str()); + if ( xml_doc ) + printout(INFO,"Locals","PUSH[%d]: %s [%s]", preserv_level++, obj_path.c_str(), xml_doc->id.c_str()); + else + printout(INFO,"Locals","PUSH[%d]: %s ", preserv_level++, obj_path.c_str()); #endif - } - ~PreservedLocals() { + } + ~PreservedLocals() { #ifdef __DEBUG_LOCALS - if ( xml_doc ) - printout(INFO,"Locals","POP [%d]: %s [%s]", --preserv_level, obj_path.c_str(), xml_doc->id.c_str()); - else - printout(INFO,"Locals","POP [%d]: %s", --preserv_level, obj_path.c_str()); + if ( xml_doc ) + printout(INFO,"Locals","POP [%d]: %s [%s]", --preserv_level, obj_path.c_str(), xml_doc->id.c_str()); + else + printout(INFO,"Locals","POP [%d]: %s", --preserv_level, obj_path.c_str()); #endif - context->locals = *this; - } + context->locals = *this; + } }; public: @@ -156,22 +157,22 @@ namespace DD4hep { /// Default constructor Context(lcdd_t& l) - : lcdd(l), resolver(0), geo(0), - print_xml(false), - print_docs(false), - print_materials(false), - print_logvol(false), - print_shapes(false), - print_physvol(false), - print_params(false), - print_detelem(false), - print_detelem_ref(false), - print_detelem_xml(false), - print_condition(false), - print_condition_ref(false), - print_catalog(false), - print_catalog_ref(false), - print_tabprop(false) + : lcdd(l), resolver(0), geo(0), + print_xml(false), + print_docs(false), + print_materials(false), + print_logvol(false), + print_shapes(false), + print_physvol(false), + print_params(false), + print_detelem(false), + print_detelem_ref(false), + print_detelem_xml(false), + print_condition(false), + print_condition_ref(false), + print_catalog(false), + print_catalog_ref(false), + print_tabprop(false) { } /// Default destructor ~Context() { @@ -315,14 +316,14 @@ namespace DD4hep { xml_h find_local_element(xml_elt_t element, const string& ref, const xml_tag_t& tag) { size_t hash = ref.find("#"); if ( hash == 0 ) { - string name = ref.substr(1); - xml_h root = element.document().root(); - for(xml_coll_t coll(root,tag); coll; ++coll ) { - string entry = coll.attr<string>(_U(name)); - if ( entry == name ) { - return coll; - } - } + string name = ref.substr(1); + xml_h root = element.document().root(); + for(xml_coll_t coll(root,tag); coll; ++coll ) { + string entry = coll.attr<string>(_U(name)); + if ( entry == name ) { + return coll; + } + } } return xml_h(0); } @@ -368,10 +369,10 @@ namespace DD4hep { template <typename ACTION=dddb> void load_dddb_entity(Context* context, - Catalog* catalog, - xml_h element, - const string& ref, - bool print=false); + Catalog* catalog, + xml_h element, + const string& ref, + bool print=false); /// Helper to locate objects in a map using string identifiers template <typename Q> bool _find(const string& id, const Q& container) { @@ -453,110 +454,110 @@ namespace DD4hep { } template<typename KEY, typename VAL> - static void insert_map_item(const KEY& k, const string& val, BlockData& block) { + static void insert_map_item(const KEY& k, const string& val, OpaqueDataBlock& block) { typedef std::map<KEY,VAL> map_t; map_t& m = block.get<map_t>(); VAL v; if ( !BasicGrammar::instance<VAL>().fromString(&v, val) ) { - except("Condition::map","++ Failed to convert conditions map entry."); + except("Condition::map","++ Failed to convert conditions map entry."); } m.insert(make_pair(k,v)); } template<typename KEY> static void insert_map_key(const string& key_val, const string& val_type, - const string& val, BlockData& block) + const string& val, OpaqueDataBlock& block) { KEY key; BasicGrammar::instance<KEY>().fromString(&key, key_val); if ( val_type.substr(0,5) == "short" ) - insert_map_item<KEY,short>(key,val,block); + insert_map_item<KEY,short>(key,val,block); else if ( val_type.substr(0,3) == "int" ) - insert_map_item<KEY,int>(key,val,block); + insert_map_item<KEY,int>(key,val,block); else if ( val_type.substr(0,4) == "long" ) - insert_map_item<KEY,long>(key,val,block); + insert_map_item<KEY,long>(key,val,block); else if ( val_type.substr(0,5) == "float" ) - insert_map_item<KEY,float>(key,val,block); + insert_map_item<KEY,float>(key,val,block); else if ( val_type.substr(0,6) == "double" ) - insert_map_item<KEY,double>(key,val,block); + insert_map_item<KEY,double>(key,val,block); else if ( val_type.substr(0,6) == "string" ) - insert_map_item<KEY,string>(key,val,block); + insert_map_item<KEY,string>(key,val,block); else if ( val_type == "std::string" ) - insert_map_item<KEY,string>(key,val,block); + insert_map_item<KEY,string>(key,val,block); else { - printout(INFO,"Param","++ Unknown conditions parameter type:%s data:%s", - val_type.c_str(),val.c_str()); - insert_map_item<KEY,string>(key,val,block); + printout(INFO,"Param","++ Unknown conditions parameter type:%s data:%s", + val_type.c_str(),val.c_str()); + insert_map_item<KEY,string>(key,val,block); } } template<typename KEY> - static void bind_map(const string& val_type, BlockData& block) { + static void bind_map(const string& val_type, OpaqueDataBlock& block) { if ( val_type.substr(0,5) == "short" ) - block.bind< map<KEY,short> >(); + block.bind< map<KEY,short> >(); else if ( val_type.substr(0,3) == "int" ) - block.bind< map<KEY,int> >(); + block.bind< map<KEY,int> >(); else if ( val_type.substr(0,4) == "long" ) - block.bind< map<KEY,long> >(); + block.bind< map<KEY,long> >(); else if ( val_type.substr(0,5) == "float" ) - block.bind< map<KEY,float> >(); + block.bind< map<KEY,float> >(); else if ( val_type.substr(0,6) == "double" ) - block.bind< map<KEY,double> >(); + block.bind< map<KEY,double> >(); else if ( val_type.substr(0,6) == "string" ) - block.bind< map<KEY,string> >(); + block.bind< map<KEY,string> >(); else if ( val_type == "std::string" ) - block.bind< map<KEY,string> >(); + block.bind< map<KEY,string> >(); else { - block.bind< map<KEY,string> >(); + block.bind< map<KEY,string> >(); } } - static void extractMap(xml_h element, BlockData& block) { + static void extractMap(xml_h element, OpaqueDataBlock& block) { dddb_dim_t e = element; string n = e.nameStr(); string key_type = e.attr<string>(_LBU(keytype)); string val_type = e.attr<string>(_LBU(valuetype)); if ( key_type.substr(0,5) == "short" ) - bind_map<short>(val_type,block); + bind_map<short>(val_type,block); else if ( key_type.substr(0,3) == "int" ) - bind_map<int>(val_type,block); + bind_map<int>(val_type,block); else if ( key_type.substr(0,4) == "long" ) - bind_map<long>(val_type,block); + bind_map<long>(val_type,block); else if ( key_type.substr(0,5) == "float" ) - bind_map<float>(val_type,block); + bind_map<float>(val_type,block); else if ( key_type.substr(0,6) == "double" ) - bind_map<double>(val_type,block); + bind_map<double>(val_type,block); else if ( key_type.substr(0,6) == "string" ) - bind_map<string>(val_type,block); + bind_map<string>(val_type,block); else if ( key_type == "std::string" ) - bind_map<string>(val_type,block); + bind_map<string>(val_type,block); else { - printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); - bind_map<string>(val_type,block); + printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); + bind_map<string>(val_type,block); } for(xml_coll_t i(e,_LBU(item)); i; ++i) { - string key = i.attr<string>(_LBU(key)); - string val = i.attr<string>(_LBU(value)); - if ( key_type.substr(0,5) == "short" ) - insert_map_key<short>(key,val_type,val,block); - else if ( key_type.substr(0,3) == "int" ) - insert_map_key<int>(key,val_type,val,block); - else if ( key_type.substr(0,4) == "long" ) - insert_map_key<long>(key,val_type,val,block); - else if ( key_type.substr(0,5) == "float" ) - insert_map_key<float>(key,val_type,val,block); - else if ( key_type.substr(0,6) == "double" ) - insert_map_key<double>(key,val_type,val,block); - else if ( key_type.substr(0,6) == "string" ) - insert_map_key<string>(key,val_type,val,block); - else if ( key_type == "std::string" ) - insert_map_key<string>(key,val_type,val,block); - else { - printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); - insert_map_key<string>(key,val_type,val,block); - } + string key = i.attr<string>(_LBU(key)); + string val = i.attr<string>(_LBU(value)); + if ( key_type.substr(0,5) == "short" ) + insert_map_key<short>(key,val_type,val,block); + else if ( key_type.substr(0,3) == "int" ) + insert_map_key<int>(key,val_type,val,block); + else if ( key_type.substr(0,4) == "long" ) + insert_map_key<long>(key,val_type,val,block); + else if ( key_type.substr(0,5) == "float" ) + insert_map_key<float>(key,val_type,val,block); + else if ( key_type.substr(0,6) == "double" ) + insert_map_key<double>(key,val_type,val,block); + else if ( key_type.substr(0,6) == "string" ) + insert_map_key<string>(key,val_type,val,block); + else if ( key_type == "std::string" ) + insert_map_key<string>(key,val_type,val,block); + else { + printout(INFO,"Param","++ Unknown MAP-conditions key-type:%s",key_type.c_str()); + insert_map_key<string>(key,val_type,val,block); + } } } @@ -565,35 +566,35 @@ namespace DD4hep { string nam = element.attr<string>(_U(name)); string typ = element.hasAttr(_U(type)) ? element.attr<string>(_U(type)) : string("int"); string data = element.text(); - pair<string,BlockData> block; + pair<string,OpaqueDataBlock> block; block.first = nam; if ( typ.substr(0,5) == "short" ) - block.second.set<short>(data); + block.second.set<short>(data); else if ( typ.substr(0,3) == "int" ) - block.second.set<int>(data); + block.second.set<int>(data); else if ( typ.substr(0,4) == "long" ) - block.second.set<long>(data); + block.second.set<long>(data); else if ( typ.substr(0,5) == "float" ) - block.second.set<float>(data); + block.second.set<float>(data); else if ( typ.substr(0,6) == "double" ) - block.second.set<double>(data); + block.second.set<double>(data); else if ( typ.substr(0,6) == "string" ) - block.second.set<string>(data); + block.second.set<string>(data); else if ( typ == "std::string" ) - block.second.set<string>(data); + block.second.set<string>(data); else if ( typ == "Histo1D" ) - block.second.set<string>(data); + block.second.set<string>(data); else if ( typ == "Histo2D" ) - block.second.set<string>(data); + block.second.set<string>(data); else { - printout(INFO,"Param","++ Unknown conditions parameter type:%s data:%s",typ.c_str(),data.c_str()); - block.second.set<string>(data); + printout(INFO,"Param","++ Unknown conditions parameter type:%s data:%s",typ.c_str(),data.c_str()); + block.second.set<string>(data); } ConditionParams* par = _option<ConditionParams>(); pair<ConditionParams::iterator,bool> res = par->insert(block); if ( !res.second ) { - printout(INFO,"ParamVector","++ Failed to insert condition parameter:%s",nam.c_str()); + printout(INFO,"ParamVector","++ Failed to insert condition parameter:%s",nam.c_str()); } } @@ -602,70 +603,70 @@ namespace DD4hep { string nam = element.attr<string>(_U(name)); string typ = element.hasAttr(_U(type)) ? element.attr<string>(_U(type)) : string("int"); string data = element.text(); - pair<string,BlockData> block; + pair<string,OpaqueDataBlock> block; string d = "["+data+" "; size_t idx, idq; block.first = nam; for(idx = d.find_first_not_of(' ',1); idx != string::npos;) { - if ( ::isspace(d[idx]) ) d[idx] = ' '; - idx = d.find_first_not_of(' ',++idx); + if ( ::isspace(d[idx]) ) d[idx] = ' '; + idx = d.find_first_not_of(' ',++idx); } for(idx = d.find_first_not_of(' ',1); idx != string::npos; ++idx) { - if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; - idq = d.find_first_of(' ',idx); - if ( idq != string::npos ) { - idx = d.find_first_not_of(' ',idq); - if ( idx == string::npos ) break; - if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; - d[idq] = ','; - continue; - } - break; + if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; + idq = d.find_first_of(' ',idx); + if ( idq != string::npos ) { + idx = d.find_first_not_of(' ',idq); + if ( idx == string::npos ) break; + if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; + d[idq] = ','; + continue; + } + break; } d[d.length()-1] = ']'; if ( typ.substr(0,5) == "short" ) - block.second.set<vector<short> >(d); + block.second.set<vector<short> >(d); else if ( typ.substr(0,3) == "int" ) - block.second.set<vector<int> >(d); + block.second.set<vector<int> >(d); else if ( typ.substr(0,4) == "long" ) - block.second.set<vector<long> >(d); + block.second.set<vector<long> >(d); else if ( typ.substr(0,5) == "float" ) - block.second.set<vector<float> >(d); + block.second.set<vector<float> >(d); else if ( typ.substr(0,6) == "double" ) - block.second.set<vector<double> >(d); + block.second.set<vector<double> >(d); else if ( typ.substr(0,6) == "string" ) - block.second.set<vector<string> >(d); + block.second.set<vector<string> >(d); else if ( typ == "std::string" ) - block.second.set<vector<string> >(d); + block.second.set<vector<string> >(d); else { - printout(INFO,"ParamVector","++ Unknown conditions parameter type:%s",typ.c_str()); - block.second.set<vector<string> >(d); + printout(INFO,"ParamVector","++ Unknown conditions parameter type:%s",typ.c_str()); + block.second.set<vector<string> >(d); } ConditionParams* par = _option<ConditionParams>(); pair<ConditionParams::iterator,bool> res = par->insert(block); if ( !res.second ) { - printout(INFO,"ParamVector","++ Failed to insert condition parameter:%s",nam.c_str()); + printout(INFO,"ParamVector","++ Failed to insert condition parameter:%s",nam.c_str()); } } /// Specialized conversion of <map/> conditions entities template <> void Conv<ConditionParamMap>::convert(xml_h element) const { string nam = element.attr<string>(_U(name)); - pair<string,BlockData> block; + pair<string,OpaqueDataBlock> block; block.first = nam; extractMap(element,block.second); ConditionParams* par = _option<ConditionParams>(); pair<ConditionParams::iterator,bool> res = par->insert(block); if ( !res.second ) - printout(INFO,"ParamMap","++ Failed to insert map-condition:%s",nam.c_str()); + printout(INFO,"ParamMap","++ Failed to insert map-condition:%s",nam.c_str()); } /// Specialized conversion of <specific/> conditions entities template <> void Conv<ConditionParamSpecific>::convert(xml_h element) const { string nam = element.parent().attr<string>(_U(name)); - pair<string,BlockData> block; + pair<string,OpaqueDataBlock> block; stringstream str; XML::dump_tree(element, str); @@ -675,7 +676,7 @@ namespace DD4hep { ConditionParams* par = _option<ConditionParams>(); pair<ConditionParams::iterator,bool> res = par->insert(block); if ( !res.second ) { - printout(INFO,"ParamVector","++ Failed to insert condition entry:%s of type <specific/>",nam.c_str()); + printout(INFO,"ParamVector","++ Failed to insert condition entry:%s of type <specific/>",nam.c_str()); } } @@ -688,33 +689,33 @@ namespace DD4hep { size_t idx, idq; for(idx = d.find_first_not_of(' ',1); idx != string::npos;) { - if ( ::isspace(d[idx]) ) d[idx] = ' '; - idx = d.find_first_not_of(' ',++idx); + if ( ::isspace(d[idx]) ) d[idx] = ' '; + idx = d.find_first_not_of(' ',++idx); } for(idx = d.find_first_not_of(' ',1); idx != string::npos; ++idx) { - if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; - idq = d.find_first_of(' ',idx); - if ( idq != string::npos ) { - idx = d.find_first_not_of(' ',idq); - if ( idx == string::npos ) break; - if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; - d[idq] = ','; - continue; - } - break; + if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; + idq = d.find_first_of(' ',idx); + if ( idq != string::npos ) { + idx = d.find_first_not_of(' ',idq); + if ( idx == string::npos ) break; + if ( d[idx] != ' ' && ::isspace(d[idx]) ) d[idx] = ' '; + d[idq] = ','; + continue; + } + break; } d[d.length()-1] = ')'; - Geometry::Position pos; - const BasicGrammar& g = BasicGrammar::instance<Geometry::Position>(); + Position pos; + const BasicGrammar& g = BasicGrammar::instance<Position>(); if ( !g.fromString(&pos,d) ) g.invalidConversion(d, g.type()); if ( nam == "dPosXYZ" ) - a->position = pos; + a->translation = pos; else if ( nam == "dRotXYZ" ) - a->rotation = AlignmentDelta::Rotation(pos.z(),pos.y(),pos.x()); + a->rotation = RotationZYX(pos.z(),pos.y(),pos.x()); else if ( nam == "pivotXYZ" ) - a->pivot = pos; + a->pivot = pos; else - printout(ERROR,"AlignmentDelta","++ Unknown alignment conditions tag: %s",nam.c_str()); + printout(ERROR,"AlignmentDelta","++ Unknown alignment conditions tag: %s",nam.c_str()); } /// Specialized conversion of <condition/> entities @@ -723,76 +724,76 @@ namespace DD4hep { string name = element.attr<string>(_U(name)); string id = object_href(element,name); if ( !_find(id, context->geo->conditions) ) { - Catalog* catalog = _option<Catalog>(); - Document* doc = context->locals.xml_doc; - - string path = object_path(context,name); - static int num_param=0, num_vector=0, num_map=0, num_spec=0, num_align=0; - - Condition cond(path,"DDDB"); - cond->address = id; - cond->value = path; // doc->name; - cond->validity = ""; - cond->hash = Conditions::ConditionKey::hashCode(cond->value); - cond->setFlag(Condition::ACTIVE); - if ( element.hasAttr(_U(comment)) ) { - cond->comment = element.attr<string>(_U(comment)); - } - - AbstractMap& d = cond.bind<AbstractMap>(); - d.clientData = doc->addRef(); - d.classID = -1; - if ( element.hasAttr(_LBU(classID)) ) { - d.classID = element.attr<int>(_LBU(classID)); - } - if ( d.classID == AbstractMap::ALIGNMENT ) { - pair<string,BlockData> block; - AlignmentDelta& align = block.second.bind<AlignmentDelta>(); - Conv<AlignmentDelta> conv(lcdd,context,&align); - block.first = name; - xml_coll_t(element,_LBU(paramVector)).for_each(conv); - pair<ConditionParams::iterator,bool> res = d.params.insert(block); - if ( !res.second ) { - printout(INFO,"ParamVector","++ Failed to insert condition parameter:%s",name.c_str()); - } - ++num_align; - } - else { - Conv<ConditionParam> object_cnv(lcdd,context,&d.params); - xml_coll_t(element,_U(param)).for_each(object_cnv); - - Conv<ConditionParamVector> vector_cnv(lcdd,context,&d.params); - xml_coll_t(element,_LBU(paramVector)).for_each(vector_cnv); - - Conv<ConditionParamMap> map_cnv(lcdd,context,&d.params); - xml_coll_t(element,_LBU(map)).for_each(map_cnv); - - Conv<ConditionParamSpecific> specific_cnv(lcdd,context,&d.params); - xml_coll_t(element,_LBU(specific)).for_each(specific_cnv); - } - for(xml_coll_t iter(element,_U(star)); iter; ++iter) { - string tag = iter.tag(); - string nam = iter.hasAttr(_U(name)) ? iter.attr<string>(_U(name)) : string(); - if ( context->print_condition ) { - printout(INFO,"ParamMap","++ Condition:%s -> %s",path.c_str(),nam.c_str()); - } - if ( d.classID == AbstractMap::ALIGNMENT ) { continue; } - if ( tag == "param" ) { ++num_param; continue; } - if ( tag == "paramVector" ) { ++num_vector; continue; } - if ( tag == "map" ) { ++num_map; continue; } - if ( tag == "specific" ) { ++num_spec; continue; } - printout(INFO,"Condition","++ Unknown conditions tag:%s obj:%s id:%s", - tag.c_str(), path.c_str(), id.c_str()); - } - context->collect(id, cond); - if ( catalog ) { - context->collectPath(path, cond); - } - num_param += int(d.params.size()); - if ( (context->geo->conditions.size()%500) == 0 ) { - printout(INFO,"Condition","++ Processed %d conditions....last:%s Number of Params: %d Vec:%d Map:%d Spec:%d Align:%d", - int(context->geo->conditions.size()), path.c_str(), num_param, num_vector, num_map, num_spec, num_align); - } + Catalog* catalog = _option<Catalog>(); + Document* doc = context->locals.xml_doc; + + string path = object_path(context,name); + static int num_param=0, num_vector=0, num_map=0, num_spec=0, num_align=0; + + Condition cond(path,"DDDB"); + cond->address = id; + cond->value = path; // doc->name; + cond->validity = ""; + cond->hash = Conditions::ConditionKey::hashCode(cond->value); + cond->setFlag(Condition::ACTIVE); + if ( element.hasAttr(_U(comment)) ) { + cond->comment = element.attr<string>(_U(comment)); + } + + AbstractMap& d = cond.bind<AbstractMap>(); + d.clientData = doc->addRef(); + d.classID = -1; + if ( element.hasAttr(_LBU(classID)) ) { + d.classID = element.attr<int>(_LBU(classID)); + } + if ( d.classID == AbstractMap::ALIGNMENT ) { + pair<string,OpaqueDataBlock> block; + AlignmentDelta& align = block.second.bind<AlignmentDelta>(); + Conv<AlignmentDelta> conv(lcdd,context,&align); + block.first = name; + xml_coll_t(element,_LBU(paramVector)).for_each(conv); + pair<ConditionParams::iterator,bool> res = d.params.insert(block); + if ( !res.second ) { + printout(INFO,"ParamVector","++ Failed to insert condition parameter:%s",name.c_str()); + } + ++num_align; + } + else { + Conv<ConditionParam> object_cnv(lcdd,context,&d.params); + xml_coll_t(element,_U(param)).for_each(object_cnv); + + Conv<ConditionParamVector> vector_cnv(lcdd,context,&d.params); + xml_coll_t(element,_LBU(paramVector)).for_each(vector_cnv); + + Conv<ConditionParamMap> map_cnv(lcdd,context,&d.params); + xml_coll_t(element,_LBU(map)).for_each(map_cnv); + + Conv<ConditionParamSpecific> specific_cnv(lcdd,context,&d.params); + xml_coll_t(element,_LBU(specific)).for_each(specific_cnv); + } + for(xml_coll_t iter(element,_U(star)); iter; ++iter) { + string tag = iter.tag(); + string nam = iter.hasAttr(_U(name)) ? iter.attr<string>(_U(name)) : string(); + if ( context->print_condition ) { + printout(INFO,"ParamMap","++ Condition:%s -> %s",path.c_str(),nam.c_str()); + } + if ( d.classID == AbstractMap::ALIGNMENT ) { continue; } + if ( tag == "param" ) { ++num_param; continue; } + if ( tag == "paramVector" ) { ++num_vector; continue; } + if ( tag == "map" ) { ++num_map; continue; } + if ( tag == "specific" ) { ++num_spec; continue; } + printout(INFO,"Condition","++ Unknown conditions tag:%s obj:%s id:%s", + tag.c_str(), path.c_str(), id.c_str()); + } + context->collect(id, cond); + if ( catalog ) { + context->collectPath(path, cond); + } + num_param += int(d.params.size()); + if ( (context->geo->conditions.size()%500) == 0 ) { + printout(INFO,"Condition","++ Processed %d conditions....last:%s Number of Params: %d Vec:%d Map:%d Spec:%d Align:%d", + int(context->geo->conditions.size()), path.c_str(), num_param, num_vector, num_map, num_spec, num_align); + } } } @@ -806,23 +807,23 @@ namespace DD4hep { xml_h target = find_local_element(element, href, _LBU(condition)); if ( target ) - Conv<Condition>(lcdd,context,catalog)(target); + Conv<Condition>(lcdd,context,catalog)(target); else - load_dddb_entity(context, catalog, element, href); + load_dddb_entity(context, catalog, element, href); dddb::Conditions::const_iterator i=context->geo->conditions.find(refid); if ( i == context->geo->conditions.end() ) { - printout(ERROR,"ConditionRef","++ MISSING ID: %s Failed to convert ref:%s cat:%s", - refid.c_str(),path.c_str(), catalog ? catalog->path.c_str() : "???"); - if ( context->print_condition_ref ) { - print_ref("ConditionRef", context, element, href, "Path:----"); - } - return; + printout(ERROR,"ConditionRef","++ MISSING ID: %s Failed to convert ref:%s cat:%s", + refid.c_str(),path.c_str(), catalog ? catalog->path.c_str() : "???"); + if ( context->print_condition_ref ) { + print_ref("ConditionRef", context, element, href, "Path:----"); + } + return; } Condition cond((*i).second); path = object_path(context,cond->name); context->collectPath(path, cond); if ( context->print_condition_ref ) { - print_ref("ConditionRef", context, element, href, "Path:"+path); + print_ref("ConditionRef", context, element, href, "Path:"+path); } } @@ -862,13 +863,13 @@ namespace DD4hep { string name = x_i.nameStr(); string id = object_path(context,name); if ( !_find(id, context->geo->isotopes) ) { - Isotope* i = new Isotope(); - i->name = name; - i->A = x_i.A(-1.0); - i->Z = x_i.Z(-1.0); - i->density = x_i.density(-1.0); - context->collect(id, i); - i->setDocument(context->locals.xml_doc); + Isotope* i = new Isotope(); + i->name = name; + i->A = x_i.A(-1.0); + i->Z = x_i.Z(-1.0); + i->density = x_i.density(-1.0); + context->collect(id, i); + i->setDocument(context->locals.xml_doc); } } @@ -881,7 +882,7 @@ namespace DD4hep { load_dddb_entity(context, catalog, element, href); dddb::Elements::const_iterator i=context->geo->elements.find(refid); if ( i == context->geo->elements.end() ) { - printout(ERROR,"ElementRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); + printout(ERROR,"ElementRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); } Element* e = (*i).second; string path = object_path(context,e->name); @@ -895,31 +896,31 @@ namespace DD4hep { string name = x_elem.nameStr(); string id = object_href(element, name); if ( !_find(id, context->geo->elements) ) { - Element* e = new Element(); - dddb_dim_t atom = x_elem.child(_U(atom),false); - e->id = id; - e->name = name; - e->path = object_path(context,name); - e->density = x_elem.density(-1.0); - e->ionization = x_elem.I(-1.0); - e->symbol = x_elem.symbol(e->name); - e->atom.A = atom ? atom.attr<double>(_U(A)) : -1.0; - e->atom.Zeff = atom ? atom.attr<double>(_U(Zeff)) : -1.0; - string st = x_elem.state(); - if ( st == "solid" ) e->state = Element::SOLID; - else if ( st == "liquid" ) e->state = Element::LIQUID; - else if ( st == "gas" ) e->state = Element::GAS; - else e->state = Element::UNKNOWN; - - for(xml_coll_t p(x_elem,_LBU(isotoperef)); p; ++p) { - dddb_dim_t isotope = p; - double frac = isotope.fractionmass(1.0); - string iso_id = object_path(context,isotope.href()); - e->isotopes.push_back(make_pair(iso_id,frac)); - } - context->collect(e->id, e); - context->collectPath(e->path, e); - e->setDocument(context->locals.xml_doc); + Element* e = new Element(); + dddb_dim_t atom = x_elem.child(_U(atom),false); + e->id = id; + e->name = name; + e->path = object_path(context,name); + e->density = x_elem.density(-1.0); + e->ionization = x_elem.I(-1.0); + e->symbol = x_elem.symbol(e->name); + e->atom.A = atom ? atom.attr<double>(_U(A)) : -1.0; + e->atom.Zeff = atom ? atom.attr<double>(_U(Zeff)) : -1.0; + string st = x_elem.state(); + if ( st == "solid" ) e->state = Element::SOLID; + else if ( st == "liquid" ) e->state = Element::LIQUID; + else if ( st == "gas" ) e->state = Element::GAS; + else e->state = Element::UNKNOWN; + + for(xml_coll_t p(x_elem,_LBU(isotoperef)); p; ++p) { + dddb_dim_t isotope = p; + double frac = isotope.fractionmass(1.0); + string iso_id = object_path(context,isotope.href()); + e->isotopes.push_back(make_pair(iso_id,frac)); + } + context->collect(e->id, e); + context->collectPath(e->path, e); + e->setDocument(context->locals.xml_doc); } } @@ -943,12 +944,12 @@ namespace DD4hep { load_dddb_entity(context, catalog, element, href); dddb::Materials::const_iterator i=context->geo->materials.find(refid); if ( i == context->geo->materials.end() ) { - printout(ERROR,"MaterialRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); + printout(ERROR,"MaterialRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); } if ( catalog ) { - Material* m = (*i).second; - string path = object_path(context,m->name); - context->collectPath(path, m); + Material* m = (*i).second; + string path = object_path(context,m->name); + context->collectPath(path, m); } } @@ -960,23 +961,23 @@ namespace DD4hep { string name = x_mat.nameStr(); string id = object_href(element, name); if ( !_find(id, context->geo->materials) ) { - Material* m = new Material(); - m->name = name; - m->id = id; - m->path = object_path(context,name); - m->density = x_mat.density(-1.0); - m->pressure = x_mat.pressure(-1.0); - m->temperature = x_mat.temperature(-1.0); - m->radlen = x_mat.radlen(-1.0); - m->lambda = x_mat.lambda(-1.0); - for(xml_coll_t p(element,_LBU(tabprops)); p; ++p) - m->properties.push_back(p.attr<string>(_LBU(address))); - - xml_coll_t(element, _U(component)).for_each(Conv<MaterialComponent>(lcdd,context,m)); - context->collect(m->id, m); // We collect materials by NAME!!! - context->collect(m->name, m); - m->setDocument(context->locals.xml_doc); - if ( catalog ) context->collectPath(m->path, m); + Material* m = new Material(); + m->name = name; + m->id = id; + m->path = object_path(context,name); + m->density = x_mat.density(-1.0); + m->pressure = x_mat.pressure(-1.0); + m->temperature = x_mat.temperature(-1.0); + m->radlen = x_mat.radlen(-1.0); + m->lambda = x_mat.lambda(-1.0); + for(xml_coll_t p(element,_LBU(tabprops)); p; ++p) + m->properties.push_back(p.attr<string>(_LBU(address))); + + xml_coll_t(element, _U(component)).for_each(Conv<MaterialComponent>(lcdd,context,m)); + context->collect(m->id, m); // We collect materials by NAME!!! + context->collect(m->name, m); + m->setDocument(context->locals.xml_doc); + if ( catalog ) context->collectPath(m->path, m); } } @@ -1092,7 +1093,7 @@ namespace DD4hep { dddb_dim_t dim = element; ShapeConv<Shape>(lcdd,param)(element,s); if ( s->name == "Cut_out_right" ) { - s->type = to_type::type(); + s->type = to_type::type(); } s->type = to_type::type(); s->s.trap.dz = dim.sizeZ()/2e0; @@ -1175,24 +1176,24 @@ namespace DD4hep { context->locals.obj_path = id; 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 ) { - ShapeConv<BooleanOperation>(lcdd,context)(p,s->s.boolean.first); - s->s.boolean.first->id = id + "/" + s->s.boolean.first->name; - ++p; - } - BooleanOperation op; - ShapeConv<BooleanOperation>(lcdd,context)(p,op.shape); - if ( 0 == op.shape ) { - // Error. What to do? - // Anyhow: ShapeConv<BooleanOperation> throws exception if the - // shape is unknown. We never get here. - } - op.shape->id = id + "/" + op.shape->name; - ++p; - extract_transformation(lcdd, param, p, op.trafo); - s->boolean_ops.push_back(op); - } + if ( p.parent() == element ) { // Only next level is processed here + if ( 0 == s->s.boolean.first ) { + ShapeConv<BooleanOperation>(lcdd,context)(p,s->s.boolean.first); + s->s.boolean.first->id = id + "/" + s->s.boolean.first->name; + ++p; + } + BooleanOperation op; + ShapeConv<BooleanOperation>(lcdd,context)(p,op.shape); + if ( 0 == op.shape ) { + // Error. What to do? + // Anyhow: ShapeConv<BooleanOperation> throws exception if the + // shape is unknown. We never get here. + } + op.shape->id = id + "/" + op.shape->name; + ++p; + extract_transformation(lcdd, param, p, op.trafo); + s->boolean_ops.push_back(op); + } } } @@ -1222,32 +1223,32 @@ namespace DD4hep { // Now convert all possible / supported shapes if ( tag == "box" ) - ShapeConv<Box>(lcdd,context)(elt,s); + ShapeConv<Box>(lcdd,context)(elt,s); else if ( tag == "cons" ) - ShapeConv<Cons>(lcdd,context)(elt,s); + ShapeConv<Cons>(lcdd,context)(elt,s); else if ( tag == "tubs" ) - ShapeConv<Tubs>(lcdd,context)(elt,s); + ShapeConv<Tubs>(lcdd,context)(elt,s); else if ( tag == "trap" ) - ShapeConv<Trap>(lcdd,context)(elt,s); + ShapeConv<Trap>(lcdd,context)(elt,s); else if ( tag == "polycone" ) - ShapeConv<Polycone>(lcdd,context)(elt,s); + ShapeConv<Polycone>(lcdd,context)(elt,s); else if ( tag == "polygon" ) - ShapeConv<Polygon>(lcdd,context)(elt,s); + ShapeConv<Polygon>(lcdd,context)(elt,s); else if ( tag == "trd" ) - ShapeConv<TRD>(lcdd,context)(elt,s); + ShapeConv<TRD>(lcdd,context)(elt,s); else if ( tag == "eltu" ) - ShapeConv<EllipticalTube>(lcdd,context)(elt,s); + ShapeConv<EllipticalTube>(lcdd,context)(elt,s); else if ( tag == "sphere" ) - ShapeConv<Sphere>(lcdd,context)(elt,s); + ShapeConv<Sphere>(lcdd,context)(elt,s); else if ( tag == "union" ) - ShapeConv<BooleanUnion>(lcdd,context)(elt,s); + ShapeConv<BooleanUnion>(lcdd,context)(elt,s); else if ( tag == "subtraction" ) - ShapeConv<BooleanSubtraction>(lcdd,context)(elt,s); + ShapeConv<BooleanSubtraction>(lcdd,context)(elt,s); else if ( tag == "intersection" ) - ShapeConv<BooleanIntersection>(lcdd,context)(elt,s); + ShapeConv<BooleanIntersection>(lcdd,context)(elt,s); else { - XML::dump_tree(element.parent()); - except("BooleanOperation","Unknown shape conversion requested:"+tag); + XML::dump_tree(element.parent()); + except("BooleanOperation","Unknown shape conversion requested:"+tag); } } @@ -1261,15 +1262,15 @@ namespace DD4hep { load_dddb_entity(context, catalog, element, href); dddb::Volumes::const_iterator i=context->geo->volumes.find(refid); if ( i == context->geo->volumes.end() ) { - string r = reference_href(element,href); - printout(ERROR,"LogVolRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); + string r = reference_href(element,href); + printout(ERROR,"LogVolRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); } LogVol* vol = (*i).second; catalog->logvolrefs[vol->id] = vol; string path = object_path(context,vol->name); context->collectPath(path, vol); if ( context->print_logvol ) { - print_ref("LogVolRef", context, element, href, "Path:"+path); + print_ref("LogVolRef", context, element, href, "Path:"+path); } } @@ -1279,67 +1280,67 @@ 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->name = name; - vol->path = object_path(context,name); - if ( element.hasAttr(_U(material)) ) { - vol->material = element.attr<string>(_U(material)); - } - Shape* s = 0; - // Now convert all possible / supported shapes - if ( (elt=element.child(_U(box),false)) ) - ShapeConv<Box>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(cons),false)) ) - ShapeConv<Cons>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(tubs),false)) ) - ShapeConv<Tubs>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(trap),false)) ) - ShapeConv<Trap>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(trd),false)) ) - ShapeConv<TRD>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(polycone),false)) ) - ShapeConv<Polycone>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(sphere),false)) ) - ShapeConv<Sphere>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(union),false)) ) - ShapeConv<BooleanUnion>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(subtraction),false)) ) - ShapeConv<BooleanSubtraction>(lcdd,context)(elt,s); - else if ( (elt=element.child(_U(intersection),false)) ) - ShapeConv<BooleanIntersection>(lcdd,context)(elt,s); - else { - ShapeConv<Assembly>(lcdd,context)(elt,s); - // Dump element if not known and processed.... - for(xml_coll_t p(element,_U(star)); p; ++p) { - if ( p.parent() == element ) { - string tag = p.tag(); - if ( tag == "physvol" ) continue; - if ( tag == "paramphysvol" ) continue; - if ( tag == "paramphysvol2D" ) continue; - if ( tag == "paramphysvol3D" ) continue; - printout(WARNING,"LogVol","++ Unknown and not processed tag found: %s",tag.c_str()); - XML::dump_tree(element); - break; - } - } - } - // Now collect the information - vol->shape = id; - s->setDocument(context->locals.xml_doc); - vol->setDocument(context->locals.xml_doc); - context->collect(id, s); - context->collect(id, vol); - if ( catalog ) context->collectPath(vol->path, vol); - { - Context::PreservedLocals locals(context); - context->locals.obj_path = id; - xml_coll_t(element, _U(physvol)).for_each(Conv<PhysVol>(lcdd,context,vol)); - xml_coll_t(element, _LBU(paramphysvol)).for_each(Conv<ParamPhysVol>(lcdd,context,vol)); - xml_coll_t(element, _LBU(paramphysvol2D)).for_each(Conv<ParamPhysVol2D>(lcdd,context,vol)); - } + Catalog* catalog = _option<Catalog>(); + string material; + LogVol* vol = new LogVol; + xml_h elt; + vol->name = name; + vol->path = object_path(context,name); + if ( element.hasAttr(_U(material)) ) { + vol->material = element.attr<string>(_U(material)); + } + Shape* s = 0; + // Now convert all possible / supported shapes + if ( (elt=element.child(_U(box),false)) ) + ShapeConv<Box>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(cons),false)) ) + ShapeConv<Cons>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(tubs),false)) ) + ShapeConv<Tubs>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(trap),false)) ) + ShapeConv<Trap>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(trd),false)) ) + ShapeConv<TRD>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(polycone),false)) ) + ShapeConv<Polycone>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(sphere),false)) ) + ShapeConv<Sphere>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(union),false)) ) + ShapeConv<BooleanUnion>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(subtraction),false)) ) + ShapeConv<BooleanSubtraction>(lcdd,context)(elt,s); + else if ( (elt=element.child(_U(intersection),false)) ) + ShapeConv<BooleanIntersection>(lcdd,context)(elt,s); + else { + ShapeConv<Assembly>(lcdd,context)(elt,s); + // Dump element if not known and processed.... + for(xml_coll_t p(element,_U(star)); p; ++p) { + if ( p.parent() == element ) { + string tag = p.tag(); + if ( tag == "physvol" ) continue; + if ( tag == "paramphysvol" ) continue; + if ( tag == "paramphysvol2D" ) continue; + if ( tag == "paramphysvol3D" ) continue; + printout(WARNING,"LogVol","++ Unknown and not processed tag found: %s",tag.c_str()); + XML::dump_tree(element); + break; + } + } + } + // Now collect the information + vol->shape = id; + s->setDocument(context->locals.xml_doc); + vol->setDocument(context->locals.xml_doc); + context->collect(id, s); + context->collect(id, vol); + if ( catalog ) context->collectPath(vol->path, vol); + { + Context::PreservedLocals locals(context); + context->locals.obj_path = id; + xml_coll_t(element, _U(physvol)).for_each(Conv<PhysVol>(lcdd,context,vol)); + xml_coll_t(element, _LBU(paramphysvol)).for_each(Conv<ParamPhysVol>(lcdd,context,vol)); + xml_coll_t(element, _LBU(paramphysvol2D)).for_each(Conv<ParamPhysVol2D>(lcdd,context,vol)); + } } } @@ -1361,14 +1362,14 @@ namespace DD4hep { string name = x_vol.nameStr(); string id = object_href(element, name); if ( !_find(id, context->geo->placements) ) { - PhysVol* vol = new PhysVol(); - this->fill(element, vol); - context->collect(id, vol); - context->collectPath(vol->path,vol); - vol->setDocument(context->locals.xml_doc); - if ( optional ) { - _option<LogVol>()->physvols.push_back(vol); - } + PhysVol* vol = new PhysVol(); + this->fill(element, vol); + context->collect(id, vol); + context->collectPath(vol->path,vol); + vol->setDocument(context->locals.xml_doc); + if ( optional ) { + _option<LogVol>()->physvols.push_back(vol); + } } } @@ -1420,17 +1421,17 @@ namespace DD4hep { string name = x_dim.nameStr(); string id = object_href(element, name); if ( !_find(id, context->geo->tabproperties) ) { - TabProperty* p = new TabProperty(); - p->name = name; - p->path = object_path(context,name); - if ( element.hasAttr(_U(type)) ) p->type = element.attr<string>(_U(type)); - if ( element.hasAttr(_LBU(xunit)) ) p->xunit = element.attr<string>(_LBU(xunit)); - if ( element.hasAttr(_LBU(yunit)) ) p->yunit = element.attr<string>(_LBU(yunit)); - if ( element.hasAttr(_LBU(xaxis)) ) p->xaxis = element.attr<string>(_LBU(xaxis)); - if ( element.hasAttr(_LBU(yaxis)) ) p->yaxis = element.attr<string>(_LBU(yaxis)); - context->collect(id, p); - context->collectPath(p->path, p); - p->setDocument(context->locals.xml_doc); + TabProperty* p = new TabProperty(); + p->name = name; + p->path = object_path(context,name); + if ( element.hasAttr(_U(type)) ) p->type = element.attr<string>(_U(type)); + if ( element.hasAttr(_LBU(xunit)) ) p->xunit = element.attr<string>(_LBU(xunit)); + if ( element.hasAttr(_LBU(yunit)) ) p->yunit = element.attr<string>(_LBU(yunit)); + if ( element.hasAttr(_LBU(xaxis)) ) p->xaxis = element.attr<string>(_LBU(xaxis)); + if ( element.hasAttr(_LBU(yaxis)) ) p->yaxis = element.attr<string>(_LBU(yaxis)); + context->collect(id, p); + context->collectPath(p->path, p); + p->setDocument(context->locals.xml_doc); } } @@ -1444,16 +1445,16 @@ namespace DD4hep { load_dddb_entity(context, catalog, element, href); dddb::TabProperties::const_iterator i=context->geo->tabproperties.find(refid); if ( i == context->geo->tabproperties.end() ) { - string r = reference_href(element,href); - printout(ERROR,"TabPropertyRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); - return; + string r = reference_href(element,href); + printout(ERROR,"TabPropertyRef","++ MISSING ID: %s Failed to convert ref:%s",refid.c_str(),href.c_str()); + return; } TabProperty* p = (*i).second; catalog->tabpropertyrefs[p->id] = p; string path = object_path(context,p->name); context->collectPath(path, p); if ( context->print_tabprop ) { - print_ref("TabPropertyRef", context, element, href, "Path:"+path); + print_ref("TabPropertyRef", context, element, href, "Path:"+path); } } @@ -1464,7 +1465,7 @@ namespace DD4hep { string value = element.attr<string>(_U(value)); _toDictionary(name,value); if ( context->print_params ) { - printout(INFO,"Parameter","++ %s = %s",name.c_str(),value.c_str()); + printout(INFO,"Parameter","++ %s = %s",name.c_str(),value.c_str()); } } @@ -1477,13 +1478,13 @@ namespace DD4hep { xml_h target = find_local_element(element, href, _LBU(detelem)); if ( target ) - Conv<DetElem>(lcdd,context,catalog)(target); + Conv<DetElem>(lcdd,context,catalog)(target); else - load_dddb_entity(context, catalog, element, href); + load_dddb_entity(context, catalog, element, href); dddb::Catalogs::const_iterator i=context->geo->catalogs.find(refid); catalog->catalogrefs[refid] = (i==context->geo->catalogs.end()) ? 0 : (*i).second; if ( context->print_detelem_ref ) { - print_ref("DetElemRef", context, element, href); + print_ref("DetElemRef", context, element, href); } } @@ -1497,48 +1498,48 @@ namespace DD4hep { dddb::Catalogs::iterator idet = geo->catalogs.find(id); if ( idet == geo->catalogs.end() ) { - xml_h elt; - string path = object_path(context, name); - boost::filesystem::path p(path); - string parent = p.parent_path().native(); - Catalog* det = new Catalog(); - det->typeID = 1; - det->name = name; - det->type = x_det.typeStr(); - det->path = path; - det->id = id; - det->support = parent; - det->setDocument(context->locals.xml_doc); - if ( context->print_detelem ) { - printout(INFO,"DetElem"," xml:%s id=%s [%s/%s] doc:%s obj:%s / %s", - element.parent().tag().c_str(), - det->id.c_str(), - det->name.c_str(), - det->type.c_str(), - context->locals.xml_doc->id.c_str(), - context->locals.obj_path.c_str(), - det->name.c_str() - ); - } - // Now extract all availible information from the xml - if ( (elt=x_det.child(_U(author),false)) ) - Conv<Author>(lcdd,context,&det->author)(elt); - if ( (elt=x_det.child(_U(version),false)) ) - Conv<Version>(lcdd,context,&det->version)(elt); - xml_coll_t(element, _U(param)).for_each(Conv<Param>(lcdd,context,det)); - xml_coll_t(element, _LBU(userParameter)).for_each(Conv<Param>(lcdd,context,det)); - xml_coll_t(element, _LBU(conditioninfo)).for_each(Conv<ConditionInfo>(lcdd,context,det)); - { - Context::PreservedLocals locals(context); - context->locals.obj_path = det->path; - xml_coll_t(element, _LBU(geometryinfo)).for_each(Conv<GeometryInfo>(lcdd,context,det)); - xml_coll_t(element, _LBU(detelemref)).for_each(Conv<DetElemRef>(lcdd,context,det)); - } - det->path = det->support + "/" + det->name; - context->collect(det->id, det); - context->collectPath(det->path, det); - context->print(det); - return; + xml_h elt; + string path = object_path(context, name); + boost::filesystem::path p(path); + string parent = p.parent_path().native(); + Catalog* det = new Catalog(); + det->typeID = 1; + det->name = name; + det->type = x_det.typeStr(); + det->path = path; + det->id = id; + det->support = parent; + det->setDocument(context->locals.xml_doc); + if ( context->print_detelem ) { + printout(INFO,"DetElem"," xml:%s id=%s [%s/%s] doc:%s obj:%s / %s", + element.parent().tag().c_str(), + det->id.c_str(), + det->name.c_str(), + det->type.c_str(), + context->locals.xml_doc->id.c_str(), + context->locals.obj_path.c_str(), + det->name.c_str() + ); + } + // Now extract all availible information from the xml + if ( (elt=x_det.child(_U(author),false)) ) + Conv<Author>(lcdd,context,&det->author)(elt); + if ( (elt=x_det.child(_U(version),false)) ) + Conv<Version>(lcdd,context,&det->version)(elt); + xml_coll_t(element, _U(param)).for_each(Conv<Param>(lcdd,context,det)); + xml_coll_t(element, _LBU(userParameter)).for_each(Conv<Param>(lcdd,context,det)); + xml_coll_t(element, _LBU(conditioninfo)).for_each(Conv<ConditionInfo>(lcdd,context,det)); + { + Context::PreservedLocals locals(context); + context->locals.obj_path = det->path; + xml_coll_t(element, _LBU(geometryinfo)).for_each(Conv<GeometryInfo>(lcdd,context,det)); + xml_coll_t(element, _LBU(detelemref)).for_each(Conv<DetElemRef>(lcdd,context,det)); + } + det->path = det->support + "/" + det->name; + context->collect(det->id, det); + context->collectPath(det->path, det); + context->print(det); + return; } printout(DEBUG,"DetElem","ALREADY PROCESSED: xid:%s -> %s",id.c_str(),(*idet).second->path.c_str()); } @@ -1551,20 +1552,20 @@ namespace DD4hep { string refid = reference_href(element,href); #if 0 if ( href.find("@ChamAlign.xml#") != string::npos ) { - print_ref("CatalogRef", context, element, href); + print_ref("CatalogRef", context, element, href); } #endif xml_h target = find_local_element(element, href,_LBU(catalog)); if ( target ) { - Conv<Catalog>(lcdd,context,catalog)(target); + Conv<Catalog>(lcdd,context,catalog)(target); } else { - load_dddb_entity(context, catalog, element, href); + load_dddb_entity(context, catalog, element, href); } dddb::Catalogs::const_iterator i=context->geo->catalogs.find(refid); catalog->catalogrefs[refid] = (i == context->geo->catalogs.end()) ? 0 : (*i).second; if ( context->print_catalog_ref ) { - print_ref("CatalogRef", context, element, href); + print_ref("CatalogRef", context, element, href); } } @@ -1576,57 +1577,57 @@ namespace DD4hep { dddb::Catalogs::const_iterator icat = context->geo->catalogs.find(id); if ( icat == context->geo->catalogs.end() ) { - Catalog* catalog = new Catalog(); - catalog->name = name; - catalog->path = object_path(context,name); - //printout(INFO,"Catalog","PROCESSING: xid:%s -> %s",id.c_str(),catalog->path.c_str()); - catalog->level = Increment<Catalog>::counter(); - catalog->type = "Logical"; - catalog->support = ""; - catalog->setDocument(context->locals.xml_doc); - context->collect(id, catalog); - context->collectPath(catalog->path, catalog); - if ( catalog->path == "/dd" ) { - catalog->type = "World"; - context->geo->top = catalog; - } - else if ( catalog->path == "/dd/Structure" ) { - catalog->type = "Structure"; - context->geo->structure = catalog; - } - else if ( catalog->path == "/dd/Geometry" ) { - catalog->type = "Geometry"; - context->geo->geometry = catalog; - } - { - Context::PreservedLocals locals(context); - context->locals.obj_path = catalog->path; - xml_coll_t(e, _U(parameter)).for_each(Conv<Parameter>(lcdd,context,catalog)); - xml_coll_t(e, _U(isotope)).for_each(Conv<Isotope>(lcdd,context,catalog)); - xml_coll_t(e, _U(element)).for_each(Conv<Element>(lcdd,context,catalog)); - xml_coll_t(e, _U(material)).for_each(Conv<Material>(lcdd,context,catalog)); - xml_coll_t(e, _U(logvol)).for_each(Conv<LogVol>(lcdd,context,catalog)); - - xml_coll_t(e, _LBU(tabproperty)).for_each(Conv<TabProperty>(lcdd,context,catalog)); - - //xml_coll_t(e, _LBU(condition)).for_each(Conv<Condition>(lcdd,context,catalog)); - //xml_coll_t(e, _LBU(detelem)).for_each(Conv<DetElem>(lcdd,context,catalog)); - //xml_coll_t(e, _LBU(catalog)).for_each(Conv<Catalog>(lcdd,context,catalog)); - - xml_coll_t(e, _LBU(elementref)).for_each(Conv<ElementRef>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(materialref)).for_each(Conv<MaterialRef>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(logvolref)).for_each(Conv<LogVolRef>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(tabpropertyref)).for_each(Conv<TabPropertyRef>(lcdd,context,catalog)); - - xml_coll_t(e, _LBU(conditionref)).for_each(Conv<ConditionRef>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(catalogref)).for_each(Conv<CatalogRef>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(detelemref)).for_each(Conv<DetElemRef>(lcdd,context,catalog)); - - xml_coll_t(e, _LBU(catalog)).for_each(Conv<Catalog>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(detelem)).for_each(Conv<DetElem>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(condition)).for_each(Conv<Condition>(lcdd,context,catalog)); - } - return; + Catalog* catalog = new Catalog(); + catalog->name = name; + catalog->path = object_path(context,name); + //printout(INFO,"Catalog","PROCESSING: xid:%s -> %s",id.c_str(),catalog->path.c_str()); + catalog->level = Increment<Catalog>::counter(); + catalog->type = "Logical"; + catalog->support = ""; + catalog->setDocument(context->locals.xml_doc); + context->collect(id, catalog); + context->collectPath(catalog->path, catalog); + if ( catalog->path == "/dd" ) { + catalog->type = "World"; + context->geo->top = catalog; + } + else if ( catalog->path == "/dd/Structure" ) { + catalog->type = "Structure"; + context->geo->structure = catalog; + } + else if ( catalog->path == "/dd/Geometry" ) { + catalog->type = "Geometry"; + context->geo->geometry = catalog; + } + { + Context::PreservedLocals locals(context); + context->locals.obj_path = catalog->path; + xml_coll_t(e, _U(parameter)).for_each(Conv<Parameter>(lcdd,context,catalog)); + xml_coll_t(e, _U(isotope)).for_each(Conv<Isotope>(lcdd,context,catalog)); + xml_coll_t(e, _U(element)).for_each(Conv<Element>(lcdd,context,catalog)); + xml_coll_t(e, _U(material)).for_each(Conv<Material>(lcdd,context,catalog)); + xml_coll_t(e, _U(logvol)).for_each(Conv<LogVol>(lcdd,context,catalog)); + + xml_coll_t(e, _LBU(tabproperty)).for_each(Conv<TabProperty>(lcdd,context,catalog)); + + //xml_coll_t(e, _LBU(condition)).for_each(Conv<Condition>(lcdd,context,catalog)); + //xml_coll_t(e, _LBU(detelem)).for_each(Conv<DetElem>(lcdd,context,catalog)); + //xml_coll_t(e, _LBU(catalog)).for_each(Conv<Catalog>(lcdd,context,catalog)); + + xml_coll_t(e, _LBU(elementref)).for_each(Conv<ElementRef>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(materialref)).for_each(Conv<MaterialRef>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(logvolref)).for_each(Conv<LogVolRef>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(tabpropertyref)).for_each(Conv<TabPropertyRef>(lcdd,context,catalog)); + + xml_coll_t(e, _LBU(conditionref)).for_each(Conv<ConditionRef>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(catalogref)).for_each(Conv<CatalogRef>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(detelemref)).for_each(Conv<DetElemRef>(lcdd,context,catalog)); + + xml_coll_t(e, _LBU(catalog)).for_each(Conv<Catalog>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(detelem)).for_each(Conv<DetElem>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(condition)).for_each(Conv<Condition>(lcdd,context,catalog)); + } + return; } printout(DEBUG,"Catalog","ALREADY PROCESSED: xid:%s -> %s",id.c_str(),(*icat).second->path.c_str()); } @@ -1667,42 +1668,42 @@ namespace DD4hep { xml_coll_t(e, _LBU(conditionref)).for_each(Conv<ConditionRef>(lcdd,context,catalog)); xml_coll_t(e, _LBU(catalogref)).for_each(Conv<CatalogRef>(lcdd,context,catalog)); { - Context::PreservedLocals locals(context); - xml_coll_t(e, _LBU(condition)).for_each(Conv<Condition>(lcdd,context,catalog)); - xml_coll_t(e, _LBU(catalog)).for_each(Conv<Catalog>(lcdd,context,catalog)); + Context::PreservedLocals locals(context); + xml_coll_t(e, _LBU(condition)).for_each(Conv<Condition>(lcdd,context,catalog)); + xml_coll_t(e, _LBU(catalog)).for_each(Conv<Catalog>(lcdd,context,catalog)); } } void apply_trafo(int apply, Position& pos, RotationZYX& rot, Transform3D& trafo, Transform3D& tr) { switch(apply) { case 99: { - tr *= trafo; - trafo = Transform3D(); - pos = Position(); - rot = RotationZYX(); - break; + tr *= trafo; + trafo = Transform3D(); + pos = Position(); + rot = RotationZYX(); + break; } case 2: { - Transform3D r(rot); - trafo = Transform3D(pos); - trafo = trafo * r; - tr = trafo * tr; - trafo = Transform3D(); - pos = Position(); - rot = RotationZYX(); - break; + Transform3D r(rot); + trafo = Transform3D(pos); + trafo = trafo * r; + tr = trafo * tr; + trafo = Transform3D(); + pos = Position(); + rot = RotationZYX(); + break; } case 1: { - trafo = Transform3D(pos); - tr *= trafo; - trafo = Transform3D(); - pos = Position(); - rot = RotationZYX(); - break; + trafo = Transform3D(pos); + tr *= trafo; + trafo = Transform3D(); + pos = Position(); + rot = RotationZYX(); + break; } case 0: default: - break; + break; } } @@ -1713,37 +1714,37 @@ namespace DD4hep { RotationZYX rot; 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); - Conv<Transform3D>(lcdd,context,&trafo)(p); - apply = 99; - } - else if ( tag == "posXYZ" && (which<0 || count == which) ) { - apply_trafo(apply, pos, rot, trafo, tr); - 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)) ) { - rot.SetComponents(dim.rotZ(0.0), dim.rotY(0.0), dim.rotX(0.0)); - apply = 2; - } - else { - --p; - apply_trafo(apply, pos, rot, trafo, tr); - return; - } - if ( apply > 1 ) { - apply_trafo(apply, pos, rot, trafo, tr); - apply = 0; - } - } + 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); + Conv<Transform3D>(lcdd,context,&trafo)(p); + apply = 99; + } + else if ( tag == "posXYZ" && (which<0 || count == which) ) { + apply_trafo(apply, pos, rot, trafo, tr); + 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)) ) { + rot.SetComponents(dim.rotZ(0.0), dim.rotY(0.0), dim.rotX(0.0)); + apply = 2; + } + else { + --p; + apply_trafo(apply, pos, rot, trafo, tr); + return; + } + if ( apply > 1 ) { + apply_trafo(apply, pos, rot, trafo, tr); + apply = 0; + } + } } if ( apply > 0 ) { - apply_trafo(apply, pos, rot, trafo, tr); + apply_trafo(apply, pos, rot, trafo, tr); } } string reference_href(xml_h element, const string& ref) { @@ -1752,19 +1753,19 @@ namespace DD4hep { size_t idq = ref.find("/"); if ( idx != string::npos && idx < idq ) { - if ( hash == string::npos && idq != string::npos ) { - if ( (idq=ref.rfind("/")) != string::npos ) - return ref + '#' + ref.substr(idq+1); - } - return ref; + if ( hash == string::npos && idq != string::npos ) { + if ( (idq=ref.rfind("/")) != string::npos ) + return ref + '#' + ref.substr(idq+1); + } + return ref; } // Resolve relative path string p = XML::DocumentHandler::system_path(element); if ( hash == 0 ) { // This is a local object. Take the element's path - p += ref; - boost::filesystem::path path = p; // Remote object. Parent + local path - p = path.normalize().native(); - return p; + p += ref; + boost::filesystem::path path = p; // Remote object. Parent + local path + p = path.normalize().native(); + return p; } boost::filesystem::path path = p; // Remote object. Parent + local path path = path.parent_path(); @@ -1776,96 +1777,96 @@ namespace DD4hep { /// conddb:/Conditions/Online/L0MUON/Q1/FOI instead of: /// conddb:/Conditions/Online/L0MUON/Q1/FOI#FOI ... if ( hash == string::npos ) { - if ( (idq=p.rfind("/")) != string::npos ) - p += '#' + p.substr(idq+1); - else if ( (idx=p.find(":")) != string::npos ) - p += '#' + p.substr(idx+1); - else - p += '#' + ref; + if ( (idq=p.rfind("/")) != string::npos ) + p += '#' + p.substr(idq+1); + else if ( (idx=p.find(":")) != string::npos ) + p += '#' + p.substr(idx+1); + else + p += '#' + ref; } return p; } template <typename ACTION=dddb> void load_dddb_entity(Context* context, - Catalog* catalog, - xml_h element, - const string& ref, - bool prt) + Catalog* catalog, + xml_h element, + const string& ref, + bool prt) { size_t hash = ref.find("#"); if ( hash != 0 ) { - try { - string doc_path = element.ptr() ? reference_href(element,ref) : ref; - if ( ref == "conddb:/Conditions/Online" ) - doc_path = reference_href(element,ref); - hash = doc_path.find('#'); - if ( hash != string::npos ) doc_path = doc_path.substr(0,hash); + try { + string doc_path = element.ptr() ? reference_href(element,ref) : ref; + if ( ref == "conddb:/Conditions/Online" ) + 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("conddb:/Rich") != string::npos ) { - printout(INFO, "load_dddb", "SKIPPING DOC %s", doc_path.c_str()); - return; - } + if ( doc_path.find("conddb:/Rich") != string::npos ) { + printout(INFO, "load_dddb", "SKIPPING DOC %s", doc_path.c_str()); + return; + } #endif - dddb::Documents& docs = context->geo->documents; - if ( _find(doc_path,docs) ) - return; - - size_t idx = doc_path.find('['); - size_t idq = doc_path.find(']'); - string key, fp = doc_path; - if ( idq != string::npos && idx != string::npos ) { - key = doc_path.substr(idx+1,idq-idx-1); - fp = doc_path.substr(0,idx); - } - XML::UriReader* rdr = context->resolver; - DDDBReaderContext* ctx = (DDDBReaderContext*)rdr->context(); - Document* xml_doc = new Document(); - xml_doc->id = doc_path; - xml_doc->name = context->locals.obj_path; - xml_doc->context.doc = xml_doc->id; - xml_doc->context.event_time = ctx->event_time; - xml_doc->context.valid_since = 0; - xml_doc->context.valid_until = 0; - docs.insert(make_pair(doc_path,xml_doc->addRef())); - XML::UriContextReader reader(rdr, &xml_doc->context); - xml_doc_holder_t doc(xml_handler_t().load(fp, &reader)); - xml_h e = doc.root(); - context->print(xml_doc); - if ( e ) { - if ( !key.empty() ) { - stringstream str; - XML::dump_tree(e, str); - string buffer = str.str(); - while( (idx=buffer.find("-KEY-")) != string::npos ) - buffer.replace(idx,5,key); - doc.assign(xml_handler_t().parse(buffer.c_str(), - buffer.length(), - doc_path.c_str(), - &reader)); - e = doc.root(); - } - Context::PreservedLocals locals(context); - context->locals.xml_doc = xml_doc; - Conv<ACTION> converter(context->lcdd, context, catalog); - context->print_condition = prt; - if ( prt || context->print_xml ) XML::dump_tree(e); - converter(e); - } - } - catch(const exception& e) { - printout(INFO,"load_dddb","Failed to load %s [%s]",ref.c_str(),e.what()); - } - catch(...) { - printout(INFO,"load_dddb","Failed to load %s",ref.c_str()); - } + dddb::Documents& docs = context->geo->documents; + if ( _find(doc_path,docs) ) + return; + + size_t idx = doc_path.find('['); + size_t idq = doc_path.find(']'); + string key, fp = doc_path; + if ( idq != string::npos && idx != string::npos ) { + key = doc_path.substr(idx+1,idq-idx-1); + fp = doc_path.substr(0,idx); + } + XML::UriReader* rdr = context->resolver; + DDDBReaderContext* ctx = (DDDBReaderContext*)rdr->context(); + Document* xml_doc = new Document(); + xml_doc->id = doc_path; + xml_doc->name = context->locals.obj_path; + xml_doc->context.doc = xml_doc->id; + xml_doc->context.event_time = ctx->event_time; + xml_doc->context.valid_since = 0; + xml_doc->context.valid_until = 0; + docs.insert(make_pair(doc_path,xml_doc->addRef())); + XML::UriContextReader reader(rdr, &xml_doc->context); + xml_doc_holder_t doc(xml_handler_t().load(fp, &reader)); + xml_h e = doc.root(); + context->print(xml_doc); + if ( e ) { + if ( !key.empty() ) { + stringstream str; + XML::dump_tree(e, str); + string buffer = str.str(); + while( (idx=buffer.find("-KEY-")) != string::npos ) + buffer.replace(idx,5,key); + doc.assign(xml_handler_t().parse(buffer.c_str(), + buffer.length(), + doc_path.c_str(), + &reader)); + e = doc.root(); + } + Context::PreservedLocals locals(context); + context->locals.xml_doc = xml_doc; + Conv<ACTION> converter(context->lcdd, context, catalog); + context->print_condition = prt; + if ( prt || context->print_xml ) XML::dump_tree(e); + converter(e); + } + } + catch(const exception& e) { + printout(INFO,"load_dddb","Failed to load %s [%s]",ref.c_str(),e.what()); + } + catch(...) { + printout(INFO,"load_dddb","Failed to load %s",ref.c_str()); + } } } void config_context(Context& context, - XML::UriReader* rdr, - const std::string& doc_path, - const std::string& obj_path) { + XML::UriReader* rdr, + const std::string& doc_path, + const std::string& obj_path) { DDDBReaderContext* ctx = (DDDBReaderContext*)rdr->context(); Document* doc = new Document(); doc->name = obj_path; @@ -1900,35 +1901,35 @@ namespace DD4hep { long load_dddb_objects(lcdd_t& lcdd, int argc, char** argv) { DDDBHelper* hlp = lcdd.extension<DDDBHelper>(false); if ( hlp ) { - Context ctxt(lcdd); - string sys_id = "conddb://lhcb.xml"; - string obj_path = "/"; - XML::UriReader* rdr = hlp->xmlReader(); - if ( argc == 0 ) { - return 0; - } - if ( argc >= 1 && argv[0] != 0 ) { - rdr = (XML::UriReader*)argv[0]; - } - if ( argc >= 2 && argv[1] != 0 ) { - sys_id = argv[1]; - } - if ( argc >= 3 && argv[2] != 0 ) { - obj_path = argv[2]; - } - if ( argc >= 4 && argv[3] != 0 ) { - long evt_time = *(long*)argv[3]; - DDDBReaderContext* ctx = (DDDBReaderContext*)rdr->context(); - ctx->event_time = evt_time; - } - config_context(ctxt, rdr, sys_id, obj_path); - load_dddb_entity<ACTION>(&ctxt,0,0,ctxt.locals.xml_doc->id); - checkParents( &ctxt ); - fixCatalogs( &ctxt ); - /// Transfer ownership from local context to the helper - hlp->setDetectorDescription( ctxt.geo ); - ctxt.geo = 0; - return 1; + Context ctxt(lcdd); + string sys_id = "conddb://lhcb.xml"; + string obj_path = "/"; + XML::UriReader* rdr = hlp->xmlReader(); + if ( argc == 0 ) { + return 0; + } + if ( argc >= 1 && argv[0] != 0 ) { + rdr = (XML::UriReader*)argv[0]; + } + if ( argc >= 2 && argv[1] != 0 ) { + sys_id = argv[1]; + } + if ( argc >= 3 && argv[2] != 0 ) { + obj_path = argv[2]; + } + if ( argc >= 4 && argv[3] != 0 ) { + long evt_time = *(long*)argv[3]; + DDDBReaderContext* ctx = (DDDBReaderContext*)rdr->context(); + ctx->event_time = evt_time; + } + config_context(ctxt, rdr, sys_id, obj_path); + load_dddb_entity<ACTION>(&ctxt,0,0,ctxt.locals.xml_doc->id); + checkParents( &ctxt ); + fixCatalogs( &ctxt ); + /// Transfer ownership from local context to the helper + hlp->setDetectorDescription( ctxt.geo ); + ctxt.geo = 0; + return 1; } except("DDDB","+++ Failed to access cool. No DDDBHelper object defined. Run plugin DDDBInstallHelper."); return 0; @@ -1946,17 +1947,17 @@ namespace DD4hep { long load_dddb_from_handle(lcdd_t& lcdd, xml_h element) { DDDBHelper* helper = lcdd.extension<DDDBHelper>(false); if ( helper ) { - Context context(lcdd); - config_context(context, helper->xmlReader(), "conddb://lhcb.xml", "/"); - /// Convert the XML information - Conv<dddb> converter(lcdd, &context); - converter( element ); - checkParents( &context ); - fixCatalogs( &context ); - /// Transfer ownership from local context to the helper - helper->setDetectorDescription( context.geo ); - context.geo = 0; - return 1; + Context context(lcdd); + config_context(context, helper->xmlReader(), "conddb://lhcb.xml", "/"); + /// Convert the XML information + Conv<dddb> converter(lcdd, &context); + converter( element ); + checkParents( &context ); + fixCatalogs( &context ); + /// Transfer ownership from local context to the helper + helper->setDetectorDescription( context.geo ); + context.geo = 0; + return 1; } except("DDDB","+++ Failed to access cool. No DDDBHelper object defined. Run plugin DDDBInstallHelper."); return 0; diff --git a/DDDB/src/DDDB2Objects.cpp b/DDDB/src/DDDB2Objects.cpp index 6fd4a52b1a6b02a5ee341eae8ac773855448381c..38a713d0db6af269e0e18421d9773db5a37aa250 100644 --- a/DDDB/src/DDDB2Objects.cpp +++ b/DDDB/src/DDDB2Objects.cpp @@ -59,14 +59,11 @@ namespace DD4hep { typedef Conditions::Interna::ConditionObject GeoCondition; typedef Conditions::ConditionsManager ConditionsManager; typedef Conditions::ConditionsPool ConditionsPool; - typedef Conditions::IOVType IOVType; typedef Conditions::AbstractMap AbstractMap; 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; @@ -75,7 +72,7 @@ namespace DD4hep { typedef set<string> StringSet; - Context(Geometry::LCDD& l, dddb* g) + Context(LCDD& l, dddb* g) : lcdd(l), geo(g), helper(0), epoch(0), max_volume_depth(9999), print_materials(false), @@ -100,7 +97,7 @@ namespace DD4hep { } template <typename T> void collect(const string& id, T* s); template <typename T,typename Q> void collect(const string& id, T* s, Q* c); - Geometry::LCDD& lcdd; + LCDD& lcdd; DDDB::dddb* geo; DDDB::DDDBHelper* helper; typedef std::map<Isotope*, TGeoIsotope*> Isotopes; @@ -186,7 +183,7 @@ namespace DD4hep { template <typename T> struct CNV : Converter<T,T*> { public: /// Initializing constructor of the functor with initialization of the user parameter - CNV(Geometry::LCDD& l, void* p, void* o=0) : Converter<T,T*>(l,p,o) {} + CNV(LCDD& l, void* p, void* o=0) : Converter<T,T*>(l,p,o) {} template<typename Q> CNV<Q> cnv() const { return CNV<Q>(this->lcdd,this->param,this->optional); } void* convert(T* obj) const; template<typename Q> Q get(const string& obj) const { @@ -232,7 +229,7 @@ namespace DD4hep { template <> void* CNV<GeoCondition>::convert(GeoCondition *obj) const { Context* context = _param<Context>(); if ( obj ) { - typedef Conditions::IOV::Key _K; + typedef IOV::Key _K; Conditions::Condition cond = obj; AbstractMap& d = cond.get<AbstractMap>(); Document* doc = d.option<Document>(); @@ -501,7 +498,7 @@ namespace DD4hep { for(i=object->boolean_ops.begin(); i != object->boolean_ops.end(); ++i) { Shape* right_shape = (*i).shape; GeoSolid right_solid = (TGeoShape*)convert(right_shape); - const Geometry::Transform3D& trafo = (*i).trafo; + const Transform3D& trafo = (*i).trafo; if ( !right_solid.isValid() ) { // Error .... except("Cnv<Shape>","++ %s: Unknown right boolean shape creation:%s -> %d", object->c_name(), right_shape->c_name(), right_shape->type); @@ -580,7 +577,7 @@ namespace DD4hep { } } mother->SetTitle(object->path.c_str()); - VisAttr vis = context->helper->visAttr(object->path); + Geometry::VisAttr vis = context->helper->visAttr(object->path); if ( vis.isValid() ) { if ( context->print_vis ) { printout(INFO,"Cnv<LogVol>","++ Vol:%s Vis:%s",mother->GetTitle(), vis.name()); @@ -1021,7 +1018,7 @@ namespace DD4hep { manager["UserPoolType"] = "DD4hep_ConditionsMapUserPool"; manager["UpdatePoolType"] = "DD4hep_ConditionsLinearUpdatePool"; manager.initialize(); - pair<bool,const Conditions::IOVType*> e = manager.registerIOVType(0, "epoch"); + pair<bool,const IOVType*> e = manager.registerIOVType(0, "epoch"); context->manager = manager; context->epoch = e.second; } @@ -1029,7 +1026,7 @@ namespace DD4hep { } if ( !context->manager.isValid() ) { Conditions::ConditionsManager manager = Conditions::ConditionsManager::from(lcdd); - pair<bool,const Conditions::IOVType*> e = manager.registerIOVType(0, "epoch"); + pair<bool,const IOVType*> e = manager.registerIOVType(0, "epoch"); context->manager = manager; context->epoch = e.second; } @@ -1041,7 +1038,7 @@ namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit namespace DDDB { - long dddb_2_dd4hep(Geometry::LCDD& lcdd, int , char** ) { + long dddb_2_dd4hep(LCDD& lcdd, int , char** ) { DDDBHelper* helper = lcdd.extension<DDDBHelper>(false); if ( helper ) { Context context(lcdd, helper->detectorDescription()); @@ -1073,7 +1070,7 @@ namespace DD4hep { except("DDDB","++ No DDDBHelper instance installed. Geometry conversion failed!"); return 1; } - long dddb_conditions_2_dd4hep(Geometry::LCDD& lcdd, int , char** ) { + long dddb_conditions_2_dd4hep(LCDD& lcdd, int , char** ) { DDDBHelper* helper = lcdd.extension<DDDBHelper>(false); if ( helper ) { Context context(lcdd, helper->detectorDescription()); diff --git a/DDDB/src/DDDBAlignmentTest.cpp b/DDDB/src/DDDBAlignmentTest.cpp index 1d5c388d021ce05ae505911d9b8c82ac9563b4a2..5002b764e6e1879fcabc791270eb85c70fad97dc 100644 --- a/DDDB/src/DDDBAlignmentTest.cpp +++ b/DDDB/src/DDDBAlignmentTest.cpp @@ -25,6 +25,7 @@ #include "DD4hep/Factories.h" #include "DD4hep/ConditionsData.h" #include "DD4hep/ConditionDerived.h" +#include "DD4hep/Alignments.h" #include "DDCond/ConditionsAccess.h" #include "DDCond/ConditionsManager.h" @@ -37,9 +38,6 @@ #include "DDDB/DDDBConversion.h" #include "DDDB/DDDBConditionPrinter.h" -//#include "DDCond/AlignmentCondition.h" -#include "AlignmentCondition.h" - using namespace std; using namespace DD4hep; using namespace DD4hep::Conditions; @@ -53,12 +51,12 @@ namespace { class AlignmentTypes { public: - typedef AbstractMap::Params::const_iterator ParamIter; - typedef AlignmentConditionData _AD; - typedef AlignmentDelta _Delta; - typedef AbstractMap _Map; - typedef AbstractMap::Params::value_type::second_type _Param; - typedef DDDB::ConditionPrinter _Printer; + typedef AbstractMap Map; + typedef Map::Params Params; + typedef Params::value_type::second_type Param; + typedef Alignments::AlignmentData Data; + typedef Alignments::Delta Delta; + typedef DDDB::ConditionPrinter _Printer; }; /// Specialized conditions update callback for alignments @@ -71,27 +69,27 @@ namespace { */ class AlignmentUpdate1 : public ConditionUpdateCall, public AlignmentTypes { public: - AlignmentUpdate1() { } + AlignmentUpdate1() { } virtual ~AlignmentUpdate1() { } /// Interface to client Callback in order to update the condition virtual Condition operator()(const ConditionKey& key, const Context& context) { printout(INFO,"AlignmentUpdate1","++ Building dependent condition: %s",key.name.c_str()); - Condition target(key.name,"Alignment"); - _AD& data = target.bind<AlignmentConditionData>(); - Condition cond0 = context.condition(0); - const _Map& src0 = cond0.get<_Map>(); - const _Param& par0 = src0.firstParam().second; - if ( par0.typeInfo() == typeid(_Delta) ) { - const _Delta& delta = src0.first<_Delta>(); - data.delta = delta; - data.flag = _AD::HAVE_NONE; + Condition target(key.name,"Alignment"); + Data& data = target.bind<Data>(); + Condition cond0 = context.condition(0); + const Map& src0 = cond0.get<Map>(); + const Param& par0 = src0.firstParam().second; + if ( par0.typeInfo() == typeid(Delta) ) { + const Delta& delta = src0.first<Delta>(); + data.delta = delta; + data.flag = Data::HAVE_NONE; } else { - printout(INFO,"AlignmentUpdate1","++ Failed to access AlignmentDelta from %s", - cond0->value.c_str()); - _Printer()(cond0); + printout(INFO,"AlignmentUpdate1","++ Failed to access alignment-Delta from %s", + cond0->value.c_str()); + _Printer()(cond0); } - data.condition = target; + //data.condition = target; return target; } }; @@ -105,30 +103,30 @@ namespace { */ class AlignmentUpdate2 : public ConditionUpdateCall, public AlignmentTypes { public: - AlignmentUpdate2() { } + AlignmentUpdate2() { } virtual ~AlignmentUpdate2() { } /// Interface to client Callback in order to update the condition virtual Condition operator()(const ConditionKey& key, const Context& context) { printout(INFO,"AlignmentUpdate2","++ Building dependent condition: %s",key.name.c_str()); Condition target(key.name,"Alignment"); - _AD& data = target.bind<_AD>(); + Data& data = target.bind<Data>(); Condition cond0 = context.condition(0); - const _Map& src0 = cond0.get<_Map>(); - const _Param& par0 = src0.firstParam().second; + const Map& src0 = cond0.get<Map>(); + const Param& par0 = src0.firstParam().second; - if ( par0.typeInfo() == typeid(_Delta) ) { - const _Delta& delta0 = src0.first<_Delta>(); - const _AD& delta1 = context.get<_AD>(1); - data.delta = delta0; - data.delta = delta1.delta; - data.flag = _AD::HAVE_NONE; + if ( par0.typeInfo() == typeid(Delta) ) { + const Delta& delta0 = src0.first<Delta>(); + const Data& delta1 = context.get<Data>(1); + data.delta = delta0; + data.delta = delta1.delta; + data.flag = Data::HAVE_NONE; } else { - printout(INFO,"AlignmentUpdate2","++ Failed to access AlignmentDelta from %s", - cond0->value.c_str()); - _Printer()(cond0); + printout(INFO,"AlignmentUpdate2","++ Failed to access alignment-Delta from %s", + cond0->value.c_str()); + _Printer()(cond0); } - data.condition = target; + //data.condition = target; return target; } }; @@ -142,33 +140,32 @@ namespace { */ class AlignmentUpdate3 : public ConditionUpdateCall, public AlignmentTypes { public: - AlignmentUpdate3() { } + AlignmentUpdate3() { } virtual ~AlignmentUpdate3() { } /// Interface to client Callback in order to update the condition virtual Condition operator()(const ConditionKey& key, const Context& context) { printout(INFO,"AlignmentUpdate3","++ Building dependent condition: %s",key.name.c_str()); - Condition target(key.name,"Alignment"); - _AD& data = target.bind<_AD>(); - - Condition cond0 = context.condition(0); - const _Map& src0 = cond0.get<_Map>(); - const _Param& par0 = src0.firstParam().second; + Condition target(key.name,"Alignment"); + Data& data = target.bind<Data>(); + Condition cond0 = context.condition(0); + const Map& src0 = cond0.get<Map>(); + const Param& par0 = src0.firstParam().second; - if ( par0.typeInfo() == typeid(_Delta) ) { - const _Delta& delta0 = src0.first<_Delta>(); - const _AD& delta1 = context.get<_AD>(1); - const _AD& delta2 = context.get<_AD>(2); - data.delta = delta0; - data.delta = delta1.delta; - data.delta = delta2.delta; - data.flag = _AD::HAVE_NONE; + if ( par0.typeInfo() == typeid(Delta) ) { + const Delta& delta0 = src0.first<Delta>(); + const Data& delta1 = context.get<Data>(1); + const Data& delta2 = context.get<Data>(2); + data.delta = delta0; + data.delta = delta1.delta; + data.delta = delta2.delta; + data.flag = Data::HAVE_NONE; } else { - printout(INFO,"AlignmentUpdate2","++ Failed to access AlignmentDelta from %s", - cond0->value.c_str()); - _Printer()(cond0); + printout(INFO,"AlignmentUpdate2","++ Failed to access alignment-Delta from %s", + cond0->value.c_str()); + _Printer()(cond0); } - data.condition = target; + //data.condition = target; return target; } }; @@ -210,21 +207,21 @@ namespace { RangeConditions findCond(const string& match) { RangeConditions result; if ( !match.empty() ) { - for(RangeConditions::iterator ic=m_allConditions.begin(); ic!=m_allConditions.end(); ++ic) { - Condition cond = (*ic); - size_t idx = cond->value.find(match); - if ( idx == 0 ) { - if (cond->value.length() == match.length() ) { - result.push_back(cond); - } - else if ( cond->value[match.length()] == '/' ) { - size_t idq = cond->value.find('/',match.length()+1); - if ( idq == string::npos ) { - result.push_back(cond); - } - } - } - } + for(RangeConditions::iterator ic=m_allConditions.begin(); ic!=m_allConditions.end(); ++ic) { + Condition cond = (*ic); + size_t idx = cond->value.find(match); + if ( idx == 0 ) { + if (cond->value.length() == match.length() ) { + result.push_back(cond); + } + else if ( cond->value[match.length()] == '/' ) { + size_t idq = cond->value.find('/',match.length()+1); + if ( idq == string::npos ) { + result.push_back(cond); + } + } + } + } } return result; } @@ -239,53 +236,51 @@ namespace { prt.setPrefix(text); try { - ::sprintf(fmt,"%03d %%-%ds Detector: %%s #Dau:%%d VolID:%%p",level+1,2*level+1); - printout(INFO,m_name,fmt,"",de.path().c_str(),int(c.size()),(void*)de.volumeID()); - cat = de.extension<DDDB::Catalog>(); - ::sprintf(fmt,"%03d %%-%ds %%-20s -> %%s",level+1,2*level+3); - if ( !cat->condition.empty() ) { - RangeConditions rc = findCond(cat->condition); - printout(INFO,m_name,fmt,"","Alignment: ", - rc.empty() ? (cat->condition+" !!!UNRESOLVED!!!").c_str() : cat->condition.c_str()); - if ( !rc.empty() ) { - ConditionKey target1(cat->condition+"/derived_1"); - ConditionKey target2(cat->condition+"/derived_2"); - ConditionKey target3(cat->condition+"/derived_3"); - DependencyBuilder build_1(target1, new AlignmentUpdate1()); - DependencyBuilder build_2(target2, new AlignmentUpdate2()); - DependencyBuilder build_3(target3, new AlignmentUpdate3()); + ::sprintf(fmt,"%03d %%-%ds Detector: %%s #Dau:%%d VolID:%%p",level+1,2*level+1); + printout(INFO,m_name,fmt,"",de.path().c_str(),int(c.size()),(void*)de.volumeID()); + cat = de.extension<DDDB::Catalog>(); + ::sprintf(fmt,"%03d %%-%ds %%-20s -> %%s",level+1,2*level+3); + if ( !cat->condition.empty() ) { + RangeConditions rc = findCond(cat->condition); + printout(INFO,m_name,fmt,"","Alignment: ", + rc.empty() ? (cat->condition+" !!!UNRESOLVED!!!").c_str() : cat->condition.c_str()); + if ( !rc.empty() ) { + ConditionKey target1(cat->condition+"/derived_1"); + ConditionKey target2(cat->condition+"/derived_2"); + ConditionKey target3(cat->condition+"/derived_3"); + DependencyBuilder build_1(target1, new AlignmentUpdate1()); + DependencyBuilder build_2(target2, new AlignmentUpdate2()); + DependencyBuilder build_3(target3, new AlignmentUpdate3()); - build_1->detector = de; - build_2->detector = de; - build_3->detector = de; - for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) { - Condition cond = *ic; - const AbstractMap& data = cond.get<AbstractMap>(); - //const Document* doc = data.option<Document>(); - ConditionKey key(cond->value); - if ( cond->value.find("/dd/Conditions/Alignment/Velo/Detector10-01") != string::npos ) { - printout(INFO,m_name,fmt,"","Alignment--2: ", cond->value.c_str()); - } - build_1.add(key); + build_1->detector = de; + build_2->detector = de; + build_3->detector = de; + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) { + Condition cond = *ic; + ConditionKey key(cond->value); + if ( cond->value.find("/dd/Conditions/Alignment/Velo/Detector10-01") != string::npos ) { + printout(INFO,m_name,fmt,"","Alignment--2: ", cond->value.c_str()); + } + build_1.add(key); - build_2.add(key); - build_2.add(target1); + build_2.add(key); + build_2.add(target1); - build_3.add(key); - build_3.add(target1); - build_3.add(target2); - } - addDependency(build_1.release()); - addDependency(build_2.release()); - addDependency(build_3.release()); - } - ++m_counters.numAlignments; - } + build_3.add(key); + build_3.add(target1); + build_3.add(target2); + } + addDependency(build_1.release()); + addDependency(build_2.release()); + addDependency(build_3.release()); + } + ++m_counters.numAlignments; + } } catch(...) { - ::sprintf(fmt,"%03d %%-%ds %%s%%-20s -> %%s",level+1,2*level+3); - printout(INFO,m_name, fmt, "", de.path().c_str(), "NO CATALOG availible!", ""); - ++m_counters.numNoCatalogs; + ::sprintf(fmt,"%03d %%-%ds %%s%%-20s -> %%s",level+1,2*level+3); + printout(INFO,m_name, fmt, "", de.path().c_str(), "NO CATALOG availible!", ""); + ++m_counters.numNoCatalogs; } for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) collectDependencies((*i).second,level+1); @@ -299,8 +294,8 @@ namespace { IOV iov(iovType, IOV::Key(time,time)); long num_expired = m_manager.prepare(iov, user_pool, dependencies); printout(INFO,"Conditions", - "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", - num_expired, iov.str().c_str()); + "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", + num_expired, iov.str().c_str()); user_pool->clear(); return 1; } diff --git a/DDDB/src/DDDBConditionPrinter.cpp b/DDDB/src/DDDBConditionPrinter.cpp index 14c53825417042d1cb0dd8d80544bb9ba8a64dcd..9b3da26c7ded82ec7bdc5a8e660753061caaeac0 100644 --- a/DDDB/src/DDDBConditionPrinter.cpp +++ b/DDDB/src/DDDBConditionPrinter.cpp @@ -45,18 +45,18 @@ void ConditionPrinter::ParamPrinter::operator()(const AbstractMap::Params::value value += "..."; } printout(INFO,"Condition","++ %s\t-> Param: %-16s %-8s -> %s", - m_prefix.c_str(), - obj.first.c_str(), - obj.second.dataType().c_str(), - value.c_str()); + m_prefix.c_str(), + obj.first.c_str(), + obj.second.dataType().c_str(), + value.c_str()); } else if ( type == typeid(AbstractMap) ) { const AbstractMap& d= obj.second.get<AbstractMap>(); printout(INFO,"Condition","++ %s\t-> [%s] CL:%d %-8s -> %s", - m_prefix.c_str(), - obj.first.c_str(), d.classID, - obj.second.dataType().c_str(), - obj.second.str().c_str()); + m_prefix.c_str(), + obj.first.c_str(), d.classID, + obj.second.dataType().c_str(), + obj.second.str().c_str()); } else { string value = obj.second.str(); @@ -66,10 +66,10 @@ void ConditionPrinter::ParamPrinter::operator()(const AbstractMap::Params::value value += "..."; } printout(INFO,"Condition","++ %s\t-> [%s] %-8s -> %s", - m_prefix.c_str(), - obj.first.c_str(), - obj.second.dataType().c_str(), - value.c_str()); + m_prefix.c_str(), + obj.first.c_str(), + obj.second.dataType().c_str(), + value.c_str()); } } @@ -87,17 +87,17 @@ int ConditionPrinter::operator()(Condition cond) { string new_prefix = m_prefix; new_prefix.assign(m_prefix.length(),' '); printout(INFO,"Condition","++ %s Path:%s Class:%d [%s]", - m_prefix.c_str(), - cond.name().c_str(), - data.classID, - cond.block().dataType().c_str()); + m_prefix.c_str(), + cond.name().c_str(), + data.classID, + cond.data().dataType().c_str()); if ( !data.params.empty() ) { if ( m_print ) { - const string& tmp = m_print->prefix(); - m_print->setPrefix(new_prefix); - for_each(data.params.begin(), data.params.end(),*m_print); - m_print->setPrefix(tmp); - return 1; + const string& tmp = m_print->prefix(); + m_print->setPrefix(new_prefix); + for_each(data.params.begin(), data.params.end(),*m_print); + m_print->setPrefix(tmp); + return 1; } for_each(data.params.begin(), data.params.end(),ParamPrinter(new_prefix)); } diff --git a/DDDB/src/DDDBConversion.cpp b/DDDB/src/DDDBConversion.cpp index c524306e3a6ac155ee3642aef2c6dafbbb226e71..92c4af429a5a2e6c787e16539eb14a7582c67963 100644 --- a/DDDB/src/DDDBConversion.cpp +++ b/DDDB/src/DDDBConversion.cpp @@ -40,14 +40,15 @@ namespace DD4hep { using namespace std; + using namespace DDDB; /// Default constructor - DDDB::dddb::dddb() : top(0), structure(0), geometry(0) { + dddb::dddb() : top(0), structure(0), geometry(0) { InstanceCount::increment(this); } /// Default destructor - DDDB::dddb::~dddb() { + dddb::~dddb() { // need to release heare all allocated resources. releaseObjects(isotopes)(); releaseObjects(elements)(); @@ -79,31 +80,31 @@ namespace DD4hep { } /// Default constructor - DDDB::Named::Named() + Named::Named() : name(), id(), document(0), refCount(0) { } /// Initializing constructor - DDDB::Named::Named(const std::string& c) + Named::Named(const std::string& c) : name(c), id(), document(0), refCount(0) { } /// Copy constructor - DDDB::Named::Named(const Named& c) + Named::Named(const Named& c) : name(c.name), id(c.id), document(c.document), refCount(0) { if ( document ) document->addRef(); } /// Default destructor - DDDB::Named::~Named() { + Named::~Named() { if ( document ) document->release(); } /// Assignment operator - DDDB::Named& DDDB::Named::operator=(const Named& c) { + Named& Named::operator=(const Named& c) { if ( this != &c ) { setDocument(c.document); name = c.name; @@ -113,40 +114,40 @@ namespace DD4hep { } /// Assign document - void DDDB::Named::setDocument(Document* doc) { + void Named::setDocument(Document* doc) { if ( doc ) doc->addRef(); if ( document ) document->release(); document = doc; } /// Default constructor - DDDB::Document::Document() : Named(), context() { + Document::Document() : Named(), context() { InstanceCount::increment(this); } /// Default destructor - DDDB::Document::~Document() { + Document::~Document() { //printout(INFO,"Document","Delete doc %s",c_id()); InstanceCount::decrement(this); } /// Default constructor - DDDB::Isotope::Isotope() : Named() { + Isotope::Isotope() : Named() { InstanceCount::increment(this); } /// Default destructor - DDDB::Isotope::~Isotope() { + Isotope::~Isotope() { InstanceCount::decrement(this); } /// Default constructor - DDDB::Element::Element() : Named(), density(0), ionization(0), state(UNKNOWN) { + Element::Element() : Named(), density(0), ionization(0), state(UNKNOWN) { InstanceCount::increment(this); } /// Copy constructor - DDDB::Element::Element(const Element& e) + 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) @@ -155,54 +156,54 @@ namespace DD4hep { } /// Default destructor - DDDB::Element::~Element() { + Element::~Element() { InstanceCount::decrement(this); } /// Default constructor - DDDB::Material::Material() : density(0), pressure(-1), temperature(-1), radlen(0), lambda(0) { + Material::Material() : density(0), pressure(-1), temperature(-1), radlen(0), lambda(0) { InstanceCount::increment(this); } /// Default destructor - DDDB::Material::~Material() { + Material::~Material() { InstanceCount::decrement(this); } /// Default constructor - DDDB::LogVol::LogVol() : Named(), material(), shape(), physvols() { + LogVol::LogVol() : Named(), material(), shape(), physvols() { InstanceCount::increment(this); } /// Default destructor - DDDB::LogVol::~LogVol() { + LogVol::~LogVol() { InstanceCount::decrement(this); } /// Default constructor - DDDB::PhysVol::PhysVol() : type(PHYSVOL_REGULAR), logvol(), path(), trafo() { + PhysVol::PhysVol() : type(PHYSVOL_REGULAR), logvol(), path(), trafo() { InstanceCount::increment(this); } /// Copy constructor - DDDB::PhysVol::PhysVol(const PhysVol& c) + 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() { + PhysVol::~PhysVol() { InstanceCount::decrement(this); } /// Default constructor - DDDB::Shape::Shape() : type(0), zplanes(), boolean_ops() { + Shape::Shape() : type(0), zplanes(), boolean_ops() { ::memset(&s.box,0,sizeof(s)); InstanceCount::increment(this); } /// Default destructor - DDDB::Shape::~Shape() { + Shape::~Shape() { if ( type == BooleanUnion::type() || type == BooleanSubtraction::type() || type == BooleanIntersection::type() ) { @@ -216,27 +217,27 @@ namespace DD4hep { } /// Default constructor - DDDB::Catalog::Catalog() : Named(), level(0), typeID(0) { + Catalog::Catalog() : Named(), level(0), typeID(0) { InstanceCount::increment(this); } /// Default destructor - DDDB::Catalog::~Catalog() { + Catalog::~Catalog() { InstanceCount::decrement(this); } /// Default constructor - DDDB::TabProperty::TabProperty() { + TabProperty::TabProperty() { InstanceCount::increment(this); } /// Default destructor - DDDB::TabProperty::~TabProperty() { + TabProperty::~TabProperty() { InstanceCount::decrement(this); } - pair<const DDDB::Catalog*,string> DDDB::Catalog::parent(const string& nam) const { + pair<const Catalog*,string> Catalog::parent(const string& nam) const { const Catalog* cat = this; string rest = nam.substr(cat->path.length()+1); size_t idx = rest.find('/'); @@ -255,27 +256,27 @@ namespace DD4hep { return make_pair(cat,sub); } - template <> void dddb_print(const DDDB::Position* p) { + template <> void dddb_print(const Position* p) { CHECK_OBJECT(p); printout(INFO,"PosXYZ"," PosXYZ: x=%f y=%f z=%f",p->X(),p->Y(),p->Z()); } - template <> void dddb_print(const DDDB::RotationZYX* p) { + template <> void dddb_print(const RotationZYX* p) { CHECK_OBJECT(p); printout(INFO,"RotXYZ"," RotXYZ: z/phi=%f y/theta=%f x/psi=%f",p->Phi(),p->Theta(),p->Psi()); } - template <> void dddb_print(const DDDB::Transform3D* tr) { + template <> void dddb_print(const Transform3D* tr) { CHECK_OBJECT(tr); - DDDB::Rotation3D rot; - DDDB::Position pos; + Rotation3D rot; + Position pos; tr->GetDecomposition(rot,pos); double dot_pos = pos.mag2(); printout(INFO,"Transformation"," Position:%s",dot_pos>1e-10 ? "YES" : "NO"); if ( dot_pos>1e-10 ) dddb_print(&pos); } - template <> void dddb_print(const DDDB::Isotope* i) { + template <> void dddb_print(const Isotope* i) { CHECK_OBJECT(i); printout(INFO,"Isotope","++ %-20s A=%6.0f Z=%3.0f Density=%8.2g id=%s", i->c_name(), i->A, i->Z, i->density,i->c_id()); @@ -287,7 +288,7 @@ namespace DD4hep { i->GetName(), i->GetN(), i->GetZ(), i->GetA()); } - template <> void dddb_print(const DDDB::Element* e) { + template <> void dddb_print(const Element* e) { CHECK_OBJECT(e); printout(INFO,"Element","++ %-20s A=%6.0f Z=%3.0f Density=%8g ioni:%8.2g (%d isotopes) id=%s", (e->name+"/"+e->symbol).c_str(), e->atom.A, e->atom.Zeff, @@ -300,7 +301,7 @@ namespace DD4hep { e->GetName(), e->N(), e->Z(), e->A()); } - template <> void dddb_print(const DDDB::Material* m) { + template <> void dddb_print(const Material* m) { CHECK_OBJECT(m); printout(INFO,"Material","++ %-20s Density=%8g P=%f T=%f %d components id:%s", ("'"+m->path+"'").c_str(), m->density, m->pressure, m->temperature, @@ -318,37 +319,37 @@ namespace DD4hep { mat->GetNelements()); } - template <> void dddb_print(const DDDB::Shape* s) { + template <> void dddb_print(const Shape* s) { CHECK_OBJECT(s); - if (s-> type == DDDB::Box::type() ) { + if (s-> type == Box::type() ) { printout(INFO,"Box","++ %3d/%-12s: x=%f y=%f z=%f", s->type,s->c_name(), s->s.box.x,s->s.box.y,s->s.box.z); } - else if (s-> type == DDDB::Cons::type() ) { + else if (s-> type == Cons::type() ) { printout(INFO,"Cons","++ %3d/%-12s: z=%f innerMZ=%f innerPZ=%f outerMZ=%f outerPZ=%f", s->type,s->c_name(),s->s.cons.sizeZ, s->s.cons.innerRadiusMZ,s->s.cons.innerRadiusPZ, s->s.cons.outerRadiusMZ,s->s.cons.outerRadiusPZ); } - else if (s-> type == DDDB::Tubs::type() ) { + else if (s-> type == Tubs::type() ) { printout(INFO,"Tubs","++ %3d/%-12s: z=%f innerR=%f outerR=%f", s->type,s->c_name(),s->s.tubs.sizeZ, s->s.tubs.innerRadius,s->s.tubs.outerRadius); } - else if (s-> type == DDDB::Polycone::type() ) { + else if (s-> type == Polycone::type() ) { printout(INFO,"Polycone","++ %3d/%-12s: %d zplanes", s->type,s->c_name(),int(s->zplanes.size())); } - else if (s-> type == DDDB::BooleanUnion::type() ) { + else if (s-> type == BooleanUnion::type() ) { printout(INFO,"union","++ %3d/%-12s: %d modifications", s->type,s->c_name(),int(s->boolean_ops.size())); } - else if (s-> type == DDDB::BooleanSubtraction::type() ) { + else if (s-> type == BooleanSubtraction::type() ) { printout(INFO,"subtraction","++ %3d/%-12s: %d modifications", s->type,s->c_name(),int(s->boolean_ops.size())); } - else if (s-> type == DDDB::BooleanIntersection::type() ) { + else if (s-> type == BooleanIntersection::type() ) { printout(INFO,"intersection","++ %3d%-12s: %d modifications", s->type,s->path.c_str(),int(s->boolean_ops.size())); } @@ -356,7 +357,7 @@ namespace DD4hep { "", s->path.c_str(), s->c_id()); } - template <> void dddb_print(const DDDB::PhysVol* obj) { + template <> void dddb_print(const PhysVol* obj) { CHECK_OBJECT(obj); printout(INFO,"PhysVol","++ %-12s: logvol:%s", obj->path.c_str(),obj->logvol.c_str()); @@ -364,7 +365,7 @@ namespace DD4hep { "",obj->c_name(),obj->c_id()); } - template <> void dddb_print(const DDDB::LogVol* obj) { + template <> void dddb_print(const LogVol* obj) { CHECK_OBJECT(obj); printout(INFO,"LogVol", "++ %-12s: Material:%s Shape:%s", obj->path.c_str(),obj->material.c_str(), @@ -373,7 +374,7 @@ namespace DD4hep { "",obj->c_name(),obj->c_id()); } - template <> void dddb_print(const DDDB::TabProperty* obj) { + template <> void dddb_print(const TabProperty* obj) { CHECK_OBJECT(obj); printout(INFO,"Detector", "++ %-12s: [%s] xunit:%s xaxis:%s yunit:%s yaxis:%s siz:%d", obj->path.c_str(), obj->type.c_str(), @@ -382,7 +383,7 @@ namespace DD4hep { int(obj->data.size())); } - template <> void dddb_print(const DDDB::Catalog* obj) { + template <> void dddb_print(const Catalog* obj) { CHECK_OBJECT(obj); printout(INFO,"Detector", "++ %-12s: [%s] %d children support:%s geo:%s", obj->path.c_str(), obj->type.c_str(), int(obj->catalogrefs.size()), @@ -390,7 +391,7 @@ namespace DD4hep { printout(INFO,"Detector", "++ %-12s name:%s id:%s", "",obj->c_name(),obj->c_id()); } - template <> void dddb_print(const DDDB::Document* obj) { + template <> void dddb_print(const Document* obj) { CHECK_OBJECT(obj); char c_since[64], c_until[64], c_evt[64]; struct tm since, until, evt; diff --git a/DDDB/src/DDDBDerivedCondTest.cpp b/DDDB/src/DDDBDerivedCondTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da66a62d86e9b6cb221ebf815d3e7613d07b1991 --- /dev/null +++ b/DDDB/src/DDDBDerivedCondTest.cpp @@ -0,0 +1,314 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// DDDB is a detector description convention developed by the LHCb experiment. +// For further information concerning the DTD, please see: +// http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf +// +//========================================================================== + +// Framework includes +#include "DD4hep/LCDD.h" +#include "DD4hep/Plugins.h" +#include "DD4hep/Printout.h" +#include "DD4hep/Factories.h" +#include "DD4hep/ConditionsData.h" +#include "DD4hep/ConditionDerived.h" +#include "DD4hep/Alignments.h" + +#include "DDCond/ConditionsAccess.h" +#include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsIOVPool.h" +#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsInterna.h" +#include "DDCond/ConditionsOperators.h" + +#include "DDDB/DDDBConversion.h" +#include "DDDB/DDDBConditionPrinter.h" + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Conditions; + +using DDDB::Document; +using Geometry::LCDD; +using Geometry::DetElement; + +/// Anonymous namespace for plugins +namespace { + + class DataTypes { + public: + typedef AbstractMap Map; + typedef Map::Params Params; + typedef Params::value_type::second_type Param; + typedef Alignments::AlignmentData Data; + typedef Alignments::Delta Delta; + typedef DDDB::ConditionPrinter _Printer; + }; + + /// Specialized conditions update callback for alignments + /** + * Used by clients to update a condition. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionUpdate1 : public ConditionUpdateCall, public DataTypes { + public: + ConditionUpdate1() { } + virtual ~ConditionUpdate1() { } + /// Interface to client Callback in order to update the condition + virtual Condition operator()(const ConditionKey& key, const Context& context) { + printout(INFO,"ConditionUpdate1","++ Building dependent condition: %s",key.name.c_str()); + Condition target(key.name,"Alignment"); + Data& data = target.bind<Data>(); + Condition cond0 = context.condition(0); + const Map& src0 = cond0.get<Map>(); + const Param& par0 = src0.firstParam().second; + if ( par0.typeInfo() == typeid(Delta) ) { + const Delta& delta = src0.first<Delta>(); + data.delta = delta; + data.flag = Data::HAVE_NONE; + } + else { + printout(INFO,"ConditionUpdate1","++ Failed to access Delta from %s", + cond0->value.c_str()); + _Printer()(cond0); + } + //data.condition = target; + return target; + } + }; + /// Specialized conditions update callback for alignments + /** + * Used by clients to update a condition. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionUpdate2 : public ConditionUpdateCall, public DataTypes { + public: + ConditionUpdate2() { } + virtual ~ConditionUpdate2() { } + /// Interface to client Callback in order to update the condition + virtual Condition operator()(const ConditionKey& key, const Context& context) { + printout(INFO,"ConditionUpdate2","++ Building dependent condition: %s",key.name.c_str()); + Condition target(key.name,"Alignment"); + Data& data = target.bind<Data>(); + Condition cond0 = context.condition(0); + const Map& src0 = cond0.get<Map>(); + const Param& par0 = src0.firstParam().second; + + if ( par0.typeInfo() == typeid(Delta) ) { + const Delta& delta0 = src0.first<Delta>(); + const Data& delta1 = context.get<Data>(1); + data.delta = delta0; + data.delta = delta1.delta; + data.flag = Data::HAVE_NONE; + } + else { + printout(INFO,"ConditionUpdate2","++ Failed to access Delta from %s", + cond0->value.c_str()); + _Printer()(cond0); + } + //data.condition = target; + return target; + } + }; + /// Specialized conditions update callback for alignments + /** + * Used by clients to update a condition. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionUpdate3 : public ConditionUpdateCall, public DataTypes { + public: + ConditionUpdate3() { } + virtual ~ConditionUpdate3() { } + /// Interface to client Callback in order to update the condition + virtual Condition operator()(const ConditionKey& key, const Context& context) { + printout(INFO,"ConditionUpdate3","++ Building dependent condition: %s",key.name.c_str()); + Condition target(key.name,"Alignment"); + Data& data = target.bind<Data>(); + Condition cond0 = context.condition(0); + const Map& src0 = cond0.get<Map>(); + const Param& par0 = src0.firstParam().second; + + if ( par0.typeInfo() == typeid(Delta) ) { + const Delta& delta0 = src0.first<Delta>(); + const Data& delta1 = context.get<Data>(1); + const Data& delta2 = context.get<Data>(2); + data.delta = delta0; + data.delta = delta1.delta; + data.delta = delta2.delta; + data.flag = Data::HAVE_NONE; + } + else { + printout(INFO,"ConditionUpdate2","++ Failed to access Delta from %s", + cond0->value.c_str()); + _Printer()(cond0); + } + //data.condition = target; + return target; + } + }; + + /// DDDB Conditions analyser to select alignments. + /** + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + * \ingroup DD4HEP_DDDB + */ + class AlignmentSelector { + public: + typedef ConditionsManager::Dependencies Dependencies; + string m_name; + RangeConditions m_allConditions; + Dependencies m_allDependencies; + ConditionsManager m_manager; + struct Counters { + size_t numAlignments; + size_t numNoCatalogs; + void reset() { numAlignments=numNoCatalogs=0; } + } m_counters; + + /// Initializing constructor + AlignmentSelector(ConditionsAccess mgr) : m_manager(mgr) { + Operators::collectAllConditions(mgr, m_allConditions); + } + + virtual ~AlignmentSelector() { + destroyObjects(m_allDependencies); + } + + void addDependency(ConditionDependency* dependency) { + const ConditionKey& key = dependency->target; + m_allDependencies.insert(make_pair(key.hash,dependency)); + } + + RangeConditions findCond(const string& match) { + RangeConditions result; + if ( !match.empty() ) { + for(RangeConditions::iterator ic=m_allConditions.begin(); ic!=m_allConditions.end(); ++ic) { + Condition cond = (*ic); + size_t idx = cond->value.find(match); + if ( idx == 0 ) { + if (cond->value.length() == match.length() ) { + result.push_back(cond); + } + else if ( cond->value[match.length()] == '/' ) { + size_t idq = cond->value.find('/',match.length()+1); + if ( idq == string::npos ) { + result.push_back(cond); + } + } + } + } + } + return result; + } + long collectDependencies(DetElement de, int level) { + char fmt[64], text[256]; + DDDB::Catalog* cat = 0; + DDDB::ConditionPrinter prt; + const DetElement::Children& c = de.children(); + + ::snprintf(fmt,sizeof(fmt),"%%-%ds-> ",2*level+5); + ::snprintf(text,sizeof(text),fmt,""); + prt.setPrefix(text); + + try { + ::sprintf(fmt,"%03d %%-%ds Detector: %%s #Dau:%%d VolID:%%p",level+1,2*level+1); + printout(INFO,m_name,fmt,"",de.path().c_str(),int(c.size()),(void*)de.volumeID()); + cat = de.extension<DDDB::Catalog>(); + ::sprintf(fmt,"%03d %%-%ds %%-20s -> %%s",level+1,2*level+3); + if ( !cat->condition.empty() ) { + RangeConditions rc = findCond(cat->condition); + printout(INFO,m_name,fmt,"","Alignment: ", + rc.empty() ? (cat->condition+" !!!UNRESOLVED!!!").c_str() : cat->condition.c_str()); + if ( !rc.empty() ) { + ConditionKey target1(cat->condition+"/derived_1"); + ConditionKey target2(cat->condition+"/derived_2"); + ConditionKey target3(cat->condition+"/derived_3"); + DependencyBuilder build_1(target1, new ConditionUpdate1()); + DependencyBuilder build_2(target2, new ConditionUpdate2()); + DependencyBuilder build_3(target3, new ConditionUpdate3()); + + build_1->detector = de; + build_2->detector = de; + build_3->detector = de; + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) { + Condition cond = *ic; + ConditionKey key(cond->value); + build_1.add(key); + + build_2.add(key); + build_2.add(target1); + + build_3.add(key); + build_3.add(target1); + build_3.add(target2); + } + addDependency(build_1.release()); + addDependency(build_2.release()); + addDependency(build_3.release()); + } + ++m_counters.numAlignments; + } + } + catch(...) { + ::sprintf(fmt,"%03d %%-%ds %%s%%-20s -> %%s",level+1,2*level+3); + printout(INFO,m_name, fmt, "", de.path().c_str(), "NO CATALOG availible!", ""); + ++m_counters.numNoCatalogs; + } + for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) + collectDependencies((*i).second,level+1); + return 1; + } + + int computeDependencies(long time) { + dd4hep_ptr<UserPool> user_pool; + const Dependencies& dependencies = m_allDependencies; + const IOVType* iovType = m_manager.iovType("epoch"); + IOV iov(iovType, IOV::Key(time,time)); + long num_expired = m_manager.prepare(iov, user_pool, dependencies); + printout(INFO,"Conditions", + "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", + num_expired, iov.str().c_str()); + user_pool->clear(); + return 1; + } + }; + + /// Plugin function + long dddb_derived_alignments(LCDD& lcdd, int , char** argv) { + long init_time = *(long*)argv[0]; + ConditionsManager manager = ConditionsManager::from(lcdd); + AlignmentSelector selector(manager); + int ret = selector.collectDependencies(lcdd.world(), 0); + if ( ret == 1 ) { + ret = selector.computeDependencies(init_time); + } + return ret; + } +} /* End anonymous namespace */ + +DECLARE_APPLY(DDDB_DerivedCondTest,dddb_derived_alignments) +//========================================================================== diff --git a/DDDB/src/DDDBExecutor.cpp b/DDDB/src/DDDBExecutor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b7f87ca5af35bb203d711ad348929bca2e376eb0 --- /dev/null +++ b/DDDB/src/DDDBExecutor.cpp @@ -0,0 +1,213 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// DDDB is a detector description convention developed by the LHCb experiment. +// For further information concerning the DTD, please see: +// http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf +// +//========================================================================== + +// Framework includes +#include "DDDB/DDDBReader.h" +#include "DDDB/DDDBHelper.h" +#include "DD4hep/Factories.h" +#include "DD4hep/Printout.h" +#include "DD4hep/LCDD.h" + +// C/C++ include files +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <iostream> +#include <cerrno> +#include "boost/filesystem/path.hpp" +#include "TGeoManager.h" +#include "TRint.h" + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::DDDB; + +static void check_result(long result) { + if ( 0 == result ) + except("DDDBExecutor","+++ Odd things going on....."); + //result = *(long*)result; + if ( result != 1 ) + except("DDDBExecutor","+++ Odd things going on.....Processing result=%ld",result); +} + +static void usage_load_xml_dddb() { + cout << + "DDDBExecutor opt [opt]\n" + " Note: No '-' signs infront of identifiers! \n" + " \n" + " -loader <plugin> Plugin instance for XML entity resolution. \n" + " -param <file-name> Preprocessing xml file \n" + " -input <file-name> Directory containing DDDB \n" + " -config <plugin> Execute config plugin initializing the helper. \n" + " -match <string> Match string for entity resolver e.g.'conddb:' \n" + " -xml <file-name> Parse additional XML files using LCDD. \n" + " -setup <plugin> Add setup plugin after dddb parsing. \n" + " -exec <plugin> Add execution plugin after setup. \n" + " -attr <file-name> Optional XML parsing for visualization attrs. \n" + " -dump Call DDDB_DetectorConditionDump plugin. \n" + " -visualize Call display after processing \n" + "" + "" << endl; + + ::exit(EINVAL); +} + +static long load_xml_dddb(Geometry::LCDD& lcdd, int argc, char** argv) { + if ( argc > 0 ) { + string sys_id, params, match="conddb:", attr="", loader_name="DDDB_FileReader"; + std::vector<string> setup, xmlFiles, executors, config; + long result = 0, visualize = 0, dump = 0; + + for(int i=0; i<argc;++i) { + if ( argv[i][0] == '-' ) { + char c = ::toupper(argv[i][1]); + switch(c) { + case 'A': + attr = argv[++i]; + break; + case 'C': + config.push_back(argv[++i]); + break; + case 'D': + dump = 1; + break; + case 'E': + executors.push_back(argv[++i]); + break; + case 'I': + sys_id = argv[++i]; + break; + case 'L': + loader_name = argv[++i]; + break; + case 'M': + match = argv[++i]; + break; + case 'P': + params = argv[++i]; + break; + case 'S': + setup.push_back(argv[++i]); + break; + case 'V': + visualize = 1; + break; + case 'X': + xmlFiles.push_back(argv[++i]); + break; + case 'H': + case '?': + default: + usage_load_xml_dddb(); + } + } + } + + boost::filesystem::path path = sys_id; + sys_id = path.normalize().c_str(); + + /// Install helper + { + lcdd.apply("DDDB_InstallHelper", 0, 0); + } + + DDDBHelper* helper = lcdd.extension<DDDBHelper>(); + if ( !loader_name.empty() ) { + DDDBReader* resolver = (DDDBReader*)DD4hep::PluginService::Create<void*>(loader_name,(const char*)0); + resolver->setMatch(match); + resolver->setDirectory(path.parent_path().c_str()); + helper->setXmlReader(resolver); + } + + /// Execute config plugins without arguments + if ( !config.empty() ) { + for(size_t i=0; i<config.size(); ++i) + lcdd.apply(config[i].c_str(), 0, 0); + } + + /// Pre-Process Parameters + if ( !params.empty() ) { + const void* args[] = {0, params.c_str(), 0}; + printout(INFO,"DDDBExecutor","++ Pre-processing parameters: %s",params.c_str()); + result = lcdd.apply("DDDB_Loader", 2, (char**)args); + check_result(result); + printout(INFO,"DDDBExecutor"," .... done"); + } + + /// Process XML + if ( !sys_id.empty() ) { + long long int init_time = DDDBReader::makeTime(2016,4,1,12); + const void* args[] = {0, sys_id.c_str(), "/", &init_time, 0}; + printout(INFO,"DDDBExecutor","+++ Processing DDDB: %s", sys_id.c_str()); + result = lcdd.apply("DDDB_Loader", 4, (char**)args); + check_result(result); + printout(INFO,"DDDBExecutor"," .... done"); + } + + /// Convert local database to TGeo + { + result = lcdd.apply("DDDB_2DD4hep", 0, 0); + check_result(result); + } + + /// Load XML files as wanted (may also be plugins) + if ( !xmlFiles.empty() ) { + for(size_t i=0; i<xmlFiles.size(); ++i) { + const void* args[] = {xmlFiles[i].c_str(), 0}; + lcdd.apply("DD4hepXMLLoader", 1, (char**)args); + } + } + + /// Execute further setup plugins without arguments + if ( !setup.empty() ) { + for(size_t i=0; i<setup.size(); ++i) + lcdd.apply(setup[i].c_str(), 0, 0); + } + + /// Call executors + if ( !executors.empty() ) { + for(size_t i=0; i<executors.size(); ++i) + lcdd.apply(executors[i].c_str(), 0, 0); + } + + if ( !attr.empty() ) { + const void* args[] = {attr.c_str(), 0}; + printout(INFO,"DDDBExecutor","+++ Processing attrs: %s", attr.c_str()); + result = lcdd.apply("DD4hepXMLLoader", 1, (char**)args); + check_result(result); + } + if ( dump ) { + printout(INFO,"DDDBExecutor","------------------> Conditions dump:"); + lcdd.apply("DDDB_DetectorConditionDump", 0, 0); + } + if ( visualize ) { /// Fire off display + pair<int, char**> a(0,0); + TRint app("DDDB", &a.first, a.second); + TGeoManager& mgr = lcdd.manager(); + mgr.SetVisLevel(999); + mgr.SetVisOption(1); + lcdd.worldVolume()->Draw("ogl"); + app.Run(); + } + } + return 1; +} +DECLARE_APPLY(DDDB_Executor,load_xml_dddb) diff --git a/DDDB/src/DDDBFileReader.cpp b/DDDB/src/DDDBFileReader.cpp index 87969a7bdce6b546bf213806c995c9aec9da51de..847a348e572dbc752da92ee5e7936a34495047ea 100644 --- a/DDDB/src/DDDBFileReader.cpp +++ b/DDDB/src/DDDBFileReader.cpp @@ -19,33 +19,52 @@ //========================================================================== // Framework includes -#include "DDDB/DDDBFileReader.h" +#include "DDDB/DDDBReader.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace of the DDDB conversion stuff + namespace DDDB { + + /// Class supporting the interface of the LHCb conditions database to DD4hep + /** + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_XML + */ + class DDDBFileReader : public DDDBReader { + public: + /// Standard constructor + DDDBFileReader() : DDDBReader() {} + /// Default destructor + virtual ~DDDBFileReader() {} + /// Read raw XML object from the database / file + virtual int getObject(const std::string& system_id, UserContext* ctxt, std::string& data); + + }; + } /* End namespace DDDB */ +} /* End namespace DD4hep */ + + +//========================================================================== +// Framework includes #include "DD4hep/Factories.h" #include "DD4hep/Printout.h" #include "DD4hep/LCDD.h" -#include "XML/DocumentHandler.h" -#include "XML/XMLElements.h" // C/C++ include files #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> -#include <iostream> -#include <cerrno> -#include "boost/filesystem/path.hpp" -#include "TGeoManager.h" -#include "TRint.h" - -using namespace std; -using namespace DD4hep; -using namespace DD4hep::DDDB; -int DDDBFileReader::getObject(const string& system_id, - UserContext* /* ctxt */, - string& buffer) +int DD4hep::DDDB::DDDBFileReader::getObject(const std::string& system_id, + UserContext* /* ctxt */, + std::string& buffer) { - string path = m_directory+system_id; + std::string path = m_directory+system_id; struct stat buff; if ( 0 == ::stat(path.c_str(), &buff) ) { int fid = ::open(path.c_str(), O_RDONLY); @@ -66,142 +85,9 @@ int DDDBFileReader::getObject(const string& system_id, return 0; } -/// Resolve a given URI to a string containing the data -bool DDDBFileReader::load(const string& system_id, - UserContext* ctxt, - string& buffer) -{ - if ( system_id.substr(0,m_match.length()) == m_match ) { - string mm = m_match + "//"; - const string& sys = system_id; - string id = sys.c_str() + (sys.substr(0,mm.length()) == mm ? 9 : 7); - // Extract the COOL field name from the condition path - // "conddb:/path/to/field@folder" - string::size_type at_pos = id.find('@'); - if ( at_pos != id.npos ) { - string::size_type slash_pos = id.rfind('/',at_pos); - // always remove '@' from the path - id = id.substr(0,slash_pos+1) + id.substr(at_pos+1); - } - // GET: 1458055061070516000 /lhcb.xml 0 0 SUCCESS - int ret = getObject(id, ctxt, buffer); - if ( ret == 1 ) return true; - printout(ERROR,"DDDBFileReader","++ Failed to resolve system id: %s [%s]", - id.c_str(), ::strerror(errno)); - } - return false; -} - -static void check_result(long result) { - if ( 0 == result ) - except("DDDBFileLoader","+++ Odd things going on....."); - //result = *(long*)result; - if ( result != 1 ) - except("DDDBFileLoader","+++ Odd things going on.....Processing result=%ld",result); -} - -static void usage_load_xml_dddb() { - cout << - "DDDBFileLoader opt [opt]\n" - " Note: No '-' signs infront of identifiers! \n" - " \n" - " param <file-name> Preprocessing xml file \n" - " input <file-name> Directory containing DDDB \n" - " visualize Call display after processing \n" - " match=<string> Match string for entity resolver \n" - "" << endl; - - ::exit(EINVAL); -} - -static long load_xml_dddb(Geometry::LCDD& lcdd, int argc, char** argv) { - if ( argc > 0 ) { - string sys_id, params, match="conddb:", attr=""; - //DD4hep::LCDDBuildType type = BUILD_DEFAULT; - long result = 0, visualize = 0, dump = 0; - DDDBFileReader resolver; - - for(int i=0; i<argc;++i) { - char c = ::toupper(argv[i][0]); - switch(c) { - case 'A': - attr = argv[++i]; - break; - case 'D': - dump = 1; - break; - case 'P': - params = argv[++i]; - break; - case 'I': - sys_id = argv[++i]; - break; - case 'M': - match = argv[++i]; - break; - case 'V': - visualize = 1; - break; - case 'H': - case '?': - default: - usage_load_xml_dddb(); - } - } - boost::filesystem::path path = sys_id; - sys_id = path.normalize().c_str(); - resolver.setMatch(match); - resolver.setDirectory(path.parent_path().c_str()); - { /// Install helper - char* arguments[] = {(char*)&resolver, 0}; - lcdd.apply("DDDB_InstallHelper", 1, arguments); - } - if ( !params.empty() ) { /// Pre-Process Parameters - XML::DocumentHolder doc(XML::DocumentHandler().load(params, &resolver)); - XML::Handle_t handle = doc.root(); - char* arguments[] = {(char*)handle.ptr(), 0}; - printout(INFO,"DDDBFileLoader","+++ Pre-processing parameters...."); - result = lcdd.apply("DD4hepXMLProcessor", 1, arguments); - check_result(result); - printout(INFO,"DDDBFileLoader"," .... done"); - } - if ( !sys_id.empty() ) { /// Process XML - XML::DocumentHolder doc(XML::DocumentHandler().load(sys_id, &resolver)); - XML::Handle_t handle = doc.root(); - char* arguments[] = {(char*)handle.ptr(), 0}; - printout(INFO,"DDDBFileLoader","+++ Processing DDDB: %s", sys_id.c_str()); - result = lcdd.apply("DD4hepXMLProcessor", 1, arguments); - check_result(result); - printout(INFO,"DDDBFileLoader"," .... done"); - } - if ( !attr.empty() ) { - XML::DocumentHolder doc(XML::DocumentHandler().load(attr, &resolver)); - XML::Handle_t handle = doc.root(); - char* arguments[] = {(char*)handle.ptr(), 0}; - printout(INFO,"DDDBFileLoader","+++ Processing attrs: %s", attr.c_str()); - result = lcdd.apply("DD4hepXMLProcessor", 1, arguments); - check_result(result); - } - { /// Convert local database to TGeo - result = lcdd.apply("DDDB2DD4hep", 0, 0); - check_result(result); - } - if ( dump ) { - printout(INFO,"DDDBFileLoader","------------------> Volume tree dump:"); - lcdd.apply("DD4hepVolumeDump", 0, 0); - printout(INFO,"DDDBFileLoader","------------------> DetElement tree dump:"); - lcdd.apply("DD4hepDetectorDump", 0, 0); - } - if ( visualize ) { /// Fire off display - pair<int, char**> a(0,0); - TRint app("DDDB", &a.first, a.second); - TGeoManager& mgr = lcdd.manager(); - mgr.SetVisLevel(999); - mgr.SetVisOption(1); - lcdd.worldVolume()->Draw("ogl"); - app.Run(); - } +namespace { + void* create_dddb_xml_file_reader(const char* /* arg */) { + return new DD4hep::DDDB::DDDBFileReader(); } - return 1; } -DECLARE_APPLY(DDDBFileLoader,load_xml_dddb) +DECLARE_CONSTRUCTOR(DDDB_FileReader,create_dddb_xml_file_reader) diff --git a/DDDB/src/DDDBPlugins.cpp b/DDDB/src/DDDBPlugins.cpp index 742b8c9ec9b4f84c48cdce5c7d08a7c66dc41b8a..43f108f0d002f730a273a641fa6df12a4d764eb2 100644 --- a/DDDB/src/DDDBPlugins.cpp +++ b/DDDB/src/DDDBPlugins.cpp @@ -33,11 +33,11 @@ using namespace std; using namespace DD4hep; - -using Geometry::LCDD; +using DD4hep::Geometry::LCDD; /// Anonymous namespace for plugins namespace { + /// Plugin function long dddb_dump_conditions(LCDD& lcdd, int , char** ) { DDDB::ConditionPrinter prt; @@ -78,26 +78,26 @@ namespace { /// Recursive callback long operator()(DetElement de) { - const DetElement::Children& c = de.children(); - Conditions::DetConditions dc(de); - Conditions::Container::Object* conditions = dc.conditions().ptr(); - try { - Catalog* cat = de.extension<Catalog>(); - if ( !cat->condition.empty() ) { - conditions->addKey(cat->condition); - conditions->addKey("Alignment", cat->condition); - } - for(StringMap::const_iterator i=cat->conditioninfo.begin(); i!=cat->conditioninfo.end(); ++i) { - const string& cond_name = (*i).second; - conditions->addKey(cond_name); - conditions->addKey((*i).first, cond_name); - } - } - catch(...) { - } - for (DetElement::Children::const_iterator i=c.begin(); i != c.end(); ++i) - (*this)((*i).second); - return 1; + const DetElement::Children& c = de.children(); + Conditions::DetConditions dc(de); + Conditions::Container::Object* conditions = dc.conditions().ptr(); + try { + Catalog* cat = de.extension<Catalog>(); + if ( !cat->condition.empty() ) { + conditions->addKey(cat->condition); + conditions->addKey("Alignment", cat->condition); + } + for(StringMap::const_iterator i=cat->conditioninfo.begin(); i!=cat->conditioninfo.end(); ++i) { + const string& cond_name = (*i).second; + conditions->addKey(cond_name); + conditions->addKey((*i).first, cond_name); + } + } + catch(...) { + } + for (DetElement::Children::const_iterator i=c.begin(); i != c.end(); ++i) + (*this)((*i).second); + return 1; } }; return Actor()(lcdd.world()); @@ -121,8 +121,6 @@ namespace { using Conditions::RangeConditions; using Conditions::AbstractMap; using Conditions::Condition; - using Conditions::IOV; - using Geometry::DetElement; using DDDB::ConditionPrinter; @@ -159,203 +157,203 @@ namespace { /// Standard destructor ~Actor() { - if ( flag > 1 ) { - printout(INFO,m_name,"++ Number of DetElements without catalog: %8ld",m_counters.numNoCatalogs); - printout(INFO,m_name,"++ Number of attached alignments: %8ld",m_counters.numAlignments); - if ( flag > 2 ) { - printout(INFO,m_name,"++ Number of attached conditions: %8ld",m_counters.numConditions); - printout(INFO,m_name,"++ Total number of conditions: %8ld",m_counters.totConditions); - } - } + if ( flag > 1 ) { + printout(INFO,m_name,"++ Number of DetElements without catalog: %8ld",m_counters.numNoCatalogs); + printout(INFO,m_name,"++ Number of attached alignments: %8ld",m_counters.numAlignments); + if ( flag > 2 ) { + printout(INFO,m_name,"++ Number of attached conditions: %8ld",m_counters.numConditions); + printout(INFO,m_name,"++ Total number of conditions: %8ld",m_counters.totConditions); + } + } #if 0 - printout(INFO,m_name,"**************** DDDB Detector dump: Conditions Usage ***************************"); - for(_RC::const_iterator ic=m_allConditions.begin(); ic!=m_allConditions.end(); ++ic) { - Condition cond = (*ic).second; - const AbstractMap& data = cond.get<AbstractMap>(); - const DDDB::Document* doc = data.option<DDDB::Document>(); - if ( doc ) - printout(INFO,m_name,"++ Usage: %d Cond: %s/%s -> %s [%08X]", - (*ic).first, doc->name.c_str(), cond->name.c_str(), cond->value.c_str(), cond->hash); - else - printout(INFO,m_name,"++ Usage: %d Cond: ---/%s -> %s [%08X]", - (*ic).first, cond->name.c_str(), cond->value.c_str(), cond->hash); - } + printout(INFO,m_name,"**************** DDDB Detector dump: Conditions Usage ***************************"); + for(_RC::const_iterator ic=m_allConditions.begin(); ic!=m_allConditions.end(); ++ic) { + Condition cond = (*ic).second; + const AbstractMap& data = cond.get<AbstractMap>(); + const DDDB::Document* doc = data.option<DDDB::Document>(); + if ( doc ) + printout(INFO,m_name,"++ Usage: %d Cond: %s/%s -> %s [%08X]", + (*ic).first, doc->name.c_str(), cond->name.c_str(), cond->value.c_str(), cond->hash); + else + printout(INFO,m_name,"++ Usage: %d Cond: ---/%s -> %s [%08X]", + (*ic).first, cond->name.c_str(), cond->value.c_str(), cond->hash); + } #endif - printout(INFO,m_name,"*********************************************************************************"); + printout(INFO,m_name,"*********************************************************************************"); } /// Initialization Actor& init() { - m_counters.reset(); - m_allConditions.clear(); + m_counters.reset(); + m_allConditions.clear(); - if ( flag >= 3 ) { - RangeConditions rc; - Conditions::Operators::collectAllConditions(m_lcdd, rc); - m_iov.reset().invert(); - m_iov.iovType = 0; - for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) { - Condition cond = *ic; - m_allConditions.push_back(make_pair(0,cond)); - if ( !m_iov.iovType ) m_iov = cond.iov(); - else m_iov.iov_intersection(cond.iov()); - } - m_iov.set(m_iov.keyData.first); - if ( m_dumpConditions ) { - DDDB::ConditionPrinter prt; - printout(INFO,m_name,"**************** DDDB Detector dump: ALL Conditions *****************************"); - for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) - prt(*ic); - printout(INFO,m_name,"*********************************************************************************"); - } - } - return *this; + if ( flag >= 3 ) { + RangeConditions rc; + Conditions::Operators::collectAllConditions(m_lcdd, rc); + m_iov.reset().invert(); + m_iov.iovType = 0; + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) { + Condition cond = *ic; + m_allConditions.push_back(make_pair(0,cond)); + if ( !m_iov.iovType ) m_iov = cond.iov(); + else m_iov.iov_intersection(cond.iov()); + } + m_iov.set(m_iov.keyData.first); + if ( m_dumpConditions ) { + DDDB::ConditionPrinter prt; + printout(INFO,m_name,"**************** DDDB Detector dump: ALL Conditions *****************************"); + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) + prt(*ic); + printout(INFO,m_name,"*********************************************************************************"); + } + } + return *this; } /// __________________________________________________________________________________ RangeConditions findCond(const string& match) { - RangeConditions result; - if ( !match.empty() ) { - for(_RC::iterator ic=m_allConditions.begin(); ic!=m_allConditions.end(); ++ic) { - Condition cond = (*ic).second; - size_t idx = cond->value.find(match); - if ( idx == 0 ) { - if (cond->value.length() == match.length() ) { - (*ic).first++; - result.push_back(cond); - } - else if ( cond->value[match.length()] == '/' ) { - size_t idq = cond->value.find('/',match.length()+1); - if ( idq == string::npos ) { - (*ic).first++; - result.push_back(cond); - } - } - } - } - } - return result; + RangeConditions result; + if ( !match.empty() ) { + for(_RC::iterator ic=m_allConditions.begin(); ic!=m_allConditions.end(); ++ic) { + Condition cond = (*ic).second; + size_t idx = cond->value.find(match); + if ( idx == 0 ) { + if (cond->value.length() == match.length() ) { + (*ic).first++; + result.push_back(cond); + } + else if ( cond->value[match.length()] == '/' ) { + size_t idq = cond->value.find('/',match.length()+1); + if ( idq == string::npos ) { + (*ic).first++; + result.push_back(cond); + } + } + } + } + } + return result; } /// __________________________________________________________________________________ void printDetElement(int level, DetElement de, ConditionPrinter& prt, bool with_placement=false, bool with_keys=false, bool with_values=false) { - typedef Conditions::Container::Object::Keys _K; - char fmt[128]; - const DetElement::Children& c = de.children(); - ::sprintf(fmt,"%03d %%-%ds Detector: %%s #Dau:%%d VolID:%%p Place:%%p",level+1,2*level+1); - printout(INFO, m_name, fmt, "", de.path().c_str(), int(c.size()), - (void*)de.volumeID(), (void*)de.placement().ptr()); - if ( with_placement ) { - ::sprintf(fmt,"%03d %%-%ds Placement: %%s",level+1,2*level+3); - printout(INFO,m_name,fmt,"",de.placementPath().c_str()); - } - if ( (with_keys || with_values) && de.hasConditions() ) { - Conditions::DetConditions dc(de); - Conditions::Container cont = dc.conditions(); - const _K& keys = cont->keys; - ::sprintf(fmt,"%03d %%-%ds Key: %%08X -> %%08X -> %%s",level+1,2*level+3); - for(_K::const_iterator i=keys.begin(); i!=keys.end(); ++i) { - if ( with_keys ) { - printout(INFO,m_name,fmt,"",(*i).first,(*i).second.first, (*i).second.second.c_str()); - } - if ( with_values ) { - Condition::key_type key = (*i).second.first; - Condition cond = dc.get(key, m_iov); - prt(cond); - } - } - } + typedef Conditions::Container::Object::Keys _K; + char fmt[128]; + const DetElement::Children& c = de.children(); + ::sprintf(fmt,"%03d %%-%ds Detector: %%s #Dau:%%d VolID:%%p Place:%%p",level+1,2*level+1); + printout(INFO, m_name, fmt, "", de.path().c_str(), int(c.size()), + (void*)de.volumeID(), (void*)de.placement().ptr()); + if ( with_placement ) { + ::sprintf(fmt,"%03d %%-%ds Placement: %%s",level+1,2*level+3); + printout(INFO,m_name,fmt,"",de.placementPath().c_str()); + } + if ( (with_keys || with_values) && de.hasConditions() ) { + Conditions::DetConditions dc(de); + Conditions::Container cont = dc.conditions(); + const _K& keys = cont->keys; + ::sprintf(fmt,"%03d %%-%ds Key: %%08X -> %%08X -> %%s",level+1,2*level+3); + for(_K::const_iterator i=keys.begin(); i!=keys.end(); ++i) { + if ( with_keys ) { + printout(INFO,m_name,fmt,"",(*i).first,(*i).second.first, (*i).second.second.c_str()); + } + if ( with_values ) { + Condition::key_type key = (*i).second.first; + Condition cond = dc.get(key, m_iov); + prt(cond); + } + } + } } /// __________________________________________________________________________________ void printConditionInfo(int level, Catalog* cat, ConditionPrinter& prt, bool with_elements=false) { - if ( cat && !cat->conditioninfo.empty() ) { - char fmt[128]; - ::sprintf(fmt,"%03d %%-%ds Cond:%%-20s -> %%s",level+1,2*level+3); - for(DDDB::Named::StringMap::const_iterator i=cat->conditioninfo.begin(); i!=cat->conditioninfo.end(); ++i) { - const string& cond_name = (*i).second; - ++m_counters.numConditions; - if ( with_elements ) { - RangeConditions rc = findCond(cond_name); - printout(INFO,m_name,fmt,"",(*i).first.c_str(), - rc.empty() ? (cond_name+" !!!UNRESOLVED!!!").c_str() : cond_name.c_str()); - for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) - prt(*ic); - continue; - } - printout(INFO,m_name,fmt,"",(*i).first.c_str(),cond_name.c_str()); - } - } + if ( cat && !cat->conditioninfo.empty() ) { + char fmt[128]; + ::sprintf(fmt,"%03d %%-%ds Cond:%%-20s -> %%s",level+1,2*level+3); + for(DDDB::Named::StringMap::const_iterator i=cat->conditioninfo.begin(); i!=cat->conditioninfo.end(); ++i) { + const string& cond_name = (*i).second; + ++m_counters.numConditions; + if ( with_elements ) { + RangeConditions rc = findCond(cond_name); + printout(INFO,m_name,fmt,"",(*i).first.c_str(), + rc.empty() ? (cond_name+" !!!UNRESOLVED!!!").c_str() : cond_name.c_str()); + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) + prt(*ic); + continue; + } + printout(INFO,m_name,fmt,"",(*i).first.c_str(),cond_name.c_str()); + } + } } /// __________________________________________________________________________________ void printAlignment(int level, Catalog* cat, ConditionPrinter& prt, bool with_values=false) { - if ( cat && !cat->condition.empty() ) { - char fmt[128]; - ::sprintf(fmt,"%03d %%-%ds %%-20s -> %%s",level+1,2*level+3); - ++m_counters.numAlignments; - if ( with_values ) { - RangeConditions rc = findCond(cat->condition); - printout(INFO,m_name,fmt,"","Alignment:", - rc.empty() ? (cat->condition+" !!!UNRESOLVED!!!").c_str() : cat->condition.c_str()); - for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) - prt(*ic); - return; - } - printout(INFO,m_name,fmt,"","Alignment:",cat->condition.c_str()); - } + if ( cat && !cat->condition.empty() ) { + char fmt[128]; + ::sprintf(fmt,"%03d %%-%ds %%-20s -> %%s",level+1,2*level+3); + ++m_counters.numAlignments; + if ( with_values ) { + RangeConditions rc = findCond(cat->condition); + printout(INFO,m_name,fmt,"","Alignment:", + rc.empty() ? (cat->condition+" !!!UNRESOLVED!!!").c_str() : cat->condition.c_str()); + for(RangeConditions::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) + prt(*ic); + return; + } + printout(INFO,m_name,fmt,"","Alignment:",cat->condition.c_str()); + } } /// __________________________________________________________________________________ long dump(DetElement de, int level) { - char fmt[64], text[512]; - Catalog* cat = 0; - ConditionPrinter prt; - const DetElement::Children& c = de.children(); - ::snprintf(fmt,sizeof(fmt),"%%-%ds-> ",2*level+5); - ::snprintf(text,sizeof(text),fmt,""); - prt.setPrefix(text); - try { - if ( !m_sensitivesOnly || 0 != de.volumeID() ) { - switch(flag) { - case 0: - printDetElement(level, de, prt, false, false); - break; - case 1: - printDetElement(level, de, prt, false, false); - cat = de.extension<Catalog>(); - printAlignment(level, cat, prt, false); - printConditionInfo(level, cat, prt, false); - break; - case 2: - printDetElement(level, de, prt, true, true); - cat = de.extension<Catalog>(); - printAlignment(level, cat, prt, false); - printConditionInfo(level, cat, prt, false); - break; - case 3: - printDetElement(level, de, prt, false, false); - cat = de.extension<Catalog>(); - printAlignment(level, cat, prt, true); - break; - case 4: - printDetElement(level, de, prt, true, true); - cat = de.extension<Catalog>(); - printAlignment(level, cat, prt, true); - printConditionInfo(level, cat, prt, true); - break; - case 5: - printDetElement(level, de, prt, true, true, true); - break; - default: - break; - } - } - } - catch(...) { - ::sprintf(fmt,"%03d %%-%ds %%s%%-20s -> %%s",level+1,2*level+3); - printout(INFO,m_name, fmt, "", de.path().c_str(), "NO CATALOG availible!", ""); - ++m_counters.numNoCatalogs; - } - for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) - dump((*i).second,level+1); - return 1; + char fmt[64], text[512]; + Catalog* cat = 0; + ConditionPrinter prt; + const DetElement::Children& c = de.children(); + ::snprintf(fmt,sizeof(fmt),"%%-%ds-> ",2*level+5); + ::snprintf(text,sizeof(text),fmt,""); + prt.setPrefix(text); + try { + if ( !m_sensitivesOnly || 0 != de.volumeID() ) { + switch(flag) { + case 0: + printDetElement(level, de, prt, false, false); + break; + case 1: + printDetElement(level, de, prt, false, false); + cat = de.extension<Catalog>(); + printAlignment(level, cat, prt, false); + printConditionInfo(level, cat, prt, false); + break; + case 2: + printDetElement(level, de, prt, true, true); + cat = de.extension<Catalog>(); + printAlignment(level, cat, prt, false); + printConditionInfo(level, cat, prt, false); + break; + case 3: + printDetElement(level, de, prt, false, false); + cat = de.extension<Catalog>(); + printAlignment(level, cat, prt, true); + break; + case 4: + printDetElement(level, de, prt, true, true); + cat = de.extension<Catalog>(); + printAlignment(level, cat, prt, true); + printConditionInfo(level, cat, prt, true); + break; + case 5: + printDetElement(level, de, prt, true, true, true); + break; + default: + break; + } + } + } + catch(...) { + ::sprintf(fmt,"%03d %%-%ds %%s%%-20s -> %%s",level+1,2*level+3); + printout(INFO,m_name, fmt, "", de.path().c_str(), "NO CATALOG availible!", ""); + ++m_counters.numNoCatalogs; + } + for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) + dump((*i).second,level+1); + return 1; } }; @@ -364,11 +362,11 @@ namespace { if ( ::strcmp(argv[i],"--sensitive")==0 ) { dump_sensitive_only = true; } if ( ::strcmp(argv[i],"--dump")==0 ) { dump_all_cond = true; } if ( ::strcmp(argv[i],"--help")==0 ) { - printout(INFO,"Plugin-Help","Usage: DDDBDetectorDump --opt [--opt]"); - printout(INFO,"Plugin-Help"," --sensitive Only use sensitive elements"); - printout(INFO,"Plugin-Help"," --dump Print conditions inventory"); - printout(INFO,"Plugin-Help"," --help Print this help message"); - return 0; + printout(INFO,"Plugin-Help","Usage: DDDBDetectorDump --opt [--opt]"); + printout(INFO,"Plugin-Help"," --sensitive Only use sensitive elements"); + printout(INFO,"Plugin-Help"," --dump Print conditions inventory"); + printout(INFO,"Plugin-Help"," --help Print this help message"); + return 0; } } Actor actor(lcdd, dump_sensitive_only, dump_all_cond); diff --git a/DDDB/src/DDDBReader.cpp b/DDDB/src/DDDBReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..251b38b078270ab4116d62fea0ac8f0b14525f57 --- /dev/null +++ b/DDDB/src/DDDBReader.cpp @@ -0,0 +1,97 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// DDDB is a detector description convention developed by the LHCb experiment. +// For further information concerning the DTD, please see: +// http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf +// +//========================================================================== + +// Framework includes +#include "DDDB/DDDBReader.h" +#include "DD4hep/Printout.h" +//#include "DD4hep/LCDD.h" +//#include "XML/DocumentHandler.h" +//#include "XML/XMLElements.h" + +// C/C++ include files +#include <ctime> +#include <cstring> + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::DDDB; + +/// Standard constructor +DDDBReader::DDDBReader(const std::string& dir) + : m_directory(dir), m_match("conddb:") +{ + m_context.valid_since = makeTime(1970,1,1); + m_context.valid_until = makeTime(2030,1,1); + m_context.event_time = makeTime(2015,7,1,12,0,0); +} + + +long long int DDDBReader::makeTime(int year, int month, int day, + int hour, int minutes, int seconds) +{ + struct tm tm_init; + ::memset(&tm_init,0,sizeof(tm_init)); + tm_init.tm_year = year; + tm_init.tm_mon = month; + tm_init.tm_mday = day; + tm_init.tm_hour = hour; + tm_init.tm_min = minutes; + tm_init.tm_sec = seconds; + return ::mktime(&tm_init); +} + +/// Resolve a given URI to a string containing the data +bool DDDBReader::load(const string& system_id, string& buffer) { + return XML::UriReader::load(system_id, buffer); +} + +/// Resolve a given URI to a string containing the data +bool DDDBReader::load(const string& system_id, + UserContext* ctxt, + string& buffer) +{ + if ( system_id.substr(0,m_match.length()) == m_match ) { + string mm = m_match + "//"; + const string& sys = system_id; + string id = sys.c_str() + (sys.substr(0,mm.length()) == mm ? 9 : 7); + // Extract the COOL field name from the condition path + // "conddb:/path/to/field@folder" + string::size_type at_pos = id.find('@'); + if ( at_pos != id.npos ) { + string::size_type slash_pos = id.rfind('/',at_pos); + // always remove '@' from the path + id = id.substr(0,slash_pos+1) + id.substr(at_pos+1); + } + // GET: 1458055061070516000 /lhcb.xml 0 0 SUCCESS + int ret = getObject(id, ctxt, buffer); + if ( ret == 1 ) return true; + printout(ERROR,"DDDBReader","++ Failed to resolve system id: %s [%s]", + id.c_str(), ::strerror(errno)); + } + return false; +} + +int DDDBReader::getObject(const string& sys_id, UserContext* /* ctxt */, string& /* out */) +{ + except("DDDBReader","DDDBReader::getObject is a virtual method, " + "which must be overloaded by the concrete instance!! sys_id:%s", sys_id.c_str()); + return 0; +} + diff --git a/DDDetectors/src/LayeringExtensionPlugin.cpp b/DDDetectors/src/LayeringExtensionPlugin.cpp index deb50e63411b38f157212e9cc00440f9be3e206a..f151903ec3b7b3af7610c891b97a3a84dabadf58 100644 --- a/DDDetectors/src/LayeringExtensionPlugin.cpp +++ b/DDDetectors/src/LayeringExtensionPlugin.cpp @@ -32,7 +32,7 @@ namespace { det.addExtension<LayeringExtension>(e); for(std::map<int,DetElement>::const_iterator i=layers.begin(); i!=layers.end();++i) { DetElement de = (*i).second; - e->setLayer(de.id(), de, Position(0,0,1)); + e->setLayer(de.id(), de, DD4hep::Position(0,0,1)); std::cout << " Add layer:" << de.name() << " ID: " << de.id() << " Parent:" << de.parent().name() << std::endl; diff --git a/DDEve/src/HitActors.cpp b/DDEve/src/HitActors.cpp index 8dcbe6f73ca48139cfd883f692805de4604d4c9b..36ac980d834d7e62fa104e3bec88a5d7ebc82d7a 100644 --- a/DDEve/src/HitActors.cpp +++ b/DDEve/src/HitActors.cpp @@ -29,7 +29,7 @@ using namespace DD4hep; /// Action callback of this functor: void EtaPhiHistogramActor::operator()(const DDEveHit& hit) { - const Geometry::Position pos(hit.x/MM_2_CM,hit.y/MM_2_CM,hit.z/MM_2_CM); + const Position pos(hit.x/MM_2_CM,hit.y/MM_2_CM,hit.z/MM_2_CM); histogram->Fill(pos.Eta(),pos.Phi(),hit.deposit); } diff --git a/DDG4/include/DDG4/DDG4Dict.h b/DDG4/include/DDG4/DDG4Dict.h index c7fa2f8ce05a3597c8986c5570c70b854e12e70a..0acbe9301ae39a4a5fc5c7a6aa3e23f64078f04a 100644 --- a/DDG4/include/DDG4/DDG4Dict.h +++ b/DDG4/include/DDG4/DDG4Dict.h @@ -46,13 +46,18 @@ using namespace std; #pragma link C++ class DD4hep::Simulation::SimpleEvent+; #pragma link C++ class DD4hep::Simulation::DataExtension+; -#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::DataExtension>+; -#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::DataExtension>::base_t+; - /// Dictionaires for Geant4 particles #pragma link C++ class DD4hep::Simulation::ParticleExtension+; -#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::ParticleExtension>+; -#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::ParticleExtension>::base_t+; + +/// Auto-pointers related. ROOT cannot handle I/O! +#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::DataExtension>; +#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::ParticleExtension>; + +#ifdef DD4HEP_DD4HEP_PTR_AUTO +#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::DataExtension>::base_t; +#pragma link C++ class DD4hep::dd4hep_ptr<DD4hep::Simulation::ParticleExtension>::base_t; +#endif + #pragma link C++ class DD4hep::Simulation::Geant4Particle+; #pragma link C++ class vector<DD4hep::Simulation::Geant4Particle*>+; #pragma link C++ class map<int,DD4hep::Simulation::Geant4Particle*>+; diff --git a/DDG4/include/DDG4/Defs.h b/DDG4/include/DDG4/Defs.h index cb845ce52a29e0db73b630c8b003271270287172..40cc5884883110902222b2145874c62180cf5bbf 100644 --- a/DDG4/include/DDG4/Defs.h +++ b/DDG4/include/DDG4/Defs.h @@ -24,13 +24,14 @@ namespace DD4hep { /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit namespace Simulation { + using DD4hep::Position; + using Geometry::LCDD; + using Geometry::Readout; + using Geometry::DetElement; + // Forward declarations; - typedef Geometry::Position Position; - typedef Geometry::Position Direction; - typedef Geometry::Position Momentum; - typedef Geometry::LCDD LCDD; - typedef Geometry::Readout Readout; - typedef Geometry::DetElement DetElement; + typedef Position Direction; + typedef Position Momentum; class Geant4StepHandler; class Geant4Hit; diff --git a/DDG4/include/DDG4/Geant4Data.h b/DDG4/include/DDG4/Geant4Data.h index 8162cb9f2a69b785b22e18fe41db3596e64e93f9..be296a5790caa245750e5f715dd8f0a0acda50a3 100644 --- a/DDG4/include/DDG4/Geant4Data.h +++ b/DDG4/include/DDG4/Geant4Data.h @@ -125,7 +125,11 @@ namespace DD4hep { /// Original Geant 4 track identifier of the creating track (debugging) long g4ID; /// User data extension if required +#ifdef DD4HEP_DD4HEP_PTR_AUTO dd4hep_ptr<DataExtension> extension; +#else + dd4hep_ptr<DataExtension> extension; //! not persisten. ROOT cannot handle +#endif /// Utility class describing the monte carlo contribution of a given particle to a hit. /** diff --git a/DDG4/include/DDG4/Geant4Particle.h b/DDG4/include/DDG4/Geant4Particle.h index ac258a35bd7bc723cfc90ac51b9dc2945cb71bdb..f3a4dbdd87a544a6fe7eca9f5040910abf252001 100644 --- a/DDG4/include/DDG4/Geant4Particle.h +++ b/DDG4/include/DDG4/Geant4Particle.h @@ -122,9 +122,12 @@ namespace DD4hep { Particles daughters; /// User data extension if required +#ifdef DD4HEP_DD4HEP_PTR_AUTO dd4hep_ptr<ParticleExtension> extension; - const G4VProcess *process; //! not persistent - //const G4ParticleDefinition *definition; //! not persistent +#else + dd4hep_ptr<ParticleExtension> extension; //! not persisten. ROOT cannot handle +#endif + const G4VProcess *process; //! not persistent /// Default constructor Geant4Particle(); /// Constructor with ID initialization diff --git a/DDG4/include/DDG4/Geant4Vertex.h b/DDG4/include/DDG4/Geant4Vertex.h index 2d3a772d876db34b1a378eaffdde9a953a5365fa..e3077f49fd0984d95ae0839b8f79d5c7e71ce96e 100644 --- a/DDG4/include/DDG4/Geant4Vertex.h +++ b/DDG4/include/DDG4/Geant4Vertex.h @@ -57,8 +57,11 @@ namespace DD4hep { /// The list of incoming particles Particles in; /// User data extension if required +#ifdef DD4HEP_DD4HEP_PTR_AUTO dd4hep_ptr<VertexExtension> extension; - +#else + dd4hep_ptr<VertexExtension> extension; //! not persistent: ROOT cannot handle yet +#endif /// Default constructor Geant4Vertex(); /// Copy constructor diff --git a/DDG4/plugins/Geant4MaterialScanner.cpp b/DDG4/plugins/Geant4MaterialScanner.cpp index dd7a03d6cd81a40ec9e4a6e74f11cb13c7113461..0fb5725c22fda0233272e027b2ba9ddfb5368893 100644 --- a/DDG4/plugins/Geant4MaterialScanner.cpp +++ b/DDG4/plugins/Geant4MaterialScanner.cpp @@ -34,7 +34,6 @@ namespace DD4hep { */ class Geant4MaterialScanner : public Geant4SteppingAction { protected: - typedef Geometry::Position Position; /// Structure to hold the information of one simulation step. class StepInfo { public: diff --git a/DDG4/python/DD4hep.py b/DDG4/python/DD4hep.py index e9cf76a5aec13c94b4fa6b228b291cf488e8200f..d4dabf2daa598da15116e95b725dcaf0a3b15e6a 100644 --- a/DDG4/python/DD4hep.py +++ b/DDG4/python/DD4hep.py @@ -88,6 +88,7 @@ Core = DD4hep Geo = DD4hep.Geometry Geometry = DD4hep.Geometry Conditions = DD4hep.Conditions +Alignments = DD4hep.Alignments import_root('XmlTools') import_namespace_item('XmlTools','Evaluator') @@ -121,7 +122,8 @@ def import_geometry(): #// Readout.h import_namespace_item('Geo','Readout') - import_namespace_item('Geo','Alignment') + import_namespace_item('Alignments','Alignment') + import_namespace_item('Alignments','Container') import_namespace_item('Conditions','Condition') import_namespace_item('Conditions','Container') diff --git a/DDG4/python/DDG4Dict.C b/DDG4/python/DDG4Dict.C index d55afefae0f3d6064d48214971dc708d1f153f95..e72c310ff1e8bf8d67475fcf83179af9fa99b212 100644 --- a/DDG4/python/DDG4Dict.C +++ b/DDG4/python/DDG4Dict.C @@ -239,7 +239,9 @@ namespace { #pragma link C++ class dd4hep_ptr<VertexExtension>+; #pragma link C++ class dd4hep_ptr<PrimaryExtension>+; #pragma link C++ class dd4hep_ptr<Geant4InputAction::Particles>; +#ifdef DD4HEP_DD4HEP_PTR_AUTO #pragma link C++ class dd4hep_ptr<Geant4InputAction::Particles>::base_t; +#endif // Basic stuff #pragma link C++ class Geant4ActionCreation; diff --git a/DDRec/include/DDRec/API/Exceptions.h b/DDRec/include/DDRec/API/Exceptions.h index 8710524abec4c0095da7dad943bdbe270fe2d9a7..ffedadb3d66b6429ccedd9bcbc1904ba0cab36a3 100644 --- a/DDRec/include/DDRec/API/Exceptions.h +++ b/DDRec/include/DDRec/API/Exceptions.h @@ -39,11 +39,11 @@ private: class invalid_position: public std::invalid_argument { public: - invalid_position(const std::string& msg, const Geometry::Position& position) : + invalid_position(const std::string& msg, const Position& position) : std::invalid_argument(createMsg(msg, position)) { } private: - static std::string createMsg(const std::string& msg, const Geometry::Position& position) { + static std::string createMsg(const std::string& msg, const Position& position) { std::stringstream s; s << "Invalid position: " << msg << " " << position; return s.str(); diff --git a/DDRec/include/DDRec/API/IDDecoder.h b/DDRec/include/DDRec/API/IDDecoder.h index 32184247276e37d10a8bea9f6f4e9363d4e41b05..41f8c1d0fe2fec7fb51f54dfcc21c3cf5c88bfde 100644 --- a/DDRec/include/DDRec/API/IDDecoder.h +++ b/DDRec/include/DDRec/API/IDDecoder.h @@ -75,46 +75,46 @@ public: virtual ~IDDecoder() {}; /// Returns the cell ID from the local position in the given volume ID. - CellID cellIDFromLocal(const Geometry::Position& local, const VolumeID volumeID) const; + CellID cellIDFromLocal(const Position& local, const VolumeID volumeID) const; /// Returns the global cell ID from a given global position - CellID cellID(const Geometry::Position& global) const; + CellID cellID(const Position& global) const; /// Returns the global position from a given cell ID - Geometry::Position position(const CellID& cellID) const; + Position position(const CellID& cellID) const; /// Returns the local position from a given cell ID - Geometry::Position localPosition(const CellID& cellID) const; + Position localPosition(const CellID& cellID) const; /// Returns the volume ID of a given cell ID VolumeID volumeID(const CellID& cellID) const; /// Returns the volume ID of a given global position - VolumeID volumeID(const Geometry::Position& global) const; + VolumeID volumeID(const Position& global) const; /// Returns the placement for a given cell ID Geometry::PlacedVolume placement(const CellID& cellID) const; /// Returns the placement for a given global position - Geometry::PlacedVolume placement(const Geometry::Position& global) const; + Geometry::PlacedVolume placement(const Position& global) const; /// Returns the subdetector for a given cell ID Geometry::DetElement subDetector(const CellID& cellID) const; /// Returns the subdetector for a given global position - Geometry::DetElement subDetector(const Geometry::Position& global) const; + Geometry::DetElement subDetector(const Position& global) const; /// Returns the closest detector element in the hierarchy for a given cell ID Geometry::DetElement detectorElement(const CellID& cellID) const; /// Returns the closest detector element in the hierarchy for a given global position - Geometry::DetElement detectorElement(const Geometry::Position& global) const; + Geometry::DetElement detectorElement(const Position& global) const; /// Access to the Readout object for a given cell ID Geometry::Readout readout(const CellID& cellID) const; /// Access to the Readout object for a given global position - Geometry::Readout readout(const Geometry::Position& global) const; + Geometry::Readout readout(const Position& global) const; /// Calculates the neighbours of the given cell ID and adds them to the list of neighbours void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const; @@ -151,7 +151,7 @@ protected: Geometry::Readout findReadout(const Geometry::DetElement& det) const; /// Helper method to get the closest daughter DetElement to the position starting from the given DetElement - static Geometry::DetElement getClosestDaughter(const Geometry::DetElement& det, const Geometry::Position& position); + static Geometry::DetElement getClosestDaughter(const Geometry::DetElement& det, const Position& position); private: /// Default constructor diff --git a/DDRec/include/DDRec/Extensions/LayeringExtensionImpl.h b/DDRec/include/DDRec/Extensions/LayeringExtensionImpl.h index 7d3e3ab4a71f27c5f0d9348dc9040c44e8f5126d..795ec60ba4aa3b17bdbad7fe037b8716c4418849 100644 --- a/DDRec/include/DDRec/Extensions/LayeringExtensionImpl.h +++ b/DDRec/include/DDRec/Extensions/LayeringExtensionImpl.h @@ -88,14 +88,14 @@ public: virtual double sensorInteractionLength(int layerIndex) const; /// Stores the layer information for the given layer index - void setLayer(int layerIndex, Geometry::DetElement layer, const Geometry::Position& normal); + void setLayer(int layerIndex, Geometry::DetElement layer, const Position& normal); protected: /// Helper class to store layer attributes struct LayerAttributes { LayerAttributes(); Geometry::DetElement layer; - Geometry::Position normal; + Position normal; std::vector<Geometry::DetElement> sensors; std::vector<Geometry::DetElement> absorbers; double thickness; diff --git a/DDRec/src/IDDecoder.cpp b/DDRec/src/IDDecoder.cpp index 9ef4d808f68403bd4ebe5055e6767c848ef182fd..5bb217f8dd707988c5265b0aa3d7b322e273de8e 100644 --- a/DDRec/src/IDDecoder.cpp +++ b/DDRec/src/IDDecoder.cpp @@ -17,7 +17,6 @@ namespace DDRec { using Geometry::DetElement; using Geometry::LCDD; using Geometry::PlacedVolume; -using Geometry::Position; using Geometry::Readout; using Geometry::Solid; using Geometry::VolumeManager; @@ -167,7 +166,7 @@ Geometry::Readout IDDecoder::readout(const CellID& cell) const { } /// Access to the Readout object for a given global position -Geometry::Readout IDDecoder::readout(const Geometry::Position& global) const { +Geometry::Readout IDDecoder::readout(const Position& global) const { DetElement det = this->detectorElement(global); return this->findReadout(det); } diff --git a/DDRec/src/LayeringExtensionImpl.cpp b/DDRec/src/LayeringExtensionImpl.cpp index 3ba1268d4fb784ffc85c66f6342e668a0c11805c..e2cef63fb502a7085b7687c80388a218a573038e 100644 --- a/DDRec/src/LayeringExtensionImpl.cpp +++ b/DDRec/src/LayeringExtensionImpl.cpp @@ -159,7 +159,7 @@ double LayeringExtensionImpl::sensorInteractionLength(int layerIndex) const { } /// Stores the layer information for the given layer index -void LayeringExtensionImpl::setLayer(int layerIndex, Geometry::DetElement layer_elt, const Geometry::Position& normal) { +void LayeringExtensionImpl::setLayer(int layerIndex, Geometry::DetElement layer_elt, const Position& normal) { LayerAttributes& layerAttributes = _layerMap[layerIndex]; layerAttributes.layer = layer_elt; layerAttributes.normal = normal.Unit(); diff --git a/DDRec/src/SubdetectorExtensionImpl.cpp b/DDRec/src/SubdetectorExtensionImpl.cpp index 5175c141b139737b4d8cc69c82bdc13aa806ca71..c5e9f183e32519c696f0f9d88b6730e19c0d8d30 100644 --- a/DDRec/src/SubdetectorExtensionImpl.cpp +++ b/DDRec/src/SubdetectorExtensionImpl.cpp @@ -129,8 +129,8 @@ double SubdetectorExtensionImpl::getZMin() const { Geometry::Solid solid = det.volume().solid(); Geometry::Box box(solid); if (box.isValid()) { - Geometry::Position local(0.,0.,-box->GetDZ()/2.); - Geometry::Position global; + Position local(0.,0.,-box->GetDZ()/2.); + Position global; det.localToWorld(local, global); return global.z(); } @@ -147,8 +147,8 @@ double SubdetectorExtensionImpl::getZMax() const { Geometry::Solid solid = det.volume().solid(); Geometry::Box box(solid); if (box.isValid()) { - Geometry::Position local(0.,0.,box->GetDZ()/2.); - Geometry::Position global; + Position local(0.,0.,box->GetDZ()/2.); + Position global; det.localToWorld(local, global); return global.z(); } diff --git a/UtilityApps/src/run_plugin.h b/UtilityApps/src/run_plugin.h index 23a5a5ebbebbd72d2fb03b691fc6b09dbf071e58..c7582adab60bc0bb7e0c627a84846ce7bfb9d2c0 100644 --- a/UtilityApps/src/run_plugin.h +++ b/UtilityApps/src/run_plugin.h @@ -157,7 +157,8 @@ namespace { plugins.push_back(std::vector<const char*>()); plugins.back().push_back(argv[++i]); for( ++i; i < argc; ++i ) { - if ( argv[i][0]=='-' ) { --i; break; } + if ( strncmp(argv[i],"-plugin",5)==0 ) { --i; break; } + if ( strncmp(argv[i],"-end-plugin",4)==0 ) { break; } plugins.back().push_back(argv[i]); } plugins.back().push_back(0); diff --git a/cmake/DD4hepBuild.cmake b/cmake/DD4hepBuild.cmake index 128a164e504690f7c59f016401538d3c1da26c16..504dd7eac403e3a38ac6ca698ac13f97d15ce8c0 100644 --- a/cmake/DD4hepBuild.cmake +++ b/cmake/DD4hepBuild.cmake @@ -465,7 +465,11 @@ endfunction() # #--------------------------------------------------------------------------------------------------- function ( dd4hep_install_files ) - cmake_parse_arguments ( ARG "" "DESTINATION" "FILES" ${ARGN} ) + cmake_parse_arguments ( ARG "" "DESTINATION" "FILES" "PROGRAMS" ${ARGN} ) + foreach ( f ${ARG_PROGRAMS} ) + file ( GLOB sources ${f} ) + install (PROGRAMS ${sources} DESTINATION ${ARG_DESTINATION} ) + endforeach() foreach ( f ${ARG_UNPARSED_ARGUMENTS} ${ARG_FILES} ) file ( GLOB sources ${f} ) install (FILES ${sources} DESTINATION ${ARG_DESTINATION} )