]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONBusStruct.cxx
Coverity 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 /// \cond CLASSIMP
37 ClassImp(AliMUONBusStruct)
38 /// \endcond
39
40 const Int_t  AliMUONBusStruct::fgkHeaderLength = 4;
41 const UInt_t AliMUONBusStruct::fgkDefaultDataKey = 0xB000000B;
42 const Int_t  AliMUONBusStruct::fgkManuNofChannels(64);
43
44 //___________________________________________
45 AliMUONBusStruct::AliMUONBusStruct()
46   :  TObject(),
47      fDataKey(0),
48      fTotalLength(0),
49      fLength(0),
50      fBusPatchId(0),
51 fBufSize(43*fgkManuNofChannels), 
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]),
55      fDspId(0),
56      fBlkId(0)
57 {
58   ///
59   /// ctor
60   /// 
61
62 }
63 //___________________________________________
64 AliMUONBusStruct::~AliMUONBusStruct()
65 {
66   ///
67   /// dtor
68   ///
69   delete[] fData;
70 }
71
72 //___________________________________________
73 void AliMUONBusStruct::SetAlloc(Int_t size)
74 {
75   ///
76   /// Allocate size 
77   /// return if size < fBufSize 
78   ///
79   if (size < fBufSize) 
80     return;
81   else 
82     ResizeData(size);
83 }
84 //___________________________________________
85 void AliMUONBusStruct::AddData(UInt_t data)
86 {
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 ?
90   if (fLength == fBufSize) 
91     ResizeData();
92   fData[fLength++] = data;
93   fTotalLength = fLength + fgkHeaderLength;
94 }
95
96 //___________________________________________
97 void AliMUONBusStruct::ResizeData(Int_t size)
98 {
99   /// In case of resizing the vector
100   /// the most simplest way to do it
101   ///
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 //___________________________________________
113 AliMUONBusStruct::
114 AliMUONBusStruct(const AliMUONBusStruct& event)
115   : TObject(event),
116     fDataKey(event.fDataKey),
117     fTotalLength(event.fTotalLength),
118     fLength(event.fLength),
119     fBusPatchId(event.fBusPatchId),
120     fBufSize(event.fBufSize),
121     fData(new UInt_t[event.fBufSize]),
122     fDspId(event.fDspId),
123     fBlkId(event.fBlkId)
124 {
125   ///
126   /// copy ctor
127   ///
128
129   for (int i = 0; i < event.fBufSize; i++)
130     fData[i] = event.fData[i];
131 }
132 //___________________________________________
133 AliMUONBusStruct&
134 AliMUONBusStruct::operator=(const AliMUONBusStruct& event)
135 {
136   ///
137   /// assignment operator
138   ///
139   if (this == &event) return *this;
140   fDataKey     = event.fDataKey;
141   fTotalLength = event.fTotalLength;
142   fLength      = event.fLength;
143   fBusPatchId  = event.fBusPatchId;
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 //___________________________________________
157 Int_t AliMUONBusStruct::Compare(const TObject *obj) const
158 {
159   /// 
160   /// sort bus patch by bus patch number
161   /// important for AliMUONRawWriter
162   ///
163   AliMUONBusStruct* event = (AliMUONBusStruct*) obj;
164   return (fBusPatchId > event->GetBusPatchId()) ? 1 : -1;
165 }
166
167 //___________________________________________
168 void AliMUONBusStruct::Clear(Option_t *)
169 {
170   /// clear
171   /// delete the allocated memory 
172   ///
173   delete[] fData;
174 }
175 //___________________________________________
176 UInt_t AliMUONBusStruct::GetData(Int_t n) const 
177 {
178   ///
179   /// get data
180   ///
181   if ( n>=0 && n<fLength ) return fData[n];
182
183   AliError("Index outside limits."); 
184   return 0; 
185 }
186
187 //___________________________________________
188 Char_t AliMUONBusStruct::GetParity(Int_t n) const   
189 {
190   ///
191   /// get parity
192   ///
193   if ( n>=0 && n<fLength ) return (Char_t)(fData[n] >> 31) &  0x1;
194
195   AliError("Index outside limits."); 
196   return 0; 
197 }
198
199 //___________________________________________
200 UShort_t AliMUONBusStruct::GetManuId(Int_t n) const     
201 {
202   ///
203   /// get manu Id
204   ///
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 //___________________________________________
212 UChar_t AliMUONBusStruct::GetChannelId(Int_t n) const  
213 {
214   /// 
215   /// get channel Id
216   ///
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 //___________________________________________
224 UShort_t AliMUONBusStruct::GetCharge(Int_t n) const     
225 {
226   ///
227   /// get charge (in ADC)
228   ///
229   if ( n>=0 && n<fLength ) return (UShort_t)(fData[n] & 0xFFF);
230
231   AliError("Index outside limits."); 
232   return 0; 
233 }
234
235 //___________________________________________
236 void 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