File indexing completed on 2024-04-06 12:02:15
0001 #include "CondFormats/HcalObjects/interface/HcalDetIdTransform.h"
0002 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0003
0004 #include "FWCore/Utilities/interface/Exception.h"
0005
0006 namespace HcalDetIdTransform {
0007 unsigned transform(const HcalDetId& id, const unsigned transformCode) {
0008 static const int ietaShift = 1024;
0009 static const int maxHcalDepth = 64;
0010
0011 if (transformCode >= N_TRANSFORMS)
0012 throw cms::Exception(
0013 "In HcalDetIdTransform::transform:"
0014 " invalid transform code");
0015 unsigned t = 0;
0016 switch (transformCode) {
0017 case RAWID:
0018 t = id.rawId();
0019 break;
0020
0021 case IETA:
0022 t = id.ieta() + ietaShift;
0023 break;
0024
0025 case IETAABS:
0026 t = id.ietaAbs();
0027 break;
0028
0029 case SUBDET:
0030 t = id.subdetId();
0031 break;
0032
0033 case IETADEPTH:
0034 t = (id.ieta() + ietaShift) * maxHcalDepth + id.depth();
0035 break;
0036
0037 case IETAABSDEPTH:
0038 t = id.ietaAbs() * maxHcalDepth + id.depth();
0039 break;
0040
0041 default:
0042 throw cms::Exception(
0043 "In HcalDetIdTransform::transform:"
0044 " unhandled switch clause. This is a bug."
0045 " Please report.");
0046 }
0047 return t;
0048 }
0049
0050 void validateCode(const unsigned transformCode) {
0051 if (transformCode >= N_TRANSFORMS)
0052 throw cms::Exception(
0053 "In HcalDetIdTransform::validateCode:"
0054 " invalid transform code");
0055 }
0056 }