CMS 3D CMS Logo

EcalTimeCalibHandler.cc
Go to the documentation of this file.
5 #include <cstddef>
6 #include <cstdio>
7 #include <fstream>
8 #include <sstream>
9 #include <utility>
10 
11 const Int_t kEBChannels = 61200, kEEChannels = 14648;
12 
14  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTimeCalibHandler")),
15  m_firstRun(static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()))),
16  m_file_name(ps.getParameter<std::string>("fileName")),
17  m_file_type(ps.getParameter<std::string>("type")) // xml/txt
18 {
19  edm::LogInfo("EcalTimeCalib Source handler constructor\n");
20 }
21 
23  edm::LogInfo("going to open file ") << m_file_name;
24 
25  // EcalCondHeader header;
27  if (m_file_type == "xml")
28  readXML(m_file_name, *payload);
29  else
30  readTXT(m_file_name, *payload);
31  Time_t snc = (Time_t)m_firstRun;
32 
34 }
35 
37  std::string dummyLine, bid;
38  std::ifstream fxml;
39  fxml.open(file_);
40  if (!fxml.is_open()) {
41  throw cms::Exception("ERROR : cannot open file ") << file_;
42  }
43  // header
44  for (int i = 0; i < 6; i++) {
45  getline(fxml, dummyLine); // skip first lines
46  }
47  fxml >> bid;
48  std::string stt = bid.substr(7, 5);
49  std::istringstream iEB(stt);
50  int nEB;
51  iEB >> nEB;
52  if (nEB != kEBChannels) {
53  throw cms::Exception("Strange number of EB channels ") << nEB;
54  }
55  fxml >> bid; // <item_version>0</item_version>
56  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
57  EBDetId myEBDetId = EBDetId::unhashIndex(iChannel);
58  fxml >> bid;
59  std::size_t found = bid.find("</");
60  stt = bid.substr(6, found - 6);
61  float val = std::stof(stt);
62  record[myEBDetId] = val;
63  }
64  for (int i = 0; i < 5; i++) {
65  getline(fxml, dummyLine); // skip first lines
66  }
67  fxml >> bid;
68  stt = bid.substr(7, 5);
69  std::istringstream iEE(stt);
70  int nEE;
71  iEE >> nEE;
72  if (nEE != kEEChannels) {
73  throw cms::Exception("Strange number of EE channels ") << nEE;
74  }
75  fxml >> bid; // <item_version>0</item_version>
76  // now endcaps
77  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
78  EEDetId myEEDetId = EEDetId::unhashIndex(iChannel);
79  fxml >> bid;
80  std::size_t found = bid.find("</");
81  stt = bid.substr(6, found - 6);
82  float val = std::stof(stt);
83  record[myEEDetId] = val;
84  }
85 }
86 
88  std::ifstream ftxt;
89  ftxt.open(file_);
90  if (!ftxt.is_open()) {
91  throw cms::Exception("ERROR : cannot open file ") << file_;
92  }
93  int number_of_lines = 0, eta, phi, x, y, z;
94  float val;
96  while (std::getline(ftxt, line)) {
97  if (number_of_lines < kEBChannels) { // barrel
98  std::sscanf(line.c_str(), "%i %i %i %f", &eta, &phi, &z, &val);
100  record[ebdetid] = val;
101  } else { // endcaps
102  std::sscanf(line.c_str(), "%i %i %i %f", &x, &y, &z, &val);
103  EEDetId eedetid(x, y, z, EEDetId::XYMODE);
104  record[eedetid] = val;
105  }
106  number_of_lines++;
107  }
108  edm::LogInfo("Number of lines in text file: ") << number_of_lines;
110  if (number_of_lines != kChannels)
111  throw cms::Exception("Wrong number of channels! Please check ");
112 }
static const int XYMODE
Definition: EEDetId.h:333
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
static const int ETAPHIMODE
Definition: EBDetId.h:158
void readTXT(const std::string &filename, EcalFloatCondObjectContainer &record)
Log< level::Info, false > LogInfo
EcalTimeCalibHandler(edm::ParameterSet const &)
EcalTimeCalibConstantMap EcalTimeCalibConstants
const Int_t kEEChannels
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
cond::Time_t Time_t
Definition: Time.h:18
void readXML(const std::string &filename, EcalFloatCondObjectContainer &record)
const Int_t kEBChannels
const Int_t kChannels