Project
Loading...
Searching...
No Matches
CMVHelper.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
17
18#include <iostream>
19
21#include "TParameter.h"
22
23namespace o2::tpc
24{
25
26bool CMVFileHandle::open(const std::string& path)
27{
28 file = TFile::Open(path.c_str());
29 if (!file || file->IsZombie()) {
30 std::cerr << "CMVFileHandle: failed to open: " << path << "\n";
31 return false;
32 }
33 file->GetObject("ccdb_object", tree);
34 if (!tree) {
35 std::cerr << "CMVFileHandle: TTree 'ccdb_object' not found in: " << path << "\n";
36 close();
37 return false;
38 }
39
40 // Extract firstTF / lastTF from UserInfo if stored by the aggregation workflow
41 if (auto* ui = tree->GetUserInfo()) {
42 if (auto* p = dynamic_cast<TParameter<long>*>(ui->FindObject("firstTF"))) {
43 firstTFInTree = p->GetVal();
44 }
45 if (auto* p = dynamic_cast<TParameter<long>*>(ui->FindObject("lastTF"))) {
46 lastTFInTree = p->GetVal();
47 }
48 }
49
50 isCompressed = (tree->GetBranch("CMVPerTFCompressed") != nullptr);
51 const bool isRaw = (tree->GetBranch("CMVPerTF") != nullptr);
52 if (!isCompressed && !isRaw) {
53 std::cerr << "CMVFileHandle: no recognised branch (CMVPerTFCompressed / CMVPerTF) in: "
54 << path << "\n";
55 close();
56 return false;
57 }
58
59 if (isCompressed) {
60 tree->SetBranchAddress("CMVPerTFCompressed", &tfCompressed);
61 tfDecoded = new CMVPerTF();
62 } else {
63 tree->SetBranchAddress("CMVPerTF", &tfRaw);
64 }
65 return true;
66}
67
68const CMVPerTF* CMVFileHandle::getEntry(long long iEntry)
69{
70 tree->GetEntry(iEntry);
71 if (isCompressed) {
72 if (!tfCompressed) {
73 return nullptr;
74 }
76 return tfDecoded;
77 }
78 return tfRaw;
79}
80
82{
83 if (tree) {
84 tree->ResetBranchAddresses();
85 tree = nullptr;
86 }
87 tfCompressed = nullptr;
88 tfRaw = nullptr;
89 delete tfDecoded;
90 tfDecoded = nullptr;
91 if (file) {
92 file->Close();
93 delete file;
94 file = nullptr;
95 }
96}
97
98} // namespace o2::tpc
Structs for storing CMVs to the CCDB.
Helper utilities for reading CMV ROOT files.
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
Global TPC definitions and constants.
Definition SimTraits.h:168
CMVPerTFCompressed * tfCompressed
Definition CMVHelper.h:34
long firstTFInTree
first global TF index from tree UserInfo ("firstTF"); -1 if absent
Definition CMVHelper.h:37
const CMVPerTF * getEntry(long long iEntry)
Load entry iEntry and return a pointer to the decoded CMVPerTF, or nullptr on error.
Definition CMVHelper.cxx:68
long lastTFInTree
last global TF index from tree UserInfo ("lastTF"); -1 if absent
Definition CMVHelper.h:38
bool open(const std::string &path)
Open path and set up branch addresses. Returns false on any error.
Definition CMVHelper.cxx:26
CMVPerTF * tfDecoded
scratch buffer used when decompressing
Definition CMVHelper.h:36
void close()
Release all resources.
Definition CMVHelper.cxx:81
void decompress(CMVPerTF *cmv) const
Restore a CMVPerTF from this compressed object into *cmv (must not be null)