Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:55

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 
0014 // Framework include files
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/DetectorProcessor.h>
0017 #include <DD4hep/AlignmentsNominalMap.h>
0018 #include <DD4hep/detail/AlignmentsInterna.h>
0019 #include <DD4hep/detail/ConditionsInterna.h>
0020 
0021 using namespace dd4hep;
0022 using align::Keys;
0023 
0024 /// Standard constructor
0025 AlignmentsNominalMap::AlignmentsNominalMap(DetElement wrld) : world(wrld) {
0026 }
0027 
0028 /// Insert a new entry to the map
0029 bool AlignmentsNominalMap::insert(DetElement              detector,
0030                                   Condition::itemkey_type key,
0031                                   Condition               condition)   {
0032   auto res = data.emplace(ConditionKey(detector,key).hash,condition);
0033   return res.second;
0034 }
0035 
0036 /// Interface to access conditions by hash value
0037 Condition AlignmentsNominalMap::get(DetElement detector, Condition::itemkey_type key) const   {
0038   auto res = data.find(ConditionKey(detector,key).hash);
0039   if ( res == data.end() )  {
0040     if ( key == Keys::alignmentKey )  {
0041       return Condition(detector.nominal().ptr());
0042     }
0043     return Condition();
0044   }
0045   return res->second;
0046 }
0047 
0048 /// Interface to scan data content of the conditions mapping
0049 void AlignmentsNominalMap::scan(const Condition::Processor& processor) const  {
0050 
0051   /// Helper to implement partial scans.
0052   /*
0053    *  \author  M.Frank
0054    *  \version 1.0
0055    *  \ingroup DD4HEP_CONDITIONS
0056    */
0057   struct Scanner  {
0058     const Condition::Processor& proc;
0059     /// Constructor
0060     Scanner(const Condition::Processor& p) : proc(p)  { }
0061     /// Conditions callback for object processing
0062     int operator()(DetElement de, int /* level */)  const  {
0063       Condition c = de.nominal();
0064       return proc(c);
0065     }
0066   } scanner(processor);
0067 
0068   // First scan the local conditions
0069   for( const auto& i : data )
0070     processor(i);
0071 
0072   // We emulate here a full detector scan, access the nominal alignments and process them by the processor.
0073   if ( world.isValid() )   {
0074     DetectorScanner().scan(scanner,world,0,true);
0075     return;
0076   }
0077   dd4hep::except("AlignmentsNominalMap",
0078                  "Cannot scan conditions map for conditions of an invalid top level detector element!");
0079 }
0080 
0081 /// Interface to partially scan data content of the conditions mapping
0082 void AlignmentsNominalMap::scan(DetElement   detector,
0083                                 Condition::itemkey_type lower,
0084                                 Condition::itemkey_type upper,
0085                                 const Condition::Processor&   processor) const   {
0086 
0087   if ( detector.isValid() )   {
0088     Condition::detkey_type det_key = detector.key();
0089     Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
0090     Condition::key_type up  = ConditionKey::KeyMaker(det_key,upper).hash;
0091     ConditionKey::KeyMaker align_key(detector.key(),Keys::alignmentKey);
0092 
0093     for(auto i=data.lower_bound(low); i != data.end() && (*i).first <= up; ++i)  {
0094       ConditionKey::KeyMaker k((*i).first);
0095       if ( low <= k.hash && up >= k.hash )   {
0096         processor((*i).second);
0097         if ( k.hash == align_key.hash )   {
0098           align_key.hash = 0;
0099         }
0100       }
0101     }
0102     if ( align_key.hash )  {
0103       if ( lower <= Keys::alignmentKey && upper >= Keys::alignmentKey )   {
0104         Condition c(detector.nominal().ptr());
0105         processor(c);
0106       }
0107     }
0108     return;
0109   }
0110   dd4hep::except("AlignmentsNominalMap",
0111                  "Cannot scan conditions map for conditions of an invalid detector element!");
0112 }