DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
AlignmentNominalMap.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Printout.h>
20 
21 using namespace dd4hep;
22 using align::Keys;
23 
26 }
27 
31  Condition condition) {
32  auto res = data.emplace(ConditionKey(detector,key).hash,condition);
33  return res.second;
34 }
35 
38  auto res = data.find(ConditionKey(detector,key).hash);
39  if ( res == data.end() ) {
40  if ( key == Keys::alignmentKey ) {
41  return Condition(detector.nominal().ptr());
42  }
43  return Condition();
44  }
45  return res->second;
46 }
47 
49 void AlignmentsNominalMap::scan(const Condition::Processor& processor) const {
50 
52  /*
53  * \author M.Frank
54  * \version 1.0
55  * \ingroup DD4HEP_CONDITIONS
56  */
57  struct Scanner {
58  const Condition::Processor& proc;
60  Scanner(const Condition::Processor& p) : proc(p) { }
62  int operator()(DetElement de, int /* level */) const {
63  Condition c = de.nominal();
64  return proc(c);
65  }
66  } scanner(processor);
67 
68  // First scan the local conditions
69  for( const auto& i : data )
70  processor(i);
71 
72  // We emulate here a full detector scan, access the nominal alignments and process them by the processor.
73  if ( world.isValid() ) {
74  DetectorScanner().scan(scanner,world,0,true);
75  return;
76  }
77  dd4hep::except("AlignmentsNominalMap",
78  "Cannot scan conditions map for conditions of an invalid top level detector element!");
79 }
80 
85  const Condition::Processor& processor) const {
86 
87  if ( detector.isValid() ) {
88  Condition::detkey_type det_key = detector.key();
89  Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
91  ConditionKey::KeyMaker align_key(detector.key(),Keys::alignmentKey);
92 
93  for(auto i=data.lower_bound(low); i != data.end() && (*i).first <= up; ++i) {
94  ConditionKey::KeyMaker k((*i).first);
95  if ( low <= k.hash && up >= k.hash ) {
96  processor((*i).second);
97  if ( k.hash == align_key.hash ) {
98  align_key.hash = 0;
99  }
100  }
101  }
102  if ( align_key.hash ) {
103  if ( lower <= Keys::alignmentKey && upper >= Keys::alignmentKey ) {
104  Condition c(detector.nominal().ptr());
105  processor(c);
106  }
107  }
108  return;
109  }
110  dd4hep::except("AlignmentsNominalMap",
111  "Cannot scan conditions map for conditions of an invalid detector element!");
112 }
dd4hep::DetectorScanner
Helper to run DetElement scans.
Definition: DetectorProcessor.h:173
DetectorProcessor.h
dd4hep::AlignmentsNominalMap::scan
virtual void scan(const Condition::Processor &processor) const override
Interface to scan data content of the alignments mapping.
Definition: AlignmentNominalMap.cpp:49
dd4hep::DetElement::key
unsigned int key() const
Access hash key of this detector element (Only valid once geometry is closed!)
Definition: DetElement.cpp:134
ConditionsInterna.h
dd4hep::AlignmentsNominalMap::get
virtual Condition get(DetElement detector, Condition::itemkey_type key) const override
Interface to access alignments by hash value. The detector element key and the item key make a unique...
Definition: AlignmentNominalMap.cpp:37
AlignmentsNominalMap.h
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::align::Keys
Alignment and Delta item key.
Definition: Alignments.h:47
dd4hep::ConditionKey
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:280
dd4hep::ConditionKey::KeyMaker
Helper union to interprete conditions keys.
Definition: Conditions.h:295
dd4hep::AlignmentsNominalMap::world
DetElement world
Reference to the top detector element.
Definition: AlignmentsNominalMap.h:47
dd4hep::Condition::detkey_type
unsigned int detkey_type
High part of the key identifies the detector element.
Definition: Conditions.h:56
dd4hep::Condition
Main condition object handle.
Definition: Conditions.h:51
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::DetectorScanner::scan
int scan(Q &p, DetElement start, int level=0, bool recursive=true) const
Detector element tree scanner using wrapped DetectorProcessor objects.
Definition: DetectorProcessor.h:194
dd4hep::DetElement::nominal
Alignment nominal() const
Access to the constant ideal (nominal) alignment information.
Definition: DetElement.cpp:185
dd4hep::Condition::itemkey_type
unsigned int itemkey_type
Low part of the key identifies the item identifier.
Definition: Conditions.h:58
dd4hep::AlignmentsNominalMap::insert
virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition) override
Insert a new entry to the map. The detector element key and the item key make a unique global alignme...
Definition: AlignmentNominalMap.cpp:29
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::ConditionKey::KeyMaker::hash
Condition::key_type hash
Definition: Conditions.h:296
dd4hep::sim::hash
unsigned int hash(unsigned int initialSeed, unsigned int eventNumber, unsigned int runNumber)
calculate hash from initialSeed, eventID and runID
Definition: Geant4EventSeed.h:201
dd4hep::AlignmentsNominalMap::data
std::map< Condition::key_type, Condition > data
Potential cache of real conditions.
Definition: AlignmentsNominalMap.h:49
AlignmentsInterna.h
dd4hep::Condition::Processor
Abstract base for processing callbacks to conditions objects.
Definition: Conditions.h:112
dd4hep::AlignmentsNominalMap::AlignmentsNominalMap
AlignmentsNominalMap(DetElement wrld)
Standard constructor.
Definition: AlignmentNominalMap.cpp:25
Printout.h