Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:19

0001 #ifndef IOPool_Streamer_StreamerInputModule_h
0002 #define IOPool_Streamer_StreamerInputModule_h
0003 
0004 #include "IOPool/Streamer/interface/StreamerInputSource.h"
0005 
0006 #include "FWCore/Utilities/interface/DebugMacros.h"
0007 #include "FWCore/Utilities/interface/propagate_const.h"
0008 
0009 #include <memory>
0010 #include <string>
0011 #include <fstream>
0012 #include <vector>
0013 #include <utility>
0014 #include <iostream>
0015 #include <algorithm>
0016 #include <iterator>
0017 
0018 namespace edm {
0019   template <typename Producer>
0020   class StreamerInputModule : public StreamerInputSource {
0021     /**
0022      Requires the Producer class to provide following functions
0023            const InitMsgView* getHeader();
0024            const EventMsgView* getNextEvent();
0025            bool newHeader() const;
0026   */
0027   public:
0028     explicit StreamerInputModule(ParameterSet const& pset, InputSourceDescription const& desc);
0029     ~StreamerInputModule() override;
0030 
0031   private:
0032     void genuineCloseFile() override {
0033       if (pr_.get() != nullptr)
0034         pr_->closeFile();
0035     }
0036 
0037     void genuineReadFile() override {
0038       if (isFirstFile_) {
0039         isFirstFile_ = false;
0040         return;
0041       }
0042 
0043       InitMsgView const* header = pr_->getHeader();
0044       deserializeAndMergeWithRegistry(*header);
0045     }
0046 
0047     Next checkNext() override;
0048 
0049     edm::propagate_const<std::unique_ptr<Producer>> pr_;
0050     bool isFirstFile_ = true;
0051   };  //end-of-class-def
0052 
0053   template <typename Producer>
0054   StreamerInputModule<Producer>::~StreamerInputModule() {}
0055 
0056   template <typename Producer>
0057   StreamerInputModule<Producer>::StreamerInputModule(ParameterSet const& pset, InputSourceDescription const& desc)
0058       : StreamerInputSource(pset, desc),
0059         //prod_reg_(&productRegistry()),
0060         pr_(new Producer(pset)) {
0061     //Get header/init from Producer
0062     InitMsgView const* header = pr_->getHeader();
0063     deserializeAndMergeWithRegistry(*header);
0064   }
0065 
0066   template <typename Producer>
0067   StreamerInputSource::Next StreamerInputModule<Producer>::checkNext() {
0068     EventMsgView const* eview = pr_->getNextEvent();
0069 
0070     if (pr_->newHeader()) {
0071       FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
0072       return Next::kFile;
0073     }
0074     if (eview == nullptr) {
0075       return Next::kStop;
0076     }
0077     deserializeEvent(*eview);
0078     return Next::kEvent;
0079   }
0080 
0081 }  // namespace edm
0082 
0083 #endif