From fbed2604984b8a12160223c7b2766dfa5c5f58ed Mon Sep 17 00:00:00 2001 From: Markus Frank <Markus.Frank@cern.ch> Date: Wed, 15 Mar 2017 15:20:30 +0100 Subject: [PATCH] Group common XML parsers (XMLParsers.h,XMLParsers.cpp). --- .../include/DDAlign/GlobalAlignmentCache.h | 2 +- .../include/DDAlign/GlobalAlignmentStack.h | 24 ++++++++++++-- DDAlign/src/GlobalAlignmentCache.cpp | 2 +- DDAlign/src/GlobalAlignmentOperators.cpp | 32 ++++++++++--------- DDAlign/src/GlobalAlignmentStack.cpp | 3 +- .../plugins/ConditionsRepositoryParser.cpp | 3 +- DDCore/src/XML/XMLParsers.cpp | 6 ++-- 7 files changed, 47 insertions(+), 25 deletions(-) diff --git a/DDAlign/include/DDAlign/GlobalAlignmentCache.h b/DDAlign/include/DDAlign/GlobalAlignmentCache.h index 104c27c17..344c9b9af 100644 --- a/DDAlign/include/DDAlign/GlobalAlignmentCache.h +++ b/DDAlign/include/DDAlign/GlobalAlignmentCache.h @@ -94,7 +94,7 @@ namespace DD4hep { void commit(GlobalAlignmentStack& stack); /// Retrieve the cache section corresponding to the path of an entry. GlobalAlignmentCache* section(const std::string& path_name) const; - /// Retrieve an alignment entry by its lacement path + /// Retrieve an alignment entry by its placement path GlobalAlignment get(const std::string& path) const; /// Return all entries matching a given path. Careful: Expensive operaton! std::vector<GlobalAlignment> matches(const std::string& path_match, bool exclude_exact=false) const; diff --git a/DDAlign/include/DDAlign/GlobalAlignmentStack.h b/DDAlign/include/DDAlign/GlobalAlignmentStack.h index 6f8393e24..85bb9ffc1 100644 --- a/DDAlign/include/DDAlign/GlobalAlignmentStack.h +++ b/DDAlign/include/DDAlign/GlobalAlignmentStack.h @@ -15,7 +15,8 @@ // Framework include files #include "DD4hep/Alignments.h" -#include "DD4hep/Objects.h" +#include "DD4hep/AlignmentData.h" +//#include "DD4hep/Objects.h" #include "DD4hep/Memory.h" @@ -42,7 +43,7 @@ namespace DD4hep { RESET_CHILDREN = 1<<25, ____LLLAST = 1<<31 }; - + //#if 0 /// Stack entry definition /** * \author M.Frank @@ -70,7 +71,7 @@ namespace DD4hep { /// Assignment operator StackEntry& operator=(const StackEntry& e) = default; - +#if 0 /// Check if the overlap flag checking is enabled bool overlapDefined() const { return delta.checkFlag(OVERLAP_DEFINED); } /// Check if the overlap flag checking is enabled @@ -92,7 +93,10 @@ namespace DD4hep { StackEntry& setOverlapCheck(bool new_value=true); /// Set the precision for the overlap check (otherwise the default is 0.001 cm) StackEntry& setOverlapPrecision(double precision=0.001); +#endif }; + //#endif + //typedef AlignmentData StackEntry; typedef std::map<std::string, StackEntry*> Stack; protected: @@ -112,6 +116,20 @@ namespace DD4hep { static void create(); /// Check existence of alignment stack static bool exists(); + + /// Check if the overlap flag checking is enabled + static bool overlapDefined(const StackEntry& e) { return e.delta.checkFlag(OVERLAP_DEFINED); } + /// Check if the overlap flag checking is enabled + static bool checkOverlap(const StackEntry& e) { return e.delta.checkFlag(CHECKOVL_DEFINED); } + /// Check if the overalp value is present + static bool overlapValue(const StackEntry& e) { return e.delta.checkFlag(CHECKOVL_VALUE); } + /// Check if this alignment entry has a non unitary transformation matrix + static bool hasMatrix(const StackEntry& e) { return e.delta.checkFlag(MATRIX_DEFINED); } + /// Check flag if the node location should be reset + static bool needsReset(const StackEntry& e) { return e.delta.checkFlag(RESET_VALUE); } + /// Check flag if the node location and all children should be reset + static bool resetChildren(const StackEntry& e) { return e.delta.checkFlag(RESET_CHILDREN); } + /// Add a new entry to the cache. The key is the placement path bool insert(const std::string& full_path, dd4hep_ptr<StackEntry>& new_entry); /// Add a new entry to the cache. The key is the placement path. The placement path must be set in the entry diff --git a/DDAlign/src/GlobalAlignmentCache.cpp b/DDAlign/src/GlobalAlignmentCache.cpp index 1997d6160..7a3850610 100644 --- a/DDAlign/src/GlobalAlignmentCache.cpp +++ b/DDAlign/src/GlobalAlignmentCache.cpp @@ -194,7 +194,7 @@ void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) { Entry* e = stack.pop().release(); DetElement det = _detector(e->detector); all[det].push_back(e); - if ( e->hasMatrix() || e->needsReset() || e->resetChildren() ) { + if ( stack.hasMatrix(*e) || stack.needsReset(*e) || stack.resetChildren(*e) ) { detelt_updates.insert(make_pair(e->detector.path(),e->detector)); } } diff --git a/DDAlign/src/GlobalAlignmentOperators.cpp b/DDAlign/src/GlobalAlignmentOperators.cpp index cff58cd10..0f472e7b1 100644 --- a/DDAlign/src/GlobalAlignmentOperators.cpp +++ b/DDAlign/src/GlobalAlignmentOperators.cpp @@ -40,9 +40,9 @@ void GlobalAlignmentSelector::operator()(const Cache::value_type& entry) const TGeoPhysicalNode* pn = entry.second; for(Entries::const_iterator j=entries.begin(); j != entries.end(); ++j) { Entries::value_type e = (*j); - if ( e->needsReset() || e->hasMatrix() ) { + if ( GlobalAlignmentStack::needsReset(*e) || GlobalAlignmentStack::hasMatrix(*e) ) { const char* p = pn->GetName(); - bool reset_children = e->resetChildren(); + bool reset_children = GlobalAlignmentStack::resetChildren(*e); if ( reset_children && ::strstr(p,e->path.c_str()) == p ) { nodes.insert(make_pair(p,make_pair(pn,e))); break; @@ -61,9 +61,11 @@ template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_print>:: template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_print>::operator()(Nodes::value_type& n) const { TGeoPhysicalNode* p = n.second.first; - Entry* e = n.second.second; + const Entry& e = *n.second.second; printout(ALWAYS,"GlobalAlignmentCache","Need to reset entry:%s - %s [needsReset:%s, hasMatrix:%s]", - p->GetName(),e->path.c_str(),yes_no(e->needsReset()),yes_no(e->hasMatrix())); + p->GetName(), e.path.c_str(), + yes_no(GlobalAlignmentStack::needsReset(e)), + yes_no(GlobalAlignmentStack::hasMatrix(e))); } template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_delete>::operator()(Nodes::value_type& n) const { @@ -108,26 +110,26 @@ template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_reset>:: template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_align>::operator()(Nodes::value_type& n) const { Entry& e = *n.second.second; - bool overlap = e.overlapDefined(); + bool overlap = GlobalAlignmentStack::overlapDefined(e); DetElement det = e.detector; - if ( !det->global_alignment.isValid() && !e.hasMatrix() ) { + if ( !det->global_alignment.isValid() && !GlobalAlignmentStack::hasMatrix(e) ) { printout(WARNING,"GlobalAlignmentActor","++++ SKIP Alignment %s DE:%s Valid:%s Matrix:%s", e.path.c_str(),det.placementPath().c_str(), - yes_no(det->global_alignment.isValid()), yes_no(e.hasMatrix())); + yes_no(det->global_alignment.isValid()), yes_no(GlobalAlignmentStack::hasMatrix(e))); return; } if ( GlobalDetectorAlignment::debug() ) { printout(INFO,"GlobalAlignmentActor","++++ %s DE:%s Matrix:%s", - e.path.c_str(),det.placementPath().c_str(),yes_no(e.hasMatrix())); + e.path.c_str(),det.placementPath().c_str(),yes_no(GlobalAlignmentStack::hasMatrix(e))); } // Need to care about optional arguments 'check_overlaps' and 'overlap' GlobalDetectorAlignment ad(det); GlobalAlignment align; Transform3D trafo; - bool no_vol = e.path == det.placementPath(); - double ovl_val = e.overlapValue(); - const Delta& delta = e.delta; + const Delta& delta = e.delta; + bool no_vol = e.path == det.placementPath(); + double ovl_precision = e.overlap; if ( delta.checkFlag(Delta::HAVE_ROTATION|Delta::HAVE_PIVOT|Delta::HAVE_TRANSLATION) ) trafo = Transform3D(Translation3D(delta.translation)*delta.pivot*delta.rotation*(delta.pivot.Inverse())); @@ -140,10 +142,10 @@ template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_align>:: else if ( delta.checkFlag(Delta::HAVE_TRANSLATION) ) trafo = Transform3D(delta.translation); - if ( e.checkOverlap() && overlap ) - align = no_vol ? ad.align(trafo,ovl_val,e.overlap) : ad.align(e.path,trafo,ovl_val,e.overlap); - else if ( e.checkOverlap() ) - align = no_vol ? ad.align(trafo,ovl_val) : ad.align(e.path,trafo,ovl_val); + if ( GlobalAlignmentStack::checkOverlap(e) && overlap ) + align = no_vol ? ad.align(trafo,ovl_precision,e.overlap) : ad.align(e.path,trafo,ovl_precision,e.overlap); + else if ( GlobalAlignmentStack::checkOverlap(e) ) + align = no_vol ? ad.align(trafo,ovl_precision) : ad.align(e.path,trafo,ovl_precision); else align = no_vol ? ad.align(trafo) : ad.align(e.path,trafo); diff --git a/DDAlign/src/GlobalAlignmentStack.cpp b/DDAlign/src/GlobalAlignmentStack.cpp index 62139da25..a04936b36 100644 --- a/DDAlign/src/GlobalAlignmentStack.cpp +++ b/DDAlign/src/GlobalAlignmentStack.cpp @@ -31,7 +31,7 @@ static dd4hep_ptr<GlobalAlignmentStack>& _stack(GlobalAlignmentStack* obj) { s.adopt(obj); return s; } - +#if 0 /// Constructor with partial initialization GlobalAlignmentStack::StackEntry::StackEntry(DetElement element, const std::string& p, const Delta& del, double ov) : detector(element), delta(del), path(p), overlap(ov) @@ -79,6 +79,7 @@ GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setOverlapPr overlap = precision; return *this; } +#endif /// Default constructor GlobalAlignmentStack::GlobalAlignmentStack() diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp index 436a2354f..2086fbd98 100644 --- a/DDCond/src/plugins/ConditionsRepositoryParser.cpp +++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp @@ -343,7 +343,8 @@ namespace DD4hep { xml_h child_rot, child_pos, child_piv; ConversionArg* arg = _param<ConversionArg>(); Condition con = create_condition(arg->detector, e); - XML::parse_delta(e, con->data); + Alignments::Delta& del = con.bind<Alignments::Delta>(); + XML::parse(e, del); con->setFlag(Condition::ALIGNMENT); arg->manager.registerUnlocked(arg->pool, con); } diff --git a/DDCore/src/XML/XMLParsers.cpp b/DDCore/src/XML/XMLParsers.cpp index a65f7d3e4..1513f53dc 100644 --- a/DDCore/src/XML/XMLParsers.cpp +++ b/DDCore/src/XML/XMLParsers.cpp @@ -47,7 +47,7 @@ bool DD4hep::XML::setXMLParserDebug(bool value) { void DD4hep::XML::parse(xml_h e, Geometry::RotationZYX& rot) { xml_dim_t r(e); rot.SetComponents(r.z(), r.y(), r.x()); - printout(s_print,"Alignment<rot>", + printout(s_print,"<rotation>", " Rotation: x=%9.3f y=%9.3f z=%9.3f phi=%7.4f psi=%7.4f theta=%7.4f", r.x(), r.y(), r.z(), rot.Phi(), rot.Psi(), rot.Theta()); } @@ -56,7 +56,7 @@ void DD4hep::XML::parse(xml_h e, Geometry::RotationZYX& rot) { void DD4hep::XML::parse(xml_h e, Geometry::Position& pos) { xml_dim_t p(e); pos.SetXYZ(p.x(), p.y(), p.z()); - printout(s_print,"Alignment<pos>"," Position: x=%9.3f y=%9.3f z=%9.3f", + printout(s_print,"<position>"," Position: x=%9.3f y=%9.3f z=%9.3f", pos.X(), pos.Y(), pos.Z()); } @@ -65,7 +65,7 @@ void DD4hep::XML::parse(xml_h e, Geometry::Translation3D& tr) { xml_dim_t p(e); double x,y,z; tr.SetXYZ(x=p.x(), y=p.y(), z=p.z()); - printout(s_print,"<pivot>"," Pivot: x=%9.3f y=%9.3f z=%9.3f",x,y,z); + printout(s_print,"<translation>"," Pivot: x=%9.3f y=%9.3f z=%9.3f",x,y,z); } /// Convert alignment delta objects to Alignments::Delta -- GitLab