DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AlignmentStack.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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/LCDD.h"
16 #include "DD4hep/Objects.h"
17 #include "DD4hep/Printout.h"
18 #include "DD4hep/InstanceCount.h"
19 #include "DDAlign/AlignmentStack.h"
20 
21 using namespace std;
22 using namespace DD4hep;
23 using namespace DD4hep::Alignments;
24 
27  return s;
28 }
31  s.adopt(obj);
32  return s;
33 }
34 
36 AlignmentStack::StackEntry::StackEntry(DetElement element, const std::string& p, const Delta& del, double ov)
37  : detector(element), delta(del), path(p), overlap(ov)
38 {
40 }
41 
44  : detector(e.detector), delta(e.delta), path(e.path), overlap(e.overlap)
45 {
47 }
48 
52 }
53 
56  if ( this != &e ) {
57  detector = e.detector;
58  delta = e.delta;
59  overlap = e.overlap;
60  path = e.path;
61  }
62  return *this;
63 }
64 
67  new_value ? (delta.flags |= RESET_VALUE) : (delta.flags &= ~RESET_VALUE);
68  return *this;
69 }
70 
71 
74  new_value ? (delta.flags |= RESET_CHILDREN) : (delta.flags &= ~RESET_CHILDREN);
75  return *this;
76 }
77 
78 
81  new_value ? (delta.flags |= CHECKOVL_DEFINED) : (delta.flags &= ~CHECKOVL_DEFINED);
82  return *this;
83 }
84 
85 
88  delta.flags |= CHECKOVL_DEFINED;
89  delta.flags |= CHECKOVL_VALUE;
90  overlap = precision;
91  return *this;
92 }
93 
96 {
98 }
99 
104 }
105 
108  if ( _stack().get() ) return *_stack();
109  throw runtime_error("AlignmentStack> Stack not allocated -- may not be retrieved!");
110 }
111 
114  if ( _stack().get() ) {
115  throw runtime_error("AlignmentStack> Stack already allocated. Multiple copies are not allowed!");
116  }
117  _stack(new AlignmentStack());
118 }
119 
122  return _stack().get() != 0;
123 }
124 
127  if ( _stack().get() ) {
128  _stack(0);
129  return;
130  }
131  throw runtime_error("AlignmentStack> Attempt to delete non existing stack.");
132 }
133 
135 bool AlignmentStack::insert(const string& full_path, dd4hep_ptr<StackEntry>& entry) {
136  if ( entry.get() && !full_path.empty() ) {
137  entry->path = full_path;
138  return add(entry);
139  }
140  throw runtime_error("AlignmentStack> Attempt to apply an invalid alignment entry.");
141 }
142 
145  return add(entry);
146 }
147 
150  if ( entry.get() && !entry->path.empty() ) {
151  Stack::const_iterator i = m_stack.find(entry->path);
152  if ( i == m_stack.end() ) {
153 
154  // Need to make some checks BEFORE insertion
155  if ( !entry->detector.isValid() ) {
156  throw runtime_error("AlignmentStack> Invalid alignment entry [No such detector]");
157  }
158  printout(INFO,"AlignmentStack","Add node:%s",entry->path.c_str());
159  m_stack.insert(make_pair(entry->path,entry.get()));
160  entry.release();
161  return true;
162  }
163  throw runtime_error("AlignmentStack> The entry with path "+entry->path+
164  " cannot be re-aligned twice in one transaction.");
165  }
166  throw runtime_error("AlignmentStack> Attempt to apply an invalid alignment entry.");
167 }
168 
171  Stack::iterator i = m_stack.begin();
172  if ( i != m_stack.end() ) {
173  dd4hep_ptr<StackEntry> e((*i).second);
174  m_stack.erase(i);
175  return e;
176  }
177  throw runtime_error("AlignmentStack> Alignment stack is empty. "
178  "Cannot pop entries - check size first!");
179 }
180 
182 vector<const AlignmentStack::StackEntry*> AlignmentStack::entries() const {
183  vector<const StackEntry*> result;
184  result.reserve(m_stack.size());
185  for(Stack::const_iterator i=m_stack.begin(); i != m_stack.end(); ++i)
186  result.push_back((*i).second);
187  return result;
188 }
189 
StackEntry & operator=(const StackEntry &e)
Assignment operator.
dd4hep_ptr & adopt(T *ptr)
Assignment operator.
Definition: Memory.h:74
virtual ~StackEntry()
Default destructor.
bool add(dd4hep_ptr< StackEntry > &new_entry)
Add a new entry to the cache. The key is the placement path.
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.
static void decrement(T *)
Decrement count according to type information.
DetElement detector
Reference to the detector element.
virtual ~AlignmentStack()
Default destructor. Careful with this one:
Delta delta
Delta transformation to be applied.
TGeoShape * s
Definition: Volumes.cpp:294
Out version of the std auto_ptr implementation base either on auto_ptr or unique_ptr.
Definition: Memory.h:43
return e
Definition: Volumes.cpp:297
double overlap
Parameter for overlap checking.
void release()
Clear data content and remove the slignment stack.
DD4hep::Geometry::DetElement DetElement
static bool exists()
Check existence of alignment stack.
void destroyObjects(M &m)
Definition: Primitives.h:293
StackEntry & setReset(bool new_value=true)
Set flag to reset the entry to it's ideal geometrical position.
Class describing an condition to re-adjust an alignment.
Definition: AlignmentData.h:49
std::string path
Path to the misaligned volume.
static AlignmentStack & get()
Static client accessor.
static dd4hep_ptr< AlignmentStack > & _stack()
StackEntry & setOverlapPrecision(double precision=0.001)
Set the precision for the overlap check (otherwise the default is 0.001 cm)
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Stack m_stack
The subdetector specific map of alignments caches.
StackEntry & setOverlapCheck(bool new_value=true)
Set flag to check overlaps.
std::vector< const StackEntry * > entries() const
Get all path entries to be aligned. Note: transient!
StackEntry & setResetChildren(bool new_value=true)
Set flag to reset the entry's children to their ideal geometrical position.
StackEntry(DetElement p, const std::string &placement, const Delta &t, double ov)
Fully initializing constructor.
Stack entry definition.
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
static void create()
Create an alignment stack instance. The creation of a second instance will be refused.
AlignmentStack()
Default constructor.
Alignment Stack object definition.
dd4hep_ptr< StackEntry > pop()
Retrieve an alignment entry of the current stack.