Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:57:59

0001 //==========================================================================
0002 //  AIDA Detector description implementation
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef DD4HEP_ALIGNMENTSCALCULATOR_H
0014 #define DD4HEP_ALIGNMENTSCALCULATOR_H
0015 
0016 // Framework include files
0017 #include <DD4hep/Alignments.h>
0018 #include <DD4hep/AlignmentData.h>
0019 #include <DD4hep/ConditionsMap.h>
0020 
0021 /// Namespace for the AIDA detector description toolkit
0022 namespace dd4hep {
0023 
0024   /// Namespace for the conditions part of the AIDA detector description toolkit
0025   namespace cond   { class ConditionUpdateContext;  }
0026   
0027   /// Namespace for the alignment part of the AIDA detector description toolkit
0028   namespace align {
0029 
0030     /// Alignment calculator instance to handle alignment dependencies
0031     /**
0032      *  \author   M.Frank
0033      *  \version  1.0
0034      *  \ingroup  DD4HEP_ALIGN
0035      */
0036     class AlignmentsCalculator  {
0037     public:
0038 
0039       /// Object encapsulating the result of a computation call to the alignments calculator
0040       /**
0041        *  \author  M.Frank
0042        *  \version 1.0
0043        *  \ingroup DD4HEP_CONDITIONS
0044        */
0045       class Result  {
0046       public:
0047         size_t computed = 0;
0048         size_t missing  = 0;
0049     size_t multiply = 0;
0050         Result() = default;
0051         /// Copy constructor
0052         Result(const Result& result) = default;
0053         /// Assignment operator
0054         Result& operator  =(const Result& result) = default;
0055         /// Add results
0056         Result& operator +=(const Result& result);
0057         /// Subtract results
0058         Result& operator -=(const Result& result);
0059         /// Summed counters
0060         size_t total() const { return computed+missing; }
0061       };
0062 
0063       /// Functor for path ordered maps as they are needed for the calculator
0064       /**
0065        *  \author  M.Frank
0066        *  \version 1.0
0067        *  \ingroup DD4HEP_CONDITIONS
0068        */
0069       class PathOrdering {
0070       public:
0071         bool operator()(const DetElement& a, const DetElement& b) const
0072         { return a.path() < b.path(); }
0073       };
0074 
0075       typedef std::map<DetElement,const Delta*,PathOrdering> OrderedDeltas;
0076       typedef std::map<Condition::key_type,DetElement>       ExtractContext;
0077 
0078       /// Scanner to find all alignment deltas in the detector hierarchy
0079       /**
0080        *  The deltas are collected in the appropriate container suited for the
0081        *  calculator object, so that no re-ordering is necessary.
0082        *  
0083        *  Usage:
0084        *
0085        *  /// Interface to client Callback in order to update the condition
0086        *  Condition AlignmentCall::operator()(const ConditionKey& key,
0087        *                                      ConditionUpdateContext& ctxt)  {
0088        *  ....
0089        *   DetectorScanner().scan(AlignmentsCalculator::Scanner(ctxt,deltas),top);
0090        *  ....
0091        *  }
0092        *
0093        *  \author  M.Frank
0094        *  \version 1.0
0095        *  \ingroup DD4HEP_CONDITIONS
0096        */
0097       class Scanner  {
0098       public:
0099         /// Reference to the user pool taking into account IOV intersections
0100         cond::ConditionUpdateContext& context;
0101         /// Collection container
0102         OrderedDeltas&                deltas;
0103         /// Resulting IOV
0104         IOV*                          iov = 0;
0105       public:
0106         /// Default constructor
0107         Scanner() = delete;
0108         /// Initializing constructor
0109         Scanner(cond::ConditionUpdateContext& m, OrderedDeltas& d) : context(m), deltas(d) {}
0110         /// Initializing constructor with IOV specification
0111         Scanner(cond::ConditionUpdateContext& m, OrderedDeltas& d, IOV* i) : context(m), deltas(d), iov(i) {}
0112         /// Default move constructor is disabled
0113         Scanner(cond::ConditionUpdateContext& m, OrderedDeltas&& p) = delete;
0114         /// R-value copy from a temporary
0115         Scanner(Scanner&& copy) = delete;
0116         /// Copy constructor
0117         Scanner(const Scanner& copy) = delete;
0118         /// Default destructor
0119         ~Scanner() = default;
0120         /// Assignment operator
0121         Scanner& operator=(Scanner&& copy) = delete;
0122         /// Assignment operator
0123         Scanner& operator=(const Scanner& copy) = delete;
0124         /// Callback to output alignments information
0125         int operator()(DetElement de, int)  const;
0126       };
0127 
0128     public:
0129 
0130       /// Default constructor
0131       AlignmentsCalculator() = default;
0132       /// Copy constructor
0133       AlignmentsCalculator(const AlignmentsCalculator& copy) = delete;
0134       /// Assignment operator
0135       AlignmentsCalculator& operator=(const AlignmentsCalculator& mgr) = delete;
0136       /// Compute all alignment conditions of the internal dependency list
0137       Result compute(const std::map<DetElement, Delta>& deltas,
0138                      ConditionsMap& alignments)  const;
0139       /// Compute all alignment conditions of the internal dependency list
0140       Result compute(const std::map<DetElement, const Delta*>& deltas,
0141                      ConditionsMap& alignments)  const;
0142       /// Optimized call using already properly ordered Deltas
0143       Result compute(const OrderedDeltas& deltas, ConditionsMap& alignments)  const;
0144 
0145       /// Helper: Extract all Delta-conditions from the conditions map
0146       size_t extract_deltas(cond::ConditionUpdateContext& context,
0147                             OrderedDeltas& deltas,
0148                             IOV* effective_iov=0)   const;
0149       /// Helper: Extract all Delta-conditions from the conditions map starting at a certain sub-tree
0150       size_t extract_deltas(DetElement start,
0151                             cond::ConditionUpdateContext& ctxt,
0152                             OrderedDeltas& deltas,
0153                             IOV* effective_iov=0)   const;
0154       /// Helper: Extract all Delta-conditions from the conditions map
0155       /** If the extraction context is empty, it shall be filled.
0156        *  On every subsequent call the existing context is used and 
0157        *  the Delta-conditions are extracted directly using a linear scan 
0158        *  of the conditions map. Depending on the size of the conditons map
0159        *  this can lead to significant speed improvements.
0160        */
0161       size_t extract_deltas(cond::ConditionUpdateContext& context,
0162                             ExtractContext& extract_context,
0163                             OrderedDeltas& deltas,
0164                             IOV* effective_iov=0)   const;
0165 
0166       /// Helper: Extract all Delta-conditions from the conditions map starting at a certain sub-tree
0167       /**
0168        *  Please note: An extract_context is only valid for one sub-tree.
0169        */
0170       size_t extract_deltas(DetElement start,
0171                             cond::ConditionUpdateContext& ctxt,
0172                             ExtractContext& extract_context,
0173                             OrderedDeltas& deltas,
0174                             IOV* effective_iov=0)   const;
0175     };
0176 
0177     /// Add results
0178     inline AlignmentsCalculator::Result&
0179     AlignmentsCalculator::Result::operator +=(const Result& result)  {
0180       multiply += result.multiply;
0181       computed += result.computed;
0182       missing  += result.missing;
0183       return *this;
0184     }
0185     /// Subtract results
0186     inline AlignmentsCalculator::Result&
0187     AlignmentsCalculator::Result::operator -=(const Result& result)  {
0188       multiply -= result.multiply;
0189       computed -= result.computed;
0190       missing  -= result.missing;
0191       return *this;
0192     }
0193 
0194   }       /* End namespace align                  */
0195 }         /* End namespace dd4hep                      */
0196 #endif // DD4HEP_ALIGNMENTSCALCULATOR_H