BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnRawDataDecoder.cxx
Go to the documentation of this file.
1#include "BmnRawDataDecoder.h"
2
3#include <iostream>
4// ROOT
5#include "TStopwatch.h"
6// FairRoot
7#include "FairLogger.h"
8// BmnRoot
9#include "BmnConverterTools.h"
10#include "UniDetectorParameter.h"
11#include "UniRawFile.h"
12#include "UniRun.h"
13
14// Double_t realtime = 0.0;
15// Double_t converterTime = 0.0;
16
17#include <arpa/inet.h> /* For ntohl for Big Endian LAND. */
18
19// how protruded the noisy channel should be
23
24// if not enough statistic is in histograms
28
29// window size
33
34BmnRawDataDecoder::BmnRawDataDecoder(TString file, TString outfile, ULong_t nEvents, ULong_t period)
35 : fRawSource(nullptr)
36 , fDecoder(nullptr)
37 , isTaskMode(false)
38 , isForwardMode(false)
39 , isRawRootInputFile(false)
41 , fPeriodId(period)
42 // , fEventId(0)
43 , fNTotalEvents(0)
45 , fStartEventId(0)
46 , fRawFileName(file)
47 , fMaxEvent(nEvents)
49 , fUseCalibFile(false)
50 , fT0Serial(0)
51 , fVerbose(0)
52{
54 BmnFileProp prop;
56 fRunId = prop.GetRunId();
58 LOG(debug) << "subname " << fSubName;
59 LOG(info) << "RunId " << fRunId << " got from " << (isRawRootInputFile ? "RawRoot" : "RawData") << " file";
60 fDigiFileName = (outfile == "") ? Form("bmn_run%d%s_digi.root", fRunId, fSubName.Data()) : outfile;
63}
64
66{
67 LOG(debug) << "~BmnRawDataDecoder()";
68 if (fRawSource)
69 delete fRawSource;
70 if (fDecoder)
71 delete fDecoder;
72}
73
75{
76 if (fRootFileName.Length() == 0) {
77 Int_t lastSlash = fDigiFileName.Last('/');
78 fDigiDirPath = (lastSlash == TString::kNPOS) ? "" : TString(fDigiFileName(0, lastSlash + 1));
79 if (fRootDirPath.Length() == 0)
81 fRootFileName = Form("%sbmn_run%d%s_raw.root", fRootDirPath.Data(), fRunId, fSubName.Data());
82 }
83 if (fRootDirPath.Length()) {
84 bool dc = std::filesystem::create_directories(fRootDirPath.Data());
85 LOGF(info, "Raw directory: %s was %s", fRootDirPath.Data(), dc ? "created" : "already present");
86 }
88 fRawSource->SetDecoderConfigFileName(fDecoderConfigFileName);
89 fRawSource->SetForwardMode(isForwardMode);
90 if (fRawSource->GetRunId() == 0)
91 fRawSource->SetRunId(fRunId);
92 else
93 fRunId = fRawSource->GetRunId();
94 fRawSource->SetVerbose(fVerbose);
95}
96
98{
99 LOGF(info, "fRunId %u fRootFileName %s", fRunId, fRootFileName.Data());
100 if (fRootFileName.Length() == 0) {
101 Int_t lastSlash = fDigiFileName.Last('/');
102 fDigiDirPath = (lastSlash == TString::kNPOS) ? "" : TString(fDigiFileName(0, lastSlash + 1));
103 if (fRootDirPath.Length() == 0)
105 fRootFileName = Form("%sbmn_run%d%s_raw.root", fRootDirPath.Data(), fRunId, fSubName.Data());
106 }
108 fDecoder->SetForwardMode(isForwardMode);
109 fDecoder->SetDecoderConfigFileName(fDecoderConfigFileName);
110 fDecoder->SetDetectorSetup(fDetectorSetup);
111 fDecoder->SetBmnSetup(fBmnSetup);
112 if (fDecoder->GetRunId() == 0)
113 fDecoder->SetRunId(fRunId);
114 else
115 fRunId = fDecoder->GetRunId();
116 fDecoder->SetVerbose(fVerbose);
117}
118
120{
121 return fRawSource->InitConverter(FileName);
122}
123
125{
126 return fRawSource->InitConverter();
127}
128
130{
131 return fDecoder->InitDecoder();
132}
133
135{
136 TTree* raw_tree = fRawSource->GetRawTree();
137 fDecoder->SetRawTree(raw_tree);
138 TTree* raw_tree_spills = fRawSource->GetRawTreeSpills();
139 fDecoder->SetRawTreeSpills(raw_tree_spills);
140 fDecoder->AssignInputs();
141}
142
144{
145 return fRawSource->ConvertRawToRootIterate(buf, len);
146}
147
149{
150 return fDecoder->DecodeDataToDigiIterate();
151}
152
154{
155 if (isRawRootInputFile) {
156 LOGF(info, "Input is raw root file. Nothing to do!");
157 return kBMNSUCCESS;
158 } else {
159 if (!fRawSource)
161 return fRawSource->ConvertRawToRoot();
162 }
163}
164
166{
167 return fDecoder->DecodeDataToDigi();
168}
169
171{
172 TPRegexp re(".+\\.root");
173 return re.MatchB(name);
174}
bool Bool_t
int Int_t
constexpr Bool_t kTRUE
char * Form(const char *fmt,...)
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
@ kBMNSETUP
Definition BmnEnums.h:166
static TString GetSubNameAfterRunId(TString name)
static BmnStatus ParseRawFileName(const TString &s, BmnFileProp &prop)
uint32_t GetRunId() const
Definition BmnFileProp.h:22
static double threshCsc
static double correctionSil
static double correctionGem
static double correctionCsc
BmnStatus DecodeDataToDigiIterate()
static double threshSil
BmnRawSource * fRawSource
BmnStatus ConvertRawToRootIterate(UInt_t *buf, UInt_t len)
static double threshGem
static Bool_t IsRootFile(TString name)
std::map< DetectorId, bool > fDetectorSetup
BmnRawDataDecoder(TString file="", TString outfile="", ULong_t nEvents=0, ULong_t period=8)
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
static constexpr Ssiz_t kNPOS