artdaq_core  v3_01_04
RawEvent.hh
1 #ifndef artdaq_core_Data_RawEvent_hh
2 #define artdaq_core_Data_RawEvent_hh
3 
4 #include "artdaq-core/Data/dictionarycontrol.hh"
5 #include "artdaq-core/Data/Fragment.hh"
6 
7 #include "cetlib_except/exception.h"
8 
9 #include <iosfwd>
10 #include <memory>
11 #include <algorithm>
12 
13 namespace artdaq
14 {
18  namespace detail
19  {
20  struct RawEventHeader;
21  }
22 
31  {
32  typedef uint32_t run_id_t;
33  typedef uint32_t subrun_id_t;
35 
39  bool is_complete;
40 
48  subrun_id_t subrun,
49  sequence_id_t event) :
50  run_id(run)
51  , subrun_id(subrun)
52  , sequence_id(event)
53  , is_complete(false) { }
54  };
55 
56 
64  class RawEvent
65  {
66  public:
70 
77  RawEvent(run_id_t run, subrun_id_t subrun, sequence_id_t event);
78 
83  explicit RawEvent(detail::RawEventHeader hdr);
84 
85 #if HIDE_FROM_ROOT
86 
95  void insertFragment(FragmentPtr&& pfrag);
96 
100  void markComplete();
101 
106  size_t numFragments() const;
107 
112  size_t wordCount() const;
113 
118  run_id_t runID() const;
119 
124  subrun_id_t subrunID() const;
125 
130  sequence_id_t sequenceID() const;
131 
136  bool isComplete() const;
137 
142  void print(std::ostream& os) const;
143 
152  std::unique_ptr<Fragments> releaseProduct();
153 
158  void fragmentTypes(std::vector<Fragment::type_t>& type_list);
159 
172  std::unique_ptr<Fragments> releaseProduct(Fragment::type_t type);
173 
174 #endif
175 
176  private:
177  detail::RawEventHeader header_;
178  FragmentPtrs fragments_;
179  };
180 
181  typedef std::shared_ptr<RawEvent> RawEvent_ptr;
182 
183  inline
185  header_(run, subrun, event)
186  , fragments_() { }
187 
188  inline RawEvent::RawEvent(detail::RawEventHeader hdr) : header_(hdr), fragments_()
189  {}
190 
191 #if HIDE_FROM_ROOT
192  inline
194  {
195  if (pfrag == nullptr)
196  {
197  throw cet::exception("LogicError")
198  << "Attempt to insert a null FragmentPtr into a RawEvent detected.\n";
199  }
200  fragments_.emplace_back(std::move(pfrag));
201  }
202 
203  inline void RawEvent::markComplete() { header_.is_complete = true; }
204 
205  inline
206  size_t RawEvent::numFragments() const
207  {
208  return fragments_.size();
209  }
210 
211  inline
212  size_t RawEvent::wordCount() const
213  {
214  size_t sum = 0;
215  for (auto const& frag : fragments_) { sum += frag->size(); }
216  return sum;
217  }
218 
219  inline RawEvent::run_id_t RawEvent::runID() const { return header_.run_id; }
220  inline RawEvent::subrun_id_t RawEvent::subrunID() const { return header_.subrun_id; }
221  inline RawEvent::sequence_id_t RawEvent::sequenceID() const { return header_.sequence_id; }
222  inline bool RawEvent::isComplete() const { return header_.is_complete; }
223 
224  inline
225  std::unique_ptr<Fragments> RawEvent::releaseProduct()
226  {
227  std::unique_ptr<Fragments> result(new Fragments);
228  result->reserve(fragments_.size());
229  // 03/08/2016 ELF: Moving to range-for for STL compatibility
230  //for (size_t i = 0, sz = fragments_.size(); i < sz; ++i) {
231  for (auto& i : fragments_)
232  {
233  result->emplace_back(std::move(*i));
234  }
235  // It seems more hygenic to clear fragments_ rather than to leave
236  // it full of unique_ptrs to Fragments that have been plundered by
237  // the move.
238  fragments_.clear();
239  return result;
240  }
241 
242  inline
243  void RawEvent::fragmentTypes(std::vector<Fragment::type_t>& type_list)
244  {
245  // 03/08/2016 ELF: Moving to range-for for STL compatibility
246  //for (size_t i = 0, sz = fragments_.size(); i < sz; ++i) {
247  for (auto& i : fragments_)
248  {
249  auto fragType = i->type(); // fragments_[i]->type();
250  if (std::find(type_list.begin(), type_list.end(), fragType) == type_list.end())
251  {
252  type_list.push_back(fragType);
253  }
254  }
255  //std::sort(type_list.begin(), type_list.end());
256  //std::unique(type_list.begin(), type_list.end());
257  }
258 
259  inline
260  std::unique_ptr<Fragments>
262  {
263  std::unique_ptr<Fragments> result(new Fragments);
264  FragmentPtrs::iterator iter = fragments_.begin();
265  do
266  {
267  if ((*iter)->type() == fragment_type)
268  {
269  result->push_back(std::move(*(*iter)));
270  iter = fragments_.erase(iter);
271  }
272  else
273  {
274  ++iter;
275  }
276  }
277  while (iter != fragments_.end());
278  return result;
279  }
280 
287  inline
288  std::ostream& operator<<(std::ostream& os, RawEvent const& ev)
289  {
290  ev.print(os);
291  return os;
292  }
293 
294 #endif
295 }
296 
297 #endif /* artdaq_core_Data_RawEvent_hh */
std::unique_ptr< Fragment > FragmentPtr
A std::unique_ptr to a Fragment object.
Definition: Fragment.hh:53
std::unique_ptr< Fragments > releaseProduct()
Release all the Fragments from this RawEvent.
Definition: RawEvent.hh:225
detail::RawEventHeader::run_id_t run_id_t
Run numbers are 32 bits.
Definition: RawEvent.hh:67
void fragmentTypes(std::vector< Fragment::type_t > &type_list)
Fills in a list of unique fragment types from this event.
Definition: RawEvent.hh:243
RawEvent(run_id_t run, subrun_id_t subrun, sequence_id_t event)
Constructs a RawEvent with the given parameters.
Definition: RawEvent.hh:184
std::vector< Fragment > Fragments
A std::vector of Fragment objects.
Definition: Fragment.hh:41
subrun_id_t subrunID() const
Retrieve the subrun number from the RawEventHeader.
Definition: RawEvent.hh:220
detail::RawEventHeader::subrun_id_t subrun_id_t
Subrun numbers are 32 bits.
Definition: RawEvent.hh:68
sequence_id_t sequenceID() const
Retrieve the sequence id from the RawEventHeader.
Definition: RawEvent.hh:221
bool isComplete() const
Retrieve the value of the complete flag from the RawEventHeader.
Definition: RawEvent.hh:222
detail::RawEventHeader::sequence_id_t sequence_id_t
Field size should be the same as the Fragment::sequence_id field.
Definition: RawEvent.hh:69
detail::RawFragmentHeader::type_t type_t
typedef for type_t from RawFragmentHeader
Definition: Fragment.hh:136
size_t numFragments() const
Return the number of fragments this RawEvent contains.
Definition: RawEvent.hh:206
uint32_t run_id_t
Run numbers are 32 bits.
Definition: RawEvent.hh:32
void print(std::ostream &os) const
Print summary information about this RawEvent to the given stream.
Definition: RawEvent.cc:6
subrun_id_t subrun_id
Fragments don&#39;t know about subruns.
Definition: RawEvent.hh:37
run_id_t runID() const
Retrieve the run number from the RawEventHeader.
Definition: RawEvent.hh:219
std::ostream & operator<<(std::ostream &os, Fragment const &f)
Prints the given Fragment to the stream.
Definition: Fragment.hh:1198
Fragment::sequence_id_t sequence_id_t
Field size should be the same as the Fragment::sequence_id field.
Definition: RawEvent.hh:34
std::shared_ptr< RawEvent > RawEvent_ptr
A smart pointer to a RawEvent object.
Definition: GlobalQueue.hh:13
The header information used to identify key properties of the RawEvent object.
Definition: RawEvent.hh:30
RawEventHeader(run_id_t run, subrun_id_t subrun, sequence_id_t event)
Constructs the RawEventHeader struct with the given parameters.
Definition: RawEvent.hh:47
std::list< FragmentPtr > FragmentPtrs
A std::list of FragmentPtrs.
Definition: Fragment.hh:58
void insertFragment(FragmentPtr &&pfrag)
Insert the given (pointer to a) Fragment into this RawEvent.
Definition: RawEvent.hh:193
run_id_t run_id
Fragments don&#39;t know about runs.
Definition: RawEvent.hh:36
size_t wordCount() const
Return the sum of the word counts of all fragments in this RawEvent.
Definition: RawEvent.hh:212
void markComplete()
Mark the event as complete.
Definition: RawEvent.hh:203
uint32_t subrun_id_t
Subrun numbers are 32 bits.
Definition: RawEvent.hh:33
detail::RawFragmentHeader::sequence_id_t sequence_id_t
typedef for sequence_id_t from RawFragmentHeader
Definition: Fragment.hh:137
bool is_complete
Does the event contain the expected number of Fragment objects?
Definition: RawEvent.hh:39
RawEvent is the artdaq view of a generic event, containing a header and zero or more Fragments...
Definition: RawEvent.hh:64
sequence_id_t sequence_id
RawEvent sequence_id should be the same as its component Fragment sequence_ids.
Definition: RawEvent.hh:38