Stupid bug fix in new superlight mode (from Zurich airport)
[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///
59087bde 23/// Date: 09/07/2009
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 }
f67db810 113}
114
115
c4d90345 116//______________________________________________________________________________
f67db810 117AliITSModuleDaSSD::AliITSModuleDaSSD(const Int_t numberofstrips, const Long_t eventsnumber) :
118 fEquipId(0),
119 fEquipType(0),
120 fDdlId(0),
121 fAd(0),
122 fAdc(0),
123 fModuleId(0),
124 fNumberOfStrips(0),
125 fStrips(NULL),
c4d90345 126 fNumberOfChips(0),
127 fCm(NULL),
371588bb 128 fCmFerom(NULL),
f67db810 129 fEventsNumber(0)
130{
223dda26 131// Constructor, allocates memory for AliITSChannelDaSSD* and events data
f67db810 132 if (numberofstrips != fgkStripsPerModule)
c4d90345 133 AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i strips", fgkStripsPerModule));
223dda26 134 fStrips = new (nothrow) AliITSChannelDaSSD* [numberofstrips];
135 if (fStrips) {
f67db810 136 fNumberOfStrips = numberofstrips;
223dda26 137 memset(fStrips, 0, numberofstrips * sizeof(AliITSChannelDaSSD*));
138 for (Int_t i = 0; i < fNumberOfStrips; i++) {
139 fStrips[i] = new AliITSChannelDaSSD(i, eventsnumber);
c4d90345 140 if (!fStrips[i]) AliError(Form("AliITSModuleDaSSD: Error allocating memory for AliITSChannelDaSSD %i-th object", i));
223dda26 141 }
142 } else {
c4d90345 143 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", numberofstrips));
f67db810 144 fNumberOfStrips = 0;
145 fStrips = NULL;
f67db810 146 }
147}
148
149
150
c4d90345 151//______________________________________________________________________________
f67db810 152AliITSModuleDaSSD::AliITSModuleDaSSD(const AliITSModuleDaSSD& module) :
153 TObject(module),
154 fEquipId(module.fEquipId),
155 fEquipType(module.fEquipType),
156 fDdlId(module.fDdlId),
157 fAd(module.fAd),
158 fAdc(module.fAdc),
159 fModuleId(module.fModuleId),
160 fNumberOfStrips(module.fNumberOfStrips),
a69c8ba0 161 fStrips(NULL),
c4d90345 162 fNumberOfChips(module.fNumberOfChips),
a69c8ba0 163 fCm(NULL),
371588bb 164 fCmFerom(NULL),
f67db810 165 fEventsNumber(module.fEventsNumber)
166{
223dda26 167// copy constructor
a69c8ba0 168 if ((module.fNumberOfStrips > 0) && (module.fStrips)) {
169 fStrips = new (nothrow) AliITSChannelDaSSD* [module.fNumberOfStrips];
170 if (fStrips) {
171 for (Int_t strind = 0; strind < module.fNumberOfStrips; strind++) {
172 if (module.fStrips[strind]) {
173 fStrips[strind] = new AliITSChannelDaSSD(*(module.fStrips[strind]));
174 if (!fStrips[strind]) {
175 AliError("AliITSModuleDaSSD: Error copy constructor");
176 for (Int_t i = (strind - 1); i >= 0; i--) delete fStrips[strind];
177 delete [] fStrips;
178 fStrips = NULL;
179 break;
180 }
181 } else fStrips[strind] = NULL;
182 }
183 } else {
184 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", module.fNumberOfStrips));
185 fNumberOfStrips = 0;
186 fStrips = NULL;
187 }
188 }
189 if (module.fCm) {
190 fCm = new (nothrow) TArrayF [module.fNumberOfChips];
191 if (fCm) {
192 for (Int_t chind = 0; chind < module.fNumberOfChips; chind++) fCm[chind] = module.fCm[chind];
193 } else {
194 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", module.fNumberOfChips));
195 fNumberOfChips = 0;
196 fCm = NULL;
197 }
371588bb 198 }
199
200 if (module.fCmFerom) {
201 fCmFerom = new (nothrow) TArrayS [fgkChipsPerModule];
202 if (fCmFerom) {
203 for (Int_t chind = 0; chind < fgkChipsPerModule; chind++) fCmFerom[chind] = module.fCmFerom[chind];
204 } else {
205 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
206 fCmFerom = NULL;
207 }
61a57d07 208 }
f67db810 209}
210
211
212
c4d90345 213//______________________________________________________________________________
f67db810 214AliITSModuleDaSSD& AliITSModuleDaSSD::operator = (const AliITSModuleDaSSD& module)
215{
216// assignment operator
a69c8ba0 217 if (this == &module) return *this;
61a57d07 218 TObject::operator=(module);
a69c8ba0 219 if (fStrips) {
220 for (Long_t i = 0; i < fNumberOfStrips; i++) if (fStrips[i]) delete fStrips[i];
221 delete [] fStrips;
61a57d07 222 fStrips = NULL;
a69c8ba0 223 }
224 fEquipId = module.fEquipId;
225 fEquipType = module.fEquipType;
226 fDdlId = module.fDdlId;
227 fAd = module.fAd;
228 fAdc = module.fAdc;
229 fModuleId = module.fModuleId;
a69c8ba0 230 fStrips = NULL;
231 fNumberOfChips = module.fNumberOfChips;
232 fCm = NULL;
233 fEventsNumber = module.fEventsNumber;
234 if ((module.fNumberOfStrips > 0) && (module.fStrips)) {
235 fStrips = new (nothrow) AliITSChannelDaSSD* [module.fNumberOfStrips];
236 if (fStrips) {
61a57d07 237 memset(fStrips, 0, (sizeof(AliITSChannelDaSSD*) * module.fNumberOfStrips));
a69c8ba0 238 for (Int_t strind = 0; strind < module.fNumberOfStrips; strind++) {
239 if (module.fStrips[strind]) {
61a57d07 240 fStrips[strind] = new AliITSChannelDaSSD(*(module.fStrips[strind]));
241 if (!fStrips[strind]) {
242 AliError("AliITSModuleDaSSD: Error copy constructor");
a69c8ba0 243 for (Int_t i = (strind - 1); i >= 0; i--) delete fStrips[strind];
61a57d07 244 delete [] fStrips;
245 fStrips = NULL;
246 fNumberOfStrips = 0;
247 break;
248 }
249 } else fStrips[strind] = NULL;
250 }
251 fNumberOfStrips = module.fNumberOfStrips;
a69c8ba0 252 } else {
253 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", module.fNumberOfStrips));
254 fNumberOfStrips = 0;
255 fStrips = NULL;
256 }
257 }
258 if (fCm) delete [] fCm;
259 if (module.fCm) {
260 fCm = new (nothrow) TArrayF [module.fNumberOfChips];
261 if (fCm) {
262 for (Int_t chind = 0; chind < module.fNumberOfChips; chind++) fCm[chind] = module.fCm[chind];
263 } else {
264 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", module.fNumberOfChips));
265 fNumberOfChips = 0;
266 fCm = NULL;
267 }
268 }
59087bde 269 if (fCmFerom) { delete [] fCmFerom; fCmFerom = NULL; }
371588bb 270 if (module.fCmFerom) {
271 fCmFerom = new (nothrow) TArrayS [module.fNumberOfChips];
272 if (fCmFerom) {
273 for (Int_t chind = 0; chind < fgkChipsPerModule; chind++) fCmFerom[chind] = module.fCmFerom[chind];
274 } else {
275 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
276 fCmFerom = NULL;
277 }
278 }
f67db810 279 return *this;
280}
281
282
283
c4d90345 284//______________________________________________________________________________
f67db810 285AliITSModuleDaSSD::~AliITSModuleDaSSD()
286{
223dda26 287// Destructor
f67db810 288 if (fStrips)
289 {
290 for (Long_t i = 0; i < fNumberOfStrips; i++)
291 {
292 if (fStrips[i]) delete fStrips[i];
f67db810 293 }
294 delete [] fStrips;
295 }
c4d90345 296 if (fCm) delete [] fCm;
371588bb 297 if (fCmFerom) delete [] fCmFerom;
c4d90345 298}
299
300
301
302//______________________________________________________________________________
303Bool_t AliITSModuleDaSSD::SetNumberOfStrips(const Int_t numberofstrips)
304{
305// Allocates memory for AliITSChannelDaSSD*
306 if (fStrips) {
307 for (Int_t i = 0; i < fNumberOfStrips; i++) if (fStrips[i]) delete fStrips[i];
308 delete [] fStrips;
309 fStrips = NULL;
310 }
311 if (numberofstrips <= 0) {fNumberOfStrips = 0; return kTRUE; }
312 if (numberofstrips != fgkStripsPerModule)
313 AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i strips", fgkStripsPerModule));
314 fStrips = new (nothrow) AliITSChannelDaSSD* [numberofstrips];
315 if (fStrips) {
316 fNumberOfStrips = numberofstrips;
317 memset(fStrips, 0, sizeof(AliITSChannelDaSSD*) * numberofstrips);
318 return kTRUE;
319 } else {
320 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", numberofstrips));
321 fNumberOfStrips = 0;
322 fStrips = NULL;
323 return kFALSE;
324 }
f67db810 325}
326
327
c4d90345 328//______________________________________________________________________________
329Bool_t AliITSModuleDaSSD::SetNumberOfChips(const Int_t nchips)
330{
331// Allocate nchips TArrayF objects to save Common Mode
332 DeleteCM();
333 if (nchips <= 0) {fNumberOfChips = 0; return kTRUE; }
334 if (nchips != fgkChipsPerModule)
335 AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i HAL25 chips", fgkChipsPerModule));
336 fCm = new (nothrow) TArrayF [nchips];
337 if (fCm) {
338 fNumberOfChips = nchips;
339 return kTRUE;
340 } else {
341 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", nchips));
342 fNumberOfChips = 0;
343 fCm = NULL;
344 return kFALSE;
345 }
346}
347
f67db810 348
c4d90345 349//______________________________________________________________________________
350Bool_t AliITSModuleDaSSD::SetModuleIdData (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Short_t moduleID)
f67db810 351{
223dda26 352// SetModuleIdData
f67db810 353 if (ad > fgkMaxAdNumber) {
c4d90345 354 AliWarning(Form("AliITSModuleDaSSD: Wrong AD number: %i", ad));
f67db810 355 return kFALSE;
356 }
357 if (adc > fgkMaxAdcNumber || ForbiddenAdcNumber(adc)) {
c4d90345 358 AliWarning(Form("AliITSModuleDaSSD: Wrong ADC number: %i", adc));
f67db810 359 return kFALSE;
360 }
361 fDdlId = ddlID;
362 fAd = ad;
363 fAdc = adc;
364 fModuleId = moduleID;
365 return kTRUE;
366}
367
368
c4d90345 369//______________________________________________________________________________
f67db810 370void AliITSModuleDaSSD::SetModuleFEEId (const UChar_t ddlID, const UChar_t ad, const UChar_t adc)
371{
223dda26 372// Set id data of FEE connected to the Module
f67db810 373 fDdlId = ddlID;
374 fAd = ad;
375 fAdc = adc;
376}
377
378
c4d90345 379//______________________________________________________________________________
f67db810 380void AliITSModuleDaSSD::SetModuleRorcId (const Int_t equipid, const Int_t equiptype)
381{
223dda26 382// Set data to access FEROM registres via DDL
f67db810 383 fEquipId = equipid;
384 fEquipType = equiptype;
385}
386
387
c4d90345 388//______________________________________________________________________________
f67db810 389Bool_t AliITSModuleDaSSD::SetEventsNumber(const Long_t eventsnumber)
390{
00e18e8f 391// Allocate the memory for the events data
f67db810 392 Int_t i;
393 if (!fStrips) return kFALSE;
00e18e8f 394 for (i = 0; i < fNumberOfStrips; i++) {
5af4a2d0 395 if (fStrips[i]) {
00e18e8f 396 if (!fStrips[i]->SetEvenetsNumber(eventsnumber)) {
397 for (Int_t j = 0; j < i; j++) fStrips[j]->DeleteSignal();
a5a317a9 398 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %ld event for module %d, strip %d",eventsnumber, (Int_t)fModuleId, i));
00e18e8f 399 return kFALSE;
400 }
5af4a2d0 401 }
402 else {
00e18e8f 403 if (!(fStrips[i] = new AliITSChannelDaSSD(i, eventsnumber))) {
404 for (Int_t j = 0; j < i; j++) delete fStrips[j];
405 delete [] fStrips;
406 fNumberOfStrips = 0;
407 fStrips = NULL;
c4d90345 408 AliError(Form("AliITSModuleDaSSD: Error allocating memory for strip %i of module %i!", (Int_t)fModuleId, i));
00e18e8f 409 return kFALSE;
410 }
5af4a2d0 411 }
371588bb 412 }
371588bb 413 fEventsNumber = eventsnumber;
f67db810 414 return kTRUE;
415}
416
417
418
c4d90345 419//______________________________________________________________________________
420Bool_t AliITSModuleDaSSD::SetCM (const Float_t cm, const Int_t chipn, const Int_t evn)
421{
422// Set value of CM for a given chip and event
423 if ((!fCm) || (chipn >= fNumberOfChips)) return kFALSE;
424 if (evn >= fCm[chipn].GetSize()) return kFALSE;
425 else fCm[chipn][evn] = cm;
426 return kTRUE;
427}
428
429
430
431//______________________________________________________________________________
432Float_t AliITSModuleDaSSD::GetCM(const Int_t chipn, const Long_t evn) const
433{
434// Get value of CM for a given chip and event
435 if ((!fCm) || (chipn >= fNumberOfChips)) return 0.0f;
436 if (evn >= fCm[chipn].GetSize()) return 0.0f;
437 else return fCm[chipn][evn];
438}
439
440
59087bde 441//______________________________________________________________________________
442Bool_t AliITSModuleDaSSD::AllocateCMFeromArray(void)
443{
444// Allocates memory for the channels which contains CM calculated in Ferom
445 if (!fCmFerom) {
446 fCmFerom = new (nothrow) TArrayS [fgkChipsPerModule];
447 if (!fCmFerom) {
448 AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
449 fCmFerom = NULL;
450 return kFALSE;
451 }
452 }
453 return kTRUE;
454}
455
c4d90345 456
457//______________________________________________________________________________
371588bb 458Bool_t AliITSModuleDaSSD::SetCMFeromEventsNumber(const Long_t eventsnumber)
459{
460// Allocates memory for the values of CM calculated in Ferom
461 if (!fCmFerom) return kFALSE;
462 for (Int_t chipind = 0; chipind < fgkChipsPerModule; chipind++) {
463 fCmFerom[chipind].Set(eventsnumber);
464 fCmFerom[chipind].Reset(0);
465 }
466 return kTRUE;
467}
468
469//______________________________________________________________________________
470Bool_t AliITSModuleDaSSD::SetCMFerom (const Short_t cm, const Int_t chipn, const Int_t evn)
471{
472// Set value of FeromCM for a given chip and event
473 if ((!fCmFerom) || (chipn >= fgkChipsPerModule)) return kFALSE;
474 if (evn >= fCmFerom[chipn].GetSize()) return kFALSE;
475 else fCmFerom[chipn][evn] = cm;
476 return kTRUE;
477}
478
479
59087bde 480void AliITSModuleDaSSD::SetCMFerom (Short_t* cm, const Int_t chipn)
481// Set value of FeromCM for a given chip
482{
483 if (!fCmFerom)
484 if (!AllocateCMFeromArray()) return;
485 if (chipn < fgkChipsPerModule) fCmFerom[chipn].Set(fCmFerom[chipn].GetSize(), cm);
486}
487
371588bb 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