Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
raw_data_converter.cpp File Reference
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <fstream>
#include <list>
#include <cstring>
#include <DataFormats/daq_common_header.hh>
#include <DataFormats/clb_common_header.hh>
#include <FrameFactory/frame.hh>
#include <FrameFactory/input_buffer_collector.hh>
#include <FrameFactory/puzzled_frame.hh>
#include <external/dq_dump_file/dqdumpfile.hh>
#include <boost/program_options.hpp>

Go to the source code of this file.

Classes

struct  ID
 

Functions

int64_t abs_time (Packet const &p)
 Program name: RawDataConverter.
 
bool operator== (Packet const &p, ID const &id)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ abs_time()

int64_t abs_time ( Packet const & p)
inline

Program name: RawDataConverter.

Description: This program converts dump raw data into the DAQ frame format.

Use $ RawDataConverter -h for a detailed help.

Author: Carmelo Pellegrino E-mail: carme.nosp@m.lo.p.nosp@m.elleg.nosp@m.rino.nosp@m.@bo.i.nosp@m.nfn..nosp@m.it Date: 29 April 2015

Author
Carmelo Pellegrino

Definition at line 38 of file raw_data_converter.cpp.

39{
40 return p.CLBHeader()->timeStamp().tics() * 16 + p.CLBHeader()->timeStamp().sec() * 1000000000LL;
41}

◆ operator==()

bool operator== ( Packet const & p,
ID const & id )

Definition at line 48 of file raw_data_converter.cpp.

49{
50 int64_t const time = abs_time(p);
51 uint32_t const domid = p.CLBHeader()->domIdentifier();
52
53 return time == id.abs_time && domid == id.domid;
54}
int64_t abs_time(Packet const &p)
Program name: RawDataConverter.

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 56 of file raw_data_converter.cpp.

57{
58 std::string input_filename;
59 std::string output_filename;
60 uint64_t run_start_time = 0;
61 int timeslice_duration = 100;
62 unsigned int detector_id = 0;
63
64 po::options_description desc("Options");
65 desc.add_options()
66 ("help,h", "Print this help and exit.")
67 ("input,i",
68 po::value<std::string>(&input_filename)->required(),
69 "Set the name of the dump data file.")
70 ("output,o",
71 po::value<std::string>(&output_filename)->required(),
72 "Set the name of the output DAQ file.")
73 ("runstart,s",
74 po::value<uint64_t>(&run_start_time)->default_value(run_start_time),
75 "Set the run start time.")
76 ("timeslice,t",
77 po::value<int>(&timeslice_duration)->default_value(timeslice_duration),
78 "Set the value of the time slice duration in milliseconds.")
79 ("detector-id,",
80 po::value<unsigned int>(&detector_id)->default_value(detector_id),
81 "Set the detector id.");
82
83 try {
84 po::variables_map vm;
85 po::store(
86 po::command_line_parser(argc, argv).options(desc).run(),
87 vm);
88
89 if (vm.count("help")) {
90 std::cout << desc << std::endl;
91 return EXIT_SUCCESS;
92 }
93
94 po::notify(vm);
95 } catch (const po::error& e) {
96 std::cerr << "RawDataConverter: Error: " << e.what() << '\n'
97 << desc << std::endl;
98 return EXIT_FAILURE;
99 } catch (const std::runtime_error& e) {
100 std::cerr << "RawDataConverter: Error: " << e.what() << '\n'
101 << desc << std::endl;
102 return EXIT_FAILURE;
103 }
104
105 DumpFile df(input_filename);
106
107 assert(df.size() && "It seems that the file that you provided is empty");
108
109 std::list<Packet> all_data;
110
111 std::set<uint32_t> dom_ids;
112 std::set<int64_t> times;
113
114 for (DumpFile::iterator it = df.begin(), et = df.end(); it != et; ++it) {
115 Packet const p = *it;
116
117 dom_ids.insert(p.CLBHeader()->domIdentifier());
118
119 int64_t const time = abs_time(p);
120 times.insert(time);
121
122 all_data.push_back(*it);
123 }
124
125 std::cout << all_data.size() << " datagrams found\n";
126
127 std::ofstream outfile(output_filename.c_str());
128
129 int const print_suppression_factor = all_data.size() > 50 ? all_data.size() / 50 : 1;
130
131 Frame frame;
132
133 PuzzledFrame pframe;
134
135 ID id;
136
137 for (std::set<int64_t>::const_iterator tit = times.begin(), tet = times.end(); tit != tet ; ++tit) {
138 id.abs_time = *tit;
139 for (std::set<uint32_t>::const_iterator it = dom_ids.begin(), et = dom_ids.end(); it != et; ++it) {
140 id.domid = *it;
141
142 std::list<Packet>::iterator dg = all_data.begin();
143 bool found = false;
144
145 while (true) {
146 dg = std::find(dg, all_data.end(), id);
147
148 if (dg == all_data.end()) {
149 break;
150 }
151
152 found = true;
153 Packet const& p = *dg;
154
156
157 std::memcpy(datagram->raw(), p.data(), p.size());
158 datagram->resize(p.size());
159
160 pframe.setDataType(p.CLBHeader()->dataType());
161 pframe.setDetectorId(detector_id);
162
164 *p.CLBHeader(),
165 run_start_time,
166 timeslice_duration
167 );
168
169 if (seq_num.second) {
170 pframe.setSeqNumber(seq_num.first);
171
172 pframe.setFrameIndex(
173 data2idx(
174 *p.CLBHeader(),
175 run_start_time,
176 timeslice_duration
177 )
178 );
179
180 pframe.insert(datagram);
181 } else {
182 std::cerr
183 << "Datagram timestamp before the start of the run:\n"
184 << *p.CLBHeader() << '\n';
185 }
186
187 all_data.erase(dg++);
188 }
189
190 if (all_data.size() % print_suppression_factor == 0)
191 std::cout << std::setfill(' ')
192 << std::setw(3)
193 << 100 - static_cast<int>(all_data.size() * 100. / df.size())
194 << "%\r" << std::flush;
195
196 if (found) {
197 pframe.getFrame(frame);
198 if (frame.size() && frame.getNItems()) outfile.write(frame.data(), frame.size());
199 }
200 pframe.reset();
201 }
202 }
203}
void resize(size_t s)
char * raw()
Template Frame for ARS data.
Definition frame.hh:13
unsigned int getNItems() const
Definition frame.hh:39
static InBufferCollector & getCollector()
CLBDataGram * getEmptyDataGram()
std::size_t size() const
Definition dqdumpfile.hh:49
CLBCommonHeader const * CLBHeader() const
Definition dqdumpfile.hh:37
char * data()
Definition dqdumpfile.hh:54
void setDetectorId(unsigned int detector_id)
void setSeqNumber(unsigned int seqnumber)
void setFrameIndex(frame_idx_t frame_idx)
void getFrame(Frame &frame)
bool insert(CLBDataGram *datagram)
void setDataType(unsigned int datatype)
std::pair< uint32_t, bool > seq_number(CLBCommonHeader const &header, uint64_t start_run_ms, int ts_duration_ms)
frame_idx_t data2idx(CLBCommonHeader const &header, uint64_t start_run_ms, int ts_duration_ms)
uint32_t dataType() const
uint32_t domIdentifier() const