Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-28 06:19:07

0001 #ifndef EventFilter_Utilities_RawBufferToCollection_h
0002 #define EventFilter_Utilities_RawBufferToCollection_h
0003 
0004 #include <memory>
0005 #include <vector>
0006 
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0011 #include "DataFormats/FEDRawData/interface/RawDataBuffer.h"
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0014 #include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
0015 #include "FWCore/ServiceRegistry/interface/Service.h"
0016 #include "FWCore/Utilities/interface/EDGetToken.h"
0017 
0018 class RawBufferToCollection : public edm::one::EDProducer<> {
0019 public:
0020   explicit RawBufferToCollection(edm::ParameterSet const& ps);
0021   ~RawBufferToCollection() override {};
0022 
0023   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0024 
0025 private:
0026   void produce(edm::Event& e, edm::EventSetup const&) override;
0027   const edm::EDGetTokenT<RawDataBuffer> token_;
0028 };
0029 
0030 inline RawBufferToCollection::RawBufferToCollection(edm::ParameterSet const& ps)
0031     : token_(consumes<RawDataBuffer>(ps.getParameter<edm::InputTag>("source"))) {
0032   produces<FEDRawDataCollection>();
0033 }
0034 
0035 inline void RawBufferToCollection::produce(edm::Event& e, edm::EventSetup const&) {
0036   edm::Handle<RawDataBuffer> fedBuffer;
0037   e.getByToken(token_, fedBuffer);
0038 
0039   std::unique_ptr<FEDRawDataCollection> collection = std::make_unique<FEDRawDataCollection>();
0040 
0041   for (auto it = fedBuffer->map().begin(); it != fedBuffer->map().end(); it++) {
0042     auto singleFED = fedBuffer->fragmentData(it);
0043     if (it->first > FEDNumbering::lastFEDId())
0044       throw cms::Exception("RawBufferToCollection")
0045           << "FED " << it->first << " exceeds FEDRawDataCollection maximum FED " << FEDNumbering::lastFEDId();
0046     FEDRawData& fedData = collection->FEDData(it->first);
0047     fedData.resize(singleFED.size());
0048     memcpy(fedData.data(), &singleFED.data()[0], singleFED.size());
0049   }
0050   e.put(std::move(collection));
0051 }
0052 
0053 inline void RawBufferToCollection::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0054   edm::ParameterSetDescription desc;
0055   desc.add<edm::InputTag>("source", edm::InputTag("rawDataCollector"));
0056   descriptions.addWithDefaultLabel(desc);
0057 }
0058 
0059 #endif  // IOPool_Streamer_interface_RawBufferToCollection_h