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 = 217728; 00052 const int MAX_SHORT= 32767; 00053 CSCDBPedestals * cndbpedestals = new CSCDBPedestals(); 00054 00055 int db_index; 00056 float db_ped, db_rms; 00057 std::vector<int> db_index_id; 00058 std::vector<float> db_peds; 00059 std::vector<float> db_pedrms; 00060 int new_index; 00061 float new_ped,new_rms; 00062 std::vector<int> new_index_id; 00063 std::vector<float> new_peds; 00064 std::vector<float> new_pedrms; 00065 00066 int counter; 00067 int db_nrlines=0; 00068 int new_nrlines=0; 00069 00070 std::ifstream dbdata; 00071 dbdata.open("old_dbpeds.dat",std::ios::in); 00072 if(!dbdata) { 00073 std::cerr <<"Error: old_dbpeds.dat -> no such file!"<< std::endl; 00074 exit(1); 00075 } 00076 00077 while (!dbdata.eof() ) { 00078 dbdata >> db_index >> db_ped >> db_rms ; 00079 db_index_id.push_back(db_index); 00080 db_peds.push_back(db_ped); 00081 db_pedrms.push_back(db_rms); 00082 db_nrlines++; 00083 } 00084 dbdata.close(); 00085 00086 std::ifstream newdata; 00087 newdata.open("peds.dat",std::ios::in); 00088 if(!newdata) { 00089 std::cerr <<"Error: peds.dat -> no such file!"<< std::endl; 00090 exit(1); 00091 } 00092 00093 while (!newdata.eof() ) { 00094 newdata >> new_index >> new_ped >> new_rms ; 00095 new_index_id.push_back(new_index); 00096 new_peds.push_back(new_ped); 00097 new_pedrms.push_back(new_rms); 00098 new_nrlines++; 00099 } 00100 newdata.close(); 00101 00102 CSCDBPedestals::PedestalContainer & itemvector = cndbpedestals->pedestals; 00103 itemvector.resize(MAX_SIZE); 00104 cndbpedestals->factor_ped= int (PED_FACTOR); 00105 cndbpedestals->factor_rms= int (RMS_FACTOR); 00106 00107 for(int i=0; i<MAX_SIZE;++i){ 00108 itemvector[i].ped= (short int) (db_peds[i]*PED_FACTOR+0.5); 00109 itemvector[i].rms= (short int) (db_pedrms[i]*RMS_FACTOR+0.5); 00110 } 00111 00112 for(int i=0; i<MAX_SIZE;++i){ 00113 counter=db_index_id[i]; 00114 for (unsigned int k=0;k<new_index_id.size()-1;k++){ 00115 if(counter==new_index_id[k]){ 00116 if((short int) (fabs(new_peds[k]*PED_FACTOR+0.5))<MAX_SHORT) itemvector[counter].ped= int (new_peds[k]*PED_FACTOR+0.5); 00117 if((short int) (fabs(new_pedrms[k]*RMS_FACTOR+0.5))<MAX_SHORT) itemvector[counter].rms= int (new_pedrms[k]*RMS_FACTOR+0.5); 00118 itemvector[i] = itemvector[counter]; 00119 //std::cout<<"counter "<<counter<<" new_index_id[k] "<<new_index_id[k]<<" new_slope[k] "<<new_slope[k]<<" db_slope[k] "<<db_slope[k]<<std::endl; 00120 } 00121 } 00122 } 00123 return cndbpedestals; 00124 } 00125 00126 #endif