QDP++
qdp_map_obj_disk.cc
Go to the documentation of this file.
1
4
5#include "qdp_map_obj_disk.h"
6
7#include <errno.h>
8#include <sys/stat.h>
9
10namespace QDP
11{
12 namespace MapObjDiskEnv
13 {
14 // Anonymous namespace
15 namespace {
16 const std::string file_magic="XXXXQDPLazyDiskMapObjFileXXXX";
17 };
18
19 // Magic string at start of file.
20 std::string getFileMagic() {return file_magic;}
21
22 // Get meta-data
23 std::string getMetaData(const std::string& filename)
24 {
25 BinaryFileReader reader;
26 reader.open(filename);
27
28 std::string read_magic;
29 reader.readDesc(read_magic);
30
31 // Check magic
32 if (read_magic != MapObjDiskEnv::file_magic) {
33 QDPIO::cerr << "Magic String Wrong: Expected: " << MapObjDiskEnv::file_magic << " but read: " << read_magic << std::endl;
34 QDP_abort(1);
35 }
36
38 read(reader, read_version);
39
40 std::string user_data;
41 readDesc(reader, user_data);
42
43 reader.close();
44 return user_data;
45 }
46
47
48 // Check for a file
49 bool checkForNewFile(const std::string& file, std::ios_base::openmode mode)
50 {
51 bool new_file = false;
52
54 {
55 struct stat statbuf;
56 if ((mode & std::ios_base::trunc) || (stat(file.c_str(), &statbuf) != 0 && (errno == ENOENT)))
57 {
58 if (errno == ENOENT)
59 errno = 0; /* In case someone looks at errno. */
60 new_file = true;
61 }
62 }
63
64 QDPInternal::broadcast(new_file);
65
66 return new_file;
67 }
68 }
69
70}
Binary file input class.
Definition qdp_io.h:952
void open(const std::string &p)
Opens a file for reading.
Definition qdp_io.cc:970
void close()
Closes the last file opened.
Definition qdp_io.cc:981
virtual void readDesc(std::string &result)
Definition qdp_io.cc:610
void readDesc(BinaryReader &bin, std::string &input)
Definition qdp_io.cc:774
void read(BinaryReader &bin, std::string &input, size_t maxBytes)
Definition qdp_io.cc:778
bool primaryNode()
Returns whether this is the primary node.
bool checkForNewFile(const std::string &file, std::ios_base::openmode mode)
Check if this will be a new file.
std::string getFileMagic()
Get the file magic.
unsigned int file_version_t
std::string getMetaData(const std::string &filename)
Get the meta-data from a file.
StandardOutputStream cerr
Definition qdp_stdio.cc:22
void broadcast(T &dest)
Broadcast from primary node to all other nodes.
Yet another random number generator.
void QDP_abort(int status)
Panic button.
A Map Object that works lazily from Disk.