BmnRoot
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)
40 , fApplyThreshold(kTRUE)
41 , fPeriodId(period)
42 // , fEventId(0)
43 , fNTotalEvents(0)
44 , fNSignalEvents(0)
45 , fStartEventId(0)
46 , fRawFileName(file)
47 , fMaxEvent(nEvents)
48 , fBmnSetup(kBMNSETUP)
49 , fUseCalibFile(false)
50 , fT0Serial(0)
51 , fVerbose(0)
52{
53 isRawRootInputFile = IsRootFile(fRawFileName);
54 fRunId = GetRunIdFromFile(fRawFileName);
55 fSubName = BmnConverterTools::GetSubNameAfterRunId(fRawFileName);
56 LOG(debug) << "subname " << fSubName;
57 LOG(info) << "RunId " << fRunId << " got from " << (isRawRootInputFile ? "RawRoot" : "RawData") << " file";
58 fDigiFileName = (outfile == "") ? Form("bmn_run%d%s_digi.root", fRunId, fSubName.Data()) : outfile;
59 if (isRawRootInputFile)
60 fRootFileName = fRawFileName;
61}
62
64{
65 LOG(debug) << "~BmnRawDataDecoder()";
66 if (fRawSource)
67 delete fRawSource;
68 if (fDecoder)
69 delete fDecoder;
70}
71
73{
74 if (fRootFileName.Length() == 0) {
75 Int_t lastSlash = fDigiFileName.Last('/');
76 fDigiDirPath = (lastSlash == TString::kNPOS) ? "" : TString(fDigiFileName(0, lastSlash + 1));
77 if (fRootDirPath.Length() == 0)
78 fRootDirPath = fDigiDirPath;
79 fRootFileName = Form("%sbmn_run%d%s_raw.root", fRootDirPath.Data(), fRunId, fSubName.Data());
80 }
81 if (fRootDirPath.Length()) {
82 bool dc = std::filesystem::create_directories(fRootDirPath.Data());
83 LOGF(info, "Raw directory: %s was %s", fRootDirPath.Data(), dc ? "created" : "already present");
84 }
85 fRawSource = new BmnRawSource(fRawFileName, fRootFileName, fMaxEvent, fPeriodId);
86 fRawSource->SetDecoderConfigFileName(fDecoderConfigFileName);
87 fRawSource->SetForwardMode(isForwardMode);
88 fRawSource->SetRunId(fRunId);
89 fRawSource->SetVerbose(fVerbose);
90}
91
93{
94 if (fRootFileName.Length() == 0) {
95 Int_t lastSlash = fDigiFileName.Last('/');
96 fDigiDirPath = (lastSlash == TString::kNPOS) ? "" : TString(fDigiFileName(0, lastSlash + 1));
97 if (fRootDirPath.Length() == 0)
98 fRootDirPath = fDigiDirPath;
99 fRootFileName = Form("%sbmn_run%d%s_raw.root", fRootDirPath.Data(), fRunId, fSubName.Data());
100 }
101 fDecoder = new BmnDecoder(fRootFileName, fDigiFileName, fMaxEvent, fPeriodId);
102 fDecoder->SetForwardMode(isForwardMode);
103 fDecoder->SetDecoderConfigFileName(fDecoderConfigFileName);
104 fDecoder->SetDetectorSetup(fDetectorSetup);
105 fDecoder->SetBmnSetup(fBmnSetup);
106 fDecoder->SetRunId(fRunId);
107 fDecoder->SetVerbose(fVerbose);
108}
109
111{
112 return fRawSource->InitConverter(FileName);
113}
114
116{
117 return fRawSource->InitConverter();
118}
119
121{
122 return fDecoder->InitDecoder();
123}
124
126{
127 TTree* raw_tree = fRawSource->GetRawTree();
128 fDecoder->SetRawTree(raw_tree);
129 TTree* raw_tree_spills = fRawSource->GetRawTreeSpills();
130 fDecoder->SetRawTreeSpills(raw_tree_spills);
131 fDecoder->AssignInputs();
132}
133
135{
136 return fRawSource->ConvertRawToRootIterate(buf, len);
137}
138
143
145{
146 if (isRawRootInputFile) {
147 LOGF(info, "Input is raw root file. Nothing to do!");
148 return kBMNSUCCESS;
149 } else {
150 if (!fRawSource)
152 return fRawSource->ConvertRawToRoot();
153 }
154}
155
160
162{
163 Int_t lastSlash = name.Last('/');
164 TString str(name(lastSlash + 1, name.Length() - lastSlash));
165 TPRegexp re_universal("[^0123456789]*(\\d+)(.*)\\.(\\w+)");
166 re_universal.Substitute(str, "$1");
167 return str.Atoi();
168}
169
171{
172 TPRegexp re(".+\\.root");
173 return re.MatchB(name);
174}
175
177{
178 TPRegexp re(".+\\.data");
179 return re.MatchB(name);
180}
BmnStatus
Definition BmnEnums.h:24
@ kBMNSUCCESS
Definition BmnEnums.h:25
@ kBMNSETUP
Definition BmnEnums.h:90
static TString GetSubNameAfterRunId(TString name)
void SetRawTree(TTree *tree)
Definition BmnDecoder.h:114
void SetBmnSetup(BmnSetup v)
Definition BmnDecoder.h:235
BmnStatus DecodeDataToDigiIterate()
void SetRunId(UInt_t v)
Definition BmnDecoder.h:124
void SetForwardMode(bool v=true)
Definition BmnDecoder.h:258
void AssignInputs()
void SetDetectorSetup(std::map< DetectorId, bool > setup)
Definition BmnDecoder.h:229
void SetDecoderConfigFileName(string FileName)
Definition BmnDecoder.h:276
BmnStatus DecodeDataToDigi()
void SetRawTreeSpills(TTree *tree)
Definition BmnDecoder.h:116
void SetVerbose(Int_t v)
Definition BmnDecoder.h:239
BmnStatus InitDecoder()
static double threshCsc
static double correctionSil
static Bool_t IsRawFile(TString name)
static double correctionGem
static double correctionCsc
BmnStatus DecodeDataToDigiIterate()
static double threshSil
BmnStatus ConvertRawToRootIterate(UInt_t *buf, UInt_t len)
static double threshGem
static Bool_t IsRootFile(TString name)
BmnRawDataDecoder(TString file="", TString outfile="", ULong_t nEvents=0, ULong_t period=8)
static Int_t GetRunIdFromFile(TString name)
BmnStatus ConvertRawToRoot()
void SetDecoderConfigFileName(string FileName)
BmnStatus InitConverter(TString FileName)
TTree * GetRawTreeSpills()
BmnStatus ConvertRawToRootIterate(UInt_t *buf, UInt_t len)
void SetVerbose(Int_t v)
void SetForwardMode(bool v=true)
void SetRunId(UInt_t v)
TTree * GetRawTree()