CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
HcalText2DetIdConverter Class Reference

#include <HcalText2DetIdConverter.h>

Public Member Functions

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
 
 HcalText2DetIdConverter (const std::string &fFlavor="NA", const std::string &fField1="0", const std::string &fField2="0", const std::string &fField3="0")
 
 HcalText2DetIdConverter (DetId fId)
 
bool isHcalCalibDetId () const
 
bool isHcalDetId () const
 
bool isHcalTrigTowerDetId () const
 
bool isHcalZDCDetId () 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

Author
F.Ratnikov, UMd Converts any flavour of HcalDetId to/from ascii strings

For Calibration DetIds:

Flavor = "CALIB_[HB|HE|HO|HF]" or "HOX"

fField1 is ieta (-2:2 for CALIB) fField2 is iphi fField3 is ctype (CALIB only)

Id:
HcalText2DetIdConverter.h,v 1.1 2006/07/31 19:51:49 fedor Exp
Author
F.Ratnikov, UMd
Id:
HcalText2DetIdConverter.cc,v 1.9 2008/07/22 11:41:34 mansj Exp

Definition at line 22 of file HcalText2DetIdConverter.h.

Constructor & Destructor Documentation

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

Definition at line 42 of file HcalText2DetIdConverter.cc.

References benchmark_cfg::cerr, edm::hlt::Exception, and init().

43  {
44  if (!init (fFlavor, fField1, fField2, fField3)) {
45  std::cerr << "HcalText2DetIdConverter::HcalText2DetIdConverter-> Can not initiate detId from items: "
46  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
47  throw cms::Exception("HcalGenDetId initialization error")
48  << " Can not initiate detId from items: "
49  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
50  }
51 }
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
HcalText2DetIdConverter::HcalText2DetIdConverter ( DetId  fId)

Definition at line 53 of file HcalText2DetIdConverter.cc.

References init().

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

Member Function Documentation

int HcalText2DetIdConverter::getField ( int  i) const

Definition at line 198 of file HcalText2DetIdConverter.cc.

References benchmark_cfg::cerr, field1, field2, field3, isHcalCalibDetId(), and query::result.

Referenced by init(), and XMLDocument::makeChId().

198  {
199  char* endptr;
200  const char* nptr = i == 1 ? field1.c_str() :
201  i == 2 ? field2.c_str() : field3.c_str();
202  long result = strtol (nptr, &endptr, 0);
203  if (*nptr != '\0' && *endptr == '\0') {
204  return result;
205  }
206  if (i == 2 && isHcalCalibDetId ()) {
207  int result = calibChannel (field2);
208  if (i) return result;
209  }
210  if (*nptr != '\0') {
211  std::cerr << "HcalText2DetIdConverter::getField-> Can not convert string "<< nptr << " to int. Bad symbol: " << *endptr << std::endl;
212  }
213  return 0;
214  }
int i
Definition: DBlmapReader.cc:9
tuple result
Definition: query.py:137
const std::string& HcalText2DetIdConverter::getField1 ( ) const
inline

Definition at line 36 of file HcalText2DetIdConverter.h.

References field1.

36 {return field1;}
const std::string& HcalText2DetIdConverter::getField2 ( ) const
inline

Definition at line 37 of file HcalText2DetIdConverter.h.

References field2.

Referenced by XMLDocument::makeChId().

37 {return field2;}
const std::string& HcalText2DetIdConverter::getField3 ( ) const
inline

Definition at line 38 of file HcalText2DetIdConverter.h.

References field3.

Referenced by XMLDocument::makeChId().

38 {return field3;}
const std::string& HcalText2DetIdConverter::getFlavor ( ) const
inline

Definition at line 35 of file HcalText2DetIdConverter.h.

References flavorName.

Referenced by HcalDQMDbInterface::createChannel(), and XMLDocument::makeChId().

35 {return flavorName;}
DetId HcalText2DetIdConverter::getId ( ) const
inline

Definition at line 39 of file HcalText2DetIdConverter.h.

References mId.

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

Definition at line 144 of file HcalText2DetIdConverter.cc.

References benchmark_cfg::cerr, HcalZDCDetId::EM, field1, field2, field3, flavorName, getField(), HcalZDCDetId::HAD, HcalBarrel, HcalEndcap, HcalForward, HcalOther, HcalOuter, HcalZDCDetId::LUM, mId, query::result, strip(), HcalDetId::Undefined, and HcalZDCDetId::Unknown.

