Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRootFileWriter.hh
Go to the documentation of this file.
1 #ifndef __JROOTFILEWRITER__
2 #define __JROOTFILEWRITER__
3 
4 #include "TFile.h"
5 
6 #include "JLang/JObjectOutput.hh"
7 #include "JLang/JTypeList.hh"
8 #include "JLang/JNullType.hh"
9 #include "JLang/JException.hh"
11 #include "JROOT/JTreeParameters.hh"
12 #include "JROOT/JRootFile.hh"
13 
14 /**
15  * \author mdejong
16  */
17 
18 
19 namespace JROOT {}
20 namespace JPP { using namespace JROOT; }
21 
22 namespace JROOT {
23 
26  using JLANG::JTypeList;
27  using JLANG::JNullType;
28 
29 
30  /**
31  * Write object to ROOT directory.
32  *
33  * \param dir pointer to directory
34  * \param object object
35  * \return true if OK; else false
36  */
37  inline bool putObject(TDirectory* dir, const TObject& object)
38  {
39  return (dir != NULL && dir->WriteTObject(&object) > 0);
40  }
41 
42 
43  /**
44  * Write object to ROOT directory.
45  *
46  * \param dir pointer to directory
47  * \param object object
48  * \return true if OK; else false
49  */
50  template<class T>
51  inline bool putObject(TDirectory* dir, const T& object)
52  {
53  return (dir != NULL && dir->WriteObject(&object, T::Class_Name()) > 0);
54  }
55 
56 
57  /**
58  * Template definition of ROOT object output.
59  */
62 
63 
64  /**
65  * Implementation of object output using TDirectory::WriteTObject method.
66  *
67  * This class implements the JLANG::JObjectOutput interface.
68  */
69  template<class T>
70  class JRootObjectOutput<T,false> :
71  public virtual JObjectOutput<T>
72  {
73  protected:
74  /**
75  * Default constructor.
76  */
78  directory(NULL)
79  {}
80 
81 
82  /**
83  * Set directory.
84  *
85  * \param dir pointer to directory
86  */
87  void SetDirectory(TDirectory* dir)
88  {
89  this->directory = dir;
90  }
91 
92 
93  TDirectory* directory;
94 
95  public:
96  /**
97  * Object output.
98  *
99  * \param object object
100  * \return true if OK; else false
101  */
102  virtual bool put(const T& object) override
103  {
104  if (directory != NULL)
105  return putObject(directory, object);
106  else
107  return false;
108  }
109  };
110 
111 
112  /**
113  * Implementation of object output using TTree.
114  *
115  * This class implements the JLANG::JObjectOutput interface.
116  */
117  template<class T>
118  class JRootObjectOutput<T,true> :
119  public JTreeWriterObjectOutput<T>
120  {};
121 
122 
123  /**
124  * Implementation of object output to ROOT file for single data type.
125  */
126  template<class T>
128  public JRootObjectOutput<T>
129  {};
130 
131 
132  /**
133  * Implementation of object output to ROOT file for multiple data types.
134  *
135  * This class recursively implements the JLANG::JObjectOutput interface
136  * for all data types by deriving from:
137  * - JRootFileObjectOutput<JHead_t>; and
138  * - JRootFileObjectOutput<JTail_t>.
139  */
140  template<class JHead_t, class JTail_t>
141  class JRootFileObjectOutput< JTypeList<JHead_t, JTail_t> > :
142  public JObjectOutput< JTypeList<JHead_t, JTail_t> >,
143  public JRootFileObjectOutput<JHead_t>,
144  public JRootFileObjectOutput<JTail_t>
145 
146  {
147  protected:
148  /**
149  * Set directory.
150  *
151  * \param dir pointer to directory
152  */
153  void SetDirectory(TDirectory* dir)
154  {
157  }
158  };
159 
160 
161  /**
162  * Terminator class of recursive JRootObjectOutput class.
163  */
164  template<class JHead_t>
166  public JRootFileObjectOutput<JHead_t>
167  {};
168 
169 
170  /**
171  * ROOT file object output.
172  *
173  * This class implements the JLANG::JAccessibleObjectOutput interface.
174  */
175  template<class T>
177  public JRootFileObjectOutput <T>,
178  public JAccessibleObjectOutput<T>,
179  public JRootOutputFile
180  {
181  public:
182  /**
183  * Default constructor.
184  */
188  {}
189 
190 
191  /**
192  * Open file.
193  *
194  * \param file_name file name
195  */
196  virtual void open(const char* file_name) override
197  {
198  JRootOutputFile::open(file_name);
199 
200  if (is_open()) {
201  this->SetDirectory(getFile());
202  }
203  }
204  };
205 }
206 
207 #endif
Exceptions.
Implementation of object output to ROOT file for single data type.
Template definition of ROOT object output.
bool putObject(TDirectory *dir, const TObject &object)
Write object to ROOT directory.
Definition: JRoot.hh:19
ROOT file object output.
void SetDirectory(TDirectory *dir)
Set directory.
JRootFileWriter()
Default constructor.
Type list.
Definition: JTypeList.hh:22
TFile * getFile() const
Get file.
Definition: JRootFile.hh:65
virtual void open(const char *file_name) override
Open file.
return result
Definition: JPolint.hh:727
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Auxiliary class for no type definition.
Definition: JNullType.hh:19
ROOT output file.
Definition: JRootFile.hh:147
JRootObjectOutput()
Default constructor.
virtual bool is_open() const =0
Check is device is open.
Template interface of object output for single data type.
then echo Creating output directory
Definition: JTuneHV.sh:83
virtual void open(const char *file_name) override
Open file.
Definition: JRootFile.hh:177
Interface for object output with named access.
virtual bool put(const T &object) override
Object output.