CMS 3D CMS Logo

CSCCrosstalkDBConditions.h

Go to the documentation of this file.
00001 #ifndef _CSCCROSSTALKDBCONDITIONS_H
00002 #define _CSCCROSSTALKDBCONDITIONS_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/CSCDBCrosstalk.h"
00018 #include "CondFormats/DataRecord/interface/CSCDBCrosstalkRcd.h"
00019 
00020 class CSCCrosstalkDBConditions: public edm::ESProducer, public edm::EventSetupRecordIntervalFinder  {
00021  public:
00022   CSCCrosstalkDBConditions(const edm::ParameterSet&);
00023   ~CSCCrosstalkDBConditions();
00024   
00025 
00026   inline static CSCDBCrosstalk * prefillDBCrosstalk();
00027 
00028   typedef const  CSCDBCrosstalk * ReturnType;
00029   
00030   ReturnType produceDBCrosstalk(const CSCDBCrosstalkRcd&);
00031   
00032  private:
00033   // ----------member data ---------------------------
00034   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue&, edm::ValidityInterval & );
00035 
00036 
00037   CSCDBCrosstalk *cndbCrosstalk ;
00038 
00039 };
00040 
00041 #include<fstream>
00042 #include<vector>
00043 #include<iostream>
00044 
00045 // to workaround plugin library
00046 inline CSCDBCrosstalk *  CSCCrosstalkDBConditions::prefillDBCrosstalk()
00047 {
00048   const int MAX_SIZE = 217728;
00049   const int SLOPE_FACTOR=10000000;
00050   const int INTERCEPT_FACTOR=100000;
00051   const int MAX_SHORT= 32767;
00052   CSCDBCrosstalk * cndbcrosstalk = new CSCDBCrosstalk();
00053 
00054   int db_index,new_index;
00055   float db_slope_right,db_slope_left,db_intercept_right;
00056   float db_intercept_left, db_chi2_right,db_chi2_left;
00057   std::vector<int> db_index_id;
00058   std::vector<float> db_slope_r;
00059   std::vector<float> db_intercept_r;
00060   std::vector<float> db_chi2_r;
00061   std::vector<float> db_slope_l;
00062   std::vector<float> db_intercept_l;
00063   std::vector<float> db_chi2_l;
00064   float new_slope_right,new_slope_left,new_intercept_right;
00065   float new_intercept_left, new_chi2_right,new_chi2_left;
00066   std::vector<int> new_cham_id;
00067   std::vector<int> new_index_id;
00068   std::vector<int> new_strips;
00069   std::vector<float> new_slope_r;
00070   std::vector<float> new_intercept_r;
00071   std::vector<float> new_chi2_r;
00072   std::vector<float> new_slope_l;
00073   std::vector<float> new_intercept_l;
00074   std::vector<float> new_chi2_l;
00075     
00076   int counter;
00077   int db_nrlines=0;
00078   int new_nrlines=0;
00079     
00080   std::ifstream dbdata; 
00081   dbdata.open("old_dbxtalk.dat",std::ios::in); 
00082   if(!dbdata) {
00083     std::cerr <<"Error: old_dbxtalk.dat -> no such file!"<< std::endl;
00084     exit(1);
00085   }
00086   
00087   while (!dbdata.eof() ) { 
00088     dbdata >> db_index >> db_slope_right >> db_intercept_right >> db_chi2_right >> db_slope_left >> db_intercept_left >> db_chi2_left ;
00089     db_index_id.push_back(db_index);
00090     db_slope_r.push_back(db_slope_right);
00091     db_slope_l.push_back(db_slope_left);
00092     db_intercept_r.push_back(db_intercept_right);
00093     db_intercept_l.push_back(db_intercept_left);
00094     db_chi2_r.push_back(db_chi2_right);
00095     db_chi2_l.push_back(db_chi2_left); 
00096     db_nrlines++;
00097   }
00098   dbdata.close();
00099 
00100   std::ifstream newdata;
00101   newdata.open("xtalk.dat",std::ios::in); 
00102   if(!newdata) {
00103     std::cerr <<"Error: xtalk.dat -> no such file!"<< std::endl;
00104     exit(1);
00105   }
00106   
00107   while (!newdata.eof() ) { 
00108     newdata >> new_index >> new_slope_right >> new_intercept_right >> new_chi2_right >> new_slope_left >> new_intercept_left >> new_chi2_left ; 
00109     new_index_id.push_back(new_index);
00110     new_slope_r.push_back(new_slope_right);
00111     new_slope_l.push_back(new_slope_left);
00112     new_intercept_r.push_back(new_intercept_right);
00113     new_intercept_l.push_back(new_intercept_left);
00114     new_chi2_r.push_back(new_chi2_right);
00115     new_chi2_l.push_back(new_chi2_left);
00116     new_nrlines++;
00117   }
00118   newdata.close();
00119   
00120   CSCDBCrosstalk::CrosstalkContainer & itemvector = cndbcrosstalk->crosstalk;
00121   itemvector.resize(MAX_SIZE);
00122   cndbcrosstalk->factor_slope = int (SLOPE_FACTOR);
00123   cndbcrosstalk->factor_intercept = int (INTERCEPT_FACTOR);
00124 
00125   for(int i=0; i<MAX_SIZE;++i){
00126     itemvector[i].xtalk_slope_right=(short int) (db_slope_r[i]*SLOPE_FACTOR+0.5);
00127     itemvector[i].xtalk_intercept_right= (short int) (db_intercept_r[i]*INTERCEPT_FACTOR+0.5); 
00128     itemvector[i].xtalk_slope_left= (short int) (db_slope_l[i]*SLOPE_FACTOR+0.5);  
00129     itemvector[i].xtalk_intercept_left= (short int) (db_intercept_l[i]*INTERCEPT_FACTOR+0.5);  
00130   }
00131 
00132   for(int i=0; i<MAX_SIZE;++i){
00133     counter=db_index_id[i];  
00134     for (unsigned int k=0;k<new_index_id.size()-1;k++){
00135       if(counter==new_index_id[k]){
00136         if ((short int) (fabs(new_slope_r[k]*SLOPE_FACTOR+0.5))<MAX_SHORT)         itemvector[counter].xtalk_slope_right= int (new_slope_r[k]*SLOPE_FACTOR+0.5);
00137         if ((short int) (fabs(new_intercept_r[k]*INTERCEPT_FACTOR+0.5))<MAX_SHORT) itemvector[counter].xtalk_intercept_right= int (new_intercept_r[k]*INTERCEPT_FACTOR+0.5); 
00138         if ((short int) (fabs(new_slope_l[k]*SLOPE_FACTOR+0.5))<MAX_SHORT)         itemvector[counter].xtalk_slope_left= int (new_slope_l[k]*SLOPE_FACTOR+0.5);  
00139         if ((short int) (fabs(new_intercept_l[k]*INTERCEPT_FACTOR+0.5))<MAX_SHORT) itemvector[counter].xtalk_intercept_left= int (new_intercept_l[k]*INTERCEPT_FACTOR+0.5);  
00140         itemvector[i] = itemvector[counter];
00141         //std::cout<<" counter "<<counter <<" dbindex "<<new_index_id[k]<<" dbslope " <<db_slope_r[k]<<" new slope "<<new_slope_r[k]<<std::endl;
00142       }  
00143     }
00144   }
00145   
00146   return cndbcrosstalk;
00147 
00148 }
00149   
00150 #endif
00151 

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