Referenced by HcalText2DetIdConverter().

145  {
146  bool result = true;
147  flavorName = strip (fFlavor);
148  field1 = strip (fField1);
149  field2 = strip (fField2);
150  field3 = strip (fField3);
151  if (flavorName == "HB" ||
152  flavorName == "HE" ||
153  flavorName == "HF" ||
154  flavorName == "HO") {
155  HcalSubdetector sub = flavorName == "HB" ? HcalBarrel :
156  flavorName == "HE" ? HcalEndcap :
157  flavorName == "HO" ? HcalOuter :
158  HcalForward;
159  mId = HcalDetId (sub, getField (1), getField (2), getField (3));
160  }
161  else if (flavorName == "HT") {
163  }
164  else if (flavorName.find ("ZDC_") == 0) {
165  HcalZDCDetId::Section section = flavorName == "ZDC_EM" ? HcalZDCDetId::EM :
166  flavorName == "ZDC_HAD" ? HcalZDCDetId::HAD :
168  mId = HcalZDCDetId (section, getField (1)>0, getField (2));
169  }
170  else if (flavorName.find ("CALIB_") == 0) {
172  if (flavorName.find("HB")!=std::string::npos) sd=HcalBarrel;
173  else if (flavorName.find("HE")!=std::string::npos) sd=HcalEndcap;
174  else if (flavorName.find("HO")!=std::string::npos) sd=HcalOuter;
175  else if (flavorName.find("HF")!=std::string::npos) sd=HcalForward;
176 
177  int ieta=getField(1);
178  int iphi=getField(2);
179  int channel = calibChannel (field3);
180  mId = HcalCalibDetId (sd, ieta,iphi,channel);
181  }
182  else if (flavorName=="HOX") {
183  int ieta=getField(1);
184  int iphi=getField(2);
185  mId = HcalCalibDetId (ieta,iphi);
186  }
187  else if (flavorName == "NA") {
189  }
190  else {
191  std::cerr << "HcalText2DetIdConverter::init-> Unknown HcalDetId flavor: " << flavorName << std::endl;
192  result = false;
193  }
194  return result;
195 }
static const HcalDetId Undefined
Definition: HcalDetId.h:66
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
tuple result
Definition: query.py:137
HcalSubdetector
Definition: HcalAssistant.h:32
bool HcalText2DetIdConverter::init ( DetId  fId)
private

Definition at line 73 of file HcalText2DetIdConverter.cc.

References HcalCalibDetId::calibFlavor(), HcalCalibDetId::CalibrationBox, HcalCalibDetId::cboxChannel(), benchmark_cfg::cerr, HcalZDCDetId::channel(), HcalDetId::depth(), HcalZDCDetId::EM, flavorName, HcalGenericDetId::genericSubdet(), HcalZDCDetId::HAD, HcalBarrel, HcalEndcap, HcalForward, HcalGenericDetId::HcalGenBarrel, HcalGenericDetId::HcalGenEndcap, HcalGenericDetId::HcalGenForward, HcalGenericDetId::HcalGenOuter, HcalOuter, HcalCalibDetId::hcalSubdet(), HcalCalibDetId::HOCrosstalk, HcalDetId::ieta(), HcalTrigTowerDetId::ieta(), HcalCalibDetId::ieta(), HcalDetId::iphi(), HcalTrigTowerDetId::iphi(), HcalCalibDetId::iphi(), HcalGenericDetId::isHcalCalibDetId(), HcalGenericDetId::isHcalDetId(), HcalGenericDetId::isHcalTrigTowerDetId(), HcalGenericDetId::isHcalZDCDetId(), HcalZDCDetId::LUM, mId, DetId::rawId(), query::result, HcalZDCDetId::section(), setField(), HcalTrigTowerDetId::Undefined, HcalDetId::Undefined, and HcalZDCDetId::zside().

