Jpp  16.0.3
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTreeReader.hh
Go to the documentation of this file.
1 #ifndef __JROOT__JTREEREADER__
2 #define __JROOT__JTREEREADER__
3 
4 #include "TFile.h"
5 #include "TTree.h"
6 #include "TDictionary.h"
7 
8 #include "JROOT/JRootAddress.hh"
10 #include "JLang/JPointer.hh"
11 
12 
13 /**
14  * \file
15  * TTree reading for template data type.
16  * \author mdejong
17  */
18 namespace JROOT {}
19 namespace JPP { using namespace JROOT; }
20 
21 namespace JROOT {
22 
23  using JLANG::JPointer;
24 
25 
26  /**
27  * Interface for TTree reading.
28  */
30  public JPointer<TTree>
31  {
32  /**
33  * Load TTree from given file.
34  *
35  * \param file pointer to file
36  * \return true when TTree correctly loaded; else false
37  */
38  virtual bool load(TFile* file) = 0;
39 
40 
41  /**
42  * Get ROOT dictionary.
43  *
44  * \return dictionary.
45  */
46  virtual const TDictionary* getDictionary() = 0;
47  };
48 
49 
50  /**
51  * Auxiliary class for template TTree reading.
52  */
53  template<class T>
54  class JTreeReader :
55  public JAbstractTreeReader,
56  public JTreeParameters,
57  public JRootAddress<T>
58  {
59  public:
60  /**
61  * Constructor.
62  *
63  * Note that the default TTree parameters are obtained using method JROOT::getTreeParameters.
64  *
65  * \param parameters parameters of TTree
66  */
67  JTreeReader(const JTreeParameters& parameters = JROOT::getTreeParameters<T>()) :
69  {}
70 
71 
72  /**
73  * Load TTree from given file.
74  *
75  * This methods releases the pending memory allocated from previous data reading.
76  *
77  * \param file pointer to file
78  * \return true when TTree correctly loaded; else false
79  */
80  virtual bool load(TFile* file) override
81  {
82  this->release();
83 
84  if (file != NULL) {
85 
86  this->set(dynamic_cast<TTree*>(file->Get(this->getTreeName())));
87 
88  if (this->is_valid()) {
89 
90  this->get()->SetBranchAddress(this->getBranchName(), &this->address);
91 
92  return true;
93  }
94  }
95 
96  return false;
97  }
98 
99 
100  /**
101  * Get ROOT dictionary.
102  *
103  * \return dictionary.
104  */
105  virtual const TDictionary* getDictionary() override
106  {
107  return TDictionary::GetDictionary(T::Class_Name());
108  }
109  };
110 }
111 
112 #endif
virtual const TDictionary * getDictionary()=0
Get ROOT dictionary.
Interface for TTree reading.
Definition: JTreeReader.hh:29
then set_variable PMT_FILE set_variable DAQ_FILE set_variable OUTPUT_FILE set_variable DETECTOR else fatal Wrong number of arguments fi set_variable RUNBYRUN file
virtual const TDictionary * getDictionary() override
Get ROOT dictionary.
Definition: JTreeReader.hh:105
void release()
Release memory.
Definition: JRootAddress.hh:42
const TString & getBranchName() const
Get TBranch name.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
virtual bool load(TFile *file)=0
Load TTree from given file.
bool is_valid() const
Check validity of pointer.
Auxiliary classd for address handling within TTree or TChain.
Definition: JRootAddress.hh:18
Template implementation of class that holds pointer to object(s).
Definition: JPointer.hh:22
JTreeReader(const JTreeParameters &parameters=JROOT::getTreeParameters< T >())
Constructor.
Definition: JTreeReader.hh:67
Auxiliary class for template TTree reading.
Definition: JTreeReader.hh:54
Data structure for TTree parameters.
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
virtual bool load(TFile *file) override
Load TTree from given file.
Definition: JTreeReader.hh:80