CMS 3D CMS Logo

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 = 217728;
00047   const int FACTOR=1000;
00048   const int MAX_SHORT= 32767;
00049  
00050   int new_index, db_index;
00051   float db_elm33,db_elm34, db_elm44, db_elm35, db_elm45, db_elm55;
00052   float db_elm46, db_elm56, db_elm66, db_elm57, db_elm67, db_elm77;
00053   std::vector<int> db_index_id;
00054   std::vector<float> db_elem33;
00055   std::vector<float> db_elem34;
00056   std::vector<float> db_elem44;
00057   std::vector<float> db_elem45;
00058   std::vector<float> db_elem35;
00059   std::vector<float> db_elem55;
00060   std::vector<float> db_elem46;
00061   std::vector<float> db_elem56;
00062   std::vector<float> db_elem66;
00063   std::vector<float> db_elem57;
00064   std::vector<float> db_elem67;
00065   std::vector<float> db_elem77;
00066 
00067 
00068   float new_elm33,new_elm34, new_elm44, new_elm35, new_elm45, new_elm55;
00069   float  new_elm46, new_elm56, new_elm66, new_elm57, new_elm67, new_elm77;
00070   std::vector<int> new_cham_id;
00071   std::vector<int> new_index_id;
00072   std::vector<float> new_elem33;
00073   std::vector<float> new_elem34;
00074   std::vector<float> new_elem44;
00075   std::vector<float> new_elem45;
00076   std::vector<float> new_elem35;
00077   std::vector<float> new_elem55;
00078   std::vector<float> new_elem46;
00079   std::vector<float> new_elem56;
00080   std::vector<float> new_elem66;
00081   std::vector<float> new_elem57;
00082   std::vector<float> new_elem67;
00083   std::vector<float> new_elem77;
00084 
00085   CSCDBNoiseMatrix * cndbmatrix = new CSCDBNoiseMatrix();
00086 
00087  int counter;
00088   int db_nrlines=0;
00089   int new_nrlines=0;
00090     
00091   std::ifstream dbdata; 
00092   dbdata.open("old_dbmatrix.dat",std::ios::in); 
00093   if(!dbdata) {
00094     std::cerr <<"Error: old_dbmatrix.dat -> no such file!"<< std::endl;
00095     exit(1);
00096   }
00097   
00098   while (!dbdata.eof() ) { 
00099     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 ; 
00100     db_index_id.push_back(db_index);
00101     db_elem33.push_back(db_elm33);
00102     db_elem34.push_back(db_elm34);
00103     db_elem44.push_back(db_elm44);
00104     db_elem35.push_back(db_elm35);
00105     db_elem45.push_back(db_elm45);
00106     db_elem55.push_back(db_elm55);
00107     db_elem46.push_back(db_elm46);
00108     db_elem56.push_back(db_elm56);
00109     db_elem66.push_back(db_elm66);
00110     db_elem57.push_back(db_elm57);
00111     db_elem67.push_back(db_elm67);
00112     db_elem77.push_back(db_elm77);
00113     db_nrlines++;
00114   }
00115   dbdata.close();
00116 
00117   std::ifstream newdata;
00118   newdata.open("matrix.dat",std::ios::in); 
00119   if(!newdata) {
00120     std::cerr <<"Error: matrix.dat -> no such file!"<< std::endl;
00121     exit(1);
00122   }
00123   
00124   while (!newdata.eof() ) { 
00125     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 ; 
00126     //new_cham_id.push_back(new_chamber_id);
00127     new_index_id.push_back(new_index);
00128     new_elem33.push_back(new_elm33);
00129     new_elem34.push_back(new_elm34);
00130     new_elem44.push_back(new_elm44);
00131     new_elem35.push_back(new_elm35);
00132     new_elem45.push_back(new_elm45);
00133     new_elem55.push_back(new_elm55);
00134     new_elem46.push_back(new_elm46);
00135     new_elem56.push_back(new_elm56);
00136     new_elem66.push_back(new_elm66);
00137     new_elem57.push_back(new_elm57);
00138     new_elem67.push_back(new_elm67);
00139     new_elem77.push_back(new_elm77); 
00140     new_nrlines++;
00141   }
00142   newdata.close();
00143   
00144   CSCDBNoiseMatrix::NoiseMatrixContainer & itemvector = cndbmatrix->matrix;
00145   itemvector.resize(MAX_SIZE);
00146   cndbmatrix->factor_noise= int (FACTOR);
00147   
00148   for(int i=0; i<MAX_SIZE;++i){
00149     itemvector[i].elem33 = (short int) (db_elem33[i]*FACTOR+0.5);
00150     itemvector[i].elem34 = (short int) (db_elem34[i]*FACTOR+0.5); 
00151     itemvector[i].elem44 = (short int) (db_elem44[i]*FACTOR+0.5);
00152     itemvector[i].elem35 = (short int) (db_elem35[i]*FACTOR+0.5);
00153     itemvector[i].elem45 = (short int) (db_elem45[i]*FACTOR+0.5);
00154     itemvector[i].elem55 = (short int) (db_elem55[i]*FACTOR+0.5);
00155     itemvector[i].elem46 = (short int) (db_elem46[i]*FACTOR+0.5);
00156     itemvector[i].elem56 = (short int) (db_elem56[i]*FACTOR+0.5);
00157     itemvector[i].elem66 = (short int) (db_elem66[i]*FACTOR+0.5);
00158     itemvector[i].elem57 = (short int) (db_elem57[i]*FACTOR+0.5);
00159     itemvector[i].elem67 = (short int) (db_elem67[i]*FACTOR+0.5);
00160     itemvector[i].elem77 = (short int) (db_elem77[i]*FACTOR+0.5);
00161   }
00162 
00163   
00164   for(int i=0; i<MAX_SIZE;++i){
00165     counter=db_index_id[i];  
00166     for (unsigned int k=0;k<new_index_id.size()-1;k++){
00167       if(counter==new_index_id[k]){
00168         if((short int) (fabs(new_elem33[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem33 = int (new_elem33[k]*FACTOR+0.5);
00169         if((short int) (fabs(new_elem34[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem34 = int (new_elem34[k]*FACTOR+0.5); 
00170         if((short int) (fabs(new_elem44[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem44 = int (new_elem44[k]*FACTOR+0.5);
00171         if((short int) (fabs(new_elem35[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem35 = int (new_elem35[k]*FACTOR+0.5);
00172         if((short int) (fabs(new_elem45[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem45 = int (new_elem45[k]*FACTOR+0.5);
00173         if((short int) (fabs(new_elem55[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem55 = int (new_elem55[k]*FACTOR+0.5);
00174         if((short int) (fabs(new_elem46[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem46 = int (new_elem46[k]*FACTOR+0.5);
00175         if((short int) (fabs(new_elem56[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem56 = int (new_elem56[k]*FACTOR+0.5);
00176         if((short int) (fabs(new_elem66[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem66 = int (new_elem66[k]*FACTOR+0.5);
00177         if((short int) (fabs(new_elem57[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem57 = int (new_elem57[k]*FACTOR+0.5);
00178         if((short int) (fabs(new_elem67[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem67 = int (new_elem67[k]*FACTOR+0.5);
00179         if((short int) (fabs(new_elem77[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem77 = int (new_elem77[k]*FACTOR+0.5);
00180         itemvector[i] = itemvector[counter];
00181       }  
00182     }
00183   }
00184   
00185   return cndbmatrix;
00186 }
00187 
00188 #endif
00189 

Generated on Tue Jun 9 17:25:27 2009 for CMSSW by  doxygen 1.5.4