CMS 3D CMS Logo

CastorText2DetIdConverter Class Reference

Converts any flavour of HcalDetId to/from ascii strings. More...

#include <CalibFormats/CastorObjects/interface/CastorText2DetIdConverter.h>

List of all members.

Public Member Functions

 CastorText2DetIdConverter (DetId fId)
 CastorText2DetIdConverter (const std::string &fFlavor="NA", const std::string &fField1="0", const std::string &fField2="0", const std::string &fField3="0")
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 (DetId fId)
bool init (const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
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 24 of file CastorText2DetIdConverter.cc.

References TestMuL1L2Filter_cff::cerr, lat::endl(), Exception, and init().

00025                                                                                                       {
00026   if (!init (fFlavor, fField1, fField2, fField3)) {
00027     std::cerr << "CastorText2DetIdConverter::CastorText2DetIdConverter-> Can not initiate detId from items: "
00028               << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
00029     throw cms::Exception("HcalGenDetId initialization error") 
00030       << " Can not initiate detId from items: "
00031       << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
00032   }
00033 }

CastorText2DetIdConverter::CastorText2DetIdConverter ( DetId  fId  ) 

Definition at line 35 of file CastorText2DetIdConverter.cc.

References init().

00035                                                                {
00036   init (fId);
00037 }


Member Function Documentation

int CastorText2DetIdConverter::getField ( int  i  )  const

Definition at line 94 of file CastorText2DetIdConverter.cc.

References TestMuL1L2Filter_cff::cerr, lat::endl(), field1, field2, field3, and HLT_VtxMuL3::result.

Referenced by init().

00094                                                    {
00095   char* endptr;
00096   const char* nptr = i == 1 ? field1.c_str() :
00097     i == 2 ? field2.c_str() : field3.c_str();
00098   long result = strtol (nptr, &endptr, 0);
00099     if (*nptr != '\0' && *endptr == '\0') {
00100       return result;
00101     }
00102     if (*nptr != '\0') {
00103       std::cerr << "CastorText2DetIdConverter::getField-> Can not convert string "<< nptr << " to int. Bad symbol: " << *endptr << std::endl;
00104     }
00105     return 0;
00106 }

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

Definition at line 24 of file CastorText2DetIdConverter.h.

References field1.

Referenced by dumpId().

00024 {return field1;}

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

Definition at line 25 of file CastorText2DetIdConverter.h.

References field2.

Referenced by dumpId().

00025 {return field2;}

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

Definition at line 26 of file CastorText2DetIdConverter.h.

References field3.

Referenced by dumpId().

00026 {return field3;}

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

Definition at line 23 of file CastorText2DetIdConverter.h.

References flavorName.

Referenced by dumpId().

00023 {return flavorName;}

DetId CastorText2DetIdConverter::getId (  )  const [inline]

Definition at line 27 of file CastorText2DetIdConverter.h.

References mId.

Referenced by getId().

00027 {return mId;}

bool CastorText2DetIdConverter::init ( DetId  fId  )  [private]

Definition at line 43 of file CastorText2DetIdConverter.cc.

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

00043                                                {
00044   bool result = true;
00045   flavorName = "UNKNOWN";
00046   mId = fId;
00047   HcalGenericDetId genId (mId);
00048   if (fId == HcalDetId::Undefined) {
00049     flavorName = "NA";
00050   }
00051 
00052   else if (genId.isHcalCastorDetId ()) {
00053     HcalCastorDetId castorId (mId);
00054     switch (castorId.section()) {
00055     case HcalCastorDetId::EM: flavorName = "CASTOR_EM"; break;
00056     case HcalCastorDetId::HAD: flavorName = "CASTOR_HAD"; break;
00057     default: result = false;
00058     }
00059     setField (1, castorId.zside());
00060     setField (2, castorId.sector());
00061     setField (3, castorId.module());
00062   }
00063 
00064   else {
00065     flavorName = "UNKNOWN_FLAVOR";
00066     std::cerr << "CastorText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId() << std::endl;
00067     result = false;
00068   }
00069   return result;
00070 }

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

Definition at line 73 of file CastorText2DetIdConverter.cc.

References TestMuL1L2Filter_cff::cerr, HcalCastorDetId::EM, lat::endl(), field1, field2, field3, flavorName, getField(), HcalCastorDetId::HAD, mId, HLT_VtxMuL3::result, strip(), and HcalCastorDetId::Unknown.

Referenced by CastorText2DetIdConverter().

00074                                                                                        {
00075   bool result = true;
00076   flavorName = strip (fFlavor);
00077   field1 = strip (fField1);
00078   field2 = strip (fField2);
00079   field3 = strip (fField3);
00080   if (flavorName.find ("CASTOR_") == 0) {
00081     HcalCastorDetId::Section section = flavorName == "CASTOR_EM" ? HcalCastorDetId::EM :
00082       flavorName == "CASTOR_HAD" ? HcalCastorDetId::HAD : HcalCastorDetId::Unknown;
00083     mId = HcalCastorDetId (section, getField (1)>0, getField (2), getField(3));
00084   }
00085 
00086   else {
00087     std::cerr << "CastorText2DetIdConverter::init-> Unknown DetId flavor: " << flavorName << std::endl;
00088     result = false;
00089   }
00090   return result;
00091 }

bool CastorText2DetIdConverter::isHcalCastorDetId (  )  const

Definition at line 39 of file CastorText2DetIdConverter.cc.

References mId.

00039                                                          {
00040   return HcalGenericDetId (mId).isHcalCastorDetId ();
00041 }

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

Definition at line 108 of file CastorText2DetIdConverter.cc.

References field1, field2, and field3.

Referenced by init().

00108                                                            {
00109   char buffer [128];
00110   sprintf (buffer, "%d", fValue);
00111   if (i == 1) field1 = buffer;
00112   else if (i == 2) field2 = buffer;
00113   else  field3 = buffer;
00114 }

std::string CastorText2DetIdConverter::toString (  )  const

Definition at line 116 of file CastorText2DetIdConverter.cc.

References field1, field2, field3, and flavorName.

00116                                                      {
00117   return flavorName + " " + field1 + " " + field2 + " " + field3;
00118 }


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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:16:15 2009 for CMSSW by  doxygen 1.5.4