CbmRoot
Loading...
Searching...
No Matches
CbmQaCheckerObjectHandler.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
12#include "CbmQaCheckerResult.h"
13#include "Logger.h"
14#include "TCanvas.h"
15#include "TDirectory.h"
16#include "TNamed.h"
17
21
22// ---------------------------------------------------------------------------------------------------------------------
23//
24ObjectHandler::ObjectHandler(int iObject, int iFile, int iDataset, const char* objType)
25 : fsObjType(objType)
26 , fObjectID(iObject)
27 , fFileID(iFile)
28 , fDatasetID(iDataset)
29{
30}
31
32// ---------------------------------------------------------------------------------------------------------------------
33//
35{
36 for (auto* pObj : fvpObjects) {
37 if (pObj) {
38 delete pObj;
39 pObj = nullptr;
40 }
41 }
42}
43
44// ---------------------------------------------------------------------------------------------------------------------
45//
46void ObjectHandler::AddObjects(const std::vector<TNamed*>& vpObj)
47{
48 // ----- Check input
49 LOG_IF(fatal, !fpObjDB) << "ObjectHandler: object database was not defined";
50 LOG_IF(fatal, !fpOutDir) << "ObjectHandler: output directory was not defined";
51 LOG_IF(fatal, (int) vpObj.size() != fpObjDB->GetNofVersions())
52 << "ObjectHandler: Attempt to add vector with object pointers of different to the one of version labels";
53
54 TDirectory* pCurrDir = gDirectory;
55 gDirectory = fpOutDir;
56 for (int iVer = 0; iVer < fpObjDB->GetNofVersions(); ++iVer) {
57 if (!fsBaseName.size()) {
58 fsBaseName = vpObj[iVer]->GetName();
59 }
60 else {
61 LOG_IF(fatal, strcmp(fsBaseName.c_str(), vpObj[iVer]->GetName()))
62 << "Hist1DHandler: attempt to add object of different name " << fsBaseName << " vs. " << vpObj[iVer]->GetName();
63 }
64 const char* cloneName = Form("%s_orig_%s", fsBaseName.data(), fpObjDB->GetVersionLabel(iVer).data());
65 fvpObjects.push_back((TNamed*) vpObj[iVer]->Clone(cloneName));
66 }
67 gDirectory = pCurrDir;
68}
69
70// ---------------------------------------------------------------------------------------------------------------------
71//
73{
74 // All object versions are equal to default one (H0)
75 std::vector<Result> res(fpObjDB->GetNofVersions(), Result(ECmpInference::StronglyEqual, true, 1., 1., 1.));
76 int iDef = fpObjDB->GetDefaultID();
77 for (int iV = 0; iV < (int) fvpObjects.size(); ++iV) {
78 if (iV == iDef) {
79 continue;
80 }
81 res[iV] = this->Compare(iV);
82 }
83 return res;
84}
85
86// ---------------------------------------------------------------------------------------------------------------------
87//
89{
90 LOG_IF(fatal, !pDir) << "ObjectHandler: attempt to pass nullptr as a folder";
91 fpOutDir = pDir;
92}
93
94// ---------------------------------------------------------------------------------------------------------------------
95//
97{
98 fpOutDir->cd();
99 for (auto pObj : fvpObjects) {
100 pObj->Write();
101 }
102
103 auto WriteCanvas = [](auto canvas) -> void {
104 if (canvas.get()) canvas->Write();
105 };
106
107 WriteCanvas(fpCanvasCmp);
108 WriteCanvas(fpCanvasRat);
109 WriteCanvas(fpCanvasDiff);
110}
Base handler class (implementation)
ObjectHandler(int iObject, int iFile, int iDataset, const char *objType="")
Default constructor.
Base abstract class for object handler.
std::string fsObjType
Base type of the object to be handled.
std::string fsBaseName
Base names of the object.
std::shared_ptr< TCanvas > fpCanvasCmp
Comparison canvas: plots together.
std::vector< Result > CompareWithDefault()
Compares different versions with default.
std::shared_ptr< TCanvas > fpCanvasDiff
Comparison canvas: difference with default.
std::shared_ptr< ObjectDB > fpObjDB
Pointer to object database.
std::shared_ptr< TCanvas > fpCanvasRat
Comparison canvas: ratios to default.
std::vector< TNamed * > fvpObjects
Vector of objects.
TDirectory * fpOutDir
Pointer to directory.
void AddObjects(const std::vector< TNamed * > &vpObj)
Adds vector of pointer to objects.
void SetOutputDirectory(TDirectory *pDir)
Sets folder to store output.
virtual Result Compare(int iVersion) const =0
Compares objects to default.
A storable result of the QA-checker comparison routine.
ECmpInference
The object comparison inference.
@ StronglyEqual
All the comparison methods gave equality.