DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsMap.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>
16 #include <DD4hep/ConditionsMap.h>
18 
19 using namespace dd4hep;
20 
25  const Condition::Processor& processor) const
26 {
28  /*
29  * \author M.Frank
30  * \version 1.0
31  * \ingroup DD4HEP_CONDITIONS
32  */
33  struct Scanner : public Condition::Processor {
34  Condition::key_type lower, upper;
35  const Condition::Processor& processor;
38  : lower(low), upper(up), processor(p) {}
40  virtual int process(Condition c) const override {
41  Condition::key_type h = c->hash;
42  if ( h >= lower && h <= upper )
43  return processor(c);
44  return 0;
45  }
46  };
47  if ( detector.isValid() ) {
48  Condition::detkey_type det_key = detector.key();
49  Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
51  Scanner scn(low,up,processor);
52  this->scan(scn);
53  return;
54  }
55  dd4hep::except("ConditionsMap","Cannot scan conditions map for conditions of an invalid detector element!");
56 }
57 
59 std::vector<Condition> ConditionsMap::get(DetElement detector,
61  Condition::itemkey_type upper) const {
63  /*
64  * \author M.Frank
65  * \version 1.0
66  * \ingroup DD4HEP_CONDITIONS
67  */
68  struct Scanner : public Condition::Processor {
69  Condition::key_type lower, upper;
70  std::vector<Condition>& result;
72  Scanner(Condition::key_type low, Condition::key_type up, std::vector<Condition>& r) : lower(low), upper(up), result(r) {}
74  virtual int process(Condition c) const override {
75  Condition::key_type h = c->hash;
76  if ( h >= lower && h <= upper ) {
77  result.emplace_back(c);
78  return 1;
79  }
80  return 0;
81  }
82  };
83  std::vector<Condition> result;
84  if ( detector.isValid() ) {
85  Condition::detkey_type det_key = detector.key();
86  Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
88  Scanner scn(low,up,result);
89  this->scan(scn);
90  return result;
91  }
92  dd4hep::except("ConditionsMap","Cannot scan conditions map for conditions of an invalid detector element!");
93  return result;
94 }
95 
97 template <typename T>
99  auto res = data.emplace(ConditionKey(detector,key).hash,condition);
100  return res.second;
101 }
102 
104 template <typename T>
106  auto res = data.find(ConditionKey(detector,key).hash);
107  return (res == data.end()) ? Condition() : res->second;
108 }
109 
111 template <typename T>
112 void ConditionsMapping<T>::scan(const Condition::Processor& processor) const {
113  for( const auto& i : data )
114  processor(i);
115 }
116 
118 template <typename T>
122  const Condition::Processor& processor) const {
123  if ( detector.isValid() ) {
124  Condition::detkey_type det_key = detector.key();
125  Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
126  Condition::key_type up = ConditionKey::KeyMaker(det_key,upper).hash;
127  typename T::const_iterator first = data.lower_bound(low);
128  for(; first != data.end() && (*first).first <= up; ++first )
129  processor((*first).second);
130  return;
131  }
132  dd4hep::except("ConditionsMap","Cannot scan conditions map for conditions of an invalid detector element!");
133 }
134 
135 
137 namespace dd4hep {
138 
140  template <>
142  ::insert(DetElement detector, Condition::itemkey_type key, Condition condition) {
143  data.emplace(ConditionKey(detector,key).hash,condition);
144  return true;
145  }
146 
148  template <>
150  ::scan(DetElement detector, Condition::itemkey_type lower,
152  const Condition::Processor& proc) const
153  {
154  this->ConditionsMap::scan(detector, lower, upper, proc);
155  }
156 
157 
161 } /* End namespace dd4hep */
dd4hep::ConditionsMapping
Concrete ConditionsMap implementation class using externally defined containers.
Definition: ConditionsMap.h:125
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::ConditionsMap::scan
virtual void scan(const Condition::Processor &processor) const =0
Interface to scan data content of the conditions mapping.
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
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::ConditionsMapping::insert
virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition) override
Insert a new entry to the map.
Definition: ConditionsMap.cpp:98
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::ConditionsMapping::scan
virtual void scan(const Condition::Processor &processor) const override
Interface to scan data content of the conditions mapping.
Definition: ConditionsMap.cpp:112
dd4hep::ConditionsMap::get
virtual Condition get(DetElement detector, Condition::itemkey_type key) const =0
Interface to access conditions by hash value. The detector element key and the item key make a unique...
dd4hep::Condition::itemkey_type
unsigned int itemkey_type
Low part of the key identifies the item identifier.
Definition: Conditions.h:58
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
ConditionsMap.h
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
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::Condition::Processor
Abstract base for processing callbacks to conditions objects.
Definition: Conditions.h:112
Printout.h
dd4hep::ConditionsMapping::get
virtual Condition get(DetElement detector, Condition::itemkey_type key) const override
Interface to access conditions by hash value.
Definition: ConditionsMap.cpp:105