AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
Hdf5Journal.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
20#include <agx/config.h>
21#if AGX_USE_HDF5()
22
23
25#include <agx/AgxH5.h>
26
27namespace agxData
28{
29 class Hdf5FrameReader;
30 class Hdf5FrameWriter;
31
32 AGX_DECLARE_POINTER_TYPES( Hdf5Journal );
33
34
39 class AGXCORE_EXPORT Hdf5Journal : public agxData::JournalArchive
40 {
41 public:
42 static bool isHdf5Journal(const agx::String& path);
43
44 public:
46
51 Hdf5Journal( const agx::String& diskPath, bool readOnlyIfExists=false);
52
60 virtual JournalArchive::Session* createNewSession( const agx::Name& name ) override;
61
67 Hdf5Journal::Session* createNewHdf5Session( const agx::Name& name );
68
70 agxData::Hdf5Journal::Session* getHdf5Session( const agx::Name& name );
71
73 virtual bool removeSession(agxData::JournalArchive::Session* session) override;
74
76 virtual bool renameSession(agxData::JournalArchive::Session* session, const agx::Name& newName) override;
77
79 virtual agx::String getCustomFilesPath(bool create = true) const override;
80
82 virtual agx::String getCustomFilesPath( const agx::Name& sessionName, bool create = true ) const override;
83
85 agx::String getHdf5ArchivePath() const;
86
87 virtual DiskFrameReader* createFrameReader(JournalArchive::Session* session) override;
88 virtual DiskFrameWriter* createFrameWriter(JournalArchive::Session* session) override;
89
90 protected:
91 virtual ~Hdf5Journal();
92
93 virtual agxData::JournalArchive::Session* makeCopy(agxData::JournalArchive::Session* session) override;
94
95 private:
97 void readJournalContent();
98
99 agxData::Hdf5Journal::Session* downcastSession( agxData::JournalArchive::Session* abstractSession ) const;
100
101 private:
102 friend class Session;
103 void unlinkSessionData( const agx::Name& name );
104 void renameSessionData( const agx::Name& name, const agx::Name& newName );
105 H5::Group& getSessionsGroup();
106 H5::H5File* getFile();
107
108 private:
109 H5::H5File* m_file;
110 H5::Group m_sessions;
111 agx::String m_baseName;
112 agx::String m_parentFolder;
113 };
114
115
119 class AGXCORE_EXPORT agxData::Hdf5Journal::Session : public agxData::JournalArchive::Session
120 {
121 public:
122
138 virtual agx::String getPath() const override;
139
140
141 /*
142 Get the path to the unpack location for the scene file for this session.
143 The location will only contain a file if the unpackSceneData method has
144 been called, or if a write to the file has been done explicitly from
145 somewhere else.
146
147 \return The path to the .agx file containing the initial state of the simulation.
148 */
149 virtual agx::String getScenePath(bool create = true) const override;
150
151
152
153 /*
154 Make a copy of the initial scene configuration data stored in the archive
155 to the location pointed to by getScenePath. Returns false if there is no
156 .agx file in the HDF5 archive, or if the write to the location pointed to
157 by getScenePath fails.
158 */
159 virtual bool unpackSceneFile() override;
160
161
162 /*
163 Copy the data found in the stringstream into the initial scene
164 configuration stored in the HDF5 archive.
165 */
166 virtual bool packSceneData(std::stringstream& sceneData) override;
167
168 /*
169 Copy the initial scene data stored in the HDF5 archive into the given string stream.
170 */
171 virtual bool unpackSceneData(std::stringstream& sceneData) override;
172
173 /*
174 Copy the data found in the stringstream into the initial scene
175 configuration stored in the HDF5 archive.
176 */
177 virtual bool packSceneData(std::istream& sceneData) override;
178
179 /*
180 Copy the initial scene data stored in the HDF5 archive into the given string stream.
181 */
182 virtual bool unpackSceneData(std::ostream& sceneData) override;
183
184 /*
185 Get the path to a disk directory where custom files related to the session
186 may be stored. The folder is created, if necessary, if the 'crate'
187 argument is true.
188 */
189 virtual agx::String getCustomFilesPath(bool create = true) const override;
190
194 virtual bool truncate( agx::UInt firstFrameToRemove ) override;
195
199 virtual agxData::Frame::Header getFrameHeader( agx::UInt frameIndex ) const override;
200
202 Hdf5Journal* getHdf5Journal();
204 const Hdf5Journal* getHdf5Journal() const;
205
206 virtual bool recordExtraData( const agx::String& key, const agx::String& value ) override;
207 virtual bool retrieveExtraData( const agx::String& key, agx::String& value ) override;
208
209 virtual void savePlot( const PlotData* plot) override;
210 virtual void removePlot( const agx::String& plotName ) override;
211 virtual PlotData* getPlot( const agx::String& plotName ) override;
212 virtual void getAllPlots( PlotDataRefVector& result ) override;
213 virtual void getPlotList( agx::StringVector& result ) override;
214
215 virtual agx::UInt getNextFrameIndex(agx::UInt currentFrameIndex, agx::Int offset) const override;
216
217 virtual void writeHeader() override;
218 virtual void finalizeHeader() override;
219
220 public:
222 static agxData::Hdf5Journal::Session* create( const agx::Name& name, H5::Group& sessions );
223
225 static agxData::Hdf5Journal::Session* load( const agx::Name& name, H5::Group& sessionRoot );
226
227 private:
228 friend class agxData::Hdf5Journal;
229
230 // Rename the data owned by this session in the HDF5 archive.
231 bool renameDiskData( const agx::Name& newName );
232
233 bool copySessionFolder( agx::String targetFolderPath, bool deleteSource = false );
234
237 virtual bool transferDiskData( agxData::JournalArchive* target ) override;
238
239 bool copyDiskData( agxData::Hdf5Journal* target );
240
241
243 Session( const agx::Name& name, H5::Group& session );
244
245
246 void fixHeader(H5::Group& sessionRoot, H5::Group& header);
247 void finalizeHeader(
248 agx::UInt64 numFrames, agx::UInt64 startFrameIndex, agx::UInt64 endFrameIndex, double startFrameTime, double endFrameTime);
249
250 private:
251 friend class agxData::Hdf5FrameReader;
252 friend class agxData::Hdf5FrameWriter;
253
254 H5::Group& getHdf5Node();
255 H5::H5File* getHdf5File();
256
259 void flushToFile();
260
261
262 private:
264 agx::String getCustomFilesPath( const agx::Name& sessionName, bool create = true ) const;
265
266 // Assumes that the h5::mutex is held by the current thread.
267 bool unpackSceneDataToStream(std::ostream& sceneData);
268
269 // Open the extra data HDF5 group. If 'create' is false, then the HDF5
270 // library will Throw an exception if the group doesn't exist. The obvious
271 // action is taken if 'create' is true in this case.
272 H5::Group openExtraData(bool create);
273
274
275 struct FrameInfo : public agxData::Frame::Header
276 {
277 agx::String nodeName;
278 agx::UInt sequenceIndex;
279 };
280
281 void createFrameTable();
282
283 static herr_t iterateSession(hid_t group_id, const char * member_name, const H5L_info_t *, void* operator_data);
284 static bool compareFrames(const FrameInfo& lhs, const FrameInfo& rhs);
285
286 protected:
287 virtual ~Session();
288
289
290 private:
291 H5::Group m_session;
293 FrameTable m_frameTable;
294 agx::Vector<FrameInfo> m_tempFrames;
295 };
296
297}
298
299/* AGX_USE_HDF5 */
300#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXCORE_EXPORT
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
Session(const agx::Name &name)
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
Representation of a name string.
Definition: Name.h:33
Contains classes for low level data storage for AGX.
Definition: Container.h:23
uint64_t UInt64
Definition: Integer.h:33
uint64_t UInt
Definition: Integer.h:27
int64_t Int
Definition: Integer.h:28