73  {
74  bool result = true;
75  flavorName = "UNKNOWN";
76  mId = fId;
77  HcalGenericDetId genId (mId);
78  if (fId == HcalDetId::Undefined) {
79  flavorName = "NA";
80  }
81  else if (genId.isHcalDetId ()) {
82  HcalDetId hcalId (mId);
83  flavorName = genId.genericSubdet () == HcalGenericDetId::HcalGenBarrel ? "HB" :
84  genId.genericSubdet () == HcalGenericDetId::HcalGenEndcap ? "HE" :
85  genId.genericSubdet () == HcalGenericDetId::HcalGenOuter ? "HO" :
86  genId.genericSubdet () == HcalGenericDetId::HcalGenForward ? "HF" : "H_UNKNOWN";
87  setField (1, hcalId.ieta());
88  setField (2, hcalId.iphi());
89  setField (3, hcalId.depth());
90  }
91  else if (genId.isHcalTrigTowerDetId ()) {
92  HcalTrigTowerDetId triggerId (mId);
93  if (triggerId == HcalTrigTowerDetId::Undefined) {
94  flavorName = "NT";
95  }
96  else {
97  flavorName = "HT";
98  setField (1, triggerId.ieta());
99  setField (2, triggerId.iphi());
100  setField (3, 1);
101  }
102  }
103  else if (genId.isHcalZDCDetId ()) {
104  HcalZDCDetId zdcId (mId);
105  switch (zdcId.section()) {
106  case HcalZDCDetId::EM: flavorName = "ZDC_EM"; break;
107  case HcalZDCDetId::HAD: flavorName = "ZDC_HAD"; break;
108  case HcalZDCDetId::LUM: flavorName = "ZDC_LUM"; break;
109  default: result = false;
110  }
111  setField (1, zdcId.zside());
112  setField (2, zdcId.channel());
113  setField (3, -99);
114  }
115  else if (genId.isHcalCalibDetId ()) {
116  HcalCalibDetId calibId (mId);
117  if (calibId.calibFlavor()==HcalCalibDetId::CalibrationBox) {
118  switch (calibId.hcalSubdet()) {
119  case HcalBarrel: flavorName = "CALIB_HB"; break;
120  case HcalEndcap: flavorName = "CALIB_HE"; break;
121  case HcalOuter: flavorName = "CALIB_HO"; break;
122  case HcalForward: flavorName = "CALIB_HF"; break;
123  default: result = false;
124  }
125  setField (1, calibId.ieta());
126  setField (2, calibId.iphi());
127  setField (3, calibId.cboxChannel() );
128  } else if (calibId.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
129  flavorName="HOX";
130  setField (1, calibId.ieta());
131  setField (2, calibId.iphi());
132  setField (3, -999);
133  }
134  }
135  else {
136  flavorName = "UNKNOWN_FLAVOR";
137  std::cerr << "HcalText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId() << std::endl;
138  result = false;
139  }
140  return result;
141 }
static const HcalDetId Undefined
Definition: HcalDetId.h:66
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
void setField(int i, int fValue)
tuple result
Definition: query.py:137
static const HcalTrigTowerDetId Undefined
bool HcalText2DetIdConverter::isHcalCalibDetId ( ) const

Definition at line 61 of file HcalText2DetIdConverter.cc.

References HcalGenericDetId::isHcalCalibDetId(), and mId.

Referenced by getField().

bool HcalText2DetIdConverter::isHcalDetId ( ) const
bool HcalText2DetIdConverter::isHcalTrigTowerDetId ( ) const
bool HcalText2DetIdConverter::isHcalZDCDetId ( ) const
void HcalText2DetIdConverter::setField ( int  i,
int  fValue 
)
private

Definition at line 216 of file HcalText2DetIdConverter.cc.

References field1, field2, and field3.

Referenced by init().

216  {
217  char buffer [128];
218  sprintf (buffer, "%d", fValue);
219  if (i == 1) field1 = buffer;
220  else if (i == 2) field2 = buffer;
221  else field3 = buffer;
222 }
int i
Definition: DBlmapReader.cc:9
std::string HcalText2DetIdConverter::toString ( ) const

Definition at line 224 of file HcalText2DetIdConverter.cc.

References field1, field2, field3, and flavorName.

Referenced by HcalDbXml::dumpObject().

224  {
225  return flavorName + " " + field1 + " " + field2 + " " + field3;
226 }

Member Data Documentation

std::string HcalText2DetIdConverter::field1
private

Definition at line 49 of file HcalText2DetIdConverter.h.

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

std::string HcalText2DetIdConverter::field2
private

Definition at line 50 of file HcalText2DetIdConverter.h.

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

std::string HcalText2DetIdConverter::field3
private

Definition at line 51 of file HcalText2DetIdConverter.h.

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

std::string HcalText2DetIdConverter::flavorName
private

Definition at line 48 of file HcalText2DetIdConverter.h.

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

DetId HcalText2DetIdConverter::mId
private