Jpp
JTreeWriterObjectOutput.hh
Go to the documentation of this file.
1 #ifndef __JROOT__JTREEWRITEROBJECTOUTPUT__
2 #define __JROOT__JTREEWRITEROBJECTOUTPUT__
3 
4 #include "JLang/JTypeList.hh"
5 #include "JLang/JNullType.hh"
6 #include "JLang/JObjectOutput.hh"
7 #include "JROOT/JTreeWriter.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JROOT {}
15 namespace JPP { using namespace JROOT; }
16 
17 namespace JROOT {
18 
20  using JLANG::JTypeList;
21  using JLANG::JNullType;
22 
23 
24  /**
25  * JTreeWriter object output.
26  *
27  * This class implements the JLANG::JObjectOutput interface.
28  */
29  template<class T>
31  public virtual JObjectOutput<T>
32  {
33  protected:
34  /**
35  * Default constructor.
36  */
38  out(new JTreeWriter<T>(getTreeParameters<T>())),
39  del(true)
40  {}
41 
42 
43  /**
44  * Destructor.
45  */
47  {
48  if (del) {
49  delete out;
50  }
51  }
52 
53 
54  /**
55  * Get TreeWriter.
56  *
57  * \return TreeWriter
58  */
60  {
61  return *out;
62  }
63 
64 
65  /**
66  * Set directory.
67  *
68  * \param dir pointer to directory
69  */
70  void SetDirectory(TDirectory* dir)
71  {
72  out->SetDirectory(dir);
73 
74  del = (dir == NULL);
75  }
76 
77 
79  bool del; // delete TTree on destruction
80 
81  public:
82  /**
83  * Object output.
84  *
85  * \param object object
86  * \return true if OK; else false
87  */
88  virtual bool put(const T& object)
89  {
90  return (out->Write(object) > 0);
91  }
92 
93 
94  /**
95  * Set circular buffer size.
96  *
97  * \param size number of entries
98  */
99  void SetCircular(Long64_t size)
100  {
101  out->SetCircular(size);
102  }
103 
104 
105  /**
106  * Reset TTree.
107  */
108  void Reset()
109  {
110  out->Reset();
111  }
112  };
113 
114 
115  /**
116  * Implementation of JTreeWriterObjectOutput for multiple data types.
117  *
118  * This class recursively implements the JLANG::JObjectOutput interface
119  * for all data types by deriving from:
120  * - JTreeWriterObjectOutput<JHead_t>; and
121  * - JTreeWriterObjectOutput<JTail_t>.
122  */
123  template<class JHead_t, class JTail_t>
124  class JTreeWriterObjectOutput< JTypeList<JHead_t, JTail_t> > :
125  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
126  public JTreeWriterObjectOutput<JHead_t>,
127  public JTreeWriterObjectOutput<JTail_t>
128 
129  {
130  protected:
131  /**
132  * Set directory.
133  *
134  * \param dir pointer to directory
135  */
136  void SetDirectory(TDirectory* dir)
137  {
140  }
141 
142  public:
145 
146  /**
147  * Set circular buffer size.
148  *
149  * \param size number of entries
150  */
151  void SetCircular(Long64_t size)
152  {
155  }
156 
157 
158  /**
159  * Reset TTree.
160  */
161  void Reset()
162  {
165  }
166  };
167 
168 
169  /**
170  * Terminator class of recursive JTreeWriterObjectOutput class.
171  */
172  template<class JHead_t>
174  public JTreeWriterObjectOutput<JHead_t>
175  {};
176 }
177 
178 #endif
JROOT::JTreeWriterObjectOutput::del
bool del
Definition: JTreeWriterObjectOutput.hh:79
JROOT
Auxiliary classes and methods for ROOT I/O.
Definition: JAbstractStreamer.hh:13
JROOT::JTreeWriterObjectOutput::SetDirectory
void SetDirectory(TDirectory *dir)
Set directory.
Definition: JTreeWriterObjectOutput.hh:70
JLANG::JNullType
Auxiliary class for no type definition.
Definition: JNullType.hh:19
JROOT::JTreeWriterObjectOutput::~JTreeWriterObjectOutput
~JTreeWriterObjectOutput()
Destructor.
Definition: JTreeWriterObjectOutput.hh:46
JLANG::JObjectOutput
Forward declarations for definitions of I/O redirect and pipe operators.
Definition: JObjectIterator.hh:31
JROOT::JTreeWriterObjectOutput::SetCircular
void SetCircular(Long64_t size)
Set circular buffer size.
Definition: JTreeWriterObjectOutput.hh:99
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JROOT::JTreeWriterObjectOutput::JTreeWriterObjectOutput
JTreeWriterObjectOutput()
Default constructor.
Definition: JTreeWriterObjectOutput.hh:37
JROOT::JTreeWriterObjectOutput::put
virtual bool put(const T &object)
Object output.
Definition: JTreeWriterObjectOutput.hh:88
JROOT::JTreeWriterObjectOutput< JTypeList< JHead_t, JTail_t > >::SetCircular
void SetCircular(Long64_t size)
Set circular buffer size.
Definition: JTreeWriterObjectOutput.hh:151
JLANG::JTypeList
Type list.
Definition: JTypeList.hh:22
JROOT::JTreeWriterObjectOutput< JTypeList< JHead_t, JTail_t > >::SetDirectory
void SetDirectory(TDirectory *dir)
Set directory.
Definition: JTreeWriterObjectOutput.hh:136
JROOT::JTreeWriterObjectOutput::getTreeWriter
JTreeWriter< T > & getTreeWriter()
Get TreeWriter.
Definition: JTreeWriterObjectOutput.hh:59
JROOT::JTreeWriterObjectOutput< JTypeList< JHead_t, JTail_t > >::Reset
void Reset()
Reset TTree.
Definition: JTreeWriterObjectOutput.hh:161
JROOT::JTreeWriterObjectOutput
JTreeWriter object output.
Definition: JTreeWriterObjectOutput.hh:30
JROOT::JTreeWriterObjectOutput::Reset
void Reset()
Reset TTree.
Definition: JTreeWriterObjectOutput.hh:108
JROOT::JTreeWriter
Auxiliary class for template TTree writing.
Definition: JTreeWriter.hh:28
JTreeWriter.hh
JTypeList.hh
JNullType.hh
JObjectOutput.hh
JROOT::JTreeWriterObjectOutput::out
JTreeWriter< T > * out
Definition: JTreeWriterObjectOutput.hh:78
getTreeParameters
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JFIT::JEvt >)
Get TTree parameters for given data type.
Definition: JEvt.hh:357