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
JTreeWriter.hh
Go to the documentation of this file.
1 #ifndef __JROOT__JTREEWRITER__
2 #define __JROOT__JTREEWRITER__
3 
4 #pragma GCC diagnostic push
5 #pragma GCC diagnostic ignored "-Wall"
6 #include "TTree.h"
7 #include "TBranch.h"
8 #pragma GCC diagnostic pop
9 
10 #include "JROOT/JTreeParameters.hh"
11 #include "JIO/JSerialisable.hh"
12 
13 
14 /**
15  * \file
16  * TTree writing for template data type.
17  * \author mdejong
18  */
19 namespace JROOT {}
20 namespace JPP { using namespace JROOT; }
21 
22 namespace JROOT {
23 
24  using JIO::JReader;
25 
26 
27  /**
28  * Auxiliary class for template TTree writing.
29  */
30  template<class T>
31  class JTreeWriter :
32  public virtual TTree,
33  public JTreeParameters
34  {
35  public:
36  /**
37  * Constructor.
38  *
39  * Note that the default TTree parameters are obtained using method JROOT::getTreeParameters.
40  *
41  * \param parameters parameters of TTree
42  */
43  JTreeWriter(const JTreeParameters& parameters = JROOT::getTreeParameters<T>()) :
45  address(NULL)
46  {
47  SetNameTitle(this->getTreeName(), this->getTreeTitle());
48 
49  branch = Branch(this->getBranchName(),
50  T::Class_Name(),
51  &address,
52  this->getBasketSize(),
53  this->getSplitLevel());
54 
55  branch->SetCompressionLevel(this->getCompressionLevel());
56  }
57 
58 
59  /**
60  * Get the pointer to the unique TBranch belonging this TTree.
61  *
62  * \return pointer to TBranch
63  */
64  const TBranch* GetBranch() const
65  {
66  return branch;
67  }
68 
69 
70  /**
71  * Data object output equivalent of TTree::Fill().
72  *
73  * \param object data object
74  * \return as TTree::Fill
75  */
76  Int_t Write(const T& object)
77  {
78  address = &object;
79 
80  return this->Fill();
81  }
82 
83  protected:
84  using TTree::GetBranch;
85  using TTree::Write;
86 
87  private:
88  TBranch* branch; //!< Pointer to unique branch belonging to this TTree.
89  const T* address; //!< Pointer to unique object belonging to this TTree.
90  };
91 
92 
93  /**
94  * Interface for template TTree writing and copying.
95  */
97  public virtual TTree
98  {
99  /**
100  * Copy data.
101  *
102  * \param in binary reader
103  */
104  virtual Int_t copy(JReader& in) = 0;
105  };
106 
107 
108  /**
109  * Implementation for template TTree writing and copying.
110  * This class implements the JTreeCopyWriter interface.
111  */
112  template<class T>
114  public JTreeWriter<T>,
116  {
117  protected:
118  /**
119  * Constructor.
120  *
121  * \param tree parameters of TTree
122  */
124  JTreeWriter<T>(tree)
125  {}
126 
127 
128  /**
129  * Hide copy constructor.
130  *
131  * \param writer TTree writer object
132  */
133  JTreeCopyWriter(const JTreeCopyWriter<T>& writer);
134 
135 
136  public:
137  /**
138  * Get reference to unique instance of this class object.
139  *
140  * \return reference to this class object
141  */
143  {
144  static JTreeCopyWriter<T> writer(getTreeParameters<T>());
145 
146  return writer;
147  }
148 
149 
150  /**
151  * Copy data.
152  *
153  * \param in binary reader
154  */
155  virtual Int_t copy(JReader& in) override
156  {
157  in >> object;
158 
159  return static_cast<JTreeWriter<T>&>(*this).Write(object);
160  }
161 
162 
163  protected:
165  };
166 
167 
168  /**
169  * Get the TTree writer and copy for this type of object.
170  *
171  * \return TTree writer and copy for this type of object
172  */
173  template <class T>
175  {
177  }
178 }
179 
180 #endif
const TBranch * GetBranch() const
Get the pointer to the unique TBranch belonging this TTree.
Definition: JTreeWriter.hh:64
const TString & getBranchName() const
Get TBranch name.
const T * address
Pointer to unique object belonging to this TTree.
Definition: JTreeWriter.hh:89
Auxiliary class for template TTree writing.
Definition: JTreeWriter.hh:31
*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
JTreeWriter(const JTreeParameters &parameters=JROOT::getTreeParameters< T >())
Constructor.
Definition: JTreeWriter.hh:43
int getCompressionLevel() const
Get compression level.
int getSplitLevel() const
Get split level.
TBranch * branch
Pointer to unique branch belonging to this TTree.
Definition: JTreeWriter.hh:88
static JTreeCopyWriter< T > & getInstance()
Get reference to unique instance of this class object.
Definition: JTreeWriter.hh:142
const TString & getTreeTitle() const
Get TTree title.
Interface for template TTree writing and copying.
Definition: JTreeWriter.hh:96
JTreeCopyWriter(const JTreeParameters &tree)
Constructor.
Definition: JTreeWriter.hh:123
Int_t Write(const T &object)
Data object output equivalent of TTree::Fill().
Definition: JTreeWriter.hh:76
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Interface for binary input.
Implementation for template TTree writing and copying.
Definition: JTreeWriter.hh:113
int getBasketSize() const
Get basket size.
Data structure for TTree parameters.
virtual Int_t copy(JReader &in)=0
Copy data.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
const TString & getTreeName() const
Get TTree name.
JTreeCopyWriter< T > & getTreeCopyWriter()
Get the TTree writer and copy for this type of object.
Definition: JTreeWriter.hh:174
virtual Int_t copy(JReader &in) override
Copy data.
Definition: JTreeWriter.hh:155