File indexing completed on 2025-01-18 09:14:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "DD4hep/Plugins.h"
0022 #include "DD4hep/Printout.h"
0023 #include "DD4hep/Factories.h"
0024 #include "DD4hep/DetectorTools.h"
0025 #include "DD4hep/ConditionsPrinter.h"
0026 #include "DD4hep/DetectorProcessor.h"
0027
0028 #include "DDCond/ConditionsSlice.h"
0029 #include "DDCond/ConditionsManager.h"
0030 #include "DDCond/ConditionsIOVPool.h"
0031
0032 #include "DDDB/DDDBHelper.h"
0033 #include "DDDB/DDDBReader.h"
0034 #include "DDDB/DDDBConversion.h"
0035
0036 #include "DetService.h"
0037 #include "Detector/DeVelo.h"
0038 #include "Detector/DeAlignmentCall.h"
0039 #include "Detector/DeVeloConditionCalls.h"
0040
0041 using namespace std;
0042 using namespace gaudi;
0043
0044
0045
0046
0047
0048
0049 namespace {
0050 dd4hep::PrintLevel s_PrintLevel = INFO;
0051 }
0052
0053
0054
0055 namespace {
0056
0057
0058
0059
0060
0061
0062
0063 long dump_det(dd4hep::Detector& description, int argc, char** argv) {
0064
0065
0066
0067
0068
0069
0070
0071 struct DumpActor {
0072 dd4hep::DetElement m_de;
0073 unique_ptr<VeloUpdateContext> m_context;
0074
0075 dd4hep::DDDB::DDDBReader* m_reader = 0;
0076 shared_ptr<IDetService> m_service;
0077
0078
0079 void configReader(long iov_start, long iov_end) {
0080 try {
0081 const IDetService::IOVType* iov_typ = m_service->iovType("epoch");
0082 dd4hep::IOV iov_range(iov_typ);
0083 iov_range.keyData.first = iov_start;
0084 iov_range.keyData.second = iov_end;
0085 m_reader->property("ValidityLower").set(iov_range.keyData.first);
0086 m_reader->property("ValidityUpper").set(iov_range.keyData.second);
0087 printout(INFO,"ConditionsManager","+++ Configure file based reader for IOV:%s",
0088 iov_range.str().c_str());
0089 }
0090 catch(...) {
0091 }
0092 }
0093
0094
0095 DumpActor(dd4hep::Detector& dsc, const string& path) {
0096 IDetService::Slice slice;
0097 IDetService::Content cont;
0098 vector<pair<dd4hep::DetElement, int> > elts;
0099 dd4hep::DDDB::DDDBHelper* helper = dsc.extension<dd4hep::DDDB::DDDBHelper>(false);
0100 dd4hep::cond::ConditionsManager manager = dd4hep::cond::ConditionsManager(dsc);
0101
0102 m_de = dd4hep::detail::tools::findElement(dsc, path);
0103 m_reader = helper->reader<dd4hep::DDDB::DDDBReader>();
0104 m_service.reset(new DetService(manager));
0105 const IDetService::IOVType* iov_typ = m_service->iovType("epoch");
0106 dd4hep::IOV iov(iov_typ,dd4hep::detail::makeTime(2018,1,1));
0107 IDetService::Content content = m_service->openContent("DDDB");
0108 configReader(dd4hep::detail::makeTime(2008,1,1), dd4hep::detail::makeTime(2018,12,31));
0109
0110 cont.reset(new dd4hep::cond::ConditionsContent());
0111 slice.reset(new dd4hep::cond::ConditionsSlice(manager,cont));
0112 dd4hep::cond::fill_content(manager, *cont, *iov_typ);
0113 dd4hep::cond::ConditionsManager::Result res = manager.prepare(iov, *slice);
0114 printout(dd4hep::ALWAYS,"Prepare","Total %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) of IOV %s",
0115 res.total(), res.selected, res.loaded, res.computed, res.missing, iov.str().c_str());
0116
0117 m_context.reset(new VeloUpdateContext());
0118 dd4hep::DetectorScanner(dd4hep::detElementsCollector(elts), m_de);
0119 dd4hep::cond::DependencyBuilder align_builder(dsc.world(),
0120 Keys::alignmentsComputedKey,
0121 make_shared<DeAlignmentCall>(m_de));
0122 auto* dep = align_builder.release();
0123 dep->target.hash = Keys::alignmentsComputedKey;
0124 m_service->addContent(content, dep);
0125
0126 auto static_update = make_shared<DeVeloStaticConditionCall>();
0127 for(const auto& e : elts) {
0128 dd4hep::DetElement de = e.first;
0129 dd4hep::DDDB::DDDBCatalog* cat = de.extension<dd4hep::DDDB::DDDBCatalog>();
0130 dd4hep::Condition::detkey_type det_key = de.key();
0131 dd4hep::ConditionKey::KeyMaker lower(det_key, dd4hep::Condition::FIRST_ITEM_KEY);
0132 dd4hep::ConditionKey::KeyMaker upper(det_key, dd4hep::Condition::LAST_ITEM_KEY);
0133 printout(DEBUG, "ServiceTest","Processing %ld class %d -> %s",
0134 e.second, cat->classID, de.path().c_str());
0135 m_context->detectors.insert(make_pair(det_key,make_pair(de,cat)));
0136 {
0137 auto first = cont->conditions().lower_bound(lower.hash);
0138 for(; first != cont->conditions().end() && (*first).first <= upper.hash; ++first) {
0139 dd4hep::cond::ConditionsLoadInfo* ptr = (*first).second->addRef();
0140 m_service->addContent(content, (*first).first, *ptr->data<string>());
0141 }
0142 }
0143 {
0144 auto first = cont->derived().lower_bound(lower.hash);
0145 for(; first != cont->derived().end() && (*first).first <= upper.hash; ++first) {
0146 m_service->addContent(content, (*first).second);
0147 }
0148 }
0149
0150 dd4hep::cond::DependencyBuilder static_builder(de, Keys::staticKey, static_update);
0151 m_service->addContent(content, static_builder.release());
0152
0153 shared_ptr<dd4hep::cond::ConditionUpdateCall> call = ( e.first == m_de )
0154 ? make_shared<DeVeloConditionCall>(de, cat, m_context.get())
0155 : make_shared<DeVeloIOVConditionCall>(de, cat, m_context.get());
0156 dd4hep::cond::DependencyBuilder iov_builder(de, Keys::deKey, call);
0157 m_service->addContent(content, iov_builder.release());
0158 }
0159 m_service->closeContent(content);
0160 manager.clear();
0161 }
0162
0163
0164 ~DumpActor() {
0165 }
0166
0167
0168 long dump() {
0169 size_t num_round = 10;
0170 long daq_start = dd4hep::detail::makeTime(2016,5,20,0,0,0);
0171 shared_ptr<dd4hep::cond::ConditionsSlice> slice;
0172 const IDetService::IOVType* iov_typ = m_service->iovType("epoch");
0173
0174 printout(INFO,"ConditionsManager","+++ Starting conditions dump loop");
0175 for(size_t i=0; i<num_round; ++i) {
0176 long event_stamp = daq_start + (i*3600) + 1800;
0177 dd4hep::IOV iov(iov_typ, event_stamp);
0178 configReader(event_stamp-1800, event_stamp+1799);
0179
0180 m_context->alignments_done = dd4hep::Condition();
0181
0182 slice = m_service->project("DDDB", m_context.get(), "epoch", event_stamp);
0183 printout(INFO,"ConditionsManager","+++ Prepared slice Round: %ld for IOV:%s",
0184 i, slice->iov().str().c_str());
0185
0186 DeVelo devp = slice->get(m_de,Keys::deKey);
0187
0188 DetectorElement<DeVelo> detVP = devp;
0189 cout << "TEST: Got detector element:"
0190 << " " << detVP.conditions().size()
0191 << " " << detVP.detector().path()
0192 << " " << detVP.detectorAlignment().name()
0193 << " " << detVP.conditions().size()
0194 << endl;
0195 try {
0196 DeVeloGeneric deGEN = devp;
0197 cout << " " << deGEN.conditions().size()
0198 << " " << deGEN.children().size()
0199 << endl;
0200 }
0201 catch(const exception& e) {
0202 cout << "Exception(This is GOOD!): " << e.what() << endl;
0203 }
0204 }
0205 m_service->cleanup(dd4hep::cond::ConditionsFullCleanup());
0206 printout(dd4hep::ALWAYS,"TestSummary",
0207 "Total %ld slices created and accessed during the test.", num_round);
0208
0209 printout(dd4hep::ALWAYS,"ServiceTest","Test finished....");
0210 return 1;
0211 }
0212 };
0213
0214 dd4hep::setPrintFormat("%-18s %5s %s");
0215 for(int i=0; i<argc; ++i) {
0216 if ( ::strcmp(argv[i],"-print")==0 ) {
0217 s_PrintLevel = dd4hep::printLevel(argv[++i]);
0218 printout(INFO,"ServiceTest","Setting print level for %s to %s [%d]",__FILE__,argv[i-1],s_PrintLevel);
0219 }
0220 else if ( ::strcmp(argv[i],"--help")==0 ) {
0221 printout(INFO,"Plugin-Help","Usage: DDDB_DeVeloServiceTest --opt [--opt] ");
0222 printout(INFO,"Plugin-Help"," -print <value> Printlevel for output ");
0223 printout(INFO,"Plugin-Help"," -help Print this help message ");
0224 return 0;
0225 }
0226 }
0227 DumpActor actor(description, "/world/LHCb/BeforeMagnetRegion/Velo");
0228 return actor.dump();
0229 }
0230 }
0231
0232 using namespace dd4hep;
0233 DECLARE_APPLY(DDDB_DeVeloServiceTest,dump_det)
0234