diff --git a/DDAlign/include/DDAlign/AlignmentOperators.h b/DDAlign/include/DDAlign/AlignmentOperators.h index 596e108abed8bd5a4179d33ef9a258abb6088e76..080bfc449bada8b44974605124373cef3184d18a 100644 --- a/DDAlign/include/DDAlign/AlignmentOperators.h +++ b/DDAlign/include/DDAlign/AlignmentOperators.h @@ -17,7 +17,7 @@ // Framework include files #include "DD4hep/Alignments.h" #include "DD4hep/GlobalAlignment.h" -#include "DDAlign/AlignmentCache.h" +#include "DDAlign/GlobalAlignmentCache.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -33,17 +33,17 @@ namespace DD4hep { */ class AlignmentOperator { public: - typedef AlignmentStack::StackEntry Entry; - typedef AlignmentCache::Cache Cache; - typedef std::vector<Entry*> Entries; + typedef AlignmentStack::StackEntry Entry; + typedef GlobalAlignmentCache::Cache Cache; + typedef std::vector<Entry*> Entries; typedef std::map<std::string,std::pair<TGeoPhysicalNode*,Entry*> > Nodes; - AlignmentCache& cache; + GlobalAlignmentCache& cache; Nodes& nodes; public: /// Initializing functor constructor - AlignmentOperator(AlignmentCache& c, Nodes& n) : cache(c), nodes(n) {} + AlignmentOperator(GlobalAlignmentCache& c, Nodes& n) : cache(c), nodes(n) {} /// Insert alignment entry - void insert(Alignment alignment) const; + void insert(GlobalAlignment alignment) const; }; /// Select alignment operations according to certain criteria @@ -56,11 +56,11 @@ namespace DD4hep { public: const Entries& entries; /// Initializing functor constructor - AlignmentSelector(AlignmentCache& c, Nodes& n, const Entries& e) : AlignmentOperator(c,n), entries(e) {} + AlignmentSelector(GlobalAlignmentCache& c, Nodes& n, const Entries& e) : AlignmentOperator(c,n), entries(e) {} ~AlignmentSelector() { } const AlignmentSelector& reset() const { nodes.clear(); return *this; } /// Function callback for cache entries - void operator()(const AlignmentCache::Cache::value_type& e) const; + void operator()(const GlobalAlignmentCache::Cache::value_type& e) const; /// Function callback for entries void operator()(Entry* e) const; }; @@ -74,7 +74,7 @@ namespace DD4hep { template <typename T> class AlignmentActor : public AlignmentOperator { public: /// Initializing functor constructor - AlignmentActor(AlignmentCache& c, Nodes& n) : AlignmentOperator(c,n) { init(); } + AlignmentActor(GlobalAlignmentCache& c, Nodes& n) : AlignmentOperator(c,n) { init(); } void init() {} /// Function callback for entries void operator()(Nodes::value_type& e) const; diff --git a/DDAlign/include/DDAlign/AlignmentStack.h b/DDAlign/include/DDAlign/AlignmentStack.h index 87be8a206adb7576c2cabb6d0829f77205659981..ad0dffbf228b9ac8a06ce4ed057093fe428f5216 100644 --- a/DDAlign/include/DDAlign/AlignmentStack.h +++ b/DDAlign/include/DDAlign/AlignmentStack.h @@ -15,7 +15,7 @@ #define DD4HEP_ALIGNMENT_ALIGNMENTSTACK_H // Framework include files -#include "DD4hep/Detector.h" +#include "DD4hep/Alignments.h" #include "DD4hep/Objects.h" #include "DD4hep/Memory.h" @@ -35,12 +35,12 @@ namespace DD4hep { class AlignmentStack { public: enum { - OVERLAP_DEFINED = 1<<0, - MATRIX_DEFINED = 1<<1, - CHECKOVL_DEFINED = 1<<2, - CHECKOVL_VALUE = 1<<3, - RESET_VALUE = 1<<4, - RESET_CHILDREN = 1<<5, + OVERLAP_DEFINED = 1<<20, + MATRIX_DEFINED = 1<<21, + CHECKOVL_DEFINED = 1<<22, + CHECKOVL_VALUE = 1<<23, + RESET_VALUE = 1<<24, + RESET_CHILDREN = 1<<25, ____LLLAST = 1<<31 } Flags; @@ -52,28 +52,16 @@ namespace DD4hep { */ struct StackEntry { /// Reference to the detector element - DetElement detector; - /// 3-D Transformation matrix for the volume - Transform3D transform; + DetElement detector; + /// Delta transformation to be applied + Delta delta; /// Path to the misaligned volume - std::string path; + std::string path; /// Parameter for overlap checking - double overlap; - /// Flag containing various encodings - int flag; + double overlap; /// Fully initializing constructor - StackEntry(const DetElement& p, const std::string& placement, const Transform3D& t, double ov, int flg); - /// Constructor with partial initialization - StackEntry(DetElement element, bool rst=true, bool rst_children=true); - /// Constructor with partial initialization - StackEntry(DetElement element, const Transform3D& trafo, bool rst=true, bool rst_children=true); - /// Constructor with partial initialization - StackEntry(DetElement element, const Position& translation, bool rst=true, bool rst_children=true); - /// Constructor with partial initialization - StackEntry(DetElement element, const RotationZYX& rot, bool rst=true, bool rst_children=true); - /// Constructor with partial initialization - StackEntry(DetElement element, const Position& translation, const RotationZYX& rot, bool rst=true, bool rst_children=true); + StackEntry(DetElement p, const std::string& placement, const Delta& t, double ov); /// Copy constructor StackEntry(const StackEntry& e); /// Default destructor @@ -82,25 +70,19 @@ namespace DD4hep { /// Assignment operator StackEntry& operator=(const StackEntry& e); - /// Check a given flag - bool checkFlag(int mask) const { return (flag&mask) == mask; } /// Check if the overlap flag checking is enabled - bool overlapDefined() const { return checkFlag(OVERLAP_DEFINED); } + bool overlapDefined() const { return delta.checkFlag(OVERLAP_DEFINED); } /// Check if the overlap flag checking is enabled - bool checkOverlap() const { return checkFlag(CHECKOVL_DEFINED); } + bool checkOverlap() const { return delta.checkFlag(CHECKOVL_DEFINED); } /// Check if the overalp value is present - bool overlapValue() const { return checkFlag(CHECKOVL_VALUE); } + bool overlapValue() const { return delta.checkFlag(CHECKOVL_VALUE); } /// Check if this alignment entry has a non unitary transformation matrix - bool hasMatrix() const { return checkFlag(MATRIX_DEFINED); } + bool hasMatrix() const { return delta.checkFlag(MATRIX_DEFINED); } /// Check flag if the node location should be reset - bool needsReset() const { return checkFlag(RESET_VALUE); } + bool needsReset() const { return delta.checkFlag(RESET_VALUE); } /// Check flag if the node location and all children should be reset - bool resetChildren() const { return checkFlag(RESET_CHILDREN); } + bool resetChildren() const { return delta.checkFlag(RESET_CHILDREN); } - /// Attach transformation object - StackEntry& setTransformation(const Transform3D& trafo); - /// Instruct entry to ignore the transformation - StackEntry& clearTransformation(); /// Set flag to reset the entry to it's ideal geometrical position StackEntry& setReset(bool new_value=true); /// Set flag to reset the entry's children to their ideal geometrical position @@ -130,9 +112,9 @@ namespace DD4hep { /// Check existence of alignment stack static bool exists(); /// Add a new entry to the cache. The key is the placement path - static bool insert(const std::string& full_path, dd4hep_ptr<StackEntry>& new_entry); + 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 - static bool insert(dd4hep_ptr<StackEntry>& new_entry); + bool insert(dd4hep_ptr<StackEntry>& new_entry); /// Clear data content and remove the slignment stack void release(); /// Access size of the alignment stack diff --git a/DDAlign/include/DDAlign/AlignmentTags.h b/DDAlign/include/DDAlign/AlignmentTags.h index 44d295b8e0baa5fcc55f32eefd41477fdfe87980..7287c19e9525c96b7b8676fb6e92a3998a97c516 100644 --- a/DDAlign/include/DDAlign/AlignmentTags.h +++ b/DDAlign/include/DDAlign/AlignmentTags.h @@ -42,6 +42,7 @@ namespace DD4hep { UNICODE(open_transaction); UNICODE(close_transaction); UNICODE(check_overlaps); + UNICODE(debug); } } diff --git a/DDAlign/include/DDAlign/AlignmentTransaction.h b/DDAlign/include/DDAlign/AlignmentTransaction.h deleted file mode 100644 index bb525291cb1d6cf8e1b51442cad891dae6846679..0000000000000000000000000000000000000000 --- a/DDAlign/include/DDAlign/AlignmentTransaction.h +++ /dev/null @@ -1,54 +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_ALIGNMENT_ALIGNMENTTRANSACTION_H -#define DD4HEP_ALIGNMENT_ALIGNMENTTRANSACTION_H - -// Framework include files -#include "DD4hep/Alignments.h" - -/// Namespace for the AIDA detector description toolkit -namespace DD4hep { - - namespace XML { class Handle_t; } - - /// Namespace for the geometry part of the AIDA detector description toolkit - namespace Alignments { - - // Forward declarations - class AlignmentCache; - - /// Manage alignment transaction to the cache for a given LCDD instance - /** - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_ALIGN - */ - class AlignmentTransaction { - public: - /// Internal flag to remember transaction contexts - bool flag; - /// Reference to the current LCDD instance - LCDD& lcdd; - /// Reference to the alignment cache - AlignmentCache* m_cache; - - /// Default constructor - AlignmentTransaction(LCDD& l, const XML::Handle_t& e); - /// Default destructor - ~AlignmentTransaction(); - }; - - } /* End namespace Geometry */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_ALIGNMENT_ALIGNMENTTRANSACTION_H */ diff --git a/DDAlign/include/DDAlign/AlignmentCache.h b/DDAlign/include/DDAlign/GlobalAlignmentCache.h similarity index 78% rename from DDAlign/include/DDAlign/AlignmentCache.h rename to DDAlign/include/DDAlign/GlobalAlignmentCache.h index a10fb19b91eaac4f802590aa3ce9d66456899aed..17e3471c00b7b7ff6ce3c0cb7a8d800bc6c5588b 100644 --- a/DDAlign/include/DDAlign/AlignmentCache.h +++ b/DDAlign/include/DDAlign/GlobalAlignmentCache.h @@ -11,8 +11,8 @@ // Author : M.Frank // //========================================================================== -#ifndef DD4HEP_ALIGNMENT_ALIGNMENTCACHE_H -#define DD4HEP_ALIGNMENT_ALIGNMENTCACHE_H +#ifndef DD4HEP_ALIGNMENT_GLOBALALIGNMENTCACHE_H +#define DD4HEP_ALIGNMENT_GLOBALALIGNMENTCACHE_H // Framework include files #include "DD4hep/GlobalAlignment.h" @@ -26,7 +26,7 @@ namespace DD4hep { /// Forward declarations class AlignmentOperator; - class AlignmentCache; + class GlobalAlignmentCache; class AlignmentStack; /// Class caching all known alignment operations for one LCDD instance. @@ -38,14 +38,15 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP_ALIGN */ - class AlignmentCache { + class GlobalAlignmentCache { friend class LCDD; friend class AlignmentOperator; public: + typedef AlignmentStack Stack; typedef AlignmentStack::StackEntry Entry; typedef std::map<unsigned int, TGeoPhysicalNode*> Cache; - typedef std::map<std::string,AlignmentCache*> SubdetectorAlignments; + typedef std::map<std::string,GlobalAlignmentCache*> SubdetectorAlignments; protected: LCDD& m_lcdd; @@ -53,6 +54,7 @@ namespace DD4hep { SubdetectorAlignments m_detectors; /// The subdetector specific map of alignments caches Cache m_cache; + /// /// Branchg name: If it is not the main tree instance, the name of the subdetector std::string m_sdPath; /// The length of the branch name to optimize lookups.... @@ -63,12 +65,13 @@ namespace DD4hep { bool m_top; protected: - /// Default constructor - AlignmentCache(LCDD& lcdd, const std::string& sdPath, bool top); + /// Default constructor initializing variables + GlobalAlignmentCache(LCDD& lcdd, const std::string& sdPath, bool top); /// Default destructor - virtual ~AlignmentCache(); + virtual ~GlobalAlignmentCache(); + /// Retrieve branch cache by name. If not present it will be created - AlignmentCache* subdetectorAlignments(const std::string& name); + GlobalAlignmentCache* subdetectorAlignments(const std::string& name); /// Population entry: Apply a complete stack of ordered alignments to the geometry structure void apply(AlignmentStack& stack); @@ -79,28 +82,25 @@ namespace DD4hep { public: /// Create and install a new instance tree - static void install(LCDD& lcdd); + static GlobalAlignmentCache* install(LCDD& lcdd); /// Unregister and delete a tree instance static void uninstall(LCDD& lcdd); - /// Add reference count int addRef(); /// Release object. If reference count goes to NULL, automatic deletion is triggered. int release(); /// Access the section name const std::string& name() const { return m_sdPath; } - /// Open a new transaction stack (Note: only one stack allowed!) - void openTransaction(); /// Close existing transaction stack and apply all alignments - void closeTransaction(); + void commit(AlignmentStack& stack); /// Retrieve the cache section corresponding to the path of an entry. - AlignmentCache* section(const std::string& path_name) const; + GlobalAlignmentCache* section(const std::string& path_name) const; /// Retrieve an alignment entry by its lacement 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; }; - } /* End namespace Alignments */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_ALIGNMENT_ALIGNMENTCACHE_H */ + } /* End namespace Alignments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_ALIGNMENT_GLOBALALIGNMENTCACHE_H */ diff --git a/DDAlign/include/DDAlign/AlignmentWriter.h b/DDAlign/include/DDAlign/GlobalAlignmentWriter.h similarity index 86% rename from DDAlign/include/DDAlign/AlignmentWriter.h rename to DDAlign/include/DDAlign/GlobalAlignmentWriter.h index 43d36dc125c091b4b4c58a4d8df76534bddfa80b..632039de3bd7cc7a80faf37f13da3b8618ba9162 100644 --- a/DDAlign/include/DDAlign/AlignmentWriter.h +++ b/DDAlign/include/DDAlign/GlobalAlignmentWriter.h @@ -11,8 +11,8 @@ // Author : M.Frank // //========================================================================== -#ifndef DD4HEP_DDALIGN_ALIGNMENTWRITER_H -#define DD4HEP_DDALIGN_ALIGNMENTWRITER_H +#ifndef DD4HEP_DDALIGN_GLOBALALIGNMENTWRITER_H +#define DD4HEP_DDALIGN_GLOBALALIGNMENTWRITER_H // Framework include files #include "XML/XMLElements.h" @@ -26,7 +26,7 @@ namespace DD4hep { namespace Alignments { // Forward declarations - class AlignmentCache; + class GlobalAlignmentCache; /// Write aligment data to XML data file /** @@ -34,21 +34,21 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP_ALIGN */ - class AlignmentWriter { + class GlobalAlignmentWriter { protected: /// Reference to detector description LCDD& m_lcdd; /// Reference to the alignment cache - AlignmentCache* m_cache; + GlobalAlignmentCache* m_cache; /// Add single alignment node to the XML document void addNode(XML::Element elt, GlobalAlignment a) const; public: /// Initializing Constructor - AlignmentWriter(LCDD& lcdd); + GlobalAlignmentWriter(LCDD& lcdd); /// Standard destructor - virtual ~AlignmentWriter(); + virtual ~GlobalAlignmentWriter(); /// Dump one full DetElement subtree into a newly created document XML::Document dump(DetElement element, bool enable_transactions=false) const; @@ -61,5 +61,5 @@ namespace DD4hep { }; } // End namespace XML } // End namespace DD4hep -#endif // DD4HEP_DDALIGN_ALIGNMENTWRITER_H +#endif // DD4HEP_DDALIGN_GLOBALALIGNMENTWRITER_H diff --git a/DDAlign/include/DDAlign/DetectorAlignment.h b/DDAlign/include/DDAlign/GlobalDetectorAlignment.h similarity index 86% rename from DDAlign/include/DDAlign/DetectorAlignment.h rename to DDAlign/include/DDAlign/GlobalDetectorAlignment.h index dad90f60aa95cfb2b4f55b38aad968ea9d71d769..3ee1389f1c8b0b5c8a53599c73622ce4fff8e061 100644 --- a/DDAlign/include/DDAlign/DetectorAlignment.h +++ b/DDAlign/include/DDAlign/GlobalDetectorAlignment.h @@ -11,8 +11,8 @@ // Author : M.Frank // //========================================================================== -#ifndef DD4HEP_GEOMETRY_DETECTORALIGNMENT_H -#define DD4HEP_GEOMETRY_DETECTORALIGNMENT_H +#ifndef DD4HEP_GEOMETRY_GLOBALDETECTORALIGNMENT_H +#define DD4HEP_GEOMETRY_GLOBALDETECTORALIGNMENT_H // Framework include files #include "DD4hep/Detector.h" @@ -27,17 +27,21 @@ namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit namespace Alignments { - /// DetectorAlignment. DetElement Handle supporting alignment operations. + /// GlobalDetectorAlignment. DetElement Handle supporting alignment operations. /** * \author M.Frank * \version 1.0 * \ingroup DD4HEP_ALIGN */ - class DetectorAlignment : public DetElement { + class GlobalDetectorAlignment : public DetElement { protected: public: /// Initializing constructor - DetectorAlignment(DetElement e); + GlobalDetectorAlignment(DetElement e); + /// Access debugging flag + static bool debug(); + /// Set debugging flag + static bool debug(bool value); /// Collect all placements from the detector element up to the world volume void collectNodes(std::vector<PlacedVolume>& nodes); /// Access to the alignment block @@ -72,6 +76,6 @@ namespace DD4hep { GlobalAlignment align(const std::string& volume_path, TGeoHMatrix* matrix, bool check = false, double overlap = 0.001); }; - } /* End namespace Alignments */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_GEOMETRY_DETECTORALIGNMENT_H */ + } /* End namespace Alignments */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_GEOMETRY_GLOBALDETECTORALIGNMENT_H */ diff --git a/DDAlign/src/AlignmentOperators.cpp b/DDAlign/src/AlignmentOperators.cpp index a331152eb3135a9be07d22b4997054b191cdbc29..05a4aac789d463ee3ecbec65e769a4ecd9d038fa 100644 --- a/DDAlign/src/AlignmentOperators.cpp +++ b/DDAlign/src/AlignmentOperators.cpp @@ -17,7 +17,7 @@ #include "DD4hep/Printout.h" #include "DD4hep/objects/DetectorInterna.h" #include "DDAlign/AlignmentOperators.h" -#include "DDAlign/DetectorAlignment.h" +#include "DDAlign/GlobalDetectorAlignment.h" // C/C++ include files #include <stdexcept> @@ -26,7 +26,7 @@ using namespace std; using namespace DD4hep; using namespace DD4hep::Alignments; -void AlignmentOperator::insert(Alignment alignment) const { +void AlignmentOperator::insert(GlobalAlignment alignment) const { if ( !cache.insert(alignment) ) { // Error } @@ -57,13 +57,13 @@ void AlignmentSelector::operator()(const Cache::value_type& entry) const { } template <> void AlignmentActor<DDAlign_standard_operations::node_print>::init() { - printout(ALWAYS,"AlignmentCache","++++++++++++++++++++++++ Summary ++++++++++++++++++++++++"); + printout(ALWAYS,"GlobalAlignmentCache","++++++++++++++++++++++++ Summary ++++++++++++++++++++++++"); } template <> void AlignmentActor<DDAlign_standard_operations::node_print>::operator()(Nodes::value_type& n) const { TGeoPhysicalNode* p = n.second.first; Entry* e = n.second.second; - printout(ALWAYS,"AlignmentCache","Need to reset entry:%s - %s [needsReset:%s, hasMatrix:%s]", + 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())); } @@ -74,7 +74,6 @@ template <> void AlignmentActor<DDAlign_standard_operations::node_delete>::opera template <> void AlignmentActor<DDAlign_standard_operations::node_reset>::operator()(Nodes::value_type& n) const { TGeoPhysicalNode* p = n.second.first; - //Entry* e = n.second.second; string np; if ( p->IsAligned() ) { for (Int_t i=0, nLvl=p->GetLevel(); i<=nLvl; i++) { @@ -103,55 +102,55 @@ 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(); + Entry& e = *n.second.second; bool overlap = e.overlapDefined(); - bool has_matrix = e.hasMatrix(); - DetElement det = e.detector; - bool valid = det->global_alignment.isValid(); - string det_placement = det.placementPath(); - - if ( !valid && !has_matrix ) { - cout << "++++ SKIP ALIGNMENT: ++++ " << e.path - << " DE:" << det_placement - << " Valid:" << yes_no(valid) - << " Matrix:" << yes_no(has_matrix) << endl; - /* */ - return; - } + DetElement det = e.detector; - cout << "++++ " << e.path - << " DE:" << det_placement - << " Valid:" << yes_no(valid) - << " Matrix:" << yes_no(has_matrix) - << endl; - /* */ - // Need to care about optional arguments 'check_overlaps' and 'overlap' - DetectorAlignment ad(det); - Alignment alignment; - bool is_not_volume = e.path == det_placement; - if ( check && overlap ) { - alignment = is_not_volume - ? ad.align(e.transform, e.overlapValue(), e.overlap) - : ad.align(e.path, e.transform, e.overlapValue(), e.overlap); - } - else if ( check ) { - alignment = is_not_volume - ? ad.align(e.transform, e.overlapValue()) - : ad.align(e.path, e.transform, e.overlapValue()); + if ( !det->global_alignment.isValid() && !e.hasMatrix() ) { + printout(WARNING,"AlignmentActor","++++ 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())); + return; } - else { - alignment = is_not_volume ? ad.align(e.transform) : ad.align(e.path, e.transform); + if ( GlobalDetectorAlignment::debug() ) { + printout(INFO,"AlignmentActor","++++ %s DE:%s Matrix:%s", + e.path.c_str(),det.placementPath().c_str(),yes_no(e.hasMatrix())); } - if ( alignment.isValid() ) { - insert(alignment); + // 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; + + if ( delta.checkFlag(Delta::HAVE_ROTATION|Delta::HAVE_PIVOT|Delta::HAVE_TRANSLATION) ) + trafo = Transform3D(Translation3D(delta.translation)*delta.pivot*delta.rotation*(delta.pivot.Inverse())); + else if ( delta.checkFlag(Delta::HAVE_ROTATION|Delta::HAVE_TRANSLATION) ) + trafo = Transform3D(delta.rotation,delta.translation); + else if ( delta.checkFlag(Delta::HAVE_ROTATION|Delta::HAVE_PIVOT) ) + trafo = Transform3D(delta.pivot*delta.rotation*(delta.pivot.Inverse())); + else if ( delta.checkFlag(Delta::HAVE_ROTATION) ) + trafo = Transform3D(delta.rotation); + 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); + else + align = no_vol ? ad.align(trafo) : ad.align(e.path,trafo); + + if ( align.isValid() ) { + insert(align); return; } - throw runtime_error("Failed to apply alignment for "+e.path); + except("AlignmentActor","Failed to apply alignment for "+e.path); } #if 0 -void alignment_reset_dbg(const string& path, const Alignment& a) { +void alignment_reset_dbg(const string& path, const GlobalAlignment& a) { TGeoPhysicalNode* n = a.ptr(); cout << " +++++++++++++++++++++++++++++++ " << path << endl; cout << " +++++ Misaligned physical node: " << endl; diff --git a/DDAlign/src/AlignmentStack.cpp b/DDAlign/src/AlignmentStack.cpp index 74f3176de5eb0bbe14242a374f942c8e2299a5d9..02450af33f6bec10154f949aa5512743cbaa9984 100644 --- a/DDAlign/src/AlignmentStack.cpp +++ b/DDAlign/src/AlignmentStack.cpp @@ -33,74 +33,16 @@ static dd4hep_ptr<AlignmentStack>& _stack(AlignmentStack* obj) { return s; } -/// Fully initializing constructor -AlignmentStack::StackEntry::StackEntry(const DetElement& p, const string& placement, const Transform3D& t, double ov, int f) - : detector(p), transform(t), path(placement), overlap(ov), flag(f) -{ - InstanceCount::increment(this); -} - -/// Constructor with partial initialization -AlignmentStack::StackEntry::StackEntry(DetElement element, bool rst, bool rst_children) - : detector(element), transform(), overlap(0.001), flag(0) -{ - InstanceCount::increment(this); - if ( rst ) flag |= RESET_VALUE; - if ( rst_children ) flag |= RESET_CHILDREN; - if ( detector.isValid() ) path = detector.placementPath(); -} - -/// Constructor with partial initialization -AlignmentStack::StackEntry::StackEntry(DetElement element, const Transform3D& trafo, bool rst, bool rst_children) - : detector(element), transform(trafo), overlap(0.001), flag(0) -{ - InstanceCount::increment(this); - flag |= MATRIX_DEFINED; - if ( rst ) flag |= RESET_VALUE; - if ( rst_children ) flag |= RESET_CHILDREN; - if ( detector.isValid() ) path = detector.placementPath(); -} - -/// Constructor with partial initialization -AlignmentStack::StackEntry::StackEntry(DetElement element, const Position& translation, bool rst, bool rst_children) - : detector(element), transform(translation), overlap(0.001), flag(0) -{ - InstanceCount::increment(this); - flag |= MATRIX_DEFINED; - if ( rst ) flag |= RESET_VALUE; - if ( rst_children ) flag |= RESET_CHILDREN; - if ( detector.isValid() ) path = detector.placementPath(); -} - /// Constructor with partial initialization -AlignmentStack::StackEntry::StackEntry(DetElement element, const RotationZYX& rot, bool rst, bool rst_children) - : detector(element), transform(rot), overlap(0.001), flag(0) +AlignmentStack::StackEntry::StackEntry(DetElement element, const std::string& p, const Delta& del, double ov) + : detector(element), delta(del), path(p), overlap(ov) { InstanceCount::increment(this); - flag |= MATRIX_DEFINED; - if ( rst ) flag |= RESET_VALUE; - if ( rst_children ) flag |= RESET_CHILDREN; - if ( detector.isValid() ) path = detector.placementPath(); -} - -/// Constructor with partial initialization -AlignmentStack::StackEntry::StackEntry(DetElement element, - const Position& translation, - const RotationZYX& rot, - bool rst, - bool rst_children) - : detector(element), transform(rot,translation), overlap(0.001), flag(0) -{ - InstanceCount::increment(this); - flag |= MATRIX_DEFINED; - if ( rst ) flag |= RESET_VALUE; - if ( rst_children ) flag |= RESET_CHILDREN; - if ( detector.isValid() ) path = detector.placementPath(); } /// Copy constructor AlignmentStack::StackEntry::StackEntry(const StackEntry& e) - : detector(e.detector), transform(e.transform), path(e.path), overlap(e.overlap), flag(e.flag) + : detector(e.detector), delta(e.delta), path(e.path), overlap(e.overlap) { InstanceCount::increment(this); } @@ -114,53 +56,38 @@ AlignmentStack::StackEntry::~StackEntry() { AlignmentStack::StackEntry& AlignmentStack::StackEntry::operator=(const StackEntry& e) { if ( this != &e ) { detector = e.detector; - transform = e.transform; - overlap = e.overlap; - path = e.path; - flag = e.flag; + delta = e.delta; + overlap = e.overlap; + path = e.path; } return *this; } -/// Attach transformation object -AlignmentStack::StackEntry& AlignmentStack::StackEntry::setTransformation(const Transform3D& trafo) { - flag |= MATRIX_DEFINED; - transform = trafo; - return *this; -} - -/// Instruct entry to ignore the transformation -AlignmentStack::StackEntry& AlignmentStack::StackEntry::clearTransformation() { - flag &= ~MATRIX_DEFINED; - transform = Transform3D(); - return *this; -} - /// Set flag to reset the entry to it's ideal geometrical position AlignmentStack::StackEntry& AlignmentStack::StackEntry::setReset(bool new_value) { - new_value ? (flag |= RESET_VALUE) : (flag &= ~RESET_VALUE); + new_value ? (delta.flags |= RESET_VALUE) : (delta.flags &= ~RESET_VALUE); return *this; } /// Set flag to reset the entry's children to their ideal geometrical position AlignmentStack::StackEntry& AlignmentStack::StackEntry::setResetChildren(bool new_value) { - new_value ? (flag |= RESET_CHILDREN) : (flag &= ~RESET_CHILDREN); + new_value ? (delta.flags |= RESET_CHILDREN) : (delta.flags &= ~RESET_CHILDREN); return *this; } /// Set flag to check overlaps AlignmentStack::StackEntry& AlignmentStack::StackEntry::setOverlapCheck(bool new_value) { - new_value ? (flag |= CHECKOVL_DEFINED) : (flag &= ~CHECKOVL_DEFINED); + new_value ? (delta.flags |= CHECKOVL_DEFINED) : (delta.flags &= ~CHECKOVL_DEFINED); return *this; } /// Set the precision for the overlap check (otherwise the default is 0.001 cm) AlignmentStack::StackEntry& AlignmentStack::StackEntry::setOverlapPrecision(double precision) { - flag |= CHECKOVL_DEFINED; - flag |= CHECKOVL_VALUE; + delta.flags |= CHECKOVL_DEFINED; + delta.flags |= CHECKOVL_VALUE; overlap = precision; return *this; } @@ -209,14 +136,14 @@ void AlignmentStack::release() { bool AlignmentStack::insert(const string& full_path, dd4hep_ptr<StackEntry>& entry) { if ( entry.get() && !full_path.empty() ) { entry->path = full_path; - return get().add(entry); + return add(entry); } throw runtime_error("AlignmentStack> Attempt to apply an invalid alignment entry."); } /// Add a new entry to the cache. The key is the placement path bool AlignmentStack::insert(dd4hep_ptr<StackEntry>& entry) { - return get().add(entry); + return add(entry); } /// Add a new entry to the cache. The key is the placement path diff --git a/DDAlign/src/AlignmentTransaction.cpp b/DDAlign/src/AlignmentTransaction.cpp deleted file mode 100644 index 0a3cd82c4ea8384ad4645715c604a06fddefbf26..0000000000000000000000000000000000000000 --- a/DDAlign/src/AlignmentTransaction.cpp +++ /dev/null @@ -1,41 +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 include files -#include "DD4hep/LCDD.h" -#include "DDAlign/AlignmentTags.h" -#include "DDAlign/AlignmentCache.h" -#include "DDAlign/AlignmentTransaction.h" - -using namespace DD4hep; -using namespace DD4hep::Alignments; - -/// Default constructor -AlignmentTransaction::AlignmentTransaction(LCDD& l, const XML::Handle_t& e) : lcdd(l) { - flag = e.hasChild(_ALU(close_transaction)); - /// First check if a transaction is to be opened - m_cache = lcdd.extension<Alignments::AlignmentCache>(); - m_cache->addRef(); - if ( e.hasChild(_ALU(open_transaction)) ) { - m_cache->openTransaction(); - } -} -/// Default destructor -AlignmentTransaction::~AlignmentTransaction() { - /// Last check if a transaction is to be closed - if ( flag ) { - lcdd.extension<Alignments::AlignmentCache>()->closeTransaction(); - } - m_cache->release(); -} diff --git a/DDAlign/src/AlignmentCache.cpp b/DDAlign/src/GlobalAlignmentCache.cpp similarity index 71% rename from DDAlign/src/AlignmentCache.cpp rename to DDAlign/src/GlobalAlignmentCache.cpp index 4a6ae6d486d385e780c58c4db0c007a20bc47d4c..a8ceb60addd258ebce2261231a3c68d0516c6c1a 100644 --- a/DDAlign/src/AlignmentCache.cpp +++ b/DDAlign/src/GlobalAlignmentCache.cpp @@ -15,11 +15,9 @@ // Framework include files #include "DD4hep/LCDD.h" #include "DD4hep/Printout.h" -#include "DD4hep/DetectorTools.h" -#include "DDAlign/AlignmentCache.h" +#include "DDAlign/GlobalAlignmentCache.h" #include "DDAlign/AlignmentOperators.h" #include "DD4hep/objects/DetectorInterna.h" -#include "DD4hep/objects/ConditionsInterna.h" // ROOT include files #include "TGeoManager.h" @@ -43,29 +41,29 @@ DetElement _detector(DetElement child) { } /// Default constructor -AlignmentCache::AlignmentCache(LCDD& lcdd, const string& sdPath, bool top) +GlobalAlignmentCache::GlobalAlignmentCache(LCDD& lcdd, const string& sdPath, bool top) : m_lcdd(lcdd), m_sdPath(sdPath), m_sdPathLen(sdPath.length()), m_refCount(1), m_top(top) { } /// Default destructor -AlignmentCache::~AlignmentCache() { +GlobalAlignmentCache::~GlobalAlignmentCache() { int nentries = (int)m_cache.size(); int nsect = (int)m_detectors.size(); releaseObjects(m_detectors); m_cache.clear(); - printout(INFO,"AlignmentCache", + printout(INFO,"GlobalAlignmentCache", "Destroy cache for subdetector %s [%d section(s), %d entrie(s)]", m_sdPath.c_str(),nsect,nentries); } /// Add reference count -int AlignmentCache::addRef() { +int GlobalAlignmentCache::addRef() { return ++m_refCount; } /// Release object. If reference count goes to NULL, automatic deletion is triggered. -int AlignmentCache::release() { +int GlobalAlignmentCache::release() { int value = --m_refCount; if ( value == 0 ) { delete this; @@ -73,12 +71,28 @@ int AlignmentCache::release() { return value; } +/// Create and install a new instance tree +GlobalAlignmentCache* GlobalAlignmentCache::install(LCDD& lcdd) { + GlobalAlignmentCache* cache = lcdd.extension<GlobalAlignmentCache>(false); + if ( !cache ) { + lcdd.addExtension<GlobalAlignmentCache>(new GlobalAlignmentCache(lcdd,"world",true)); + } + return cache; +} + +/// Unregister and delete a tree instance +void GlobalAlignmentCache::uninstall(LCDD& lcdd) { + if ( lcdd.extension<GlobalAlignmentCache>(false) ) { + lcdd.removeExtension<GlobalAlignmentCache>(true); + } +} + /// Add a new entry to the cache. The key is the placement path -bool AlignmentCache::insert(GlobalAlignment alignment) { +bool GlobalAlignmentCache::insert(GlobalAlignment alignment) { TGeoPhysicalNode* pn = alignment.ptr(); unsigned int index = hash32(pn->GetName()+m_sdPathLen); Cache::const_iterator i = m_cache.find(index); - printout(ALWAYS,"AlignmentCache","Section: %s adding entry: %s", + printout(ALWAYS,"GlobalAlignmentCache","Section: %s adding entry: %s", name().c_str(),alignment->GetName()); if ( i == m_cache.end() ) { m_cache[index] = pn; @@ -88,13 +102,13 @@ bool AlignmentCache::insert(GlobalAlignment alignment) { } /// Retrieve the cache section corresponding to the path of an entry. -AlignmentCache* AlignmentCache::section(const string& path_name) const { +GlobalAlignmentCache* GlobalAlignmentCache::section(const string& path_name) const { size_t idx, idq; if ( path_name[0] != '/' ) { return section(m_lcdd.world().placementPath()+'/'+path_name); } else if ( (idx=path_name.find('/',1)) == string::npos ) { - return (m_sdPath == path_name.c_str()+1) ? (AlignmentCache*)this : 0; + return (m_sdPath == path_name.c_str()+1) ? (GlobalAlignmentCache*)this : 0; } else if ( m_detectors.empty() ) { return 0; @@ -106,7 +120,7 @@ AlignmentCache* AlignmentCache::section(const string& path_name) const { } /// Retrieve an alignment entry by its placement path -GlobalAlignment AlignmentCache::get(const string& path_name) const { +GlobalAlignment GlobalAlignmentCache::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); @@ -131,9 +145,9 @@ GlobalAlignment AlignmentCache::get(const string& path_name) const { } /// Return all entries matching a given path. -vector<GlobalAlignment> AlignmentCache::matches(const string& match, bool exclude_exact) const { +vector<GlobalAlignment> GlobalAlignmentCache::matches(const string& match, bool exclude_exact) const { vector<GlobalAlignment> result; - AlignmentCache* c = section(match); + GlobalAlignmentCache* c = section(match); if ( c ) { size_t len = match.length(); result.reserve(c->m_cache.size()); @@ -149,55 +163,19 @@ vector<GlobalAlignment> AlignmentCache::matches(const string& match, bool exclud return result; } -/// Open a new transaction stack (Note: only one stack allowed!) -void AlignmentCache::openTransaction() { - /// Check if transaction already present. If not, open, else issue an error - if ( !AlignmentStack::exists() ) { - AlignmentStack::create(); - return; - } - string msg = "Request to open a second alignment transaction stack -- not allowed!"; - string err = format("Alignment<alignment>",msg); - printout(FATAL,"AlignmentCache",msg); - throw runtime_error(err); -} - /// Close existing transaction stack and apply all alignments -void AlignmentCache::closeTransaction() { - /// Check if transaction is open. If yes, close it and apply alignment stack. - /// If no transaction is active, ignore the staement, but issue a warning. - if ( AlignmentStack::exists() ) { - TGeoManager& mgr = m_lcdd.manager(); - mgr.UnlockGeometry(); - apply(AlignmentStack::get()); - AlignmentStack::get().release(); - mgr.LockGeometry(); - return; - } - printout(WARNING,"Alignment<alignment>", - "Request to close a non-existing alignmant transaction."); -} - -/// Create and install a new instance tree -void AlignmentCache::install(LCDD& lcdd) { - AlignmentCache* cache = lcdd.extension<AlignmentCache>(false); - if ( !cache ) { - lcdd.addExtension<AlignmentCache>(new AlignmentCache(lcdd,"world",true)); - } -} - -/// Unregister and delete a tree instance -void AlignmentCache::uninstall(LCDD& lcdd) { - if ( lcdd.extension<AlignmentCache>(false) ) { - lcdd.removeExtension<AlignmentCache>(true); - } +void GlobalAlignmentCache::commit(AlignmentStack& stack) { + TGeoManager& mgr = m_lcdd.manager(); + mgr.UnlockGeometry(); + apply(stack); + mgr.LockGeometry(); } /// Retrieve branch cache by name. If not present it will be created -AlignmentCache* AlignmentCache::subdetectorAlignments(const string& nam) { +GlobalAlignmentCache* GlobalAlignmentCache::subdetectorAlignments(const string& nam) { SubdetectorAlignments::const_iterator i = m_detectors.find(nam); if ( i == m_detectors.end() ) { - AlignmentCache* ptr = new AlignmentCache(m_lcdd,nam,false); + GlobalAlignmentCache* ptr = new GlobalAlignmentCache(m_lcdd,nam,false); m_detectors.insert(make_pair(nam,ptr)); return ptr; } @@ -205,7 +183,7 @@ AlignmentCache* AlignmentCache::subdetectorAlignments(const string& nam) { } /// Apply a complete stack of ordered alignments to the geometry structure -void AlignmentCache::apply(AlignmentStack& stack) { +void GlobalAlignmentCache::apply(AlignmentStack& stack) { typedef map<string,DetElement> DetElementUpdates; typedef map<DetElement,vector<Entry*> > sd_entries_t; TGeoManager& mgr = m_lcdd.manager(); @@ -222,12 +200,12 @@ void AlignmentCache::apply(AlignmentStack& stack) { } for(sd_entries_t::iterator i=all.begin(); i!=all.end(); ++i) { DetElement det((*i).first); - AlignmentCache* sd_cache = subdetectorAlignments(det.placement().name()); + GlobalAlignmentCache* sd_cache = subdetectorAlignments(det.placement().name()); sd_cache->apply( (*i).second ); (*i).second.clear(); } - printout(INFO,"AlignmentCache","Alignments were applied. Refreshing physical nodes...."); + printout(INFO,"GlobalAlignmentCache","Alignments were applied. Refreshing physical nodes...."); mgr.GetCurrentNavigator()->ResetAll(); mgr.GetCurrentNavigator()->BuildCache(); mgr.RefreshPhysicalNodes(); @@ -235,7 +213,7 @@ void AlignmentCache::apply(AlignmentStack& stack) { // Provide update callback for every detector element with a changed placement for(DetElementUpdates::iterator i=detelt_updates.begin(); i!=detelt_updates.end(); ++i) { DetElement elt((*i).second); - printout(DEBUG,"AlignmentCache","+++ Trigger placement update for %s [2]",elt.path().c_str()); + printout(DEBUG,"GlobalAlignmentCache","+++ Trigger placement update for %s [2]",elt.path().c_str()); elt->update(DetElement::PLACEMENT_CHANGED|DetElement::PLACEMENT_ELEMENT,elt.ptr()); } // Provide update callback for the highest detector element @@ -244,7 +222,7 @@ void AlignmentCache::apply(AlignmentStack& stack) { const string& path = (*i).first; if ( path.find(last_path) == string::npos ) { DetElement elt((*i).second); - printout(DEBUG,"AlignmentCache","+++ Trigger placement update for %s [1]",elt.path().c_str()); + printout(DEBUG,"GlobalAlignmentCache","+++ Trigger placement update for %s [1]",elt.path().c_str()); elt->update(DetElement::PLACEMENT_CHANGED|DetElement::PLACEMENT_HIGHEST,elt.ptr()); last_path = (*i).first; } @@ -252,13 +230,13 @@ void AlignmentCache::apply(AlignmentStack& stack) { // Provide update callback at the detector level for(sd_entries_t::iterator i=all.begin(); i!=all.end(); ++i) { DetElement elt((*i).first); - printout(DEBUG,"AlignmentCache","+++ Trigger placement update for %s [0]",elt.path().c_str()); + printout(DEBUG,"GlobalAlignmentCache","+++ Trigger placement update for %s [0]",elt.path().c_str()); elt->update(DetElement::PLACEMENT_CHANGED|DetElement::PLACEMENT_DETECTOR,elt.ptr()); } } /// Apply a vector of SD entries of ordered alignments to the geometry structure -void AlignmentCache::apply(const vector<Entry*>& changes) { +void GlobalAlignmentCache::apply(const vector<Entry*>& changes) { typedef map<string,pair<TGeoPhysicalNode*,Entry*> > Nodes; Nodes nodes; AlignmentSelector selector(*this,nodes,changes); diff --git a/DDAlign/src/AlignmentWriter.cpp b/DDAlign/src/GlobalAlignmentWriter.cpp similarity index 84% rename from DDAlign/src/AlignmentWriter.cpp rename to DDAlign/src/GlobalAlignmentWriter.cpp index d6d9cb03275d2f05f55d79fbaffca5670acae249..d6b921601f8da8a430a704ef02432a60f5f0df12 100644 --- a/DDAlign/src/AlignmentWriter.cpp +++ b/DDAlign/src/GlobalAlignmentWriter.cpp @@ -13,16 +13,16 @@ //========================================================================== // Framework includes -#include "DDAlign/AlignmentWriter.h" +#include "DDAlign/GlobalAlignmentWriter.h" +#include "DDAlign/GlobalAlignmentCache.h" +#include "DDAlign/GlobalDetectorAlignment.h" +#include "DDAlign/AlignmentTags.h" #include "DD4hep/LCDD.h" #include "DD4hep/Printout.h" #include "DD4hep/MatrixHelpers.h" #include "DD4hep/objects/DetectorInterna.h" #include "XML/DocumentHandler.h" -#include "DDAlign/AlignmentTags.h" -#include "DDAlign/AlignmentCache.h" -#include "DDAlign/DetectorAlignment.h" #include "TGeoMatrix.h" @@ -36,23 +36,24 @@ using namespace DD4hep; using namespace std; /// Initializing Constructor -AlignmentWriter::AlignmentWriter(LCDD& lcdd) +GlobalAlignmentWriter::GlobalAlignmentWriter(LCDD& lcdd) : m_lcdd(lcdd) { - m_cache = lcdd.extension<Alignments::AlignmentCache>(); + m_cache = lcdd.extension<Alignments::GlobalAlignmentCache>(); + if ( m_cache ) m_cache->addRef(); } /// Standard destructor -AlignmentWriter::~AlignmentWriter() { +GlobalAlignmentWriter::~GlobalAlignmentWriter() { if ( m_cache ) m_cache->release(); } /// Create the element corresponding to one single detector element without children -XML::Element AlignmentWriter::createElement(XML::Document doc, DetElement element) const { +XML::Element GlobalAlignmentWriter::createElement(XML::Document doc, DetElement element) const { XML::Element e(0), placement(0), elt = XML::Element(doc,_ALU(detelement)); string path = element.placementPath(); GlobalAlignment a = element->global_alignment; - DetectorAlignment det(element); + GlobalDetectorAlignment det(element); const vector<GlobalAlignment>& va = det.volumeAlignments(); elt.setAttr(_ALU(path),element.path()); @@ -69,7 +70,7 @@ XML::Element AlignmentWriter::createElement(XML::Document doc, DetElement elemen } /// Add single alignment node to the XML document -void AlignmentWriter::addNode(XML::Element elt, GlobalAlignment a) const { +void GlobalAlignmentWriter::addNode(XML::Element elt, GlobalAlignment a) const { TGeoNode* n = a->GetNode(); TGeoHMatrix mat(a->GetOriginalMatrix()->Inverse()); mat.Multiply(n->GetMatrix()); @@ -78,7 +79,7 @@ void AlignmentWriter::addNode(XML::Element elt, GlobalAlignment a) const { placement.setAttr(_ALU(placement),a->GetName()); elt.append(placement); - printout(INFO,"AlignmentWriter","Write Delta constants for %s",a->GetName()); + printout(INFO,"GlobalAlignmentWriter","Write Delta constants for %s",a->GetName()); //mat.Print(); if ( fabs(t[0]) > numeric_limits<double>::epsilon() || fabs(t[1]) > numeric_limits<double>::epsilon() || @@ -107,7 +108,7 @@ void AlignmentWriter::addNode(XML::Element elt, GlobalAlignment a) const { } /// Scan a DetElement subtree and add on the fly the XML entries -XML::Element AlignmentWriter::scan(XML::Document doc, DetElement element) const { +XML::Element GlobalAlignmentWriter::scan(XML::Document doc, DetElement element) const { XML::Element elt(0); if ( element.isValid() ) { const DetElement::Children& c = element.children(); @@ -124,7 +125,7 @@ XML::Element AlignmentWriter::scan(XML::Document doc, DetElement element) const } /// Dump the tree content into a XML document structure -XML::Document AlignmentWriter::dump(DetElement top, bool enable_transactions) const { +XML::Document GlobalAlignmentWriter::dump(DetElement top, bool enable_transactions) const { const char comment[] = "\n" " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" " ++++ DD4hep generated alignment file using the ++++\n" @@ -147,7 +148,7 @@ XML::Document AlignmentWriter::dump(DetElement top, bool enable_transactions) c } /// Write the XML document structure to a file. -long AlignmentWriter::write(XML::Document doc, const string& output) const { +long GlobalAlignmentWriter::write(XML::Document doc, const string& output) const { XML::DocumentHandler docH; return docH.output(doc, output); } diff --git a/DDAlign/src/DetectorAlignment.cpp b/DDAlign/src/GlobalDetectorAlignment.cpp similarity index 69% rename from DDAlign/src/DetectorAlignment.cpp rename to DDAlign/src/GlobalDetectorAlignment.cpp index 7f0e605153be1873da05c6b5b5825f582f274f79..3e88e366e4606343c59a83c56f690c343ba33eab 100644 --- a/DDAlign/src/DetectorAlignment.cpp +++ b/DDAlign/src/GlobalDetectorAlignment.cpp @@ -13,7 +13,7 @@ //========================================================================== // Framework include files -#include "DDAlign/DetectorAlignment.h" +#include "DDAlign/GlobalDetectorAlignment.h" #include "DD4hep/DetectorTools.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/MatrixHelpers.h" @@ -36,13 +36,16 @@ namespace DD4hep { GlobalAlignment global; std::vector<GlobalAlignment> volume_alignments; public: - GlobalAlignmentData() : NamedObject("","global-alignment") {} - virtual ~GlobalAlignmentData() {} + GlobalAlignmentData(const std::string& path) : NamedObject(path,"global-alignment") { + global = GlobalAlignment(path); + } + virtual ~GlobalAlignmentData() { + destroyHandle (global); + } }; } /* End namespace Aligments */ } /* End namespace DD4hep */ - using namespace std; using namespace DD4hep; using namespace DD4hep::Alignments; @@ -50,20 +53,30 @@ using namespace DD4hep::Alignments; namespace DetectorTools = DD4hep::Geometry::DetectorTools; typedef vector<pair<int,DetElement> > LevelElements; +DD4HEP_INSTANTIATE_HANDLE_NAMED(GlobalAlignmentData); + + namespace { + static bool s_GlobalDetectorAlignment_debug = false; + GlobalAlignment _align(const GlobalAlignment& a, TGeoHMatrix* transform, bool check, double overlap) { TGeoPhysicalNode* n = a.ptr(); if ( n ) { TGeoMatrix* mm = n->GetNode()->GetMatrix(); - printout(INFO,"Alignment","DELTA matrix of %s",n->GetName()); - transform->Print(); - /* + bool dbg = GlobalDetectorAlignment::debug(); + if ( dbg ) { + printout(INFO,"Alignment","DELTA matrix of %s",n->GetName()); + transform->Print(); printout(INFO,"Alignment","OLD matrix of %s",n->GetName()); mm->Print(); - */ + } transform->MultiplyLeft(mm); // orig * delta n->Align(transform, 0, check, overlap); + if ( dbg ) { + printout(INFO,"Alignment","NEW matrix of %s",n->GetName()); + n->GetNode()->GetMatrix()->Print(); + } /* printout(INFO,"Alignment","Apply new relative matrix mother to daughter:"); transform->Print(); @@ -71,8 +84,6 @@ namespace { printout(INFO,"Alignment","With deltas %s ....",n->GetName()); transform->Print(); n->Align(transform, 0, check, overlap); - printout(INFO,"Alignment","NEW matrix of %s",n->GetName()); - n->GetNode()->GetMatrix()->Print(); Position local, global = a.toGlobal(local); cout << "Local:" << local << " Global: " << global @@ -83,25 +94,20 @@ namespace { throw runtime_error("DD4hep: Cannot align non existing physical node. [Invalid Handle]"); } - 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 + GlobalAlignment _alignment(const GlobalDetectorAlignment& det) { DetElement::Object& e = det._data(); - if ( !e.alignment.isValid() ) { + if ( !e.global_alignment.isValid() ) { string path = DetectorTools::placementPath(det); - //cout << "Align path:" << path << endl; - e.alignment = GlobalAlignment(path); + e.global_alignment = Ref_t(new GlobalAlignmentData(path)); } - return e.alignment; -#endif + Handle<GlobalAlignmentData> h(e.global_alignment); + if ( h.isValid() && h->global.isValid() ) { + return h->global; + } + throw runtime_error("DD4hep: Cannot access global alignment data. [Invalid Handle]"); } - void _dumpParentElements(DetectorAlignment& det, LevelElements& elements) { + void _dumpParentElements(GlobalDetectorAlignment& det, LevelElements& elements) { int level = 0; DetectorTools::PlacementPath nodes; DetectorTools::ElementPath det_nodes; @@ -127,84 +133,94 @@ namespace { } } -DD4HEP_INSTANTIATE_HANDLE_NAMED(GlobalAlignmentData); - /// Initializing constructor -DetectorAlignment::DetectorAlignment(DetElement e) +GlobalDetectorAlignment::GlobalDetectorAlignment(DetElement e) : DetElement(e) { } +/// Access debugging flag +bool GlobalDetectorAlignment::debug() { + return s_GlobalDetectorAlignment_debug; +} + +/// Set debugging flag +bool GlobalDetectorAlignment::debug(bool value) { + bool tmp = s_GlobalDetectorAlignment_debug; + s_GlobalDetectorAlignment_debug = value; + return tmp; +} + /// Collect all placements from the detector element up to the world volume -void DetectorAlignment::collectNodes(vector<PlacedVolume>& nodes) { +void GlobalDetectorAlignment::collectNodes(vector<PlacedVolume>& nodes) { DetectorTools::placementPath(*this,nodes); } /// Access to the alignment block -GlobalAlignment DetectorAlignment::alignment() const { +GlobalAlignment GlobalDetectorAlignment::alignment() const { return _alignment(*this); } /// Alignment entries for lower level volumes, which are NOT attached to daughter DetElements -vector<GlobalAlignment>& DetectorAlignment::volumeAlignments() { +vector<GlobalAlignment>& GlobalDetectorAlignment::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<GlobalAlignment>& DetectorAlignment::volumeAlignments() const { +const vector<GlobalAlignment>& GlobalDetectorAlignment::volumeAlignments() const { Handle<GlobalAlignmentData> h(_data().global_alignment); return h->volume_alignments; } /// Align the PhysicalNode of the placement of the detector element (translation only) -GlobalAlignment DetectorAlignment::align(const Position& pos, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const Position& pos, bool chk, double overlap) { return align(Geometry::_transform(pos),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (rotation only) -GlobalAlignment DetectorAlignment::align(const RotationZYX& rot, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const RotationZYX& rot, bool chk, double overlap) { return align(Geometry::_transform(rot),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (translation + rotation) -GlobalAlignment DetectorAlignment::align(const Position& pos, const RotationZYX& rot, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const Position& pos, const RotationZYX& rot, bool chk, double overlap) { return align(Geometry::_transform(pos,rot),chk,overlap); } /// Align the physical node according to a generic Transform3D -GlobalAlignment DetectorAlignment::align(const Transform3D& transform, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const Transform3D& transform, bool chk, double overlap) { return align(Geometry::_transform(transform),chk,overlap); } /// Align the physical node according to a generic TGeo matrix -GlobalAlignment DetectorAlignment::align(TGeoHMatrix* matrix, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::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) -GlobalAlignment DetectorAlignment::align(const string& elt_path, const Position& pos, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, const Position& pos, bool chk, double overlap) { return align(elt_path,Geometry::_transform(pos),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (rotation only) -GlobalAlignment DetectorAlignment::align(const string& elt_path, const RotationZYX& rot, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, const RotationZYX& rot, bool chk, double overlap) { return align(elt_path,Geometry::_transform(rot),chk,overlap); } /// Align the PhysicalNode of the placement of the detector element (translation + rotation) GlobalAlignment -DetectorAlignment::align(const string& elt_path, const Position& pos, const RotationZYX& rot, bool chk, double overlap) { +GlobalDetectorAlignment::align(const string& elt_path, const Position& pos, const RotationZYX& rot, bool chk, double overlap) { return align(elt_path,Geometry::_transform(pos,rot),chk,overlap); } /// Align the physical node according to a generic Transform3D -GlobalAlignment DetectorAlignment::align(const string& elt_path, const Transform3D& transform, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::align(const string& elt_path, const Transform3D& transform, bool chk, double overlap) { return align(elt_path,Geometry::_transform(transform),chk,overlap); } /// Align the physical node according to a generic TGeo matrix -GlobalAlignment DetectorAlignment::align(const string& elt_path, TGeoHMatrix* matrix, bool chk, double overlap) { +GlobalAlignment GlobalDetectorAlignment::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() ) diff --git a/DDAlign/src/plugins/AlignmentParser.cpp b/DDAlign/src/plugins/AlignmentParser.cpp index e0df8b57cbc9e180b912b71ba4195ef4b4ab0206..ae840d820a1c4c0a687ecd694a7feb26ecd870e2 100644 --- a/DDAlign/src/plugins/AlignmentParser.cpp +++ b/DDAlign/src/plugins/AlignmentParser.cpp @@ -14,6 +14,8 @@ // Framework include files #include "DD4hep/LCDD.h" +#include "DD4hep/Path.h" +#include "DD4hep/Mutex.h" #include "DD4hep/Printout.h" #include "XML/Conversions.h" #include "XML/XMLElements.h" @@ -23,8 +25,8 @@ #include "DDAlign/AlignmentTags.h" #include "DDAlign/AlignmentStack.h" -#include "DDAlign/AlignmentCache.h" -#include "DDAlign/AlignmentTransaction.h" +#include "DDAlign/GlobalAlignmentCache.h" +#include "DDAlign/GlobalDetectorAlignment.h" // C/C++ include files #include <stdexcept> @@ -41,14 +43,16 @@ namespace DD4hep { class rotation; class position; class pivot; - class transform3d; + class delta; + class debug; } /// Forward declarations for all specialized converters + template <> void Converter<debug>::operator()(xml_h seq) const; template <> void Converter<pivot>::operator()(xml_h seq) const; template <> void Converter<position>::operator()(xml_h seq) const; template <> void Converter<rotation>::operator()(xml_h seq) const; - template <> void Converter<transform3d>::operator()(xml_h seq) const; + template <> void Converter<delta>::operator()(xml_h seq) const; template <> void Converter<volume>::operator()(xml_h seq) const; template <> void Converter<alignment>::operator()(xml_h seq) const; @@ -62,6 +66,17 @@ using namespace DD4hep::Alignments; using DD4hep::Geometry::Position; using DD4hep::Geometry::Translation3D; +/** Convert to enable/disable debugging. + * + * @author M.Frank + * @version 1.0 + * @date 01/04/2014 + */ +template <> void Converter<debug>::operator()(xml_h e) const { + bool value = e.attr<bool>(_U(value)); + GlobalDetectorAlignment::debug(value); +} + /** Convert rotation objects * * <rotation x="0.5" y="0" z="0"/> @@ -74,7 +89,7 @@ template <> void Converter<rotation>::operator()(xml_h e) const { xml_comp_t r(e); RotationZYX* v = (RotationZYX*)param; v->SetComponents(r.z(), r.y(), r.x()); - printout(INFO,"Alignment<rotation>", + printout(INFO,"Alignment<rot>", " 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(), v->Phi(), v->Psi(), v->Theta()); } @@ -91,7 +106,7 @@ template <> void Converter<position>::operator()(xml_h e) const { xml_comp_t p(e); Position* v = (Position*)param; v->SetXYZ(p.x(), p.y(), p.z()); - printout(INFO,"Alignment<position>"," Position: x=%9.3f y=%9.3f z=%9.3f", + printout(INFO,"Alignment<pos>"," Position: x=%9.3f y=%9.3f z=%9.3f", v->X(), v->Y(), v->Z()); } @@ -108,10 +123,10 @@ template <> void Converter<pivot>::operator()(xml_h e) const { double x,y,z; Translation3D* v = (Translation3D*)param; v->SetXYZ(x=p.x(), y=p.y(), z=p.z()); - printout(INFO,"Alignment<pivot>"," Pivot: x=%9.3f y=%9.3f z=%9.3f",x,y,z); + printout(INFO,"Alignment<piv>"," Pivot: x=%9.3f y=%9.3f z=%9.3f",x,y,z); } -/** Convert transform3d objects +/** Convert delta objects * * A generic alignment transformation is defined by * - a translation in 3D space identified in XML as a @@ -134,35 +149,30 @@ template <> void Converter<pivot>::operator()(xml_h e) const { * @version 1.0 * @date 01/04/2014 */ -template <> void Converter<transform3d>::operator()(xml_h e) const { - typedef pair<bool,Transform3D> Data; +template <> void Converter<delta>::operator()(xml_h e) const { Position pos; RotationZYX rot; Translation3D piv; - xml_h child_rot, child_pos, child_piv; - Data* tr = (Data*)param; + xml_h child_rot, child_pos, child_piv; + Delta* delta = (Delta*)param; if ( (child_pos=e.child(_U(position),false)) ) - Converter<position>(lcdd,&pos)(child_pos); + Converter<position>(lcdd,&delta->translation)(child_pos); if ( (child_rot=e.child(_U(rotation),false)) ) { - Converter<rotation>(lcdd,&rot)(child_rot); + Converter<rotation>(lcdd,&delta->rotation)(child_rot); if ( (child_piv=e.child(_U(pivot),false)) ) - Converter<pivot>(lcdd,&piv)(child_piv); + Converter<pivot>(lcdd,&delta->pivot)(child_piv); } - tr->first = true; if ( child_rot && child_pos && child_piv ) - tr->second = Transform3D(Translation3D(pos)*piv*rot*(piv.Inverse())); + delta->flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT|Delta::HAVE_TRANSLATION; else if ( child_rot && child_pos ) - tr->second = Transform3D(rot,pos); + delta->flags |= Delta::HAVE_ROTATION|Delta::HAVE_TRANSLATION; else if ( child_rot && child_piv ) - tr->second = Transform3D(piv*rot*(piv.Inverse())); + delta->flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT; else if ( child_rot ) - tr->second = Transform3D(rot); + delta->flags |= Delta::HAVE_ROTATION; else if ( child_pos ) - tr->second = Transform3D(pos); - else { - tr->first = false; - } + delta->flags |= Delta::HAVE_TRANSLATION; } typedef AlignmentStack::StackEntry StackEntry; @@ -183,32 +193,32 @@ typedef AlignmentStack::StackEntry StackEntry; * @date 01/04/2014 */ template <> void Converter<volume>::operator()(xml_h e) const { - pair<bool,Transform3D> trafo; + Delta val; pair<DetElement,string>* elt = (pair<DetElement,string>*)param; - 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; + AlignmentStack* stack = _option<AlignmentStack>(); + 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 elt_place = elt->first.placementPath(); + string placement = subpath[0]=='/' ? subpath : elt_place + "/" + subpath; - printout(INFO,"Alignment<volume>"," path:%s placement:%s reset:%s children:%s", - subpath.c_str(), placementPath.c_str(), yes_no(reset), yes_no(reset_dau)); + printout(INFO,"Alignment<vol>"," path:%s placement:%s reset:%s children:%s", + subpath.c_str(), placement.c_str(), yes_no(reset), yes_no(reset_dau)); - Converter<transform3d>(lcdd,&trafo)(e); - int flags = 0; - if ( overlap ) flags |= AlignmentStack::OVERLAP_DEFINED; - if ( trafo.first ) flags |= AlignmentStack::MATRIX_DEFINED; - if ( reset ) flags |= AlignmentStack::RESET_VALUE; - if ( reset_dau ) flags |= AlignmentStack::RESET_CHILDREN; - if ( check ) flags |= AlignmentStack::CHECKOVL_DEFINED; - if ( check_val ) flags |= AlignmentStack::CHECKOVL_VALUE; + Converter<delta>(lcdd,&val)(e); + if ( val.flags ) val.flags |= AlignmentStack::MATRIX_DEFINED; + if ( overlap ) val.flags |= AlignmentStack::OVERLAP_DEFINED; + if ( reset ) val.flags |= AlignmentStack::RESET_VALUE; + if ( reset_dau ) val.flags |= AlignmentStack::RESET_CHILDREN; + if ( check ) val.flags |= AlignmentStack::CHECKOVL_DEFINED; + if ( check_val ) val.flags |= AlignmentStack::CHECKOVL_VALUE; - dd4hep_ptr<StackEntry> entry(new StackEntry(elt->first,placementPath,trafo.second,ovl,flags)); - AlignmentStack::insert(entry); + dd4hep_ptr<StackEntry> entry(new StackEntry(elt->first,placement,val,ovl)); + stack->insert(entry); pair<DetElement,string> vol_param(elt->first,subpath); xml_coll_t(e,_U(volume)).for_each(Converter<volume>(lcdd,&vol_param)); } @@ -230,7 +240,8 @@ template <> void Converter<volume>::operator()(xml_h e) const { * @date 01/04/2014 */ template <> void Converter<detelement>::operator()(xml_h e) const { - DetElement det = param ? *(DetElement*)param : DetElement(); + DetElement det(_param<DetElement::Object>()); + AlignmentStack* stack = _option<AlignmentStack>(); 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; @@ -239,39 +250,39 @@ template <> void Converter<detelement>::operator()(xml_h e) const { 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("-----"); + string placement = elt.isValid() ? elt.placementPath() : string("-----"); if ( !elt.isValid() ) { string err = "DD4hep: DetElement "+det.path()+" has no child:"+path+" [No such child]"; throw runtime_error(err); } - pair<bool,Transform3D> trafo; - Converter<transform3d>(lcdd,&trafo)(e); - int flags = 0; - if ( trafo.first ) { - flags |= AlignmentStack::MATRIX_DEFINED; + Delta val; + Converter<delta>(lcdd,&val)(e); + if ( val.flags ) { + val.flags |= AlignmentStack::MATRIX_DEFINED; reset = reset_dau = true; } - if ( overlap ) flags |= AlignmentStack::OVERLAP_DEFINED; - if ( check ) flags |= AlignmentStack::CHECKOVL_DEFINED; - if ( reset ) flags |= AlignmentStack::RESET_VALUE; - if ( reset_dau ) flags |= AlignmentStack::RESET_CHILDREN; - if ( check_val ) flags |= AlignmentStack::CHECKOVL_VALUE; + if ( overlap ) val.flags |= AlignmentStack::OVERLAP_DEFINED; + if ( check ) val.flags |= AlignmentStack::CHECKOVL_DEFINED; + if ( reset ) val.flags |= AlignmentStack::RESET_VALUE; + if ( reset_dau ) val.flags |= AlignmentStack::RESET_CHILDREN; + if ( check_val ) val.flags |= AlignmentStack::CHECKOVL_VALUE; - printout(INFO,"Alignment<detelement>","path:%s [%s] placement:%s matrix:%s reset:%s children:%s", + printout(INFO,"Alignment<det>","path:%s [%s] placement:%s matrix:%s reset:%s children:%s", path.c_str(), elt.isValid() ? elt.path().c_str() : "-----", - placementPath.c_str(), - yes_no(trafo.first), yes_no(reset), yes_no(reset_dau)); + placement.c_str(), + yes_no(val.checkFlag(AlignmentStack::MATRIX_DEFINED)), + yes_no(reset), yes_no(reset_dau)); - dd4hep_ptr<StackEntry> entry(new StackEntry(elt,placementPath,trafo.second,ovl,flags)); - AlignmentStack::insert(entry); + dd4hep_ptr<StackEntry> entry(new StackEntry(elt,placement,val,ovl)); + stack->insert(entry); pair<DetElement,string> vol_param(elt,""); - xml_coll_t(e,_U(volume)).for_each(Converter<volume>(lcdd,&vol_param)); - 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)); + xml_coll_t(e,_U(volume)).for_each(Converter<volume>(lcdd,&vol_param,optional)); + xml_coll_t(e,_ALU(detelement)).for_each(Converter<detelement>(lcdd,elt.ptr(),optional)); + xml_coll_t(e,_U(include)).for_each(Converter<include_file>(lcdd,elt.ptr(),optional)); } /** Convert detelement_include objects @@ -290,11 +301,11 @@ template <> void Converter<include_file>::operator()(xml_h element) const { xml_h node = doc.root(); string tag = node.tag(); if ( tag == "alignment" ) - Converter<alignment>(lcdd,param)(node); + Converter<alignment>(lcdd,param,optional)(node); else if ( tag == "detelement" ) - Converter<detelement>(lcdd,param)(node); + Converter<detelement>(lcdd,param,optional)(node); else if ( tag == "subdetectors" || tag == "detelements" ) - xml_coll_t(node,_ALU(detelements)).for_each(Converter<detelement>(lcdd,param)); + xml_coll_t(node,_ALU(detelements)).for_each(Converter<detelement>(lcdd,param,optional)); else throw runtime_error("Undefined tag name in XML structure:"+tag+" XML parsing abandoned."); } @@ -312,14 +323,13 @@ template <> void Converter<include_file>::operator()(xml_h element) const { * @date 01/04/2014 */ template <> void Converter<alignment>::operator()(xml_h e) const { - DetElement top = param ? *(DetElement*)param : lcdd.world(); - /// Now we process all allowed elements within the alignment tag: /// <detelement/>, <detelements/>, <subdetectors/> and <include/> - 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)); + xml_coll_t(e,_ALU(debug)).for_each(Converter<debug>(lcdd,param,optional)); + xml_coll_t(e,_ALU(detelement)).for_each(Converter<detelement>(lcdd,param,optional)); + xml_coll_t(e,_ALU(detelements)).for_each(_ALU(detelement),Converter<detelement>(lcdd,param,optional)); + xml_coll_t(e,_ALU(subdetectors)).for_each(_ALU(detelement),Converter<detelement>(lcdd,param,optional)); + xml_coll_t(e,_U(include)).for_each(Converter<include_file>(lcdd,param,optional)); } /** Basic entry point to read alignment files @@ -329,12 +339,35 @@ template <> void Converter<alignment>::operator()(xml_h e) const { * @date 01/04/2014 */ static long setup_Alignment(lcdd_t& lcdd, const xml_h& e) { - AlignmentCache::install(lcdd); - AlignmentTransaction tr(lcdd, e); - (DD4hep::Converter<DD4hep::alignment>(lcdd))(e); + static dd4hep_mutex_t s_mutex; + dd4hep_lock_t lock(s_mutex); + bool open_trans = e.hasChild(_ALU(close_transaction)); + bool close_trans = e.hasChild(_ALU(close_transaction)); + + GlobalAlignmentCache::install(lcdd); + /// Check if transaction already present. If not, open, else issue an error + if ( open_trans ) { + if ( AlignmentStack::exists() ) { + except("GlobalAlignment","Request to open a second alignment transaction stack -- not allowed!"); + } + AlignmentStack::create(); + } + AlignmentStack& stack = AlignmentStack::get(); + (DD4hep::Converter<DD4hep::alignment>(lcdd,lcdd.world().ptr(),&stack))(e); + if ( close_trans ) { + GlobalAlignmentCache* cache = lcdd.extension<Alignments::GlobalAlignmentCache>(); + cache->commit(stack); + AlignmentStack::get().release(); + } + if ( GlobalDetectorAlignment::debug() ) { + xml_elt_t elt(e); + Path uri = elt.document().uri(); + printout(INFO,"GlobalAlignment","+++ Successfully parsed XML: %s", + uri.filename().c_str()); + } return 1; } -DECLARE_XML_DOC_READER(alignment,setup_Alignment) +DECLARE_XML_DOC_READER(global_alignment,setup_Alignment) /** Basic entry point to install the alignment cache in a LCDD instance * @@ -343,7 +376,7 @@ DECLARE_XML_DOC_READER(alignment,setup_Alignment) * @date 01/04/2014 */ static long install_Alignment(lcdd_t& lcdd, int, char**) { - AlignmentCache::install(lcdd); + GlobalAlignmentCache::install(lcdd); return 1; } -DECLARE_APPLY(DD4hepAlignmentInstall,install_Alignment) +DECLARE_APPLY(DD4hep_GlobalAlignmentInstall,install_Alignment) diff --git a/DDAlign/src/plugins/AlignmentPlugins.cpp b/DDAlign/src/plugins/AlignmentPlugins.cpp index 3fefd1e623762f689b070e6e6a2082e8625a0df1..adb146a805a740634ae7d35f20f1082e4a49708e 100644 --- a/DDAlign/src/plugins/AlignmentPlugins.cpp +++ b/DDAlign/src/plugins/AlignmentPlugins.cpp @@ -39,7 +39,7 @@ namespace { DECLARE_APPLY(DD4hep_AlignmentsManagerInstaller,ddalign_install_align_mgr) // ====================================================================================== -#include "DDAlign/AlignmentWriter.h" +#include "DDAlign/GlobalAlignmentWriter.h" namespace { namespace DetectorTools = DD4hep::Geometry::DetectorTools; long create_global_alignment_file(Geometry::LCDD& lcdd, int argc, char** argv) { @@ -64,7 +64,7 @@ namespace { path.c_str(), output.c_str()); top = DetectorTools::findDaughterElement(lcdd.world(),path); if ( top.isValid() ) { - AlignmentWriter wr(lcdd); + GlobalAlignmentWriter wr(lcdd); return wr.write(wr.dump(top,enable_transactions), output); } throw std::runtime_error("AlignmentWriter: Invalid top level element name:"+path); diff --git a/DDCore/include/DD4hep/AlignmentData.h b/DDCore/include/DD4hep/AlignmentData.h index 35af9d8ac33b8a932988fd573bd5fe6f218f3206..a8e762fcea84fdc140367f4cf159374d3cc7c964 100644 --- a/DDCore/include/DD4hep/AlignmentData.h +++ b/DDCore/include/DD4hep/AlignmentData.h @@ -50,8 +50,8 @@ namespace DD4hep { class Delta { public: typedef Translation3D Pivot; - Pivot pivot; Position translation; + Pivot pivot; RotationZYX rotation; unsigned int flags; @@ -64,6 +64,21 @@ namespace DD4hep { /// Default constructor Delta() : flags(0) {} + /// Initializing constructor + Delta(const Position& tr) + : translation(tr), flags(HAVE_TRANSLATION) {} + /// Initializing constructor + Delta(const RotationZYX& rot) + : translation(), rotation(rot), flags(HAVE_ROTATION) {} + /// Initializing constructor + Delta(const Position& tr, const RotationZYX& rot) + : translation(tr), rotation(rot), flags(HAVE_ROTATION|HAVE_TRANSLATION) {} + /// Initializing constructor + Delta(const Translation3D& piv, const RotationZYX& rot) + : pivot(piv), rotation(rot), flags(HAVE_ROTATION|HAVE_PIVOT) {} + /// Initializing constructor + Delta(const Position& tr, const Translation3D& piv, const RotationZYX& rot) + : translation(tr), pivot(piv), rotation(rot), flags(HAVE_ROTATION|HAVE_PIVOT|HAVE_TRANSLATION) {} /// Copy constructor Delta(const Delta& c); /// Default destructor @@ -72,12 +87,16 @@ namespace DD4hep { Delta& operator=(const Delta& c); /// Reset information to identity void clear(); + /// Check a given flag + bool checkFlag(unsigned int mask) const { return (flags&mask) == mask; } + /// Check a given flag + void setFlag(unsigned int mask) { flags |= mask; } /// Access flags: Check if the delta operation contains a translation - bool hasTranslation() const { return (flags&HAVE_TRANSLATION) != 0; } + bool hasTranslation() const { return checkFlag(HAVE_TRANSLATION); } /// Access flags: Check if the delta operation contains a rotation - bool hasRotation() const { return (flags&HAVE_ROTATION) != 0; } + bool hasRotation() const { return checkFlag(HAVE_ROTATION); } /// Access flags: Check if the delta operation contains a pivot - bool hasPivot() const { return (flags&HAVE_PIVOT) != 0; } + bool hasPivot() const { return checkFlag(HAVE_PIVOT); } }; /// Derived condition data-object definition diff --git a/DDCore/include/DD4hep/GlobalAlignment.h b/DDCore/include/DD4hep/GlobalAlignment.h index 75cc59b909e38a2711fcafeb664e1490655e2977..95f065ca8d1f777a352ed65089667d6c01560933 100644 --- a/DDCore/include/DD4hep/GlobalAlignment.h +++ b/DDCore/include/DD4hep/GlobalAlignment.h @@ -36,7 +36,7 @@ namespace DD4hep { * \ingroup DD4HEP_GEOMETRY * \ingroup DD4HEP_ALIGN */ - class GlobalAlignment: public Handle<TGeoPhysicalNode> { + class GlobalAlignment : public Handle<TGeoPhysicalNode> { typedef Geometry::RotationZYX RotationZYX; typedef Geometry::Transform3D Transform3D; diff --git a/DDCore/include/XML/XMLElements.h b/DDCore/include/XML/XMLElements.h index 979fbd825aff63900f5d6a46843b33cbcbab056a..5bd36037c4adc2fa3a00c425fe22393e5afa7399 100644 --- a/DDCore/include/XML/XMLElements.h +++ b/DDCore/include/XML/XMLElements.h @@ -637,6 +637,8 @@ namespace DD4hep { Handle_t createElt(const XmlChar* tag) const; /// Clone a DOM element / sub-tree Handle_t clone(Handle_t source) const; + /// Acces the document URI + std::string uri() const; }; /// Class supporting the basic functionality of an XML document including ownership diff --git a/DDCore/src/AlignmentData.cpp b/DDCore/src/AlignmentData.cpp index dc7c1b28d03a2623e25396a3c4faab0dd987e5a5..6319fece5e2f46233c7fc51969187d8f3be44ac9 100644 --- a/DDCore/src/AlignmentData.cpp +++ b/DDCore/src/AlignmentData.cpp @@ -27,7 +27,7 @@ using namespace DD4hep::Alignments; /// Copy constructor Delta::Delta(const Delta& c) - : pivot(c.pivot), translation(c.translation), rotation(c.rotation), flags(c.flags) + : translation(c.translation), pivot(c.pivot), rotation(c.rotation), flags(c.flags) { } diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp index efccaf2029e6cdff4ca13a291aea5ad52adbf4f7..d2ed4bd35585044a600406b5634809597ab23de5 100644 --- a/DDCore/src/XML/XMLElements.cpp +++ b/DDCore/src/XML/XMLElements.cpp @@ -63,6 +63,7 @@ namespace { #define appendChild LinkEndChild #define getOwnerDocument GetDocument #define getDocumentElement RootElement +#define getDocumentURI Value /// Union to ease castless object access in TinyXML union Xml { @@ -1034,6 +1035,15 @@ Handle_t Document::root() const { throw runtime_error("Document::root: Invalid handle!"); } +/// Acces the document URI +std::string Document::uri() const { + if (m_doc) { + Tag_t val(_D(m_doc)->getDocumentURI()); + return val; + } + throw runtime_error("Document::uri: Invalid handle!"); +} + /// Assign new document. Old document is dropped. DocumentHolder& DocumentHolder::assign(DOC d) { if (m_doc) { diff --git a/DDCore/src/plugins/StandardPlugins.cpp b/DDCore/src/plugins/StandardPlugins.cpp index ab71e35c5dc3ce5edeb76caa9bda0807079aa8a5..ea1b822b7f2d5125b356f034381debdb1a761c8f 100644 --- a/DDCore/src/plugins/StandardPlugins.cpp +++ b/DDCore/src/plugins/StandardPlugins.cpp @@ -35,7 +35,9 @@ using namespace DD4hep; using namespace DD4hep::Geometry; static LCDDBuildType build_type(const char* value) { - if ( strcmp(value,"BUILD_DEFAULT")==0 ) + if ( !value ) + return BUILD_DEFAULT; + else if ( strcmp(value,"BUILD_DEFAULT")==0 ) return BUILD_DEFAULT; else if ( strcmp(value,"BUILD_SIMU")==0 ) return BUILD_SIMU; diff --git a/UtilityApps/src/run_plugin.h b/UtilityApps/src/run_plugin.h index c7582adab60bc0bb7e0c627a84846ce7bfb9d2c0..f276af34efda5c7726524f0eb378dbe18bb54b8b 100644 --- a/UtilityApps/src/run_plugin.h +++ b/UtilityApps/src/run_plugin.h @@ -91,8 +91,7 @@ namespace { " The lower the level, the more printout... \n" " -plugin <name> <args> Execute plugin <name> after loading geometry. \n" " All arguments following until the next '-' \n" - " are considered as arguments to the plugin. \n" - " "; + " are considered as arguments to the plugin. \n"; return cout; } @@ -138,6 +137,8 @@ namespace { } else if ( strncmp(argv[i],"-load_only",5)==0 ) dry_run = true; + else if ( strncmp(argv[i],"-dry-run",5)==0 ) + dry_run = true; else if ( strncmp(argv[i],"-print",4)==0 ) DD4hep::setPrintLevel(DD4hep::PrintLevel(print = decodePrintLevel(argv[++i]))); else if ( strncmp(argv[i],"-destroy",5)==0 ) @@ -174,20 +175,23 @@ namespace { long result; for(size_t i=0; i<plugins.size(); ++i) { std::vector<const char*>& plug=plugins[i]; - result = run_plugin(lcdd,plug[0],plug.size()-1,(char**)(plug.size()>1 ? &plug[1] : 0)); + // Remove plugin name and trailing 0x0 from args. + size_t num_args = plug.size()>2 ? plug.size()-2 : 0; + + result = run_plugin(lcdd,plug[0],plug.size()-1,(char**)(num_args>0 ? &plug[1] : 0)); if ( result == EINVAL ) { cout << "FAILED to execute DD4hep plugin: '" << plug[0] - << "' with args (" << (plug.size()-1) << ") :[ "; + << "' with args (" << num_args << ") :[ "; for(size_t j=1; j<plug.size(); ++j) { - cout << plug[j] << " "; + if ( plug[j] ) cout << plug[j] << " "; } cout << "]" << endl; usage_default(name); } cout << "Executed DD4hep plugin: '" << plug[0] - << "' with args (" << (plug.size()-1) << ") :[ "; + << "' with args (" << num_args << ") :[ "; for(size_t j=1; j<plug.size(); ++j) { - cout << plug[j] << " "; + if ( plug[j] ) cout << plug[j] << " "; } cout << "]" << endl; } diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt index b83229baa2d5221a8c30f51c4598d91c3491c218..d07c95a2631625a560db0b31743922e164e5401b 100644 --- a/examples/AlignDet/CMakeLists.txt +++ b/examples/AlignDet/CMakeLists.txt @@ -12,7 +12,7 @@ cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR) include ( ${DD4hep_DIR}/cmake/DD4hep.cmake ) -#----------------------------------------------------------------------------------- +#-------------------------------------------------------------------------- dd4hep_configure_output() dd4hep_package ( AlignDet MAJOR 0 MINOR 0 PATCH 1 USES [ROOT REQUIRED COMPONENTS Geom GenVector MathCore] @@ -24,3 +24,33 @@ dd4hep_package ( AlignDet MAJOR 0 MINOR 0 PATCH 1 dd4hep_add_plugin( AlignDet SOURCES src/*.cpp ) dd4hep_install_dir( compact DESTINATION examples/AlignDet ) dd4hep_configure_scripts( AlignDet DEFAULT_SETUP WITH_TESTS) + +# +#---Testing: Load ALEPH TPC geometry -------------------------------------- +dd4hep_add_test_reg( test_DetAlign_AlephTPC_load + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh" + EXEC_ARGS geoPluginRun + -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/AlephTPC.xml + -destroy -no-interpreter -plugin DD4hep_GlobalAlignmentInstall + REGEX_PASS "189 nodes/ 23 volume UID's in LCDD Geometry" ) +# +#---Testing: Load and misalign ALEPH TPC geometry ------------------------- +dd4hep_add_test_reg( test_DetAlign_Global_AlephTPC_align + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh" + EXEC_ARGS geoPluginRun + -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/AlephTPC.xml + -destroy -no-interpreter + -plugin DD4hep_GlobalAlignmentInstall + -plugin DD4hepXMLLoader file:${CMAKE_CURRENT_SOURCE_DIR}/compact/AlephTPC_alignment.xml BUILD_DEFAULT + REGEX_PASS "Successfully parsed XML: AlephTPC_alignment.xml") +# +#---Testing: Load and misalign ALEPH TPC geometry ------------------------- +dd4hep_add_test_reg( test_DetAlign_Global_AlephTPC_reset + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh" + EXEC_ARGS geoPluginRun + -input file:${CMAKE_CURRENT_SOURCE_DIR}/compact/AlephTPC.xml + -destroy -no-interpreter + -plugin DD4hep_GlobalAlignmentInstall + -plugin DD4hepXMLLoader file:${CMAKE_CURRENT_SOURCE_DIR}/compact/AlephTPC_alignment.xml + -plugin DD4hepXMLLoader file:${CMAKE_CURRENT_SOURCE_DIR}/compact/AlephTPC_reset.xml + REGEX_PASS "Successfully parsed XML: AlephTPC_reset.xml" ) diff --git a/examples/AlignDet/compact/AlephTPC_alignment.xml b/examples/AlignDet/compact/AlephTPC_alignment.xml index c7181f69d141adcfa21e2a5752d89c380da3f72f..d8bff42d43b75b29647d2238b4ec8b1028988503 100644 --- a/examples/AlignDet/compact/AlephTPC_alignment.xml +++ b/examples/AlignDet/compact/AlephTPC_alignment.xml @@ -1,5 +1,6 @@ -<alignment> +<global_alignment> + <debug value="true"/> <open_transaction/> <subdetectors> <!-- @@ -76,4 +77,4 @@ Any supplied pivot point in this case is ignored. </subdetectors> <close_transaction/> -</alignment> +</global_alignment> diff --git a/examples/AlignDet/compact/AlephTPC_reset.xml b/examples/AlignDet/compact/AlephTPC_reset.xml index ed5d594c07d8f9e124348a7d3cf864423f60a05b..98ea4111bb9ecad9fcf211069431cb467edbb801 100644 --- a/examples/AlignDet/compact/AlephTPC_reset.xml +++ b/examples/AlignDet/compact/AlephTPC_reset.xml @@ -1,4 +1,4 @@ -<alignment print="true"> +<global_alignment print="true"> <open_transaction/> <subdetectors> <!-- @@ -23,4 +23,4 @@ </detelement> </subdetectors> <close_transaction/> -</alignment> +</global_alignment> diff --git a/examples/Conditions/CMakeLists.txt b/examples/Conditions/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..05bad5ed3767c96f5f94de7b79c03283efe3dc27 --- /dev/null +++ b/examples/Conditions/CMakeLists.txt @@ -0,0 +1,31 @@ +# $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. +# +#========================================================================== +cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR) +include ( ${DD4hep_DIR}/cmake/DD4hep.cmake ) + +#----------------------------------------------------------------------------------- +dd4hep_configure_output () +dd4hep_package ( CLICSiD MAJOR 0 MINOR 0 PATCH 1 + USES [ROOT REQUIRED COMPONENTS Geom] + [DD4hep REQUIRED COMPONENTS DDCore] +) +dd4hep_install_dir( xml DESTINATION ${DD4hep_DIR}/examples/Conditions ) +#-------------------------------------------------------------------------- +#if (DD4HEP_USE_GEANT4) +# dd4hep_add_executable(CLICSiDXML SOURCES scripts/CLICSiDXML.C +# USES [DD4hep REQUIRED COMPONENTS DDG4] GEANT4 ) +# #-------------------------------------------------------------------------- +# dd4hep_add_executable(CLICSiDAClick SOURCES scripts/CLICSiDAClick.C +# USES [DD4hep REQUIRED COMPONENTS DDG4] GEANT4 ) +#endif() +# +dd4hep_configure_scripts ( Conditions DEFAULT_SETUP WITH_TESTS ) diff --git a/examples/Conditions/xml/Sequence_1.xml b/examples/Conditions/xml/Sequence_1.xml new file mode 100644 index 0000000000000000000000000000000000000000..d661d9afd9dac5478c2148fff2b4ca65f95557ae --- /dev/null +++ b/examples/Conditions/xml/Sequence_1.xml @@ -0,0 +1,20 @@ +<plugins> + + <plugin name="DD4hepXMLLoader"> + <arg value="file:../DD4hep.trunk/DDExamples/AlignDet/compact/AlephTPC.xml"/> + </plugin> + + <plugin name="DD4hepVolumeManager"/> + <plugin name="DD4hepConditionsManagerInstaller"/> + + <plugin name="DD4hepXMLLoader"> + <arg value="file:../DD4hep.trunk/DDExamples/AlignDet/compact/AlephTPC_alignment.xml"/> + </plugin> + <plugin name="DD4hepXMLLoader"> + <arg value="file:../DD4hep.trunk/DDExamples/AlignDet/compact/AlephTPC_reset.xml"/> + </plugin> + + <plugin name="DD4hep_Test_CallbackInstall"/> + <plugin name="DD4hep_Test_ConditionsAccess"/> + <plugin name="DD4hep_Test_ConditionsTreeDump"/> +</plugins> diff --git a/examples/Conditions/xml/Sequence_2.xml b/examples/Conditions/xml/Sequence_2.xml new file mode 100644 index 0000000000000000000000000000000000000000..e264937e8a30c44e8d24983431d01e22fba53c0f --- /dev/null +++ b/examples/Conditions/xml/Sequence_2.xml @@ -0,0 +1,12 @@ +<plugins> + + <plugin name="DD4hepXMLLoader"> + <arg value="file:../DD4hep.trunk/DDExamples/AlignDet/compact/AlephTPC.xml"/> + </plugin> + + <plugin name="DD4hepVolumeManager"/> + <plugin name="DD4hepConditionsManagerInstaller"/> + <plugin name="DD4hep_Test_CallbackInstall"/> + <plugin name="DD4hep_Test_ConditionsExample3"/> + +</plugins> diff --git a/examples/Conditions/xml/SideB_conditions.xml b/examples/Conditions/xml/SideB_conditions.xml new file mode 100644 index 0000000000000000000000000000000000000000..e6cc9e42203ec0565a7c341d55b8acbb0b9ca1fe --- /dev/null +++ b/examples/Conditions/xml/SideB_conditions.xml @@ -0,0 +1,18 @@ + +<conditions> + <detelement path="TPC/TPC_SideB" name="ambience" validity="1396887257,1396887257#epoch"> + <alignment ref="SideB_aligments.xml" validity="563543#run"/> + <temperature name="AmbientTemperature" value="20.9*kelvin"/> + <pressure name="ExternalPressure" value="980*hPa"/> + <whatever name="SomeMultiParams" validity="563543#run">[0.0, 1.0, 2.0, 3.0]</whatever> + + <detelement path="TPC_SideB_sector08" name="ambience" validity="1396887257,1396887257#epoch"> + <temperature name="AmbientTemperature" value="20.9*kelvin"/> + <pressure name="ExternalPressure" value="980*hPa"/> + </detelement> + <detelement path="TPC_SideB_sector09" name="ambience" validity="1396887257,1396887257#epoch"> + <temperature name="AmbientTemperature" value="20.9*kelvin"/> + </detelement> + + </detelement> +</conditions> diff --git a/examples/Conditions/xml/TPC.xml b/examples/Conditions/xml/TPC.xml new file mode 100644 index 0000000000000000000000000000000000000000..fd5ca8aaed0b949e2c931872bdb1a00132806c45 --- /dev/null +++ b/examples/Conditions/xml/TPC.xml @@ -0,0 +1,9 @@ +<conditions> + <detelement path="TPC" name="ambience" validity="1396887257,1396887257#epoch"> + <temperature name="AmbientTemperature" value="20.9*kelvin"/> + <pressure name="ExternalPressure" value="980*hPa"/> + <whatever name="SomeMultiParams" validity="1396887257,1396887257#epoch">[0.0, 1.0, 2.0, 3.0]</whatever> + </detelement> + + <include ref="SideB_conditions.xml"/> +</conditions> diff --git a/examples/Conditions/xml/TPC_alignment.xml b/examples/Conditions/xml/TPC_alignment.xml new file mode 100644 index 0000000000000000000000000000000000000000..c7181f69d141adcfa21e2a5752d89c380da3f72f --- /dev/null +++ b/examples/Conditions/xml/TPC_alignment.xml @@ -0,0 +1,79 @@ +<alignment> + + <open_transaction/> + <subdetectors> + <!-- + Note: The subdetector name MUST be in the list of top level + detector elements attached to the LCDD structure. + +A generic alignment transformation is defined by +- a translation in 3D space identified in XML as a +<position/> element +- a rotation in 3D space around a pivot point specified in XML by +2 elements: the <rotation/> and the <pivot/> element. +The specification of any of the elements is optional: +- The absence of a translation implies the origin (0,0,0) +- The absence of a pivot point implies the origin (0,0,0) +- The absence of a rotation implies the identity rotation. +Any supplied pivot point in this case is ignored. + +<position x="30" y="30" z="80"/> + + --> + + <detelement path="TPC" reset="true" reset_children="true"> + <comment ref="Move the entire TPC in the world volume."/> + <position x="0" y="0" z="0*mm"/> + <rotation x="0" y="0" z="0"/> + + <comment ref="Twist a bit the entire endcap A"/> + <detelement path="/world/TPC/TPC_SideA" check_overlaps="false"> + <position x="0" y="0" z="-500*mm"/> + <rotation x="-0.2" y="-0.2" z="0"/> + + <comment ref="A detector element relative to the parent"/> + <detelement path="TPC_SideA_sector02" check_overlaps="true"> + <position x="0" y="0" z="0"/> + <rotation x="0.5" y="0.1" z="0.2"/> + </detelement> + </detelement> + + <detelement path="TPC_SideA/TPC_SideA_sector03" check_overlaps="true"> + <position x="0" y="0" z="290.0*mm"/> + <rotation x="0" y="pi/2" z="0"/> + <pivot x="0" y="0" z="100"/> + <volume path="TPC_sector_K_layer2_2"> + <position x="0" y="0" z="0.0001*mm"/> + <rotation x="0" y="0.5" z="0"/> + </volume> + </detelement> + + <detelement path="TPC_SideA/TPC_SideA_sector05" check_overlaps="false"> + <position x="0" y="0" z="150.0*mm"/> + <rotation x="0" y="0" z="0"/> + </detelement> + + <detelement path="TPC_SideA/TPC_SideA_sector10" check_overlaps="false"> + <position x="0" y="0" z="450.0*mm"/> + <rotation x="0" y="0" z="pi/4"/> + </detelement> + + <comment ref="Twist a bit the entire endcap B"/> + <detelement path="TPC_SideB" check_overlaps="false"> + <position x="0" y="0" z="0"/> + <rotation x="0" y="0" z="0"/> + + <comment ref="A detector element relative to the parent"/> + <detelement path="TPC_SideB_sector02" check_overlaps="true"> + <position x="0" y="0" z="0"/> + <rotation x="0.5" y="0.1" z="0.2"/> + </detelement> + </detelement> <comment ref="end: TPC side B"/> +<!-- +--> + </detelement> <!-- end: TPC --> + + </subdetectors> + + <close_transaction/> +</alignment> diff --git a/examples/Conditions/xml/TPC_run_123456.xml b/examples/Conditions/xml/TPC_run_123456.xml new file mode 100644 index 0000000000000000000000000000000000000000..07b353a70862f437bb870f479f7ee787750b2b52 --- /dev/null +++ b/examples/Conditions/xml/TPC_run_123456.xml @@ -0,0 +1,7 @@ +<conditions> + <detelement path="TPC" name="ambience"> + <alignment ref="TPC_Alignment.xml" validity="123456#run"/> + <alignment path="TPC_SideA" ref="TPC_SideA_Alignment.xml" validity="123456#run"/> + <alignment name="TPC_A_align" ref="TPC_SideA_Alignment.xml" validity="123456#run"/> + </detelement> +</conditions> diff --git a/examples/Conditions/xml/TPC_run_234567.xml b/examples/Conditions/xml/TPC_run_234567.xml new file mode 100644 index 0000000000000000000000000000000000000000..f2579945b70f00899b073b894a666bd2cc299b1b --- /dev/null +++ b/examples/Conditions/xml/TPC_run_234567.xml @@ -0,0 +1,7 @@ +<conditions> + <detelement path="TPC" name="ambience"> + <alignment ref="TPC_Alignment.xml" validity="234567#run"/> + <alignment path="TPC_SideA" ref="TPC_SideA_Alignment.xml" validity="234567#run"/> + <alignment name="TPC_A_align" ref="TPC_SideA_Alignment.xml" validity="234567#run"/> + </detelement> +</conditions> diff --git a/examples/Conditions/xml/TPC_run_563543.xml b/examples/Conditions/xml/TPC_run_563543.xml new file mode 100644 index 0000000000000000000000000000000000000000..0a6d9cfd8f302d5eb612c0b6b970ac1eb4837544 --- /dev/null +++ b/examples/Conditions/xml/TPC_run_563543.xml @@ -0,0 +1,7 @@ +<conditions> + <detelement path="TPC" name="ambience"> + <alignment ref="TPC_Alignment.xml" validity="563543#run"/> + <alignment path="TPC_SideA" ref="TPC_SideA_Alignment.xml" validity="563543#run"/> + <alignment name="TPC_A_align" ref="TPC_SideA_Alignment.xml" validity="563543#run"/> + </detelement> +</conditions> diff --git a/examples/Conditions/xml/TPC_run_filler.xml b/examples/Conditions/xml/TPC_run_filler.xml new file mode 100644 index 0000000000000000000000000000000000000000..ed0f94b9f61a9efb3a0eb829f002196e3bd00d6b --- /dev/null +++ b/examples/Conditions/xml/TPC_run_filler.xml @@ -0,0 +1,15 @@ +<conditions> + <detelement path="TPC" name="ambience"> + <alignment ref="TPC_Alignment.xml" validity="123457,234566#run"/> + <alignment path="TPC_SideA" ref="TPC_SideA_Alignment.xml" validity="123457,234566#run"/> + <alignment name="TPC_A_align" ref="TPC_SideA_Alignment.xml" validity="123457,234566#run"/> + + <alignment ref="TPC_Alignment.xml" validity="234568,563542#run"/> + <alignment path="TPC_SideA" ref="TPC_SideA_Alignment.xml" validity="234568,563542#run"/> + <alignment name="TPC_A_align" ref="TPC_SideA_Alignment.xml" validity="234568,563542#run"/> + + <alignment ref="TPC_Alignment.xml" validity="563544,999999#run"/> + <alignment path="TPC_SideA" ref="TPC_SideA_Alignment.xml" validity="563544,999999#run"/> + <alignment name="TPC_A_align" ref="TPC_SideA_Alignment.xml" validity="563544,999999#run"/> + </detelement> +</conditions> diff --git a/examples/Conditions/xml/examples.xml b/examples/Conditions/xml/examples.xml new file mode 100644 index 0000000000000000000000000000000000000000..15d2f3087a4e5c75db67f0aa713c763bb9c185bb --- /dev/null +++ b/examples/Conditions/xml/examples.xml @@ -0,0 +1,24 @@ +<conditions> + <open_transaction/> + <detelement path="TPC" name="ambience" validity="1396887257,1396887257#epoch"> + <alignment validity="563543#run"/> + <alignment path="TPC_SideA" validity="563543#run"/> + <temperature name="AmbientTemperature" value="20.9*kelvin"/> + <pressure name="ExternalPressure" value="980*hPa"/> + <whatever name="SomeMultiParams" validity="563543#run">[0.0, 1.0, 2.0, 3.0]</whatever> + +<!-- + <gains> + <gain/> + </gains> +--> + +<!-- + <include ref=""/> +--> + </detelement> + + <include ref="SideB_conditions.xml"/> + <close_transaction/> + +</conditions> diff --git a/examples/Conditions/xml/plugins.xml b/examples/Conditions/xml/plugins.xml new file mode 100644 index 0000000000000000000000000000000000000000..ff25edf35c31d1987091b53dcd5c8d52fa3e2fb0 --- /dev/null +++ b/examples/Conditions/xml/plugins.xml @@ -0,0 +1,25 @@ +<plugins> + + <plugin name="DD4hepXMLLoader"> + <arg value="file:../DD4hep.trunk/DDExamples/AlignDet/compact/AlephTPC.xml"/> + </plugin> + + <plugin name="DD4hepVolumeManager"/> + <plugin name="DD4hepConditionsManagerInstaller"/> + + <plugin name="DD4hepXMLLoader"> + <arg value="file:../DD4hep.trunk/DDExamples/AlignDet/compact/AlephTPC_alignment.xml"/> + </plugin> + <plugin name="DD4hepXMLLoader"> + <arg value="file:../DD4hep.trunk/DDExamples/AlignDet/compact/AlephTPC_reset.xml"/> + </plugin> + + <plugin name="DD4hep_Test_CallbackInstallTest"/> + +<!-- + <plugin name="DD4hep_Test_ConditionsAccess"/> + <plugin name="DD4hep_Test_ConditionsTreeDump"/> +--> + <plugin name="DD4hepExample3"/> + +</plugins>