DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
AlignmentsCalib.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 includes
16 
17 #include <DD4hep/Memory.h>
18 #include <DD4hep/Printout.h>
19 #include <DD4hep/DetectorTools.h>
21 
22 using namespace dd4hep::align;
23 
25 
33 public:
39  int dirty = 0;
40  Entry() = default;
41  Entry(const Entry& c) = delete;
42  Entry& operator=(const Entry& c) = delete;
43 };
44 
47  : description(det), slice(cond_map)
48 {
49 }
50 
53  clear();
54 }
55 
57 dd4hep::DetElement AlignmentsCalib::detector(const std::string& path) const {
59  return det;
60 }
61 
63 std::pair<dd4hep::Condition::key_type,AlignmentsCalib::Entry*>
66  UsedConditions::iterator i = used.find(tar_key.hash);
67  if ( i != used.end() ) {
68  (*i).second->delta = delta;
69  return (*i);
70  }
71 
73  if ( !src_cond.isValid() ) {
74  // Try to create a new condition and register it to the
75  // conditions manager from the delta value.
78  src_cond.bind<Delta>();
80  src_cond->hash = key.hash;
81  if ( !slice.insert(detector, Keys::deltaKey, src_cond) ) {
82  detail::destroyHandle(src_cond);
83  }
85  if ( !src_cond.isValid() ) {
86  except("AlignmentsCalib",
87  "++ The SOURCE alignment condition [%016llX]: %s#%s is invalid.",
88  key.hash, detector.path().c_str(), Keys::deltaName.c_str());
89  }
90  }
91  // Add the entry the usual way. This should also check everything again.
92  dd4hep_ptr<Entry> entry(new Entry());
93  entry->original = src_cond.get<Delta>();
94  entry->delta = delta;
95  entry->detector = detector;
96  entry->source = src_cond;
97  entry->target = tar_key.hash;
98  entry->dirty = 1;
99  return *(used.emplace(tar_key,entry.release()).first);
100 }
101 
105  return _set(det.access(), delta).first;
106 }
107 
110 AlignmentsCalib::set(const std::string& path, const Delta& delta) {
111  return _set(detector(path).access(), delta).first;
112 }
113 
116  if ( !used.empty() ) {
117  for ( auto& e : used ) {
118  e.second->delta.clear();
119  e.second->dirty = 0;
120  }
121  }
122 }
123 
125 void AlignmentsCalib::clear() noexcept(false) {
126  for(auto& e : used) {
127  e.second->source.get<Delta>() = e.second->delta;
128  detail::deletePtr(e.second);
129  }
130  used.clear();
131 }
132 
135  std::map<DetElement, Delta> deltas;
136  AlignmentsCalculator calculator;
137 
139  for ( auto& entry : used ) {
140  Entry* e = entry.second;
141  if ( e->dirty ) {
143  deltas[e->detector] = e->delta;
144  e->source.get<Delta>() = e->delta;
145  e->dirty = 0;
146  }
147  }
148  return calculator.compute(deltas, slice);
149 }
dd4hep::DetElement::path
const std::string & path() const
Path of the detector element (not necessarily identical to placement path!)
Definition: DetElement.cpp:158
dd4hep::align::AlignmentsCalib::Entry::Entry
Entry(const Entry &c)=delete
dd4hep::DetElement::key
unsigned int key() const
Access hash key of this detector element (Only valid once geometry is closed!)
Definition: DetElement.cpp:134
dd4hep::detail::destroyHandle
void destroyHandle(T &handle)
Helper to delete objects from heap and reset the handle.
Definition: Handle.h:185
dd4hep::align::AlignmentsCalib::Entry::source
dd4hep::Condition source
Definition: AlignmentsCalib.cpp:36
dd4hep::align::AlignmentsCalib::set
Condition::key_type set(DetElement det, const Delta &delta)
(1) Add a new entry to an existing DetElement structure.
Definition: AlignmentsCalib.cpp:104
dd4hep::align::AlignmentsCalib::Entry::Entry
Entry()=default
dd4hep::align::AlignmentsCalib::clearDeltas
void clearDeltas()
Clear all delta data in the caches transaction stack.
Definition: AlignmentsCalib.cpp:115
dd4hep::ConditionKey::hash
Condition::key_type hash
Hashed key representation.
Definition: Conditions.h:287
Entry
GlobalAlignmentStack::StackEntry Entry
Definition: GlobalAlignmentCache.cpp:25
delta
const Delta * delta
Definition: AlignmentsCalculator.cpp:67
dd4hep::align::AlignmentsCalib::Entry::operator=
Entry & operator=(const Entry &c)=delete
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::ConditionsMap::insert
virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition)=0
Insert a new entry to the map. The detector element key and the item key make a unique global conditi...
dd4hep::ConditionKey
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:280
dd4hep::align::AlignmentsCalib::Entry::target
dd4hep::Condition::key_type target
Definition: AlignmentsCalib.cpp:38
dd4hep::align::AlignmentsCalib::used
UsedConditions used
Internal work stack of cached deltas.
Definition: AlignmentsCalib.h:61
dd4hep::Delta
Class describing an condition to re-adjust an alignment.
Definition: AlignmentData.h:38
dd4hep::align::AlignmentsCalib::detector
DetElement detector(const std::string &path) const
Convenience only: Access detector element by path.
Definition: AlignmentsCalib.cpp:57
dd4hep::detail::tools::findElement
DetElement findElement(const Detector &description, const std::string &path)
Find DetElement as child of the top level volume by its absolute path.
Definition: DetectorTools.cpp:214
dd4hep::align::AlignmentsCalib::Entry
Helper class to store information about alignment calibration items.
Definition: AlignmentsCalib.cpp:32
dd4hep::Condition
Main condition object handle.
Definition: Conditions.h:51
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::Condition::ALIGNMENT_DELTA
@ ALIGNMENT_DELTA
Definition: Conditions.h:86
dd4hep::align::AlignmentsCalib::slice
ConditionsMap & slice
Reference to the alignment manager object.
Definition: AlignmentsCalib.h:59
dd4hep::align::Keys::alignmentKey
static const Condition::itemkey_type alignmentKey
Key value of an alignment condition object "alignment".
Definition: Alignments.h:56
dd4hep::align::AlignmentsCalib::description
Detector & description
Reference to the detector description object.
Definition: AlignmentsCalib.h:57
dd4hep::align::Keys::deltaKey
static const Condition::itemkey_type deltaKey
Key value of a delta condition "alignment_delta".
Definition: Alignments.h:52
dd4hep::align::Keys::deltaName
static const std::string deltaName
Key name of a delta condition "alignment_delta".
Definition: Alignments.h:50
dd4hep::align::AlignmentsCalib::_set
std::pair< Condition::key_type, Entry * > _set(DetElement det, const Delta &delta)
Implementation: Add a new entry to the transaction stack.
Definition: AlignmentsCalib.cpp:64
DetectorTools.h
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::align::AlignmentsCalib::Entry::delta
dd4hep::Delta delta
Definition: AlignmentsCalib.cpp:34
dd4hep::align::AlignmentsCalculator::Result
Object encapsulating the result of a computation call to the alignments calculator.
Definition: AlignmentsCalculator.h:45
dd4hep::align::AlignmentsCalib::Entry::dirty
int dirty
Definition: AlignmentsCalib.cpp:39
dd4hep::Condition::bind
T & bind()
Bind the data of the conditions object to a given format.
Definition: Conditions.h:250
dd4hep::align::AlignmentsCalib::Entry::detector
dd4hep::DetElement detector
Definition: AlignmentsCalib.cpp:37
dd4hep::Condition::get
T & get()
Generic getter. Specify the exact type, not a polymorph type.
Definition: Conditions.h:258
dd4hep::align::AlignmentsCalib::clear
void clear() noexcept(false)
We clear the entire cached stack of used entries.
Definition: AlignmentsCalib.cpp:125
AlignmentsCalib.h
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
Memory.h
dd4hep::Condition::setFlag
void setFlag(mask_type option)
Flag operations: Set a conditons flag.
Definition: Conditions.cpp:191
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::align::AlignmentsCalib::~AlignmentsCalib
virtual ~AlignmentsCalib() noexcept(false)
Default destructor.
Definition: AlignmentsCalib.cpp:52
det
DetElement::Object * det
Definition: AlignmentsCalculator.cpp:66
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::align::AlignmentsCalib::commit
AlignmentsCalculator::Result commit()
Commit all pending transactions. Returns number of altered entries.
Definition: AlignmentsCalib.cpp:134
dd4hep::align::AlignmentsCalib::Entry::original
dd4hep::Delta original
Definition: AlignmentsCalib.cpp:35
AlignmentsInterna.h
dd4hep::align::AlignmentsCalculator::compute
Result compute(const std::map< DetElement, Delta > &deltas, ConditionsMap &alignments) const
Compute all alignment conditions of the internal dependency list.
Definition: AlignmentsCalculator.cpp:218
dd4hep::align::AlignmentsCalib::AlignmentsCalib
AlignmentsCalib()=delete
No default constructor.
Printout.h
dd4hep::ConditionsMap
ConditionsMap class.
Definition: ConditionsMap.h:59
dd4hep::align
Namespace for implementation details of the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:31
dd4hep::align::AlignmentsCalculator
Alignment calculator instance to handle alignment dependencies.
Definition: AlignmentsCalculator.h:36
dd4hep::dd4hep_ptr
Out version of the std auto_ptr implementation base either on auto_ptr or unique_ptr.
Definition: Memory.h:46