Jpp
 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/JObjectOutput.hh"
5 #include "JROOT/JTreeWriter.hh"
6 
7 
8 /**
9  * \author mdejong
10  */
11 
12 namespace JROOT {}
13 namespace JPP { using namespace JROOT; }
14 
15 namespace JROOT {
16 
18 
19 
20  /**
21  * JTreeWriter object output.
22  *
23  * This class implements the JLANG::JObjectOutput interface.
24  */
25  template<class T>
27  public virtual JObjectOutput<T>
28  {
29  protected:
30  /**
31  * Default constructor.
32  */
34  out(new JTreeWriter<T>(getTreeParameters<T>())),
35  del(true)
36  {}
37 
38 
39  /**
40  * Destructor.
41  */
43  {
44  if (del) {
45  delete out;
46  }
47  }
48 
49 
50  /**
51  * Get TreeWriter.
52  *
53  * \return TreeWriter
54  */
56  {
57  return *out;
58  }
59 
60 
61  /**
62  * Set directory.
63  *
64  * \param dir pointer to directory
65  */
66  void SetDirectory(TDirectory* dir)
67  {
68  out->SetDirectory(dir);
69 
70  del = (dir == NULL);
71  }
72 
73 
75  bool del; // delete TTree on destruction
76 
77  public:
78  /**
79  * Object output.
80  *
81  * \param object object
82  * \return true if OK; else false
83  */
84  virtual bool put(const T& object)
85  {
86  return (out->Write(object) > 0);
87  }
88  };
89 }
90 
91 #endif
Auxiliary class for template TTree writing.
Definition: JTreeWriter.hh:28
void SetDirectory(TDirectory *dir)
Set directory.
JROOT::JTreeParameters getTreeParameters(JLANG::JType< JFIT::JEvt >)
Get TTree parameters for given data type.
Definition: JEvt.hh:367
JTreeWriter< T > & getTreeWriter()
Get TreeWriter.
virtual bool put(const T &object)
Object output.
Forward declarations for definitions of I/O redirect and pipe operators.
TTree writing for template data type.
JTreeWriterObjectOutput()
Default constructor.