CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CalibMuon/CSCCalibration/interface/CSCNoiseMatrixDBConditions.h

Go to the documentation of this file.
00001 #ifndef _CSCNOISEMATRIXDBCONDITIONS_H
00002 #define _CSCNOISEMATRIXDBCONDITIONS_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/CSCDBNoiseMatrix.h"
00018 #include "CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h"
00019 
00020 class CSCNoiseMatrixDBConditions: public edm::ESProducer, public edm::EventSetupRecordIntervalFinder  {
00021  public:
00022   CSCNoiseMatrixDBConditions(const edm::ParameterSet&);
00023   ~CSCNoiseMatrixDBConditions();
00024   
00025   inline static CSCDBNoiseMatrix * prefillDBNoiseMatrix();
00026 
00027   typedef const  CSCDBNoiseMatrix * ReturnType;
00028   
00029   ReturnType produceDBNoiseMatrix(const CSCDBNoiseMatrixRcd&);
00030   
00031  private:
00032   // ----------member data ---------------------------
00033   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue&, edm::ValidityInterval & );
00034   CSCDBNoiseMatrix *cndbMatrix ;
00035 
00036 };
00037 
00038 
00039 #include<fstream>
00040 #include<vector>
00041 #include<iostream>
00042 
00043 // to workaround plugin library
00044 inline CSCDBNoiseMatrix *  CSCNoiseMatrixDBConditions::prefillDBNoiseMatrix()
00045 {
00046   //const int MAX_SIZE = 273024; //for ME1a unganged
00047   const int MAX_SIZE = 252288;
00048   const int FACTOR=1000;
00049   const int MAX_SHORT= 32767;
00050  
00051   int new_index, db_index;
00052   float db_elm33,db_elm34, db_elm44, db_elm35, db_elm45, db_elm55;
00053   float db_elm46, db_elm56, db_elm66, db_elm57, db_elm67, db_elm77;
00054   std::vector<int> db_index_id;
00055   std::vector<float> db_elem33;
00056   std::vector<float> db_elem34;
00057   std::vector<float> db_elem44;
00058   std::vector<float> db_elem45;
00059   std::vector<float> db_elem35;
00060   std::vector<float> db_elem55;
00061   std::vector<float> db_elem46;
00062   std::vector<float> db_elem56;
00063   std::vector<float> db_elem66;
00064   std::vector<float> db_elem57;
00065   std::vector<float> db_elem67;
00066   std::vector<float> db_elem77;
00067 
00068 
00069   float new_elm33,new_elm34, new_elm44, new_elm35, new_elm45, new_elm55;
00070   float  new_elm46, new_elm56, new_elm66, new_elm57, new_elm67, new_elm77;
00071   std::vector<int> new_cham_id;
00072   std::vector<int> new_index_id;
00073   std::vector<float> new_elem33;
00074   std::vector<float> new_elem34;
00075   std::vector<float> new_elem44;
00076   std::vector<float> new_elem45;
00077   std::vector<float> new_elem35;
00078   std::vector<float> new_elem55;
00079   std::vector<float> new_elem46;
00080   std::vector<float> new_elem56;
00081   std::vector<float> new_elem66;
00082   std::vector<float> new_elem57;
00083   std::vector<float> new_elem67;
00084   std::vector<float> new_elem77;
00085 
00086   CSCDBNoiseMatrix * cndbmatrix = new CSCDBNoiseMatrix();
00087 
00088  int counter;
00089   int db_nrlines=0;
00090   int new_nrlines=0;
00091     
00092   std::ifstream dbdata; 
00093   dbdata.open("old_dbmatrix.dat",std::ios::in); 
00094   if(!dbdata) {
00095     std::cerr <<"Error: old_dbmatrix.dat -> no such file!"<< std::endl;
00096     exit(1);
00097   }
00098   
00099   while (!dbdata.eof() ) { 
00100     dbdata >> db_index >> db_elm33 >> db_elm34 >> db_elm44 >> db_elm35 >> db_elm45 >> db_elm55 >> db_elm46 >> db_elm56 >> db_elm66 >> db_elm57 >> db_elm67 >> db_elm77 ; 
00101     db_index_id.push_back(db_index);
00102     db_elem33.push_back(db_elm33);
00103     db_elem34.push_back(db_elm34);
00104     db_elem35.push_back(db_elm35);
00105     db_elem44.push_back(db_elm44);
00106     db_elem45.push_back(db_elm45);
00107     db_elem46.push_back(db_elm46);
00108     db_elem55.push_back(db_elm55);
00109     db_elem56.push_back(db_elm56);
00110     db_elem57.push_back(db_elm57);
00111     db_elem66.push_back(db_elm66);
00112     db_elem67.push_back(db_elm67);
00113     db_elem77.push_back(db_elm77);
00114     db_nrlines++;
00115   }
00116   dbdata.close();
00117 
00118   std::ifstream newdata;
00119   newdata.open("matrix.dat",std::ios::in); 
00120   if(!newdata) {
00121     std::cerr <<"Error: matrix.dat -> no such file!"<< std::endl;
00122     exit(1);
00123   }
00124   
00125   while (!newdata.eof() ) { 
00126     newdata >> new_index>> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >> new_elm55 >> new_elm46 >> new_elm56 >> new_elm66 >> new_elm57 >> new_elm67 >> new_elm77 ; 
00127     //new_cham_id.push_back(new_chamber_id);
00128     new_index_id.push_back(new_index);
00129     new_elem33.push_back(new_elm33);
00130     new_elem34.push_back(new_elm34);
00131     new_elem35.push_back(new_elm35);
00132     new_elem44.push_back(new_elm44);
00133     new_elem45.push_back(new_elm45);
00134     new_elem46.push_back(new_elm46);
00135     new_elem55.push_back(new_elm55);
00136     new_elem56.push_back(new_elm56);
00137     new_elem57.push_back(new_elm57);
00138     new_elem66.push_back(new_elm66);
00139     new_elem67.push_back(new_elm67);
00140     new_elem77.push_back(new_elm77); 
00141     new_nrlines++;
00142   }
00143   newdata.close();
00144   
00145   CSCDBNoiseMatrix::NoiseMatrixContainer & itemvector = cndbmatrix->matrix;
00146   itemvector.resize(MAX_SIZE);
00147   cndbmatrix->factor_noise= int (FACTOR);
00148   
00149   for(int i=0; i<MAX_SIZE;++i){
00150     itemvector[i].elem33 = (short int) (db_elem33[i]*FACTOR+0.5);
00151     itemvector[i].elem34 = (short int) (db_elem34[i]*FACTOR+0.5); 
00152     itemvector[i].elem35 = (short int) (db_elem35[i]*FACTOR+0.5);
00153     itemvector[i].elem44 = (short int) (db_elem44[i]*FACTOR+0.5);
00154     itemvector[i].elem45 = (short int) (db_elem45[i]*FACTOR+0.5);
00155     itemvector[i].elem46 = (short int) (db_elem46[i]*FACTOR+0.5);
00156     itemvector[i].elem55 = (short int) (db_elem55[i]*FACTOR+0.5);
00157     itemvector[i].elem56 = (short int) (db_elem56[i]*FACTOR+0.5);
00158     itemvector[i].elem57 = (short int) (db_elem57[i]*FACTOR+0.5);
00159     itemvector[i].elem66 = (short int) (db_elem66[i]*FACTOR+0.5);
00160     itemvector[i].elem67 = (short int) (db_elem67[i]*FACTOR+0.5);
00161     itemvector[i].elem77 = (short int) (db_elem77[i]*FACTOR+0.5);
00162   }
00163 
00164   
00165   for(int i=0; i<MAX_SIZE;++i){
00166     counter=db_index_id[i];  
00167     itemvector[i] = itemvector[counter];
00168     itemvector[i].elem33 = int (db_elem33[i]);
00169     itemvector[i].elem34 = int (db_elem34[i]);
00170     itemvector[i].elem35 = int (db_elem35[i]);
00171     itemvector[i].elem44 = int (db_elem44[i]);
00172     itemvector[i].elem45 = int (db_elem45[i]);
00173     itemvector[i].elem46 = int (db_elem46[i]);
00174     itemvector[i].elem55 = int (db_elem55[i]);
00175     itemvector[i].elem56 = int (db_elem56[i]);
00176     itemvector[i].elem57 = int (db_elem57[i]);
00177     itemvector[i].elem66 = int (db_elem66[i]);
00178     itemvector[i].elem67 = int (db_elem67[i]);
00179     itemvector[i].elem77 = int (db_elem77[i]);
00180     
00181     for (unsigned int k=0;k<new_index_id.size()-1;k++){
00182       if(counter==new_index_id[k]){
00183         if((short int) (fabs(new_elem33[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem33 = int (new_elem33[k]*FACTOR+0.5);
00184         if((short int) (fabs(new_elem34[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem34 = int (new_elem34[k]*FACTOR+0.5); 
00185         if((short int) (fabs(new_elem35[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem35 = int (new_elem35[k]*FACTOR+0.5);
00186         if((short int) (fabs(new_elem44[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem44 = int (new_elem44[k]*FACTOR+0.5);
00187         if((short int) (fabs(new_elem45[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem45 = int (new_elem45[k]*FACTOR+0.5);
00188         if((short int) (fabs(new_elem46[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem46 = int (new_elem46[k]*FACTOR+0.5);
00189         if((short int) (fabs(new_elem55[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem55 = int (new_elem55[k]*FACTOR+0.5);
00190         if((short int) (fabs(new_elem56[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem56 = int (new_elem56[k]*FACTOR+0.5);
00191         if((short int) (fabs(new_elem57[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem57 = int (new_elem57[k]*FACTOR+0.5);
00192         if((short int) (fabs(new_elem66[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem66 = int (new_elem66[k]*FACTOR+0.5);
00193         if((short int) (fabs(new_elem67[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem67 = int (new_elem67[k]*FACTOR+0.5);
00194         if((short int) (fabs(new_elem77[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem77 = int (new_elem77[k]*FACTOR+0.5);
00195         itemvector[i] = itemvector[counter];
00196       }  
00197     }
00198 
00199     if (counter>223968){
00200       itemvector[counter].elem33 = int (db_elem33[i]);
00201       itemvector[counter].elem34 = int (db_elem34[i]);
00202       itemvector[counter].elem35 = int (db_elem35[i]);
00203       itemvector[counter].elem44 = int (db_elem44[i]);
00204       itemvector[counter].elem45 = int (db_elem45[i]);
00205       itemvector[counter].elem46 = int (db_elem46[i]);
00206       itemvector[counter].elem55 = int (db_elem55[i]);
00207       itemvector[counter].elem56 = int (db_elem56[i]);
00208       itemvector[counter].elem57 = int (db_elem57[i]);
00209       itemvector[counter].elem66 = int (db_elem66[i]);
00210       itemvector[counter].elem67 = int (db_elem67[i]);
00211       itemvector[counter].elem77 = int (db_elem77[i]);
00212       itemvector[i] = itemvector[counter];
00213     }
00214   }
00215   
00216   return cndbmatrix;
00217 }
00218 
00219 #endif
00220