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 "Logger.h"
13#include "TCanvas.h"
14#include "TDirectory.h"
15#include "TNamed.h"
16
19
20// ---------------------------------------------------------------------------------------------------------------------
21//
22ObjectHandler::ObjectHandler(int iObject, int iFile, int iDataset, const char* objType)
23 : fsObjType(objType)
24 , fObjectID(iObject)
25 , fFileID(iFile)
26 , fDatasetID(iDataset)
27{
28}
29
30// ---------------------------------------------------------------------------------------------------------------------
31//
33{
34 for (auto* pObj : fvpObjects) {
35 if (pObj) {
36 delete pObj;
37 pObj = nullptr;
38 }
39 }
40}
41
42// ---------------------------------------------------------------------------------------------------------------------
43//
44void ObjectHandler::AddObjects(const std::vector<TNamed*>& vpObj)
45{
46 // ----- Check input
47 LOG_IF(fatal, !fpObjDB) << "ObjectHandler: object database was not defined";
48 LOG_IF(fatal, !fpOutDir) << "ObjectHandler: output directory was not defined";
49 LOG_IF(fatal, (int) vpObj.size() != fpObjDB->GetNofVersions())
50 << "ObjectHandler: Attempt to add vector with object pointers of different to the one of version labels";
51
52 TDirectory* pCurrDir = gDirectory;
53 gDirectory = fpOutDir;
54 for (int iVer = 0; iVer < fpObjDB->GetNofVersions(); ++iVer) {
55 if (!fsBaseName.size()) {
56 fsBaseName = vpObj[iVer]->GetName();
57 }
58 else {
59 LOG_IF(fatal, strcmp(fsBaseName.c_str(), vpObj[iVer]->GetName()))
60 << "Hist1DHandler: attempt to add object of different name " << fsBaseName << " vs. " << vpObj[iVer]->GetName();
61 }
62 const char* cloneName = Form("%s_orig_%s", fsBaseName.data(), fpObjDB->GetVersionLabel(iVer).data());
63 fvpObjects.push_back((TNamed*) vpObj[iVer]->Clone(cloneName));
64 }
65 gDirectory = pCurrDir;
66}
67
68// ---------------------------------------------------------------------------------------------------------------------
69//
70std::vector<ECmpInference> ObjectHandler::CompareWithDefault()
71{
72 // All object versions are equal to default one (H0)
73 std::vector<ECmpInference> res(fpObjDB->GetNofVersions(), ECmpInference::StronglyEqual);
74 int iDef = fpObjDB->GetDefaultID();
75 for (int iV = 0; iV < (int) fvpObjects.size(); ++iV) {
76 if (iV == iDef) {
77 continue;
78 }
79 res[iV] = this->Compare(iV);
80 }
81 return res;
82}
83
84// ---------------------------------------------------------------------------------------------------------------------
85//
87{
88 LOG_IF(fatal, !pDir) << "ObjectHandler: attempt to pass nullptr as a folder";
89 fpOutDir = pDir;
90}
91
92// ---------------------------------------------------------------------------------------------------------------------
93//
95{
96 fpOutDir->cd();
97 for (auto pObj : fvpObjects) {
98 pObj->Write();
99 }
100 if (fpCanvas.get()) {
101 fpCanvas->Write();
102 }
103}
Base handler class (implementation)
Base abstract class for object handler.
std::string fsBaseName
Base names of the object.
std::shared_ptr< TCanvas > fpCanvas
Comparison canvas.
std::shared_ptr< ObjectDB > fpObjDB
Pointer to object database.
virtual ECmpInference Compare(int iVersion) const =0
Compares objects to default.
std::vector< TNamed * > fvpObjects
Vector of objects.
ObjectHandler(int iObject, int iFile, int iDataset, const char *objType="")
Default constructor.
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.
std::vector< ECmpInference > CompareWithDefault()
Compares different versions with default.
ECmpInference
The object comparison inference.
@ StronglyEqual
All the comparison methods gave equality.