Jpp  18.2.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
39  del(true)
40  {}
41 
42 
43  /**
44  * Destructor.
45  */
47  {
48  if (del) {
49  delete out;
50  }
51  }
52 
53 
54  /**
55  * Set directory.
56  *
57  * \param dir pointer to directory
58  */
59  void SetDirectory(TDirectory* dir)
60  {
61  out->SetDirectory(dir);
62 
63  del = (dir == NULL);
64  }
65 
66 
68  bool del; // delete TTree on destruction
69 
70  public:
71  /**
72  * Get TreeWriter.
73  *
74  * \return TreeWriter
75  */
77  {
78  return *out;
79  }
80 
81 
82  /**
83  * Object output.
84  *
85  * \param object object
86  * \return true if OK; else false
87  */
88  virtual bool put(const T& object) override
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  private:
118  };
119 
120 
121  /**
122  * Implementation of JTreeWriterObjectOutput for multiple data types.
123  *
124  * This class recursively implements the JLANG::JObjectOutput interface
125  * for all data types by deriving from:
126  * - JTreeWriterObjectOutput<JHead_t>; and
127  * - JTreeWriterObjectOutput<JTail_t>.
128  */
129  template<class JHead_t, class JTail_t>
130  class JTreeWriterObjectOutput< JTypeList<JHead_t, JTail_t> > :
131  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
132  public JTreeWriterObjectOutput<JHead_t>,
133  public JTreeWriterObjectOutput<JTail_t>
134 
135  {
136  protected:
137  /**
138  * Set directory.
139  *
140  * \param dir pointer to directory
141  */
142  void SetDirectory(TDirectory* dir)
143  {
146  }
147 
148  public:
151 
152  /**
153  * Set circular buffer size.
154  *
155  * \param size number of entries
156  */
157  void SetCircular(Long64_t size)
158  {
161  }
162 
163 
164  /**
165  * Reset TTree.
166  */
167  void Reset()
168  {
171  }
172  };
173 
174 
175  /**
176  * Terminator class of recursive JTreeWriterObjectOutput class.
177  */
178  template<class JHead_t>
180  public JTreeWriterObjectOutput<JHead_t>
181  {};
182 }
183 
184 #endif
Auxiliary class for template TTree writing.
Definition: JTreeWriter.hh:31
Type list.
Definition: JTypeList.hh:22
void SetDirectory(TDirectory *dir)
Set directory.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for no type definition.
Definition: JNullType.hh:19
virtual bool put(const T &object) override
Object output.
void SetCircular(Long64_t size)
Set circular buffer size.
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JRECONSTRUCTION::JEvt >)
Get TTree parameters for given data type.
JTreeWriter< T > & getTreeWriter()
Get TreeWriter.
Template interface of object output for single data type.
TTree writing for template data type.
JTreeWriterObjectOutput & operator=(const JTreeWriterObjectOutput &)
JTreeWriterObjectOutput()
Default constructor.