AGX Dynamics  2.37.2.0
JournalArchive.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXDATA_JOURNALARCHIVE_H
18 #define AGXDATA_JOURNALARCHIVE_H
19 
20 #include <agx/Device.h>
21 #include <agx/Component.h>
22 #include <agx/Range.h>
23 #include <agx/Date.h>
24 #include <agxNet/FramePacket.h>
26 #include <agxData/FrameIO.h>
27 
28 
29 namespace agxData
30 {
31  class DiskFrameReader;
32  class DiskFrameWriter;
33 
34 
35 
42  {
43  public:
45 
46 
48 
49 
51  const agx::Name& getName() const;
52 
55  const agx::String& getPath() const;
56 
58  void listSessionNames( agx::Vector<agx::Name>& result ) const;
59 
61  agxData::JournalArchive::Session* getSession( const agx::Name& name );
62 
64  const agxData::JournalArchive::Session* getSession( const agx::Name& name ) const;
65 
67  const SessionTable& getSessions() const;
68 
73  virtual agxData::JournalArchive::Session* createNewSession( const agx::Name& name ) = 0;
74 
76  bool removeSession( const agx::Name& name );
77 
79  virtual bool removeSession( agxData::JournalArchive::Session* session ) = 0;
80 
92  virtual bool renameSession( agxData::JournalArchive::Session* session, const agx::Name& newName ) = 0;
93 
94 
103  bool copySession( agxData::JournalArchive::Session* session, agxData::JournalArchive* target );
104 
116  bool transferSession( agxData::JournalArchive::Session* session, agxData::JournalArchive* target );
117 
118 
119 
128  virtual agx::String getCustomFilesPath(bool create = true) const = 0;
129 
130 
142  virtual agx::String getCustomFilesPath( const agx::Name& sessionName, bool create = true ) const = 0;
143 
145  bool isOwnerOf( const agxData::JournalArchive::Session* session) const;
146 
148  size_t getNumSessions() const;
149 
150 
151  virtual DiskFrameReader* createFrameReader(agxData::JournalArchive::Session* session) = 0;
152  virtual DiskFrameWriter* createFrameWriter(agxData::JournalArchive::Session* session) = 0;
153 
154  protected:
155  JournalArchive( const agx::Name& name, const agx::String& path );
156  JournalArchive();
157 
158  virtual ~JournalArchive();
159 
160  void setName( const agx::Name& name );
161  void setPath( const agx::String& path );
162 
165  bool registerSession( agxData::JournalArchive::Session* newSession );
166 
169  bool unregisterSession( agxData::JournalArchive::Session* removedSession );
170 
172  bool updateSessionAndTableWithNewName( agxData::JournalArchive::Session* session, const agx::Name& newName );
173 
175  virtual agxData::JournalArchive::Session* makeCopy( agxData::JournalArchive::Session* session ) = 0;
176 
177  private:
178  agx::Name m_name;
179  agx::String m_path;
180  SessionTable m_sessions;
181 
182  };
184 
185 
186 
187  /*
188  The JournalArchive::Session class is a handle to a particular session in a journal. Every journal storage format
189  that has a JournalArchive subclass should also provide a JournalArchive::Session derivation.
190  */
191  class AGXCORE_EXPORT JournalArchive::Session : public agx::Referenced
192  {
193  public:
194  static agx::String generateNameFromCurrentDate();
195 
196  public:
197 
199  const agx::Name& getName() const;
200 
205  virtual agx::String getPath() const = 0;
206 
207 
209  agxData::JournalArchive* getJournal();
211  const agxData::JournalArchive* getJournal() const;
212 
220  void setHeaderFormat(SerializedFrame::HeaderFormat format);
221 
222  SerializedFrame::HeaderFormat getHeaderFormat() const;
223 
225  virtual bool truncate( agx::UInt firstFrameToRemove ) = 0;
226 
227 
230  bool copyTo( agxData::JournalArchive* target );
231 
233  bool transferTo( agxData::JournalArchive* target );
234 
235 
247  virtual agx::String getScenePath(bool create = true) const = 0;
248 
249 
255  virtual bool unpackSceneFile() = 0;
256 
262  virtual bool packSceneData(std::stringstream& sceneData) = 0;
263 
269  virtual bool unpackSceneData(std::stringstream& sceneData) = 0;
270 
276  virtual bool packSceneData(std::istream& sceneData) = 0;
277 
283  virtual bool unpackSceneData(std::ostream& sceneData) = 0;
284 
285 
294  virtual agx::String getCustomFilesPath(bool create = true) const = 0;
295 
297  virtual bool recordExtraData( const agx::String& key, const agx::String& value ) = 0;
298 
300  virtual bool retrieveExtraData( const agx::String& key, agx::String& value ) = 0;
301  agx::String retrieveExtraData(const agx::String& key);
302 
304  bool recordExtraDataAsJSon(const agx::String& key, const agx::String& value);
305 
307  bool retrieveExtraDataAsJSon(const agx::String& key, agx::String& value);
308  agx::String retrieveExtraDataAsJSon(const agx::String& key);
309 
311  virtual agxData::Frame::Header getFrameHeader( agx::UInt frameIndex ) const = 0;
312 
313  void setFrameIO(agxData::FrameIO* frameIO);
314  agxData::FrameIO* getFrameIO();
315 
319 
320  virtual void savePlot(const PlotData* plot) = 0;
321  virtual void removePlot(const agx::String& plotName) = 0;
322  virtual PlotData* getPlot(const agx::String& plotName) = 0;
323  virtual void getAllPlots(PlotDataRefVector& result) = 0;
324  virtual void getPlotList(agx::StringVector& result) = 0;
325 
326  virtual agx::UInt getNextFrameIndex(agx::UInt currentFrameIndex, agx::Int offset) const = 0;
327 
328  public:
329  virtual void writeHeader() = 0;
330  virtual void finalizeHeader() = 0;
331 
332  void setDate(agx::Date* date);
333  const agx::Date* getDate() const;
334 
335  void setFirstFrameIndex(agx::UInt64 startFrame);
336  agx::UInt64 getFirstFrameIndex() const;
337 
338  void setFirstFrameTimeStamp(agx::Real64 startTime);
339  agx::Real64 getFirstFrameTimeStamp() const;
340 
341  void setLastFrameIndex(agx::UInt64 endFrame);
342  agx::UInt64 getLastFrameIndex() const;
343 
344  void setLastFrameTimeStamp(agx::Real64 endTime);
345  agx::Real64 getLastFrameTimeStamp() const;
346 
347  void setTimeStep(agx::Real64 timeStep);
348  agx::Real64 getTimeStep() const;
349 
350  void setFrameStride(agx::UInt64 stride);
351  agx::UInt64 getFrameStride() const;
352 
353  void setNumFrames(agx::UInt64 numFrames);
354  agx::UInt64 getNumFrames() const;
355 
356  void setComputationTime(agx::Real64 computationTime);
357  agx::Real64 getComputationTime() const;
358 
359  void setAgxVersionString(const agx::String& version);
360  const agx::String& getAgxVersionString() const;
361  void setAgxVersionNumber( const agx::UInt32 version);
362  agx::UInt32 getAgxVersionNumber() const;
363 
364  bool is64BitReal() const;
365  bool is64BitArchitecture() const;
366  bool isLittleEndian() const;
367 
368  void set64BitReal(bool flag);
369  void set64BitArchitecture(bool flag);
370  void setLittleEndian(bool flag);
371 
372  void setSimulationHeader(agx::Component* header);
373  agx::Component* getSimulationHeader();
374 
375  protected:
376 #ifndef SWIG
377  Session( const agx::Name& name );
378 #endif
379  virtual ~Session();
380 
381  bool rename( const agx::Name& name );
382 
383  private:
384  friend class JournalArchive;
385  void setName( const agx::Name& newName );
386  void setJournal( agxData::JournalArchive* journal );
387 
389  virtual bool transferDiskData( agxData::JournalArchive* target ) = 0;
390 
391 
392  private:
393  agx::Name m_name;
394  agxData::JournalArchive* m_journal;
395  agx::DateRef m_date;
396  bool m_is64BitReal;
397  bool m_is64BitArchitecture;
398  bool m_isLittleEndian;
399  agx::ComponentRef m_simulationHeader;
400  agx::UInt64 m_numFrames;
401  agx::UInt64 m_frameStride;
402  agx::UInt64 m_startFrame;
403  agx::Real64 m_startTime;
404  agx::UInt64 m_endFrame;
405  agx::Real64 m_endTime;
406  agx::Real64 m_timeStep;
407  agx::Real64 m_computationTime;
408  agx::String m_agxVersionString;
409  agx::UInt32 m_agxVersionNumber;
410  SerializedFrame::HeaderFormat m_headerFormat;
411  agxData::FrameIOObserver m_frameIO;
412  };
413 
414 
415 
416 
417  /* Implementation */
418 
420 
421  AGX_FORCE_INLINE bool JournalArchive::Session::is64BitReal() const { return m_is64BitReal; }
422  AGX_FORCE_INLINE bool JournalArchive::Session::is64BitArchitecture() const { return m_is64BitArchitecture; }
423  AGX_FORCE_INLINE bool JournalArchive::Session::isLittleEndian() const { return m_isLittleEndian; }
424 
425  AGX_FORCE_INLINE const agx::Date* JournalArchive::Session::getDate() const { return m_date; }
426  AGX_FORCE_INLINE agx::UInt64 JournalArchive::Session::getFirstFrameIndex() const { return m_startFrame; }
427  AGX_FORCE_INLINE agx::Real64 JournalArchive::Session::getFirstFrameTimeStamp() const { return m_startTime; }
428  AGX_FORCE_INLINE agx::UInt64 JournalArchive::Session::getLastFrameIndex() const { return m_endFrame; }
429  AGX_FORCE_INLINE agx::Real64 JournalArchive::Session::getLastFrameTimeStamp() const { return m_endTime; }
430  AGX_FORCE_INLINE agx::Real64 JournalArchive::Session::getTimeStep() const { return m_timeStep; }
431  AGX_FORCE_INLINE agx::UInt64 JournalArchive::Session::getFrameStride() const { return m_frameStride; }
432  AGX_FORCE_INLINE const agx::String& JournalArchive::Session::getAgxVersionString() const { return m_agxVersionString; }
433  AGX_FORCE_INLINE agx::UInt32 JournalArchive::Session::getAgxVersionNumber() const { return m_agxVersionNumber; }
434  // AGX_FORCE_INLINE agx::UInt JournalArchive::Session::getNumFrames() const { return m_numFrames; }
435  AGX_FORCE_INLINE agx::UInt64 JournalArchive::Session::getNumFrames() const { return m_numFrames; }
436  AGX_FORCE_INLINE SerializedFrame::HeaderFormat JournalArchive::Session::getHeaderFormat() const { return m_headerFormat; }
437 
439 
440 }
441 
442 
443 #endif /* AGXDATA_JOURNALARCHIVE_H */
Helper class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:34
double Real64
Definition: Real.h:45
Session(const agx::Name &name)
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
Base class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:107
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
int32_t Int
Definition: Integer.h:35
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
Base class providing referencing counted objects.
Definition: Referenced.h:119
uint32_t UInt
Definition: Integer.h:34
Contains classes for low level data storage for AGX.
Definition: Container.h:23
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxNet::StructuredMessage PlotData
agx::Vector< PlotDataRef > PlotDataRefVector
Definition: Date.h:27
uint64_t UInt64
Definition: Integer.h:41
agx::HashTable< agx::Name, agxData::JournalArchive::SessionRef > SessionTable
Inheritance with partial specialization due to bug with ref_ptr containers.
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define AGXCORE_EXPORT
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agx::ref_ptr< PlotData > PlotDataRef