File indexing completed on 2025-01-30 09:17:44
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 "AlignmentExampleObjects.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::AlignmentExamples;
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 static int alignment_example (Detector& description, int argc, char** argv) {
0046
0047 string input;
0048 int num_iov = 10, num_runs = 10;
0049 bool arg_error = false;
0050 for(int i=0; i<argc && argv[i]; ++i) {
0051 if ( 0 == ::strncmp("-input",argv[i],4) )
0052 input = argv[++i];
0053 else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0054 num_iov = ::atol(argv[++i]);
0055 else if ( 0 == ::strncmp("-runs",argv[i],4) )
0056 num_runs = ::atol(argv[++i]);
0057 else
0058 arg_error = true;
0059 }
0060 if ( arg_error || input.empty() ) {
0061
0062 cout <<
0063 "Usage: -plugin <name> -arg [-arg] \n"
0064 " name: factory name DD4hep_AlignmentExample_stress \n"
0065 " -input <string> Geometry file \n"
0066 " -iovs <number> Number of parallel IOV slots for processing. \n"
0067 " -runs <number> Number of collision loads to be performed. \n"
0068 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0069 ::exit(EINVAL);
0070 }
0071
0072
0073 description.fromXML(input);
0074
0075
0076 ConditionsManager manager = installManager(description);
0077 const IOVType* iov_typ = manager.registerIOVType(0,"run").second;
0078 if ( 0 == iov_typ )
0079 except("ConditionsPrepare","++ Unknown IOV type supplied.");
0080
0081 TStatistic cr_stat("Creation"), comp_stat("Computation"), access_stat("Access");
0082 size_t total_created = 0;
0083
0084
0085 for(int i=0; i<num_iov; ++i) {
0086 TTimeStamp start;
0087 IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10));
0088 ConditionsPool* iov_pool = manager.registerIOV(*iov.iovType, iov.key());
0089
0090 total_created += Scanner().scan(AlignmentCreator(manager, *iov_pool),description.world());
0091 TTimeStamp stop;
0092 cr_stat.Fill(stop.AsDouble()-start.AsDouble());
0093 }
0094
0095
0096 shared_ptr<ConditionsContent> content(new ConditionsContent());
0097 shared_ptr<ConditionsSlice> slice(new ConditionsSlice(manager,content));
0098 cond::fill_content(manager,*content,*iov_typ);
0099
0100
0101
0102
0103
0104
0105
0106 IOV iov(iov_typ,15);
0107 manager.prepare(iov,*slice);
0108 slice->pool->flags |= cond::UserPool::PRINT_INSERT;
0109
0110
0111 map<DetElement, Delta> deltas;
0112 Scanner(deltaCollector(*slice,deltas),description.world());
0113 printout(INFO,"Prepare","Got a total of %ld deltas for processing alignments.",deltas.size());
0114
0115 ConditionsManager::Result total_cres;
0116 AlignmentsCalculator::Result total_ares;
0117
0118 for(int i=0; i<num_iov; ++i) {
0119 TTimeStamp start;
0120 IOV req_iov(iov_typ,1+i*10);
0121 shared_ptr<ConditionsSlice> sl(new ConditionsSlice(manager,content));
0122 ConditionsManager::Result cres = manager.prepare(req_iov,*sl);
0123
0124 AlignmentsCalculator calculator;
0125 AlignmentsCalculator::Result ares = calculator.compute(deltas,*sl);
0126 TTimeStamp stop;
0127 total_cres += cres;
0128 total_ares += ares;
0129
0130 comp_stat.Fill(stop.AsDouble()-start.AsDouble());
0131 printout(INFO,"ComputedDerived",
0132 "Setup %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) (D:%ld,A:%ld,M:%ld) for IOV:%-12s [%8.3f sec]",
0133 cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing,
0134 deltas.size(),ares.computed, ares.missing, req_iov.str().c_str(),
0135 stop.AsDouble()-start.AsDouble());
0136 }
0137
0138
0139 TRandom3 random;
0140 for(int i=0; i<num_runs; ++i) {
0141 TTimeStamp start;
0142 unsigned int rndm = 1+random.Integer(num_iov*10);
0143 IOV req_iov(iov_typ,rndm);
0144
0145 ConditionsManager::Result res = manager.prepare(req_iov,*slice);
0146 TTimeStamp stop;
0147 total_cres += res;
0148 access_stat.Fill(stop.AsDouble()-start.AsDouble());
0149 printout(INFO,"Setup slice: ",
0150 "Total %ld conditions (S:%6ld,L:%6ld,C:%4ld,M:%ld) for random %4d of type %s. [%8.4f sec]",
0151 res.total(), res.selected, res.loaded, res.computed, res.missing, rndm,
0152 iov_typ->str().c_str(), stop.AsDouble()-start.AsDouble());
0153 }
0154 printout(INFO,"Statistics","+======= Summary: # of IOV: %3d # of Runs: %3d ===========================", num_iov, num_runs);
0155 printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0156 cr_stat.GetName(), cr_stat.GetMean(), cr_stat.GetMeanErr(), cr_stat.GetRMS(), cr_stat.GetN());
0157 printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0158 comp_stat.GetName(), comp_stat.GetMean(), comp_stat.GetMeanErr(), comp_stat.GetRMS(), comp_stat.GetN());
0159 printout(INFO,"Statistics","+ %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0160 access_stat.GetName(), access_stat.GetMean(), access_stat.GetMeanErr(), access_stat.GetRMS(), access_stat.GetN());
0161 printout(INFO,"Statistics",
0162 "+ Summary: Total %ld conditions used (S:%ld,L:%ld,C:%ld,M:%ld) (A:%ld,M:%ld). Created:%ld",
0163 total_cres.total(), total_cres.selected, total_cres.loaded, total_cres.computed, total_cres.missing,
0164 total_ares.computed, total_ares.missing, total_created);
0165
0166 printout(INFO,"Statistics","+==========================================================================");
0167
0168 return 1;
0169 }
0170
0171
0172 DECLARE_APPLY(DD4hep_AlignmentExample_stress,alignment_example)