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 
6 
9 
10 #include <memory>
11 #include <string>
12 #include <fstream>
13 #include <vector>
14 #include <utility>
15 #include <iostream>
16 #include <algorithm>
17 #include <iterator>
18 
19 namespace edm::streamer {
20  template <typename Producer>
28  public:
30  ~StreamerInputModule() override;
31 
32  private:
33  void genuineCloseFile() override {
34  if (didArtificialFile_) {
35  return;
36  }
37  if (pr_.get() != nullptr)
38  pr_->closeFile();
39  }
40 
41  void setupMetaData() {
42  InitMsgView const* header = pr_->getHeader();
43  assert(header);
45 
46  //NOTE: should read first Event to get the meta data
47  auto eview = pr_->getNextEvent();
48  assert(eview);
49  assert(eview->isEventMetaData());
52  }
53 
54  void genuineReadFile() override {
55  if (isFirstFile_) {
56  isFirstFile_ = false;
57  return;
58  }
59 
60  if (didArtificialFile_) {
61  //update the event meta data
62  didArtificialFile_ = false;
64 
65  return;
66  }
67  setupMetaData();
68  }
69 
70  Next checkNext() override;
71 
73  bool isFirstFile_ = true;
74  bool didArtificialFile_ = false;
75  }; //end-of-class-def
76 
77  template <typename Producer>
79 
80  template <typename Producer>
83  //prod_reg_(&productRegistry()),
84  pr_(new Producer(pset)) {
85  //Get header/init from Producer
86  setupMetaData();
87  }
88 
89  template <typename Producer>
91  EventMsgView const* eview = pr_->getNextEvent();
92 
93  if (eview == nullptr) {
94  if (pr_->newHeader()) {
95  FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
96  return Next::kFile;
97  }
98  return Next::kStop;
99  }
100  if (eview->isEventMetaData()) {
101  //we lie and say there is a new file since we need to synchronize to update the meta data
102  deserializeEventMetaData(*eview);
103  didArtificialFile_ = true;
104  return Next::kFile;
105  }
106  deserializeEvent(*eview);
107  return Next::kEvent;
108  }
109 
110 } // namespace edm::streamer
111 
112 #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)