File indexing completed on 2025-01-30 09:16:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/DetectorProcessor.h>
0017 #include <DD4hep/AlignmentsNominalMap.h>
0018 #include <DD4hep/detail/AlignmentsInterna.h>
0019 #include <DD4hep/detail/ConditionsInterna.h>
0020
0021 using namespace dd4hep;
0022 using align::Keys;
0023
0024
0025 AlignmentsNominalMap::AlignmentsNominalMap(DetElement wrld) : world(wrld) {
0026 }
0027
0028
0029 bool AlignmentsNominalMap::insert(DetElement detector,
0030 Condition::itemkey_type key,
0031 Condition condition) {
0032 auto res = data.emplace(ConditionKey(detector,key).hash,condition);
0033 return res.second;
0034 }
0035
0036
0037 Condition AlignmentsNominalMap::get(DetElement detector, Condition::itemkey_type key) const {
0038 auto res = data.find(ConditionKey(detector,key).hash);
0039 if ( res == data.end() ) {
0040 if ( key == Keys::alignmentKey ) {
0041 return Condition(detector.nominal().ptr());
0042 }
0043 return Condition();
0044 }
0045 return res->second;
0046 }
0047
0048
0049 void AlignmentsNominalMap::scan(const Condition::Processor& processor) const {
0050
0051
0052
0053
0054
0055
0056
0057 struct Scanner {
0058 const Condition::Processor& proc;
0059
0060 Scanner(const Condition::Processor& p) : proc(p) { }
0061
0062 int operator()(DetElement de, int ) const {
0063 Condition c = de.nominal();
0064 return proc(c);
0065 }
0066 } scanner(processor);
0067
0068
0069 for( const auto& i : data )
0070 processor(i);
0071
0072
0073 if ( world.isValid() ) {
0074 DetectorScanner().scan(scanner,world,0,true);
0075 return;
0076 }
0077 dd4hep::except("AlignmentsNominalMap",
0078 "Cannot scan conditions map for conditions of an invalid top level detector element!");
0079 }
0080
0081
0082 void AlignmentsNominalMap::scan(DetElement detector,
0083 Condition::itemkey_type lower,
0084 Condition::itemkey_type upper,
0085 const Condition::Processor& processor) const {
0086
0087 if ( detector.isValid() ) {
0088 Condition::detkey_type det_key = detector.key();
0089 Condition::key_type low = ConditionKey::KeyMaker(det_key,lower).hash;
0090 Condition::key_type up = ConditionKey::KeyMaker(det_key,upper).hash;
0091 ConditionKey::KeyMaker align_key(detector.key(),Keys::alignmentKey);
0092
0093 for(auto i=data.lower_bound(low); i != data.end() && (*i).first <= up; ++i) {
0094 ConditionKey::KeyMaker k((*i).first);
0095 if ( low <= k.hash && up >= k.hash ) {
0096 processor((*i).second);
0097 if ( k.hash == align_key.hash ) {
0098 align_key.hash = 0;
0099 }
0100 }
0101 }
0102 if ( align_key.hash ) {
0103 if ( lower <= Keys::alignmentKey && upper >= Keys::alignmentKey ) {
0104 Condition c(detector.nominal().ptr());
0105 processor(c);
0106 }
0107 }
0108 return;
0109 }
0110 dd4hep::except("AlignmentsNominalMap",
0111 "Cannot scan conditions map for conditions of an invalid detector element!");
0112 }