CMS 3D CMS Logo

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 = 217728;
00047   const int FACTOR = 1000;
00048   const int MAX_SHORT = 32767;
00049   CSCDBGains * cndbgains = new CSCDBGains();
00050     
00051   int db_index;
00052   float db_gainslope,db_intercpt, db_chisq;
00053   std::vector<int> db_index_id;
00054   std::vector<float> db_slope;
00055   std::vector<float> db_intercept;
00056   std::vector<float> db_chi2;
00057   int new_index;
00058   float new_gainslope,new_intercpt, new_chisq;
00059   std::vector<int> new_cham_id;
00060   std::vector<int> new_index_id;
00061   std::vector<int> new_strips;
00062   std::vector<float> new_slope;
00063   std::vector<float> new_intercept;
00064   std::vector<float> new_chi2;
00065 
00066   int counter;
00067   int db_nrlines=0;
00068   int new_nrlines=0;
00069   
00070   std::ifstream dbdata; 
00071   dbdata.open("old_dbgains.dat",std::ios::in); 
00072   if(!dbdata) {
00073     std::cerr <<"Error: old_dbgains.dat -> no such file!"<< std::endl;
00074     exit(1);
00075   }
00076   
00077   while (!dbdata.eof() ) { 
00078     dbdata >> db_index >> db_gainslope >> db_intercpt >> db_chisq ; 
00079     db_index_id.push_back(db_index);
00080     db_slope.push_back(db_gainslope);
00081     db_intercept.push_back(db_intercpt);
00082     db_chi2.push_back(db_chisq);
00083     db_nrlines++;
00084   }
00085   dbdata.close();
00086 
00087   std::ifstream newdata;
00088   newdata.open("gains.dat",std::ios::in); 
00089   if(!newdata) {
00090     std::cerr <<"Error: gains.dat -> no such file!"<< std::endl;
00091     exit(1);
00092   }
00093   
00094   while (!newdata.eof() ) { 
00095     newdata >> new_index >> new_gainslope >> new_intercpt >> new_chisq ; 
00096     new_index_id.push_back(new_index);
00097     new_slope.push_back(new_gainslope);
00098     new_intercept.push_back(new_intercpt);
00099     new_chi2.push_back(new_chisq);
00100     new_nrlines++;
00101   }
00102   newdata.close();
00103 
00104   CSCDBGains::GainContainer & itemvector = cndbgains->gains;
00105   itemvector.resize(MAX_SIZE);
00106   cndbgains->factor_gain = (short int) (FACTOR);
00107   std::cout<<" myfactor "<<cndbgains->factor_gain<<std::endl;
00108 
00109   for(int i=0; i<MAX_SIZE;++i){
00110     itemvector[i].gain_slope= int (db_slope[i]*FACTOR+0.5);
00111   }
00112 
00113    for(int i=0; i<MAX_SIZE;++i){
00114      counter=db_index_id[i];  
00115      for (unsigned int k=0;k<new_index_id.size()-1;k++){
00116        if(counter==new_index_id[k]){
00117          if ((short int) (fabs(new_slope[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].gain_slope= int (new_slope[k]*FACTOR+0.5);
00118          itemvector[i] = itemvector[counter];
00119         //std::cout<<"counter "<<counter<<" new_index_id[k] "<<new_index_id[k]<<" new_slope[k] "<<new_slope[k]<<" db_slope[k] "<<db_slope[k]<<std::endl;
00120        }  
00121      }
00122    }
00123      return cndbgains;
00124 }
00125 
00126 
00127 #endif
00128 

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