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