StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtIOBinary.hh
1 /**********************************************************
2  *
3  * Here are defined the input/output stream operators for
4  * StHbtEvent and associated classes
5  *
6  *********************************************************/
7 #ifndef StHbtIOBinary_hh
8 #define StHbtIOBinary_hh
9 
10 
11 #include "StHbtMaker/Infrastructure/StHbtV0.hh"
12 #include "StHbtMaker/Infrastructure/StHbtTrack.hh"
13 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
14 #include "StarClassLibrary/StPhysicalHelix.hh"
15 #include <float.h> // these tell maximum values of types so we
16 #include <limits.h> // don't write the characters "inf" to our microDST
17 #include <Stiostream.h>
18 #include "Stiostream.h"
19 
20 typedef unsigned int colSizeType;
21 
22 // /////////////////////////////////////////////////////////////////////////
23 // the god damned SOLARIS compiler can handle templates only in global scope
24 // for that reason we have to stick the OStream in to the function call
25 // this would not be nessesarry on linux where we would declare the
26 // binaryWrite/Read function as methods of the StHbtBinary class (see below)
27 // /////////////////////////////////////////////////////////////////////////
28 
29 enum ioStatus { ioOK=0, ioERR, ioEOF, ioEOL, ioERROpen };
30 
31 class StHbtIOBinary /*: friend StHbtEvent, friend StHbtTrack, friend StHbtV0*/ {
32 protected:
33  int mDebug;
34 public:
35  int byteCounterEvent;
36  int byteCounterTotal;
37  ofstream* mOStream;
38  ifstream* mIStream;
39 
40  StHbtIOBinary(const char* dirName, const char* fileName, const char* appendix, const char* readWrite);
41  ~StHbtIOBinary();
42 
43 #ifndef SOLARIS
44  template<class T> int read(T& x);
45  template<class T> int write(const T& x);
46 #else
47  int read(unsigned short x) {return 0;}
48  int read(const StHbtTrack) {return 0;}
49  int read(const StHbtV0) {return 0;};
50  int write(const StHbtTrack) {return 0;}
51  int write(unsigned short x) {return 0;}
52  int write(const StHbtV0) {return 0;}
53 #endif
54 
55  int read(StThreeVectorD& x);
56  int write(const StThreeVectorD& x);
57  int read(StPhysicalHelixD& x);
58  int write(const StPhysicalHelixD& x);
59  // StHbtEvent
60  int read(StHbtEvent& event, unsigned short evVersion, unsigned short trVersion, unsigned short v0Version );
61  int write(const StHbtEvent& event, unsigned short evVersion, unsigned short trVersion, unsigned short v0Version );
62  // StHbtTrack
63  int read(StHbtTrack&, unsigned short);
64  int write(const StHbtTrack&, unsigned short);
65  // StHbtV0
66  int read(StHbtV0&, unsigned short);
67  int write(const StHbtV0&, unsigned short);
68  // StHbtString
69  int readString(StHbtString&);
70  int writeString(const StHbtString&);
71  int readHeader(StHbtString&);
72  int writeHeader(const StHbtString&);
73  int bytesRead();
74  int bytesWritten();
75 
76  // StHbtEvent Versions
77  int read_V0(StHbtEvent& event, unsigned short trVersion, unsigned short v0Version );
78  int read_V1(StHbtEvent& event, unsigned short trVersion, unsigned short v0Version );
79  int read_V2(StHbtEvent& event, unsigned short trVersion, unsigned short v0Version );
80  int write_V0(const StHbtEvent& event, unsigned short trVersion, unsigned short v0Version );
81  int write_V1(const StHbtEvent& event, unsigned short trVersion, unsigned short v0Version );
82  int write_V2(const StHbtEvent& event, unsigned short trVersion, unsigned short v0Version );
83  // StHbtTrack Versions
84  int read_V1(StHbtTrack&);
85  int read_V2(StHbtTrack&);
86  int write_V1(const StHbtTrack&);
87  int write_V2(const StHbtTrack&);
88  // StHbtV0 Versions
89  int read_V1(StHbtV0&);
90  int read_V2(StHbtV0&);
91  int read_V3(StHbtV0&);
92  int write_V1(const StHbtV0&);
93  int write_V2(const StHbtV0&);
94  int write_V3(const StHbtV0&);
95 
96  int outputStreamStatus();
97  int inputStreamStatus();
98 
99  int readTrackList(StHbtEvent&, unsigned short trVersion);
100  int readV0List(StHbtEvent&, unsigned short v0Version);
101  int writeTrackList(const StHbtEvent&, unsigned short trVersion);
102  int writeV0List(const StHbtEvent&, unsigned short v0Version);
103 
104  const char* parseDirFile(const char*, const char*, const char*);
105 
106  void wait(int n, const char* c) {
107  for (int i = 0; i< 1e6*n; i++) {
108  cout << c;
109  }
110  }
111 };
112 
113 inline int StHbtIOBinary::outputStreamStatus() {
114  if (mOStream) return !mOStream->good();
115  return ioERR;
116 }
117 inline int StHbtIOBinary::inputStreamStatus() {
118  if (mIStream) return !mIStream->good();
119  return ioERR;
120 }
121 
122 #ifndef SOLARIS
123 template<class T>
124 inline int StHbtIOBinary::read(T& x){
125  mIStream->read( (char*)&x, sizeof(x) );
126  byteCounterEvent += sizeof(x);
127  return (!mIStream->good());
128 }
129 template<class T>
130 inline int StHbtIOBinary::write(const T& x){
131  mOStream->write( (char*)&x, sizeof(x) );
132  byteCounterEvent += sizeof(x);
133  return (!mOStream->good());
134 }
135 #endif
136 
137 inline int StHbtIOBinary::read(StThreeVectorD& x) {
138  int iret;
139  double a,b,c;
140  iret = read(a);
141  iret = read(b);
142  iret = read(c);
143  x = StHbtThreeVector(a,b,c);
144  return (!mIStream->good());
145 };
146 
147 inline int StHbtIOBinary::write(const StThreeVectorD& x) {
148  int iret;
149  double a,b,c;
150  a = x.x(); b = x.y(); c = x.z();
151  iret = write(a);
152  iret = write(b);
153  iret = write(c);
154  return (!mOStream->good());
155 };
156 inline int StHbtIOBinary::read(StPhysicalHelixD& x){
157  int iret;
158  double c, dip, phase;
159  StThreeVectorD o;
160  int h=-1;
161  iret = read(o);
162  iret = read(dip);
163  iret = read(c);
164  iret = read(phase);
165  iret = read(h);
166  x = StPhysicalHelixD(c,dip,phase,o,h);
167  return (!mIStream->good());
168 };
169 
170 inline int StHbtIOBinary::write(const StPhysicalHelixD& x){
171  int iret;
172  double c, dip, phase;
173  StThreeVectorD o;
174  int h=-1;
175  c = x.curvature();
176  dip = x.dipAngle();
177  phase = x.phase();
178  o = x.origin();
179  h = x.h();
180  iret = write(o);
181  iret = write(dip);
182  iret = write(c);
183  iret = write(phase);
184  iret = write(h);
185  return (!mOStream->good());
186 };
187 
188 #endif
int h() const
y-center of circle in xy-plane
Definition: StHelix.hh:174
const StThreeVector< double > & origin() const
-sign(q*B);
Definition: StHelix.hh:224
double phase() const
1/R in xy-plane
Definition: StHelix.hh:180