CbmRoot
Loading...
Searching...
No Matches
CbmRichUnpackMonitor.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 Goethe-University, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Adrian Weber [committer]*/
4
6
7#include "MicrosliceDescriptor.hpp"
8
9#include <FairRun.h>
10#include <FairRunOnline.h>
11#include <Logger.h>
12
13#include <RtypesCore.h>
14#include <TFile.h>
15#include <TH1.h>
16#include <TH2.h>
17#include <THttpServer.h>
18#include <TProfile.h>
19#include <TROOT.h>
20
21#include <cmath>
22#include <cstdint>
23#include <iomanip>
24#include <iostream>
25#include <memory>
26#include <string>
27#include <vector>
28
29CbmRichUnpackMonitor::CbmRichUnpackMonitor(/* args */) : vNbMessType(7, 0), fvpAllHistoPointers() {}
30
32{
33 for (auto iter = fvpAllHistoPointers.begin(); iter != fvpAllHistoPointers.end();) {
34 if (iter->first != nullptr) {
35 delete iter->first;
36 }
37 iter = fvpAllHistoPointers.erase(iter);
38 }
39}
40
42{
43 TString sHistName{""};
44 TString title{""};
45 //const UInt_t uNbAsics = pUnpackPar->GetNrOfAsics();
46
47
49 fhDigisTimeInRun = new TH1I("hRichDigisTimeInRun", "Digis Nb vs Time in Run; Time in run [s]; Digis Nb []", 10, 0, 1);
50 fhDigisTimeInRun->SetCanExtend(TH1::kAllAxes);
52
53 fhDigisToT = new TH1D("hDigisToT", "fhDigisToT; ToT [ns]; Entries", 400, 0, 40.);
55
56 for (Int_t i = 0; i < pUnpackPar->GetNaddresses(); ++i) {
57 auto DiRICH = pUnpackPar->GetAddress(i);
58 TH2* hist =
59 new TH2D(Form("fhDigisToT_0x%04x", DiRICH), Form("fhDigisToT_0x%04x; channel; ToT [ns]; Entries", DiRICH), 33, 0,
60 32, 450, 0x7900 < DiRICH ? 0 : 15., 0x7900 < DiRICH ? 45 : 30.);
61 fhDigisToTDiRICH.push_back(hist);
63 }
64
65 fhVectorSize = new TH1I("fhVectorSize", "Size of the vector VS TS index; TS index; Size [bytes]", 10, 0, 10);
66 fhVectorSize->SetCanExtend(TH1::kAllAxes);
68
70 new TH1I("fhVectorCapacity", "Size of the vector VS TS index; TS index; Size [bytes]", 10000, 0., 10000.);
72
73 return kTRUE;
74}
75
76
78{
79 fhDigisTimeInRun->Reset();
80 fhVectorSize->Reset();
81 fhVectorCapacity->Reset();
82
83 return kTRUE;
84}
85
86Bool_t CbmRichUnpackMonitor::CreateDebugHistograms(CbmMcbm2018RichPar* /*pUnpackPar*/) { return kTRUE; }
87
89// -------------------------------------------------------------------------
90
91
92// -------------------------------------------------------------------------
94{
95 if (0 == dFirstTsStartTime) dFirstTsStartTime = dTsStartTimeS;
96 // double_t dTimeInRun = dTsStartTimeS - dFirstTsStartTime;
97 // double_t dRatio = 0;
98}
99
100void CbmRichUnpackMonitor::FillDigisToTDiRICH(Int_t Address, Double_t ToT)
101{
102 // Get Index from Address;
103 Int_t Fpga = (Address >> 16) & 0xFFFF;
104 Int_t channel = Address & 0xFFFF;
105
106 fhDigisToTDiRICH.at(pUnpackParameters->GetAddressIdx(Fpga))->Fill(channel, ToT);
107}
108
109// -------------------------------------------------------------------------
110void CbmRichUnpackMonitor::PrintDebugInfo(const uint64_t /*MsStartTime*/, const size_t /*NrProcessedTs*/,
111 const uint16_t /*msDescriptorFlags*/, const uint32_t /*uSize*/)
112{
113}
114
115// ---- Init ----
117{
118 pUnpackParameters = parset;
119
121 TFile* oldFile = gFile;
122 TDirectory* oldDir = gDirectory;
123 gROOT->cd();
124
126 CreateHistograms(parset);
128
130 gFile = oldFile;
131 gDirectory = oldDir;
132
134 std::vector<std::pair<TNamed*, std::string>> vHistos = GetHistoVector();
135
137 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
138 if (nullptr != server) {
139 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
140 server->Register(Form("/rich/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
141 }
142 /*
143 server->RegisterCommand("/Reset_UnpRich_Hist", "bMcbm2018UnpackerTaskRichResetHistos=kTRUE");
144 server->Restrict("/Reset_UnpRich_Hist", "allow=admin");
145*/
146 }
147
148 return kTRUE;
149}
150
151// ---- Finish ----
153{
154
156 std::vector<std::pair<TNamed*, std::string>> vHistos = GetHistoVector();
157
159 TFile* oldFile = gFile;
160 TDirectory* oldDir = gDirectory;
161 TFile* histoFile = nullptr;
162
163 // open separate histo file in recreate mode
164 histoFile = new TFile(fHistoFileName, "RECREATE");
165 histoFile->cd();
166
168 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
170 TString sFolder = vHistos[uHisto].second.data();
171 if (nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
172 gDirectory->cd(sFolder);
173
175 vHistos[uHisto].first->Write();
176
177 histoFile->cd();
178 }
179
181 gFile = oldFile;
182 gDirectory = oldDir;
183
184 histoFile->Close();
185 delete histoFile;
186}
187
188
ClassImp(CbmConverterManager)
Monitoring historgrams class for Rich unpacker.
Int_t GetNaddresses(void) const
Int_t GetAddress(Int_t ind) const
Int_t GetAddressIdx(Int_t addr, bool bVerbose=true) const
void PrintDebugInfo(const uint64_t MsStartTime, const size_t NrProcessedTs, const uint16_t msDescriptorFlags, const uint32_t uSize)
Bool_t CreateDebugHistograms(CbmMcbm2018RichPar *pUnpackPar)
void FillDigisToTDiRICH(Int_t Address, Double_t ToT)
void Finish()
Write all histograms to file.
CbmMcbm2018RichPar * pUnpackParameters
std::vector< std::pair< TNamed *, std::string > > fvpAllHistoPointers
bool fDebugMode
Flag if debug mode is active or not.
void AddHistoToVector(TNamed *pointer, std::string sFolder="")
std::vector< TH2 * > fhDigisToTDiRICH
Bool_t CreateHistograms(CbmMcbm2018RichPar *pUnpackPar)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
Bool_t Init(CbmMcbm2018RichPar *parset)
Init all required parameter informations and histograms.
void FillPerTimesliceCountersHistos(double_t dTsStartTime)
TH1 * fhDigisTimeInRun
General histograms.