RceFragment.cc
Go to the documentation of this file.
2 
3 #include "dam/HeaderFragmentUnpack.hh"
4 #include "dam/TpcStreamUnpack.hh"
5 
6 #include "artdaq-core/Data/ContainerFragment.hh"
7 
8 #include <iostream>
9 #include <fstream>
10 
11 dune::RceFragment::RceFragment(const uint64_t* data_ptr) :
12  _data_ptr(data_ptr)
13 {
14  _init();
15 }
16 
17 dune::RceFragment::RceFragment(artdaq::Fragment const& afrag) :
18  _data_ptr((uint64_t const*)(afrag.dataBeginBytes() + 12))
19 {
20  _init();
21 }
22 
24 {
25  HeaderFragmentUnpack const header (_data_ptr);
26  if ( header.isData() )
27  {
28  _data_fragment = std::make_unique<DataFragmentUnpack>(_data_ptr);
29  // if (_data_fragment->isTpcNormal())
30  // {
31 
32  _tpc_fragment = std::make_unique<TpcFragmentUnpack>(*_data_fragment);
33  _n_streams = _tpc_fragment->getNStreams();
34 
35  // }
36  //else
37  // {
38  //std::cout << "Fragment skipped in RceFragment::_init() because not TpcNormal." << std::endl;
39  //}
40  }
41  else
42  {
43  //std::cout << "Fragment skipped in RceFragment::_init() because header says is not data." << std::endl;
44  }
45 }
46 
47 TpcStreamUnpack const *
49 {
50  if (_n_streams <= 0)
51  return nullptr;
52  return _tpc_fragment->getStream(i);
53 }
54 
55 void dune::RceFragment::hexdump(std::ostream& out, int n_words) const
56 {
57  out << std::hex;
58  for (int i = 0; i < n_words; ++i)
59  out << *(_data_ptr + i) << " ";
60  out << std::dec << std::endl;
61 }
62 
64 {
65  // TODO check header
66  uint64_t header = *_data_ptr;
67  size_t bytes = (header >> 8) & 0xffffff;
68  bytes *= sizeof(uint64_t);
69 
70  std::ofstream b_stream(filepath.c_str(),
71  std::fstream::out | std::fstream::binary);
72 
73  char const* data = reinterpret_cast<decltype(data)>(_data_ptr);
74  b_stream.write(data, bytes);
75  b_stream.close();
76 }
77 
80 {
81  RceFragments rces;
82 
83  for (auto const& frag: frags)
84  {
85  artdaq::ContainerFragment cfrag(frag);
86  for (size_t ii = 0 ; ii < cfrag.block_count(); ++ii)
87  {
88  auto* data_ptr = (uint8_t*) (cfrag.dataBegin());
89  data_ptr += cfrag.fragmentIndex(ii);
90 
91  size_t afrag_size = 16;
92  artdaq::Fragment afrag;
93  afrag.resizeBytes(afrag_size);
94  memcpy(afrag.headerAddress(), data_ptr, afrag_size);
95 
96  int afrag_header_bytes = afrag.dataBeginBytes()
97  - afrag.headerBeginBytes();
98 
99  data_ptr += afrag_header_bytes;
100  data_ptr += 12;
101 
102  dune::RceFragment rce((uint64_t*) data_ptr);
103  rces.push_back(std::move(rce));
104  }
105  }
106  //return std::move(rces);
107  return rces;
108 }
std::unique_ptr< DataFragmentUnpack > _data_fragment
Definition: RceFragment.hh:35
TpcStreamUnpack const * get_stream(int i) const
Definition: RceFragment.cc:48
std::string string
Definition: nybbler.cc:12
QTextStream & hex(QTextStream &s)
const uint64_t * _data_ptr
Definition: RceFragment.hh:38
void hexdump(std::ostream &out, int n_words=10) const
Definition: RceFragment.cc:55
std::vector< dune::RceFragment > RceFragments
Definition: RceFragment.hh:13
std::unique_ptr< TpcFragmentUnpack > _tpc_fragment
Definition: RceFragment.hh:36
RceFragment(artdaq::Fragment const &fragment)
Definition: RceFragment.cc:17
def move(depos, offset)
Definition: depos.py:107
static RceFragments from_container_frags(const artdaq::Fragments &frags)
Definition: RceFragment.cc:79
QTextStream & dec(QTextStream &s)
string filepath
Definition: train.py:371
void save(const std::string &filepath) const
Definition: RceFragment.cc:63
byte bytes
Alias for common language habits.
Definition: datasize.h:101
std::vector< Fragment > Fragments
Definition: HDF5Utils.h:57
QTextStream & endl(QTextStream &s)