File indexing completed on 2024-06-19 10:59:50
0001 #ifndef IOPool_Streamer_StreamerInputModule_h
0002 #define IOPool_Streamer_StreamerInputModule_h
0003
0004 #include "IOPool/Streamer/interface/StreamerInputSource.h"
0005 #include "IOPool/Streamer/interface/EventMessage.h"
0006
0007 #include "FWCore/Utilities/interface/DebugMacros.h"
0008 #include "FWCore/Utilities/interface/propagate_const.h"
0009
0010 #include <memory>
0011 #include <string>
0012 #include <fstream>
0013 #include <vector>
0014 #include <utility>
0015 #include <iostream>
0016 #include <algorithm>
0017 #include <iterator>
0018
0019 namespace edm::streamer {
0020 template <typename Producer>
0021 class StreamerInputModule : public StreamerInputSource {
0022
0023
0024
0025
0026
0027
0028 public:
0029 explicit StreamerInputModule(ParameterSet const& pset, InputSourceDescription const& desc);
0030 ~StreamerInputModule() override;
0031
0032 private:
0033 void genuineCloseFile() override {
0034 if (didArtificialFile_) {
0035 return;
0036 }
0037 if (pr_.get() != nullptr)
0038 pr_->closeFile();
0039 }
0040
0041 void setupMetaData() {
0042 InitMsgView const* header = pr_->getHeader();
0043 assert(header);
0044 deserializeAndMergeWithRegistry(*header);
0045
0046
0047 auto eview = pr_->getNextEvent();
0048 assert(eview);
0049 assert(eview->isEventMetaData());
0050 deserializeEventMetaData(*eview);
0051 updateEventMetaData();
0052 }
0053
0054 void genuineReadFile() override {
0055 if (isFirstFile_) {
0056 isFirstFile_ = false;
0057 return;
0058 }
0059
0060 if (didArtificialFile_) {
0061
0062 didArtificialFile_ = false;
0063 updateEventMetaData();
0064
0065 return;
0066 }
0067 setupMetaData();
0068 }
0069
0070 Next checkNext() override;
0071
0072 edm::propagate_const<std::unique_ptr<Producer>> pr_;
0073 bool isFirstFile_ = true;
0074 bool didArtificialFile_ = false;
0075 };
0076
0077 template <typename Producer>
0078 StreamerInputModule<Producer>::~StreamerInputModule() {}
0079
0080 template <typename Producer>
0081 StreamerInputModule<Producer>::StreamerInputModule(ParameterSet const& pset, InputSourceDescription const& desc)
0082 : StreamerInputSource(pset, desc),
0083
0084 pr_(new Producer(pset)) {
0085
0086 setupMetaData();
0087 }
0088
0089 template <typename Producer>
0090 StreamerInputSource::Next StreamerInputModule<Producer>::checkNext() {
0091 EventMsgView const* eview = pr_->getNextEvent();
0092
0093 if (eview == nullptr) {
0094 if (pr_->newHeader()) {
0095 FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
0096 return Next::kFile;
0097 }
0098 return Next::kStop;
0099 }
0100 if (eview->isEventMetaData()) {
0101
0102 deserializeEventMetaData(*eview);
0103 didArtificialFile_ = true;
0104 return Next::kFile;
0105 }
0106 deserializeEvent(*eview);
0107 return Next::kEvent;
0108 }
0109
0110 }
0111
0112 #endif