CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CastorText2DetIdConverter Class Reference

#include <CastorText2DetIdConverter.h>

Public Member Functions

 CastorText2DetIdConverter (const std::string &fFlavor="NA", const std::string &fField1="0", const std::string &fField2="0", const std::string &fField3="0")
 
 CastorText2DetIdConverter (DetId fId)
 
int getField (int i) const
 
const std::string & getField1 () const
 
const std::string & getField2 () const
 
const std::string & getField3 () const
 
const std::string & getFlavor () const
 
DetId getId () const
 
bool isHcalCastorDetId () const
 
std::string toString () const
 

Private Member Functions

bool init (const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
 
bool init (DetId fId)
 
void setField (int i, int fValue)
 

Private Attributes

std::string field1
 
std::string field2
 
std::string field3
 
std::string flavorName
 
DetId mId
 

Detailed Description

Converts any flavour of HcalDetId to/from ascii strings

Definition at line 12 of file CastorText2DetIdConverter.h.

Constructor & Destructor Documentation

◆ CastorText2DetIdConverter() [1/2]

CastorText2DetIdConverter::CastorText2DetIdConverter ( const std::string &  fFlavor = "NA",
const std::string &  fField1 = "0",
const std::string &  fField2 = "0",
const std::string &  fField3 = "0" 
)

Definition at line 26 of file CastorText2DetIdConverter.cc.

29  {
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 }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, Exception, and init().

◆ CastorText2DetIdConverter() [2/2]

CastorText2DetIdConverter::CastorText2DetIdConverter ( DetId  fId)

Definition at line 39 of file CastorText2DetIdConverter.cc.

39 { init(fId); }

References init().

Member Function Documentation

◆ getField()

int CastorText2DetIdConverter::getField ( int  i) const

Definition at line 101 of file CastorText2DetIdConverter.cc.

101  {
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 }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, field1, field2, field3, mps_fire::i, and mps_fire::result.

Referenced by init().

◆ getField1()

const std::string& CastorText2DetIdConverter::getField1 ( ) const
inline

Definition at line 25 of file CastorText2DetIdConverter.h.

25 { return field1; }

References field1.

◆ getField2()

const std::string& CastorText2DetIdConverter::getField2 ( ) const
inline

Definition at line 26 of file CastorText2DetIdConverter.h.

26 { return field2; }

References field2.

◆ getField3()

const std::string& CastorText2DetIdConverter::getField3 ( ) const
inline

Definition at line 27 of file CastorText2DetIdConverter.h.

27 { return field3; }

References field3.

◆ getFlavor()

const std::string& CastorText2DetIdConverter::getFlavor ( ) const
inline

Definition at line 24 of file CastorText2DetIdConverter.h.

24 { return flavorName; }

References flavorName.

◆ getId()

DetId CastorText2DetIdConverter::getId ( ) const
inline

Definition at line 28 of file CastorText2DetIdConverter.h.

28 { return mId; }

References mId.

◆ init() [1/2]

bool CastorText2DetIdConverter::init ( const std::string &  fFlavor,
const std::string &  fField1,
const std::string &  fField2,
const std::string &  fField3 
)
private

Definition at line 78 of file CastorText2DetIdConverter.cc.

81  {
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_HAD" ? HcalCastorDetId::HAD
92  }
93 
94  else {
95  std::cerr << "CastorText2DetIdConverter::init-> Unknown DetId flavor: " << flavorName << std::endl;
96  result = false;
97  }
98  return result;
99 }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, HcalCastorDetId::EM, field1, field2, field3, flavorName, getField(), HcalCastorDetId::HAD, mId, mps_fire::result, hgcalPlots::section, digitizers_cfi::strip, and HcalCastorDetId::Unknown.

Referenced by CastorText2DetIdConverter().

◆ init() [2/2]

bool CastorText2DetIdConverter::init ( DetId  fId)
private

Definition at line 43 of file CastorText2DetIdConverter.cc.

43  {
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 }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, HcalCastorDetId::EM, flavorName, HcalCastorDetId::HAD, HcalGenericDetId::isHcalCastorDetId(), mId, HcalCastorDetId::module(), DetId::rawId(), mps_fire::result, HcalCastorDetId::section(), HcalCastorDetId::sector(), setField(), HcalDetId::Undefined, and HcalCastorDetId::zside().

◆ isHcalCastorDetId()

bool CastorText2DetIdConverter::isHcalCastorDetId ( ) const

Definition at line 41 of file CastorText2DetIdConverter.cc.

References HcalGenericDetId::isHcalCastorDetId(), and mId.

◆ setField()

void CastorText2DetIdConverter::setField ( int  i,
int  fValue 
)
private

Definition at line 115 of file CastorText2DetIdConverter.cc.

115  {
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 }

References edmScanValgrind::buffer, field1, field2, field3, and mps_fire::i.

Referenced by init().

◆ toString()

std::string CastorText2DetIdConverter::toString ( ) const

Definition at line 126 of file CastorText2DetIdConverter.cc.

126  {
127  return flavorName + " " + field1 + " " + field2 + " " + field3;
128 }

References field1, field2, field3, and flavorName.

Referenced by CastorDbXml::dumpObject().

Member Data Documentation

◆ field1

std::string CastorText2DetIdConverter::field1
private

Definition at line 40 of file CastorText2DetIdConverter.h.

Referenced by getField(), getField1(), init(), setField(), and toString().

◆ field2

std::string CastorText2DetIdConverter::field2
private

Definition at line 41 of file CastorText2DetIdConverter.h.

Referenced by getField(), getField2(), init(), setField(), and toString().

◆ field3

std::string CastorText2DetIdConverter::field3
private

Definition at line 42 of file CastorText2DetIdConverter.h.

Referenced by getField(), getField3(), init(), setField(), and toString().

◆ flavorName

std::string CastorText2DetIdConverter::flavorName
private

Definition at line 39 of file CastorText2DetIdConverter.h.

Referenced by getFlavor(), init(), and toString().

◆ mId

DetId CastorText2DetIdConverter::mId
private

Definition at line 43 of file CastorText2DetIdConverter.h.

Referenced by getId(), init(), and isHcalCastorDetId().

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
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
CastorText2DetIdConverter::flavorName
std::string flavorName
Definition: CastorText2DetIdConverter.h:39
HcalCastorDetId
Definition: HcalCastorDetId.h:23
CastorText2DetIdConverter::field3
std::string field3
Definition: CastorText2DetIdConverter.h:42
CastorText2DetIdConverter::mId
DetId mId
Definition: CastorText2DetIdConverter.h:43
HcalGenericDetId::isHcalCastorDetId
bool isHcalCastorDetId() const
Definition: HcalGenericDetId.cc:84
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Exception
Definition: hltDiff.cc:245
hgcalPlots.section
section
Definition: hgcalPlots.py:2679
HcalCastorDetId::HAD
Definition: HcalCastorDetId.h:25
mps_fire.result
result
Definition: mps_fire.py:311
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
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