49 static int ddcond_install_cond_mgr (
Detector& description,
int argc,
char** argv) {
52 if ( !mgr.isValid() ) {
53 bool arg_error =
false;
54 std::string factory =
"DD4hep_ConditionsManager_Type1";
55 for(
int i = 0; i < argc && argv[i]; ++i) {
56 if ( 0 == ::strncmp(
"-type",argv[i],4) )
58 else if ( 0 == ::strncmp(
"-handle",argv[i],5) )
66 "Usage: -plugin <name> -arg [-arg] \n"
67 " name: factory name DD4hep_ConditionsManagerInstaller \n"
68 " -type <string> Manager type. \n"
69 " Default: ConditionsManagerObject_Type1_t \n"
70 " -handle <pointer> Pointer to Handle<NamedObject> to pass pointer \n"
72 "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
77 except(
"ConditionsManagerInstaller",
"Failed to create manager object of type %s",
81 printout(INFO,
"DDCond",
82 "+++ Successfully installed conditions manager instance '%s' to Detector.",
86 else if ( argc > 0 ) {
87 for(
int i=0; i<argc && argv[i]; ++i) {
88 if ( 0 == ::strncmp(
"-handle",argv[i],5) ) {
97 DECLARE_APPLY(DD4hep_ConditionsManagerInstaller,ddcond_install_cond_mgr)
106 static ConditionsSlice* ddcond_prepare(
Detector& description,
const std::string& iov_typ,
long iov_val,
int argc,
char** argv) {
108 long iovvalue = iov_val;
111 for(
int i = 0; i < argc; ++i) {
112 if ( ::strncmp(argv[i],
"-iov_type",7) == 0 )
113 iovtype = manager.
iovType(argv[++i]);
114 else if ( ::strncmp(argv[i],
"-iov_value",7) == 0 )
115 iovvalue = ::atol(argv[++i]);
118 iovtype = manager.
iovType(iov_typ);
120 except(
"ConditionsPrepare",
"++ Unknown IOV type supplied.");
122 except(
"ConditionsPrepare",
123 "++ Unknown IOV value supplied for iov type %s.",iovtype->
str().c_str());
125 IOV iov(iovtype,iovvalue);
127 std::unique_ptr<ConditionsSlice> slice(
new ConditionsSlice(manager,content));
130 printout(INFO,
"Conditions",
131 "+++ ConditionsUpdate: Collected %ld conditions of type %s [iov-value:%ld].",
132 long(slice->size()), iovtype ? iovtype->
str().c_str() :
"???", iovvalue);
133 return slice.release();
145 static int ddcond_conditions_pool_processor(
Detector& description,
bool process_pool,
bool process_conditions,
int argc,
char** argv) {
146 std::unique_ptr<Condition::Processor> proc(createProcessor<Condition::Processor>(description,argc,argv));
151 printout(WARNING,
"Conditions",
"+++ Conditions processor of type %s is invalid!",argv[0]);
153 if ( process_conditions && !proc.get() ) {
154 except(
"Conditions",
"+++ Conditions processor of type %s is invalid!",argv[0]);
156 for(
const IOVType* type : types ) {
161 if ( process_pool ) {
162 printout(INFO,
"CondPoolProcessor",
"+++ ConditionsIOVPool for type %s [%d IOV element%s]",
163 type->str().c_str(),
int(e.size()),e.size()==1 ?
"" :
"s");
165 for (
const auto& cp : e ) {
166 if ( process_pool ) {
167 cp.second->print(
"");
169 if ( process_conditions ) {
171 cp.second->select_all(rc);
173 if ( proc.get() ) { (*proc)(c); }
182 static int ddcond_conditions_pool_process(
Detector& description,
int argc,
char** argv) {
183 return ddcond_conditions_pool_processor(description,
false,
true, argc, argv);
185 DECLARE_APPLY(DD4hep_ConditionsPoolProcessor,ddcond_conditions_pool_process)
197 static int ddcond_conditions_pool_print(
Detector& description,
bool print_conditions,
int argc,
char** argv) {
199 for(
int i = 0; i < argc; ++i) {
200 if ( argv[i] && 0 == ::strncmp(argv[i],
"-processor",3) ) {
201 std::vector<char*> args;
202 for(
int j=i; j<argc && argv[j] && 0 != ::strncmp(argv[i],
"-end-processor",8); ++j)
203 args.emplace_back(argv[j]);
204 args.emplace_back(
nullptr);
205 return ddcond_conditions_pool_processor(description,
true,print_conditions,
int(args.size()-1),&args[0]);
208 printout(WARNING,
"DDCondProcessor",
"++ Found arguments in plugin call, "
209 "but could not make any sense of them....");
211 const void* args[] = {
"-processor",
"DD4hep_ConditionsPrinter", 0};
212 return ddcond_conditions_pool_processor(description,
true,print_conditions,2,(
char**)args);
215 static int ddcond_dump_pools(
Detector& description,
int argc,
char** argv) {
216 return ddcond_conditions_pool_print(description,
false, argc, argv);
218 static int ddcond_dump_conditions(
Detector& description,
int argc,
char** argv) {
219 return ddcond_conditions_pool_print(description,
true, argc, argv);
233 static int ddcond_detelement_dump(
Detector& description,
int argc,
char** argv) {
248 virtual int operator()(
DetElement de,
int level)
const {
252 char fmt[128], tmp[32];
253 ::snprintf(tmp,
sizeof(tmp),
"%03d/",level+1);
254 ::snprintf(fmt,
sizeof(fmt),
"%03d %%-%ds %%s #Dau:%%d VolID:%%08X %%c",level+1,2*level+1);
255 printout(INFO,
"DetectorDump",fmt,
"",de.
path().c_str(),
int(children.size()),
256 (
unsigned long)de.
volumeID(), sens);
258 (printer)(de, level);
265 pool->
print(
"User pool");
266 Actor actor(printer);
267 int ret = actor.process(description.
world(),0,
true);
269 return ret > 0 ? 1 : 0;
271 DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump)
282 static void* ddcond_prepare_plugin(
Detector& description,
int argc,
char** argv) {
285 return p && p->
size() > 0 ? slice.release() : 0;
298 static int ddcond_detelement_processor(
Detector& description,
int argc,
char** argv) {
314 {
return de.hasConditions() ? processor->processElement(de) : 1; }
318 processor = createProcessor<ConditionsProcessor>(description, argc, argv);
321 const void* args[] = {
"-processor",
"DD4hep_ConditionsPrinter", 0};
322 processor = createProcessor<ConditionsProcessor>(description, 2, (
char**)args);
326 Actor actor(processor);
327 pool->
print(
"User pool");
328 processor->setPool(pool);
329 int ret = Actor(processor).
process(description.
world(),0,
true);
331 return ret > 0 ? 1 : 0;
333 DECLARE_APPLY(DD4hep_DetElementConditionsProcessor,ddcond_detelement_processor)
344 static long ddcond_synchronize_conditions(
Detector& description,
int argc,
char** argv) {
346 std::string iov_typ = argv[0];
347 IOV::Key::first_type iov_key = *(IOV::Key::first_type*)argv[1];
350 pool->
print(
"User pool");
355 except(
"Conditions",
"+++ Failed update conditions. Arguments were: '%s'",
356 arguments(argc,argv).c_str());
359 DECLARE_APPLY(DD4hep_ConditionsSynchronize,ddcond_synchronize_conditions)
370 static long ddcond_clean_conditions(
Detector& description,
int argc,
char** argv) {
372 std::string iov_type = argv[0];
373 int max_age = *(
int*)argv[1];
374 printout(INFO,
"Conditions",
375 "+++ ConditionsUpdate: Cleaning conditions... type:%s max age:%d",
376 iov_type.c_str(), max_age);
379 manager.
clean(iov_typ, max_age);
382 except(
"Conditions",
"+++ Failed cleaning conditions. Insufficient arguments!");
385 DECLARE_APPLY(DD4hep_ConditionsClean,ddcond_clean_conditions)
396 template <
typename WRAPPER,
typename PRINTER>
397 static void* create_printer(
Detector& description,
int argc,
char** argv) {
398 PrintLevel print_level = INFO;
399 std::string prefix =
"", name =
"";
400 int flags = 0, have_pool = 0, arg_error =
false;
401 for(
int i=0; i<argc && argv[i]; ++i) {
402 if ( 0 == ::strncmp(
"-prefix",argv[i],4) )
404 else if ( 0 == ::strncmp(
"-name",argv[i],5) )
406 else if ( 0 == ::strncmp(
"-flags",argv[i],5) )
407 flags = ::atol(argv[++i]);
408 else if ( 0 == ::strncmp(
"-pool",argv[i],5) )
410 else if ( 0 == ::strncmp(
"-print",argv[i],5) )
411 print_level = dd4hep::printLevel(argv[++i]);
418 "Usage: -plugin <name> -arg [-arg] \n"
419 " name: factory name(s) DD4hep_ConditionsPrinter, \n"
420 " dd4hep_AlignmentsPrinter \n"
421 " dd4hep_AlignedVolumePrinter \n"
422 " -prefix <string> Printout prefix for user customized output. \n"
423 " -flags <number> Printout processing flags. \n"
424 " -pool Attach conditions user pool from \n"
425 " PluginTester's slice instance attached. \n\n"
426 " -print <value> Printout level for the printer object. \n"
427 "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
431 printout(INFO,
"Printer",
"World=%s [%p]",world.
path().c_str(),world.
ptr());
437 PRINTER* p = (flags) ?
new PRINTER(slice, prefix, flags) :
new PRINTER(slice, prefix);
438 p->printLevel = print_level;
439 if ( !name.empty() ) p->name = std::move(name);
443 static void* create_cond_printer(
Detector& description,
int argc,
char** argv)
444 {
return create_printer<Condition::Processor,ConditionsPrinter>(description,argc,argv); }
459 static long ddcond_create_repository(
Detector& description,
int argc,
char** argv) {
460 bool arg_error =
false;
461 std::string output =
"";
462 for(
int i=0; i<argc && argv[i]; ++i) {
463 if ( 0 == ::strncmp(
"-output",argv[i],4) )
468 if ( arg_error || output.empty() ) {
471 "Usage: -plugin <name> -arg [-arg] \n"
472 " name: factory name DD4hep_ConditionsCreateRepository \n\n"
473 " -output <string> Output file name. \n\n"
474 "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
477 printout(INFO,
"Conditions",
478 "+++ ConditionsRepository: Creating %s",output.c_str());
483 DECLARE_APPLY(DD4hep_ConditionsCreateRepository,ddcond_create_repository)
494 static long ddcond_dump_repository(
Detector& ,
int argc,
char** argv) {
496 bool arg_error =
false;
497 std::string input =
"";
499 for(
int i=0; i<argc && argv[i]; ++i) {
500 if ( 0 == ::strncmp(
"-input",argv[i],4) )
505 if ( arg_error || input.empty() ) {
508 "Usage: -plugin <name> -arg [-arg] \n"
509 " name: factory name DD4hep_ConditionsDumpRepository \n\n"
510 " -input <string> Input file name. \n\n"
511 "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
514 printout(INFO,
"Conditions",
"+++ ConditionsRepository: Dumping %s",input.c_str());
516 printout(INFO,
"Repository",
"%-8s %-60s %-60s",
"Key",
"Name",
"Address");
517 for(Data::const_iterator i=data.begin(); i!=data.end(); ++i) {
520 if ( add.length() > 80 ) add = e.
address.substr(0,60) +
"...";
521 printout(INFO,
"Repository",
"%16llX %s",e.
key,e.
name.c_str());
522 printout(INFO,
"Repository",
" -> %s",e.
address.c_str());
527 DECLARE_APPLY(DD4hep_ConditionsDumpRepository,ddcond_dump_repository)
541 static long ddcond_load_repository(
Detector& ,
int argc,
char** argv) {
543 std::string input = argv[0];
544 printout(INFO,
"Conditions",
"+++ ConditionsRepository: Loading %s",input.c_str());
549 except(
"Conditions",
"+++ Failed loading conditions repository. Insufficient arguments!");
552 DECLARE_APPLY(DD4hep_ConditionsLoadRepository,ddcond_load_repository)