]>
Commit | Line | Data |
---|---|---|
1 | #ifndef ALIFMDALTROIO_H | |
2 | #define ALIFMDALTROIO_H | |
3 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights | |
4 | * reserved. | |
5 | * | |
6 | * Latest changes by Christian Holm Christensen <cholm@nbi.dk> | |
7 | * | |
8 | * See cxx source for full Copyright notice | |
9 | */ | |
10 | #include <iosfwd> | |
11 | #include <TObject.h> | |
12 | ||
13 | //____________________________________________________________________ | |
14 | class AliFMDAltroIO : public TObject | |
15 | { | |
16 | public: | |
17 | /** Type of 40 bit words (signed) */ | |
18 | typedef long long W40_t; | |
19 | /** Type of 10 bit words (signed) */ | |
20 | typedef Int_t W10_t; | |
21 | /** Constructor */ | |
22 | AliFMDAltroIO(); | |
23 | /** Destructor */ | |
24 | virtual ~AliFMDAltroIO() {} | |
25 | /** Error states */ | |
26 | enum { | |
27 | /** No error */ | |
28 | kNoError, | |
29 | /** Bad state after open/close file */ | |
30 | kBadFile, | |
31 | /** Bad bit offset specified */ | |
32 | kBadBits, | |
33 | /** Bad state after reading from file */ | |
34 | kBadRead, | |
35 | /** Bad state after writing to file */ | |
36 | kBadWrite, | |
37 | /** Bad state after seeking in file */ | |
38 | kBadSeek, | |
39 | /** Could not tell position in file */ | |
40 | kBadTell, | |
41 | /** Bad trailer 40 bit word in file */ | |
42 | kBadTrailer, | |
43 | /** Bad fill word in file */ | |
44 | kBadFill | |
45 | }; | |
46 | /** Trailer mask */ | |
47 | static const W40_t fgkTrailerMask; | |
48 | /** Get error string */ | |
49 | const char* ErrorString(Int_t err) const; | |
50 | protected: | |
51 | /** I/O Buffer */ | |
52 | W40_t fBuffer; | |
53 | /** Pointer into buffer */ | |
54 | Int_t fIBuffer; | |
55 | ||
56 | /** Concatenate a 10 bit word into a 40 bit word. | |
57 | @param n Offset (0-3) | |
58 | @param w 10 bit word | |
59 | @return @a w at offset @a n in a 40 bit word on success, a | |
60 | negative error code on failure. */ | |
61 | virtual W40_t ConcatW40(size_t n, const W10_t& w) const; | |
62 | /** Extract a 10 bit word from a 40 bit word | |
63 | @param n The number 10bit word to extract (0-3) | |
64 | @param w 40 bit word to extract from. | |
65 | @return The 10 bit word at @a n of @a w on success, or a | |
66 | negative error code otherwise. */ | |
67 | virtual W10_t ExtractW10(size_t n, const W40_t w) const; | |
68 | ||
69 | ClassDef(AliFMDAltroIO,0); | |
70 | }; | |
71 | ||
72 | //____________________________________________________________________ | |
73 | class AliFMDAltroReader : public AliFMDAltroIO | |
74 | { | |
75 | public: | |
76 | /** Constructor | |
77 | @param filename File to read from | |
78 | @exception Int_t A negative error code in case of failure */ | |
79 | AliFMDAltroReader(std::istream& stream); | |
80 | virtual ~AliFMDAltroReader() {} | |
81 | /** Read one channel from the input file. Note, that channels are | |
82 | read from the back of the file. | |
83 | @param board On return, the FEC board number | |
84 | @param chip On return, the ALTRO chip number | |
85 | @param channel On return, the ALTRO channel number | |
86 | @param last On return, the size of the data | |
87 | @param data An array to fill with the data. note, this | |
88 | should be large enough to hold all the data (1024 is the maximum | |
89 | number of timebins that can be read, so that's a safe size). | |
90 | @return negative error code on failure, 0 if nothing is read, or | |
91 | the number of 10 bit words read. */ | |
92 | Int_t ReadChannel(UShort_t& board, UShort_t& chip, UShort_t& channel, | |
93 | UShort_t& last, UShort_t* data); | |
94 | /** Read one channel from the input file. Note, that channels are | |
95 | read from the back of the file. | |
96 | @param hwaddr On return, the hardware address | |
97 | @param last On return, the size of the data | |
98 | @param data An array to fill with the data. note, this | |
99 | should be large enough to hold all the data (1024 is the maximum | |
100 | number of timebins that can be read, so that's a safe size). | |
101 | @return negative error code on failure, 0 if nothing is read, or | |
102 | the number of 10 bit words read. */ | |
103 | Int_t ReadChannel(UShort_t& hwaddr, UShort_t& last, UShort_t* data); | |
104 | /** Extract the channel trailer. | |
105 | @param hwaddr On return, the hardware address | |
106 | @param last On return, the size of the data | |
107 | @return negative error code on failure, 0 if nothing is read, or | |
108 | the number of 10 bit words read. */ | |
109 | Int_t ExtractTrailer(UShort_t& hwaddr, UShort_t& last); | |
110 | /** Extract bunches from data section of a channel. | |
111 | @param last Pointer to last meaning full data entry. | |
112 | @param data An array to fill with the read data. | |
113 | @return negative error code on failure, otherwise number of 10 | |
114 | bit words read. */ | |
115 | Int_t ExtractBunches(UShort_t last, UShort_t* data); | |
116 | /** Extract possible fill words. | |
117 | @param last Pointer to last meaning full data entry. | |
118 | @return Negative error code on failure, otherwise number of fill | |
119 | words read. */ | |
120 | Int_t ExtractFillWords(UShort_t last); | |
121 | /** Extract bunch information from data. | |
122 | @param data An array to fill with the read data. | |
123 | @return negative error code on failure, otherwise number of 10 | |
124 | bit words read. */ | |
125 | Int_t ExtractBunch(UShort_t* data); | |
126 | /** Check if @a x is a valid trailer | |
127 | @param x 40 bit word to check. | |
128 | @return @c true if @a x is a valid trailer */ | |
129 | Bool_t IsTrailer(W40_t x); | |
130 | /** @return @c true if we're at the beginning of the file */ | |
131 | Bool_t IsBof(); | |
132 | protected: | |
133 | /** Input stream */ | |
134 | std::istream& fInput; | |
135 | /** Current position in file */ | |
136 | // std::istream::pos_type | |
137 | size_t fCurrent; | |
138 | /** High water mark */ | |
139 | size_t fBegin; | |
140 | ||
141 | /** Read a 40 bit word from the input. | |
142 | @return negative error code on failure, current position otherwise. */ | |
143 | virtual Int_t ReadW40(); | |
144 | /** Get a 10 bit word from the (buffered) input. | |
145 | @return 10 bit word on success, negative error code on failure. */ | |
146 | virtual W10_t GetNextW10(); | |
147 | /** Get the next 40 bit word from the (buffered) input. | |
148 | @return The 40 bit word, or negative error code on failure */ | |
149 | virtual W40_t GetNextW40(); | |
150 | ||
151 | ClassDef(AliFMDAltroReader,0); | |
152 | }; | |
153 | ||
154 | //____________________________________________________________________ | |
155 | class AliFMDAltroWriter : public AliFMDAltroIO | |
156 | { | |
157 | public: | |
158 | /** Constructor. | |
159 | @param filename File to read from | |
160 | @exception Int_t A negative error code in case of failure */ | |
161 | AliFMDAltroWriter(std::ostream& stream); | |
162 | virtual ~AliFMDAltroWriter() {} | |
163 | /** @param threshold Zero-suppresion threshold */ | |
164 | void SetThreshold(UShort_t threshold) { fThreshold = threshold; } | |
165 | /** Close the output, by writing the appropriate header. The actual | |
166 | stream should be called by the user. | |
167 | @return number of bytes written, or negative error code on failure */ | |
168 | Int_t Close(); | |
169 | /** Flush buffered output to file (if there is any). | |
170 | @return 0, or negative error code on failure */ | |
171 | Int_t Flush(); | |
172 | /** Add a signal to output. If the signal @a adc is less then the | |
173 | current threshold, a new bunch trailer is written. | |
174 | @param adc Signal | |
175 | @return 0 on success, or negative error code on failure */ | |
176 | Int_t AddSignal(UShort_t adc); | |
177 | /** Write a channel trailer to output. | |
178 | @param board The FEC board number (0-31) | |
179 | @param chip The ALTRO chip number (0-7) | |
180 | @param channel The ALTRO channel number (0-16) | |
181 | @return Number of 10 bit words written, or negative error code | |
182 | on failure */ | |
183 | Int_t AddChannelTrailer(UShort_t board, UShort_t chip, UShort_t channel); | |
184 | /** Write a channel trailer to output. | |
185 | @param hwaddr Hardware address (channel address) | |
186 | @return Number of 10 bit words written, or negative error code | |
187 | on failure */ | |
188 | Int_t AddChannelTrailer(UInt_t hwaddr); | |
189 | protected: | |
190 | /** Add a value to output buffer. | |
191 | @param x Value to add. | |
192 | @return number of 10 bit words written to disk, or negative | |
193 | error code on failure */ | |
194 | Int_t AddToBuffer(UShort_t x); | |
195 | /** Add a bunch trailer to output. | |
196 | @return number of 10 bit words written to disk, or negative | |
197 | error code on failure */ | |
198 | Int_t AddBunchTrailer(); | |
199 | /** Add fill words as needed to output | |
200 | @return number of 10 bit words written to disk, or negative | |
201 | error code on failure */ | |
202 | Int_t AddFillWords(); | |
203 | /** Zero suppression threshold */ | |
204 | UShort_t fThreshold; | |
205 | /** Current time */ | |
206 | UShort_t fTime; | |
207 | /** Current bunch length */ | |
208 | UShort_t fLength; | |
209 | /** Last meaning-full data */ | |
210 | UShort_t fLast; | |
211 | /** High-water mark (begining of file) */ | |
212 | size_t fBegin; | |
213 | /** High-water mark (begining of file) */ | |
214 | size_t fHeader; | |
215 | /** Total number of bytes written */ | |
216 | Long_t fTotal; | |
217 | /** output stream */ | |
218 | std::ostream& fOutput; | |
219 | ||
220 | ClassDef(AliFMDAltroWriter,0); | |
221 | }; | |
222 | ||
223 | ||
224 | ||
225 | #endif | |
226 | //____________________________________________________________________ | |
227 | // | |
228 | // Local Variables: | |
229 | // mode: C++ | |
230 | // End: | |
231 | // | |
232 | // EOF | |
233 | // |