13 #include <FairLogger.h>
31 :
AtUnpacker(map), fNumFiles(numGrawFiles), fCurrentEventID(fNumFiles, 0), fIsSeparatedData(fNumFiles > 1)
34 fDecoder.push_back(std::make_unique<GETDecoder2>());
35 fPedestal.push_back(std::make_unique<AtPedestal>());
49 LOG(error) <<
"Problem setting the data pointer to the first file in the list!";
51 std::vector<int> iniFrameIDs;
52 LOG(info) <<
"Initial frame IDs";
55 iniFrameIDs.push_back(basicFrame->
GetEventID());
56 LOG(info) << i <<
" " << iniFrameIDs.back();
62 void AtGRAWUnpacker::FindAndSetNumEvents()
64 std::vector<int> eventCoboIDs;
65 std::vector<int> lastEvents;
66 std::vector<std::thread> file;
67 std::vector<std::future<CoboAndEvent>> futureValues;
72 std::promise<CoboAndEvent> p;
73 futureValues.push_back(p.get_future());
75 [
this](Int_t fileIdx, std::promise<CoboAndEvent> &&promise) {
76 promise.set_value(this->GetLastEvent(fileIdx));
81 for (
auto &fileThread : file)
84 for (
auto &future : futureValues) {
86 int coboNum = value.first;
87 int lastEvent = value.second;
88 if (std::find(begin(eventCoboIDs), end(eventCoboIDs), coboNum) != eventCoboIDs.end()) {
89 for (
int r = 0; r < eventCoboIDs.size(); r++) {
90 if (eventCoboIDs[r] == coboNum) {
91 if (lastEvents[r] < lastEvent) {
92 lastEvents[r] = lastEvent;
97 eventCoboIDs.push_back(coboNum);
98 lastEvents.push_back(lastEvent);
102 fNumEvents = *std::min_element(begin(lastEvents), end(lastEvents));
111 LOG(error) <<
"Data was not set, settinge event bad and skipping.";
117 std::vector<std::thread> file;
119 for (Int_t iFile = 0; iFile <
fNumFiles; iFile++) {
120 file.emplace_back([
this](Int_t fileIdx) { this->ProcessBasicFile(fileIdx); }, iFile);
124 for (
auto &fileThread : file)
132 for (Int_t iFile = 0; iFile <
fNumFiles; iFile++)
134 LOG(error) <<
"Event IDs don't match between files! fCurrentEventID[0]: " <<
fCurrentEventID[0]
135 <<
" fCurrentEventID[" << iFile <<
"]: " <<
fCurrentEventID[iFile] << std::endl;
137 event.SetIsGood(kFALSE);
146 if (layeredFrame ==
nullptr)
147 event.SetIsGood(
false);
149 ProcessLayeredFrame(layeredFrame);
153 if (frame ==
nullptr)
154 event.SetIsGood(
false);
156 ProcessBasicFrame(frame);
159 LOG(ERROR) <<
"We are not setup to unpack unseperated data for the current detector type!";
160 event.SetIsGood(
false);
173 bool isLastEvent =
false;
180 return frame ==
nullptr;
183 return frame ==
nullptr;
189 void AtGRAWUnpacker::processInputFile()
198 TString dataFileWithPath;
203 while (dataFileWithPath.ReadLine(listFile)) {
204 if (dataFileWithPath.Contains(Form(
fFileIDString.data(), i))) {
205 fDecoder[i]->AddData(dataFileWithPath);
206 LOG(info) <<
" Added file : " << dataFileWithPath <<
" - " <<
fFileIDString <<
" : " << i;
208 LOG(debug) <<
"Skipping file: " << dataFileWithPath <<
" did not match the string " <<
fFileIDString;
215 LOG(warn) <<
"Did not specify a string containing \"%i\" to use to map the incoming files to the proper GETDecoder. "
216 "Using \"AsAd%i\" by default. To change call the function SetInputFileName(std::string fileName, "
217 "std::string fileIDString) instead.";
227 Bool_t AtGRAWUnpacker::AddData(TString filename, Int_t fileIdx)
230 LOG(error) <<
"Trying to add a file with index " << fileIdx
231 <<
" which is larger than the number of files we are unpacking (" <<
fNumFiles <<
")!";
234 return fDecoder[fileIdx]->AddData(filename);
237 void AtGRAWUnpacker::ProcessFile(Int_t fileIdx)
242 if (coboFrame ==
nullptr) {
244 std::cout <<
" Null frame! CoboIdx " << fileIdx <<
"\n";
251 for (Int_t iFrame = 0; iFrame < numFrames; iFrame++) {
257 for (Int_t iAget = 0; iAget < 4; iAget++) {
258 for (Int_t iCh = 0; iCh < 68; iCh++) {
261 auto PadRefNum =
fMap->GetPadNum(PadRef);
264 if (
fMap->IsFPNchannel(PadRef)) {
270 savePad(*frame, PadRef,
fRawEvent, fileIdx);
276 void AtGRAWUnpacker::ProcessBasicFile(Int_t fileIdx)
281 if (basicFrame ==
nullptr) {
283 LOG(error) <<
"Basic frame was null! Skipping event " <<
fEventID;
292 for (Int_t iAget = 0; iAget < 4; iAget++) {
293 for (Int_t iCh = 0; iCh < 68; iCh++) {
297 if (
fMap->IsFPNchannel(PadRef)) {
303 auto PadNum =
fMap->GetPadNum(PadRef);
305 savePad(*basicFrame, PadRef,
fRawEvent, fileIdx);
313 auto PadRefNum =
fMap->GetPadNum(PadRef);
314 auto PadCenterCoord =
fMap->CalcPadCenter(PadRefNum);
316 AtPad *pad =
nullptr;
325 fillPadAdc(frame, PadRef, pad);
328 doFPNSubtraction(frame, *
fPedestal[fileIdx], *pad,
fMap->GetNearestFPN(PadRef));
330 doBaselineSubtraction(*pad);
340 for (Int_t iTb = 0; iTb < 512; iTb++)
346 AtPad *pad =
nullptr;
353 fillPadAdc(frame, PadRef, pad);
359 void AtGRAWUnpacker::saveLastCell(
AtPad &pad, Double_t lastCell)
361 auto lastCellPad =
dynamic_cast<AtPadValue *
>(pad.
AddAugment(
"lastCell", std::make_unique<AtPadValue>()));
372 void AtGRAWUnpacker::doBaselineSubtraction(
AtPad &pad)
375 Double_t baseline = std::accumulate(rawadc.begin() + 5, rawadc.begin() + 25, 0.0) / 20.;
376 for (Int_t iTb = 0; iTb < 512; iTb++) {
377 pad.
SetADC(iTb, rawadc[iTb] - baseline);
385 decoder->SetPseudoTopologyFrame(asadMask, check);
391 FindAndSetNumEvents();
400 coboInfo.first = basicFrame->
GetCoboID();
403 basicFrame =
fDecoder[fileIdx]->GetBasicFrame(-1);
404 if (basicFrame !=
nullptr) {