CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/CondFormats/HcalObjects/src/HcalCondObjectContainerBase.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00002 #include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
00003 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00004 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
00005 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00006 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
00007 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 
00011 HcalCondObjectContainerBase::HcalCondObjectContainerBase(const HcalTopology* topo) : packedIndexVersion_(0), topo_(topo) { 
00012   if (topo_) packedIndexVersion_=topo_->topoVersion();
00013 }
00014 
00015 void HcalCondObjectContainerBase::setTopo(const HcalTopology* topo) const {
00016   if (topo && !topo->denseIdConsistent(packedIndexVersion_)) {
00017     edm::LogError("HCAL") << std::string("Inconsistent dense packing between current topology (") << topo->topoVersion() << ") and calibration object (" << packedIndexVersion_ << ")";
00018   }
00019   topo_=topo;
00020 }
00021 void HcalCondObjectContainerBase::setTopo(const HcalTopology* topo) {
00022   if (topo && !topo->denseIdConsistent(packedIndexVersion_)) {
00023     edm::LogError("HCAL") << "Inconsistent dense packing between current topology (" << topo->topoVersion() << ") and calibration object (" << packedIndexVersion_ << ")";
00024   }
00025   topo_=topo;  
00026 }
00027 
00028 unsigned int HcalCondObjectContainerBase::indexFor(DetId fId) const { 
00029   unsigned int retval=0xFFFFFFFFu;
00030   if (!topo_) {
00031     edm::LogError("HCAL") << "Topology pointer not set, HCAL conditions non-functional";
00032     throw cms::Exception("Topology pointer not set, HCAL conditions non-functional");
00033     return retval;
00034   }
00035 
00036   if (fId.det()==DetId::Hcal) {
00037     switch (HcalSubdetector(fId.subdetId())) {
00038     case(HcalBarrel) : retval=topo_->detId2denseIdHB(fId); break;
00039     case(HcalEndcap) : retval=topo_->detId2denseIdHE(fId); break;
00040     case(HcalOuter) : retval=topo_->detId2denseIdHO(fId); break;
00041     case(HcalForward) : retval=topo_->detId2denseIdHF(fId); break;
00042     case(HcalTriggerTower) : retval=topo_->detId2denseIdHT(fId); break;
00043     case(HcalOther) : if (extractOther(fId)==HcalCalibration)
00044         retval=topo_->detId2denseIdCALIB(fId);
00045       break; 
00046     default: break;
00047     }
00048   } else if (fId.det()==DetId::Calo) {
00049     if (fId.subdetId()==HcalCastorDetId::SubdetectorId) {
00050       // the historical packing from HcalGeneric is different from HcalCastorDetId, so we clone the old packing here.
00051       HcalCastorDetId tid(fId); 
00052       int zside = tid.zside();
00053       int sector = tid.sector();
00054       int module = tid.module();
00055       static const int CASTORhalf=224;
00056 
00057       int index = 14*(sector-1) + (module-1);
00058       if (zside == -1) index += CASTORhalf;
00059 
00060       retval=(unsigned int)(index);
00061     } else if (fId.subdetId()==HcalZDCDetId::SubdetectorId) {
00062       HcalZDCDetId direct(fId);
00063       // THIS IS A HORRIBLE HACK because there were _two_ dense indices for ZDC differing in their handling of +/-z
00064       HcalZDCDetId swapZ(direct.section(),direct.zside()<0,direct.channel());
00065       retval=swapZ.denseIndex();
00066     }
00067   }
00068   return retval;
00069 }
00070 
00071 unsigned int HcalCondObjectContainerBase::sizeFor(DetId fId) const {
00072   unsigned int retval=0;
00073 
00074   if (!topo_) {
00075     edm::LogError("HCAL") << "Topology pointer not set, HCAL conditions non-functional";
00076     throw cms::Exception("Topology pointer not set, HCAL conditions non-functional");
00077     return retval;
00078   }
00079 
00080   if (fId.det()==DetId::Hcal) {
00081     switch (HcalSubdetector(fId.subdetId())) {
00082     case(HcalBarrel) : retval=topo_->getHBSize(); break;
00083     case(HcalEndcap) : retval=topo_->getHESize(); break;
00084     case(HcalOuter) : retval=topo_->getHOSize(); break;
00085     case(HcalForward) : retval=topo_->getHFSize(); break;
00086     case(HcalTriggerTower) : retval=topo_->getHTSize(); break;
00087     case(HcalOther) : if (extractOther(fId)==HcalCalibration) retval=topo_->getCALIBSize();
00088       break; 
00089     default: break;
00090     }
00091   } else if (fId.det()==DetId::Calo) {
00092     if (fId.subdetId()==HcalCastorDetId::SubdetectorId) {
00093       retval=HcalCastorDetId::kSizeForDenseIndexing;
00094     } else if (fId.subdetId()==HcalZDCDetId::SubdetectorId) {
00095       retval=HcalZDCDetId::kSizeForDenseIndexing;
00096     }
00097   }
00098   return retval;
00099 }
00100 
00101 std::string HcalCondObjectContainerBase::textForId(const DetId& id) const {
00102   std::ostringstream os;
00103   os << std::hex << "(0x" << id.rawId() << ") " << std::dec;
00104 
00105   if (id.det()==DetId::Hcal) {
00106     switch (HcalSubdetector(id.subdetId())) {
00107     case(HcalBarrel) : 
00108     case(HcalEndcap) : 
00109     case(HcalOuter) : 
00110     case(HcalForward) : os << HcalDetId(id); break;
00111     case(HcalTriggerTower) : os << HcalTrigTowerDetId(id); break;
00112     case(HcalOther) : 
00113       if (extractOther(id)==HcalCalibration) os << HcalCalibDetId(id);
00114       break; 
00115     default: break;
00116     }
00117   } else if (id.det()==DetId::Calo) {
00118     if (id.subdetId()==HcalCastorDetId::SubdetectorId) {
00119       os << HcalCastorDetId(id);
00120     } else if (id.subdetId()==HcalZDCDetId::SubdetectorId) {
00121       os << HcalZDCDetId(id);
00122     }
00123   }  
00124   return os.str();
00125 }