GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
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"
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");
71 CloseFile();
72}
73
74void 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);
110 fxHandle->BuildWriteDataset(fxFile);
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
131 fxHandle->SetObjectPointer(
132 event); // this will recursively update all subpointers and properties of vector (hopefully...)
133 fxHandle->Write(fiFillCount++, fxFile);
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
161Int_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
#define GO4TRACE(X)
Definition TGo4Log.h:25
Go4 condition class.
The abstract base class for the data elements of which the unpacked events (or detector structure dat...
Central class of Go4Fit package.
Definition TGo4Fitter.h:38
UInt_t fiFlags
remember file property flags.
void BuildDataType(TGo4EventElement *event, TGo4HDF5DataHandle *parent=nullptr, Int_t index=0)
Prepare data type from event structure for hdf5.
UInt_t ConvertFileMode(Go4_H5_File_Flags flags)
Convert common go4 filemode flags to hdf5 flags:
Bool_t fbDataSetExists
True if branch already exists.
TGo4HDF5DataHandle * fxHandle
handle object to recursively treat the io of nested event components
hsize_t fiFillCount
counter of filled events.
virtual void DeleteDataSet()
delete dataset resource
virtual void CloseFile()
opens the hdf5 file depending on the setup
TGo4EventElement * fxEvent
Points to event structure to be filled into dataset.
static const char * fgcFILESUF
Standard suffix for file name.
H5::H5File * fxFile
the currently open hdf5 file
Go4_H5_File_Flags GetHDF5Flags() const
Int_t Store(TGo4EventElement *event) override
Stores eventelement event into the storage implementation.
void WriteToStore(TNamed *ob)
used by all Store methods to write with referencing event number in name
void BuildDataSet(TGo4EventElement *event) override
initialize dataset from event structure
virtual ~TGo4HDF5Store()
void OpenFile(const char *name=nullptr) override
opens the hdf5 file depending on the setup
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
Definition TGo4Log.cxx:294
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
Definition TGo4Log.cxx:320
Base class for all parameter aggregations, e.g.