View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

archive_saver.h
Go to the documentation of this file.
1#ifndef VISTLE_ARCHIVE_SAVER_H
2#define VISTLE_ARCHIVE_SAVER_H
3
4#include "archives.h"
5#include "shmvector.h"
7
8#include <boost/mpl/for_each.hpp>
9
10#include <set>
11#include <map>
12#include <string>
13#include <memory>
14#include <iostream>
15
16namespace vistle {
17
19 ArraySaver(const std::string &name, int type, vistle::oarchive &ar, const void *array = nullptr)
20 : m_ok(false), m_name(name), m_type(type), m_ar(ar), m_array(array)
21 {}
22 ArraySaver() = delete;
23 ArraySaver(const ArraySaver &other) = delete;
24
25 template<typename T>
26 void operator()(T)
27 {
28 if (shm_array<T, typename shm<T>::allocator>::typeId() != m_type) {
29 //std::cerr << "ArraySaver: type mismatch - looking for " << m_type << ", is " << shm_array<T, typename shm<T>::allocator>::typeId() << std::endl;
30 return;
31 }
32
33 if (m_ok) {
34 m_ok = false;
35 std::cerr << "ArraySaver: multiple type matches for data array " << m_name << std::endl;
36 return;
37 }
38 ShmVector<T> arr;
39 if (m_array) {
40 arr = *reinterpret_cast<const ShmVector<T> *>(m_array);
41 } else {
42 arr = Shm::the().getArrayFromName<T>(m_name);
43 }
44 if (!arr) {
45 std::cerr << "ArraySaver: did not find data array " << m_name << std::endl;
46 return;
47 }
48 m_ar &m_name;
49 m_ar &*arr;
50 m_ok = true;
51 }
52
53 bool save()
54 {
55 boost::mpl::for_each<VectorTypes>(boost::reference_wrapper<ArraySaver>(*this));
56 if (!m_ok) {
57 std::cerr << "ArraySaver: failed to save array " << m_name << " to archive" << std::endl;
58 }
59 return m_ok;
60 }
61
62 bool m_ok;
63 std::string m_name;
64 int m_type;
66 const void *m_array = nullptr;
67};
68
69class V_COREEXPORT DeepArchiveSaver: public Saver, public std::enable_shared_from_this<DeepArchiveSaver> {
70public:
71 void saveArray(const std::string &name, int type, const void *array) override;
72 void saveObject(const std::string &name, obj_const_ptr obj) override;
73 SubArchiveDirectory getDirectory();
74 void flushDirectory();
75
76 bool isObjectSaved(const std::string &name) const;
77 bool isArraySaved(const std::string &name) const;
78
79 std::set<std::string> savedObjects() const;
80 std::set<std::string> savedArrays() const;
81 void setSavedObjects(const std::set<std::string> &objs);
82 void setSavedArrays(const std::set<std::string> &arrs);
83
84 void setCompressionSettings(const CompressionSettings &settings);
85
86private:
87 CompressionSettings m_compressionSettings;
88 std::map<std::string, buffer> m_objects;
89 std::map<std::string, buffer> m_arrays;
90 std::set<std::string> m_archivedObjects;
91 std::set<std::string> m_archivedArrays;
92};
93
94
95} // namespace vistle
96#endif
Definition: archive_saver.h:69
Definition: archives.h:120
static Shm & the()
Definition: shm.cpp:315
const ShmVector< T > getArrayFromName(const std::string &name) const
Definition: shm_impl.h:32
Definition: shm_reference.h:15
Definition: shm_array.h:19
Definition: archives.h:197
#define V_COREEXPORT
Definition: export.h:9
Definition: allobjects.cpp:30
std::vector< SubArchiveDirectoryEntry > SubArchiveDirectory
Definition: archives.h:118
std::shared_ptr< const Object > obj_const_ptr
Definition: archives.h:86
Definition: archive_saver.h:18
ArraySaver(const ArraySaver &other)=delete
std::string m_name
Definition: archive_saver.h:63
int m_type
Definition: archive_saver.h:64
ArraySaver(const std::string &name, int type, vistle::oarchive &ar, const void *array=nullptr)
Definition: archive_saver.h:19
bool save()
Definition: archive_saver.h:53
vistle::oarchive & m_ar
Definition: archive_saver.h:65
bool m_ok
Definition: archive_saver.h:62
void operator()(T)
Definition: archive_saver.h:26
Definition: archives.h:51
boost::interprocess::allocator< T, managed_shm::segment_manager > allocator
Definition: shm.h:111