29 using namespace DD4hep;
31 #if defined(DD4HEP_HAVE_ALL_PARSERS)
32 const char* _char() {
return 0; }
33 const unsigned char* _uchar() {
return 0; }
34 const short* _short() {
return 0; }
35 const unsigned short* _ushort() {
return 0; }
36 const unsigned int* _uint() {
return 0; }
37 const unsigned long* _ulong() {
return 0; }
39 const int* _int() {
return 0; }
40 const long* _long() {
return 0; }
41 const float* _float() {
return 0; }
42 const double* _double() {
return 0; }
43 const std::string* _string() {
return 0; }
46 template <
typename T,
typename Q>
bool __bind__(
const ValueBinder&,
T&
object,
const string& val,
const Q*)
47 {
object.template bind<Q>(val);
return true; }
50 template <
typename T,
typename Q>
bool __bind__(
const VectorBinder&,
T&
object,
const string& val,
const Q*)
51 {
object.template bind<vector<Q> >(val);
return true; }
54 template <
typename T,
typename Q>
bool __bind__(
const ListBinder&,
T&
object,
const string& val,
const Q*)
55 {
object.template bind<list<Q> >(val);
return true; }
58 template <
typename T,
typename Q>
bool __bind__(
const SetBinder&,
T&
object,
const string& val,
const Q*)
59 {
object.template bind<set<Q> >(val);
return true; }
62 template <
typename T,
typename Q>
bool __bind__(
const MapBinder&,
T&
object,
const Q*)
63 {
object.template bind<Q>();
return true; }
71 template <
typename BINDER,
typename T>
72 bool OpaqueDataBinder::bind(
const BINDER& b,
T&
object,
const string& typ,
const string& val) {
73 #if defined(DD4HEP_HAVE_ALL_PARSERS)
74 if ( typ.substr(0,4) ==
"char" )
75 return __bind__(b,
object,val,_char());
76 else if ( typ.substr(0,13) ==
"unsigned char" )
77 return __bind__(b,
object,val,_uchar());
78 else if ( typ.substr(0,5) ==
"short" )
79 return __bind__(b,
object,val,_short());
80 else if ( typ.substr(0,14) ==
"unsigned short" )
81 return __bind__(b,
object,val,_ushort());
82 else if ( typ.substr(0,12) ==
"unsigned int" )
83 return __bind__(b,
object,val,_uint());
84 else if ( typ.substr(0,13) ==
"unsigned long" )
85 return __bind__(b,
object,val,_ulong());
88 if ( typ.substr(0,4) ==
"char" )
89 return __bind__(b,
object,val,_int());
90 else if ( typ.substr(0,5) ==
"short" )
91 return __bind__(b,
object,val,_int());
93 else if ( typ.substr(0,3) ==
"int" )
94 return __bind__(b,
object,val,_int());
95 else if ( typ.substr(0,4) ==
"long" )
96 return __bind__(b,
object,val,_long());
97 else if ( typ.substr(0,5) ==
"float" )
98 return __bind__(b,
object,val,_float());
99 else if ( typ.substr(0,6) ==
"double" )
100 return __bind__(b,
object,val,_double());
101 else if ( typ.substr(0,6) ==
"string" )
102 return __bind__(b,
object,val,_string());
103 else if ( typ ==
"std::string" )
104 return __bind__(b,
object,val,_string());
105 else if ( typ ==
"Histo1D" )
106 return __bind__(b,
object,val,_string());
107 else if ( typ ==
"Histo2D" )
108 return __bind__(b,
object,val,_string());
110 printout(
INFO,
"OpaqueDataBinder",
"++ Unknown conditions parameter type:%s val:%s",typ.c_str(),val.c_str());
111 return __bind__(b,
object,val,_string());
114 const string& typ,
const string& val);
116 const string& typ,
const string& val);
118 const string& typ,
const string& val);
120 const string& typ,
const string& val);
123 const string& typ,
const string& val);
125 const string& typ,
const string& val);
127 const string& typ,
const string& val);
129 const string& typ,
const string& val);
132 template <
typename T>
133 bool OpaqueDataBinder::bind_sequence(
T&
object,
const string& typ,
const string& val)
135 size_t idx = typ.find(
'[');
136 size_t idq = typ.find(
']');
137 string value_type = typ.substr(idx+1,idq-idx-1);
138 if ( typ.substr(0,6) ==
"vector" )
140 else if ( typ.substr(0,6) ==
"list" )
141 return bind(
ListBinder(), object, value_type, val);
142 else if ( typ.substr(0,6) ==
"set" )
143 return bind(
SetBinder(), object, value_type, val);
144 else if ( idx == string::npos && idq == string::npos )
145 return bind(
ValueBinder(),
object, value_type, val);
149 template<
typename BINDER,
typename OBJECT,
typename KEY,
typename VAL>
156 typedef map<KEY,VAL> map_t;
157 map_t&
m =
object.template get<map_t>();
159 if ( !BasicGrammar::instance<VAL>().fromString(&v, val) ) {
160 except(
"OpaqueDataBinder",
"++ Failed to convert conditions map entry.");
162 m.insert(make_pair(k,v));
165 template<
typename BINDER,
typename OBJECT,
typename KEY>
168 const string& key_val,
169 const string& val_type,
174 BasicGrammar::instance<KEY>().fromString(&key, key_val);
176 if ( val_type.substr(0,4) ==
"char" )
178 else if ( val_type.substr(0,5) ==
"short" )
180 else if ( val_type.substr(0,3) ==
"int" )
182 else if ( val_type.substr(0,4) ==
"long" )
184 else if ( val_type.substr(0,5) ==
"float" )
186 else if ( val_type.substr(0,6) ==
"double" )
188 else if ( val_type.substr(0,6) ==
"string" )
190 else if ( val_type ==
"std::string" )
193 printout(
INFO,
"Param",
"++ Unknown conditions parameter type:%s data:%s",
194 val_type.c_str(),val.c_str());
199 template<
typename BINDER,
typename OBJECT,
typename KEY,
typename VAL>
206 typedef map<KEY,VAL> map_t;
208 map_t&
m =
object.template get<map_t>();
209 if ( !BasicGrammar::instance<pair<KEY,VAL> >().fromString(&entry,data) ) {
210 except(
"OpaqueDataBinder",
"++ Failed to convert conditions map entry.");
215 template<
typename BINDER,
typename OBJECT,
typename KEY>
218 const string& val_type,
219 const string& pair_data,
223 if ( val_type.substr(0,4) ==
"char" )
225 else if ( val_type.substr(0,5) ==
"short" )
227 else if ( val_type.substr(0,3) ==
"int" )
229 else if ( val_type.substr(0,4) ==
"long" )
231 else if ( val_type.substr(0,5) ==
"float" )
233 else if ( val_type.substr(0,6) ==
"double" )
235 else if ( val_type.substr(0,6) ==
"string" )
237 else if ( val_type ==
"std::string" )
240 printout(
INFO,
"Param",
"++ Unknown conditions parameter type:%s data:%s",
241 val_type.c_str(),pair_data.c_str());
246 template<
typename BINDER,
typename OBJECT,
typename KEY>
247 static void bind_mapping(
const BINDER& b,
const string& val_type, OBJECT&
object,
const KEY*) {
248 if ( val_type.substr(0,3) ==
"int" )
249 __bind__(b,
object, (map<KEY,int>*)0);
250 #if defined(DD4HEP_HAVE_ALL_PARSERS)
251 else if ( val_type.substr(0,12) ==
"unsigned int" )
252 __bind__(b,
object, (map<KEY,unsigned int>*)0);
253 else if ( val_type.substr(0,4) ==
"char" )
254 __bind__(b,
object, (map<KEY,char>*)0);
255 else if ( val_type.substr(0,13) ==
"unsigned char" )
256 __bind__(b,
object, (map<KEY,unsigned char>*)0);
257 else if ( val_type.substr(0,5) ==
"short" )
258 __bind__(b,
object, (map<KEY,short>*)0);
259 else if ( val_type.substr(0,14) ==
"unsigned short" )
260 __bind__(b,
object, (map<KEY,unsigned short>*)0);
261 else if ( val_type.substr(0,13) ==
"unsigned long" )
262 __bind__(b,
object, (map<KEY,unsigned long>*)0);
265 else if ( val_type.substr(0,4) ==
"char" )
266 __bind__(b,
object, (map<KEY,int>*)0);
267 else if ( val_type.substr(0,5) ==
"short" )
268 __bind__(b,
object, (map<KEY,int>*)0);
270 else if ( val_type.substr(0,4) ==
"long" )
271 __bind__(b,
object, (map<KEY,long>*)0);
272 else if ( val_type.substr(0,5) ==
"float" )
273 __bind__(b,
object, (map<KEY,float>*)0);
274 else if ( val_type.substr(0,6) ==
"double" )
275 __bind__(b,
object, (map<KEY,double>*)0);
276 else if ( val_type.substr(0,6) ==
"string" )
277 __bind__(b,
object, (map<KEY,string>*)0);
278 else if ( val_type ==
"std::string" )
279 __bind__(b,
object, (map<KEY,string>*)0);
281 __bind__(b,
object, (map<KEY,string>*)0);
286 template <
typename BINDER,
typename OBJECT>
287 bool OpaqueDataBinder::bind_map(
const BINDER& b, OBJECT&
object,
288 const string& key_type,
const string& val_type) {
290 if ( key_type.substr(0,3) ==
"int" )
292 #if defined(DD4HEP_HAVE_ALL_PARSERS)
293 else if ( key_type.substr(0,4) ==
"char" )
295 else if ( key_type.substr(0,5) ==
"short" )
297 else if ( key_type.substr(0,4) ==
"long" )
299 else if ( key_type.substr(0,5) ==
"float" )
301 else if ( key_type.substr(0,6) ==
"double" )
304 else if ( key_type.substr(0,6) ==
"string" )
306 else if ( key_type ==
"std::string" )
309 printout(
INFO,
"OpaqueDataBinder",
"++ Unknown MAP-conditions key-type:%s",key_type.c_str());
316 template <
typename BINDER,
typename OBJECT>
317 bool OpaqueDataBinder::insert_map(
const BINDER& b, OBJECT&
object,
318 const string& key_type,
const string& key,
319 const string& val_type,
const string& val)
321 if ( key_type.substr(0,3) ==
"int" )
323 #if defined(DD4HEP_HAVE_ALL_PARSERS)
325 else if ( key_type.substr(0,4) ==
"char" )
327 else if ( key_type.substr(0,5) ==
"short" )
329 else if ( key_type.substr(0,4) ==
"long" )
331 else if ( key_type.substr(0,5) ==
"float" )
333 else if ( key_type.substr(0,6) ==
"double" )
336 else if ( key_type.substr(0,6) ==
"string" )
338 else if ( key_type ==
"std::string" )
341 printout(
INFO,
"OpaqueDataBinder",
"++ Unknown MAP-conditions key-type:%s",key_type.c_str());
348 template <
typename BINDER,
typename OBJECT>
349 bool OpaqueDataBinder::insert_map(
const BINDER& b, OBJECT&
object,
350 const std::string& key_type,
const std::string& val_type,
351 const std::string& pair_data)
353 if ( key_type.substr(0,3) ==
"int" )
355 #if defined(DD4HEP_HAVE_ALL_PARSERS)
357 else if ( key_type.substr(0,4) ==
"char" )
359 else if ( key_type.substr(0,5) ==
"short" )
361 else if ( key_type.substr(0,4) ==
"long" )
363 else if ( key_type.substr(0,5) ==
"float" )
365 else if ( key_type.substr(0,6) ==
"double" )
368 else if ( key_type.substr(0,6) ==
"string" )
370 else if ( key_type ==
"std::string" )
373 printout(
INFO,
"OpaqueDataBinder",
"++ Unknown MAP-conditions key-type:%s",key_type.c_str());
379 template bool OpaqueDataBinder::bind_sequence<OpaqueDataBlock>(
OpaqueDataBlock& object,
const string& typ,
const string& val);
381 const string& typ,
const string& val);
383 const string& key_type,
const string& key,
384 const string& val_type,
const string& val);
386 const string& key_type,
const string& val_type,
387 const string& pair_data);
391 const string& typ,
const string& val);
394 const string& key_type,
const string& val_type)
395 {
return bind_map(b, object->
data, key_type, val_type); }
399 const string& key_type,
const string& key,
400 const string& val_type,
const string& val)
401 {
return insert_map(b, object->
data, key_type, key, val_type, val); }
405 const string& key_type,
const string& val_type,
const string& pair_data)
406 {
return insert_map(b, object->
data, key_type, val_type, pair_data); }
static void insert_map_item(const BINDER &, OBJECT &object, const KEY &k, const string &val, const VAL *)
Class describing an opaque conditions data block.
OpaqueData & data() const
Access the IOV block.
static void bind_mapping(const BINDER &b, const string &val_type, OBJECT &object, const KEY *)
Helper class to bind string values to a STL list of data objects (primitive or complex) ...
Main condition object handle.
int except(const std::string &src, const std::string &fmt,...)
Calls the display action with ERROR and throws an std::runtime_error exception.
static void insert_map_data(const BINDER &b, OBJECT &object, const string &val_type, const string &pair_data, const KEY *)
Helper class to bind string values to a STL set of data objects (primitive or complex) ...
static void insert_map_pair(const BINDER &, OBJECT &object, const string &data, const KEY *, const VAL *)
Helper class to bind string values to C++ data objects (primitive or complex)
Helper class to bind string values to a STL vector of data objects (primitive or complex) ...
static void insert_map_key(const BINDER &b, OBJECT &object, const string &key_val, const string &val_type, const string &val, const KEY *)
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Helper class to bind STL map objects.