Project
Loading...
Searching...
No Matches
GPUROOTDump.h
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
14
15#ifndef GPUROOTDUMP_H
16#define GPUROOTDUMP_H
17
18#include "GPUCommonDef.h"
19#if !defined(GPUCA_NO_ROOT) && !defined(GPUCA_GPUCODE)
20#include "GPUROOTDumpCore.h"
21#include <TTree.h>
22#include <TNtuple.h>
23#else
24class TNtuple;
25#endif
26#ifndef GPUCA_GPUCODE
27#include <memory>
28#include <stdexcept>
29#endif
30
31namespace o2::gpu
32{
33#if !defined(GPUCA_NO_ROOT) && !defined(GPUCA_GPUCODE)
34namespace
35{
36template <class S>
37struct internal_Branch {
38 template <typename... Args>
39 static void Branch(S* p, Args... args)
40 {
41 }
42};
43template <>
44struct internal_Branch<TTree> {
45 template <typename... Args>
46 static void Branch(TTree* p, Args... args)
47 {
48 p->Branch(args...);
49 }
50};
51} // namespace
52
53template <typename... Args>
55
56template <class T, typename... Args>
57class GPUROOTDump<T, Args...> : public GPUROOTDump<Args...>
58{
59 public:
60 template <typename... Names>
61 static GPUROOTDump<T, Args...>& get(const char* name1, Names... names) // return always the same instance, identified by template
62 {
63 static GPUROOTDump<T, Args...> instance(name1, names...);
64 return instance;
65 }
66 template <typename... Names>
67 static GPUROOTDump<T, Args...> getNew(const char* name1, Names... names) // return new individual instance
68 {
69 return GPUROOTDump<T, Args...>(name1, names...);
70 }
71
72 void Fill(const T& o, const Args&... args)
73 {
75 FillInternal(o, args...);
76 }
77
78 protected:
79 void FillInternal(const T& o, const Args&... args)
80 {
81 mObj = o;
83 }
84
85 using GPUROOTDump<Args...>::mTree;
86 template <typename... Names>
87 GPUROOTDump(const char* name1, Names... names) : GPUROOTDump<Args...>(names...)
88 {
90 mTree->Branch(name1, &mObj);
91 }
92
93 private:
94 T mObj;
95};
96
97template <>
99{
100 public:
101 void write() override { mTree->Write(); }
102
103 protected:
104 void Fill()
105 {
106 mTree->Fill();
107 }
108
109 GPUROOTDump(const char* name1, const char* nameTree = nullptr)
110 {
111 if (nameTree == nullptr) {
112 nameTree = name1;
113 }
115 mTree = new TTree(nameTree, nameTree);
116 }
117 TTree* mTree = nullptr;
118};
119
120template <>
121class GPUROOTDump<TNtuple> : public GPUROOTDumpBase
122{
123 public:
124 static GPUROOTDump<TNtuple>& get(const char* name, const char* options)
125 {
126 static GPUROOTDump<TNtuple> instance(name, options);
127 return instance;
128 }
129 static GPUROOTDump<TNtuple> getNew(const char* name, const char* options)
130 {
131 return GPUROOTDump<TNtuple>(name, options);
132 }
133
134 void write() override { mNTuple->Write(); }
135
136 template <typename... Args>
137 void Fill(const Args&... args)
138 {
140 mNTuple->Fill(args...);
141 }
142
143 private:
144 GPUROOTDump(const char* name, const char* options)
145 {
147 mNTuple = new TNtuple(name, name, options);
148 }
149 TNtuple* mNTuple;
150};
151#else
152template <typename... Args>
153class GPUROOTDump
154{
155 public:
156 template <typename... Names>
157 GPUd() static void Fill(Args... args)
158 {
159 }
160 template <typename... Names>
161 GPUd() static GPUROOTDump<Args...>& get(Args... args)
162 {
163 return GPUROOTDump<Args...>();
164 }
165 template <typename... Names>
166 GPUd() static GPUROOTDump<Args...>& getNew(Args... args)
167 {
168 return GPUROOTDump<Args...>();
169 }
170};
171#endif
172} // namespace o2::gpu
173
174#endif
static std::atomic_flag mMutex
static GPUROOTDump< TNtuple > getNew(const char *name, const char *options)
static GPUROOTDump< TNtuple > & get(const char *name, const char *options)
void Fill(const Args &... args)
void FillInternal(const T &o, const Args &... args)
Definition GPUROOTDump.h:79
GPUROOTDump(const char *name1, Names... names)
Definition GPUROOTDump.h:87
static GPUROOTDump< T, Args... > & get(const char *name1, Names... names)
Definition GPUROOTDump.h:61
static GPUROOTDump< T, Args... > getNew(const char *name1, Names... names)
Definition GPUROOTDump.h:67
void Fill(const T &o, const Args &... args)
Definition GPUROOTDump.h:72
void write() override
GPUROOTDump(const char *name1, const char *nameTree=nullptr)
GLuint const GLchar * name
Definition glcorearb.h:781
GPUd() const expr uint32_t MultivariatePolynomialHelper< Dim
target1_1 Fill(5)