1 #ifndef ALIFMDALTROIO_H
2 #define ALIFMDALTROIO_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights
6 * Latest changes by Christian Holm Christensen <cholm@nbi.dk>
8 * See cxx source for full Copyright notice
10 /** @file AliFMDAltroIO.h
11 @author Christian Holm Christensen <cholm@nbi.dk>
12 @date Sun Mar 26 18:27:31 2006
13 @brief ALTRO Input/output
18 //____________________________________________________________________
19 /** @class AliFMDAltroIO AliFMDAltroIO.h <FMD/AliFMDAltroIO.h>
20 @brief Base class for ALTRO Input/Output classes.
23 class AliFMDAltroIO : public TObject
26 /** Type of 40 bit words (signed) */
27 typedef long long W40_t;
28 /** Type of 10 bit words (signed) */
33 virtual ~AliFMDAltroIO() {}
38 /** Bad state after open/close file */
40 /** Bad bit offset specified */
42 /** Bad state after reading from file */
44 /** Bad state after writing to file */
46 /** Bad state after seeking in file */
48 /** Could not tell position in file */
50 /** Bad trailer 40 bit word in file */
52 /** Bad fill word in file */
56 static const W40_t fgkTrailerMask;
57 /** Get error string */
58 const char* ErrorString(Int_t err) const;
62 /** Pointer into buffer */
65 /** Concatenate a 10 bit word into a 40 bit word.
68 @return @a w at offset @a n in a 40 bit word on success, a
69 negative error code on failure. */
70 virtual W40_t ConcatW40(UShort_t n, const W10_t& w) const;
71 /** Extract a 10 bit word from a 40 bit word
72 @param n The number 10bit word to extract (0-3)
73 @param w 40 bit word to extract from.
74 @return The 10 bit word at @a n of @a w on success, or a
75 negative error code otherwise. */
76 virtual W10_t ExtractW10(UShort_t n, const W40_t w) const;
78 ClassDef(AliFMDAltroIO,0);
81 //____________________________________________________________________
82 /** @class AliFMDAltroReader AliFMDAltroIO.h <FMD/AliFMDAltroIO.h>
83 @brief Class to read ALTRO formated raw data from an AliRawReader
86 AliRawReader* reader = new AliRawReaderFile(0);
87 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader);
88 TClonesArray* array = new TClonesArray("AliFMDDigit");
89 fmdReader->ReadAdcs(array);
92 class AliFMDAltroReader : public AliFMDAltroIO
96 @param stream Stream to read from
97 @exception Int_t A negative error code in case of failure */
98 AliFMDAltroReader(std::istream& stream);
99 virtual ~AliFMDAltroReader() {}
100 /** Read one channel from the input file. Note, that channels are
101 read from the back of the file.
102 @param board On return, the FEC board number
103 @param chip On return, the ALTRO chip number
104 @param channel On return, the ALTRO channel number
105 @param last On return, the size of the data
106 @param data An array to fill with the data. note, this
107 should be large enough to hold all the data (1024 is the maximum
108 number of timebins that can be read, so that's a safe size).
109 @return negative error code on failure, 0 if nothing is read, or
110 the number of 10 bit words read. */
111 Int_t ReadChannel(UShort_t& board, UShort_t& chip, UShort_t& channel,
112 UShort_t& last, UShort_t* data);
113 /** Read one channel from the input file. Note, that channels are
114 read from the back of the file.
115 @param hwaddr On return, the hardware address
116 @param last On return, the size of the data
117 @param data An array to fill with the data. note, this
118 should be large enough to hold all the data (1024 is the maximum
119 number of timebins that can be read, so that's a safe size).
120 @return negative error code on failure, 0 if nothing is read, or
121 the number of 10 bit words read. */
122 Int_t ReadChannel(UShort_t& hwaddr, UShort_t& last, UShort_t* data);
123 /** Extract the channel trailer.
124 @param hwaddr On return, the hardware address
125 @param last On return, the size of the data
126 @return negative error code on failure, 0 if nothing is read, or
127 the number of 10 bit words read. */
128 Int_t ExtractTrailer(UShort_t& hwaddr, UShort_t& last);
129 /** Extract bunches from data section of a channel.
130 @param last Pointer to last meaning full data entry.
131 @param data An array to fill with the read data.
132 @return negative error code on failure, otherwise number of 10
134 Int_t ExtractBunches(UShort_t last, UShort_t* data);
135 /** Extract possible fill words.
136 @param last Pointer to last meaning full data entry.
137 @return Negative error code on failure, otherwise number of fill
139 Int_t ExtractFillWords(UShort_t last);
140 /** Extract bunch information from data.
141 @param data An array to fill with the read data.
142 @return negative error code on failure, otherwise number of 10
144 Int_t ExtractBunch(UShort_t* data);
145 /** Check if @a x is a valid trailer
146 @param x 40 bit word to check.
147 @return @c true if @a x is a valid trailer */
148 Bool_t IsTrailer(W40_t x);
149 /** @return @c true if we're at the beginning of the file */
153 std::istream& fInput;
154 /** Current position in file */
155 // std::istream::pos_type
157 /** High water mark */
160 /** Read a 40 bit word from the input.
161 @return negative error code on failure, current position otherwise. */
162 virtual Int_t ReadW40();
163 /** Get a 10 bit word from the (buffered) input.
164 @return 10 bit word on success, negative error code on failure. */
165 virtual W10_t GetNextW10();
166 /** Get the next 40 bit word from the (buffered) input.
167 @return The 40 bit word, or negative error code on failure */
168 virtual W40_t GetNextW40();
170 ClassDef(AliFMDAltroReader,0);
173 //____________________________________________________________________
174 /** @class AliFMDAltroWriter AliFMDAltroIO.h <FMD/AliFMDAltroIO.h>
175 @brief Class to write ALTRO formated raw data from an array of
178 AliFMDRawWriter* fmdWriter = new AliFMDRawWriter(0);
179 TClonesArray* array = fmd->DigitArray();
180 fmdWriter->WriteDigits(array);
183 class AliFMDAltroWriter : public AliFMDAltroIO
187 @param stream File to read from
188 @exception Int_t A negative error code in case of failure */
189 AliFMDAltroWriter(std::ostream& stream);
190 virtual ~AliFMDAltroWriter() {}
191 /** @param threshold Zero-suppresion threshold */
192 void SetThreshold(UShort_t threshold) { fThreshold = threshold; }
193 /** Close the output, by writing the appropriate header. The actual
194 stream should be called by the user.
195 @return number of bytes written, or negative error code on failure */
197 /** Flush buffered output to file (if there is any).
198 @return 0, or negative error code on failure */
200 /** Add a signal to output. If the signal @a adc is less then the
201 current threshold, a new bunch trailer is written.
203 @return 0 on success, or negative error code on failure */
204 Int_t AddSignal(UShort_t adc);
205 /** Write a channel trailer to output.
206 @param board The FEC board number (0-31)
207 @param chip The ALTRO chip number (0-7)
208 @param channel The ALTRO channel number (0-16)
209 @return Number of 10 bit words written, or negative error code
211 Int_t AddChannelTrailer(UShort_t board, UShort_t chip, UShort_t channel);
212 /** Write a channel trailer to output.
213 @param hwaddr Hardware address (channel address)
214 @return Number of 10 bit words written, or negative error code
216 Int_t AddChannelTrailer(UInt_t hwaddr);
218 /** Add a value to output buffer.
219 @param x Value to add.
220 @return number of 10 bit words written to disk, or negative
221 error code on failure */
222 Int_t AddToBuffer(UShort_t x);
223 /** Add a bunch trailer to output.
224 @return number of 10 bit words written to disk, or negative
225 error code on failure */
226 Int_t AddBunchTrailer();
227 /** Add fill words as needed to output
228 @return number of 10 bit words written to disk, or negative
229 error code on failure */
230 Int_t AddFillWords();
231 /** Zero suppression threshold */
235 /** Current bunch length */
237 /** Last meaning-full data */
239 /** High-water mark (begining of file) */
241 /** High-water mark (begining of file) */
243 /** Total number of bytes written */
246 std::ostream& fOutput;
248 ClassDef(AliFMDAltroWriter,0);
254 //____________________________________________________________________