Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:59

0001 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0002 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0003 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0004 
0005 #include "DataFormats/EcalDigi/interface/ESDataFrame.h"
0006 
0007 #include "EventFilter/ESDigiToRaw/interface/ESDigiToRaw.h"
0008 #include "EventFilter/ESDigiToRaw/src/ESDataFormatterV1_1.h"
0009 #include "EventFilter/ESDigiToRaw/src/ESDataFormatterV4.h"
0010 
0011 using namespace std;
0012 using namespace edm;
0013 
0014 ESDigiToRaw::ESDigiToRaw(const edm::ParameterSet& ps)
0015     : ESDataFormatter_(nullptr),
0016       label_(ps.getParameter<string>("Label")),
0017       instanceName_(ps.getParameter<string>("InstanceES")),
0018       ESDigiToken_(consumes<ESDigiCollection>(edm::InputTag(label_, instanceName_))),
0019       lookup_(ps.getUntrackedParameter<FileInPath>("LookupTable")),
0020       debug_(ps.getUntrackedParameter<bool>("debugMode", false)),
0021       formatMajor_(ps.getUntrackedParameter<int>("formatMajor", 4)),
0022       formatMinor_(ps.getUntrackedParameter<int>("formatMinor", 1)) {
0023   if (formatMajor_ == 4)
0024     ESDataFormatter_ = new ESDataFormatterV4(ps);
0025   else
0026     ESDataFormatter_ = new ESDataFormatterV1_1(ps);
0027 
0028   produces<FEDRawDataCollection>();
0029   // initialize look-up table
0030   for (int i = 0; i < 2; ++i)
0031     for (int j = 0; j < 2; ++j)
0032       for (int k = 0; k < 40; ++k)
0033         for (int m = 0; m < 40; m++)
0034           fedId_[i][j][k][m] = -1;
0035 
0036   // read in look-up table
0037   int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
0038   ifstream file;
0039   file.open(lookup_.fullPath().c_str());
0040   if (file.is_open()) {
0041     file >> nLines;
0042     for (int i = 0; i < nLines; ++i) {
0043       file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
0044       fedId_[(3 - iz) / 2 - 1][ip - 1][ix - 1][iy - 1] = fed;
0045     }
0046   } else {
0047     cout << "[ESDigiToRaw] Look up table file can not be found in " << lookup_.fullPath().c_str() << endl;
0048   }
0049 
0050   file.close();
0051 }
0052 
0053 ESDigiToRaw::~ESDigiToRaw() {
0054   if (ESDataFormatter_)
0055     delete ESDataFormatter_;
0056 }
0057 
0058 void ESDigiToRaw::produce(edm::StreamID, edm::Event& ev, const edm::EventSetup& es) const {
0059   ESDataFormatter::Meta_Data meta_data;
0060   meta_data.lv1 = ev.id().event();
0061   meta_data.run_number = ev.id().run();
0062   meta_data.orbit_number = meta_data.lv1 / LHC_BX_RANGE;
0063   meta_data.bx = (meta_data.lv1 % LHC_BX_RANGE);
0064 
0065   meta_data.kchip_ec = (meta_data.lv1 % KCHIP_EC_RANGE);
0066   meta_data.kchip_bc = (meta_data.lv1 % KCHIP_BC_RANGE);
0067 
0068   edm::Handle<ESDigiCollection> digis;
0069   ev.getByToken(ESDigiToken_, digis);
0070 
0071   int ifed;
0072   ESDataFormatter::Digis Digis;
0073   Digis.clear();
0074 
0075   for (ESDigiCollection::const_iterator it = digis->begin(); it != digis->end(); ++it) {
0076     const ESDataFrame& df = *it;
0077     const ESDetId& detId = it->id();
0078 
0079     ifed = fedId_[(3 - detId.zside()) / 2 - 1][detId.plane() - 1][detId.six() - 1][detId.siy() - 1];
0080     if (ifed < 0)
0081       continue;
0082 
0083     Digis[ifed].push_back(df);
0084   }
0085 
0086   auto productRawData = std::make_unique<FEDRawDataCollection>();
0087 
0088   ESDataFormatter::Digis::const_iterator itfed;
0089   for (itfed = Digis.begin(); itfed != Digis.end(); ++itfed) {
0090     int fId = (*itfed).first;
0091 
0092     FEDRawData& fedRawData = productRawData->FEDData(fId);
0093     ESDataFormatter_->DigiToRaw(fId, Digis, fedRawData, meta_data);
0094 
0095     if (debug_)
0096       cout << "FED : " << fId << " Data size : " << fedRawData.size() << " (Bytes)" << endl;
0097   }
0098 
0099   ev.put(std::move(productRawData));
0100 
0101   return;
0102 }