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