File indexing completed on 2025-01-30 09:18:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "DD4hep/Detector.h"
0022 #include "DD4hep/Path.h"
0023 #include "DD4hep/Printout.h"
0024 #include "DD4hep/Factories.h"
0025 #include "DD4hep/InstanceCount.h"
0026 #include "DD4hep/DetectorProcessor.h"
0027 #include "DD4hep/ConditionsPrinter.h"
0028 #include "DD4hep/AlignmentsProcessor.h"
0029 #include "DD4hep/AlignmentsCalculator.h"
0030 #include "DDCond/ConditionsSlice.h"
0031
0032 #include "DDDB/DDDBConversion.h"
0033
0034 #include "TStatistic.h"
0035 #include "TTimeStamp.h"
0036
0037 using namespace std;
0038 using namespace dd4hep;
0039 using namespace dd4hep::cond;
0040 using align::deltaCollector;
0041 using align::AlignmentsCalculator;
0042
0043
0044 namespace {
0045
0046
0047
0048
0049
0050
0051
0052
0053 class AlignmentSelector {
0054 public:
0055 typedef std::shared_ptr<ConditionsContent> Content;
0056 Detector& description;
0057 string name;
0058 PrintLevel printLevel = INFO;
0059 TStatistic load_stat, comp_stat;
0060 Content content;
0061 ConditionsPrinter printer;
0062
0063
0064 AlignmentSelector(Detector& l, PrintLevel p)
0065 : description(l), name("DDDBAlignments"), printLevel(p),
0066 load_stat("Load"), comp_stat("Compute"), printer(0,"Alignments")
0067 {
0068 printer.printLevel = DEBUG;
0069 content.reset(new ConditionsContent());
0070 }
0071
0072
0073 virtual ~AlignmentSelector() {
0074 content.reset();
0075 }
0076
0077 long collect(ConditionsManager manager, const IOV& iov) {
0078 shared_ptr<ConditionsSlice> slice(new ConditionsSlice(manager,content));
0079 ConditionsManager::Result cres = manager.prepare(iov, *slice);
0080 printout(INFO,name,
0081 "++ DDDB: Initial prepare: %7ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) for IOV:%-12s",
0082 cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing, iov.str().c_str());
0083 cond::fill_content(manager,*content,*iov.iovType);
0084 printout(INFO,name,"++ DDDB: Content: %ld conditions, %ld derived conditions.",
0085 content->conditions().size(), content->derived().size());
0086 return 1;
0087 }
0088
0089 int computeDependencies(shared_ptr<ConditionsSlice>& slice,
0090 ConditionsManager manager,
0091 const IOV& iov,
0092 bool access = false)
0093 {
0094 AlignmentsCalculator align;
0095 std::map<DetElement, Delta> align_deltas;
0096 slice.reset(new ConditionsSlice(manager,content));
0097 TTimeStamp acc_start;
0098 ConditionsManager::Result cres = manager.prepare(iov, *slice);
0099 TTimeStamp acc_stop;
0100 load_stat.Fill(acc_stop.AsDouble()-acc_start.AsDouble());
0101 printout(INFO,name,
0102 "++ DDDB: Prepared %7ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) for IOV:%-12s",
0103 cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing, iov.str().c_str());
0104
0105 DetectorScanner(deltaCollector(*slice,align_deltas),description.world(),0,true);
0106
0107 TTimeStamp comp_start;
0108 AlignmentsCalculator::Result ares = align.compute(align_deltas,*slice);
0109 TTimeStamp comp_stop;
0110 comp_stat.Fill(comp_stop.AsDouble()-comp_start.AsDouble());
0111 printout(INFO,name,
0112 "++ DDDB: AlignmentManager: %7ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) alignments: (A:%ld,M:%ld) for IOV:%-12s",
0113 cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing,
0114 ares.computed, ares.missing, iov.str().c_str());
0115 if ( access ) {
0116 set<DetElement> detectors;
0117 for ( const auto& e : align_deltas ) {
0118 Condition c = slice->get(e.first,align::Keys::alignmentKey);
0119 Alignment a = c;
0120 const Delta& D = a.data().delta;
0121 printout(PrintLevel(printLevel+1),"Alignment",
0122 "++ [%16llX] (%11s-%8s-%5s) Cond:%p '%s . %s'", c.key(),
0123 D.hasTranslation() ? "Translation" : "",
0124 D.hasRotation() ? "Rotation" : "",
0125 D.hasPivot() ? "Pivot" : "",
0126 c.ptr(),
0127 e.first.path().c_str(),
0128 c.name());
0129 detectors.insert(e.first);
0130 }
0131 printout(INFO,name,"++ DDDB: Accessed %ld alignments from %ld DetElement objects.",
0132 align_deltas.size(), detectors.size());
0133 }
0134 return 1;
0135 }
0136 };
0137 }
0138
0139
0140 namespace {
0141
0142
0143 long dddb_derived_alignments(Detector& description, int argc, char** argv) {
0144 int turns = 1, accesses = 1;
0145 PrintLevel level = INFO;
0146 long time = detail::makeTime(2016,4,1,12);
0147 string fname = Path(__FILE__).filename();
0148
0149 for(int i=0; i<argc; ++i) {
0150 if ( ::strncmp(argv[i],"-time",3)==0 ) {
0151 time = detail::makeTime(argv[++i],"%d-%m-%Y %H:%M:%S");
0152 printout(level,"DDDB","Setting event time in %s to %s [%ld]",
0153 fname.c_str(), argv[i-1], time);
0154 }
0155 else if ( ::strncmp(argv[i],"-print",3)==0 ) {
0156 level = dd4hep::printLevel(argv[++i]);
0157 printout(level,"DDDB","Setting print level in %s to %s [%d]",
0158 fname.c_str(), argv[i-1], level);
0159 }
0160 else if ( ::strncmp(argv[i],"-turns",3)==0 ) {
0161 turns = ::atol(argv[++i]);
0162 printout(level,"DDDB","Accumulate statistics in %s for %d [%s] turns.",
0163 fname.c_str(), turns, argv[i-1]);
0164 }
0165 else if ( ::strncmp(argv[i],"-access",3)==0 ) {
0166 accesses = ::atol(argv[++i]);
0167 printout(level,"DDDB","Accumulate statistics in %s for %d [%s] accesses per turn.",
0168 fname.c_str(), turns, argv[i-1]);
0169 }
0170 else if ( ::strcmp(argv[i],"--help")==0 ) {
0171 printout(level,"Plugin-Help","Usage: DDDB_DerivedAlignmentsTest --opt [--opt] ");
0172 printout(level,"Plugin-Help"," -time <string> Set event time Format: \"%%d-%%m-%%Y %%H:%%M:%%S\"");
0173 printout(level,"Plugin-Help"," -print <value> Printlevel for output ");
0174 printout(level,"Plugin-Help"," -help Print this help message ");
0175 ::exit(EINVAL);
0176 }
0177 }
0178 int ret;
0179 {
0180 AlignmentSelector selec(description, level);
0181 ConditionsManager manager(ConditionsManager::from(description));
0182 TStatistic cr_stat("Initialize"), re_acc_stat("Reaccess");
0183 const IOVType* iovType = manager.iovType("epoch");
0184 {
0185 TTimeStamp start;
0186 IOV iov(iovType, time);
0187 ret = selec.collect(manager,iov);
0188 TTimeStamp stop;
0189 cr_stat.Fill(stop.AsDouble()-start.AsDouble());
0190 }
0191 if ( ret == 1 ) {
0192 std::vector<IOV> iovs;
0193 for(int i=0; i<turns; ++i) {
0194 shared_ptr<ConditionsSlice> slice;
0195 iovs.push_back(IOV(iovType, time + (i+1)*3600));
0196 ret = selec.computeDependencies(slice,manager,iovs.back());
0197 }
0198
0199 for(int j = 0; j < accesses; ++j ) {
0200 for(int i = 0; i < turns; ++i ) {
0201 const IOV& iov = iovs[i];
0202 shared_ptr<ConditionsSlice> slice(new ConditionsSlice(manager,selec.content));
0203 TTimeStamp start;
0204 ConditionsManager::Result cres = manager.prepare(iov, *slice);
0205 TTimeStamp stop;
0206 re_acc_stat.Fill(stop.AsDouble()-start.AsDouble());
0207 printout(INFO,"DDDBAlign",
0208 "++ DDDB: REACCESS: %7ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) for IOV:%-12s",
0209 cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing, iov.str().c_str());
0210 }
0211 }
0212 }
0213 printout(INFO,"Statistics","+======= Summary: # of Runs: %3d ==========================================",turns);
0214 printout(INFO,"Statistics","+ DDDB: %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0215 cr_stat.GetName(), cr_stat.GetMean(), cr_stat.GetMeanErr(), cr_stat.GetRMS(), cr_stat.GetN());
0216 printout(INFO,"Statistics","+ DDDB: %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0217 selec.load_stat.GetName(), selec.load_stat.GetMean(), selec.load_stat.GetMeanErr(),
0218 selec.load_stat.GetRMS(), selec.load_stat.GetN());
0219 printout(INFO,"Statistics","+ DDDB: %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0220 selec.comp_stat.GetName(), selec.comp_stat.GetMean(), selec.comp_stat.GetMeanErr(),
0221 selec.comp_stat.GetRMS(), selec.comp_stat.GetN());
0222 printout(INFO,"Statistics","+ DDDB: %-12s: %11.5g +- %11.4g RMS = %11.5g N = %lld",
0223 re_acc_stat.GetName(), re_acc_stat.GetMean(), re_acc_stat.GetMeanErr(),
0224 re_acc_stat.GetRMS(), re_acc_stat.GetN());
0225 printout(INFO,"Statistics","+=========================================================================");
0226 }
0227 InstanceCount::dump();
0228 return ret;
0229 }
0230 }
0231 DECLARE_APPLY(DDDB_DerivedAlignmentsTest,dddb_derived_alignments)
0232
0233
0234 namespace {
0235
0236 long dddb_access_alignments(Detector& description, int argc, char** argv) {
0237 PrintLevel level = INFO;
0238 long time = detail::makeTime(2016,4,1,12);
0239 for(int i=0; i<argc; ++i) {
0240 if ( ::strcmp(argv[i],"-time")==0 ) {
0241 time = detail::makeTime(argv[++i],"%d-%m-%Y %H:%M:%S");
0242 printout(level,"DDDB","Setting event time in %s to %s [%ld]",
0243 Path(__FILE__).filename().c_str(), argv[i-1], time);
0244 }
0245 else if ( ::strcmp(argv[i],"-print")==0 ) {
0246 level = dd4hep::printLevel(argv[++i]);
0247 printout(level,"DDDB","Setting print level in %s to %s [%d]",
0248 Path(__FILE__).filename().c_str(), argv[i-1], level);
0249 }
0250 else if ( ::strcmp(argv[i],"--help")==0 ) {
0251 printout(level,"Plugin-Help","Usage: DDDB_AlignmentsAccessTest --opt [--opt] ");
0252 printout(level,"Plugin-Help"," -time <string> Set event time Format: \"%%d-%%m-%%Y %%H:%%M:%%S\"");
0253 printout(level,"Plugin-Help"," -print <value> Printlevel for output ");
0254 printout(level,"Plugin-Help"," -help Print this help message ");
0255 ::exit(EINVAL);
0256 }
0257 }
0258 AlignmentSelector selec(description,level);
0259 ConditionsManager manager(ConditionsManager::from(description));
0260 const IOVType* iovType = manager.iovType("epoch");
0261 IOV iov(iovType, time);
0262 int ret = selec.collect(manager,iov);
0263 if ( ret == 1 ) {
0264 shared_ptr<ConditionsSlice> slice;
0265 ret = selec.computeDependencies(slice,manager,iov, true);
0266 }
0267 return ret;
0268 }
0269 }
0270 DECLARE_APPLY(DDDB_AlignmentsAccessTest,dddb_access_alignments)
0271
0272