57 template <>
void Converter<iov>::operator()(
xml_h seq)
const;
58 template <>
void Converter<iov_type>::operator()(
xml_h seq)
const;
59 template <>
void Converter<repository>::operator()(
xml_h seq)
const;
60 template <>
void Converter<manager>::operator()(
xml_h seq)
const;
61 template <>
void Converter<value>::operator()(
xml_h e)
const;
62 template <>
void Converter<pressure>::operator()(
xml_h e)
const;
63 template <>
void Converter<temperature>::operator()(
xml_h e)
const;
64 template <>
void Converter<sequence>::operator()(
xml_h e)
const;
65 template <>
void Converter<mapping>::operator()(
xml_h e)
const;
66 template <>
void Converter<alignment>::operator()(
xml_h e)
const;
67 template <>
void Converter<conditions>::operator()(
xml_h seq)
const;
68 template <>
void Converter<arbitrary>::operator()(
xml_h seq)
const;
77 static dd4hep::PrintLevel s_parseLevel = dd4hep::DEBUG;
85 struct ConversionArg {
89 ConversionArg() =
delete;
90 ConversionArg(
const ConversionArg&) =
delete;
93 ConversionArg& operator=(
const ConversionArg&) =
delete;
102 struct CurrentDetector {
105 CurrentDetector(ConversionArg* a) : arg(a) {
106 detector = arg->detector;
109 arg->detector = detector;
111 void set(
const std::string& path) {
112 if ( !path.empty() ) {
126 CurrentPool(ConversionArg* a) : arg(a) {
145 std::string tag = elt.tag();
146 std::string typ = elt.hasAttr(
_U(type)) ? elt.typeStr() : tag;
147 std::string nam = elt.hasAttr(
_U(name)) ? elt.nameStr() : tag;
149 std::string cond_nam =
det.path()+
"#"+nam;
152 dd4hep::printout(s_parseLevel,
"XMLConditions",
"++ Processing condition tag:%s name:%s type:%s [%s] hash:%016X det:%p",
153 tag.c_str(),
cond.name(), typ.c_str(),
155 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
159 if ( elt.hasAttr(
_U(comment)) ) {
160 cond->comment = elt.attr<std::string>(
_U(comment));
176 const std::string& type=
"")
179 std::string typ = type.empty() ? elt.typeStr() : type;
180 std::string val = elt.hasAttr(
_U(value)) ? elt.valueStr() : elt.text();
182 std::string unit = elt.hasAttr(
_U(unit)) ? elt.attr<std::string>(
_U(unit)) : std::string(
"");
183 if ( !unit.empty() ) val +=
"*"+unit;
199 template <>
void Converter<iov_type>::operator()(
xml_h element)
const {
201 std::string nam = e.nameStr();
202 std::size_t
id = e.id() >= 0 ? e.id() : INT_MAX;
203 ConversionArg* arg = _param<ConversionArg>();
204 dd4hep::printout(s_parseLevel,
"XMLConditions",
"++ Registering IOV type: [%d]: %s",
int(
id),nam.c_str());
205 const IOVType* iov_type = arg->manager.registerIOVType(
id,nam).second;
207 except(
"XMLConditions",
"Failed to register iov type: [%d]: %s",
int(
id),nam.c_str());
217 template <>
void Converter<iov>::operator()(
xml_h element)
const {
219 std::string val = e.
attr<std::string>(
_UC(validity));
220 ConversionArg* arg = _param<ConversionArg>();
221 CurrentPool pool(arg);
223 pool.set(arg->manager.registerIOV(val));
224 if ( e.hasAttr(
_U(ref)) ) {
225 std::string ref = e.attr<std::string>(
_U(ref));
226 dd4hep::printout(s_parseLevel,
"XMLConditions",
"++ Reading IOV file: %s -> %s",val.c_str(),ref.c_str());
228 Converter<conditions>(description,param,optional)(doc.root());
240 template <>
void Converter<manager>::operator()(
xml_h element)
const {
241 ConversionArg* arg = _param<ConversionArg>();
244 Converter<arbitrary>(description,param,optional)(doc.root());
248 std::string nam = d.nameStr();
249 std::string val = d.valueStr();
251 printout(s_parseLevel,
"XMLConditions",
"++ Setup conditions Manager[%s] = %s",
252 nam.c_str(),val.c_str());
253 arg->manager[nam].str(val);
256 printout(ERROR,
"XMLConditions",
"++ FAILED: conditions Manager[%s] = %s [%s]",
257 nam.c_str(),val.c_str(),e.what());
260 arg->manager.initialize();
261 printout(s_parseLevel,
"XMLConditions",
"++ Conditions Manager successfully initialized.");
270 template <>
void Converter<value>::operator()(
xml_h e)
const {
271 ConversionArg* arg = _param<ConversionArg>();
273 arg->manager.registerUnlocked(*arg->pool, con);
284 template <>
void Converter<pressure>::operator()(
xml_h e)
const {
285 ConversionArg* arg = _param<ConversionArg>();
286 dd4hep::Condition con = bind_condition(detail::ValueBinder(), arg->detector, e,
"double");
288 arg->manager.registerUnlocked(*arg->pool, con);
299 template <>
void Converter<temperature>::operator()(
xml_h e)
const {
300 ConversionArg* arg = _param<ConversionArg>();
301 dd4hep::Condition con = bind_condition(detail::ValueBinder(), arg->detector, e,
"double");
303 arg->manager.registerUnlocked(*arg->pool, con);
312 template <>
void Converter<sequence>::operator()(
xml_h e)
const {
313 ConversionArg* arg = _param<ConversionArg>();
316 arg->manager.registerUnlocked(*arg->pool, con);
325 template <>
void Converter<mapping>::operator()(
xml_h e)
const {
326 ConversionArg* arg = _param<ConversionArg>();
329 arg->manager.registerUnlocked(*arg->pool, con);
338 template <>
void Converter<alignment>::operator()(
xml_h e)
const {
339 xml_h child_rot, child_pos, child_piv;
340 ConversionArg* arg = _param<ConversionArg>();
345 arg->manager.registerUnlocked(*arg->pool, con);
354 template <>
void Converter<detelement>::operator()(
xml_h e)
const {
356 ConversionArg* arg = _param<ConversionArg>();
357 CurrentDetector detector(arg);
358 if ( elt.hasAttr(
_U(path)) ) {
359 detector.set(e.
attr<std::string>(
_U(path)));
360 printout(s_parseLevel,
"XMLConditions",
"++ Processing condition for:%s",
361 arg->detector.path().c_str());
363 if ( elt.hasAttr(
_U(ref)) ) {
382 template <>
void Converter<repository>::operator()(
xml_h element)
const {
394 template <>
void Converter<arbitrary>::operator()(
xml_h e)
const {
396 std::string tag = elt.tag();
397 if ( tag ==
"repository" )
398 Converter<repository>(description,param,optional)(e);
399 else if ( tag ==
"manager" )
400 Converter<manager>(description,param,optional)(e);
401 else if ( tag ==
"conditions" )
402 Converter<conditions>(description,param,optional)(e);
403 else if ( tag ==
"detelement" )
404 Converter<detelement>(description,param,optional)(e);
405 else if ( tag ==
"iov_type" )
406 Converter<iov_type>(description,param,optional)(e);
407 else if ( tag ==
"iov" )
408 Converter<iov>(description,param,optional)(e);
410 except(
"XMLConditions",
411 "++ Failed to handle unknown tag: %s",tag.c_str());
420 template <>
void Converter<conditions>::operator()(
xml_h e)
const {
431 static long setup_repository_loglevel(
dd4hep::Detector& ,
int argc,
char** argv) {
433 s_parseLevel = dd4hep::printLevel(argv[0]);
436 dd4hep::except(
"ConditionsXMLRepositoryPrintLevel",
"++ Invalid plugin arguments: %s",
437 dd4hep::arguments(argc,argv).c_str());
440 DECLARE_APPLY(DD4hep_ConditionsXMLRepositoryPrintLevel,setup_repository_loglevel)
442 #include <DD4hep/DD4hepUI.h>
449 static long setup_repository_Conditions(
dd4hep::Detector& description,
int argc,
char** argv) {
452 std::string fname(argv[0]);
454 ConversionArg arg(description.
world(), mgr);
456 (dd4hep::Converter<dd4hep::conditions>(description,&arg))(doc.root());
459 dd4hep::except(
"XML_DOC_READER",
"Invalid number of arguments to interprete conditions: %d != %d.",argc,1);
462 DECLARE_APPLY(DD4hep_ConditionsXMLRepositoryParser,setup_repository_Conditions)