Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:33

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   // ----------member data ---------------------------
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 // to workaround plugin library
0048 inline CSCDBPedestals *CSCPedestalsDBConditions::prefillDBPedestals() {
0049   const int PED_FACTOR = 10;
0050   const int RMS_FACTOR = 1000;
0051   const int MAX_SIZE = 252288;
0052   // const int MAX_SIZE = 273024; //for extra ME1a unganged case
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   int db_nrlines = 0;
0069   int new_nrlines = 0;
0070 
0071   std::ifstream dbdata;
0072   dbdata.open("old_dbpeds.dat", std::ios::in);
0073   if (!dbdata) {
0074     std::cerr << "Error: old_dbpeds.dat -> no such file!" << std::endl;
0075     exit(1);
0076   }
0077 
0078   while (!dbdata.eof()) {
0079     dbdata >> db_index >> db_ped >> db_rms;
0080     db_index_id.push_back(db_index);
0081     db_peds.push_back(db_ped);
0082     db_pedrms.push_back(db_rms);
0083     db_nrlines++;
0084   }
0085   dbdata.close();
0086 
0087   std::ifstream newdata;
0088   newdata.open("peds.dat", std::ios::in);
0089   if (!newdata) {
0090     std::cerr << "Error: peds.dat -> no such file!" << std::endl;
0091     exit(1);
0092   }
0093 
0094   while (!newdata.eof()) {
0095     newdata >> new_index >> new_ped >> new_rms;
0096     new_index_id.push_back(new_index);
0097     new_peds.push_back(new_ped);
0098     new_pedrms.push_back(new_rms);
0099     new_nrlines++;
0100   }
0101   newdata.close();
0102 
0103   CSCDBPedestals::PedestalContainer &itemvector = cndbpedestals->pedestals;
0104   itemvector.resize(MAX_SIZE);
0105   cndbpedestals->factor_ped = int(PED_FACTOR);
0106   cndbpedestals->factor_rms = int(RMS_FACTOR);
0107 
0108   for (int i = 0; i < MAX_SIZE; ++i) {
0109     itemvector[i].ped = (short int)(db_peds[i] * PED_FACTOR + 0.5);
0110     itemvector[i].rms = (short int)(db_pedrms[i] * RMS_FACTOR + 0.5);
0111   }
0112 
0113   for (int i = 0; i < MAX_SIZE; ++i) {
0114     counter = db_index_id[i];
0115     itemvector[i] = itemvector[counter];
0116     itemvector[i].ped = int(db_peds[i]);
0117     itemvector[i].rms = int(db_pedrms[i]);
0118 
0119     for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
0120       if (counter == new_index_id[k]) {
0121         if ((short int)(fabs(new_peds[k] * PED_FACTOR + 0.5)) < MAX_SHORT)
0122           itemvector[counter].ped = int(new_peds[k] * PED_FACTOR + 0.5);
0123         if ((short int)(fabs(new_pedrms[k] * RMS_FACTOR + 0.5)) < MAX_SHORT)
0124           itemvector[counter].rms = int(new_pedrms[k] * RMS_FACTOR + 0.5);
0125         itemvector[i] = itemvector[counter];
0126         // if (new_peds[k]==0) itemvector[counter].ped = int (db_peds[i]);
0127         // if (new_pedrms[k]==0) itemvector[counter].rms = int (db_pedrms[i]);
0128       }
0129     }
0130 
0131     if (counter > 223968) {
0132       itemvector[counter].ped = int(db_peds[i]);
0133       itemvector[counter].rms = int(db_pedrms[i]);
0134       itemvector[i] = itemvector[counter];
0135     }
0136   }
0137   return cndbpedestals;
0138 }
0139 
0140 #endif