File indexing completed on 2025-01-31 09:20:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "Detector/DeVPConditionCalls.h"
0018 #include "DD4hep/DetectorProcessor.h"
0019 #include "DDDB/DDDBConversion.h"
0020
0021 using namespace gaudi;
0022
0023
0024 dd4hep::Condition DeVPStaticConditionCall::operator()(const ConditionKey& key, Context& context) {
0025 VPUpdateContext* ctxt = dynamic_cast<VPUpdateContext*>(context.parameter);
0026 KeyMaker km(key.hash);
0027 auto ide = ctxt->detectors.find(km.values.det_key);
0028 auto* cat = (*ide).second.second;
0029 DetElement det = (*ide).second.first;
0030 DeStatic s;
0031 if ( cat->classID == DeVPSensor::classID() )
0032 s = DeStatic(new detail::DeVPSensorStaticObject());
0033 else if ( cat->classID == DeVP::classID() )
0034 s = DeStatic(new detail::DeVPStaticObject());
0035 else
0036 s = DeStatic(new detail::DeVPGenericStaticObject());
0037 return s->fill_info(det, cat);
0038 }
0039
0040
0041 void DeVPStaticConditionCall::resolve(Condition c, Context& context) {
0042 DeStatic s(c);
0043 if ( s->clsID == DeVP::classID() ) {
0044 DeVPStatic vp = s;
0045 DeVPSensorStatic sens;
0046 DeVPGenericStatic side, support, module, ladder;
0047 std::vector<std::pair<DetElement, int> > elts;
0048 dd4hep::DetectorScanner(dd4hep::detElementsCollector(elts), s->detector);
0049
0050 vp->de_user |= VP::MAIN;
0051 vp->sensors.resize(200);
0052 for ( const auto& i : elts ) {
0053 DetElement de = i.first;
0054 KeyMaker key(de.key(), Keys::staticKey);
0055 DeStatic cond = context.condition(key.hash);
0056 const std::string& path = de.path();
0057 if ( path.find("/VPLeft") != std::string::npos || path.find("/VPRight") != std::string::npos ) {
0058 switch( i.second ) {
0059 case 0:
0060 break;
0061 case 1:
0062 side = cond;
0063 side->parent = vp.access();
0064 side->de_user |= VP::SIDE;
0065 vp->sides.push_back(side);
0066 printout(INFO,"DeVPStatic","Add Side[%03ld]: %s",vp->sides.size()-1,path.c_str());
0067 break;
0068 case 2:
0069 support = cond;
0070 support->parent = side.access();
0071 support->de_user |= VP::SUPPORT;
0072 vp->supports.push_back(support);
0073 printout(INFO,"DeVPStatic","Add Support[%03ld]: %s",vp->supports.size()-1,path.c_str());
0074 break;
0075 case 3:
0076 module = cond;
0077 module->parent = support.access();
0078 module->de_user |= VP::MODULE;
0079 vp->modules.push_back(module);
0080 printout(INFO,"DeVPStatic","Add Module[%03ld]: %s",vp->modules.size()-1,path.c_str());
0081 break;
0082 case 4:
0083 ladder = cond;
0084 ladder->parent = module.access();
0085 ladder->de_user |= VP::LADDER;
0086 vp->ladders.push_back(ladder);
0087 printout(INFO,"DeVPStatic","Add Ladder[%03ld]: %s",vp->ladders.size()-1,path.c_str());
0088 break;
0089 case 5:
0090 sens = cond;
0091 sens->parent = ladder.access();
0092 if ( sens->sensorNumber >= vp->sensors.size() )
0093 vp->sensors.resize(sens->sensorNumber+1);
0094 vp->sensors[sens->sensorNumber] = sens;
0095 ladder->sensors.push_back(sens);
0096 module->sensors.push_back(sens);
0097 support->sensors.push_back(sens);
0098 side->sensors.push_back(sens);
0099 printout(DEBUG,"DeVPStatic","Add Sensor[%03ld]: %s",long(sens->sensorNumber),path.c_str());
0100 break;
0101 default:
0102 break;
0103 }
0104 }
0105 else {
0106 printout(DEBUG,"DeVPStatic","Aux.DetElmenet: %s",path.c_str());
0107 }
0108 }
0109 }
0110 s->initialize();
0111 }
0112
0113
0114 dd4hep::Condition DeVPIOVConditionCall::operator()(const ConditionKey&, Context&) {
0115 DeIOV iov;
0116 if ( catalog->classID == DeVPSensor::classID() )
0117 iov = DeIOV(new detail::DeVPSensorObject());
0118 else if ( catalog->classID == DeVP::classID() )
0119 iov = DeIOV(new detail::DeVPObject());
0120 else
0121 iov = DeIOV(new detail::DeVPGenericObject());
0122 return iov->fill_info(detector, catalog);
0123 }
0124
0125
0126 void DeVPIOVConditionCall::resolve(Condition cond, Context& context) {
0127 DeIOV iov(cond);
0128 Condition::detkey_type det_key = iov->detector.key();
0129 KeyMaker kalign(det_key,dd4hep::align::Keys::alignmentKey);
0130 KeyMaker kstatic(det_key,Keys::staticKey);
0131
0132
0133 if ( !velo_context->alignments_done.isValid() ) {
0134 velo_context->alignments_done = context.condition(Keys::alignmentsComputedKey);
0135 }
0136
0137 std::vector<Condition> conds = context.conditions(det_key);
0138 iov->de_static = context.condition(kstatic.hash);
0139 iov->detectorAlignment = context.condition(kalign.hash);
0140 for ( Condition c : conds )
0141 iov->conditions.insert(std::make_pair(c.item_key(),c));
0142 iov->initialize();
0143 }
0144
0145 static void add_generic( detail::DeVPObject* vp,
0146 std::vector<DeVPGeneric>& cont,
0147 const std::vector<DeVPGenericStatic>& src,
0148 dd4hep::cond::ConditionUpdateContext& context)
0149 {
0150 for ( const auto& i : src ) {
0151 dd4hep::ConditionKey::KeyMaker key(i->detector.key(), Keys::deKey);
0152 DeVPGeneric gen = context.condition(key.hash);
0153 cont.push_back(gen);
0154 for ( const auto& j : i->sensors )
0155 gen->sensors.push_back(vp->sensors[j->sensorNumber]);
0156 printout(DEBUG,"DeVP","Add [%03ld]: %s",cont.size()-1,gen->detector.path().c_str());
0157 }
0158 }
0159
0160
0161 void DeVPConditionCall::resolve(Condition cond, Context& context) {
0162 DeIOV iov(cond);
0163 DeVP vp(cond);
0164 DeVPIOVConditionCall::resolve(cond, context);
0165 DeVPStatic s = vp.access()->vp_static;
0166
0167 vp->sensors.resize(s->sensors.size());
0168 for ( const auto& i : s->sensors ) {
0169 if ( i.isValid() ) {
0170 KeyMaker key(i->detector.key(), Keys::deKey);
0171 DeVPSensor sens = context.condition(key.hash);
0172 vp->sensors[i->sensorNumber] = sens;
0173 printout(DEBUG,"DeVP","Add Sensor[%03ld]: %s",long(i->sensorNumber),i->detector.path().c_str());
0174 }
0175 }
0176 add_generic(vp.ptr(), vp->sides, s->sides, context);
0177 add_generic(vp.ptr(), vp->supports, s->supports, context);
0178 add_generic(vp.ptr(), vp->modules, s->modules, context);
0179 add_generic(vp.ptr(), vp->ladders, s->ladders, context);
0180 }