VMC Version 2.2
Loading...
Searching...
No Matches
TMCTTreeWriter.h
Go to the documentation of this file.
1#ifndef ROOT_TMCTTreeWriter
2#define ROOT_TMCTTreeWriter
3
4//------------------------------------------------
5// The Geant4 Virtual Monte Carlo package
6// Copyright (C) 2013 - 2018 Ivana Hrivnacova
7// All rights reserved.
8//
9// For the licensing terms see geant4_vmc/LICENSE.
10// Contact: root-vmc@cern.ch
11//-------------------------------------------------
12
20
21#include "TMCVNtupleWriter.h"
22
23#include <TFile.h>
24#include <TTree.h>
25
27public:
28 TMCTTreeWriter(const char *storageName, TFile* file, Bool_t workerMode);
29 TMCTTreeWriter() = delete;
30 virtual ~TMCTTreeWriter() = default;
31
32 template <typename T>
33 void Register(const char *name, T *&obj);
34 void Register(const char *name, const char *className, void *objAddress);
35 void Register(const char *name, const char *className, const void *objAddress);
36
37 // Standard virtual interface for the rest of the lifecycle
38 virtual void CreateRNTuple() override {}
39 virtual void Fill() override;
40 virtual void WriteAll() override;
41 virtual void Close() override {}
42 virtual void ReadEvent(Int_t i) override;
43
44private:
45 TTree* fTree{nullptr};
46};
47
48#include <iostream>
49
50template <typename T>
51void TMCTTreeWriter::Register(const char *brname, T *&obj)
52{
53 if (!fTree) return;
54
55 fFile->cd();
56 if (!fTree->GetBranch(brname)) {
57 std::cout << "Create branch " << brname << std::endl;
58 fTree->Branch(brname, &obj, 32000, 99);
59 }
60 else
61 fTree->GetBranch(brname)->SetAddress(&obj);
62}
63
64#endif // ROOT_TMCTTreeWriter
Definition of the TMCVNtupleWriter class.
virtual void ReadEvent(Int_t i) override
virtual void CreateRNTuple() override
virtual ~TMCTTreeWriter()=default
TMCTTreeWriter()=delete
virtual void Close() override
virtual void WriteAll() override
void Register(const char *name, T *&obj)
TMCTTreeWriter(const char *storageName, TFile *file, Bool_t workerMode)
virtual void Fill() override
TMCVNtupleWriter(const char *storageName, TFile *file, Bool_t workerMode)