]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDAltroIO.h
No need to liknk with lhapdf, pythia6 and microcern libraries
[u/mrichter/AliRoot.git] / FMD / AliFMDAltroIO.h
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 /** @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
14 */
15 #include <iosfwd>
16 #include <TObject.h>
17
18 //____________________________________________________________________
19 /** @class AliFMDAltroIO AliFMDAltroIO.h <FMD/AliFMDAltroIO.h>
20     @brief Base class for ALTRO Input/Output classes.
21     @ingroup FMD_base
22  */
23 class AliFMDAltroIO  : public TObject
24 {
25 public:
26   /** Type of 40 bit words (signed) */
27   typedef long long W40_t;
28   /** Type of 10 bit words (signed) */
29   typedef Int_t W10_t;
30   /** Constructor */
31   AliFMDAltroIO();
32   /** Destructor */
33   virtual ~AliFMDAltroIO() {}
34   /** Error states */
35   enum {
36     /** No error */
37     kNoError,
38     /** Bad state after open/close file */
39     kBadFile,
40     /** Bad bit offset specified */
41     kBadBits, 
42     /** Bad state after reading from file */
43     kBadRead, 
44     /** Bad state after writing to file */
45     kBadWrite, 
46     /** Bad state after seeking in file */
47     kBadSeek, 
48     /** Could not tell position in file */
49     kBadTell, 
50     /** Bad trailer 40 bit word in file */
51     kBadTrailer, 
52     /** Bad fill word in file */
53     kBadFill
54   };
55   /** Trailer mask */
56   static const W40_t  fgkTrailerMask;
57   /** Get error string */ 
58   const char* ErrorString(Int_t err)  const;
59 protected:
60   /** I/O Buffer */
61   W40_t fBuffer;
62   /** Pointer into buffer */
63   Int_t fIBuffer;
64
65   /** Concatenate a 10 bit word into a 40 bit word.
66       @param n Offset (0-3)
67       @param w 10 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;
77
78   ClassDef(AliFMDAltroIO,0);
79 };
80
81 //____________________________________________________________________
82 /** @class AliFMDAltroReader AliFMDAltroIO.h <FMD/AliFMDAltroIO.h>
83     @brief Class to read ALTRO formated raw data from an AliRawReader
84     object. 
85     @code 
86     AliRawReader*    reader    = new AliRawReaderFile(0);
87     AliFMDRawReader* fmdReader = new AliFMDRawReader(reader);
88     TClonesArray*    array     = new TClonesArray("AliFMDDigit");
89     fmdReader->ReadAdcs(array);
90     @endcode 
91 */
92 class AliFMDAltroReader : public AliFMDAltroIO
93 {
94 public:
95   /** Constructor 
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
133       bit words read.  */
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
138       words read. */
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
143       bit words read.  */
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 */
150   Bool_t IsBof();
151 protected:
152   /** Input stream */
153   std::istream& fInput;
154   /** Current position in file */
155   // std::istream::pos_type 
156   UShort_t fCurrent;
157   /** High water mark */
158   UShort_t fBegin;
159   
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();
169
170   ClassDef(AliFMDAltroReader,0);
171 };
172
173 //____________________________________________________________________
174 /** @class AliFMDAltroWriter AliFMDAltroIO.h <FMD/AliFMDAltroIO.h>
175     @brief Class to write ALTRO formated raw data from an array of
176     AliFMDDigit objects.
177     @code 
178     AliFMDRawWriter* fmdWriter = new AliFMDRawWriter(0);
179     TClonesArray*    array     = fmd->DigitArray();
180     fmdWriter->WriteDigits(array);
181     @endcode 
182  */
183 class AliFMDAltroWriter : public AliFMDAltroIO
184 {
185 public:
186   /** Constructor.
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  */
196   Int_t Close();
197   /** Flush buffered output to file (if there is any). 
198       @return  0, or negative error code on failure */
199   Int_t Flush();
200   /** Add a signal to output.   If the signal @a adc is less then the
201       current threshold, a new bunch trailer is written. 
202       @param adc Signal
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
210       on failure  */ 
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
215       on failure */
216   Int_t AddChannelTrailer(UInt_t hwaddr);
217 protected:
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 */
232   UShort_t fThreshold;
233   /** Current time */
234   UShort_t fTime;
235   /** Current bunch length */
236   UShort_t fLength;
237   /** Last meaning-full data */
238   UShort_t fLast;
239   /** High-water mark (begining of file) */
240   UShort_t fBegin;
241   /** High-water mark (begining of file) */
242   UShort_t fHeader;
243   /** Total number of bytes written */
244   Long_t fTotal;
245   /** output stream */
246   std::ostream& fOutput;
247
248   ClassDef(AliFMDAltroWriter,0);
249 };
250
251
252
253 #endif
254 //____________________________________________________________________
255 //
256 // Local Variables:
257 //   mode: C++
258 // End:
259 //
260 // EOF
261 //