File indexing completed on 2024-09-20 04:57:32
0001 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0002 #include "Geometry/HcalCommonData/interface/HcalTopologyMode.h"
0003 #include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
0004 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
0005 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
0006 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
0007 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
0008 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/Utilities/interface/Exception.h"
0011
0012 HcalCondObjectContainerBase::HcalCondObjectContainerBase(const HcalTopology* topo)
0013 : packedIndexVersion_(0), topo_(topo), kSizeForDenseIndexing_(HcalZDCDetId::kSizeForDenseIndexingRun1) {
0014 if (topo) {
0015 packedIndexVersion_ = topo->topoVersion();
0016 HcalTopologyMode::Mode mode = topo->mode();
0017 kSizeForDenseIndexing_ = (((mode == HcalTopologyMode::Run3) || (mode == HcalTopologyMode::Run4))
0018 ? HcalZDCDetId::kSizeForDenseIndexingRun3
0019 : HcalZDCDetId::kSizeForDenseIndexingRun1);
0020 }
0021 }
0022
0023 void HcalCondObjectContainerBase::setTopo(const HcalTopology* topo) {
0024 if (topo) {
0025 if ((packedIndexVersion_ != 0) && (!topo->denseIdConsistent(packedIndexVersion_)))
0026 edm::LogError("HCAL") << std::string("Inconsistent dense packing between current topology (")
0027 << topo->topoVersion() << ") and calibration object (" << packedIndexVersion_ << ")";
0028 topo_ = topo;
0029 packedIndexVersion_ = topo->topoVersion();
0030 kSizeForDenseIndexing_ = ((packedIndexVersion_ >= 10) ? HcalZDCDetId::kSizeForDenseIndexingRun3
0031 : HcalZDCDetId::kSizeForDenseIndexingRun1);
0032 } else {
0033 edm::LogError("HCAL") << "Illegal call to HcalCondObjectContainerBase with a null pointer";
0034 }
0035 }
0036
0037 unsigned int HcalCondObjectContainerBase::indexFor(DetId fId) const {
0038 unsigned int retval = 0xFFFFFFFFu;
0039 if (!topo()) {
0040 edm::LogError("HCAL") << "Topology pointer not set, HCAL conditions non-functional";
0041 throw cms::Exception("Topology pointer not set, HCAL conditions non-functional");
0042 return retval;
0043 }
0044
0045 if (fId.det() == DetId::Hcal) {
0046 switch (HcalSubdetector(fId.subdetId())) {
0047 case (HcalBarrel):
0048 retval = topo()->detId2denseIdHB(fId);
0049 break;
0050 case (HcalEndcap):
0051 retval = topo()->detId2denseIdHE(fId);
0052 break;
0053 case (HcalOuter):
0054 retval = topo()->detId2denseIdHO(fId);
0055 break;
0056 case (HcalForward):
0057 retval = topo()->detId2denseIdHF(fId);
0058 break;
0059 case (HcalTriggerTower):
0060 retval = topo()->detId2denseIdHT(fId);
0061 break;
0062 case (HcalOther):
0063 if (extractOther(fId) == HcalCalibration)
0064 retval = topo()->detId2denseIdCALIB(fId);
0065 break;
0066 default:
0067 break;
0068 }
0069 } else if (fId.det() == DetId::Calo) {
0070 if (fId.subdetId() == HcalCastorDetId::SubdetectorId) {
0071
0072 HcalCastorDetId tid(fId);
0073 int zside = tid.zside();
0074 int sector = tid.sector();
0075 int module = tid.module();
0076 static const int CASTORhalf = 224;
0077
0078 int index = 14 * (sector - 1) + (module - 1);
0079 if (zside == -1)
0080 index += CASTORhalf;
0081
0082 retval = (unsigned int)(index);
0083 } else if (fId.subdetId() == HcalZDCDetId::SubdetectorId) {
0084 HcalZDCDetId direct(fId);
0085
0086 HcalZDCDetId swapZ(direct.section(), direct.zside() < 0, direct.channel());
0087 retval = swapZ.denseIndex();
0088 }
0089 }
0090 return retval;
0091 }
0092
0093 unsigned int HcalCondObjectContainerBase::sizeFor(DetId fId) const {
0094 unsigned int retval = 0;
0095
0096 if (!topo()) {
0097 edm::LogError("HCAL") << "Topology pointer not set, HCAL conditions non-functional";
0098 throw cms::Exception("Topology pointer not set, HCAL conditions non-functional");
0099 return retval;
0100 }
0101
0102 if (fId.det() == DetId::Hcal) {
0103 switch (HcalSubdetector(fId.subdetId())) {
0104 case (HcalBarrel):
0105 retval = topo()->getHBSize();
0106 break;
0107 case (HcalEndcap):
0108 retval = topo()->getHESize();
0109 break;
0110 case (HcalOuter):
0111 retval = topo()->getHOSize();
0112 break;
0113 case (HcalForward):
0114 retval = topo()->getHFSize();
0115 break;
0116 case (HcalTriggerTower):
0117 retval = topo()->getHTSize();
0118 break;
0119 case (HcalOther):
0120 if (extractOther(fId) == HcalCalibration)
0121 retval = topo()->getCALIBSize();
0122 break;
0123 default:
0124 break;
0125 }
0126 } else if (fId.det() == DetId::Calo) {
0127 if (fId.subdetId() == HcalCastorDetId::SubdetectorId) {
0128 retval = HcalCastorDetId::kSizeForDenseIndexing;
0129 } else if (fId.subdetId() == HcalZDCDetId::SubdetectorId) {
0130 retval = kSizeForDenseIndexing_;
0131 }
0132 }
0133 return retval;
0134 }
0135
0136 std::string HcalCondObjectContainerBase::textForId(const DetId& id) const {
0137 std::ostringstream os;
0138 os << std::hex << "(0x" << id.rawId() << ") " << std::dec;
0139
0140 if (id.det() == DetId::Hcal) {
0141 switch (HcalSubdetector(id.subdetId())) {
0142 case (HcalBarrel):
0143 case (HcalEndcap):
0144 case (HcalOuter):
0145 case (HcalForward):
0146 os << HcalDetId(id);
0147 break;
0148 case (HcalTriggerTower):
0149 os << HcalTrigTowerDetId(id);
0150 break;
0151 case (HcalOther):
0152 if (extractOther(id) == HcalCalibration)
0153 os << HcalCalibDetId(id);
0154 break;
0155 default:
0156 break;
0157 }
0158 } else if (id.det() == DetId::Calo) {
0159 if (id.subdetId() == HcalCastorDetId::SubdetectorId) {
0160 os << HcalCastorDetId(id);
0161 } else if (id.subdetId() == HcalZDCDetId::SubdetectorId) {
0162 os << HcalZDCDetId(id);
0163 }
0164 }
0165 return os.str();
0166 }