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