Changes related to the extraction of the V0 finder into a separate class (A. Dainese...
[u/mrichter/AliRoot.git] / ITS / AliITSModuleDaSSD.cxx
CommitLineData
223dda26 1/**************************************************************************
2 * Copyright(c) 2007-2009, 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
371588bb 16/* $Id$ */
223dda26 17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This class provides storage container ITS SSD module callibration data
21/// used by DA.
61a57d07 22///
23/// Date: 18/07/2008
223dda26 24///////////////////////////////////////////////////////////////////////////////
25
26#include "AliITSNoiseSSD.h"
2e2c6def 27#include "AliITSPedestalSSD.h"
28#include "AliITSBadChannelsSSD.h"
f67db810 29#include "AliITSModuleDaSSD.h"
c4d90345 30#include "TString.h"
31#include "AliLog.h"
f67db810 32
33ClassImp(AliITSModuleDaSSD)
34
c4d90345 35
36const Int_t AliITSModuleDaSSD::fgkStripsPerModule = 1536; // Number of strips per SSD module
37const Int_t AliITSModuleDaSSD::fgkPNStripsPerModule = 768; // Number of N/P strips per SSD module
38const Int_t AliITSModuleDaSSD::fgkStripsPerChip = 128; // Number of strips per chip HAL25
39const UChar_t AliITSModuleDaSSD::fgkMaxAdNumber = 9; // MAx SSD FEROM AD number
40const UChar_t AliITSModuleDaSSD::fgkMaxAdcNumber = 13; // MAx SSD FEROM ADC number
41const Int_t AliITSModuleDaSSD::fgkChipsPerModule = 12; // Number of HAL25 chips per SSD module
42
43
44
f67db810 45using namespace std;
46
c4d90345 47//______________________________________________________________________________
f67db810 48AliITSModuleDaSSD::AliITSModuleDaSSD() :
49 fEquipId(0),
50 fEquipType(0),
51 fDdlId(0),
52 fAd(0),
53 fAdc(0),
54 fModuleId(0),
55 fNumberOfStrips(0),
56 fStrips(NULL),
c4d90345 57 fNumberOfChips(0),
58 fCm(NULL),
371588bb 59 fCmFerom(NULL),
f67db810 60 fEventsNumber(0)
61{
223dda26 62// Default constructor
f67db810 63}
64
65
c4d90345 66//______________________________________________________________________________
f67db810 67AliITSModuleDaSSD::AliITSModuleDaSSD(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t moduleID) :
68 fEquipId(0),
69 fEquipType(0),
70 fDdlId(ddlID),
71 fAd(ad),
72 fAdc(adc),
73 fModuleId(moduleID),
74 fNumberOfStrips(0),
75 fStrips(NULL),
c4d90345 76 fNumberOfChips(0),
77 fCm(NULL),
371588bb 78 fCmFerom(NULL),
f67db810 79 fEventsNumber(0)
80{
223dda26 81// Constructor, set module id data
f67db810 82}
83
84
85
c4d90345 86//______________________________________________________________________________
f67db810 87AliITSModuleDaSSD::AliITSModuleDaSSD(const Int_t numberofstrips) :
88 fEquipId(0),
89 fEquipType(0),
90 fDdlId(0),
91 fAd(0),
92 fAdc(0),
93 fModuleId(0),
94 fNumberOfStrips(0),
95 fStrips(NULL),
c4d90345 96 fNumberOfChips(0),
97 fCm(NULL),
371588bb 98 fCmFerom(NULL),
f67db810 99 fEventsNumber(0)
100{
371588bb 101// Constructor, allocates memory for AliITSChannelDaSSD* and TArrayS* array for CM calculated in FEROM
f67db810 102 if (numberofstrips != fgkStripsPerModule)
c4d90345 103 AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i strips", fgkStripsPerModule));
223dda26 104 fStrips = new (nothrow) AliITSChannelDaSSD* [numberofstrips];
105 if (fStrips) {
f67db810 106 fNumberOfStrips = numberofstrips;
107 for (Int_t i = 0; i < numberofstrips; i++) fStrips[i]= NULL;
223dda26 108 } else {
c4d90345 109 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", numberofstrips));
f67db810 110 fNumberOfStrips = 0;
111 fStrips = NULL;
223dda26 112 }
371588bb 113 fCmFerom = new (nothrow) TArrayS [fgkChipsPerModule];
114 if (!fCmFerom) {
115 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
116 fCmFerom = NULL;
117 }
f67db810 118}
119
120
c4d90345 121//______________________________________________________________________________
f67db810 122AliITSModuleDaSSD::AliITSModuleDaSSD(const Int_t numberofstrips, const Long_t eventsnumber) :
123 fEquipId(0),
124 fEquipType(0),
125 fDdlId(0),
126 fAd(0),
127 fAdc(0),
128 fModuleId(0),
129 fNumberOfStrips(0),
130 fStrips(NULL),
c4d90345 131 fNumberOfChips(0),
132 fCm(NULL),
371588bb 133 fCmFerom(NULL),
f67db810 134 fEventsNumber(0)
135{
223dda26 136// Constructor, allocates memory for AliITSChannelDaSSD* and events data
f67db810 137 if (numberofstrips != fgkStripsPerModule)
c4d90345 138 AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i strips", fgkStripsPerModule));
223dda26 139 fStrips = new (nothrow) AliITSChannelDaSSD* [numberofstrips];
140 if (fStrips) {
f67db810 141 fNumberOfStrips = numberofstrips;
223dda26 142 memset(fStrips, 0, numberofstrips * sizeof(AliITSChannelDaSSD*));
143 for (Int_t i = 0; i < fNumberOfStrips; i++) {
144 fStrips[i] = new AliITSChannelDaSSD(i, eventsnumber);
c4d90345 145 if (!fStrips[i]) AliError(Form("AliITSModuleDaSSD: Error allocating memory for AliITSChannelDaSSD %i-th object", i));
223dda26 146 }
147 } else {
c4d90345 148 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", numberofstrips));
f67db810 149 fNumberOfStrips = 0;
150 fStrips = NULL;
f67db810 151 }
371588bb 152 fCmFerom = new (nothrow) TArrayS [fgkChipsPerModule];
153 if (fCmFerom) {
154 for (Int_t i = 0; i < fgkChipsPerModule; i++) {
155 fCmFerom[i].Set(eventsnumber);
156 fCmFerom[i].Reset(0);
157 }
158 }
159 else {
160 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
161 fCmFerom = NULL;
162 }
f67db810 163}
164
165
166
c4d90345 167//______________________________________________________________________________
f67db810 168AliITSModuleDaSSD::AliITSModuleDaSSD(const AliITSModuleDaSSD& module) :
169 TObject(module),
170 fEquipId(module.fEquipId),
171 fEquipType(module.fEquipType),
172 fDdlId(module.fDdlId),
173 fAd(module.fAd),
174 fAdc(module.fAdc),
175 fModuleId(module.fModuleId),
176 fNumberOfStrips(module.fNumberOfStrips),
a69c8ba0 177 fStrips(NULL),
c4d90345 178 fNumberOfChips(module.fNumberOfChips),
a69c8ba0 179 fCm(NULL),
371588bb 180 fCmFerom(NULL),
f67db810 181 fEventsNumber(module.fEventsNumber)
182{
223dda26 183// copy constructor
a69c8ba0 184 if ((module.fNumberOfStrips > 0) && (module.fStrips)) {
185 fStrips = new (nothrow) AliITSChannelDaSSD* [module.fNumberOfStrips];
186 if (fStrips) {
187 for (Int_t strind = 0; strind < module.fNumberOfStrips; strind++) {
188 if (module.fStrips[strind]) {
189 fStrips[strind] = new AliITSChannelDaSSD(*(module.fStrips[strind]));
190 if (!fStrips[strind]) {
191 AliError("AliITSModuleDaSSD: Error copy constructor");
192 for (Int_t i = (strind - 1); i >= 0; i--) delete fStrips[strind];
193 delete [] fStrips;
194 fStrips = NULL;
195 break;
196 }
197 } else fStrips[strind] = NULL;
198 }
199 } else {
200 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", module.fNumberOfStrips));
201 fNumberOfStrips = 0;
202 fStrips = NULL;
203 }
204 }
205 if (module.fCm) {
206 fCm = new (nothrow) TArrayF [module.fNumberOfChips];
207 if (fCm) {
208 for (Int_t chind = 0; chind < module.fNumberOfChips; chind++) fCm[chind] = module.fCm[chind];
209 } else {
210 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", module.fNumberOfChips));
211 fNumberOfChips = 0;
212 fCm = NULL;
213 }
371588bb 214 }
215
216 if (module.fCmFerom) {
217 fCmFerom = new (nothrow) TArrayS [fgkChipsPerModule];
218 if (fCmFerom) {
219 for (Int_t chind = 0; chind < fgkChipsPerModule; chind++) fCmFerom[chind] = module.fCmFerom[chind];
220 } else {
221 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
222 fCmFerom = NULL;
223 }
61a57d07 224 }
f67db810 225}
226
227
228
c4d90345 229//______________________________________________________________________________
f67db810 230AliITSModuleDaSSD& AliITSModuleDaSSD::operator = (const AliITSModuleDaSSD& module)
231{
232// assignment operator
a69c8ba0 233 if (this == &module) return *this;
61a57d07 234 TObject::operator=(module);
a69c8ba0 235 if (fStrips) {
236 for (Long_t i = 0; i < fNumberOfStrips; i++) if (fStrips[i]) delete fStrips[i];
237 delete [] fStrips;
61a57d07 238 fStrips = NULL;
a69c8ba0 239 }
240 fEquipId = module.fEquipId;
241 fEquipType = module.fEquipType;
242 fDdlId = module.fDdlId;
243 fAd = module.fAd;
244 fAdc = module.fAdc;
245 fModuleId = module.fModuleId;
a69c8ba0 246 fStrips = NULL;
247 fNumberOfChips = module.fNumberOfChips;
248 fCm = NULL;
249 fEventsNumber = module.fEventsNumber;
250 if ((module.fNumberOfStrips > 0) && (module.fStrips)) {
251 fStrips = new (nothrow) AliITSChannelDaSSD* [module.fNumberOfStrips];
252 if (fStrips) {
61a57d07 253 memset(fStrips, 0, (sizeof(AliITSChannelDaSSD*) * module.fNumberOfStrips));
a69c8ba0 254 for (Int_t strind = 0; strind < module.fNumberOfStrips; strind++) {
255 if (module.fStrips[strind]) {
61a57d07 256 fStrips[strind] = new AliITSChannelDaSSD(*(module.fStrips[strind]));
257 if (!fStrips[strind]) {
258 AliError("AliITSModuleDaSSD: Error copy constructor");
a69c8ba0 259 for (Int_t i = (strind - 1); i >= 0; i--) delete fStrips[strind];
61a57d07 260 delete [] fStrips;
261 fStrips = NULL;
262 fNumberOfStrips = 0;
263 break;
264 }
265 } else fStrips[strind] = NULL;
266 }
267 fNumberOfStrips = module.fNumberOfStrips;
a69c8ba0 268 } else {
269 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", module.fNumberOfStrips));
270 fNumberOfStrips = 0;
271 fStrips = NULL;
272 }
273 }
274 if (fCm) delete [] fCm;
275 if (module.fCm) {
276 fCm = new (nothrow) TArrayF [module.fNumberOfChips];
277 if (fCm) {
278 for (Int_t chind = 0; chind < module.fNumberOfChips; chind++) fCm[chind] = module.fCm[chind];
279 } else {
280 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", module.fNumberOfChips));
281 fNumberOfChips = 0;
282 fCm = NULL;
283 }
284 }
371588bb 285 if (fCmFerom) delete [] fCmFerom;
286 if (module.fCmFerom) {
287 fCmFerom = new (nothrow) TArrayS [module.fNumberOfChips];
288 if (fCmFerom) {
289 for (Int_t chind = 0; chind < fgkChipsPerModule; chind++) fCmFerom[chind] = module.fCmFerom[chind];
290 } else {
291 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
292 fCmFerom = NULL;
293 }
294 }
f67db810 295 return *this;
296}
297
298
299
c4d90345 300//______________________________________________________________________________
f67db810 301AliITSModuleDaSSD::~AliITSModuleDaSSD()
302{
223dda26 303// Destructor
f67db810 304 if (fStrips)
305 {
306 for (Long_t i = 0; i < fNumberOfStrips; i++)
307 {
308 if (fStrips[i]) delete fStrips[i];
f67db810 309 }
310 delete [] fStrips;
311 }
c4d90345 312 if (fCm) delete [] fCm;
371588bb 313 if (fCmFerom) delete [] fCmFerom;
c4d90345 314}
315
316
317
318//______________________________________________________________________________
319Bool_t AliITSModuleDaSSD::SetNumberOfStrips(const Int_t numberofstrips)
320{
321// Allocates memory for AliITSChannelDaSSD*
322 if (fStrips) {
323 for (Int_t i = 0; i < fNumberOfStrips; i++) if (fStrips[i]) delete fStrips[i];
324 delete [] fStrips;
325 fStrips = NULL;
326 }
327 if (numberofstrips <= 0) {fNumberOfStrips = 0; return kTRUE; }
328 if (numberofstrips != fgkStripsPerModule)
329 AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i strips", fgkStripsPerModule));
330 fStrips = new (nothrow) AliITSChannelDaSSD* [numberofstrips];
331 if (fStrips) {
332 fNumberOfStrips = numberofstrips;
333 memset(fStrips, 0, sizeof(AliITSChannelDaSSD*) * numberofstrips);
334 return kTRUE;
335 } else {
336 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", numberofstrips));
337 fNumberOfStrips = 0;
338 fStrips = NULL;
339 return kFALSE;
340 }
f67db810 341}
342
343
c4d90345 344//______________________________________________________________________________
345Bool_t AliITSModuleDaSSD::SetNumberOfChips(const Int_t nchips)
346{
347// Allocate nchips TArrayF objects to save Common Mode
348 DeleteCM();
349 if (nchips <= 0) {fNumberOfChips = 0; return kTRUE; }
350 if (nchips != fgkChipsPerModule)
351 AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i HAL25 chips", fgkChipsPerModule));
352 fCm = new (nothrow) TArrayF [nchips];
353 if (fCm) {
354 fNumberOfChips = nchips;
355 return kTRUE;
356 } else {
357 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", nchips));
358 fNumberOfChips = 0;
359 fCm = NULL;
360 return kFALSE;
361 }
362}
363
f67db810 364
c4d90345 365//______________________________________________________________________________
366Bool_t AliITSModuleDaSSD::SetModuleIdData (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Short_t moduleID)
f67db810 367{
223dda26 368// SetModuleIdData
f67db810 369 if (ad > fgkMaxAdNumber) {
c4d90345 370 AliWarning(Form("AliITSModuleDaSSD: Wrong AD number: %i", ad));
f67db810 371 return kFALSE;
372 }
373 if (adc > fgkMaxAdcNumber || ForbiddenAdcNumber(adc)) {
c4d90345 374 AliWarning(Form("AliITSModuleDaSSD: Wrong ADC number: %i", adc));
f67db810 375 return kFALSE;
376 }
377 fDdlId = ddlID;
378 fAd = ad;
379 fAdc = adc;
380 fModuleId = moduleID;
381 return kTRUE;
382}
383
384
c4d90345 385//______________________________________________________________________________
f67db810 386void AliITSModuleDaSSD::SetModuleFEEId (const UChar_t ddlID, const UChar_t ad, const UChar_t adc)
387{
223dda26 388// Set id data of FEE connected to the Module
f67db810 389 fDdlId = ddlID;
390 fAd = ad;
391 fAdc = adc;
392}
393
394
c4d90345 395//______________________________________________________________________________
f67db810 396void AliITSModuleDaSSD::SetModuleRorcId (const Int_t equipid, const Int_t equiptype)
397{
223dda26 398// Set data to access FEROM registres via DDL
f67db810 399 fEquipId = equipid;
400 fEquipType = equiptype;
401}
402
403
c4d90345 404//______________________________________________________________________________
f67db810 405Bool_t AliITSModuleDaSSD::SetEventsNumber(const Long_t eventsnumber)
406{
00e18e8f 407// Allocate the memory for the events data
f67db810 408 Int_t i;
409 if (!fStrips) return kFALSE;
00e18e8f 410 for (i = 0; i < fNumberOfStrips; i++) {
5af4a2d0 411 if (fStrips[i]) {
00e18e8f 412 if (!fStrips[i]->SetEvenetsNumber(eventsnumber)) {
413 for (Int_t j = 0; j < i; j++) fStrips[j]->DeleteSignal();
5af4a2d0 414 AliError(Form("AliITSModuleDaSSD: Error allocating memory for i% events for module %i, strip %i",eventsnumber, (Int_t)fModuleId, i));
00e18e8f 415 return kFALSE;
416 }
5af4a2d0 417 }
418 else {
00e18e8f 419 if (!(fStrips[i] = new AliITSChannelDaSSD(i, eventsnumber))) {
420 for (Int_t j = 0; j < i; j++) delete fStrips[j];
421 delete [] fStrips;
422 fNumberOfStrips = 0;
423 fStrips = NULL;
c4d90345 424 AliError(Form("AliITSModuleDaSSD: Error allocating memory for strip %i of module %i!", (Int_t)fModuleId, i));
00e18e8f 425 return kFALSE;
426 }
5af4a2d0 427 }
00e18e8f 428 }
371588bb 429 if (fCmFerom) {
4adcf390 430 for (Int_t ie = 0; ie < fgkChipsPerModule; ie++) {
431 fCmFerom[ie].Set(eventsnumber);
432 fCmFerom[ie].Reset(0);
371588bb 433 }
434 }
435 else AliError("AliITSModuleDaSSD: No memory was allocated for fCmFerom!");
436 fEventsNumber = eventsnumber;
f67db810 437 return kTRUE;
438}
439
440
441
c4d90345 442//______________________________________________________________________________
443Bool_t AliITSModuleDaSSD::SetCM (const Float_t cm, const Int_t chipn, const Int_t evn)
444{
445// Set value of CM for a given chip and event
446 if ((!fCm) || (chipn >= fNumberOfChips)) return kFALSE;
447 if (evn >= fCm[chipn].GetSize()) return kFALSE;
448 else fCm[chipn][evn] = cm;
449 return kTRUE;
450}
451
452
453
454//______________________________________________________________________________
455Float_t AliITSModuleDaSSD::GetCM(const Int_t chipn, const Long_t evn) const
456{
457// Get value of CM for a given chip and event
458 if ((!fCm) || (chipn >= fNumberOfChips)) return 0.0f;
459 if (evn >= fCm[chipn].GetSize()) return 0.0f;
460 else return fCm[chipn][evn];
461}
462
463
464
465//______________________________________________________________________________
371588bb 466Bool_t AliITSModuleDaSSD::SetCMFeromEventsNumber(const Long_t eventsnumber)
467{
468// Allocates memory for the values of CM calculated in Ferom
469 if (!fCmFerom) return kFALSE;
470 for (Int_t chipind = 0; chipind < fgkChipsPerModule; chipind++) {
471 fCmFerom[chipind].Set(eventsnumber);
472 fCmFerom[chipind].Reset(0);
473 }
474 return kTRUE;
475}
476
477//______________________________________________________________________________
478Bool_t AliITSModuleDaSSD::SetCMFerom (const Short_t cm, const Int_t chipn, const Int_t evn)
479{
480// Set value of FeromCM for a given chip and event
481 if ((!fCmFerom) || (chipn >= fgkChipsPerModule)) return kFALSE;
482 if (evn >= fCmFerom[chipn].GetSize()) return kFALSE;
483 else fCmFerom[chipn][evn] = cm;
484 return kTRUE;
485}
486
487
488
489//______________________________________________________________________________
490Short_t AliITSModuleDaSSD::GetCMFerom(const Int_t chipn, const Long_t evn) const
491{
492// Get value of FeromCM for a given chip and event
493 if ((!fCmFerom) || (chipn >= fgkChipsPerModule)) return 0;
494 if (evn >= fCmFerom[chipn].GetSize()) return 0;
495 else return fCmFerom[chipn][evn];
496}
497
498
499
61a57d07 500UChar_t AliITSModuleDaSSD::CheckIfBad(const Int_t stripn) const
2e2c6def 501{
61a57d07 502//Applies the bad channel creteria and set the appropriate flags for returned valie
503 UInt_t bcflags = 0;
504 const UInt_t WOffsetMask = 0x000003FF;
505 if (!fStrips[stripn]) bcflags |= 3;
506 else {
507 if (fStrips[stripn]->GetNoiseCM() == AliITSChannelDaSSD::GetUndefinedValue()) bcflags |= 8;
508 if (fStrips[stripn]->GetNoiseCM() > 20) bcflags |= 8;
509 if (fStrips[stripn]->GetNoiseCM() < 1) bcflags |= 16;
510 if (fStrips[stripn]->GetPedestal() > ((WOffsetMask >> 1) - 1)) bcflags |= 4;
511 else if ((-(fStrips[stripn]->GetPedestal())) > (WOffsetMask >> 1)) bcflags |= 4;
512 if (bcflags) bcflags |= 3;
2e2c6def 513 }
61a57d07 514 return bcflags;
2e2c6def 515}