EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDbBinaryFile.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDbBinaryFile.h
1 #ifndef FAIRDBBINARYFILE_H
2 #define FAIRDBBINARYFILE_H
3 
4 #include <fstream>
5 using std::fstream;
6 using std::ios_base;
7 
8 #include <string>
9 using std::string;
10 
11 #include <vector>
12 using std::vector;
13 
14 #ifndef ROOT_Rtypes
15 #if !defined(__CINT__) || defined(__MAKECINT__)
16 #include "Rtypes.h"
17 #endif
18 #endif
19 
20 class FairDbTableRow;
21 class ValTimeStamp;
22 class ValRange;
23 
25 {
26 
27  public:
28 
29  FairDbBinaryFile(const char* fileName= "",
30  Bool_t input = kTRUE);
32 
33 // State testing.
34 
35  string GetFileName() const { return fFileName; }
36  Bool_t IsOK() const { return ! fHasErrors;}
37  Bool_t IsReading() const { return this->IsOK() && fReading; }
38  Bool_t IsWriting() const { return this->IsOK() && ! fReading; }
39 
40 // State changing.
41 
42  void Close();
43 
44 // Builtin data type I/O.
45 
47  FairDbBinaryFile& operator << (const Bool_t& num);
49  FairDbBinaryFile& operator << (const Int_t& num);
51  FairDbBinaryFile& operator << (const UInt_t& num);
52  FairDbBinaryFile& operator >> (Double_t& num);
53  FairDbBinaryFile& operator << (const Double_t& num);
54 
55 // Simple Virtual object I/O.
56 // (i.e. object with vptr but only built-in data types)
57 
60 
61 // String I/O.
62 // Warning: Implimentation assumes that string does not contain
63 // a null character.
64 
65  FairDbBinaryFile& operator >> (string& str);
66  FairDbBinaryFile& operator << (const string& str);
67 
68 // Compound object I/O.
69 
72 
73 // Vector I/O.
74 
75  FairDbBinaryFile& operator >> (vector<FairDbTableRow*>& arr);
76  FairDbBinaryFile& operator << (vector<FairDbTableRow*>& arr);
78  char* buff = fArrayBuffer;
79  fArrayBuffer = 0;
80  return buff;
81  }
82 
83 // Global control of all created FairDbBinaryFile objects.
84 
85  static Bool_t CanReadL2Cache() { return fgWorkDir.size() && fgReadAccess; }
86  static Bool_t CanWriteL2Cache() { return fgWorkDir.size() && fgWriteAccess; }
87  static void SetWorkDir(const string& dir) {
88  fgWorkDir = dir;
89  if ( fgWorkDir[fgWorkDir.size()-1] != '/' ) { fgWorkDir += '/'; }
90  }
91  static void SetReadAccess(Bool_t access = kTRUE) { fgReadAccess = access; }
92  static void SetWriteAccess(Bool_t access = kTRUE) { fgWriteAccess = access; }
93 
94  private:
95 
98 
99 // The functions that do the low-level I/O.
100 
101  Bool_t CanRead();
102  Bool_t CanWrite();
103  void CheckFileStatus();
104 
105  Bool_t Read(char* bytes, UInt_t numBytes);
106  Bool_t Write(const char* bytes, UInt_t numBytes);
107 
108 // CINT does not recognise fstream; only ifstream and ofstream.
109 #if !defined(__CINT__)
110 
112  fstream* fFile;
113 #endif
114 
115  Bool_t fReading;
116  Bool_t fHasErrors;
118  string fFileName;
119 
120  static string fgWorkDir; //Level 2 Cache directory or null if none.
121  static Bool_t fgReadAccess; //Have read access if true.
122  static Bool_t fgWriteAccess;//Have write access if true.
123 
124 };
125 
126 #endif // FAIRDBBINARYFILE_H