CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CalibMuon/CSCCalibration/interface/CSCBadWiresConditions.h

Go to the documentation of this file.
00001 #ifndef _CSCBADWIRESCONDITIONS_H
00002 #define _CSCBADWIRESCONDITIONS_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/CSCBadWires.h"
00018 #include "CondFormats/DataRecord/interface/CSCBadWiresRcd.h"
00019 
00020 class CSCBadWiresConditions: public edm::ESProducer, public edm::EventSetupRecordIntervalFinder  {
00021  public:
00022   CSCBadWiresConditions(const edm::ParameterSet&);
00023   ~CSCBadWiresConditions();
00024   
00025 
00026   inline static CSCBadWires *  prefillBadWires();
00027 
00028   typedef const  CSCBadWires * ReturnType;
00029   
00030   ReturnType produceBadWires(const CSCBadWiresRcd&);
00031   
00032  private:
00033   // ----------member data ---------------------------
00034   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue&, edm::ValidityInterval & );
00035   CSCBadWires *cndbBadWires ;
00036 
00037 };
00038 
00039 #include<fstream>
00040 #include<vector>
00041 #include<iostream>
00042 
00043 // to workaround plugin library
00044 inline CSCBadWires *  CSCBadWiresConditions::prefillBadWires()
00045 {
00046   CSCBadWires * cndbbadwires = new CSCBadWires();
00047 
00048   int new_index,new_chan;
00049   int new_layer,new_channel, new_flag1,  new_flag2, new_flag3,new_pointer;
00050   std::vector<int> new_index_id;
00051   std::vector<short int> new_layer_id;
00052   std::vector<short int> new_chan_id;
00053   std::vector<int> new_badchannels;
00054   std::vector<short int> new_flag1_id;
00055   std::vector<short int> new_flag2_id;
00056   std::vector<short int> new_flag3_id;
00057   std::vector<int> new_cham_id;
00058   std::vector<int> new_point;
00059 
00060   //when bad channels exist use the following
00061    int new_nrlines1=0;
00062    int new_nrlines2=0;
00063   //when empty
00064   //int new_nrlines1=-1;
00065   //int new_nrlines2=-1;
00066  
00067   std::ifstream newdata1;
00068   std::ifstream newdata2;
00069 
00070   newdata1.open("badwires1.dat",std::ios::in); 
00071   if(!newdata1) {
00072     std::cerr <<"Error: badwires1.dat -> no such file!"<< std::endl;
00073     exit(1);
00074   }
00075   newdata2.open("badwires2.dat",std::ios::in); //channelcontainer
00076   if(!newdata2) {
00077     std::cerr <<"Error: badwires2.dat -> no such file!"<< std::endl;
00078     exit(1);
00079   }
00080   
00081   while (!newdata1.eof() ) { 
00082     newdata1 >> new_index >> new_pointer >> new_chan; 
00083     new_index_id.push_back(new_index);
00084     new_point.push_back(new_pointer);
00085      new_badchannels.push_back(new_chan);
00086     new_nrlines1++;
00087   }
00088   newdata1.close();
00089   
00090  while (!newdata2.eof() ) { 
00091     newdata2 >> new_layer >> new_channel >> new_flag1 >> new_flag2 >> new_flag3; 
00092     new_layer_id.push_back(new_layer);
00093     new_chan_id.push_back(new_channel);
00094     new_flag1_id.push_back(new_flag1);
00095     new_flag2_id.push_back(new_flag2);
00096     new_flag3_id.push_back(new_flag3);
00097     new_nrlines2++;
00098   }
00099   newdata2.close();
00100 
00101  
00102   CSCBadWires::BadChamberContainer & itemvector1 = cndbbadwires->chambers;
00103   itemvector1.resize(new_nrlines1);
00104   
00105 
00106   CSCBadWires::BadChannelContainer & itemvector2 = cndbbadwires->channels;
00107   itemvector2.resize(new_nrlines2);
00108   
00109   cndbbadwires->numberOfBadChannels = new_nrlines2;
00110 
00111   for(int i=0; i<new_nrlines1;i++){
00112     itemvector1[i].chamber_index = new_index_id[i];
00113     itemvector1[i].pointer = new_point[i];
00114     itemvector1[i].bad_channels = new_badchannels[i];
00115     
00116   }
00117 
00118   for(int j=0; j<new_nrlines2;++j){
00119        itemvector2[j].layer = new_layer_id[j];
00120        itemvector2[j].channel = new_chan_id[j];
00121        itemvector2[j].flag1 = new_flag1_id[j];
00122        itemvector2[j].flag2 = new_flag2_id[j];
00123        itemvector2[j].flag3 = new_flag3_id[j];
00124   }
00125 
00126   return cndbbadwires;
00127 }
00128 
00129 #endif
00130