CMS 3D CMS Logo

CastorText2DetIdConverter.cc
Go to the documentation of this file.
1 
3 #include <cstdlib>
4 #include <iostream>
5 #include <iomanip>
6 #include <cstdio>
7 
9 
13 
15 
16 namespace {
17  std::string strip(const std::string& fString) {
18  if (fString.empty())
19  return fString;
20  int startIndex = fString.find_first_not_of(" \t\n");
21  int endIndex = fString.find_last_not_of(" \t\n");
22  return fString.substr(startIndex, (endIndex - startIndex) + 1);
23  }
24 } // namespace
25 
27  const std::string& fField1,
28  const std::string& fField2,
29  const std::string& fField3) {
30  if (!init(fFlavor, fField1, fField2, fField3)) {
31  std::cerr << "CastorText2DetIdConverter::CastorText2DetIdConverter-> Can not initiate detId from items: " << fFlavor
32  << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
33  throw cms::Exception("HcalGenDetId initialization error")
34  << " Can not initiate detId from items: " << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3
35  << std::endl;
36  }
37 }
38 
40 
42 
44  bool result = true;
45  flavorName = "UNKNOWN";
46  mId = fId;
47  HcalGenericDetId genId(mId);
48  if (fId == HcalDetId::Undefined) {
49  flavorName = "NA";
50  }
51 
52  else if (genId.isHcalCastorDetId()) {
53  HcalCastorDetId castorId(mId);
54  switch (castorId.section()) {
56  flavorName = "CASTOR_EM";
57  break;
59  flavorName = "CASTOR_HAD";
60  break;
61  default:
62  result = false;
63  }
64  setField(1, castorId.zside());
65  setField(2, castorId.sector());
66  setField(3, castorId.module());
67  }
68 
69  else {
70  flavorName = "UNKNOWN_FLAVOR";
71  std::cerr << "CastorText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId()
72  << std::endl;
73  result = false;
74  }
75  return result;
76 }
77 
79  const std::string& fField1,
80  const std::string& fField2,
81  const std::string& fField3) {
82  bool result = true;
83  flavorName = strip(fFlavor);
84  field1 = strip(fField1);
85  field2 = strip(fField2);
86  field3 = strip(fField3);
87  if (flavorName.find("CASTOR_") == 0) {
89  flavorName == "CASTOR_EM" ? HcalCastorDetId::EM
92  }
93 
94  else {
95  std::cerr << "CastorText2DetIdConverter::init-> Unknown DetId flavor: " << flavorName << std::endl;
96  result = false;
97  }
98  return result;
99 }
100 
102  char* endptr;
103  const char* nptr = i == 1 ? field1.c_str() : i == 2 ? field2.c_str() : field3.c_str();
104  long result = strtol(nptr, &endptr, 0);
105  if (*nptr != '\0' && *endptr == '\0') {
106  return result;
107  }
108  if (*nptr != '\0') {
109  std::cerr << "CastorText2DetIdConverter::getField-> Can not convert string " << nptr
110  << " to int. Bad symbol: " << *endptr << std::endl;
111  }
112  return 0;
113 }
114 
115 void CastorText2DetIdConverter::setField(int i, int fValue) {
116  char buffer[128];
117  sprintf(buffer, "%d", fValue);
118  if (i == 1)
119  field1 = buffer;
120  else if (i == 2)
121  field2 = buffer;
122  else
123  field3 = buffer;
124 }
125 
127  return flavorName + " " + field1 + " " + field2 + " " + field3;
128 }
HcalDetId::Undefined
static const HcalDetId Undefined
Definition: HcalDetId.h:273
mps_fire.i
i
Definition: mps_fire.py:428
CastorText2DetIdConverter::field1
std::string field1
Definition: CastorText2DetIdConverter.h:40
HcalGenericDetId
Definition: HcalGenericDetId.h:15
CastorText2DetIdConverter::field2
std::string field2
Definition: CastorText2DetIdConverter.h:41
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
CastorText2DetIdConverter::getField
int getField(int i) const
Definition: CastorText2DetIdConverter.cc:101
HcalGenericDetId.h
HcalCastorDetId::Section
Section
Definition: HcalCastorDetId.h:25
HcalCastorDetId::Unknown
Definition: HcalCastorDetId.h:25
CastorText2DetIdConverter::setField
void setField(int i, int fValue)
Definition: CastorText2DetIdConverter.cc:115
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
DetId
Definition: DetId.h:17
CastorText2DetIdConverter::flavorName
std::string flavorName
Definition: CastorText2DetIdConverter.h:39
CastorText2DetIdConverter::CastorText2DetIdConverter
CastorText2DetIdConverter(const std::string &fFlavor="NA", const std::string &fField1="0", const std::string &fField2="0", const std::string &fField3="0")
Definition: CastorText2DetIdConverter.cc:26
HcalCastorDetId::section
Section section() const
get the section
Definition: HcalCastorDetId.cc:49
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalCastorDetId
Definition: HcalCastorDetId.h:23
HcalCastorDetId::module
int module() const
get the module (1-2 for EM, 1-12 for HAD)
Definition: HcalCastorDetId.h:58
CastorText2DetIdConverter::field3
std::string field3
Definition: CastorText2DetIdConverter.h:42
CastorText2DetIdConverter::mId
DetId mId
Definition: CastorText2DetIdConverter.h:43
HcalDetId.h
HcalCastorDetId::zside
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalCastorDetId.h:50
HcalCastorDetId::sector
int sector() const
get the sector (1-16)
Definition: HcalCastorDetId.h:62
CastorText2DetIdConverter.h
HcalGenericDetId::isHcalCastorDetId
bool isHcalCastorDetId() const
Definition: HcalGenericDetId.cc:84
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CastorText2DetIdConverter::toString
std::string toString() const
Definition: CastorText2DetIdConverter.cc:126
Exception
Definition: hltDiff.cc:245
hgcalPlots.section
section
Definition: hgcalPlots.py:2670
HcalCastorDetId::HAD
Definition: HcalCastorDetId.h:25
Exception.h
mps_fire.result
result
Definition: mps_fire.py:311
HcalCastorDetId.h
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
CastorText2DetIdConverter::isHcalCastorDetId
bool isHcalCastorDetId() const
Definition: CastorText2DetIdConverter.cc:41
CastorText2DetIdConverter::init
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
Definition: CastorText2DetIdConverter.cc:78
HcalCastorDetId::EM
Definition: HcalCastorDetId.h:25