CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CalibMuon/CSCCalibration/interface/CSCPedestalsDBConditions.h

Go to the documentation of this file.
00001 #ifndef _CSCPEDESTALSDBCONDITIONS_H
00002 #define _CSCPEDESTALSDBCONDITIONS_H
00003 
00004 #include <memory>
00005 #include <cmath>
00006 #include "FWCore/Framework/interface/SourceFactory.h"
00007 #include "FWCore/Framework/interface/Frameworkfwd.h"
00008 #include "FWCore/Framework/interface/ESProducer.h"
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/Framework/interface/MakerMacros.h"
00011 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 
00016 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00017 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
00018 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
00019 
00020 class CSCPedestalsDBConditions: public edm::ESProducer, public edm::EventSetupRecordIntervalFinder  {
00021  public:
00022   CSCPedestalsDBConditions(const edm::ParameterSet&);
00023   ~CSCPedestalsDBConditions();
00024   
00025   inline static CSCDBPedestals * prefillDBPedestals();
00026 
00027   typedef const  CSCDBPedestals * ReturnType;
00028   
00029   ReturnType produceDBPedestals(const CSCDBPedestalsRcd&);
00030   
00031  private:
00032   // ----------member data ---------------------------
00033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue&, edm::ValidityInterval & );
00034   CSCDBPedestals *cndbPedestals ;
00035 
00036 };
00037 
00038 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00039 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
00040 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
00041 
00042 #include<fstream>
00043 #include<vector>
00044 #include<iostream>
00045 
00046 // to workaround plugin library
00047 inline CSCDBPedestals * CSCPedestalsDBConditions::prefillDBPedestals()  
00048 {
00049   const int PED_FACTOR=10;
00050   const int RMS_FACTOR=1000;
00051   const int MAX_SIZE = 252288;
00052   //const int MAX_SIZE = 273024; //for extra ME1a unganged case
00053   const int MAX_SHORT= 32767;
00054   CSCDBPedestals * cndbpedestals = new CSCDBPedestals();
00055 
00056   int db_index;
00057   float db_ped, db_rms;
00058   std::vector<int> db_index_id;
00059   std::vector<float> db_peds;
00060   std::vector<float> db_pedrms;
00061   int new_index;
00062   float new_ped,new_rms;
00063   std::vector<int> new_index_id;
00064   std::vector<float> new_peds;
00065   std::vector<float> new_pedrms;
00066 
00067   int counter;
00068   int db_nrlines=0;
00069   int new_nrlines=0;
00070   
00071   std::ifstream dbdata; 
00072   dbdata.open("old_dbpeds.dat",std::ios::in); 
00073   if(!dbdata) {
00074     std::cerr <<"Error: old_dbpeds.dat -> no such file!"<< std::endl;
00075     exit(1);
00076   }
00077   
00078   while (!dbdata.eof() ) { 
00079     dbdata >> db_index >> db_ped >> db_rms ; 
00080     db_index_id.push_back(db_index);
00081     db_peds.push_back(db_ped);
00082     db_pedrms.push_back(db_rms);
00083     db_nrlines++;
00084   }
00085   dbdata.close();
00086 
00087   std::ifstream newdata;
00088   newdata.open("peds.dat",std::ios::in); 
00089   if(!newdata) {
00090     std::cerr <<"Error: peds.dat -> no such file!"<< std::endl;
00091     exit(1);
00092   }
00093   
00094   while (!newdata.eof() ) { 
00095     newdata >> new_index >> new_ped >> new_rms ; 
00096     new_index_id.push_back(new_index);
00097     new_peds.push_back(new_ped);
00098     new_pedrms.push_back(new_rms);
00099     new_nrlines++;
00100   }
00101   newdata.close();
00102   
00103   CSCDBPedestals::PedestalContainer & itemvector = cndbpedestals->pedestals;
00104   itemvector.resize(MAX_SIZE);
00105   cndbpedestals->factor_ped= int (PED_FACTOR);
00106   cndbpedestals->factor_rms= int (RMS_FACTOR);
00107 
00108   for(int i=0; i<MAX_SIZE;++i){
00109     itemvector[i].ped= (short int) (db_peds[i]*PED_FACTOR+0.5);
00110     itemvector[i].rms= (short int) (db_pedrms[i]*RMS_FACTOR+0.5);
00111   }
00112 
00113   for(int i=0; i<MAX_SIZE;++i){
00114      counter=db_index_id[i];  
00115      itemvector[i] = itemvector[counter];
00116      itemvector[i].ped = int (db_peds[i]);
00117      itemvector[i].rms = int (db_pedrms[i]);
00118 
00119      for (unsigned int k=0;k<new_index_id.size()-1;k++){
00120        if(counter==new_index_id[k]){
00121          if((short int) (fabs(new_peds[k]*PED_FACTOR+0.5))<MAX_SHORT)   itemvector[counter].ped= int (new_peds[k]*PED_FACTOR+0.5);
00122          if((short int) (fabs(new_pedrms[k]*RMS_FACTOR+0.5))<MAX_SHORT) itemvector[counter].rms= int (new_pedrms[k]*RMS_FACTOR+0.5);
00123          itemvector[i] = itemvector[counter];
00124          //if (new_peds[k]==0) itemvector[counter].ped = int (db_peds[i]);
00125          //if (new_pedrms[k]==0) itemvector[counter].rms = int (db_pedrms[i]);
00126        }  
00127      }
00128      
00129      if (counter>223968){
00130        itemvector[counter].ped = int (db_peds[i]);
00131        itemvector[counter].rms = int (db_pedrms[i]);
00132        itemvector[i] = itemvector[counter];
00133      }
00134      
00135    }
00136    return cndbpedestals;
00137 }
00138 
00139 #endif