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::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 MessageLogger_cfi::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::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

int CastorText2DetIdConverter::getField ( int  i) const

Definition at line 101 of file CastorText2DetIdConverter.cc.

References MessageLogger_cfi::cerr, field1, field2, field3, and mps_fire::result.

Referenced by getId(), and 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 }
const std::string& CastorText2DetIdConverter::getField1 ( ) const
inline

Definition at line 25 of file CastorText2DetIdConverter.h.

References field1.

Referenced by HcalDbASCIIIO::dumpId(), and CastorDbASCIIIO::dumpObject().

25 { return field1; }
const std::string& CastorText2DetIdConverter::getField2 ( ) const
inline

Definition at line 26 of file CastorText2DetIdConverter.h.

References field2.

Referenced by HcalDbASCIIIO::dumpId(), and CastorDbASCIIIO::dumpObject().

26 { return field2; }
const std::string& CastorText2DetIdConverter::getField3 ( ) const
inline

Definition at line 27 of file CastorText2DetIdConverter.h.

References field3.

Referenced by HcalDbASCIIIO::dumpId(), and CastorDbASCIIIO::dumpObject().

27 { return field3; }
const std::string& CastorText2DetIdConverter::getFlavor ( ) const
inline

Definition at line 24 of file CastorText2DetIdConverter.h.

References flavorName.

Referenced by HcalDbASCIIIO::dumpId(), and CastorDbASCIIIO::dumpObject().

24 { return flavorName; }
DetId CastorText2DetIdConverter::getId ( ) const
inline
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 MessageLogger_cfi::cerr, HcalCastorDetId::EM, field1, field2, field3, flavorName, getField(), HcalCastorDetId::HAD, mId, mps_fire::result, trackingPlots::section, digitizers_cfi::strip, and HcalCastorDetId::Unknown.

Referenced by CastorText2DetIdConverter(), and getId().

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_EM" ? HcalCastorDetId::EM
91  mId = HcalCastorDetId(section, getField(1) > 0, getField(2), getField(3));
92  }
93 
94  else {
95  std::cerr << "CastorText2DetIdConverter::init-> Unknown DetId flavor: " << flavorName << std::endl;
96  result = false;
97  }
98  return result;
99 }
bool CastorText2DetIdConverter::init ( DetId  fId)
private

Definition at line 43 of file CastorText2DetIdConverter.cc.

References MessageLogger_cfi::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:272
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
bool CastorText2DetIdConverter::isHcalCastorDetId ( ) const
void CastorText2DetIdConverter::setField ( int  i,
int  fValue 
)
private

Definition at line 115 of file CastorText2DetIdConverter.cc.

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

Referenced by getId(), and 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 }
std::string CastorText2DetIdConverter::toString ( ) const

Definition at line 126 of file CastorText2DetIdConverter.cc.

References field1, field2, field3, and flavorName.

Referenced by CastorDbXml::dumpObject(), and getId().

Member Data Documentation

std::string CastorText2DetIdConverter::field1
private

Definition at line 40 of file CastorText2DetIdConverter.h.

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

std::string CastorText2DetIdConverter::field2
private

Definition at line 41 of file CastorText2DetIdConverter.h.

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

std::string CastorText2DetIdConverter::field3
private

Definition at line 42 of file CastorText2DetIdConverter.h.

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

std::string CastorText2DetIdConverter::flavorName
private

Definition at line 39 of file CastorText2DetIdConverter.h.

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

DetId CastorText2DetIdConverter::mId
private

Definition at line 43 of file CastorText2DetIdConverter.h.

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