File indexing completed on 2025-01-30 09:17:50
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/ConditionsManager.h"
0030 #include "DDCond/ConditionsIOVPool.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
0039
0040
0041
0042
0043
0044
0045
0046 static int condition_example (Detector& description, int argc, char** argv) {
0047 string input, conditions;
0048 int num_iov = 10;
0049 bool arg_error = false;
0050 bool output_iovpool = true;
0051 bool output_userpool = true;
0052 bool output_condpool = true;
0053
0054 for(int i=0; i<argc && argv[i]; ++i) {
0055 if ( 0 == ::strncmp("-input",argv[i],4) )
0056 input = argv[++i];
0057 else if ( 0 == ::strncmp("-conditions",argv[i],4) )
0058 conditions = argv[++i];
0059 else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0060 num_iov = ::atol(argv[++i]);
0061 else
0062 arg_error = true;
0063 }
0064 if ( arg_error || input.empty() || conditions.empty() ) {
0065
0066 cout <<
0067 "Usage: -plugin <name> -arg [-arg] \n"
0068 " name: factory name DD4hep_ConditionExample_save \n"
0069 " -input <string> Geometry file \n"
0070 " -conditions <string> Conditions output file \n"
0071 " -iovs <number> Number of parallel IOV slots for processing. \n"
0072 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0073 ::exit(EINVAL);
0074 }
0075
0076
0077 description.fromXML(input);
0078
0079
0080 ConditionsManager manager = installManager(description);
0081 const IOVType* iov_typ = manager.registerIOVType(0,"run").second;
0082 if ( 0 == iov_typ )
0083 except("ConditionsPrepare","++ Unknown IOV type supplied.");
0084
0085
0086 shared_ptr<ConditionsContent> content(new ConditionsContent());
0087 shared_ptr<ConditionsSlice> slice(new ConditionsSlice(manager,content));
0088 Scanner(ConditionsKeys(*content,INFO),description.world());
0089
0090 Scanner(ConditionsDependencyCreator(*content,DEBUG,true),description.world());
0091
0092
0093
0094 for(int i=0; i<num_iov; ++i) {
0095 IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10));
0096 ConditionsPool* iov_pool = manager.registerIOV(*iov.iovType, iov.key());
0097
0098 Scanner(ConditionsCreator(*slice, *iov_pool, INFO),description.world(),0,true);
0099 }
0100
0101 char text[132];
0102 size_t count = 0, total_count = 0;
0103 auto* persist = new cond::ConditionsRootPersistency("DD4hep Conditions");
0104
0105 ConditionsManager::Result total;
0106 for(int i=0; i<num_iov; ++i) {
0107 IOV req_iov(iov_typ,i*10+5);
0108
0109 ConditionsManager::Result r = manager.prepare(req_iov,*slice);
0110 total += r;
0111 if ( 0 == i ) {
0112 Scanner(ConditionsPrinter(slice.get(),"Example"),description.world());
0113 }
0114
0115 printout(ALWAYS,"Prepare","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0116 r.total(), r.selected, r.loaded, r.computed, r.missing, req_iov.str().c_str());
0117 if ( output_userpool ) {
0118
0119 ::snprintf(text,sizeof(text),"User pool %s:[%ld]",iov_typ->name.c_str(),long(req_iov.key().first));
0120 count = persist->add(text,*slice->pool);
0121 total_count += count;
0122 printout(ALWAYS,"Example","+++ Added %ld conditions to persistent user pool.",count);
0123 }
0124 }
0125 if ( output_condpool ) {
0126 int npool = 0;
0127 cond::ConditionsIOVPool* iov_pool = manager.iovPool(*iov_typ);
0128 for( const auto& p : iov_pool->elements ) {
0129 ::snprintf(text,sizeof(text),"Conditions pool %s:[%ld,%ld]",
0130 iov_typ->name.c_str(),long(p.second->iov->key().first),long(p.second->iov->key().second));
0131 if ( (npool%2) == 0 ) {
0132 count = persist->add(text,*p.second);
0133 printout(ALWAYS,"Example",
0134 "+++ ConditionsPool: Added %ld conditions "
0135 "to persistent conditions pool.",count);
0136 }
0137 else {
0138 vector<Condition> entries;
0139 p.second->select_all(entries);
0140 count = persist->add(text,*p.second->iov,entries);
0141 printout(ALWAYS,"Example",
0142 "+++ std::vector<Condition>: Added %ld conditions "
0143 "to persistent conditions pool.",count);
0144 }
0145 total_count += count;
0146 ++npool;
0147 }
0148 }
0149 if ( output_iovpool ) {
0150 count = persist->add("ConditionsIOVPool No 1",*manager.iovPool(*iov_typ));
0151 total_count += count;
0152 printout(ALWAYS,"Example","+++ Added %ld conditions to persistent IOV pool.",count);
0153
0154
0155 printout(ALWAYS,"Example","+++ Added %ld conditions to persistent IOV pool.",count);
0156 }
0157 int nBytes = persist->save(conditions.c_str());
0158 printout(ALWAYS,"Example",
0159 "+++ Wrote %d Bytes (%ld conditions) of data to '%s' [%8.3f seconds].",
0160 nBytes, total_count, conditions.c_str(), persist->duration);
0161 if ( nBytes > 0 ) {
0162 printout(ALWAYS,"Example",
0163 "+++ Successfully saved %ld condition to file.",total_count);
0164 }
0165 delete persist;
0166
0167 printout(ALWAYS,"Statistics","+=========================================================================");
0168 printout(ALWAYS,"Statistics","+ Accessed a total of %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld)",
0169 total.total(), total.selected, total.loaded, total.computed, total.missing);
0170 printout(ALWAYS,"Statistics","+=========================================================================");
0171
0172
0173 return 1;
0174 }
0175
0176
0177 DECLARE_APPLY(DD4hep_ConditionExample_save,condition_example)