artdaq_core  v1_07_08
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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/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 
79 #if HIDE_FROM_ROOT
80 
89  void insertFragment(FragmentPtr&& pfrag);
90 
94  void markComplete();
95 
100  size_t numFragments() const;
101 
106  size_t wordCount() const;
107 
112  run_id_t runID() const;
113 
118  subrun_id_t subrunID() const;
119 
124  sequence_id_t sequenceID() const;
125 
130  bool isComplete() const;
131 
136  void print(std::ostream& os) const;
137 
146  std::unique_ptr<Fragments> releaseProduct();
147 
152  void fragmentTypes(std::vector<Fragment::type_t>& type_list);
153 
166  std::unique_ptr<Fragments> releaseProduct(Fragment::type_t type);
167 
168 #endif
169 
170  private:
171  detail::RawEventHeader header_;
172  FragmentPtrs fragments_;
173  };
174 
175  typedef std::shared_ptr<RawEvent> RawEvent_ptr;
176 
177  inline
179  header_(run, subrun, event)
180  , fragments_() { }
181 
182 #if HIDE_FROM_ROOT
183  inline
185  {
186  if (pfrag == nullptr)
187  {
188  throw cet::exception("LogicError")
189  << "Attempt to insert a null FragmentPtr into a RawEvent detected.\n";
190  }
191  fragments_.emplace_back(std::move(pfrag));
192  }
193 
194  inline void RawEvent::markComplete() { header_.is_complete = true; }
195 
196  inline
197  size_t RawEvent::numFragments() const
198  {
199  return fragments_.size();
200  }
201 
202  inline
203  size_t RawEvent::wordCount() const
204  {
205  size_t sum = 0;
206  for (auto const& frag : fragments_) { sum += frag->size(); }
207  return sum;
208  }
209 
210  inline RawEvent::run_id_t RawEvent::runID() const { return header_.run_id; }
211  inline RawEvent::subrun_id_t RawEvent::subrunID() const { return header_.subrun_id; }
212  inline RawEvent::sequence_id_t RawEvent::sequenceID() const { return header_.sequence_id; }
213  inline bool RawEvent::isComplete() const { return header_.is_complete; }
214 
215  inline
216  std::unique_ptr<Fragments> RawEvent::releaseProduct()
217  {
218  std::unique_ptr<Fragments> result(new Fragments);
219  result->reserve(fragments_.size());
220  // 03/08/2016 ELF: Moving to range-for for STL compatibility
221  //for (size_t i = 0, sz = fragments_.size(); i < sz; ++i) {
222  for (auto& i : fragments_)
223  {
224  result->emplace_back(std::move(*i));
225  }
226  // It seems more hygenic to clear fragments_ rather than to leave
227  // it full of unique_ptrs to Fragments that have been plundered by
228  // the move.
229  fragments_.clear();
230  return result;
231  }
232 
233  inline
234  void RawEvent::fragmentTypes(std::vector<Fragment::type_t>& type_list)
235  {
236  // 03/08/2016 ELF: Moving to range-for for STL compatibility
237  //for (size_t i = 0, sz = fragments_.size(); i < sz; ++i) {
238  for (auto& i : fragments_)
239  {
240  auto fragType = i->type(); // fragments_[i]->type();
241  if (std::find(type_list.begin(), type_list.end(), fragType) == type_list.end())
242  {
243  type_list.push_back(fragType);
244  }
245  }
246  //std::sort(type_list.begin(), type_list.end());
247  //std::unique(type_list.begin(), type_list.end());
248  }
249 
250  inline
251  std::unique_ptr<Fragments>
253  {
254  std::unique_ptr<Fragments> result(new Fragments);
255  FragmentPtrs::iterator iter = fragments_.begin();
256  do
257  {
258  if ((*iter)->type() == fragment_type)
259  {
260  result->push_back(std::move(*(*iter)));
261  iter = fragments_.erase(iter);
262  }
263  else
264  {
265  ++iter;
266  }
267  }
268  while (iter != fragments_.end());
269  return result;
270  }
271 
278  inline
279  std::ostream& operator<<(std::ostream& os, RawEvent const& ev)
280  {
281  ev.print(os);
282  return os;
283  }
284 
285 #endif
286 }
287 
288 #endif /* artdaq_core_Data_RawEvent_hh */
std::unique_ptr< Fragment > FragmentPtr
A std::unique_ptr to a Fragment object.
Definition: Fragment.hh:50
std::unique_ptr< Fragments > releaseProduct()
Release all the Fragments from this RawEvent.
Definition: RawEvent.hh:216
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:234
RawEvent(run_id_t run, subrun_id_t subrun, sequence_id_t event)
Constructs a RawEvent with the given parameters.
Definition: RawEvent.hh:178
std::vector< Fragment > Fragments
A std::vector of Fragment objects.
Definition: Fragment.hh:38
subrun_id_t subrunID() const
Retrieve the subrun number from the RawEventHeader.
Definition: RawEvent.hh:211
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:212
bool isComplete() const
Retrieve the value of the complete flag from the RawEventHeader.
Definition: RawEvent.hh:213
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:133
size_t numFragments() const
Return the number of fragments this RawEvent contains.
Definition: RawEvent.hh:197
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:210
std::ostream & operator<<(std::ostream &os, Fragment const &f)
Prints the given Fragment to the stream.
Definition: Fragment.hh:1181
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:55
void insertFragment(FragmentPtr &&pfrag)
Insert the given (pointer to a) Fragment into this RawEvent.
Definition: RawEvent.hh:184
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:203
void markComplete()
Mark the event as complete.
Definition: RawEvent.hh:194
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:134
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