Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JTreeReader.hh
Go to the documentation of this file.
1#ifndef __JROOT__JTREEREADER__
2#define __JROOT__JTREEREADER__
3
4#pragma GCC diagnostic push
5#pragma GCC diagnostic ignored "-Wall"
6#include "TFile.h"
7#include "TTree.h"
8#include "TDictionary.h"
9#pragma GCC diagnostic pop
10
11#include "JROOT/JRootAddress.hh"
13#include "JLang/JPointer.hh"
15
16/**
17 * \file
18 * TTree reading for template data type.
19 * \author mdejong
20 */
21namespace JROOT {}
22namespace JPP { using namespace JROOT; }
23
24namespace JROOT {
25
26 using JLANG::JPointer;
27
28
29 /**
30 * Interface for TTree reading.
31 */
33 public JPointer<TTree>
34 {
35 /**
36 * Load TTree from given file.
37 *
38 * \param file pointer to file
39 * \return true when TTree correctly loaded; else false
40 */
41 virtual bool load(TFile* file) = 0;
42
43
44 /**
45 * Get ROOT dictionary.
46 *
47 * \return dictionary.
48 */
49 virtual const TDictionary* getDictionary() = 0;
50 };
51
52
53 /**
54 * Auxiliary class for template TTree reading.
55 */
56 template<class T>
57 class JTreeReader :
59 public JTreeParameters,
60 public JTreeBranchAddresses<T>
61 {
62 public:
63 /**
64 * Constructor.
65 *
66 * Note that the default TTree parameters are obtained using method JROOT::getTreeParameters.
67 *
68 * \param parameters parameters of TTree
69 */
71 JTreeParameters(parameters)
72 {}
73
74
75 /**
76 * Load TTree from given file.
77 *
78 * This methods releases the pending memory allocated from previous data reading.
79 *
80 * \param file pointer to file
81 * \return true when TTree correctly loaded; else false
82 */
83 virtual bool load(TFile* file) override
84 {
85 this->release();
86
87 if (file != NULL) {
88
89 this->set(dynamic_cast<TTree*>(file->Get(this->getTreeName())));
90
91 if (this->is_valid()) {
92
93 this->setBranchAddress(*(this->get()));
94
95 return true;
96 }
97 }
98
99 return false;
100 }
101
102
103 /**
104 * Get ROOT dictionary.
105 *
106 * \return dictionary.
107 */
108 virtual const TDictionary* getDictionary() override
109 {
110 return TDictionary::GetDictionary(T::Class_Name());
111 }
112 };
113}
114
115#endif
bool is_valid() const
Check validity of pointer.
Template implementation of class that holds pointer to object(s).
Definition JPointer.hh:24
virtual void set(JClass_t *p) override
Set pointer.
Definition JPointer.hh:75
virtual JClass_t * get() const override
Get pointer.
Definition JPointer.hh:64
Class responsible to setup TTree branch addresses for reading objects of type T.
Data structure for TTree parameters.
Auxiliary class for template TTree reading.
virtual const TDictionary * getDictionary() override
Get ROOT dictionary.
JTreeReader(const JTreeParameters &parameters=JROOT::getTreeParameters< T >())
Constructor.
virtual bool load(TFile *file) override
Load TTree from given file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
JTreeParameters & getTreeParameters()
Template definition for method returning TTree parameters.
Interface for TTree reading.
virtual bool load(TFile *file)=0
Load TTree from given file.
virtual const TDictionary * getDictionary()=0
Get ROOT dictionary.
void release()
Release memory.