Jpp  master_rocky
the software that should make you happy
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  template<class T> class JRootCreateFlatTree : public std::false_type {};
25 
26  /**
27  * JTreeWriter object output.
28  *
29  * This class implements the JLANG::JObjectOutput interface.
30  */
31  template<class T>
33  public virtual JObjectOutput<T>
34  {
35  protected:
36  /**
37  * Default constructor.
38  */
40  out(new JTreeWriter<T,JRootCreateFlatTree<T>::value>(getTreeParameters<T>())),
41  del(true)
42  {}
43 
44 
45  /**
46  * Destructor.
47  */
49  {
50  if (del) {
51  delete out;
52  }
53  }
54 
55 
56  /**
57  * Set directory.
58  *
59  * \param dir pointer to directory
60  */
61  void SetDirectory(TDirectory* dir)
62  {
63  out->SetDirectory(dir);
64 
65  del = (dir == NULL);
66  }
67 
68 
70  bool del; // delete TTree on destruction
71 
72  public:
73  /**
74  * Get TreeWriter.
75  *
76  * \return TreeWriter
77  */
79  {
80  return *out;
81  }
82 
83 
84  /**
85  * Object output.
86  *
87  * \param object object
88  * \return true if OK; else false
89  */
90  virtual bool put(const T& object) override
91  {
92  return (out->Write(object) > 0);
93  }
94 
95 
96  /**
97  * Set circular buffer size.
98  *
99  * \param size number of entries
100  */
101  void SetCircular(Long64_t size)
102  {
103  out->SetCircular(size);
104  }
105 
106 
107  /**
108  * Reset TTree.
109  */
110  void Reset()
111  {
112  out->Reset();
113  }
114 
115  private:
120  };
121 
122 
123  /**
124  * Implementation of JTreeWriterObjectOutput for multiple data types.
125  *
126  * This class recursively implements the JLANG::JObjectOutput interface
127  * for all data types by deriving from:
128  * - JTreeWriterObjectOutput<JHead_t>; and
129  * - JTreeWriterObjectOutput<JTail_t>.
130  */
131  template<class JHead_t, class JTail_t>
132  class JTreeWriterObjectOutput< JTypeList<JHead_t, JTail_t> > :
133  public virtual JObjectOutput< JTypeList<JHead_t, JTail_t> >,
134  public JTreeWriterObjectOutput<JHead_t>,
135  public JTreeWriterObjectOutput<JTail_t>
136 
137  {
138  protected:
139  /**
140  * Set directory.
141  *
142  * \param dir pointer to directory
143  */
144  void SetDirectory(TDirectory* dir)
145  {
148  }
149 
150  public:
153 
154  /**
155  * Set circular buffer size.
156  *
157  * \param size number of entries
158  */
159  void SetCircular(Long64_t size)
160  {
163  }
164 
165 
166  /**
167  * Reset TTree.
168  */
169  void Reset()
170  {
173  }
174  };
175 
176 
177  /**
178  * Terminator class of recursive JTreeWriterObjectOutput class.
179  */
180  template<class JHead_t>
182  public JTreeWriterObjectOutput<JHead_t>
183  {};
184 }
185 
186 #endif
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JRECONSTRUCTION::JEvt >)
Get TTree parameters for given data type.
TTree writing for template data type.
Template interface of object output for single data type.
JTreeWriter< T > & getTreeWriter()
Get TreeWriter.
JTreeWriter< T, JRootCreateFlatTree< T >::value > * out
JTreeWriterObjectOutput()
Default constructor.
void SetDirectory(TDirectory *dir)
Set directory.
JTreeWriterObjectOutput(const JTreeWriterObjectOutput &)
virtual bool put(const T &object) override
Object output.
JTreeWriterObjectOutput & operator=(const JTreeWriterObjectOutput &)
void SetCircular(Long64_t size)
Set circular buffer size.
JTreeWriterObjectOutput(JTreeWriterObjectOutput &&)
JTreeWriterObjectOutput & operator=(JTreeWriterObjectOutput &&)
Auxiliary class for default template TTree writing.
Definition: JTreeWriter.hh:38
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
Type list.
Definition: JTypeList.hh:23