CMS 3D CMS Logo

CSCPedestalsDBConditions.h
Go to the documentation of this file.
1 #ifndef _CSCPEDESTALSDBCONDITIONS_H
2 #define _CSCPEDESTALSDBCONDITIONS_H
3 
13 #include <cmath>
14 #include <memory>
15 
19 
21 public:
23  ~CSCPedestalsDBConditions() override;
24 
25  inline static CSCDBPedestals *prefillDBPedestals();
26 
27  typedef std::unique_ptr<CSCDBPedestals> ReturnType;
28 
30 
31 private:
32  // ----------member data ---------------------------
34  const edm::IOVSyncValue &,
35  edm::ValidityInterval &) override;
37 };
38 
42 
43 #include <fstream>
44 #include <iostream>
45 #include <vector>
46 
47 // to workaround plugin library
49  const int PED_FACTOR = 10;
50  const int RMS_FACTOR = 1000;
51  const int MAX_SIZE = 252288;
52  // const int MAX_SIZE = 273024; //for extra ME1a unganged case
53  const int MAX_SHORT = 32767;
54  CSCDBPedestals *cndbpedestals = new CSCDBPedestals();
55 
56  int db_index;
57  float db_ped, db_rms;
58  std::vector<int> db_index_id;
59  std::vector<float> db_peds;
60  std::vector<float> db_pedrms;
61  int new_index;
62  float new_ped, new_rms;
63  std::vector<int> new_index_id;
64  std::vector<float> new_peds;
65  std::vector<float> new_pedrms;
66 
67  int counter;
68 
69  std::ifstream dbdata;
70  dbdata.open("old_dbpeds.dat", std::ios::in);
71  if (!dbdata) {
72  std::cerr << "Error: old_dbpeds.dat -> no such file!" << std::endl;
73  exit(1);
74  }
75 
76  while (!dbdata.eof()) {
77  dbdata >> db_index >> db_ped >> db_rms;
78  db_index_id.push_back(db_index);
79  db_peds.push_back(db_ped);
80  db_pedrms.push_back(db_rms);
81  }
82  dbdata.close();
83 
84  std::ifstream newdata;
85  newdata.open("peds.dat", std::ios::in);
86  if (!newdata) {
87  std::cerr << "Error: peds.dat -> no such file!" << std::endl;
88  exit(1);
89  }
90 
91  while (!newdata.eof()) {
92  newdata >> new_index >> new_ped >> new_rms;
93  new_index_id.push_back(new_index);
94  new_peds.push_back(new_ped);
95  new_pedrms.push_back(new_rms);
96  }
97  newdata.close();
98 
99  CSCDBPedestals::PedestalContainer &itemvector = cndbpedestals->pedestals;
100  itemvector.resize(MAX_SIZE);
101  cndbpedestals->factor_ped = int(PED_FACTOR);
102  cndbpedestals->factor_rms = int(RMS_FACTOR);
103 
104  for (int i = 0; i < MAX_SIZE; ++i) {
105  itemvector[i].ped = (short int)(db_peds[i] * PED_FACTOR + 0.5);
106  itemvector[i].rms = (short int)(db_pedrms[i] * RMS_FACTOR + 0.5);
107  }
108 
109  for (int i = 0; i < MAX_SIZE; ++i) {
110  counter = db_index_id[i];
111  itemvector[i] = itemvector[counter];
112  itemvector[i].ped = int(db_peds[i]);
113  itemvector[i].rms = int(db_pedrms[i]);
114 
115  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
116  if (counter == new_index_id[k]) {
117  if ((short int)(fabs(new_peds[k] * PED_FACTOR + 0.5)) < MAX_SHORT)
118  itemvector[counter].ped = int(new_peds[k] * PED_FACTOR + 0.5);
119  if ((short int)(fabs(new_pedrms[k] * RMS_FACTOR + 0.5)) < MAX_SHORT)
120  itemvector[counter].rms = int(new_pedrms[k] * RMS_FACTOR + 0.5);
121  itemvector[i] = itemvector[counter];
122  // if (new_peds[k]==0) itemvector[counter].ped = int (db_peds[i]);
123  // if (new_pedrms[k]==0) itemvector[counter].rms = int (db_pedrms[i]);
124  }
125  }
126 
127  if (counter > 223968) {
128  itemvector[counter].ped = int(db_peds[i]);
129  itemvector[counter].rms = int(db_pedrms[i]);
130  itemvector[i] = itemvector[counter];
131  }
132  }
133  return cndbpedestals;
134 }
135 
136 #endif
ReturnType produceDBPedestals(const CSCDBPedestalsRcd &)
std::unique_ptr< CSCDBPedestals > ReturnType
static CSCDBPedestals * prefillDBPedestals()
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
std::vector< Item > PedestalContainer
PedestalContainer pedestals
CSCPedestalsDBConditions(const edm::ParameterSet &)
static std::atomic< unsigned int > counter
constexpr unsigned int MAX_SIZE
def exit(msg="")