File indexing completed on 2024-04-06 11:58:21
0001 #ifndef _CSCPEDESTALSDBCONDITIONS_H
0002 #define _CSCPEDESTALSDBCONDITIONS_H
0003
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/ESProducer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/SourceFactory.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include <cmath>
0014 #include <memory>
0015
0016 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
0017 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
0018 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0019
0020 class CSCPedestalsDBConditions : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0021 public:
0022 CSCPedestalsDBConditions(const edm::ParameterSet &);
0023 ~CSCPedestalsDBConditions() override;
0024
0025 inline static CSCDBPedestals *prefillDBPedestals();
0026
0027 typedef std::unique_ptr<CSCDBPedestals> ReturnType;
0028
0029 ReturnType produceDBPedestals(const CSCDBPedestalsRcd &);
0030
0031 private:
0032
0033 void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &,
0034 const edm::IOVSyncValue &,
0035 edm::ValidityInterval &) override;
0036 CSCDBPedestals *cndbPedestals;
0037 };
0038
0039 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
0040 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
0041 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0042
0043 #include <fstream>
0044 #include <iostream>
0045 #include <vector>
0046
0047
0048 inline CSCDBPedestals *CSCPedestalsDBConditions::prefillDBPedestals() {
0049 const int PED_FACTOR = 10;
0050 const int RMS_FACTOR = 1000;
0051 const int MAX_SIZE = 252288;
0052
0053 const int MAX_SHORT = 32767;
0054 CSCDBPedestals *cndbpedestals = new CSCDBPedestals();
0055
0056 int db_index;
0057 float db_ped, db_rms;
0058 std::vector<int> db_index_id;
0059 std::vector<float> db_peds;
0060 std::vector<float> db_pedrms;
0061 int new_index;
0062 float new_ped, new_rms;
0063 std::vector<int> new_index_id;
0064 std::vector<float> new_peds;
0065 std::vector<float> new_pedrms;
0066
0067 int counter;
0068
0069 std::ifstream dbdata;
0070 dbdata.open("old_dbpeds.dat", std::ios::in);
0071 if (!dbdata) {
0072 std::cerr << "Error: old_dbpeds.dat -> no such file!" << std::endl;
0073 exit(1);
0074 }
0075
0076 while (!dbdata.eof()) {
0077 dbdata >> db_index >> db_ped >> db_rms;
0078 db_index_id.push_back(db_index);
0079 db_peds.push_back(db_ped);
0080 db_pedrms.push_back(db_rms);
0081 }
0082 dbdata.close();
0083
0084 std::ifstream newdata;
0085 newdata.open("peds.dat", std::ios::in);
0086 if (!newdata) {
0087 std::cerr << "Error: peds.dat -> no such file!" << std::endl;
0088 exit(1);
0089 }
0090
0091 while (!newdata.eof()) {
0092 newdata >> new_index >> new_ped >> new_rms;
0093 new_index_id.push_back(new_index);
0094 new_peds.push_back(new_ped);
0095 new_pedrms.push_back(new_rms);
0096 }
0097 newdata.close();
0098
0099 CSCDBPedestals::PedestalContainer &itemvector = cndbpedestals->pedestals;
0100 itemvector.resize(MAX_SIZE);
0101 cndbpedestals->factor_ped = int(PED_FACTOR);
0102 cndbpedestals->factor_rms = int(RMS_FACTOR);
0103
0104 for (int i = 0; i < MAX_SIZE; ++i) {
0105 itemvector[i].ped = (short int)(db_peds[i] * PED_FACTOR + 0.5);
0106 itemvector[i].rms = (short int)(db_pedrms[i] * RMS_FACTOR + 0.5);
0107 }
0108
0109 for (int i = 0; i < MAX_SIZE; ++i) {
0110 counter = db_index_id[i];
0111 itemvector[i] = itemvector[counter];
0112 itemvector[i].ped = int(db_peds[i]);
0113 itemvector[i].rms = int(db_pedrms[i]);
0114
0115 for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
0116 if (counter == new_index_id[k]) {
0117 if ((short int)(fabs(new_peds[k] * PED_FACTOR + 0.5)) < MAX_SHORT)
0118 itemvector[counter].ped = int(new_peds[k] * PED_FACTOR + 0.5);
0119 if ((short int)(fabs(new_pedrms[k] * RMS_FACTOR + 0.5)) < MAX_SHORT)
0120 itemvector[counter].rms = int(new_pedrms[k] * RMS_FACTOR + 0.5);
0121 itemvector[i] = itemvector[counter];
0122
0123
0124 }
0125 }
0126
0127 if (counter > 223968) {
0128 itemvector[counter].ped = int(db_peds[i]);
0129 itemvector[counter].rms = int(db_pedrms[i]);
0130 itemvector[i] = itemvector[counter];
0131 }
0132 }
0133 return cndbpedestals;
0134 }
0135
0136 #endif