CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/CalibMuon/CSCCalibration/interface/CSCGainsDBConditions.h

Go to the documentation of this file.
00001 #ifndef _CSCGAINSDBCONDITIONS_H
00002 #define _CSCGAINSDBCONDITIONS_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/CSCDBGains.h"
00018 #include "CondFormats/DataRecord/interface/CSCDBGainsRcd.h"
00019 
00020 class CSCGainsDBConditions: public edm::ESProducer, public edm::EventSetupRecordIntervalFinder  {
00021  public:
00022   CSCGainsDBConditions(const edm::ParameterSet&);
00023   ~CSCGainsDBConditions();
00024   
00025 
00026   inline static CSCDBGains *  prefillDBGains();
00027 
00028   typedef const  CSCDBGains * ReturnType;
00029   
00030   ReturnType produceDBGains(const CSCDBGainsRcd&);
00031   
00032  private:
00033   // ----------member data ---------------------------
00034   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue&, edm::ValidityInterval & );
00035   CSCDBGains *cndbGains ;
00036 
00037 };
00038 
00039 #include<fstream>
00040 #include<vector>
00041 #include<iostream>
00042 
00043 // to workaround plugin library
00044 inline CSCDBGains *  CSCGainsDBConditions::prefillDBGains()
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   CSCDBGains * cndbgains = new CSCDBGains();
00051     
00052   int db_index;
00053   float db_gainslope;//db_intercpt, db_chisq;
00054   std::vector<int> db_index_id;
00055   std::vector<float> db_slope;
00056   std::vector<float> db_intercept;
00057   std::vector<float> db_chi2;
00058   int new_index;
00059   float new_gainslope,new_intercpt, new_chisq;
00060   std::vector<int> new_cham_id;
00061   std::vector<int> new_index_id;
00062   std::vector<int> new_strips;
00063   std::vector<float> new_slope;
00064   std::vector<float> new_intercept;
00065   std::vector<float> new_chi2;
00066 
00067   int counter;
00068   int db_nrlines=0;
00069   int new_nrlines=0;
00070   
00071   std::ifstream dbdata; 
00072   dbdata.open("old_dbgains.dat",std::ios::in); 
00073   if(!dbdata) {
00074     std::cerr <<"Error: old_dbgains.dat -> no such file!"<< std::endl;
00075     exit(1);
00076   }
00077   
00078   while (!dbdata.eof() ) { 
00079     dbdata >> db_index >> db_gainslope; 
00080     db_index_id.push_back(db_index);
00081     db_slope.push_back(db_gainslope);
00082     //db_intercept.push_back(db_intercpt);
00083     //db_chi2.push_back(db_chisq);
00084     db_nrlines++;
00085   }
00086   dbdata.close();
00087 
00088   std::ifstream newdata;
00089   newdata.open("gains.dat",std::ios::in); 
00090   if(!newdata) {
00091     std::cerr <<"Error: gains.dat -> no such file!"<< std::endl;
00092     exit(1);
00093   }
00094   
00095   while (!newdata.eof() ) { 
00096     newdata >> new_index >> new_gainslope >> new_intercpt >> new_chisq ; 
00097     new_index_id.push_back(new_index);
00098     new_slope.push_back(new_gainslope);
00099     new_intercept.push_back(new_intercpt);
00100     new_chi2.push_back(new_chisq);
00101     new_nrlines++;
00102   }
00103   newdata.close();
00104 
00105   CSCDBGains::GainContainer & itemvector = cndbgains->gains;
00106   itemvector.resize(MAX_SIZE);
00107   cndbgains->factor_gain = (short int) (FACTOR);
00108   std::cout<<" myfactor "<<cndbgains->factor_gain<<std::endl;
00109 
00110   for(int i=0; i<MAX_SIZE;++i){
00111     itemvector[i].gain_slope= int (db_slope[i]*FACTOR+0.5);
00112   }
00113 
00114    for(int i=0; i<MAX_SIZE;++i){
00115      counter=db_index_id[i]; 
00116      itemvector[i] = itemvector[counter];
00117      itemvector[i].gain_slope = int (db_slope[i]);
00118  
00119      for (unsigned int k=0;k<new_index_id.size()-1;k++){
00120        if(counter==new_index_id[k]){
00121          if ((short int) (fabs(new_slope[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].gain_slope= int (new_slope[k]*FACTOR+0.5);
00122          itemvector[i] = itemvector[counter];
00123        }
00124      }
00125      if(counter>223968){
00126        itemvector[counter].gain_slope = int (db_slope[i]);
00127        itemvector[i] = itemvector[counter];
00128      }
00129    }
00130      return cndbgains;
00131 }
00132 
00133 
00134 #endif
00135