Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:12

0001 /** \file
0002  * Implementation of class RawDataCollectorByLabel
0003  *
0004  */
0005 
0006 #include "EventFilter/RawDataCollector/src/RawDataCollectorByLabel.h"
0007 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0008 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0009 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0010 
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 #include <iostream>
0020 
0021 using namespace edm;
0022 
0023 RawDataCollectorByLabel::RawDataCollectorByLabel(const edm::ParameterSet &pset) {
0024   inputTags_ = pset.getParameter<std::vector<InputTag> >("RawCollectionList");
0025   verbose_ = pset.getUntrackedParameter<int>("verbose", 0);
0026 
0027   inputTokens_.reserve(inputTags_.size());
0028   for (tag_iterator_t inputTag = inputTags_.begin(); inputTag != inputTags_.end(); ++inputTag) {
0029     inputTokens_.push_back(consumes<FEDRawDataCollection>(*inputTag));
0030   }
0031   produces<FEDRawDataCollection>();
0032 }
0033 
0034 RawDataCollectorByLabel::~RawDataCollectorByLabel() {}
0035 
0036 void RawDataCollectorByLabel::produce(Event &e, const EventSetup &c) {
0037   /// Get Data from all FEDs
0038   std::vector<Handle<FEDRawDataCollection> > rawData;
0039   rawData.reserve(inputTokens_.size());
0040   for (tok_iterator_t inputTok = inputTokens_.begin(); inputTok != inputTokens_.end(); ++inputTok) {
0041     Handle<FEDRawDataCollection> input;
0042     if (e.getByToken(*inputTok, input)) {
0043       rawData.push_back(input);
0044     }
0045     //else{     //skipping the inputtag requested. but this is a normal operation to bare data & MC. silent warning   }
0046   }
0047 
0048   auto producedData = std::make_unique<FEDRawDataCollection>();
0049 
0050   for (unsigned int i = 0; i < rawData.size(); ++i) {
0051     const FEDRawDataCollection *rdc = rawData[i].product();
0052 
0053     if (verbose_ > 0) {
0054       std::cout << "\nRAW collection #" << i + 1 << std::endl;
0055       std::cout << "branch name = " << rawData[i].provenance()->branchName() << std::endl;
0056       std::cout << "process index = " << rawData[i].provenance()->productID().processIndex() << std::endl;
0057     }
0058 
0059     for (int j = 0; j < FEDNumbering::MAXFEDID; ++j) {
0060       const FEDRawData &fedData = rdc->FEDData(j);
0061       size_t size = fedData.size();
0062 
0063       if (size > 0) {
0064         // this fed has data -- lets copy it
0065         if (verbose_ > 1)
0066           std::cout << "Copying data from FED #" << j << std::endl;
0067         FEDRawData &fedDataProd = producedData->FEDData(j);
0068         if (fedDataProd.size() != 0) {
0069           if (verbose_ > 1) {
0070             std::cout << " More than one FEDRawDataCollection with data in FED ";
0071             std::cout << j << " Skipping the 2nd\n";
0072           }
0073           continue;
0074         }
0075         fedDataProd.resize(size);
0076         unsigned char *dataProd = fedDataProd.data();
0077         const unsigned char *data = fedData.data();
0078         for (unsigned int k = 0; k < size; ++k) {
0079           dataProd[k] = data[k];
0080         }
0081       }
0082     }
0083   }
0084 
0085   // Insert the new product in the event
0086   e.put(std::move(producedData));
0087 }