CbmRoot
Loading...
Searching...
No Matches
CaToolsDebugger.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov, Sergei Zharko [committer] */
4
9
10/*
11root -l CAdebug.root
12TNtuple *n = (TNtuple*) gDirectory->FindObjectAny("triplets")
13n->Draw("chi2")
14*/
15
16#include "CaToolsDebugger.h"
17
19#include "TDirectory.h"
20#include "TFile.h"
21#include "TNtuple.h"
22
23#include <cstdarg>
24#include <iostream>
25#include <memory>
26#include <string>
27
29
31 public:
33 {
34 std::shared_ptr<Debugger> instance(new Debugger("CaDebug.root"));
35 Debugger::SetInstance(instance);
36 }
37};
38
40
41
43{
45 fIsWritten = true;
46 TDirectory* currDir = gDirectory;
47 if (fFile) {
48 fFile->cd();
49 for (unsigned int i = 0; i < fNtuples.size(); i++) {
50 fNtuples[i]->Write();
51 }
52 }
53 gDirectory = currDir;
54}
55
57{
59 if (!fIsWritten && fFile) {
60 LOG(error) << "CaDebugger: you forgot to Write()!!";
61 }
62}
63
64void Debugger::AddNtuple(const char* name, const char* varlist)
65{
67
68 if (!fFile) {
69 fFile = new TFile(fFileName.c_str(), "RECREATE");
70 }
71 assert(fFile);
72 if (GetNtupleIndex(name) >= 0) return;
73 TDirectory* currDir = gDirectory;
74 fFile->cd();
75 fNtuples.push_back(new TNtuple(name, name, varlist));
76 gDirectory = currDir;
77}
78
79int Debugger::GetNtupleIndex(const char* name)
80{
81 int ind = -1;
82 for (unsigned int i = 0; i < fNtuples.size(); i++) {
83 if (strcmp(name, fNtuples[i]->GetName()) == 0) {
84 ind = i;
85 break;
86 }
87 }
88 return ind;
89}
90
91void Debugger::FillNtuple(const char* name, float v[])
92{
93 int iNtuple = GetNtupleIndex(name);
94 if (iNtuple < 0) {
95 std::cerr << "CaDebugger: Ntuple (" << name << ") doesn't exist" << std::endl;
96 }
97 fNtuples[iNtuple]->Fill(v);
98}
static DebuggerInitialiser debuggerInitialiser
Tracking Debugger class (implementation)
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
void Write() override
Write ntuples to the file.
static void SetInstance(std::shared_ptr< Debugger > instance)
Set instance.
void AddNtuple(const char *name, const char *varlist) override
Set new ntuple.
std::vector< TNtuple * > fNtuples
void FillNtuple(const char *name, float v[]) override
Add an entry to ntuple.
int GetNtupleIndex(const char *name)
Get ntuple index.