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 <class T, typename... Args>
54class GPUROOTDump : public GPUROOTDump<Args...>
55{
56 public:
57 template <typename... Names>
58 static GPUROOTDump<T, Args...>& get(const char* name1, Names... names) // return always the same instance, identified by template
59 {
60 static GPUROOTDump<T, Args...> instance(name1, names...);
61 return instance;
62 }
63 template <typename... Names>
64 static GPUROOTDump<T, Args...> getNew(const char* name1, Names... names) // return new individual instance
65 {
66 return GPUROOTDump<T, Args...>(name1, names...);
67 }
68 void Fill(const T& o, Args... args)
69 {
70 mObj = o;
72 }
73
74 protected:
75 using GPUROOTDump<Args...>::mTree;
76 template <typename... Names>
77 GPUROOTDump(const char* name1, Names... names) : GPUROOTDump<Args...>(names...)
78 {
79 mTree->Branch(name1, &mObj);
80 }
81
82 private:
83 T mObj;
84};
85
86template <class T>
88{
89 public:
90 static GPUROOTDump<T>& get(const char* name) // return always the same instance, identified by template
91 {
92 static GPUROOTDump<T> instance(name);
93 return instance;
94 }
95 static GPUROOTDump<T> getNew(const char* name) // return new individual instance
96 {
97 return GPUROOTDump<T>(name);
98 }
99
100 void write() override { mTree->Write(); }
101
102 void Fill(const T& o)
103 {
104 mObj = o;
105 mTree->Fill();
106 }
107
108 protected:
109 GPUROOTDump(const char* name1, const char* nameTree = nullptr)
110 {
111 if (nameTree == nullptr) {
112 nameTree = name1;
113 }
114 mTree = new TTree(nameTree, nameTree);
115 mTree->Branch(name1, &mObj);
116 }
117 TTree* mTree = nullptr;
118
119 private:
120 T mObj;
121};
122
123template <>
124class GPUROOTDump<TNtuple> : public GPUROOTDumpBase
125{
126 public:
127 static GPUROOTDump<TNtuple>& get(const char* name, const char* options)
128 {
129 static GPUROOTDump<TNtuple> instance(name, options);
130 return instance;
131 }
132 static GPUROOTDump<TNtuple> getNew(const char* name, const char* options)
133 {
134 return GPUROOTDump<TNtuple>(name, options);
135 }
136
137 void write() override { mNTuple->Write(); }
138
139 template <typename... Args>
140 void Fill(Args... args)
141 {
142 mNTuple->Fill(args...);
143 }
144
145 private:
146 GPUROOTDump(const char* name, const char* options)
147 {
148 mNTuple = new TNtuple(name, name, options);
149 }
150 TNtuple* mNTuple;
151};
152#else
153template <typename... Args>
154class GPUROOTDump
155{
156 public:
157 template <typename... Names>
158 GPUd() void Fill(Args... args) const
159 {
160 }
161 template <typename... Names>
162 GPUd() static GPUROOTDump<Args...>& get(Args... args)
163 {
164 return *(GPUROOTDump<Args...>*)(size_t)(1024); // Will never be used, return just some reference, which must not be nullptr by specification
165 }
166 template <typename... Names>
167 GPUd() static GPUROOTDump<Args...>& getNew(Args... args)
168 {
169 return *(GPUROOTDump<Args...>*)(size_t)(1024); // Will never be used, return just some reference, which must not be nullptr by specification
170 }
171};
172#endif
173} // namespace o2::gpu
174
175#endif
bool o
static GPUROOTDump< TNtuple > getNew(const char *name, const char *options)
static GPUROOTDump< TNtuple > & get(const char *name, const char *options)
void Fill(const T &o)
GPUROOTDump(const char *name1, const char *nameTree=nullptr)
static GPUROOTDump< T > & get(const char *name)
Definition GPUROOTDump.h:90
static GPUROOTDump< T > getNew(const char *name)
Definition GPUROOTDump.h:95
void Fill(const T &o, Args... args)
Definition GPUROOTDump.h:68
GPUROOTDump(const char *name1, Names... names)
Definition GPUROOTDump.h:77
static GPUROOTDump< T, Args... > getNew(const char *name1, Names... names)
Definition GPUROOTDump.h:64
static GPUROOTDump< T, Args... > & get(const char *name1, Names... names)
Definition GPUROOTDump.h:58
GLuint const GLchar * name
Definition glcorearb.h:781
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GPUd() const expr uint32_t MultivariatePolynomialHelper< Dim