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