Newer
Older
Markus Frank
committed
//==========================================================================
// AIDA Detector description implementation for LCD
Markus Frank
committed
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
Markus Frank
committed
// All rights reserved.
Markus Frank
committed
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
Markus Frank
committed
// Author : M.Frank
//
//==========================================================================
// Framework include files
#include "DD4hep/LCDD.h"
#include "DD4hep/Objects.h"
#include "DD4hep/Printout.h"
#include "DD4hep/InstanceCount.h"
#include "DDAlign/GlobalAlignmentStack.h"
using namespace std;
using namespace DD4hep;
using namespace DD4hep::Alignments;
static dd4hep_ptr<GlobalAlignmentStack>& _stack() {
static dd4hep_ptr<GlobalAlignmentStack> s;
static dd4hep_ptr<GlobalAlignmentStack>& _stack(GlobalAlignmentStack* obj) {
dd4hep_ptr<GlobalAlignmentStack>& s = _stack();
/// Constructor with partial initialization
GlobalAlignmentStack::StackEntry::StackEntry(DetElement element, const std::string& p, const Delta& del, double ov)
: detector(element), delta(del), path(p), overlap(ov)
}
/// Copy constructor
GlobalAlignmentStack::StackEntry::StackEntry(const StackEntry& e)
: detector(e.detector), delta(e.delta), path(e.path), overlap(e.overlap)
InstanceCount::increment(this);
}
/// Default destructor
GlobalAlignmentStack::StackEntry::~StackEntry() {
InstanceCount::decrement(this);
}
/// Set flag to reset the entry to it's ideal geometrical position
GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setReset(bool new_value) {
new_value ? (delta.flags |= RESET_VALUE) : (delta.flags &= ~RESET_VALUE);
return *this;
}
/// Set flag to reset the entry's children to their ideal geometrical position
GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setResetChildren(bool new_value) {
new_value ? (delta.flags |= RESET_CHILDREN) : (delta.flags &= ~RESET_CHILDREN);
return *this;
}
/// Set flag to check overlaps
GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setOverlapCheck(bool new_value) {
new_value ? (delta.flags |= CHECKOVL_DEFINED) : (delta.flags &= ~CHECKOVL_DEFINED);
return *this;
}
/// Set the precision for the overlap check (otherwise the default is 0.001 cm)
GlobalAlignmentStack::StackEntry& GlobalAlignmentStack::StackEntry::setOverlapPrecision(double precision) {
delta.flags |= CHECKOVL_DEFINED;
delta.flags |= CHECKOVL_VALUE;
overlap = precision;
return *this;
}
GlobalAlignmentStack::GlobalAlignmentStack()
}
/// Default destructor
GlobalAlignmentStack::~GlobalAlignmentStack() {
}
/// Static client accessor
GlobalAlignmentStack& GlobalAlignmentStack::get() {
if ( _stack().get() ) return *_stack();
throw runtime_error("GlobalAlignmentStack> Stack not allocated -- may not be retrieved!");
}
/// Create an alignment stack instance. The creation of a second instance will be refused.
throw runtime_error("GlobalAlignmentStack> Stack already allocated. Multiple copies are not allowed!");
}
/// Check existence of alignment stack
}
/// Clear data content and remove the slignment stack
if ( _stack().get() ) {
_stack(0);
throw runtime_error("GlobalAlignmentStack> Attempt to delete non existing stack.");
}
/// Add a new entry to the cache. The key is the placement path
bool GlobalAlignmentStack::insert(const string& full_path, dd4hep_ptr<StackEntry>& entry) {
if ( entry.get() && !full_path.empty() ) {
throw runtime_error("GlobalAlignmentStack> Attempt to apply an invalid alignment entry.");
}
/// Add a new entry to the cache. The key is the placement path
bool GlobalAlignmentStack::insert(dd4hep_ptr<StackEntry>& entry) {
}
/// Add a new entry to the cache. The key is the placement path
bool GlobalAlignmentStack::add(dd4hep_ptr<StackEntry>& entry) {
if ( entry.get() && !entry->path.empty() ) {
Stack::const_iterator i = m_stack.find(entry->path);
if ( i == m_stack.end() ) {
StackEntry* e = entry.get();
// Need to make some checks BEFORE insertion
if ( !e->detector.isValid() ) {
throw runtime_error("GlobalAlignmentStack> Invalid alignment entry [No such detector]");
printout(INFO,"GlobalAlignmentStack","Add node:%s",e->path.c_str());
m_stack.insert(make_pair(e->path,entry.release()));
throw runtime_error("GlobalAlignmentStack> The entry with path "+entry->path+
Markus Frank
committed
" cannot be re-aligned twice in one transaction.");
throw runtime_error("GlobalAlignmentStack> Attempt to apply an invalid alignment entry.");
}
/// Retrieve an alignment entry of the current stack
dd4hep_ptr<GlobalAlignmentStack::StackEntry> GlobalAlignmentStack::pop() {
Stack::iterator i = m_stack.begin();
if ( i != m_stack.end() ) {
dd4hep_ptr<StackEntry> e((*i).second);
throw runtime_error("GlobalAlignmentStack> Alignment stack is empty. "
Markus Frank
committed
"Cannot pop entries - check size first!");
}
/// Get all pathes to be aligned
vector<const GlobalAlignmentStack::StackEntry*> GlobalAlignmentStack::entries() const {
vector<const StackEntry*> result;
result.reserve(m_stack.size());
for(Stack::const_iterator i=m_stack.begin(); i != m_stack.end(); ++i)
result.push_back((*i).second);
return result;
}