CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

CastorText2DetIdConverter Class Reference

#include <CastorText2DetIdConverter.h>

List of all members.

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 benchmark_cfg::cerr, Exception, and init().

                                                                                                      {
  if (!init (fFlavor, fField1, fField2, fField3)) {
    std::cerr << "CastorText2DetIdConverter::CastorText2DetIdConverter-> Can not initiate detId from items: "
              << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
    throw cms::Exception("HcalGenDetId initialization error") 
      << " Can not initiate detId from items: "
      << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
  }
}
CastorText2DetIdConverter::CastorText2DetIdConverter ( DetId  fId)

Definition at line 36 of file CastorText2DetIdConverter.cc.

References init().

                                                               {
  init (fId);
}

Member Function Documentation

int CastorText2DetIdConverter::getField ( int  i) const

Definition at line 95 of file CastorText2DetIdConverter.cc.

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

Referenced by init().

                                                   {
  char* endptr;
  const char* nptr = i == 1 ? field1.c_str() :
    i == 2 ? field2.c_str() : field3.c_str();
  long result = strtol (nptr, &endptr, 0);
    if (*nptr != '\0' && *endptr == '\0') {
      return result;
    }
    if (*nptr != '\0') {
      std::cerr << "CastorText2DetIdConverter::getField-> Can not convert string "<< nptr << " to int. Bad symbol: " << *endptr << std::endl;
    }
    return 0;
}
const std::string& CastorText2DetIdConverter::getField1 ( ) const [inline]

Definition at line 24 of file CastorText2DetIdConverter.h.

References field1.

Referenced by HcalDbASCIIIO::dumpId().

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

Definition at line 25 of file CastorText2DetIdConverter.h.

References field2.

Referenced by HcalDbASCIIIO::dumpId().

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

Definition at line 26 of file CastorText2DetIdConverter.h.

References field3.

Referenced by HcalDbASCIIIO::dumpId().

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

Definition at line 23 of file CastorText2DetIdConverter.h.

References flavorName.

Referenced by HcalDbASCIIIO::dumpId().

{return flavorName;}
DetId CastorText2DetIdConverter::getId ( ) const [inline]

Definition at line 27 of file CastorText2DetIdConverter.h.

References mId.

Referenced by HcalDbASCIIIO::getId().

{return mId;}
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 benchmark_cfg::cerr, HcalCastorDetId::EM, field1, field2, field3, flavorName, getField(), HcalCastorDetId::HAD, mId, query::result, strip(), and Unknown.

Referenced by CastorText2DetIdConverter().

                                                                                       {
  bool result = true;
  flavorName = strip (fFlavor);
  field1 = strip (fField1);
  field2 = strip (fField2);
  field3 = strip (fField3);
  if (flavorName.find ("CASTOR_") == 0) {
    HcalCastorDetId::Section section = flavorName == "CASTOR_EM" ? HcalCastorDetId::EM :
      flavorName == "CASTOR_HAD" ? HcalCastorDetId::HAD : HcalCastorDetId::Unknown;
    mId = HcalCastorDetId (section, getField (1)>0, getField (2), getField(3));
  }

  else {
    std::cerr << "CastorText2DetIdConverter::init-> Unknown DetId flavor: " << flavorName << std::endl;
    result = false;
  }
  return result;
}
bool CastorText2DetIdConverter::init ( DetId  fId) [private]

Definition at line 44 of file CastorText2DetIdConverter.cc.

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

                                               {
  bool result = true;
  flavorName = "UNKNOWN";
  mId = fId;
  HcalGenericDetId genId (mId);
  if (fId == HcalDetId::Undefined) {
    flavorName = "NA";
  }

  else if (genId.isHcalCastorDetId ()) {
    HcalCastorDetId castorId (mId);
    switch (castorId.section()) {
    case HcalCastorDetId::EM: flavorName = "CASTOR_EM"; break;
    case HcalCastorDetId::HAD: flavorName = "CASTOR_HAD"; break;
    default: result = false;
    }
    setField (1, castorId.zside());
    setField (2, castorId.sector());
    setField (3, castorId.module());
  }

  else {
    flavorName = "UNKNOWN_FLAVOR";
    std::cerr << "CastorText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId() << std::endl;
    result = false;
  }
  return result;
}
bool CastorText2DetIdConverter::isHcalCastorDetId ( ) const
void CastorText2DetIdConverter::setField ( int  i,
int  fValue 
) [private]

Definition at line 109 of file CastorText2DetIdConverter.cc.

References field1, field2, and field3.

Referenced by init().

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

Definition at line 117 of file CastorText2DetIdConverter.cc.

References field1, field2, field3, and flavorName.

Referenced by CastorDbXml::dumpObject().

                                                     {
  return flavorName + " " + field1 + " " + field2 + " " + field3;
}

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

Definition at line 36 of file CastorText2DetIdConverter.h.

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

Definition at line 40 of file CastorText2DetIdConverter.h.

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