Newer
Older
Markus Frank
committed
// $Id: run_plugin.h 1663 2015-03-20 13:54:53Z gaede $
//==========================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------------
// Copyright (C) Organisation européenne pour la Recherche nucléaire (CERN)
// 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/Printout.h"
#include "DD4hep/InstanceCount.h"
#include "DDCond/ConditionsStack.h"
#include "DD4hep/objects/ConditionsInterna.h"
using namespace std;
using namespace DD4hep;
using namespace DD4hep::Geometry;
Markus Frank
committed
static dd4hep_ptr<ConditionsStack>& _stack() {
static dd4hep_ptr<ConditionsStack> s;
Markus Frank
committed
static dd4hep_ptr<ConditionsStack>& _stack(ConditionsStack* obj) {
dd4hep_ptr<ConditionsStack>& s = _stack();
s = dd4hep_ptr<ConditionsStack>(obj);
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
return s;
}
/// Standard constructor
ConditionsStack::ConditionsStack() {
InstanceCount::increment(this);
}
/// Standard destructor
ConditionsStack::~ConditionsStack() {
destroyObjects(m_stack)();
InstanceCount::decrement(this);
}
/// Static client accessor
ConditionsStack& ConditionsStack::get() {
if ( _stack().get() ) return *_stack();
throw runtime_error("ConditionsStack> Stack not allocated -- may not be retrieved!");
}
/// Create an conditions stack instance. The creation of a second instance will be refused.
void ConditionsStack::create() {
if ( _stack().get() ) {
throw runtime_error("ConditionsStack> Stack already allocated. Multiple copies are not allowed!");
}
_stack(new ConditionsStack());
}
/// Check existence of conditions stack
bool ConditionsStack::exists() {
return _stack().get() != 0;
}
/// Clear data content and remove the slignment stack
void ConditionsStack::release() {
if ( _stack().get() ) {
_stack(0);
return;
}
throw runtime_error("ConditionsStack> Attempt to delete non existing stack.");
}
/// Retrieve an conditions entry of the current stack
Markus Frank
committed
dd4hep_ptr<ConditionsStack::Entry> ConditionsStack::pop() {
Stack::iterator i = m_stack.begin();
if ( i != m_stack.end() ) {
Entry* e = (*i).second;
m_stack.erase(i);
Markus Frank
committed
return dd4hep_ptr<Entry>(e);
}
throw runtime_error("ConditionsStack> pop: Conditions stack is empty. Check size first!");
}
/// Get all pathes to be aligned
vector<const ConditionsStack::Entry*> ConditionsStack::entries() const {
vector<const Entry*> 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;
}
/// Push new entry into the stack
Markus Frank
committed
void ConditionsStack::insert(dd4hep_ptr<Entry>& data) {
if ( data.get() && !data->name.empty() ) {
DetElement det = data->detector;
// Need to make some checks BEFORE insertion
if ( !det.isValid() ) {
throw runtime_error("ConditionsStack> Invalid conditions data [No such detector]");
}
string path = det.path()+'!'+data->name;
Stack::const_iterator i = m_stack.find(path);
printout(DEBUG,"ConditionsStack","+++ %s name:%s type:%s value:%s Validity:%s",
Markus Frank
committed
det.path().c_str(), data->name.c_str(), data->type.c_str(),
data->value.c_str(), data->validity.c_str());
if ( i == m_stack.end() ) {
m_stack.insert(make_pair(path,data.release()));
return;
}
throw runtime_error("ConditionsStack> The data with path "+path+
Markus Frank
committed
" cannot be set twice in one transaction. [Intended inhibit]");
}
throw runtime_error("ConditionsStack> Attempt to apply an invalid conditions data.");
}