CMS 3D CMS Logo

EcalIntercalibHandler.cc
Go to the documentation of this file.
5 
6 #include<iostream>
7 
8 const Int_t kEBChannels = 61200, kEEChannels = 14648;
9 
11  : m_name(ps.getUntrackedParameter<std::string>("name","EcalIntercalibHandler")) {
12 
13  edm::LogInfo("EcalIntercalib Source handler constructor\n");
14  m_firstRun = static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
15  m_file_type = ps.getParameter<std::string>("type"); // xml/txt
16  m_file_name = ps.getParameter<std::string>("fileName");
17 }
18 
20 
22  // std::cout << "------- Ecal - > getNewObjects\n";
23  std::ostringstream ss;
24  ss<<"ECAL ";
25 
26  unsigned long long irun;
27  std::string file_= m_file_name;
28  edm::LogInfo("going to open file ") << file_;
29 
30  // EcalCondHeader header;
32  if(m_file_type == "xml")
33  readXML(file_, *payload);
34  else
35  readTXT(file_, *payload);
36  irun = m_firstRun;
37  Time_t snc= (Time_t) irun ;
38 
39  popcon::PopConSourceHandler<EcalIntercalibConstants>::m_to_transfer.push_back(std::make_pair(payload, snc));
40 }
41 
44  std::string dummyLine, bid;
45  std::ifstream fxml;
46  fxml.open(file_);
47  if(!fxml.is_open()) {
48  edm::LogInfo("ERROR : cannot open file ") << file_;
49  exit (1);
50  }
51  // header
52  for( int i=0; i< 6; i++) {
53  getline(fxml, dummyLine); // skip first lines
54  // std::cout << dummyLine << std::endl;
55  }
56  fxml >> bid;
57  std::string stt = bid.substr(7,5);
58  std::istringstream iEB(stt);
59  int nEB;
60  iEB >> nEB;
61  if(nEB != kEBChannels) {
62  edm::LogInfo("strange number of EB channels ") << nEB;
63  exit(-1);
64  }
65  fxml >> bid; // <item_version>0</item_version>
66  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
67  EBDetId myEBDetId = EBDetId::unhashIndex(iChannel);
68  fxml >> bid;
69  std::size_t found = bid.find("</");
70  stt = bid.substr(6, found - 6);
71  float val = std::stof(stt);
72  record[myEBDetId] = val;
73  }
74  for( int i=0; i< 5; i++) {
75  getline(fxml, dummyLine); // skip first lines
76  // std::cout << dummyLine << std::endl;
77  }
78  fxml >> bid;
79  stt = bid.substr(7,5);
80  std::istringstream iEE(stt);
81  int nEE;
82  iEE >> nEE;
83  if(nEE != kEEChannels) {
84  edm::LogInfo("strange number of EE channels ") << nEE;
85  exit(-1);
86  }
87  fxml >> bid; // <item_version>0</item_version>
88  // now endcaps
89  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
90  EEDetId myEEDetId = EEDetId::unhashIndex(iChannel);
91  fxml >> bid;
92  std::size_t found = bid.find("</");
93  stt = bid.substr(6, found - 6);
94  float val = std::stof(stt);
95  record[myEEDetId] = val;
96  }
97 }
98 
101  std::ifstream ftxt;
102  ftxt.open(file_);
103  if(!ftxt.is_open()) {
104  edm::LogInfo("ERROR : cannot open file ") << file_;
105  exit (1);
106  }
107  int number_of_lines = 0, eta, phi, x, y, z;
108  float val;
110  while (std::getline(ftxt, line)) {
111  if(number_of_lines < kEBChannels) { // barrel
112  sscanf(line.c_str(), "%i %i %i %f", &eta, &phi, &z, &val);
113  EBDetId ebdetid(eta, phi, EBDetId::ETAPHIMODE);
114  record[ebdetid] = val;
115  }
116  else { // endcaps
117  sscanf(line.c_str(), "%i %i %i %f", &x, &y, &z, &val);
118  EEDetId eedetid(x, y, z, EEDetId::XYMODE);
119  record[eedetid] = val;
120  }
121  number_of_lines++;
122  }
123  edm::LogInfo("Number of lines in text file: ") << number_of_lines;
125  if(number_of_lines != kChannels)
126  edm::LogInfo("wrong number of channels! Please check ");
127 }
T getParameter(std::string const &) const
JetCorrectorParameters::Record record
Definition: classes.h:7
static const int XYMODE
Definition: EEDetId.h:335
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
void readTXT(const std::string &filename, EcalFloatCondObjectContainer &record)
const Int_t kEEChannels
void readXML(const std::string &filename, EcalFloatCondObjectContainer &record)
EcalIntercalibHandler(edm::ParameterSet const &)
static const int ETAPHIMODE
Definition: EBDetId.h:158
const Int_t kEBChannels
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
EcalIntercalibConstantMap EcalIntercalibConstants
const Int_t kChannels