DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
GlobalAlignmentStack.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/Detector.h>
16 #include <DD4hep/Objects.h>
17 #include <DD4hep/Printout.h>
18 #include <DD4hep/InstanceCount.h>
20 
21 using namespace dd4hep::align;
22 
25  return s;
26 }
29  stk.adopt(obj);
30  return stk;
31 }
32 
34 GlobalAlignmentStack::StackEntry::StackEntry(DetElement element, const std::string& p, const Delta& del, double ov)
35  : detector(element), delta(del), path(p), overlap(ov)
36 {
38 }
39 
42  : detector(e.detector), delta(e.delta), path(e.path), overlap(e.overlap)
43 {
45 }
46 
50 }
51 #if 0
52 GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setReset(bool new_value) {
54  new_value ? (delta.flags |= RESET_VALUE) : (delta.flags &= ~RESET_VALUE);
55  return *this;
56 }
57 
58 
60 GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setResetChildren(bool new_value) {
61  new_value ? (delta.flags |= RESET_CHILDREN) : (delta.flags &= ~RESET_CHILDREN);
62  return *this;
63 }
64 
65 
67 GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setOverlapCheck(bool new_value) {
68  new_value ? (delta.flags |= CHECKOVL_DEFINED) : (delta.flags &= ~CHECKOVL_DEFINED);
69  return *this;
70 }
71 
72 
74 GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setOverlapPrecision(double precision) {
75  delta.flags |= CHECKOVL_DEFINED;
76  delta.flags |= CHECKOVL_VALUE;
77  overlap = precision;
78  return *this;
79 }
80 #endif
81 
84 {
86 }
87 
90  detail::destroyObjects(m_stack);
92 }
93 
96  if ( _stack().get() ) return *_stack();
97  except("GlobalAlignmentStack", "Stack not allocated -- may not be retrieved!");
98  throw std::runtime_error("Stack not allocated");
99 }
100 
103  if ( _stack().get() ) {
104  except("GlobalAlignmentStack", "Stack already allocated. Multiple copies are not allowed!");
105  }
106  _stack(new GlobalAlignmentStack());
107 }
108 
111  return _stack().get() != 0;
112 }
113 
116  if ( _stack().get() ) {
117  _stack(0);
118  return;
119  }
120  except("GlobalAlignmentStack", "Attempt to delete non existing stack.");
121 }
122 
124 bool GlobalAlignmentStack::insert(const std::string& full_path, dd4hep_ptr<StackEntry>& entry) {
125  if ( entry.get() && !full_path.empty() ) {
126  entry->path = full_path;
127  return add(entry);
128  }
129  except("GlobalAlignmentStack", "Attempt to apply an invalid alignment entry.");
130  return false;
131 }
132 
135  return add(entry);
136 }
137 
140  if ( entry.get() && !entry->path.empty() ) {
141  Stack::const_iterator i = m_stack.find(entry->path);
142  if ( i == m_stack.end() ) {
143  StackEntry* e = entry.get();
144  // Need to make some checks BEFORE insertion
145  if ( !e->detector.isValid() ) {
146  except("GlobalAlignmentStack", "Invalid alignment entry [No such detector]");
147  }
148  printout(INFO,"GlobalAlignmentStack","Add node:%s",e->path.c_str());
149  m_stack.emplace(e->path,entry.release());
150  return true;
151  }
152  except("GlobalAlignmentStack", "The entry with path "+entry->path+
153  " cannot be re-aligned twice in one transaction.");
154  }
155  except("GlobalAlignmentStack", "Attempt to apply an invalid alignment entry.");
156  return false;
157 }
158 
161  Stack::iterator i = m_stack.begin();
162  if ( i != m_stack.end() ) {
163  dd4hep_ptr<StackEntry> e((*i).second);
164  m_stack.erase(i);
165  return e;
166  }
167  except("GlobalAlignmentStack", "Alignment stack is empty. "
168  "Cannot pop entries - check size first!");
169  return {};
170 }
171 
173 std::vector<const GlobalAlignmentStack::StackEntry*> GlobalAlignmentStack::entries() const {
174  std::vector<const StackEntry*> result;
175  result.reserve(m_stack.size());
176  transform(begin(m_stack),end(m_stack),back_inserter(result),detail::select2nd(m_stack));
177  return result;
178 }
179 
dd4hep::align::GlobalAlignmentStack::get
static GlobalAlignmentStack & get()
Static client accessor.
Definition: GlobalAlignmentStack.cpp:95
dd4hep::align::GlobalAlignmentStack::StackEntry::detector
DetElement detector
Reference to the detector element.
Definition: GlobalAlignmentStack.h:55
Objects.h
dd4hep::align::GlobalAlignmentStack::CHECKOVL_DEFINED
@ CHECKOVL_DEFINED
Definition: GlobalAlignmentStack.h:39
dd4hep::align::GlobalAlignmentStack
Alignment Stack object definition.
Definition: GlobalAlignmentStack.h:34
dd4hep::align::GlobalAlignmentStack::GlobalAlignmentStack
GlobalAlignmentStack()
Default constructor.
Definition: GlobalAlignmentStack.cpp:83
Detector.h
dd4hep::align::GlobalAlignmentStack::create
static void create()
Create an alignment stack instance. The creation of a second instance will be refused.
Definition: GlobalAlignmentStack.cpp:102
delta
const Delta * delta
Definition: AlignmentsCalculator.cpp:67
dd4hep::align::GlobalAlignmentStack::insert
bool insert(const std::string &full_path, dd4hep_ptr< StackEntry > &new_entry)
Add a new entry to the cache. The key is the placement path.
Definition: GlobalAlignmentStack.cpp:124
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::dd4hep_ptr::adopt
dd4hep_ptr & adopt(T *ptr)
Assignment operator.
Definition: Memory.h:64
dd4hep::Delta
Class describing an condition to re-adjust an alignment.
Definition: AlignmentData.h:38
dd4hep::align::GlobalAlignmentStack::StackEntry::StackEntry
StackEntry()=delete
Default constructor.
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::align::GlobalAlignmentStack::CHECKOVL_VALUE
@ CHECKOVL_VALUE
Definition: GlobalAlignmentStack.h:40
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::align::GlobalAlignmentStack::entries
std::vector< const StackEntry * > entries() const
Get all path entries to be aligned. Note: transient!
Definition: GlobalAlignmentStack.cpp:173
dd4hep::align::GlobalAlignmentStack::RESET_CHILDREN
@ RESET_CHILDREN
Definition: GlobalAlignmentStack.h:42
dd4hep::align::GlobalAlignmentStack::StackEntry::~StackEntry
virtual ~StackEntry()
Default destructor.
Definition: GlobalAlignmentStack.cpp:48
GlobalAlignmentStack.h
dd4hep::align::GlobalAlignmentStack::pop
dd4hep_ptr< StackEntry > pop()
Retrieve an alignment entry of the current stack.
Definition: GlobalAlignmentStack.cpp:160
dd4hep::align::GlobalAlignmentStack::RESET_VALUE
@ RESET_VALUE
Definition: GlobalAlignmentStack.h:41
dd4hep::align::GlobalAlignmentStack::m_stack
Stack m_stack
The subdetector specific map of alignments caches.
Definition: GlobalAlignmentStack.h:104
dd4hep::align::GlobalAlignmentStack::StackEntry::path
std::string path
Path to the misaligned volume.
Definition: GlobalAlignmentStack.h:59
dd4hep::align::GlobalAlignmentStack::add
bool add(dd4hep_ptr< StackEntry > &new_entry)
Add a new entry to the cache. The key is the placement path.
Definition: GlobalAlignmentStack.cpp:139
dd4hep::align::GlobalAlignmentStack::~GlobalAlignmentStack
virtual ~GlobalAlignmentStack()
Default destructor. Careful with this one:
Definition: GlobalAlignmentStack.cpp:89
InstanceCount.h
dd4hep::align::GlobalAlignmentStack::exists
static bool exists()
Check existence of alignment stack.
Definition: GlobalAlignmentStack.cpp:110
dd4hep::align::GlobalAlignmentStack::StackEntry
Stack entry definition.
Definition: GlobalAlignmentStack.h:52
Printout.h
dd4hep::align::GlobalAlignmentStack::release
void release()
Clear data content and remove the slignment stack.
Definition: GlobalAlignmentStack.cpp:115
dd4hep::align
Namespace for implementation details of the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:31
dd4hep::dd4hep_ptr
Out version of the std auto_ptr implementation base either on auto_ptr or unique_ptr.
Definition: Memory.h:46