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