CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CalibMuon/CSCCalibration/interface/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 = 273024; //for ME1a unganged
00049   const int MAX_SIZE = 252288;
00050   const int SLOPE_FACTOR=10000000;
00051   const int INTERCEPT_FACTOR=100000;
00052   const int MAX_SHORT= 32767;
00053   CSCDBCrosstalk * cndbcrosstalk = new CSCDBCrosstalk();
00054 
00055   int db_index,new_index;
00056   float db_slope_right,db_slope_left,db_intercept_right;
00057   float db_intercept_left;
00058   std::vector<int> db_index_id;
00059   std::vector<float> db_slope_r;
00060   std::vector<float> db_intercept_r;
00061   std::vector<float> db_slope_l;
00062   std::vector<float> db_intercept_l;
00063   float new_slope_right,new_slope_left,new_intercept_right;
00064   float new_intercept_left;
00065    std::vector<int> new_index_id;
00066    std::vector<float> new_slope_r;
00067   std::vector<float> new_intercept_r;
00068   std::vector<float> new_slope_l;
00069   std::vector<float> new_intercept_l;
00070     
00071   int counter;
00072   int db_nrlines=0;
00073   int new_nrlines=0;
00074     
00075   std::ifstream dbdata; 
00076   dbdata.open("old_dbxtalk.dat",std::ios::in); 
00077   if(!dbdata) {
00078     std::cerr <<"Error: old_dbxtalk.dat -> no such file!"<< std::endl;
00079     exit(1);
00080   }
00081   
00082   while (!dbdata.eof() ) { 
00083     dbdata >> db_index >> db_slope_right >> db_intercept_right >> db_slope_left >> db_intercept_left ;
00084     db_index_id.push_back(db_index);
00085     db_slope_r.push_back(db_slope_right);
00086     db_slope_l.push_back(db_slope_left);
00087     db_intercept_r.push_back(db_intercept_right);
00088     db_intercept_l.push_back(db_intercept_left);
00089     db_nrlines++;
00090   }
00091   dbdata.close();
00092 
00093   std::ifstream newdata;
00094   newdata.open("xtalk.dat",std::ios::in); 
00095   if(!newdata) {
00096     std::cerr <<"Error: xtalk.dat -> no such file!"<< std::endl;
00097     exit(1);
00098   }
00099   
00100   while (!newdata.eof() ) { 
00101     newdata >> new_index >> new_slope_right >> new_intercept_right >> new_slope_left >> new_intercept_left; 
00102     new_index_id.push_back(new_index);
00103     new_slope_r.push_back(new_slope_right);
00104     new_slope_l.push_back(new_slope_left);
00105     new_intercept_r.push_back(new_intercept_right);
00106     new_intercept_l.push_back(new_intercept_left);
00107     new_nrlines++;
00108   }
00109   newdata.close();
00110   
00111   CSCDBCrosstalk::CrosstalkContainer & itemvector = cndbcrosstalk->crosstalk;
00112   itemvector.resize(MAX_SIZE);
00113   cndbcrosstalk->factor_slope = int (SLOPE_FACTOR);
00114   cndbcrosstalk->factor_intercept = int (INTERCEPT_FACTOR);
00115 
00116   for(int i=0; i<MAX_SIZE;++i){
00117     itemvector[i].xtalk_slope_right=(short int) (db_slope_r[i]*SLOPE_FACTOR+0.5);
00118     itemvector[i].xtalk_intercept_right= (short int) (db_intercept_r[i]*INTERCEPT_FACTOR+0.5); 
00119     itemvector[i].xtalk_slope_left= (short int) (db_slope_l[i]*SLOPE_FACTOR+0.5);  
00120     itemvector[i].xtalk_intercept_left= (short int) (db_intercept_l[i]*INTERCEPT_FACTOR+0.5);  
00121   }
00122 
00123   for(int i=0; i<MAX_SIZE;++i){
00124     counter=db_index_id[i];  
00125     for (unsigned int k=0;k<new_index_id.size()-1;k++){
00126       if(counter==new_index_id[k]){
00127         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);
00128         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); 
00129         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);  
00130         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);  
00131         itemvector[i] = itemvector[counter];
00132         //std::cout<<" counter "<<counter <<" dbindex "<<new_index_id[k]<<" dbslope " <<db_slope_r[k]<<" new slope "<<new_slope_r[k]<<std::endl;
00133       }  
00134     }
00135 
00136      if (counter>223968){
00137       itemvector[counter].xtalk_slope_right = int (db_slope_r[i]);
00138       itemvector[counter].xtalk_slope_left = int (db_slope_l[i]);
00139       itemvector[counter].xtalk_intercept_right = int (db_intercept_r[i]);
00140       itemvector[counter].xtalk_intercept_left = int (db_intercept_l[i]);
00141      }
00142   }
00143   
00144   return cndbcrosstalk;
00145 
00146 }
00147   
00148 #endif
00149