76int main(
int argc,
char* argv[])
79 std::vector<unsigned>
size(1, 0);
80 std::vector<unsigned> CRU(1, 0);
81 std::vector<unsigned> link(1, 0);
82 std::vector<std::string> infile(1,
"NOFILE");
83 std::vector<std::string> outfile(1,
"NOFILE");
84 std::string adcInFile =
"NOFILE";
85 std::string rorcFlavor =
"grorc";
86 bool checkAdcClock =
false;
87 bool compileAdcValues =
false;
88 bool keepGbtFrames =
false;
89 bool printGbtFrames =
false;
92 bpo::variables_map vm;
93 bpo::options_description desc(
"Allowed options");
96 (
"help,h",
"Produce help message.")
97 (
"infile,i", bpo::value<std::vector<std::string>>(&infile),
"Input data files")
98 (
"outfile,o", bpo::value<std::vector<std::string>>(&outfile),
"Output data files")
99 (
",n", bpo::value<int>(&frames),
"Frames to read")
100 (
",s", bpo::value<std::vector<unsigned>>(&
size),
"Container sizes")
101 (
"CRU", bpo::value<std::vector<unsigned>>(&CRU),
"CRUs")
102 (
"link", bpo::value<std::vector<unsigned>>(&link),
"links")
103 (
"clock,c", bpo::bool_switch(&checkAdcClock),
"check ADC clock")
104 (
"ADC,a", bpo::bool_switch(&compileAdcValues),
"compiles the ADC values")
105 (
"keep,k", bpo::bool_switch(&keepGbtFrames),
"keeps the GBT frames in memory")
106 (
"type,t", bpo::value<std::string>(&rorcFlavor), R
"(Type of RORC which generated binary file ("trorc" or "grorc"))")
107 ("print,p", bpo::bool_switch(&printGbtFrames),
"print GBT frames")
108 (
"file,f", bpo::value<std::string>(&adcInFile),
"ADC input file");
110 bpo::store(parse_command_line(argc, argv, desc), vm);
114 if (vm.count(
"help")) {
115 std::cout << desc << std::endl;
119 if (adcInFile ==
"NOFILE") {
122 std::chrono::time_point<std::chrono::system_clock>
start,
end;
123 std::vector<o2::tpc::GBTFrameContainer*> container;
127 std::vector<int> addData_done(infile.size(), 0);
128 std::vector<int> reading_done(infile.size(), 0);
129 for (
int i = 0;
i < infile.size(); ++
i) {
130 if (
size.size() >= infile.size()) {
135 if (CRU.size() >= infile.size()) {
140 if (link.size() >= infile.size()) {
147 container.back()->setEnableAdcClockWarning(checkAdcClock);
148 container.back()->setEnableSyncPatternWarning(
false);
149 container.back()->setEnableStoreGBTFrames(keepGbtFrames);
150 container.back()->setEnableCompileAdcValues(compileAdcValues);
153 std::vector<std::thread> threads;
155 start = std::chrono::system_clock::now();
156 for (
int i = 0;
i < infile.size(); ++
i) {
157 if (infile[
i] !=
"NOFILE") {
158 threads.emplace_back(
addData, std::ref(*container[
i]), std::ref(infile[
i]), frames, rorcFlavor, std::ref(addData_done[
i]));
162 std::vector<std::vector<std::ofstream*>> outfiles(infile.size());
164 for (
int i = 0;
i < infile.size(); ++
i) {
165 for (
int j = 0;
j < 3; ++
j) {
167 if (
i >= outfile.size()) {
168 outfiles[
i].push_back(
nullptr);
169 }
else if (outfile[
i] ==
"NOFILE") {
170 outfiles[
i].push_back(
nullptr);
172 outname = outfile[
i];
173 outname +=
"_SAMPA_";
178 out =
new std::ofstream(outname, std::ios::out | std::ios::binary);
179 outfiles[
i].push_back(out);
186 if (
i >= outfile.size()) {
187 outfiles[
i].push_back(
nullptr);
188 }
else if (outfile[
i] ==
"NOFILE") {
189 outfiles[
i].push_back(
nullptr);
191 outname = outfile[
i];
192 outname +=
"_SAMPA_";
197 out =
new std::ofstream(outname, std::ios::out | std::ios::binary);
198 outfiles[
i].push_back(out);
201 threads.emplace_back(
readData, std::ref(*container[
i]), std::ref(outfiles[
i]), std::ref(addData_done[
i]), std::ref(reading_done[
i]));
204 std::this_thread::sleep_for(std::chrono::seconds{1});
205 std::cout << std::endl;
206 std::cout <<
" Container | stored frames | processed frames | avail. ADC values " << std::endl;
207 std::cout <<
"-----------|---------------|------------------|-------------------" << std::endl;
209 std::this_thread::sleep_for(std::chrono::seconds{1});
210 for (std::vector<o2::tpc::GBTFrameContainer*>::iterator it = container.begin(); it != container.end(); ++it) {
212 std::cout <<
" " << std::right
213 << std::setw(9) << std::distance(container.begin(), it) <<
" | "
214 << std::setw(13) << (*it)->getSize() <<
" | "
215 << std::setw(16) << (*it)->getNFramesAnalyzed() <<
" | "
216 << std::setw(17) << (*it)->getNentries() << std::endl;
221 for (
auto& aThread : threads) {
224 end = std::chrono::system_clock::now();
226 std::cout << std::endl
228 std::cout <<
"Summary:" << std::endl;
230 unsigned framesProcessed = 0;
231 for (std::vector<o2::tpc::GBTFrameContainer*>::iterator it = container.begin(); it != container.end(); ++it) {
232 framesProcessed += (*it)->getNFramesAnalyzed();
233 std::cout <<
"Container " << std::distance(container.begin(), it) <<
" analyzed " << (*it)->getNFramesAnalyzed() <<
" GBT Frames" << std::endl;
236 std::chrono::duration<float> elapsed_seconds =
end -
start;
237 std::cout <<
"In total: " << framesProcessed <<
" Frames processed in " << elapsed_seconds.count() <<
"s => " << framesProcessed / elapsed_seconds.count() <<
" frames/s" << std::endl;
239 unsigned word3, word2, word1, word0;
240 if (printGbtFrames) {
241 for (std::vector<o2::tpc::GBTFrameContainer*>::iterator it = container.begin(); it != container.end(); ++it) {
242 std::cout <<
"Container " << std::distance(container.begin(), it) <<
":" << std::endl;
243 for (std::vector<o2::tpc::GBTFrame>::iterator itt = (*it)->begin(); itt != (*it)->end(); ++itt) {
244 itt->getGBTFrame(word3, word2, word1, word0);
245 std::cout << *itt <<
" ";
246 std::cout << std::hex << std::setfill(
'0') << std::right << std::setw(8) << word3 <<
" "
247 << std::setfill(
'0') << std::right << std::setw(8) << word2 <<
" "
248 << std::setfill(
'0') << std::right << std::setw(8) << word1 <<
" "
249 << std::setfill(
'0') << std::right << std::setw(8) << word0 << std::dec << std::endl;
254 for (std::vector<std::vector<std::ofstream*>>::iterator it = outfiles.begin(); it != outfiles.end(); ++it) {
255 for (std::vector<std::ofstream*>::iterator itt = (*it).begin(); itt != (*it).end(); ++itt) {
256 if ((*itt) !=
nullptr) {
264 std::cout <<
"Reading from file " << adcInFile << std::endl;
265 std::ifstream inFile(adcInFile, std::ios::in | std::ios::binary);
267 if (!inFile.is_open()) {
268 std::cout <<
"ERROR: can't read file " << adcInFile << std::endl;
275 for (
int j = 0;
j < 100; ++
j) {
276 inFile.read(
reinterpret_cast<char*
>(&adcValues[0]), 16 *
sizeof(adcValues[0]));
278 for (
i = 0;
i < 16; ++
i) {
279 std::cout << adcValues[
i] <<
"\t";
281 std::cout << std::endl;