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 #include "ConditionExampleObjects.h"
0028 #include "DD4hep/Factories.h"
0029 #include "TStatistic.h"
0030 #include "TTimeStamp.h"
0031 #include "TRandom3.h"
0032
0033 using namespace std;
0034 using namespace dd4hep;
0035 using namespace dd4hep::ConditionExamples;
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 static int condition_example (Detector& description, int argc, char** argv) {
0046 string input;
0047 int num_iov = 10, num_runs = 10;
0048 bool arg_error = false;
0049 for(int i=0; i<argc && argv[i]; ++i) {
0050 if ( 0 == ::strncmp("-input",argv[i],4) )
0051 input = argv[++i];
0052 else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0053 num_iov = ::atol(argv[++i]);
0054 else if ( 0 == ::strncmp("-runs",argv[i],4) )
0055 num_runs = ::atol(argv[++i]);
0056 else
0057 arg_error = true;
0058 }
0059 if ( arg_error || input.empty() ) {
0060
0061 cout <<
0062 "Usage: -plugin <name> -arg [-arg] \n"
0063 " name: factory name DD4hep_AlignmentExample1 \n"
0064 " -input <string> Geometry file \n"
0065 " -iovs <number> Number of parallel IOV slots for processing. \n"
0066 " -runs <number> Number of collision loads to be performed. \n"
0067 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0068 ::exit(EINVAL);
0069 }
0070
0071
0072 description.fromXML(input);
0073
0074
0075 ConditionsManager manager = installManager(description);
0076 const IOVType* iov_typ = manager.registerIOVType(0,"run").second;
0077 if ( 0 == iov_typ ) {
0078 except("ConditionsPrepare","++ Unknown IOV type supplied.");
0079 }
0080
0081
0082 shared_ptr<ConditionsContent> content(new ConditionsContent());
0083 shared_ptr<ConditionsSlice> slice(new ConditionsSlice(manager,content));
0084 Scanner(ConditionsKeys(*content,INFO),description.world());
0085 Scanner(ConditionsDependencyCreator(*content,DEBUG),description.world());
0086
0087 TStatistic cr_stat("Creation"), acc_stat("Access");
0088
0089
0090 size_t total_created = 0;
0091 for(int i=0; i<num_iov; ++i) {
0092 TTimeStamp start;
0093 IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10));
0094 ConditionsPool* iov_pool = manager.registerIOV(*iov.iovType, iov.key());
0095
0096 int count = Scanner().scan(ConditionsCreator(*slice, *iov_pool, DEBUG), description.world());
0097 TTimeStamp stop;
0098 cr_stat.Fill(stop.AsDouble()-start.AsDouble());
0099 printout(INFO,"Example", "Setup %ld conditions for IOV:%s [%8.3f sec]",
0100 count, iov.str().c_str(), stop.AsDouble()-start.AsDouble());
0101 total_created += count;
0102 }
0103
0104
0105 TRandom3 random;
0106 ConditionsManager::Result total;
0107 for(int i=0; i<num_runs; ++i) {
0108 TTimeStamp start;
0109 unsigned int rndm = 1+random.Integer(num_iov*10);
0110 IOV req_iov(iov_typ,rndm);
0111
0112 ConditionsManager::Result res = manager.prepare(req_iov,*slice);
0113 TTimeStamp stop;
0114 total += res;
0115 acc_stat.Fill(stop.AsDouble()-start.AsDouble());
0116
0117 printout(INFO,"Prepare","Total %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld) of type %s [%8.3f sec]",
0118 res.total(), res.selected, res.loaded, res.computed, res.missing,
0119 req_iov.str().c_str(), stop.AsDouble()-start.AsDouble());
0120 }
0121 printout(INFO,"Statistics","+======= Summary: # of IOV: %3d # of Runs: %3d ===========================", num_iov, num_runs);
0122 printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0123 cr_stat.GetName(), cr_stat.GetMean(), cr_stat.GetMeanErr(), cr_stat.GetRMS(), cr_stat.GetN());
0124 printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0125 acc_stat.GetName(), acc_stat.GetMean(), acc_stat.GetMeanErr(), acc_stat.GetRMS(), acc_stat.GetN());
0126 printout(INFO,"Statistics","+ Accessed a total of %ld conditions (S:%6ld,L:%6ld,C:%6ld,M:%ld). Created:%ld",
0127 total.total(), total.selected, total.loaded, total.computed, total.missing, total_created);
0128 printout(INFO,"Statistics","+=========================================================================");
0129
0130 return 1;
0131 }
0132
0133
0134 DECLARE_APPLY(DD4hep_ConditionExample_stress,condition_example)