File indexing completed on 2025-01-30 09:17:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include "ConditionExampleObjects.h"
0029 #include "DDCond/ConditionsIOVPool.h"
0030 #include "DDCond/ConditionsManager.h"
0031 #include "DDCond/ConditionsRootPersistency.h"
0032 #include "DD4hep/Factories.h"
0033
0034 using namespace std;
0035 using namespace dd4hep;
0036 using namespace dd4hep::ConditionExamples;
0037
0038 static void help(int argc, char** argv) {
0039
0040 cout <<
0041 "Usage: -plugin <name> -arg [-arg] \n"
0042 " name: factory name DD4hep_ConditionExample_load \n"
0043 " -input <string> Geometry file \n"
0044 " -conditions <string> Conditions input file \n"
0045 " -iovs <number> Number of parallel IOV slots for processing. \n"
0046 " -restore <string> Restore strategy: iovpool, userpool or condpool.\n"
0047 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0048 ::exit(EINVAL);
0049 }
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 static int condition_example (Detector& description, int argc, char** argv) {
0060 string input, conditions, restore="iovpool";
0061 int num_iov = 10, extend = 0;
0062 bool arg_error = false;
0063 for(int i=0; i<argc && argv[i]; ++i) {
0064 if ( 0 == ::strncmp("-input",argv[i],4) )
0065 input = argv[++i];
0066 else if ( 0 == ::strncmp("-conditions",argv[i],4) )
0067 conditions = argv[++i];
0068 else if ( 0 == ::strncmp("-restore",argv[i],4) )
0069 restore = argv[++i];
0070 else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0071 num_iov = ::atol(argv[++i]);
0072 else if ( 0 == ::strncmp("-extend",argv[i],4) )
0073 extend = ::atol(argv[++i]);
0074 else
0075 arg_error = true;
0076 }
0077 if ( arg_error || input.empty() || conditions.empty() ) help(argc,argv);
0078
0079
0080 description.fromXML(input);
0081
0082 detail::have_condition_item_inventory(1);
0083
0084
0085 ConditionsManager manager = installManager(description);
0086 shared_ptr<ConditionsContent> content(new ConditionsContent());
0087 shared_ptr<ConditionsSlice> slice(new ConditionsSlice(manager,content));
0088 Scanner(ConditionsKeys(*content,INFO),description.world());
0089 Scanner(ConditionsDependencyCreator(*content,DEBUG,false,extend),description.world());
0090
0091
0092 printout(INFO,"ConditionsExample","+ Start conditions import from ROOT object(s): %s",
0093 conditions.c_str());
0094 try {
0095 auto pers = cond::ConditionsRootPersistency::load(conditions.c_str(),"DD4hep Conditions");
0096 printout(ALWAYS,"Statistics","+=========================================================================");
0097 printout(ALWAYS,"Statistics","+ Loaded conditions object from file %s. Took %8.3f seconds.",
0098 conditions.c_str(),pers->duration);
0099 size_t num_cond = 0;
0100 if ( restore == "iovpool" )
0101 num_cond = pers->importIOVPool("ConditionsIOVPool No 1","run",manager);
0102 else if ( restore == "userpool" )
0103 num_cond = pers->importUserPool("*","run",manager);
0104 else if ( restore == "condpool" )
0105 num_cond = pers->importConditionsPool("*","run",manager);
0106 else
0107 help(argc,argv);
0108
0109 printout(ALWAYS,"Statistics","+ Imported %ld conditions from %s to IOV pool. Took %8.3f seconds.",
0110 num_cond, restore.c_str(), pers->duration);
0111 printout(ALWAYS,"Statistics","+=========================================================================");
0112 }
0113 catch(const exception& e) {
0114 printout(ERROR,"ConditionsExample","Failed to import ROOT object(s): %s",e.what());
0115 throw;
0116 }
0117
0118
0119 const IOVType* iov_typ = manager.iovType("run");
0120 cond::ConditionsIOVPool* pool = manager.iovPool(*iov_typ);
0121 for( const auto& p : pool->elements )
0122 p.second->print("*");
0123
0124 ConditionsManager::Result total;
0125 for(int i=0; i<num_iov; ++i) {
0126 IOV req_iov(iov_typ,i*10+5);
0127
0128 ConditionsManager::Result r = manager.prepare(req_iov,*slice);
0129 total += r;
0130 if ( 0 == i ) {
0131 Scanner(ConditionsPrinter(slice.get(),"Example"),description.world());
0132 }
0133 printout(ALWAYS,"Prepare","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0134 r.total(), r.selected, r.loaded, r.computed, r.missing, req_iov.str().c_str());
0135 }
0136 printout(ALWAYS,"Statistics","+=========================================================================");
0137 printout(ALWAYS,"Statistics","+ Accessed a total of %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld)",
0138 total.total(), total.selected, total.loaded, total.computed, total.missing);
0139 printout(ALWAYS,"Statistics","+=========================================================================");
0140
0141 return 1;
0142 }
0143
0144
0145 DECLARE_APPLY(DD4hep_ConditionExample_load,condition_example)