genericIO
basicIO.h
1 #ifndef BASIC_IOH
2 #define BASIC_IOH 1
3 #include <stdio.h>
4 #include <memory>
5 #include "genericFile.h"
6 #include <assert.h>
7 /*this is very rudimentary class for file io */
8 namespace SEP {
9 class basicIO {
10 public:
11 basicIO(){
12  _swapData=false;
13 }
14 void readWindow(const std::vector<int> &nw, const std::vector<int> &fw,const std::vector<int>& jw,void *data, void *head=0);
15 void writeWindow(const std::vector<int>& nw, const std::vector<int>& fw,const std::vector<int>& jw,const void *data, void *head=0);
16 virtual void readStream(const long long sz, void *data){
17  assert(1==2);
18 }
19 virtual void writeStream(const long long sz, const void *dat){
20  assert(1==2);
21 }
22 virtual void readTraceStream(const long long sz, void *dat, void *head=0);
23 virtual void writeTraceStream(const long long sz, const void *dat, const void *head=0);
24 virtual void writeReelHead(const void *reelH);
25 void readBlocks(const int naxes,const std::vector<int>& nwo,const std::vector<int>& fwo, const std::vector<int>& jwo,
26  const std::vector<int> &nwi, const std::vector<int>& fwi, const std::vector<int> &jwi,
27  const long long buf, void *data,void *head);
28 void writeBlocks(const int naxes,const std::vector<int> &nwo,const std::vector<int> &fwo,const std::vector<int> &jwo,
29  const std::vector<int>& nwi, const std::vector<int> &fwi,const std::vector<int> &jwi,
30  const long long buf,const void *data,const void *head);
31 virtual void partsToBlock(const std::vector<int> &nw, const std::vector<int>& fw, const std::vector<int> &jw, void *in, const void *out,const void *head);
32 virtual void blockToParts(const std::vector<int> &nw,const std::vector<int> &fw, const std::vector<int> &jw, const void *in, void *out, void *head);
33 virtual long long getCurrentPos() const {
34  assert(1==2);
35 }
36 virtual long long getSize(){
37  assert(1==2);
38 }
39 void swap_float_bytes(const int n, float *buf);
40 virtual inline void seekTo(const long long off, const int whence){
41  assert(1==2);
42 }
43 virtual inline void seekToPos(const long long pos){
44  assert(1==2);
45 
46 }
47 void setFileParams(const std::string nm, const usage_code usage,const int reelH, const int traceH,
48  const int esize, const bool swapData,std::shared_ptr<hypercube> hyper);
49 protected:
50 usage_code _usage;
51 FILE *_myf;
52 bool _swapData=false;
53 long long _reelH,_traceH;
54 long long _esize;
55 std::string _nm;
56 std::shared_ptr<hypercube> _hyper;
57 };
58 class myFileIO : public basicIO {
59 public:
60 myFileIO(const std::string& nm,const usage_code usage,const int reelH, const int traceH,const int esize,const bool swapData,std::shared_ptr<hypercube> hyper);
61 virtual inline void seekToPos(const long long pos){
62  long long ft=getCurrentPos();
63  long long bg=1024*1024*1024;
64  long long diff=pos-ft;
65  while(diff!=0) {
66  long long dst;
67  if(diff>0) dst=std::min(bg,diff);
68  else dst=-std::min(-diff,bg);
69  fseek(_myf,dst,SEEK_CUR);
70  diff-=dst;
71  }
72 }
73 virtual inline void seekTo(const long long pos, const int whence){
74 
75  fseek(_myf,pos,whence);
76 
77 }
78 virtual long long getCurrentPos() const {
79  return ftell(_myf);
80 }
81 virtual long long getSize(){
82  long long cp=getCurrentPos();
83  fseek(_myf,0L,SEEK_END);
84  long long end=getCurrentPos();
85  fseek(_myf,cp,0);
86  return end;
87 }
88 virtual void readStream(const long long sz, void *data);
89 virtual void writeStream(const long long sz,const void *data);
90 virtual void close(){
91  if(myf!=0) fclose(myf);
92 }
93 ~myFileIO(){
94  close();
95 }
96 FILE *myf=0;
97 };
98 
99 }
100 
101 #endif
Definition: basicIO.h:9
Definition: basicIO.h:58
Definition: axis.h:8