GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4HDF5Store.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 
15 #include "TGo4HDF5Store.h"
16 
17 #include "TFolder.h"
18 #include "TFile.h"
19 #include "TTree.h"
20 #include "TDataMember.h"
21 #include "TVirtualCollectionProxy.h"
22 #include "TBaseClass.h"
23 
24 #include "TGo4Log.h"
25 #include "TGo4EventElement.h"
26 #include "TGo4CompositeEvent.h"
28 
29 #include "TGo4Parameter.h"
30 #include "TGo4Condition.h"
31 #include "TGo4Fitter.h"
32 #include "TGo4HDF5StoreParameter.h"
33 
34 
36  TGo4EventStore("Go4 Default HDF5 Store"), TGo4HDF5Adapter()
37 
38 {
39  GO4TRACE((15,"TGo4HDF5Store::TGo4HDF5Store()", __LINE__, __FILE__));
40 }
41 
43  UInt_t flags) :
45 
46 {
47  GO4TRACE((15,"TGo4HDF5Store::TGo4HDF5Store(char*,...)", __LINE__, __FILE__));
48  OpenFile();
49 }
50 
51 
54 {
55  GO4TRACE((15,"TGo4HDF5Store::TGo4HDF5Store(TGo4HDF5StoreParameter* par)", __LINE__, __FILE__));
56  if (!par) {
57  TGo4Log::Error("TGo4HDF5Store::TGo4HDF5Store(.., TGo4HDF5StoreParameter* is not specified");
58  return;
59  }
60  SetName(par->GetName());
62  OpenFile();
63 }
64 
65 
67 {
68  GO4TRACE((15,"TGo4HDF5Store::~TGo4HDF5Store()", __LINE__, __FILE__));
69  //printf("TGo4HDF5Store::~TGo4HDF5Store()\n");
70  DeleteDataSet();
71  CloseFile();
72 }
73 
74 void TGo4HDF5Store::OpenFile(const char *)
75 {
76  TString buffer(GetName());
77  if (!strstr(buffer.Data(), fgcFILESUF))
78  buffer.Append(fgcFILESUF);
79 
80  try {
81  CloseFile();
82  fxFile = new H5::H5File(buffer.Data(), fiFlags);
83  if (fiFlags == H5F_ACC_TRUNC) {
84  TGo4Log::Info("TGo4HDF5Store: Open file %s RECREATE", buffer.Data());
85  } else if (fiFlags == H5F_ACC_RDWR) {
86  TGo4Log::Info("TGo4HDF5Store: Open file %s for UPDATE", buffer.Data());
87  } else if (fiFlags == H5F_ACC_EXCL) {
88  TGo4Log::Info("TGo4HDF5Store: Open file %s exclusively", buffer.Data());
89  } else {
90  TGo4Log::Info("TGo4HDF5Store: Open file %s with unsupported mode %d", buffer.Data(), fiFlags);
91  }
92 
93  } catch (H5::Exception &ex) {
94  TString msg = TString::Format("OpenFile with HDF5 exception in %s : %s\n", ex.getCFuncName(), ex.getCDetailMsg());
95  TGo4Log::Error("TGo4HDF5Store: %s", msg.Data());
96  throw TGo4EventStoreException(this, msg.Data());
97  }
98 }
99 
100 
102 {
103  if (fbDataSetExists)
104  return;
105  if (!event || !fxFile)
106  return;
107  try {
108 
109  BuildDataType(event);
111  fbDataSetExists = kTRUE;
112  }
113 
114  catch (H5::Exception &ex) {
115  TString msg =
116  TString::Format("BuildDataSet with HDF5 exception in %s : %s\n", ex.getCFuncName(), ex.getCDetailMsg());
117  TGo4Log::Error("TGo4HDF5Store: %s", msg.Data());
118  throw TGo4EventStoreException(this, msg.Data());
119  }
120 }
121 
123 {
124  GO4TRACE((12,"TGo4HDF5Store::Store(TGo4EventElement *)", __LINE__, __FILE__));
125 
126  fxEvent = event; // address of next event into event pointer
127  BuildDataSet(event);
128 
129  try {
130 
132  event); // this will recursively update all subpointers and properties of vector (hopefully...)
134 
135  } catch (H5::Exception &ex) {
136  TString msg = TString::Format("Store() with HDF5 exception in %s : %s\n", ex.getCFuncName(), ex.getCDetailMsg());
137  TGo4Log::Error("TGo4HDF5Store: %s", msg.Data());
138  throw TGo4EventStoreException(this, msg.Data());
139  }
140  return 0;
141 }
142 
144 {
145  WriteToStore(cali);
146  return 0;
147 }
148 
150 {
151  WriteToStore(conny);
152  return 0;
153 }
154 
156 {
157  WriteToStore(fitter);
158  return 0;
159 }
160 
161 Int_t TGo4HDF5Store::Store(TFolder *fold)
162 {
163  WriteToStore(fold);
164  return 0;
165 }
166 
168 {
169  if (!ob) return;
170  TGo4Log::Info("TGo4HDF5Store: WriteToStore not yet implemented for auxiliary objects of class %s (name:%s)\n",ob->Class()->GetName(), ob->GetName());
171 }
172 
Int_t Store(TGo4EventElement *event) override
static const char * fgcFILESUF
H5::H5File * fxFile
static void Info(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:294
UInt_t ConvertFileMode(Go4_H5_File_Flags flags)
TGo4EventElement * fxEvent
virtual void Write(hsize_t sequencenum, H5::H5File *file)
void WriteToStore(TNamed *ob)
virtual void DeleteDataSet()
Go4_H5_File_Flags GetHDF5Flags() const
static void Error(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:320
void OpenFile(const char *name=nullptr) override
virtual void BuildWriteDataset(H5::H5File *file)
void BuildDataType(TGo4EventElement *event, TGo4HDF5DataHandle *parent=nullptr, Int_t index=0)
virtual ~TGo4HDF5Store()
virtual void SetObjectPointer(void *memptr)
#define GO4TRACE(X)
Definition: TGo4Log.h:25
virtual void CloseFile()
void BuildDataSet(TGo4EventElement *event) override
string msg
Definition: go4init.py:11
TGo4HDF5DataHandle * fxHandle