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