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  int db_nrlines = 0;
69  int new_nrlines = 0;
70 
71  std::ifstream dbdata;
72  dbdata.open("old_dbpeds.dat", std::ios::in);
73  if (!dbdata) {
74  std::cerr << "Error: old_dbpeds.dat -> no such file!" << std::endl;
75  exit(1);
76  }
77 
78  while (!dbdata.eof()) {
79  dbdata >> db_index >> db_ped >> db_rms;
80  db_index_id.push_back(db_index);
81  db_peds.push_back(db_ped);
82  db_pedrms.push_back(db_rms);
83  db_nrlines++;
84  }
85  dbdata.close();
86 
87  std::ifstream newdata;
88  newdata.open("peds.dat", std::ios::in);
89  if (!newdata) {
90  std::cerr << "Error: peds.dat -> no such file!" << std::endl;
91  exit(1);
92  }
93 
94  while (!newdata.eof()) {
95  newdata >> new_index >> new_ped >> new_rms;
96  new_index_id.push_back(new_index);
97  new_peds.push_back(new_ped);
98  new_pedrms.push_back(new_rms);
99  new_nrlines++;
100  }
101  newdata.close();
102 
103  CSCDBPedestals::PedestalContainer &itemvector = cndbpedestals->pedestals;
104  itemvector.resize(MAX_SIZE);
105  cndbpedestals->factor_ped = int(PED_FACTOR);
106  cndbpedestals->factor_rms = int(RMS_FACTOR);
107 
108  for (int i = 0; i < MAX_SIZE; ++i) {
109  itemvector[i].ped = (short int)(db_peds[i] * PED_FACTOR + 0.5);
110  itemvector[i].rms = (short int)(db_pedrms[i] * RMS_FACTOR + 0.5);
111  }
112 
113  for (int i = 0; i < MAX_SIZE; ++i) {
114  counter = db_index_id[i];
115  itemvector[i] = itemvector[counter];
116  itemvector[i].ped = int(db_peds[i]);
117  itemvector[i].rms = int(db_pedrms[i]);
118 
119  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
120  if (counter == new_index_id[k]) {
121  if ((short int)(fabs(new_peds[k] * PED_FACTOR + 0.5)) < MAX_SHORT)
122  itemvector[counter].ped = int(new_peds[k] * PED_FACTOR + 0.5);
123  if ((short int)(fabs(new_pedrms[k] * RMS_FACTOR + 0.5)) < MAX_SHORT)
124  itemvector[counter].rms = int(new_pedrms[k] * RMS_FACTOR + 0.5);
125  itemvector[i] = itemvector[counter];
126  // if (new_peds[k]==0) itemvector[counter].ped = int (db_peds[i]);
127  // if (new_pedrms[k]==0) itemvector[counter].rms = int (db_pedrms[i]);
128  }
129  }
130 
131  if (counter > 223968) {
132  itemvector[counter].ped = int(db_peds[i]);
133  itemvector[counter].rms = int(db_pedrms[i]);
134  itemvector[i] = itemvector[counter];
135  }
136  }
137  return cndbpedestals;
138 }
139 
140 #endif
counter
Definition: counter.py:1
CSCDBPedestalsRcd
Definition: CSCDBPedestalsRcd.h:5
CSCDBPedestals::pedestals
PedestalContainer pedestals
Definition: CSCDBPedestals.h:26
mps_fire.i
i
Definition: mps_fire.py:355
ESHandle.h
CSCDBPedestals::factor_ped
int factor_ped
Definition: CSCDBPedestals.h:20
edm::ValidityInterval
Definition: ValidityInterval.h:28
ESProducer.h
CSCPedestalsDBConditions::CSCPedestalsDBConditions
CSCPedestalsDBConditions(const edm::ParameterSet &)
Definition: CSCPedestalsDBConditions.cc:8
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
CSCDetId.h
CSCPedestalsDBConditions::cndbPedestals
CSCDBPedestals * cndbPedestals
Definition: CSCPedestalsDBConditions.h:36
MakerMacros.h
CSCPedestalsDBConditions::~CSCPedestalsDBConditions
~CSCPedestalsDBConditions() override
Definition: CSCPedestalsDBConditions.cc:17
CSCPedestalsDBConditions::prefillDBPedestals
static CSCDBPedestals * prefillDBPedestals()
Definition: CSCPedestalsDBConditions.h:48
CSCDBPedestals
Definition: CSCDBPedestals.h:9
CSCPedestalsDBConditions::ReturnType
std::unique_ptr< CSCDBPedestals > ReturnType
Definition: CSCPedestalsDBConditions.h:27
CSCPedestalsDBConditions::produceDBPedestals
ReturnType produceDBPedestals(const CSCDBPedestalsRcd &)
Definition: CSCPedestalsDBConditions.cc:27
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
EventSetupRecordIntervalFinder.h
SourceFactory.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
CSCDBPedestals.h
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
recoMuon::in
Definition: RecoMuonEnumerators.h:6
createfilelist.int
int
Definition: createfilelist.py:10
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:15
Frameworkfwd.h
EventSetup.h
edm::ESProducer
Definition: ESProducer.h:101
CSCDBPedestals::PedestalContainer
std::vector< Item > PedestalContainer
Definition: CSCDBPedestals.h:25
CSCPedestalsDBConditions::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: CSCPedestalsDBConditions.cc:32
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
ParameterSet.h
CSCDBPedestalsRcd.h
CSCPedestalsDBConditions
Definition: CSCPedestalsDBConditions.h:20
CSCDBPedestals::factor_rms
int factor_rms
Definition: CSCDBPedestals.h:21