CMS 3D CMS Logo

StreamerInputModule.h
Go to the documentation of this file.
1 #ifndef IOPool_Streamer_StreamerInputModule_h
2 #define IOPool_Streamer_StreamerInputModule_h
3 
5 
8 
9 #include <memory>
10 #include <string>
11 #include <fstream>
12 #include <vector>
13 #include <utility>
14 #include <iostream>
15 #include <algorithm>
16 #include <iterator>
17 
18 namespace edm::streamer {
19  template <typename Producer>
27  public:
29  ~StreamerInputModule() override;
30 
31  private:
32  void genuineCloseFile() override {
33  if (didArtificialFile_) {
34  didArtificialFile_ = false;
35 
36  return;
37  }
38  if (pr_.get() != nullptr)
39  pr_->closeFile();
40  }
41 
42  void setupMetaData() {
43  InitMsgView const* header = pr_->getHeader();
44  assert(header);
46 
47  //NOTE: should read first Event to get the meta data
48  auto eview = pr_->getNextEvent();
49  assert(eview);
50  assert(eview->isEventMetaData());
53  }
54 
55  void genuineReadFile() override {
56  if (isFirstFile_) {
57  isFirstFile_ = false;
58  return;
59  }
60 
61  if (didArtificialFile_) {
62  //update the event meta data
63  didArtificialFile_ = false;
65 
66  return;
67  }
68  setupMetaData();
69  }
70 
71  Next checkNext() override;
72 
74  bool isFirstFile_ = true;
75  bool didArtificialFile_ = false;
76  }; //end-of-class-def
77 
78  template <typename Producer>
80 
81  template <typename Producer>
84  //prod_reg_(&productRegistry()),
85  pr_(new Producer(pset)) {
86  //Get header/init from Producer
87  setupMetaData();
88  }
89 
90  template <typename Producer>
92  EventMsgView const* eview = pr_->getNextEvent();
93 
94  if (eview == nullptr) {
95  if (pr_->newHeader()) {
96  FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
97  return Next::kFile;
98  }
99  return Next::kStop;
100  }
101  if (eview->isEventMetaData()) {
102  //we lie and say there is a new file since we need to synchronize to update the meta data
103  deserializeEventMetaData(*eview);
104  didArtificialFile_ = true;
105  return Next::kFile;
106  }
107  deserializeEvent(*eview);
108  return Next::kEvent;
109  }
110 
111 } // namespace edm::streamer
112 
113 #endif
void deserializeEventMetaData(EventMsgView const &eventView)
constexpr char const *const kStop
Definition: channel_names.h:34
#define FDEBUG(lev)
Definition: DebugMacros.h:19
assert(be >=bs)
constexpr element_type const * get() const
edm::propagate_const< std::unique_ptr< Producer > > pr_
StreamerInputModule(ParameterSet const &pset, InputSourceDescription const &desc)
void deserializeAndMergeWithRegistry(InitMsgView const &initView, bool subsequent=false)