AGX Dynamics  2.35.0.1
FileJournal.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_FILEJOURNAL_H
18 #define AGXDATA_FILEJOURNAL_H
19 
20 #include <agxData/JournalArchive.h>
22 #include <agx/HashVector.h>
23 
24 namespace agx
25 {
26  class TiXmlElement;
27  class TiXmlText;
28 }
29 
30 
31 namespace agxData
32 {
34 
35 
40  {
41  public:
42 
43  static bool isFileJournal(const agx::String& path);
44 
45  public:
47 
52  FileJournal( const agx::String& diskPath );
53 
59  virtual JournalArchive::Session* createNewSession( const agx::Name& name ) override;
60 
61 
64 
65 
67  virtual bool removeSession( agxData::JournalArchive::Session* session ) override;
68 
70  virtual bool renameSession( agxData::JournalArchive::Session* session, const agx::Name& newName ) override;
71 
73  virtual agx::String getCustomFilesPath(bool create = true) const override;
74 
77  virtual agx::String getCustomFilesPath( const agx::Name& sessionName, bool create = true ) const override;
78 
79 
87  static bool parseSessionPath(const agx::String& fullPath, agx::String& journalPath, agx::String& sessionName);
88 
89 
92 
93  protected:
94  virtual ~FileJournal();
95 
97 
98  private:
100  void readJournalContent();
101 
104  FileJournal::Session* createNewFileSession( const agx::Name& name );
105 
106 
108  agxData::FileJournal::Session* downcastSession( agxData::JournalArchive::Session* abstractSession ) const;
109 
110 
111  // agxData::JournalArchive::Session* makeCopy( agxData::JournalArchive::Session* session );
112  };
113 
114 
119  {
120  public:
121 
124 
125 
127  virtual agx::String getPath() const override;
128 
130  virtual agx::String getScenePath(bool create = true) const override;
131 
132 
135  virtual bool unpackSceneFile() override;
136 
139  virtual bool packSceneData(std::stringstream& sceneData) override;
140 
142  virtual bool unpackSceneData(std::stringstream& sceneData) override;
143 
146  virtual bool packSceneData(std::istream& sceneData) override;
147 
149  virtual bool unpackSceneData(std::ostream& sceneData) override;
150 
151 
153  virtual bool truncate( agx::UInt firstFrameToRemove ) override;
154 
157  agx::String buildFramePath( agx::UInt frameIndex ) const;
158 
159 
161  virtual agxData::Frame::Header getFrameHeader( agx::UInt frameIndex ) const override;
162 
166  const FileJournal* getFileJournal() const;
167 
168 
169 
170 
171  virtual agx::String getCustomFilesPath(bool create = true) const override;
174 
175  virtual bool recordExtraData( const agx::String& key, const agx::String& value ) override;
176  virtual bool retrieveExtraData( const agx::String& key, agx::String& value ) override;
177 
178  virtual void savePlot(const PlotData* plot) override;
179  virtual void removePlot(const agx::String& plotName) override;
180  virtual PlotData* getPlot(const agx::String& plotName) override;
181  virtual void getAllPlots(PlotDataRefVector& result) override;
182  virtual void getPlotList(agx::StringVector& result) override;
183 
184  virtual void writeHeader() override;
185  virtual void finalizeHeader() override;
186 
187  virtual agx::UInt getNextFrameIndex(agx::UInt currentFrameIndex, agx::Int offset) const override;
188 
189  public:
191 
192  static agxData::FileJournal::Session* create( const agx::Name& name, const agx::String& path );
193 
195  static FileJournal::Session* load( const agx::TiXmlElement* eSession );
196 
197 
199  {
203  };
204 
205 
206  const FrameInfo* getFrameInfo(agx::UInt frameIndex) const;
207 
210 
211  private:
212  friend class agxData::FileJournal;
213 
216  bool copyDiskData( agxData::FileJournal* target );
217 
220  virtual bool transferDiskData( agxData::JournalArchive* target ) override;
221 
222 
223  agx::TiXmlElement* generateHeader();
224 
225  private:
226 
228  Session( const agx::Name& name );
229 
230  agx::TiXmlText* getTextNode(agx::TiXmlElement* root, const agx::String& key, bool create);
231 
232  bool unpackSceneDataToStream(std::ostream& sceneData);
233  void createFrameTable();
234  void printFileStatistics();
235  void readExtraData(agx::TiXmlElement* eExtraData);
236  void readPlotData(agx::TiXmlElement* ePlotData);
237 
238  protected:
239  virtual ~Session();
240 
241  private:
242  // std::ofstream m_file;
243  agx::UInt64 m_sceneDataOffset;
244  agx::UInt64 m_sceneDataSize;
245  agx::UInt64 m_frameDataOffset;
246  agx::UInt64 m_frameHead;
247 
249  FrameTable m_frameTable;
250 
252  ExtraDataTable m_extraDataTable;
253 
254 
255  struct PlotEntry
256  {
257  agx::UInt64 offset;
258  agx::UInt64 headerSize;
259  agx::UInt64 dataSize;
260  };
261 
262  class PlotSort;
263 
264  typedef agx::HashTable<agx::Name, PlotEntry> PlotTable;
265  PlotTable m_plotTable;
266  };
267 
268 }
269 
270 
271 /* AGXDATA_FILEJOURNAL_H */
272 #endif
#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 FileJournal provides a way to inspect and manipulate a journal created by the FileFrameWriter and...
Definition: FileJournal.h:40
static bool isFileJournal(const agx::String &path)
virtual bool removeSession(agxData::JournalArchive::Session *session) override
Remove the given session from the journal.
virtual agx::String getCustomFilesPath(bool create=true) const override
static bool parseSessionPath(const agx::String &fullPath, agx::String &journalPath, agx::String &sessionName)
Split the given session path into the path to the path to the journal and the name of the session.
virtual DiskFrameReader * createFrameReader(JournalArchive::Session *session) override
virtual bool renameSession(agxData::JournalArchive::Session *session, const agx::Name &newName) override
Rename the given session, including data movement on disk.
virtual DiskFrameWriter * createFrameWriter(JournalArchive::Session *session) override
virtual JournalArchive::Session * createNewSession(const agx::Name &name) override
Create a new session within the journal.
virtual agx::String getCustomFilesPath(const agx::Name &sessionName, bool create=true) const override
agxData::FileJournal::Session * getFileSession(const agx::Name &name)
virtual agxData::JournalArchive::Session * makeCopy(agxData::JournalArchive::Session *session) override
Create a copy of the given session. The copy will have its disk data stored in the current JournalArc...
FileJournal(const agx::String &diskPath)
Open a journal on disk.
The JournalArchive provides an abstract class for inspecting and manipulating the contents of a creat...
Session(const agx::Name &name)
virtual bool retrieveExtraData(const agx::String &key, agx::String &value) override
virtual void getPlotList(agx::StringVector &result) override
virtual agx::String getPath() const override
virtual bool recordExtraData(const agx::String &key, const agx::String &value) override
FileJournal * getFileJournal()
const FrameInfo * getFrameInfo(agx::UInt frameIndex) const
static agxData::FileJournal::Session * create(const agx::Name &name, const agx::String &path)
Create a new empty session to which a recording can be made. Will return nullptr on error.
virtual agxData::Frame::Header getFrameHeader(agx::UInt frameIndex) const override
Load the header data for a particular frame.
virtual ~Session()
virtual void finalizeHeader() override
virtual void writeHeader() override
virtual void removePlot(const agx::String &plotName) override
virtual bool unpackSceneData(std::stringstream &sceneData) override
Copy the scene data from the file pointed to by getScenePath into the given string stream.
agx::UInt64 getFrameHead()
virtual bool unpackSceneData(std::ostream &sceneData) override
Copy the scene data from the file pointed to by getScenePath into the given output stream.
agx::String getFramesPath() const
virtual bool packSceneData(std::istream &sceneData) override
Copy the scene data found in the given input stream into the scene file pointed to by getScenePath.
virtual bool packSceneData(std::stringstream &sceneData) override
Copy the scene data found in the given string stream into the scene file pointed to by getScenePath.
virtual agx::String getCustomFilesPath(bool create=true) const override
agx::String getPlotDirectoryPath() const
static FileJournal::Session * load(const agx::TiXmlElement *eSession)
Load a session from disk. Will return nullptr on error.
virtual PlotData * getPlot(const agx::String &plotName) override
void setFrameHead(agx::UInt64 head)
virtual agx::UInt getNextFrameIndex(agx::UInt currentFrameIndex, agx::Int offset) const override
virtual void getAllPlots(PlotDataRefVector &result) override
virtual agx::String getScenePath(bool create=true) const override
virtual void savePlot(const PlotData *plot) override
virtual bool unpackSceneFile() override
The file journal does not support packing, so this does nothing.
agx::String getSessionHeaderPath() const
virtual bool truncate(agx::UInt firstFrameToRemove) override
Remove all frames from the given index and forward.
const FileJournal * getFileJournal() const
agx::String buildFramePath(agx::UInt frameIndex) const
Inheritance with partial specialization due to bug with ref_ptr containers.
Representation of a name string.
Definition: Name.h:33
Contains classes for low level data storage for AGX.
Definition: Container.h:23
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint64_t UInt64
Definition: Integer.h:41
int32_t Int
Definition: Integer.h:35
AGXCORE_EXPORT Component * root()
uint32_t UInt
Definition: Integer.h:34