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.

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

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 }
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)

◆ CastorText2DetIdConverter() [2/2]

CastorText2DetIdConverter::CastorText2DetIdConverter ( DetId  fId)

Definition at line 39 of file CastorText2DetIdConverter.cc.

References init().

39 { init(fId); }
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)

Member Function Documentation

◆ getField()

int CastorText2DetIdConverter::getField ( int  i) const

Definition at line 101 of file CastorText2DetIdConverter.cc.

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

Referenced by init().

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 }

◆ getField1()

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

Definition at line 25 of file CastorText2DetIdConverter.h.

References field1.

25 { return field1; }

◆ getField2()

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

Definition at line 26 of file CastorText2DetIdConverter.h.

References field2.

26 { return field2; }

◆ getField3()

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

Definition at line 27 of file CastorText2DetIdConverter.h.

References field3.

27 { return field3; }

◆ getFlavor()

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

Definition at line 24 of file CastorText2DetIdConverter.h.

References flavorName.

24 { return flavorName; }

◆ getId()

DetId CastorText2DetIdConverter::getId ( ) const
inline

Definition at line 28 of file CastorText2DetIdConverter.h.

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.

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

Referenced by CastorText2DetIdConverter().

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 }

◆ init() [2/2]

bool CastorText2DetIdConverter::init ( DetId  fId)
private

Definition at line 43 of file CastorText2DetIdConverter.cc.

References DMR_cfg::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().

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 }
static const HcalDetId Undefined
Definition: HcalDetId.h:273
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57

◆ isHcalCastorDetId()

bool CastorText2DetIdConverter::isHcalCastorDetId ( ) const

◆ setField()

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

Definition at line 115 of file CastorText2DetIdConverter.cc.

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

Referenced by init().

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 }

◆ toString()

std::string CastorText2DetIdConverter::toString ( ) const

Definition at line 126 of file CastorText2DetIdConverter.cc.

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().