Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:10

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