Project
Loading...
Searching...
No Matches
TestDataReader.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <vector>
13#include <TTree.h>
14#include <TFile.h>
15#include <TStopwatch.h>
16#include <string>
17#include "TTree.h"
18
28#include <TCanvas.h>
29#include <iostream>
30#include <dirent.h>
31#include <cstdio>
32#include <algorithm>
33#include <iterator>
34#include <thread>
35
36using namespace o2::framework;
37using namespace o2::itsmft;
38using namespace std;
39
40namespace o2
41{
42namespace its
43{
44
45const std::string TestDataReader::sRunTypeFileName = "Config/RunType.dat";
46const std::string TestDataReader::sFakeRateDefConfig = "Config/ConfigFakeRate.dat";
47const std::string TestDataReader::sThresholdDefConfig = "Config/ConfigThreshold.dat";
48
50{
51 mIndexPush = 0;
52
53 std::ifstream RunFileType(sRunTypeFileName);
54 RunFileType >> mRunType;
55
56 LOG(debug) << "OLD CONFIG: RunFileType = " << mRunType;
57
58 if (mRunType == "FakeHitRate") {
59 std::ifstream EventPush(sFakeRateDefConfig);
60 EventPush >> mEventPerPush >> mTrackError >> mWorkDir;
61 }
62
63 if (mRunType == "ThresholdScan") {
64 std::ifstream EventPush(sThresholdDefConfig);
65 EventPush >> mEventPerPush >> mTrackError >> mWorkDir;
66 }
67
68 LOG(debug) << "OLD CONFIG: EventPerPush = " << mEventPerPush << " TrackError = " << mTrackError << " WorkDir = " << mWorkDir;
69 LOG(debug) << "DONE Reset Histogram Decision";
70
71 mFolderNames = GetFName(mWorkDir);
72
73 cout << "NFolder = " << mFolderNames.size() << endl;
74 for (size_t i = 0; i < mFolderNames.size(); i++) {
75
76 cout << "FDN = " << mFolderNames[i] << endl;
77
78 mFileNames.push_back(GetFName(mFolderNames[i]));
79
80 cout << "FDN File Size = " << mFileNames[i].size() << endl;
81
82 for (size_t j = 0; j < mFileNames[i].size(); j++) {
83
84 cout << "FDN File = " << mFileNames[i][j] << endl;
85 }
86 }
87 for (int i = 0; i < sNError; i++) {
88 mErrors[i] = 0;
89 }
90
91 // mEventPerPush = 3000;
92 mEventRegistered = 0;
93 mTotalPixelSize = 0;
94
95 //("infile");
96 //
97
98 const Int_t numOfChips = o2::itsmft::ChipMappingITS::getNChips();
99 LOG(debug) << "numOfChips = " << numOfChips;
100 setNChips(numOfChips);
101 // j = 0;
102 mFileDone = 1;
103 mFileRemain = 0;
104 mNewFileInj = 1;
105 mMaxPixelSize = 58700095;
106}
107
109{
110 // Keep checking new folders (and files in the folders)
111 // If found, process them one by one
112
113 // Defining all local variables
114 int j = 0;
115 int NEventPre = 0;
116 int NEvent;
117 double PercentDone = 0;
118 int ErrorDetcted;
119
120 cout << "----------------------------------------------------------" << endl
121 << endl;
122
123 cout << "New Cycle" << endl;
124 cout << "Old Folder Size = " << mFolderNames.size() << endl;
125
126 // Get folders in working directory, put all files in a vector
127 mNowFolderNames = GetFName(mWorkDir);
128 cout << "Now NFolder = " << mNowFolderNames.size() << endl;
129 for (size_t i = 0; i < mNowFolderNames.size(); i++) {
130 mNowFileNames.push_back(GetFName(mNowFolderNames[i]));
131 }
132
133 // Check for new folders comparing with the previous cycle
134 std::set_difference(mNowFolderNames.begin(), mNowFolderNames.end(), mFolderNames.begin(), mFolderNames.end(), std::inserter(mDiffFolderName, mDiffFolderName.begin()));
135
136 cout << "Difference Size Between New and Initial Runs = " << mDiffFolderName.size() << endl;
137
138 // No new folder
139 if (mDiffFolderName.size() == 0) {
140 cout << "No New Run -- No Need to Reset" << endl;
141 mResetCommand = 0;
142 pc.outputs().snapshot(Output{"ITS", "TEST", 0}, mResetCommand);
143 }
144
145 // New folders found, send the reset signal and reload configuration
146 if (mDiffFolderName.size() > 0) {
147 cout << "New Run Started -- Reset All Histograms" << endl;
148 mResetCommand = 1;
149 pc.outputs().snapshot(Output{"ITS", "TEST", 0}, mResetCommand);
150 for (int i = 0; i < sNError; i++) {
151 mErrors[i] = 0;
152 }
153 mErrorsVec.clear();
154 mResetCommand = 0;
155 mNewFileInj = 1;
156 std::ifstream RunFileType(sRunTypeFileName);
157 RunFileType >> mRunType;
158
159 LOG(debug) << "NEW CONFIG: RunFileType = " << mRunType;
160
161 if (mRunType == "FakeHitRate") {
162 std::ifstream EventPush(sFakeRateDefConfig);
163 EventPush >> mEventPerPush >> mTrackError >> mWorkDir;
164 }
165
166 if (mRunType == "ThresholdScan") {
167 std::ifstream EventPush(sThresholdDefConfig);
168 EventPush >> mEventPerPush >> mTrackError >> mWorkDir;
169 }
170
171 LOG(debug) << "NEW CONFIG: EventPerPush = " << mEventPerPush << " TrackError = " << mTrackError << " mWorkDir = " << mWorkDir;
172 LOG(debug) << "DONE Reset Histogram Decision";
173 }
174
175 LOG(debug) << "Start Creating New Now Vector";
176
177 LOG(debug) << "Get IN LOOP";
178 // Checking for new files, extract them into new vector
179 for (size_t i = 0; i < mFolderNames.size(); i++) {
180 std::set_difference(mNowFileNames[i].begin(), mNowFileNames[i].end(), mFileNames[i].begin(), mFileNames[i].end(), std::inserter(mDiffFileNamePush, mDiffFileNamePush.begin()));
181 mDiffFileNames.push_back(mDiffFileNamePush);
182 cout << "Difference File Size Between New and Initial Runs " << mDiffFileNames[i].size() << endl;
183
184 mDiffFileNamePush.clear();
185 }
186
187 LOG(debug) << "DONE GRABING Existing";
188
189 // Getting the new files from new folders that does not exist in the previous cycle
190 for (size_t i = mFolderNames.size(); i < mNowFolderNames.size(); i++) {
191 mDiffFileNames.push_back(mNowFileNames[i]);
192 cout << "New File Size Between New and Initial Runs " << mDiffFileNames[i].size() << endl;
193 }
194
195 LOG(debug) << "Total New Files = " << mDiffFileNames.size();
196
197 LOG(debug) << "DONE Creating Difference";
198
199 LOG(debug) << "mDiffFileNames Size = " << mDiffFileNames.size();
200
201 LOG(debug) << "Start Loop";
202
203 // Start Decoding New Files by loop through the new file vector
204
205 for (size_t i = 0; i < mNowFolderNames.size(); i++) {
206
207 LOG(debug) << "i = " << i << " mDiffFileNames[i].size() = " << mDiffFileNames[i].size();
208
209 // Getting the folder name ID
210
211 size_t pos = mNowFolderNames[i].find_last_of("/");
212
213 if (pos != string::npos) {
214 mRunID = mNowFolderNames[i].substr(pos + 1);
215 }
216
217 LOG(debug) << "FileDone = " << mFileDone << endl;
218
219 // Reading files one by one
220
221 if (mDiffFileNames[i].size() > 0 && mFileDone == 1) {
222
223 mFileRemain = mDiffFileNames[i].size();
224 mFileDone = 0;
225 cout << "RunID = " << mRunID << endl;
226 cout << "File Location = " << mDiffFileNames[i][0] << endl;
227
228 // Getting the RunID
229 size_t last_index1 = mRunID.find_last_not_of("0123456789");
230 string RunIDS = mRunID.substr(last_index1 + 1);
231
232 // Getting the FileID
233 string FileIDS;
234 pos = mDiffFileNames[i][0].find_last_of("/");
235 if (pos != string::npos) {
236 FileIDS = mDiffFileNames[i][0].substr(pos + 1);
237 }
238
239 cout << "Before FileIDS = " << FileIDS << endl;
240
241 size_t last_index2 = FileIDS.find_last_not_of("0123456789");
242 FileIDS = FileIDS.substr(last_index2 + 1);
243
244 // Extracting the RunID and File to integer in order to make it possible to inject to the QC
245 mRunNumber = std::stoi(RunIDS);
246 mFileID = std::stoi(FileIDS);
247
248 ofstream fout(Form("ErrorData/ErrorLogRun%d_File%d.dat", mRunNumber, mFileID));
249 fout << " START OF ERROR REPORT For Run " << mRunNumber << " File " << mFileID << endl;
250
251 // Reading the first file (Because it is one by one)
252 mInputName = mDiffFileNames[i][0];
253
254 mEventRegistered = 0;
255 LOG(debug) << "mInputName = " << mInputName;
256
257 // Inject fake thing digits for the QC to update immediately
258 // mDigitsTest is the fake digit for updating the QC immediately on the QC GUI
259
260 if (mNewFileInj == 1) {
261 cout << "New File Injected, Now Updating the Canvas and Light" << endl;
262 mDigitsTest.emplace_back(0, 0, 0, 0);
263 mMultiDigitsTest.push_back(mDigitsTest[0]);
264 mErrorsVecTest.push_back(mErrors);
265 mFileDone = 1;
266 mFileInfo = mFileDone + mFileRemain * 10;
267 pc.outputs().snapshot(Output{"ITS", "Run", 0}, mRunNumber);
268 pc.outputs().snapshot(Output{"ITS", "File", 0}, mFileID);
269 pc.outputs().snapshot(Output{"ITS", "Error", 0}, mErrorsVecTest[0]);
270 pc.outputs().snapshot(Output{"ITS", "Finish", 0}, mFileInfo);
271 pc.outputs().snapshot(Output{"ITS", "DIGITS", 0}, mMultiDigitsTest);
272 mNewFileInj = 0;
273 mErrorsVecTest.clear();
274 mDigitsTest.clear();
275 mMultiDigitsTest.clear();
276 if (mFolderNames.size() < mNowFolderNames.size()) {
277 mFileNames.push_back(NewNextFold);
278 }
279 cout << "Done!!! You should see the Canvas Updated " << endl;
280 break;
281 }
282
283 // DONE Inhection//
284
286 mRawReader.setPadding128(true); // payload GBT words are padded to 16B
287 mRawReader.setVerbosity(0);
288 mRawReader.setMinTriggersToCache(1025);
289
290 mRawReader.openInput(mInputName);
291
292 int Index = 0;
293 int IndexMax = -1;
294 int NChip = 0;
295 int NChipMax = -1;
296 int TimePrint = 0;
298 auto& rawErrorReader = reinterpret_cast<RawReader&>(mRawReader);
299
300 while ((mChipData = mRawReader.getNextChipData(mChips))) {
301 if (NChip < NChipMax) {
302 break;
303 }
304 // cout << "Pass Chip" << endl;
305
306 const auto* ruInfo = rawErrorReader.getCurrRUDecodeData()->ruInfo;
307 const auto& statRU = rawErrorReader.getRUDecodingStatSW(ruInfo->idSW);
308
309 const auto& pixels = mChipData->getData();
310 int pixelSize = mChipData->getData().size();
311
312 NEvent = statRU->nPackets;
313
314 mTotalPixelSize = mTotalPixelSize + pixelSize;
315
316 if (NEvent > (mEventRegistered + 1) * mEventPerPush) {
317
318 if (mTotalPixelSize < mMaxPixelSize || mTotalPixelSize == mMaxPixelSize) {
319 cout << "Digit OK for 1 Push" << endl;
320 mNDigits.push_back(mTotalPixelSize);
321 mEventRegistered = mEventRegistered + 1;
322 mErrorsVec.push_back(mErrors);
323 cout << "TotalPixelSize = " << mTotalPixelSize << " Pushed" << endl;
324 }
325
326 if (mTotalPixelSize > mMaxPixelSize) {
327 cout << "Digit Spilt into 2 Pusbhes" << endl;
328 mNDigits.push_back(mTotalPixelSize / 2);
329 mNDigits.push_back(mTotalPixelSize / 2);
330 mErrorsVec.push_back(mErrors);
331 mErrorsVec.push_back(mErrors);
332 mEventRegistered = mEventRegistered + 1;
333 cout << "TotalPixelSize = " << mTotalPixelSize << " Pushed" << endl;
334 }
335
336 mTotalPixelSize = 0;
337 }
338
339 // Printing the Event Number Processed
340
341 if (NEvent % 1000000 == 0 && TimePrint == 0) {
342 cout << "Event Number = " << NEvent << endl;
343 TimePrint = 1;
344 }
345
346 if (NEvent % 100000 != 0) {
347 TimePrint = 0;
348 }
349
351 if (mErrors[i] < 4294967295) {
352 mErrors[i] = mErrors[i] + (int)statRU->errorCounts[i];
353 }
354 }
355
356 if (mTrackError == 1) {
357 if (NEventPre != NEvent) {
358 ErrorDetcted = 0;
359
361 if ((int)statRU->errorCounts[i] > 0) {
362 ErrorDetcted = 1;
363 }
364 }
365
366 if (ErrorDetcted == 1) {
367 fout << "Event Number = " << NEvent << endl;
368 fout << " ------------------------------------------------" << endl;
370 if (statRU->errorCounts[i]) {
371 fout << "Error ID " << i << " " << o2::itsmft::GBTLinkDecodingStat::ErrNames[i] << endl;
372 }
373 }
374 fout << " ------------------------------------------------" << endl;
375 }
376 }
377 }
378
379 int ChipID = mChipData->getChipID();
380
381 for (auto& pixel : pixels) {
382 if (Index < IndexMax) {
383 break;
384 }
385 int col = pixel.getCol();
386 int row = pixel.getRow();
387 mDigits.emplace_back(ChipID, row, col, 0);
388 Index = Index + 1;
389 }
390 NChip = NChip + 1;
391 NEventPre = NEvent;
392 }
393
394 cout << "Final TotalPixelSize = " << mTotalPixelSize << endl;
395 mNDigits.push_back(mTotalPixelSize);
396 mErrorsVec.push_back(mErrors);
397 LOG(debug) << "Run " << mNowFolderNames[i] << " File " << mInputName << " Integrated Raw Pixel Pushed " << mDigits.size();
398 if (mFolderNames.size() < mNowFolderNames.size()) {
399 mFileNames.push_back(NewNextFold);
400 }
401 mFileNames[i].push_back(mInputName);
402 fout << " END OF ERROR REPORT " << endl;
403 }
404 }
405
406 LOG(debug) << "DONE Pushing";
407
408 LOG(debug) << "mIndexPush Before = " << mIndexPush << " mDigits.size() = " << mDigits.size();
409
410 if (mDigits.size() > 0) {
411 PercentDone = double(mIndexPush) / double(mDigits.size());
412 }
413 cout << "Percentage Processed = " << Form("%.2f", 100. * PercentDone) << endl;
414
415 if (mIndexPush < mDigits.size()) {
416 for (int i = 0; i < mNDigits[j]; i++) {
417 mMultiDigits.push_back(mDigits[mIndexPush + i]);
418 }
419 LOG(debug) << "j = " << j << " NDgits = " << mNDigits[j] << " mMultiDigits Pushed = " << mMultiDigits.size();
420 LOG(debug) << "i = " << 10 << " ErrorShould = " << mErrors[10] << " ErrorInjected = " << mErrorsVec[j][10];
421 ;
422
423 cout << "RunIDS = " << mRunNumber << " FileIDS = " << mFileID << endl;
424
425 pc.outputs().snapshot(Output{"ITS", "Run", 0}, mRunNumber);
426 pc.outputs().snapshot(Output{"ITS", "File", 0}, mFileID);
427
428 pc.outputs().snapshot(Output{"ITS", "Error", 0}, mErrorsVec[j]);
429 mIndexPushEx = mIndexPush + mNDigits[j];
430 LOG(debug) << "IndexPushEx = " << mIndexPushEx << " mDigits.size() " << mDigits.size();
431 if (mIndexPushEx > mDigits.size() - 5) {
432 mFileDone = 1;
433 }
434 LOG(debug) << "FileDone = " << mFileDone;
435 LOG(debug) << "FileRemain = " << mFileRemain;
436
437 mFileInfo = mFileDone + mFileRemain * 10;
438
439 pc.outputs().snapshot(Output{"ITS", "Finish", 0}, mFileInfo);
440
441 LOG(debug) << "mIndexPush = " << mIndexPush << " Chip ID Pushing " << mDigits[mIndexPush].getChipIndex();
442
443 pc.outputs().snapshot(Output{"ITS", "DIGITS", 0}, mMultiDigits);
444
445 mMultiDigits.clear();
446 mIndexPush = mIndexPush + mNDigits[j];
447 j = j + 1;
448 }
449
450 LOG(debug) << "mIndexPush After = " << mIndexPush;
451
452 // LOG(debug) << "Before: "
453 // << "mIndexPush = " << mIndexPush << " mDigits.size() = " << mDigits.size();
454 // while (mIndexPush < mDigits.size()) {
455 // LOG(debug) << "mDigits.size() = " << mDigits.size();
456 // pc.outputs().snapshot(Output{"ITS", "DIGITS", 0}, mDigits[mIndexPush++]);
457 // if (mIndexPush % 100000 == 0)
458 // LOG(debug) << "mIndexPush = " << mIndexPush << " Chip ID Pushing " << mDigits[mIndexPush].getChipIndex();
459 // }
460 // // pc.services().get<ControlService>().readyToQuit(QuitRequest::All);
461 // LOG(debug) << "After: "
462 // << "mIndexPush = " << mIndexPush << " mDigits.size() = " << mDigits.size();
463
464 mFolderNames.clear();
465 // mFileNames.clear();
466 NewNextFold.clear();
467 mFolderNames = mNowFolderNames;
468 // mFileNames = mNowFileNames;
469
470 mNowFolderNames.clear();
471 mNowFileNames.clear();
472 mDiffFileNames.clear();
473 mDiffFolderName.clear();
474
475 LOG(debug) << "Pushing Reset Histogram Decision";
476
477 cout << "Resetting Pushing Things" << endl;
478
479 // Resetting a New File //
480 if (mIndexPush > mDigits.size() - 5) {
481 mDigits.clear();
482 mIndexPush = 0;
483 j = 0;
484 mNDigits.clear();
485 mFileDone = 1;
486 pc.outputs().snapshot(Output{"TST", "Finish", 0}, mFileDone);
487 PercentDone = 0;
488 mErrorsVec.clear();
489 }
490
491 // if(mNewFileInjAction == 1){
492 // mNewFileInjAction = 0;
493 // }
494
495 cout << "Start Sleeping" << endl;
496 cout << " " << endl;
497 cout << " " << endl;
498 cout << " " << endl;
499 cout << " " << endl;
500 cout << " " << endl;
501 cout << " " << endl;
502 cout << " " << endl;
503 cout << " " << endl;
504 cout << " " << endl;
505 cout << " " << endl;
506
507 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
508}
509
510std::vector<string> TestDataReader::GetFName(std::string folder)
511{
512
513 DIR* dirp;
514
515 char cstr[folder.size() + 1];
516 strcpy(cstr, folder.c_str());
517 dirp = opendir(cstr);
518 std::vector<string> names;
519 // string search_path = folder + "/*";
520 if (dirp) {
521 struct dirent* directory;
522 while ((directory = readdir(dirp)) != nullptr) {
523
524 // printf("%s\n", directory->d_name);
525
526 if (!(!strcmp(directory->d_name, ".") || !strcmp(directory->d_name, ".."))) {
527 names.push_back(folder + "/" + directory->d_name);
528 }
529 }
530
531 closedir(dirp);
532 }
533
534 cout << "names size = " << names.size() << endl;
535 return (names);
536}
537
539{
540 return DataProcessorSpec{
541 "Raw-Pixel-Reader",
542 Inputs{},
543 Outputs{
544 OutputSpec{"ITS", "DIGITS", 0, Lifetime::Timeframe},
545 OutputSpec{"ITS", "TEST", 0, Lifetime::Timeframe},
546 OutputSpec{"ITS", "Error", 0, Lifetime::Timeframe},
547 OutputSpec{"ITS", "Run", 0, Lifetime::Timeframe},
548 OutputSpec{"ITS", "File", 0, Lifetime::Timeframe},
549 OutputSpec{"ITS", "Finish", 0, Lifetime::Timeframe},
550 /*
551 OutputSpec{ "TST", "Error0", 0, Lifetime::Timeframe },
552 OutputSpec{ "TST", "Error1", 0, Lifetime::Timeframe },
553 OutputSpec{ "TST", "Error2", 0, Lifetime::Timeframe },
554 OutputSpec{ "TST", "Error3", 0, Lifetime::Timeframe },
555 OutputSpec{ "TST", "Error4", 0, Lifetime::Timeframe },
556 OutputSpec{ "TST", "Error5", 0, Lifetime::Timeframe },
557 OutputSpec{ "TST", "Error6", 0, Lifetime::Timeframe },
558 OutputSpec{ "TST", "Error7", 0, Lifetime::Timeframe },
559 OutputSpec{ "TST", "Error8", 0, Lifetime::Timeframe },
560 OutputSpec{ "TST", "Error9", 0, Lifetime::Timeframe },
561 */
562 // OutputSpec{ "TST", "TEST3", 0, Lifetime::Timeframe },
563 },
564 AlgorithmSpec{adaptFromTask<TestDataReader>()},
565 };
566}
567
568} // namespace its
569} // namespace o2
int32_t i
Definition of the ITSMFT ROFrame (trigger) record.
Declaration of class for continuos buffer of ALPIDE data.
Transient data classes for single pixel and set of pixels from current chip.
uint16_t pos
Definition RawData.h:3
uint32_t j
Definition RawData.h:0
uint32_t col
Definition RawData.h:4
Definition of the Alpide pixel reader for raw data processing.
std::ostringstream debug
void snapshot(const Output &spec, T const &object)
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
void init(InitContext &ic) final
std::vector< std::string > GetFName(std::string folder)
void run(ProcessingContext &pc) final
static constexpr int getNChips()
number of chips per barrel
uint16_t getChipID() const
Definition PixelData.h:108
const std::vector< PixelData > & getData() const
Definition PixelData.h:115
void setMinTriggersToCache(int n)
set min number of triggers to cache per frame
void openInput(const std::string filename)
const RUDecodeData * getCurrRUDecodeData() const
void setPadding128(bool v)
impose padding model for GBT words
ChipPixelData * getNextChipData(std::vector< ChipPixelData > &chipDataVec) override
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLuint end
Definition glcorearb.h:469
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition glcorearb.h:275
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
framework::DataProcessorSpec getTestDataReaderSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
static constexpr std::array< std::string_view, NErrorsDefined > ErrNames
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< int > row