Jpp  18.6.0-rc.1
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 #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"
12 #include "JROOT/JTreeParameters.hh"
13 #include "JLang/JPointer.hh"
14 
15 
16 /**
17  * \file
18  * TTree reading for template data type.
19  * \author mdejong
20  */
21 namespace JROOT {}
22 namespace JPP { using namespace JROOT; }
23 
24 namespace 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 :
58  public JAbstractTreeReader,
59  public JTreeParameters,
60  public JRootAddress<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  */
70  JTreeReader(const JTreeParameters& parameters = JROOT::getTreeParameters<T>()) :
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->get()->SetBranchAddress(this->getBranchName(), &this->address);
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
virtual const TDictionary * getDictionary()=0
Get ROOT dictionary.
Interface for TTree reading.
Definition: JTreeReader.hh:32
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
Definition: JDataQuality.sh:19
virtual const TDictionary * getDictionary() override
Get ROOT dictionary.
Definition: JTreeReader.hh:108
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:70
Auxiliary class for template TTree reading.
Definition: JTreeReader.hh:57
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:83