CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/EventFilter/ESDigiToRaw/src/ESDigiToRaw.cc

Go to the documentation of this file.
00001 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00002 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00003 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00004 
00005 #include "DataFormats/EcalDigi/interface/ESDataFrame.h"
00006 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00007 
00008 #include "EventFilter/ESDigiToRaw/interface/ESDigiToRaw.h"
00009 #include "EventFilter/ESDigiToRaw/src/ESDataFormatterV1_1.h"
00010 #include "EventFilter/ESDigiToRaw/src/ESDataFormatterV4.h"
00011 
00012 using namespace std;
00013 using namespace edm;
00014 
00015 ESDigiToRaw::ESDigiToRaw(const edm::ParameterSet& ps) : ESDataFormatter_(0)
00016 {
00017   
00018   label_ = ps.getParameter<string>("Label");
00019   instanceName_ = ps.getParameter<string>("InstanceES");
00020   debug_ = ps.getUntrackedParameter<bool>("debugMode", false);
00021   formatMajor_ = ps.getUntrackedParameter<int>("formatMajor", 4);
00022   formatMinor_ = ps.getUntrackedParameter<int>("formatMinor", 1);
00023   lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable");
00024 
00025   counter_ = 0;
00026   kchip_ec_ = 0; 
00027   kchip_bc_ = 0; 
00028 
00029   produces<FEDRawDataCollection>();
00030   
00031   if (formatMajor_ == 4) 
00032     ESDataFormatter_ = new ESDataFormatterV4(ps);
00033   else 
00034     ESDataFormatter_ = new ESDataFormatterV1_1(ps);
00035 
00036   // initialize look-up table
00037   for (int i=0; i<2; ++i)
00038     for (int j=0; j<2; ++j)
00039       for (int k=0 ;k<40; ++k)
00040         for (int m=0; m<40; m++)
00041           fedId_[i][j][k][m] = -1;
00042 
00043   // read in look-up table
00044   int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
00045   ifstream file;
00046   file.open(lookup_.fullPath().c_str());
00047   if( file.is_open() ) {
00048     
00049     file >> nLines;
00050     for (int i=0; i<nLines; ++i) {
00051       file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx ;
00052       fedId_[(3-iz)/2-1][ip-1][ix-1][iy-1] = fed;
00053     }
00054   } else {
00055     cout<<"[ESDigiToRaw] Look up table file can not be found in "<<lookup_.fullPath().c_str() <<endl;
00056   }
00057 
00058   file.close();
00059 }
00060 
00061 ESDigiToRaw::~ESDigiToRaw() {
00062   if (ESDataFormatter_) delete ESDataFormatter_;
00063 }
00064 
00065 void ESDigiToRaw::beginJob() {
00066 }
00067 
00068 void ESDigiToRaw::produce(edm::Event& ev, const edm::EventSetup& es) {
00069 
00070   run_number_ = ev.id().run();
00071   orbit_number_ = counter_ / LHC_BX_RANGE;
00072   bx_ = (counter_ % LHC_BX_RANGE);
00073    
00074   lv1_ = ev.id().event();
00075   kchip_ec_ = (lv1_ % KCHIP_EC_RANGE); 
00076   kchip_bc_ = (counter_ % KCHIP_BC_RANGE);
00077   counter_++;
00078 
00079   ESDataFormatter_->setRunNumber(run_number_);
00080   ESDataFormatter_->setOrbitNumber(orbit_number_);
00081   ESDataFormatter_->setBX(bx_);
00082   ESDataFormatter_->setLV1(lv1_);
00083   ESDataFormatter_->setKchipBC(kchip_bc_);
00084   ESDataFormatter_->setKchipEC(kchip_ec_);
00085 
00086   edm::Handle<ESDigiCollection> digis;
00087   ev.getByLabel(label_, instanceName_, digis);
00088 
00089   int ifed;
00090   ESDataFormatter::Digis Digis;
00091   Digis.clear();
00092 
00093   for (ESDigiCollection::const_iterator it=digis->begin(); it!=digis->end(); ++it) {
00094 
00095     const ESDataFrame& df = *it;
00096     const ESDetId& detId = it->id();
00097 
00098     ifed = fedId_[(3-detId.zside())/2-1][detId.plane()-1][detId.six()-1][detId.siy()-1];
00099     if (ifed < 0) continue;
00100 
00101     Digis[ifed].push_back(df);
00102   }
00103 
00104   auto_ptr<FEDRawDataCollection> productRawData( new FEDRawDataCollection );
00105 
00106   ESDataFormatter::Digis::const_iterator itfed; 
00107   for (itfed = Digis.begin(); itfed != Digis.end(); ++itfed) {   
00108     int fId = (*itfed).first ; 
00109 
00110     FEDRawData& fedRawData = productRawData->FEDData(fId); 
00111     ESDataFormatter_->DigiToRaw(fId, Digis, fedRawData); 
00112 
00113     if (debug_) cout<<"FED : "<<fId<<" Data size : "<<fedRawData.size()<<" (Bytes)"<<endl;
00114   } 
00115 
00116   ev.put(productRawData);
00117 
00118   return;
00119 }
00120 
00121 void ESDigiToRaw::endJob() {
00122 }