GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HDF5Store.cxx
Go to the documentation of this file.
1 // $Id: TGo4HDF5Store.cxx 2810 2020-05-13 12:22:03Z linev $
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 
35 
37  TGo4EventStore("Go4 Default HDF5 Store"), TGo4HDF5Adapter()
38 
39 {
40  GO4TRACE((15,"TGo4HDF5Store::TGo4HDF5Store()", __LINE__, __FILE__));
41 
42  //printf("TGo4HDF5Store::TGo4HDF5Store() default ctor\n");
43  // public default ctor for streamer
44 
45 }
46 
48  UInt_t flags) :
50 
51 {
52 
53 
54  GO4TRACE((15,"TGo4HDF5Store::TGo4HDF5Store(char*,...)", __LINE__, __FILE__));
55  //printf("TGo4HDF5Store::TGo4HDF5Store(char*,...)\n");
56  OpenFile();
57 }
58 
59 
62 {
63  GO4TRACE((15,"TGo4HDF5Store::TGo4HDF5Store(TGo4HDF5StoreParameter* par)", __LINE__, __FILE__));
64  //printf("TGo4HDF5Store::TGo4HDF5Store(TGo4HDF5StoreParameter* par)\n");
65  if (par==0) {
66  TGo4Log::Error("TGo4HDF5Store::TGo4HDF5Store(.., TGo4HDF5StoreParameter* is not specified");
67  return;
68  }
69  SetName(par->GetName());
71  OpenFile();
72 }
73 
74 
76 {
77  GO4TRACE((15,"TGo4HDF5Store::~TGo4HDF5Store()", __LINE__, __FILE__));
78  //printf("TGo4HDF5Store::~TGo4HDF5Store()\n");
79  DeleteDataSet();
80  CloseFile();
81 }
82 
83 void TGo4HDF5Store::OpenFile(const char*)
84 {
85  TString buffer(GetName());
86  if (strstr(buffer.Data(), fgcFILESUF) == 0)
87  buffer.Append(fgcFILESUF);
88 
89 try{
90  CloseFile();
91  fxFile = new H5::H5File(buffer.Data(), fiFlags);
92  if (fiFlags == H5F_ACC_TRUNC)
93  {
94  TGo4Log::Info("TGo4HDF5Store: Open file %s RECREATE", buffer.Data());
95  }
96  else if (fiFlags == H5F_ACC_RDWR)
97  {
98  TGo4Log::Info("TGo4HDF5Store: Open file %s for UPDATE", buffer.Data());
99  }
100  else if (fiFlags == H5F_ACC_EXCL)
101  {
102  TGo4Log::Info("TGo4HDF5Store: Open file %s exclusively", buffer.Data());
103  }
104  else
105  {
106  TGo4Log::Info("TGo4HDF5Store: Open file %s with unsupported mode %d", buffer.Data(),fiFlags);
107 
108  }
109 
110 }
111 catch(H5::Exception& ex)
112 {
113  TString msg= TString::Format( "OpenFile with HDF5 exception in %s : %s\n", ex. getCFuncName (), ex.getCDetailMsg ());
114  TGo4Log::Error("TGo4HDF5Store: %s", msg.Data());
115  throw TGo4EventStoreException(this, msg.Data());
116 }
117 
118 
119 }
120 
121 
122 
124 {
125  if(fbDataSetExists) return;
126  if (event==0 || fxFile==0) return;
127  try{
128 
129  BuildDataType(event);
131  fbDataSetExists=kTRUE;
132  }
133 
134 catch(H5::Exception& ex)
135 {
136  TString msg= TString::Format( "BuildDataSet 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 }
141 
142 }
143 
144 
145 
147 {
148  GO4TRACE((12,"TGo4HDF5Store::Store(TGo4EventElement*)", __LINE__, __FILE__));
149 
150  fxEvent = event; // address of next event into event pointer
151  BuildDataSet(event);
152 
153 try{
154 
155  fxHandle->SetObjectPointer(event); // this will recursively update all subpointers and properties of vector (hopefully...)
157 
158 }
159 catch(H5::Exception& ex)
160 {
161  TString msg = TString::Format( "Store() with HDF5 exception in %s : %s\n", ex.getCFuncName (), ex.getCDetailMsg ());
162  TGo4Log::Error("TGo4HDF5Store: %s", msg.Data());
163  throw TGo4EventStoreException(this, msg.Data());
164 }
165  return 0;
166 }
167 
169 {
170  WriteToStore(cali);
171  return 0;
172 }
173 
175 {
176  WriteToStore(conny);
177  return 0;
178 }
179 
181 {
182  WriteToStore(fitter);
183  return 0;
184 }
185 
186 Int_t TGo4HDF5Store::Store(TFolder* fold)
187 {
188  WriteToStore(fold);
189  return 0;
190 }
191 
192 
193 
195 {
196  if (ob==0) return;
197  TGo4Log::Info("TGo4HDF5Store: WriteToStore not yet implemented for auxiliary objects of class %s (name:%s)\n",ob->Class()->GetName(), ob->GetName());
198 
199 }
200 
static const char * fgcFILESUF
virtual void OpenFile(const char *name=0)
H5::H5File * fxFile
UInt_t ConvertFileMode(Go4_H5_File_Flags flags)
void BuildDataType(TGo4EventElement *event, TGo4HDF5DataHandle *parent=0, Int_t index=0)
virtual void BuildDataSet(TGo4EventElement *event)
TGo4EventElement * fxEvent
virtual void Write(hsize_t sequencenum, H5::H5File *file)
void WriteToStore(TNamed *ob)
virtual void DeleteDataSet()
Go4_H5_File_Flags GetHDF5Flags() const
virtual void BuildWriteDataset(H5::H5File *file)
virtual ~TGo4HDF5Store()
virtual void SetObjectPointer(void *memptr)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
virtual Int_t Store(TGo4EventElement *event)
virtual void CloseFile()
static void Error(const char *text,...)
Definition: TGo4Log.cxx:323
static void Info(const char *text,...)
Definition: TGo4Log.cxx:297
string msg
Definition: go4init.py:11
TGo4HDF5DataHandle * fxHandle