Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JTreeRecorder.hh
Go to the documentation of this file.
1#ifndef __JSUPPORT_JTREERECORDER__
2#define __JSUPPORT_JTREERECORDER__
3
6#include "JROOT/JRootFile.hh"
7
8/**
9 * \author mdejong
10 */
11
12namespace JSUPPORT {}
13namespace JPP { using namespace JSUPPORT; }
14
15namespace JSUPPORT {
16
20
21
22 /**
23 * ROOT TTree object output.
24 *
25 * This class implements the JLANG::JAccessibleObjectOutput interface.
26 */
27 template<class T>
31 public JRootOutputFile
32 {
33 public:
34 /**
35 * Default constructor.
36 */
39
40
41 /**
42 * Constructor.
43 *
44 * \param file_name file name
45 */
46 JTreeRecorder(const char* file_name)
47 {
48 open(file_name);
49 }
50
51
52 /**
53 * Open file.
54 *
55 * \param file_name file name
56 */
57 virtual void open(const char* file_name) override
58 {
59 JRootOutputFile::open(file_name);
60
61 if (is_open()) {
62 this->SetDirectory(getFile());
63 }
64 }
65
66
67 /**
68 * Close file.
69 */
70 virtual void close() override
71 {
72 // Write objects in memory.
73
74 if (is_open()) {
75 getFile()->Write();
76 }
77
78 // Detach TTree from TDirectory to avoid deletion of TTree.
79
80 this->SetDirectory(0);
81
82 // Close file.
83
84 if (is_open()) {
85 getFile()->Close();
86 }
87
88 reset();
89
90 // Reset TTree.
91
92 this->Reset();
93 }
94 };
95}
96
97#endif
Interface for object output with named access.
virtual bool is_open() const =0
Check is device is open.
virtual void reset() override
Reset pointer.
Definition JStorage.hh:42
TFile * getFile() const
Get file.
Definition JRootFile.hh:66
ROOT output file.
Definition JRootFile.hh:198
virtual void open(const char *file_name) override
Open file.
Definition JRootFile.hh:237
void SetDirectory(TDirectory *dir)
Set directory.
ROOT TTree object output.
JTreeRecorder()
Default constructor.
virtual void open(const char *file_name) override
Open file.
virtual void close() override
Close file.
JTreeRecorder(const char *file_name)
Constructor.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Support classes and methods for experiment specific I/O.