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