]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONBusStruct.cxx
typo fix
[u/mrichter/AliRoot.git] / MUON / AliMUONBusStruct.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 #include "AliMUONBusStruct.h"
19
20 #include "AliLog.h"
21 #include <Riostream.h>
22 #include <string.h>
23
24 //-----------------------------------------------------------------------------
25 /// \class AliMUONBusStruct
26 /// Bus patch structure for tracker raw data
27 /// each Dsp contains at most 5 bus patch structure
28 /// Beside the total length and length of the below data
29 /// the header of the block contains the bus patch id, trigger words 
30 /// and data structure itself (11bits for manu id, 6 bits for channel id and
31 /// 12 bits for charge)
32 ///
33 /// \author Christian Finck
34 //-----------------------------------------------------------------------------
35
36 using std::cout;
37 using std::endl;
38 /// \cond CLASSIMP
39 ClassImp(AliMUONBusStruct)
40 /// \endcond
41
42 const Int_t  AliMUONBusStruct::fgkHeaderLength = 4;
43 const UInt_t AliMUONBusStruct::fgkDefaultDataKey = 0xB000000B;
44 const Int_t  AliMUONBusStruct::fgkManuNofChannels(64);
45
46 //___________________________________________
47 AliMUONBusStruct::AliMUONBusStruct()
48   :  TObject(),
49      fDataKey(0),
50      fTotalLength(0),
51      fLength(0),
52      fBusPatchId(0),
53 fBufSize(43*fgkManuNofChannels), 
54   /* assuming 43 manus max per bustpatch.
55   Anyway fData is resized where needed (though it makes it slower) */
56      fData(new UInt_t[fBufSize]),
57      fDspId(0),
58      fBlkId(0)
59 {
60   ///
61   /// ctor
62   /// 
63
64 }
65 //___________________________________________
66 AliMUONBusStruct::~AliMUONBusStruct()
67 {
68   ///
69   /// dtor
70   ///
71   delete[] fData;
72 }
73
74 //___________________________________________
75 void AliMUONBusStruct::SetAlloc(Int_t size)
76 {
77   ///
78   /// Allocate size 
79   /// return if size < fBufSize 
80   ///
81   if (size < fBufSize) 
82     return;
83   else 
84     ResizeData(size);
85 }
86 //___________________________________________
87 void AliMUONBusStruct::AddData(UInt_t data)
88 {
89   /// could have used class from ROOT
90   /// but the structure must be as simple as possible
91   /// to be written on disc blockwise, not so sure ?
92   if (fLength == fBufSize) 
93     ResizeData();
94   fData[fLength++] = data;
95   fTotalLength = fLength + fgkHeaderLength;
96 }
97
98 //___________________________________________
99 void AliMUONBusStruct::ResizeData(Int_t size)
100 {
101   /// In case of resizing the vector
102   /// the most simplest way to do it
103   ///
104   if (size == 0)
105     fBufSize *= 2;
106   else
107     fBufSize = size;
108   UInt_t* newData = new UInt_t[fBufSize];
109   for (Int_t i = 0; i < fLength; i++)
110     newData[i] = fData[i];
111   delete[] fData;
112   fData = newData;
113 }
114 //___________________________________________
115 AliMUONBusStruct::
116 AliMUONBusStruct(const AliMUONBusStruct& event)
117   : TObject(event),
118     fDataKey(event.fDataKey),
119     fTotalLength(event.fTotalLength),
120     fLength(event.fLength),
121     fBusPatchId(event.fBusPatchId),
122     fBufSize(event.fBufSize),
123     fData(new UInt_t[event.fBufSize]),
124     fDspId(event.fDspId),
125     fBlkId(event.fBlkId)
126 {
127   ///
128   /// copy ctor
129   ///
130
131   for (int i = 0; i < event.fBufSize; i++)
132     fData[i] = event.fData[i];
133 }
134 //___________________________________________
135 AliMUONBusStruct&
136 AliMUONBusStruct::operator=(const AliMUONBusStruct& event)
137 {
138   ///
139   /// assignment operator
140   ///
141   if (this == &event) return *this;
142   fDataKey     = event.fDataKey;
143   fTotalLength = event.fTotalLength;
144   fLength      = event.fLength;
145   fBusPatchId  = event.fBusPatchId;
146   fBufSize     = event.fBufSize;
147
148   fBlkId = event.fBlkId;
149   fDspId = event.fDspId;
150
151   delete [] fData;  
152   fData =  new UInt_t[event.fBufSize];
153   for (int i = 0; i < event.fLength; i++)
154     fData[i] = event.fData[i];
155
156   return *this;
157 }
158 //___________________________________________
159 Int_t AliMUONBusStruct::Compare(const TObject *obj) const
160 {
161   /// 
162   /// sort bus patch by bus patch number
163   /// important for AliMUONRawWriter
164   ///
165   AliMUONBusStruct* event = (AliMUONBusStruct*) obj;
166   return (fBusPatchId > event->GetBusPatchId()) ? 1 : -1;
167 }
168
169 //___________________________________________
170 void AliMUONBusStruct::Clear(Option_t *)
171 {
172   /// clear
173   /// delete the allocated memory 
174   ///
175   delete[] fData;
176 }
177 //___________________________________________
178 UInt_t AliMUONBusStruct::GetData(Int_t n) const 
179 {
180   ///
181   /// get data
182   ///
183   if ( n>=0 && n<fLength ) return fData[n];
184
185   AliError("Index outside limits."); 
186   return 0; 
187 }
188
189 //___________________________________________
190 Char_t AliMUONBusStruct::GetParity(Int_t n) const   
191 {
192   ///
193   /// get parity
194   ///
195   if ( n>=0 && n<fLength ) return (Char_t)(fData[n] >> 31) &  0x1;
196
197   AliError("Index outside limits."); 
198   return 0; 
199 }
200
201 //___________________________________________
202 UShort_t AliMUONBusStruct::GetManuId(Int_t n) const     
203 {
204   ///
205   /// get manu Id
206   ///
207   if ( n>=0 && n<fLength ) return (UShort_t)(fData[n] >> 18) &  0x7FF;
208
209   AliError("Index outside limits."); 
210   return 0; 
211 }
212
213 //___________________________________________
214 UChar_t AliMUONBusStruct::GetChannelId(Int_t n) const  
215 {
216   /// 
217   /// get channel Id
218   ///
219   if ( n>=0 && n<fLength ) return (Char_t)(fData[n] >> 12) & 0x3F;
220
221   AliError("Index outside limits."); 
222   return 0; 
223 }
224
225 //___________________________________________
226 UShort_t AliMUONBusStruct::GetCharge(Int_t n) const     
227 {
228   ///
229   /// get charge (in ADC)
230   ///
231   if ( n>=0 && n<fLength ) return (UShort_t)(fData[n] & 0xFFF);
232
233   AliError("Index outside limits."); 
234   return 0; 
235 }
236
237 //___________________________________________
238 void AliMUONBusStruct::Print(Option_t* opt) const
239 {
240   /// print out
241
242   cout << "Bus patch info" << endl;
243   cout << "DataKey: "      << fDataKey << endl;
244   cout << "fTotalLength: " << fTotalLength << endl;
245   cout << "fLength: "      << fLength << endl;
246   cout << "fBusPatchId: "  << fBusPatchId << endl;
247   cout << "fBufSize: "     << fBufSize << endl;
248
249   if (strstr(opt, "all")) {
250   for (Int_t i = 0; i <fLength; ++i)
251       cout << "Data["<< i << "] = " << fData[i] << endl;
252   }
253 }
254
255