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 25 of file CastorText2DetIdConverter.cc.

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

26  {
27  if (!init (fFlavor, fField1, fField2, fField3)) {
28  std::cerr << "CastorText2DetIdConverter::CastorText2DetIdConverter-> Can not initiate detId from items: "
29  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
30  throw cms::Exception("HcalGenDetId initialization error")
31  << " Can not initiate detId from items: "
32  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
33  }
34 }
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 36 of file CastorText2DetIdConverter.cc.

References init().

36  {
37  init (fId);
38 }
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 95 of file CastorText2DetIdConverter.cc.

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

Referenced by getId(), and init().

95  {
96  char* endptr;
97  const char* nptr = i == 1 ? field1.c_str() :
98  i == 2 ? field2.c_str() : field3.c_str();
99  long result = strtol (nptr, &endptr, 0);
100  if (*nptr != '\0' && *endptr == '\0') {
101  return result;
102  }
103  if (*nptr != '\0') {
104  std::cerr << "CastorText2DetIdConverter::getField-> Can not convert string "<< nptr << " to int. Bad symbol: " << *endptr << std::endl;
105  }
106  return 0;
107 }
const std::string& CastorText2DetIdConverter::getField1 ( ) const
inline

Definition at line 24 of file CastorText2DetIdConverter.h.

References field1.

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

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

Definition at line 25 of file CastorText2DetIdConverter.h.

References field2.

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

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

Definition at line 26 of file CastorText2DetIdConverter.h.

References field3.

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

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

Definition at line 23 of file CastorText2DetIdConverter.h.

References flavorName.

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

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 74 of file CastorText2DetIdConverter.cc.

References MessageLogger_cfi::cerr, HcalCastorDetId::EM, field1, field2, field3, flavorName, getField(), HcalCastorDetId::HAD, mId, mps_fire::result, vertexPlots::section, digi_MixPreMix_cfi::strip, and HcalCastorDetId::Unknown.

Referenced by CastorText2DetIdConverter(), and getId().

75  {
76  bool result = true;
77  flavorName = strip (fFlavor);
78  field1 = strip (fField1);
79  field2 = strip (fField2);
80  field3 = strip (fField3);
81  if (flavorName.find ("CASTOR_") == 0) {
84  mId = HcalCastorDetId (section, getField (1)>0, getField (2), getField(3));
85  }
86 
87  else {
88  std::cerr << "CastorText2DetIdConverter::init-> Unknown DetId flavor: " << flavorName << std::endl;
89  result = false;
90  }
91  return result;
92 }
bool CastorText2DetIdConverter::init ( DetId  fId)
private

Definition at line 44 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().

44  {
45  bool result = true;
46  flavorName = "UNKNOWN";
47  mId = fId;
48  HcalGenericDetId genId (mId);
49  if (fId == HcalDetId::Undefined) {
50  flavorName = "NA";
51  }
52 
53  else if (genId.isHcalCastorDetId ()) {
54  HcalCastorDetId castorId (mId);
55  switch (castorId.section()) {
56  case HcalCastorDetId::EM: flavorName = "CASTOR_EM"; break;
57  case HcalCastorDetId::HAD: flavorName = "CASTOR_HAD"; break;
58  default: result = false;
59  }
60  setField (1, castorId.zside());
61  setField (2, castorId.sector());
62  setField (3, castorId.module());
63  }
64 
65  else {
66  flavorName = "UNKNOWN_FLAVOR";
67  std::cerr << "CastorText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId() << std::endl;
68  result = false;
69  }
70  return result;
71 }
static const HcalDetId Undefined
Definition: HcalDetId.h:85
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
bool CastorText2DetIdConverter::isHcalCastorDetId ( ) const
void CastorText2DetIdConverter::setField ( int  i,
int  fValue 
)
private

Definition at line 109 of file CastorText2DetIdConverter.cc.

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

Referenced by getId(), and init().

109  {
110  char buffer [128];
111  sprintf (buffer, "%d", fValue);
112  if (i == 1) field1 = buffer;
113  else if (i == 2) field2 = buffer;
114  else field3 = buffer;
115 }
std::string CastorText2DetIdConverter::toString ( ) const

Definition at line 117 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 37 of file CastorText2DetIdConverter.h.

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

std::string CastorText2DetIdConverter::field2
private

Definition at line 38 of file CastorText2DetIdConverter.h.

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

std::string CastorText2DetIdConverter::field3
private

Definition at line 39 of file CastorText2DetIdConverter.h.

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

std::string CastorText2DetIdConverter::flavorName
private

Definition at line 36 of file CastorText2DetIdConverter.h.

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

DetId CastorText2DetIdConverter::mId
private

Definition at line 40 of file CastorText2DetIdConverter.h.

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