CMS 3D CMS Logo

Functions | Variables
parseHcalDetId.cc File Reference
#include <cstdlib>
#include <cerrno>
#include <cassert>
#include <vector>
#include <sstream>
#include <cstring>
#include <iterator>
#include "CondTools/Hcal/interface/parseHcalDetId.h"

Go to the source code of this file.

Functions

const char * hcalSubdetectorName (HcalSubdetector subdet)
 
static bool parse_int (const char *c, int *result)
 
HcalDetId parseHcalDetId (const std::string &s)
 
static bool parseSubdetector (const char *c, HcalSubdetector *result)
 

Variables

static const unsigned nSsubdetNames = sizeof(subdetNames)/sizeof(subdetNames[0])
 
static const char * subdetNames []
 

Function Documentation

const char* hcalSubdetectorName ( HcalSubdetector  subdet)

Definition at line 43 of file parseHcalDetId.cc.

References nSsubdetNames, and subdetNames.

44 {
45  const unsigned ind = static_cast<unsigned>(subdet);
46  assert(ind < nSsubdetNames);
47  return subdetNames[ind];
48 }
static const unsigned nSsubdetNames
static const char * subdetNames[]
static bool parse_int ( const char *  c,
int *  result 
)
static

Definition at line 33 of file parseHcalDetId.cc.

Referenced by parseHcalDetId().

34 {
35  assert(c);
36  assert(result);
37  char *endptr;
38  errno = 0;
39  *result = strtol(c, &endptr, 0);
40  return !errno && *endptr == '\0';
41 }
HcalDetId parseHcalDetId ( const std::string &  s)

Definition at line 50 of file parseHcalDetId.cc.

References egammaForCoreTracking_cff::depth, parse_int(), parseSubdetector(), and mps_fire::result.

51 {
52  using namespace std;
53 
54  // Expected string contents:
55  //
56  // ieta iphi depth subdetector
57  //
58  // subdetector is one of "HB", "HE", "HF", or "HO"
59  //
61  istringstream iss(s);
62  vector<string> tokens(istream_iterator<string>{iss},
63  istream_iterator<string>{});
64  if (tokens.size() == 4)
65  {
66  HcalSubdetector subdet;
67  int ieta, iphi, depth;
68  if (parse_int(tokens[0].c_str(), &ieta)
69  && parse_int(tokens[1].c_str(), &iphi)
70  && parse_int(tokens[2].c_str(), &depth)
71  && parseSubdetector(tokens[3].c_str(), &subdet)
72  )
73  result = HcalDetId(subdet, ieta, iphi, depth);
74  }
75  return result;
76 }
static bool parseSubdetector(const char *c, HcalSubdetector *result)
HcalSubdetector
Definition: HcalAssistant.h:31
static bool parse_int(const char *c, int *result)
static bool parseSubdetector ( const char *  c,
HcalSubdetector result 
)
static

Definition at line 20 of file parseHcalDetId.cc.

References mps_fire::i, nSsubdetNames, and subdetNames.

Referenced by parseHcalDetId().

21 {
22  assert(c);
23  assert(result);
24  for (unsigned i=1; i<nSsubdetNames; ++i)
25  if (strcmp(c, subdetNames[i]) == 0)
26  {
27  *result = static_cast<HcalSubdetector>(i);
28  return true;
29  }
30  return false;
31 }
static const unsigned nSsubdetNames
HcalSubdetector
Definition: HcalAssistant.h:31
static const char * subdetNames[]

Variable Documentation

const unsigned nSsubdetNames = sizeof(subdetNames)/sizeof(subdetNames[0])
static

Definition at line 18 of file parseHcalDetId.cc.

Referenced by hcalSubdetectorName(), and parseSubdetector().

const char* subdetNames[]
static
Initial value:
= {
"",
"HB",
"HE",
"HO",
"HF",
}

Definition at line 11 of file parseHcalDetId.cc.

Referenced by LASBarrelAlgorithm::Dump(), hcalSubdetectorName(), parseSubdetector(), and LASBarrelAlignmentParameterSet::Print().