AGX Dynamics  2.35.0.1
JournalArchive.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
59 
62 
65 
67  const SessionTable& getSessions() const;
68 
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 
104 
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 
153 
154  protected:
155  JournalArchive( const agx::Name& name, const agx::String& path );
157 
158  virtual ~JournalArchive();
159 
160  void setName( const agx::Name& name );
161  void setPath( const agx::String& path );
162 
166 
170 
173 
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:
195 
196  public:
197 
199  const agx::Name& getName() const;
200 
205  virtual agx::String getPath() const = 0;
206 
207 
212 
221 
223 
225  virtual bool truncate( agx::UInt firstFrameToRemove ) = 0;
226 
227 
231 
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;
302 
304  bool recordExtraDataAsJSon(const agx::String& key, const agx::String& value);
305 
309 
311  virtual agxData::Frame::Header getFrameHeader( agx::UInt frameIndex ) const = 0;
312 
313  void setFrameIO(agxData::FrameIO* frameIO);
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);
337 
340 
343 
346 
347  void setTimeStep(agx::Real64 timeStep);
349 
352 
353  void setNumFrames(agx::UInt64 numFrames);
355 
356  void setComputationTime(agx::Real64 computationTime);
358 
359  void setAgxVersionString(const agx::String& version);
361  void setAgxVersionNumber( const agx::UInt32 version);
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 
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 */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXCORE_EXPORT
Helper class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:35
Base class for the FrameReaders that are backed by a file on disk.
Definition: DiskTrack.h:108
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
bool updateSessionAndTableWithNewName(agxData::JournalArchive::Session *session, const agx::Name &newName)
Change the name of the given session. Will ensure that the session table is kept consistent.
agxData::JournalArchive * getJournal()
virtual bool renameSession(agxData::JournalArchive::Session *session, const agx::Name &newName)=0
Rename the given session to the given new name.
void set64BitArchitecture(bool flag)
void setSimulationHeader(agx::Component *header)
agx::UInt64 getNumFrames() const
const agx::String & getAgxVersionString() const
virtual agx::String getCustomFilesPath(const agx::Name &sessionName, bool create=true) const =0
Returns the path to a disk directory where custom files related to the given session may be stored.
void setName(const agx::Name &name)
bool registerSession(agxData::JournalArchive::Session *newSession)
Create the Journal <-> Session coupling.
void setComputationTime(agx::Real64 computationTime)
size_t getNumSessions() const
agx::Real64 getLastFrameTimeStamp() const
void setDate(agx::Date *date)
void set64BitReal(bool flag)
virtual bool unpackSceneFile()=0
Ensure that the scene file for the session is available at the location returned by getScenePath.
virtual agx::String getCustomFilesPath(bool create=true) const =0
Returns the path to a disk directory where custom files related to the journal may be stored.
void setHeaderFormat(SerializedFrame::HeaderFormat format)
Some journal formats support more than one format for frame metadata.
virtual void removePlot(const agx::String &plotName)=0
virtual agx::String getScenePath(bool create=true) const =0
Get the path on disk where the .agx file, called the scene file, containing the initial state of the ...
void setFrameStride(agx::UInt64 stride)
virtual agx::UInt getNextFrameIndex(agx::UInt currentFrameIndex, agx::Int offset) const =0
virtual void finalizeHeader()=0
bool transferSession(agxData::JournalArchive::Session *session, agxData::JournalArchive *target)
Transfer the given session from this journal into the given target.
virtual bool packSceneData(std::istream &sceneData)=0
Copy the scene data found in the given stringstream into the journal in some format specific way.
void setAgxVersionString(const agx::String &version)
virtual bool unpackSceneData(std::stringstream &sceneData)=0
Copy scene data from the archive, stored in some format specific way, into the given stringstream.
void setFirstFrameTimeStamp(agx::Real64 startTime)
agx::ref_ptr< PlotData > PlotDataRef
bool recordExtraDataAsJSon(const agx::String &key, const agx::String &value)
Store a string key-value pair to the session on disk, without ruining the .
bool retrieveExtraDataAsJSon(const agx::String &key, agx::String &value)
Read back the value associated with the key from disk.
agxNet::StructuredMessage PlotData
const SessionTable & getSessions() const
virtual DiskFrameWriter * createFrameWriter(agxData::JournalArchive::Session *session)=0
virtual agx::String getPath() const =0
Returns a format specific string that identifies the location of this session within a journal.
virtual void getAllPlots(PlotDataRefVector &result)=0
agx::UInt32 getAgxVersionNumber() const
static agx::String generateNameFromCurrentDate()
virtual void getPlotList(agx::StringVector &result)=0
bool isOwnerOf(const agxData::JournalArchive::Session *session) const
agx::Real64 getFirstFrameTimeStamp() const
virtual bool recordExtraData(const agx::String &key, const agx::String &value)=0
Store a string key-value pair to the session on disk.
void setAgxVersionNumber(const agx::UInt32 version)
void setTimeStep(agx::Real64 timeStep)
virtual DiskFrameReader * createFrameReader(agxData::JournalArchive::Session *session)=0
agx::String retrieveExtraData(const agx::String &key)
virtual bool packSceneData(std::stringstream &sceneData)=0
Copy the scene data found in the given stringstream into the journal in some format specific way.
agxData::JournalArchive::Session * getSession(const agx::Name &name)
void listSessionNames(agx::Vector< agx::Name > &result) const
Add to the end of the given Vector the names of all the sessions in the Journal.
agx::UInt64 getFrameStride() const
bool isLittleEndian() const
void setLastFrameIndex(agx::UInt64 endFrame)
void setFirstFrameIndex(agx::UInt64 startFrame)
const agx::String & getPath() const
void setLittleEndian(bool flag)
void setPath(const agx::String &path)
virtual bool unpackSceneData(std::ostream &sceneData)=0
Copy scene data from the archive, stored in some format specific way, into the given stringstream.
virtual agxData::Frame::Header getFrameHeader(agx::UInt frameIndex) const =0
Load the header data for a particular frame.
bool copyTo(agxData::JournalArchive *target)
Copy the session to another JournalArchive.
virtual void savePlot(const PlotData *plot)=0
bool is64BitArchitecture() const
virtual bool retrieveExtraData(const agx::String &key, agx::String &value)=0
Read back the value associated with the key from disk.
agx::Vector< PlotDataRef > PlotDataRefVector
void setFrameIO(agxData::FrameIO *frameIO)
agx::Real64 getComputationTime() const
bool removeSession(const agx::Name &name)
Remove the session with the given name from the journal.
const agxData::JournalArchive::Session * getSession(const agx::Name &name) const
virtual agxData::JournalArchive::Session * createNewSession(const agx::Name &name)=0
Create a new session with the given name.
agx::Real64 getTimeStep() const
const agxData::JournalArchive * getJournal() const
agx::UInt64 getFirstFrameIndex() const
SerializedFrame::HeaderFormat getHeaderFormat() const
bool transferTo(agxData::JournalArchive *target)
Transfer the session to another JournalArchive. The target JournalArchive must be of the same correct...
virtual void writeHeader()=0
virtual PlotData * getPlot(const agx::String &plotName)=0
bool is64BitReal() const
void setNumFrames(agx::UInt64 numFrames)
virtual bool truncate(agx::UInt firstFrameToRemove)=0
Remove all frames from the given index and forward.
const agx::Date * getDate() const
const agx::Name & getName() const
agx::String retrieveExtraDataAsJSon(const agx::String &key)
void setLastFrameTimeStamp(agx::Real64 endTime)
virtual bool removeSession(agxData::JournalArchive::Session *session)=0
Remove the given session from the journal.
bool rename(const agx::Name &name)
bool unregisterSession(agxData::JournalArchive::Session *removedSession)
Remove the Journal <-> Session coupling.
Session(const agx::Name &name)
agxData::FrameIO * getFrameIO()
agx::Component * getSimulationHeader()
bool copySession(agxData::JournalArchive::Session *session, agxData::JournalArchive *target)
Copy the given session from this journal into the given target journal.
virtual agxData::JournalArchive::Session * makeCopy(agxData::JournalArchive::Session *session)=0
Create a copy of the given session. The copy will have its disk data stored in the current JournalArc...
agx::UInt64 getLastFrameIndex() const
agx::HashTable< agx::Name, agxData::JournalArchive::SessionRef > SessionTable
JournalArchive(const agx::Name &name, const agx::String &path)
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
Definition: Date.h:28
Inheritance with partial specialization due to bug with ref_ptr containers.
Representation of a name string.
Definition: Name.h:33
Base class providing referencing counted objects.
Definition: Referenced.h:114
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
#define AGX_FORCE_INLINE
Definition: macros.h:58
Contains classes for low level data storage for AGX.
Definition: Container.h:23
double Real64
Definition: Real.h:45
uint32_t UInt32
Definition: Integer.h:40
uint64_t UInt64
Definition: Integer.h:41
int32_t Int
Definition: Integer.h:35
uint32_t UInt
Definition: Integer.h:34