-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathRunFindAdcError.C
More file actions
173 lines (154 loc) · 6.14 KB
/
RunFindAdcError.C
File metadata and controls
173 lines (154 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include "FairLogger.h"
#include "TPCBase/PadPos.h"
#include "TPCReconstruction/RawReader.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <algorithm>
#include <thread>
#include <mutex>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include "TH2F.h"
#endif
TH2F* hAdcError = nullptr;
bool run_parallel = true;
using namespace std;
using namespace o2::tpc;
struct Result {
int mRun;
int mEvent;
int mRegion;
int mLink;
int mSampa;
int mTimebin;
int mSyncPos;
Result() : mRun(-1), mEvent(-1), mRegion(-1), mLink(-1), mSampa(-1), mTimebin(-1), mSyncPos(-1){};
Result(int run, int event, int region, int link, int sampa, int timebin, int syncpos) : mRun(run), mEvent(event), mRegion(region), mLink(link), mSampa(sampa), mTimebin(timebin), mSyncPos(syncpos){};
};
void loopReader(std::shared_ptr<RawReader> reader_ptr, std::vector<Result>& result_ptr)
{
auto reader = reader_ptr.get();
while (reader->loadNextEventNoWrap() >= 0) {
if (reader->getAdcError()->size() != 0) {
for (const auto& err : *reader->getAdcError()) {
result_ptr.emplace_back(
reader->getRunNumber(),
reader->getEventNumber(),
reader->getRegion(),
reader->getLink(),
std::get<0>(err),
std::get<1>(err),
std::get<2>(err));
}
}
}
// LOG(INFO) << reader->getEventInfo(0)->at(0).path << " done";
}
//__________________________________________________________________________
void RunFindAdcError(int run_min, int run_max)
{
std::string DATADIR = "/local/data/tpc-beam-test-2017";
FairLogger* logger = FairLogger::GetLogger();
logger->SetLogVerbosityLevel("LOW");
logger->SetLogScreenLevel("INFO");
// ===========================================================================
// Preparing File Infos
// ===========================================================================
std::vector<std::string> fileInfos;
for (int r = run_min; r <= run_max; ++r) {
std::ostringstream ss;
ss << DATADIR << "/run" << std::setw(6) << std::setfill('0') << r << "/run" << std::setw(6) << std::setfill('0') << r;
fileInfos.emplace_back(ss.str() + "_trorc00_link00.bin:0:9");
fileInfos.emplace_back(ss.str() + "_trorc00_link01.bin:1:9");
// fileInfos.emplace_back(ss.str()+"_trorc00_link02.bin:0:10");
// fileInfos.emplace_back(ss.str()+"_trorc00_link03.bin:1:10");
// fileInfos.emplace_back(ss.str()+"_trorc00_link04.bin:0:11");
// fileInfos.emplace_back(ss.str()+"_trorc00_link05.bin:1:11");
// fileInfos.emplace_back(ss.str()+"_trorc00_link06.bin:2:11");
// fileInfos.emplace_back(ss.str()+"_trorc00_link07.bin:3:11");
// fileInfos.emplace_back(ss.str()+"_trorc00_link08.bin:2:12");
// fileInfos.emplace_back(ss.str()+"_trorc00_link09.bin:3:12");
fileInfos.emplace_back(ss.str() + "_trorc00_link10.bin:2:13");
fileInfos.emplace_back(ss.str() + "_trorc00_link11.bin:3:13");
}
// ===========================================================================
// Preparing the Readers
// ===========================================================================
LOG(INFO) << "Create all Readers...";
std::vector<std::shared_ptr<RawReader>> RawReaders;
for (const auto& s : fileInfos) {
auto rawReader = new RawReader;
rawReader->addInputFile(s);
rawReader->setUseRawInMode3(true);
rawReader->setCheckAdcClock(true);
// keep only raw data
if (rawReader->getEventInfo(0)->at(0).header.dataType != 2)
RawReaders.push_back(std::shared_ptr<RawReader>(rawReader));
else
LOG(INFO) << "\tDrop Reader of file " << rawReader->getEventInfo(0)->at(0).path << " because of readout mode 2.";
}
LOG(INFO) << "... done";
// ===========================================================================
// Loop through the Readers to find ADC errors
// ===========================================================================
LOG(INFO) << "Loop through Readers...";
std::vector<std::thread> threads;
std::vector<std::vector<Result>> results(RawReaders.size());
int i = 0;
for (auto& reader_ptr : RawReaders) {
if (run_parallel)
threads.emplace_back(loopReader, std::ref(reader_ptr), std::ref(results[i]));
else
loopReader(std::ref(reader_ptr), std::ref(results[i]));
++i;
}
for (std::thread& t : threads) {
t.join();
}
LOG(INFO) << "... done";
// ===========================================================================
// Analyse outcome
// ===========================================================================
logger->SetLogScreenLevel("DEBUG");
hAdcError = new TH2F("hAdcError", "occurrence of ADC errors", 36, 0, 36, 20, 0, 20);
hAdcError->GetXaxis()->SetTitle("SampaID");
hAdcError->GetYaxis()->SetTitle("Timebin");
o2::tpc::PadPos padPos;
std::cout << RawReaders.size() << std::endl;
for (int i = 0; i < results.size(); ++i) {
if (results[i].size() == 0)
continue;
std::cout << results[i].size() << " " << results[i][0].mEvent << " " << i << std::endl;
int sampaChip = 0;
for (const auto& r : results[i]) {
sampaChip = (r.mRegion * 4) + ((r.mLink - 9) * 3) + r.mSampa;
hAdcError->Fill(sampaChip, r.mTimebin);
std::cout
<< r.mRun << " "
<< r.mEvent << " "
<< r.mRegion << " "
<< r.mLink << " "
<< r.mSampa << " "
<< r.mTimebin << " "
<< r.mSyncPos << std::endl;
RawReaders[i]->loadEvent(r.mEvent);
}
// while (std::shared_ptr<std::vector<uint16_t>> data = RawReaders[i]->getNextData(padPos)) {
// if (!data) continue;
//
// }
}
hAdcError->Draw("colz");
}