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
Conditions.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 includes
15 #include "DD4hep/Handle.inl"
16 #include "DD4hep/Printout.h"
18 
19 // C/C++ include files
20 #include <climits>
21 #include <iomanip>
22 
23 using namespace std;
24 using namespace DD4hep::Conditions;
25 
27 Condition::Processor::Processor() {
28 }
29 
32  Condition::Object* p = c.ptr();
33  if ( p ) return ConditionKey(p->name,p->hash);
34  invalidHandleError<Condition>();
35  return ConditionKey();
36 }
37 
39 ConditionKey::ConditionKey(const string& value)
40  : name(value), hash(hashCode(value))
41 {
42 }
43 
45 ConditionKey& ConditionKey::operator=(const string& value) {
46  ConditionKey key(value);
47  hash = hashCode(value);
48  name = value;
49  return *this;
50 }
51 
53 bool ConditionKey::operator<(const string& compare) const {
54  return hash < hashCode(compare);
55 }
56 
58 Condition::Condition(const string& nam,const string& typ) : Handle<Object>() {
59  Object* o = new Object();
60  assign(o,nam,typ);
61  o->hash = ConditionKey::hashCode(nam);
62 }
63 
65 string Condition::str(int flags) const {
66  stringstream output;
67  Object* o = access();
68  const IOV* ptr_iov = o->iovData();
69  if ( 0 == (flags&NO_NAME) )
70  output << setw(16) << left << o->name;
71  if ( flags&WITH_IOV )
72  output << " " << (ptr_iov ? ptr_iov->str().c_str() : "IOV:[UNKNOWN]");
73  if ( flags&WITH_TYPE )
74  output << " (" << o->type << ")";
75  if ( flags&WITH_ADDRESS )
76  output << " " << o->address;
77  if ( flags&WITH_DATATYPE )
78  output << " -> " << o->data.dataType();
79  if ( flags&WITH_DATA )
80  output << " Data:" << o->data.str();
81  if ( flags&WITH_COMMENT )
82  output << " \"" << o->comment << "\"";
83  return output.str();
84 }
85 
87 int Condition::dataType() const {
88  return access()->data.type;
89 }
90 
93  return access()->data;
94 }
95 
98  return *(access()->iovType());
99 }
100 
102 const DD4hep::IOV& Condition::iov() const {
103  return *(access()->iovData());
104 }
105 
107 const string& Condition::type() const {
108  return access()->type;
109 }
110 
112 const string& Condition::value() const {
113  return access()->value;
114 }
115 
117 const string& Condition::comment() const {
118  return access()->comment;
119 }
120 
122 const string& Condition::address() const {
123  return access()->address;
124 }
125 
127 const type_info& Condition::typeInfo() const {
128  return descriptor().type();
129 }
130 
133  return access()->hash;
134 }
135 
138  const BasicGrammar* g = access()->data.grammar;
139  if ( !g ) {
140  invalidHandleError<Condition>();
141  // This code is never reached, since function above throws exception!
142  // Needed to satisfay CppCheck
143  throw runtime_error("Null pointer in Grammar object");
144  }
145  return *g;
146 }
147 
150  Object* o = access();
151 #if 0
152  const IOV* i = o->iov;
153  const IOVType* t = i->iovType;
154  i->fromString(o->validity);
155  if ( t != i->iovType ) {
156  except("Condition","Rebinding condition with different IOV types [%d <> %d] is not allowed!",
157  t ? t->type : -1, i->iovType ? i->iovType->type : -1);
158  }
159 #endif
160  o->data.fromString(o->value);
161  printout(INFO,"Condition","+++ condition:%s rebinding value:%s",
162  name(), o->value.c_str());
163  return *this;
164 }
165 
168 }
169 
171 size_t Container::numKeys() const {
172  Object* o = ptr();
173  if ( !o ) {
174  invalidHandleError<Container>();
175  }
176  return o->keys.size();
177 }
178 
181  Object* o = ptr();
182  if ( !o ) {
183  invalidHandleError<Container>();
184  }
185  return o->keys;
186 }
187 
189 Condition Container::get(const string& condition_key, const iov_type& iov) {
190  Object* o = ptr();
191  if ( o ) {
192  Condition c = o->get(condition_key, iov);
193  if ( c.isValid() ) {
194  return c;
195  }
196  invalidHandleError<Condition>();
197  }
198  invalidHandleError<Container>();
199  return Condition();
200 }
201 
203 Condition Container::get(key_type condition_key, const iov_type& iov) {
204  Object* o = ptr();
205  if ( o ) {
206  Condition c = o->get(condition_key, iov);
207  if ( c.isValid() ) {
208  return c;
209  }
210  invalidHandleError<Condition>();
211  }
212  invalidHandleError<Container>();
213  return Condition();
214 }
215 
217 Condition Container::get(const string& condition_key, const UserPool& pool) {
218  Object* o = ptr();
219  if ( o ) {
220  Condition c = o->get(condition_key, pool);
221  if ( c.isValid() ) {
222  return c;
223  }
224  invalidHandleError<Condition>();
225  }
226  invalidHandleError<Container>();
227  return Condition();
228 }
229 
231 Condition Container::get(key_type condition_key, const UserPool& pool) {
232  Object* o = ptr();
233  if ( o ) {
234  Condition c = o->get(condition_key, pool);
235  if ( c.isValid() ) {
236  return c;
237  }
238  invalidHandleError<Condition>();
239  }
240  invalidHandleError<Container>();
241  return Condition();
242 }
std::string validity
Condition validity (in string form)
ConditionKey & operator=(const std::string &value)
Assignment operator from the string representation.
Definition: Conditions.cpp:45
bool operator<(const ConditionKey &compare) const
Operator less (for map insertions) using key object.
Definition: Conditions.h:348
OpaqueData & data() const
Access the IOV block.
Definition: Conditions.cpp:92
virtual const std::type_info & type() const =0
Access to the type information.
const char * name() const
Access the object name (or "" if not supported by the object)
Condition & rebind()
Re-evaluate the conditions data according to the previous bound type definition.
Definition: Conditions.cpp:149
Interface for conditions pool optimized to host conditions updates.
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
The data class behind a conditions container handle.
const IOVType * iovType() const
Access safely the IOV-type.
const std::string & value() const
Access the value field of the condition as a string.
Definition: Conditions.cpp:112
The data class behind a conditions handle.
Base class describing string evaluation to C++ objects using boost::spirit.
Definition: BasicGrammar.h:37
Class describing an opaque data block.
Definition: OpaqueData.h:36
const std::string & address() const
Access the address string [e.g. database identifier].
Definition: Conditions.cpp:122
std::map< key_type, key_value > Keys
Definition of the keys.
Definition: Conditions.h:234
Main condition object handle.
Definition: Conditions.h:70
Condition::key_type key_type
Forward definition of the key type.
Definition: Conditions.h:228
unsigned int key_type
Forward definition of the key type.
Definition: Conditions.h:75
Condition get(const std::string &condition_key, const iov_type &iov)
Access to condition objects by key and IOV.
Definition: Conditions.cpp:189
int except(const std::string &src, const std::string &fmt,...)
Calls the display action with ERROR and throws an std::runtime_error exception.
Definition: Printout.cpp:217
const IOVType * iovType
Definition: IOV.h:69
Condition get(const std::string &condition_key, const iov_type &iov)
Access to condition objects by key and IOV.
T * ptr() const
Access to the held object.
Definition: Handle.h:149
std::string str(int with_data=WITH_IOV|WITH_ADDRESS|WITH_DATATYPE) const
Output method.
Definition: Conditions.cpp:65
int dataType() const
Access the data type.
Definition: Conditions.cpp:87
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:273
const Keys & keys() const
Known keys of conditions in this container.
Definition: Conditions.cpp:180
Class describing the interval of validty.
Definition: IOV.h:59
std::string str() const
Create string representation of the data block.
Definition: OpaqueData.cpp:58
std::string name
The object name.
Definition: NamedObject.h:34
const std::type_info & typeInfo() const
Access to the type information.
Definition: Conditions.cpp:127
Class describing the interval of validty type.
Definition: IOV.h:33
Condition()=default
Default constructor.
const IOVType & iovType() const
Access the IOV type.
Definition: Conditions.cpp:97
Interna::ConditionObject Object
Standard object type.
Definition: Conditions.h:73
unsigned int type
integer identifier ised internally
Definition: IOV.h:37
void assign(Implementation *n, const std::string &nam, const std::string &title)
Assign a new named object. Note: object references must be managed by the user.
Interna::ConditionObject * access() const
Checked object access. Throws invalid handle runtime exception.
unsigned int hash(unsigned int initialSeed, unsigned int eventNumber, unsigned int runNumber)
calculate hash from initialSeed, eventID and runID
const iov_type * iovData() const
Access safely the IOV.
key_type key() const
Hash identifier.
Definition: Conditions.cpp:132
static const double g
Definition: DD4hepUnits.h:162
const iov_type & iov() const
Access the IOV block.
Definition: Conditions.cpp:102
bool fromString(const std::string &rep)
Create data block from string representation.
Definition: OpaqueData.cpp:50
const std::string & comment() const
Access the comment field of the condition.
Definition: Conditions.cpp:117
std::string name
String representation of the key object.
Definition: Conditions.h:279
const std::string & dataType() const
Access type name of the condition data block.
Definition: OpaqueData.cpp:74
Keys keys
Known keys of conditions in this container.
std::string type
The object type.
Definition: NamedObject.h:36
const std::string & type() const
Access the type field of the condition.
Definition: Conditions.cpp:107
static key_type hashCode(const char *value)
Hash code generation from input string.
Definition: Conditions.h:323
const iov_type * iov
Interval of validity.
std::string value
Condition value (in string form)
const BasicGrammar & descriptor() const
Access to the grammar type.
Definition: Conditions.cpp:137
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:87
key_type hash
Hashed key representation.
Definition: Conditions.h:281
ConditionKey make_key(Condition c)
Access the key of the condition.
Definition: Conditions.cpp:31
const BasicGrammar * grammar
Data type.
Definition: OpaqueData.h:50
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
size_t numKeys() const
Access the number of conditons keys available for this detector element.
Definition: Conditions.cpp:171
key_type hash
Hash value of the name.
unsigned int type
Data buffer type: Must be a bitmap!
Definition: OpaqueData.h:99
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:126