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  return;
35  }
36  if (pr_.get() != nullptr)
37  pr_->closeFile();
38  }
39 
40  void setupMetaData() {
41  InitMsgView const* header = pr_->getHeader();
42  assert(header);
44 
45  //NOTE: should read first Event to get the meta data
46  auto eview = pr_->getNextEvent();
47  assert(eview);
48  assert(eview->isEventMetaData());
51  }
52 
53  void genuineReadFile() override {
54  if (isFirstFile_) {
55  isFirstFile_ = false;
56  return;
57  }
58 
59  if (didArtificialFile_) {
60  //update the event meta data
61  didArtificialFile_ = false;
63 
64  return;
65  }
66  setupMetaData();
67  }
68 
69  Next checkNext() override;
70 
72  bool isFirstFile_ = true;
73  bool didArtificialFile_ = false;
74  }; //end-of-class-def
75 
76  template <typename Producer>
78 
79  template <typename Producer>
82  //prod_reg_(&productRegistry()),
83  pr_(new Producer(pset)) {
84  //Get header/init from Producer
85  setupMetaData();
86  }
87 
88  template <typename Producer>
90  EventMsgView const* eview = pr_->getNextEvent();
91 
92  if (eview == nullptr) {
93  if (pr_->newHeader()) {
94  FDEBUG(6) << "A new file has been opened and we must compare Headers here !!" << std::endl;
95  return Next::kFile;
96  }
97  return Next::kStop;
98  }
99  if (eview->isEventMetaData()) {
100  //we lie and say there is a new file since we need to synchronize to update the meta data
101  deserializeEventMetaData(*eview);
102  didArtificialFile_ = true;
103  return Next::kFile;
104  }
105  deserializeEvent(*eview);
106  return Next::kEvent;
107  }
108 
109 } // namespace edm::streamer
110 
111 #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)