|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// \file GPUROOTDump.h |
| 12 | +/// \author David Rohr |
| 13 | + |
| 14 | +#ifndef GPUROOTDUMP_H |
| 15 | +#define GPUROOTDUMP_H |
| 16 | + |
| 17 | +#include "GPUROOTDumpCore.h" |
| 18 | + |
| 19 | +#if !defined(GPUCA_NO_ROOT) && !defined(GPUCA_GPUCODE) |
| 20 | +#include <TTree.h> |
| 21 | +#include <TNtuple.h> |
| 22 | +#include <memory> |
| 23 | +#include <stdexcept> |
| 24 | +#endif |
| 25 | + |
| 26 | +namespace GPUCA_NAMESPACE |
| 27 | +{ |
| 28 | +namespace gpu |
| 29 | +{ |
| 30 | +#if !defined(GPUCA_NO_ROOT) && !defined(GPUCA_GPUCODE) |
| 31 | +namespace |
| 32 | +{ |
| 33 | +template <class S> |
| 34 | +struct internal_Branch { |
| 35 | + template <typename... Args> |
| 36 | + static void Branch(S* p, Args... args) |
| 37 | + { |
| 38 | + } |
| 39 | +}; |
| 40 | +template <> |
| 41 | +struct internal_Branch<TTree> { |
| 42 | + template <typename... Args> |
| 43 | + static void Branch(TTree* p, Args... args) |
| 44 | + { |
| 45 | + p->Branch(args...); |
| 46 | + } |
| 47 | +}; |
| 48 | +} // namespace |
| 49 | + |
| 50 | +template <class T> |
| 51 | +class GPUROOTDump : public GPUROOTDumpBase |
| 52 | +{ |
| 53 | + public: |
| 54 | + static GPUROOTDump<T>& get(const char* name) |
| 55 | + { |
| 56 | + static GPUROOTDump<T> instance(name); |
| 57 | + } |
| 58 | + GPUROOTDump(const char* name) |
| 59 | + { |
| 60 | + mTree = new TTree(name, name); |
| 61 | + mTree->Branch(name, &mObj); |
| 62 | + } |
| 63 | + |
| 64 | + void write() override { mTree->Write(); } |
| 65 | + |
| 66 | + void Fill(const T& o) |
| 67 | + { |
| 68 | + mObj = o; |
| 69 | + mTree->Fill(); |
| 70 | + } |
| 71 | + |
| 72 | + private: |
| 73 | + TTree* mTree = nullptr; |
| 74 | + T mObj; |
| 75 | +}; |
| 76 | + |
| 77 | +template <> |
| 78 | +class GPUROOTDump<TNtuple> : public GPUROOTDumpBase |
| 79 | +{ |
| 80 | + public: |
| 81 | + static GPUROOTDump<TNtuple>& get(const char* name, const char* options) |
| 82 | + { |
| 83 | + static GPUROOTDump<TNtuple> instance(name, options); |
| 84 | + return instance; |
| 85 | + } |
| 86 | + GPUROOTDump(const char* name, const char* options) |
| 87 | + { |
| 88 | + mNTuple = new TNtuple(name, name, options); |
| 89 | + } |
| 90 | + |
| 91 | + void write() override { mNTuple->Write(); } |
| 92 | + |
| 93 | + template <typename... Args> |
| 94 | + void Fill(Args... args) |
| 95 | + { |
| 96 | + mNTuple->Fill(args...); |
| 97 | + } |
| 98 | + |
| 99 | + private: |
| 100 | + TNtuple* mNTuple; |
| 101 | +}; |
| 102 | +#else |
| 103 | +template <class T> |
| 104 | +class GPUROOTDump |
| 105 | +{ |
| 106 | + public: |
| 107 | + GPUROOTDump() = delete; |
| 108 | +}; |
| 109 | +#endif |
| 110 | +} // namespace gpu |
| 111 | +} // namespace GPUCA_NAMESPACE |
| 112 | + |
| 113 | +#endif |
0 commit comments