]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSHandleDaSSD.cxx
- fixing compilation warnings
[u/mrichter/AliRoot.git] / ITS / AliITSHandleDaSSD.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 ITS SSD data handling
21 /// used by DA. 
22 //  Author: Oleksandr Borysov
23 //  Date: 18/07/2008
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #include <string>
27 #include <fstream>
28 #include <new>
29 #include <Riostream.h> 
30 #include "AliITSHandleDaSSD.h"
31 #include <math.h>
32 #include <limits.h>
33 #include "event.h"
34 #include "TFile.h"
35 #include "TString.h"
36 #include "AliLog.h"
37 #include "AliITSNoiseSSDv2.h"
38 #include "AliITSPedestalSSDv2.h"
39 #include "AliITSBadChannelsSSDv2.h"
40 #include "AliITSRawStreamSSD.h"
41 #include "AliRawReaderDate.h"
42 #include "AliITSRawStreamSSD.h"
43 #include "AliITSChannelDaSSD.h"
44
45
46 ClassImp(AliITSHandleDaSSD)
47
48 using namespace std;
49
50
51 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDModules = 1698;       // Number of SSD modules in ITS
52 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDModulesPerDdl = 108;  // Number of SSD modules in DDL
53 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDModulesPerSlot = 12;  // Number of SSD modules in Slot
54 const Short_t  AliITSHandleDaSSD::fgkMinSSDModuleId = 500;            // Initial SSD modules number
55 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDSlotsPerDDL = 9;      // Number of SSD slots per DDL
56 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDDDLs = 16;            // Number of SSD modules in Slot
57 const Float_t  AliITSHandleDaSSD::fgkPedestalThresholdFactor = 3.0;   // Defalt value for fPedestalThresholdFactor 
58 const Float_t  AliITSHandleDaSSD::fgkCmThresholdFactor = 3.0;         // Defalt value for fCmThresholdFactor
59
60 const UInt_t   AliITSHandleDaSSD::fgkZsBitMask      = 0x0000003F;     // Bit mask for FEROM ZS
61 const UInt_t   AliITSHandleDaSSD::fgkOffSetBitMask  = 0x000003FF;     // Bit mask for FEROM Offset correction
62 const UInt_t   AliITSHandleDaSSD::fgkBadChannelMask = 0x00000001;     // Mask to suppress the channel from the bad channel list
63 const Int_t    AliITSHandleDaSSD::fgkAdcPerDBlock   = 6;              // FEROM configuration file constant
64
65 //______________________________________________________________________________
66 AliITSHandleDaSSD::AliITSHandleDaSSD() :
67   fRawDataFileName(NULL),
68   fNumberOfModules(0),
69   fModules(NULL),
70   fModIndProcessed(0),
71   fModIndRead(0),
72   fModIndex(NULL),
73   fEqIndex(0),
74   fNumberOfEvents(0),
75   fBadChannelsList(NULL),
76   fDDLModuleMap(NULL),
77   fALaddersOff(0),
78   fCLaddersOff(0),
79   fLdcId(0),
80   fRunId(0),
81   fPedestalThresholdFactor(fgkPedestalThresholdFactor),
82   fCmThresholdFactor(fgkCmThresholdFactor),
83   fZsDefault(-1),
84   fOffsetDefault(INT_MAX),
85   fZsMinimum(2),
86   fMergeBCLists(1),
87   fZsFactor(3.0)
88 {
89 // Default constructor
90 }
91
92
93 //______________________________________________________________________________
94 AliITSHandleDaSSD::AliITSHandleDaSSD(Char_t *rdfname) :
95   fRawDataFileName(NULL),
96   fNumberOfModules(0),
97   fModules(NULL),
98   fModIndProcessed(0),
99   fModIndRead(0),
100   fModIndex(NULL),
101   fEqIndex(0),
102   fNumberOfEvents(0),
103   fBadChannelsList(NULL),
104   fDDLModuleMap(NULL),
105   fALaddersOff(0),
106   fCLaddersOff(0),
107   fLdcId(0),
108   fRunId(0),
109   fPedestalThresholdFactor(fgkPedestalThresholdFactor) ,
110   fCmThresholdFactor(fgkCmThresholdFactor),
111   fZsDefault(-1),
112   fOffsetDefault(INT_MAX),
113   fZsMinimum(2),
114   fMergeBCLists(1),
115   fZsFactor(3.0)
116 {
117   if (!Init(rdfname)) AliError("AliITSHandleDaSSD::AliITSHandleDaSSD() initialization error!");
118 }
119
120
121 //______________________________________________________________________________
122 AliITSHandleDaSSD::AliITSHandleDaSSD(const AliITSHandleDaSSD& ssdadldc) :
123   TObject(ssdadldc),
124   fRawDataFileName(ssdadldc.fRawDataFileName),
125   fNumberOfModules(ssdadldc.fNumberOfModules),
126   fModules(NULL),
127   fModIndProcessed(ssdadldc.fModIndProcessed),
128   fModIndRead(ssdadldc.fModIndRead),
129   fModIndex(NULL),
130   fEqIndex(0),
131   fNumberOfEvents(ssdadldc.fNumberOfEvents),
132   fBadChannelsList(NULL),
133   fDDLModuleMap(NULL),
134   fALaddersOff(ssdadldc.fALaddersOff),
135   fCLaddersOff(ssdadldc.fCLaddersOff),
136   fLdcId(ssdadldc.fLdcId),
137   fRunId(ssdadldc.fRunId),
138   fPedestalThresholdFactor(ssdadldc.fPedestalThresholdFactor),
139   fCmThresholdFactor(ssdadldc.fCmThresholdFactor),
140   fZsDefault(ssdadldc.fZsDefault),
141   fOffsetDefault(ssdadldc.fOffsetDefault),
142   fZsMinimum(ssdadldc.fZsMinimum),
143   fMergeBCLists(ssdadldc.fMergeBCLists),
144   fZsFactor(ssdadldc.fZsFactor)
145 {
146   // copy constructor
147   if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
148     fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
149     if (fModules) {
150       for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
151         if (ssdadldc.fModules[modind]) {
152           fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
153           if (!fModules[modind]) { 
154             AliError("AliITSHandleDaSSD: Error copy constructor");
155             for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
156             delete [] fModules;
157             fModules = NULL;
158             break;
159           }
160         } else fModules[modind] = NULL; 
161       }   
162     } else {
163       AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
164       fNumberOfModules = 0;
165       fModules = NULL;
166     }
167   }
168   if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by copy constructor, use other methods to init it!");
169   if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by copy constructor, use other methods to init it!");
170 }
171
172
173 //______________________________________________________________________________
174 AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc)
175 {
176 // assignment operator
177   if (this == &ssdadldc)  return *this;
178   TObject::operator=(ssdadldc);
179   if (fModules) {
180     for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
181     delete [] fModules; 
182     fModules = NULL;
183   }
184   if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
185   if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
186     fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
187     if (fModules) {
188       for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
189         if (ssdadldc.fModules[modind]) {
190               fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
191           if (!fModules[modind]) { 
192                 AliError("AliITSHandleDaSSD: Error assignment operator");
193             for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
194             delete [] fModules;
195             fModules = NULL;
196             break;
197           }
198         } else fModules[modind] = NULL; 
199       }   
200     } else {
201       AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
202       fNumberOfModules = 0;
203       fModules = NULL;
204     }
205   }
206   fRawDataFileName = NULL;
207   fModIndProcessed = 0;
208   fModIndRead = 0;
209   fModIndex = NULL;
210   fEqIndex = ssdadldc.fEqIndex;
211   fNumberOfEvents = ssdadldc.fNumberOfEvents;
212   fLdcId = ssdadldc.fLdcId;
213   fRunId = ssdadldc.fRunId;
214   fPedestalThresholdFactor = ssdadldc.fPedestalThresholdFactor;
215   fCmThresholdFactor = ssdadldc.fCmThresholdFactor;
216   fZsDefault = ssdadldc.fZsDefault;
217   fOffsetDefault = ssdadldc.fOffsetDefault;
218   fZsMinimum = ssdadldc.fZsMinimum;
219   fMergeBCLists = ssdadldc.fMergeBCLists;
220   fZsFactor = ssdadldc.fZsFactor;
221   fALaddersOff = ssdadldc.fALaddersOff;
222   fCLaddersOff = ssdadldc.fCLaddersOff;
223   fBadChannelsList = NULL;
224   fDDLModuleMap = NULL;
225   fModIndex = NULL;
226   if (ssdadldc.fBadChannelsList) AliWarning("fBadChannelsList is not copied by assignment operator, use other methods to init it!");
227   if (ssdadldc.fDDLModuleMap) AliWarning("fDDLModuleMap is not copied by assignment operator, use other methods to init it!");
228   return *this;
229 }
230
231
232 //______________________________________________________________________________
233 AliITSHandleDaSSD::~AliITSHandleDaSSD()
234 {
235 // Default destructor 
236   if (fModules) 
237   {
238     for (Int_t i = 0; i < fNumberOfModules; i++)
239     { 
240       if (fModules[i]) delete fModules[i];
241     }
242     delete [] fModules;
243   }
244   if (fModIndex) delete [] fModIndex;
245   if (fBadChannelsList)  delete fBadChannelsList;
246   if (fDDLModuleMap) delete [] fDDLModuleMap;
247 }
248
249
250
251 //______________________________________________________________________________
252 void AliITSHandleDaSSD::Reset()
253 {
254 // Delete array of AliITSModuleDaSSD* objects. 
255   if (fModules) {
256     for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
257     delete [] fModules;
258     fModules = NULL;
259   }
260   if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
261 /*
262   if (fBadChannelsList) {
263     delete fBadChannelsList;
264     fBadChannelsList = NULL; 
265   }    
266   if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL; }
267 */
268   fALaddersOff.Set(0);
269   fCLaddersOff.Set(0);
270   fRawDataFileName = NULL;
271   fModIndProcessed = fModIndRead = 0;
272   fNumberOfEvents = 0;
273   fLdcId = fRunId = 0;
274   fPedestalThresholdFactor = fgkPedestalThresholdFactor;
275   fCmThresholdFactor = fgkCmThresholdFactor;
276 }
277
278
279
280 //______________________________________________________________________________
281 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname)
282 {
283 // Read raw data file and set initial and configuration parameters
284   Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
285   Int_t  nofeqipmentev, nofeqipment = 0, eqn = 0; 
286   AliRawReaderDate  *rawreaderdate = NULL;
287   UChar_t *data = NULL;
288   Long_t datasize = 0, eqbelsize = 1;
289
290   rawreaderdate = new AliRawReaderDate(rdfname, 0);
291   if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
292     AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
293     MakeZombie();
294     return kFALSE;
295   }
296   if (rawreaderdate->NextEvent()) {
297     fRunId = rawreaderdate->GetRunNumber(); 
298     rawreaderdate->RewindEvents();
299   } else { MakeZombie(); return kFALSE; }
300   if (fModules) Reset();
301   //rawreaderdate->SelectEvents(-1);
302   rawreaderdate->Select("ITSSSD");  
303   nofstrips = 0;
304   while (rawreaderdate->NextEvent()) {
305     if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
306     nofstripsev = 0;
307     nofeqipmentev = 0;
308     while (rawreaderdate->ReadNextData(data)) {
309       fLdcId = rawreaderdate->GetLDCId();
310       nofeqipmentev += 1;
311       datasize = rawreaderdate->GetDataSize();
312       eqbelsize = rawreaderdate->GetEquipmentElementSize();
313       if ( datasize % eqbelsize ) {
314         AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %i is not an integer of equipment data size %i", 
315                                     rdfname, datasize, eqbelsize));
316         MakeZombie();
317             return kFALSE;
318       }
319       nofstripsev += (Int_t) (datasize / eqbelsize);
320     }
321     if (physeventind++) {
322       if (nofstrips != nofstripsev) AliWarning(Form("AliITSHandleDaSSD: number of strips varies from event to event, ev = %i, %i", 
323                                                      physeventind, nofstripsev));
324       if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to event");
325     }
326     nofstrips = nofstripsev;
327     nofeqipment = nofeqipmentev;
328     if (strn < nofstrips)  strn = nofstrips;
329     if (eqn < nofeqipment) eqn = nofeqipment;
330   }
331   delete rawreaderdate;
332   if ((physeventind > 0) && (strn > 0))
333   {
334     fNumberOfEvents = physeventind;
335     fRawDataFileName = rdfname;
336     fEqIndex.Set(eqn);
337     fEqIndex.Reset(-1);
338     fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn];
339     if (fModIndex) 
340       for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1; 
341     else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created", 
342                                      rdfname, fgkNumberOfSSDModulesPerDdl * eqn));
343     if (SetNumberOfModules(fgkNumberOfSSDModulesPerDdl * eqn)) {
344       TString str = TString::Format("Max number of equipment: %i, max number of channels: %i\n", eqn, strn);
345       DumpInitData(str.Data());
346       return kTRUE;
347     }  
348   }
349   MakeZombie();
350   return kFALSE;
351 }
352
353
354
355 //______________________________________________________________________________
356 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
357 {
358 // Retrieve AliITSModuleDaSSD object from the array
359    if (!fModules) return NULL;
360    for (Int_t i = 0; i < fNumberOfModules; i++) {
361      if (fModules[i]) {
362        if (    (fModules[i]->GetDdlId() == ddlID)
363             && (fModules[i]->GetAD() == ad)
364             && (fModules[i]->GetADC() == adc))
365             return fModules[i];
366      }      
367    }
368    return NULL;
369 }
370
371
372 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
373 {
374 // Retrieve the position of AliITSModuleDaSSD object in the array
375    if (!fModules) return -1;
376    for (Int_t i = 0; i < fNumberOfModules; i++) {
377      if (fModules[i]) {
378        if (    (fModules[i]->GetDdlId() == ddlID)
379             && (fModules[i]->GetAD() == ad)
380             && (fModules[i]->GetADC() == adc))
381             return i;
382      }      
383    }
384    return -1;
385 }
386
387
388
389 //______________________________________________________________________________
390 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
391 {
392 // Retrieve AliITSChannalDaSSD object from the array
393   for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
394     if (    (fModules[modind]->GetDdlId() == ddlID)
395          && (fModules[modind]->GetAD() == ad)
396          && (fModules[modind]->GetADC() == adc)  ) 
397         {
398        return fModules[modind]->GetStrip(stripID);
399     }
400   }
401   AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
402                 ddlID, ad, adc, stripID));
403   return NULL;
404 }
405
406
407
408 //______________________________________________________________________________
409 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
410
411 // Assign array element with AliITSModuleDaSSD object
412    if ((index < fNumberOfModules) && (index >= 0)) 
413      { 
414         if (fModules[index]) delete fModules[index];
415         fModules[index] = module;
416         return kTRUE;
417       }
418    else return kFALSE;                         
419 }
420
421
422
423 //______________________________________________________________________________
424 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
425 {
426 // Allocates memory for AliITSModuleDaSSD objects
427   if (numberofmodules > fgkNumberOfSSDModules)
428     AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD", 
429                      numberofmodules, fgkNumberOfSSDModules));
430   if (fModules) {
431     for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
432     delete [] fModules; 
433     fModules = NULL;
434   }
435   fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
436   if (fModules) {
437     fNumberOfModules = numberofmodules;
438     memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
439     return kTRUE;
440   } else {
441      AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
442      fNumberOfModules = 0;
443      fModules = NULL;
444   }
445   return kFALSE;
446 }
447
448
449
450 //______________________________________________________________________________
451 Bool_t AliITSHandleDaSSD::ReadStaticBadChannelsMap(const Char_t *filename)
452 {
453 // Reads Static Bad Channels Map from the file
454   TFile *bcfile;
455   if (!filename) {
456     AliWarning("No file name is specified for Static Bad Channels Map!");
457     return kFALSE;
458   } 
459   bcfile = new TFile(filename, "READ");
460   if (bcfile->IsZombie()) {
461     AliWarning(Form("Error reading file %s with Static Bad Channels Map!", filename));
462     return kFALSE;
463   }
464   bcfile->GetObject("AliITSBadChannelsSSDv2;1", fBadChannelsList);
465   if (!fBadChannelsList) {
466     AliWarning("Error fBadChannelsList == NULL!");
467     bcfile->Close();
468     delete bcfile;
469     return kFALSE;
470   }
471   bcfile->Close();
472   delete bcfile;
473   return kTRUE;
474 }
475
476
477
478 Bool_t AliITSHandleDaSSD::ReadDDLModuleMap(const Char_t *filename)
479 {
480 // Reads the SSD DDL Map from the file
481   ifstream             ddlmfile;
482   AliRawReaderDate    *rwr = NULL;
483   AliITSRawStreamSSD  *rsm = NULL;
484   void                *event = NULL;
485   if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
486   fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
487   if (!fDDLModuleMap) {
488     AliWarning("Error allocation memory for DDL Map!");
489     return kFALSE;
490   }    
491   if (!filename) {
492     AliWarning("No file name is specified for SSD DDL Map, using the one from AliITSRawStreamSSD!");
493     rwr = new AliRawReaderDate(event);
494     rsm = new AliITSRawStreamSSD(rwr);
495     rsm->Setv11HybridDDLMapping();
496     for (Int_t ddli = 0; ddli < fgkNumberOfSSDDDLs; ddli++)
497       for (Int_t mi = 0; mi < fgkNumberOfSSDModulesPerDdl; mi++)
498         fDDLModuleMap[(ddli * fgkNumberOfSSDModulesPerDdl + mi)] = rsm->GetModuleNumber(ddli, mi);
499     if (rsm) delete rsm;
500     if (rwr) delete rwr;        
501     return kTRUE;
502   } 
503   ddlmfile.open(filename, ios::in);
504   if (!ddlmfile.is_open()) {
505     AliWarning(Form("Error reading file %s with SSD DDL Map!", filename));
506     if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
507     return kFALSE;
508   }
509   Int_t ind = 0;
510   while((!ddlmfile.eof()) && (ind < (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))) {
511     ddlmfile >> fDDLModuleMap[ind++];
512     if (ddlmfile.fail()) AliError(Form("Error extracting number from the DDL map file %s, ind: ", filename, ind));
513   }
514   if (ind != (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))
515     AliWarning(Form("Only %i (< %i) entries were read from DDL Map!", ind, (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl)));
516   ddlmfile.close();
517   return kTRUE;
518 }
519
520
521
522 //______________________________________________________________________________
523 Int_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
524 {
525 // Reads raw data from file
526   if (!Init(fileName)){
527     AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
528     return kFALSE;
529   }
530   fNumberOfEvents = eventsnumber;
531   return ReadModuleRawData (fNumberOfModules);  
532 }
533
534
535
536 //______________________________________________________________________________
537 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
538 {
539 // Reads raw data from file
540   AliRawReader        *rawreaderdate = NULL;
541   AliITSRawStreamSSD  *stream = NULL;
542   AliITSModuleDaSSD   *module;
543   AliITSChannelDaSSD  *strip;
544   Long_t            eventind = 0;
545   Int_t             nofeqipment, eqind;
546   Short_t           equipid, prequipid;
547   Short_t           modind;
548   if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
549   if (!fModules) {
550     AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
551     return 0;
552   }
553   if (!fDDLModuleMap) if (!ReadDDLModuleMap()) AliWarning("DDL map is not defined, ModuleID will be set to 0!");
554   stream = new AliITSRawStreamSSD(rawreaderdate);
555   stream->Setv11HybridDDLMapping();
556   //rawreaderdate->SelectEvents(-1);
557   rawreaderdate->Select("ITSSSD");  
558   modind = 0;
559   nofeqipment = 0;
560   while (rawreaderdate->NextEvent()) {
561     if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
562     prequipid = -1;
563     eqind = -1;
564     while (stream->Next()) {
565       equipid = rawreaderdate->GetEquipmentId(); 
566       if ((equipid != prequipid)) {
567         if ((eqind = GetEqIndex(equipid)) < 0) { fEqIndex.AddAt(equipid, nofeqipment); eqind = nofeqipment++; }
568         prequipid = equipid;
569       }
570       Int_t     equiptype  = rawreaderdate->GetEquipmentType();
571       UChar_t   ddlID      = (UChar_t)rawreaderdate->GetDDLID();
572       UChar_t   ad      = stream->GetAD();
573       UChar_t   adc     = stream->GetADC();
574       UShort_t  stripID = stream->GetSideFlag() ? AliITSChannelDaSSD::GetMaxStripIdConst() - stream->GetStrip() : stream->GetStrip();
575       Short_t   signal  = stream->GetSignal();
576
577       Int_t indpos = (eqind * fgkNumberOfSSDModulesPerDdl)
578                    + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
579       Int_t modpos = fModIndex[indpos];
580       if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
581       if ((modpos < 0) && (modind < modulesnumber)) {
582         module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
583         Int_t mddli;
584         if (fDDLModuleMap) mddli = RetrieveModuleId(ddlID, ad, adc);
585         else  mddli = 0;
586         if (!module->SetModuleIdData (ddlID, ad, adc, mddli)) return 0;
587         module->SetModuleRorcId (equipid, equiptype);
588         modpos = fModIndRead + modind;
589         modind += 1;
590         fModules[modpos] = module;
591         fModIndex[indpos] = modpos;
592       } 
593       if (stripID < AliITSModuleDaSSD::GetStripsPerModuleConst()) {
594         if (!(strip = fModules[modpos]->GetStrip(stripID))) {
595           strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
596           fModules[modpos]->SetStrip(strip, stripID);
597         }
598         strip->SetSignal(eventind, signal);
599           } else  {
600         if (!(fModules[modpos]->GetCMFerom())) {
601           fModules[modpos]->AllocateCMFeromArray();
602           fModules[modpos]->SetCMFeromEventsNumber(fNumberOfEvents);
603                 }
604             fModules[modpos]->SetCMFerom(signal, (stripID - AliITSModuleDaSSD::GetStripsPerModuleConst()), eventind);
605           }
606     }
607     if (++eventind > fNumberOfEvents) break;
608   }
609   delete stream;
610   delete rawreaderdate;
611   if (modind) cout << "The memory was allocated for " <<  modind << " modules." << endl;
612   fModIndRead += modind;
613   if (modind < modulesnumber) RelocateModules();
614   return modind;
615 }
616
617
618
619 //______________________________________________________________________________
620 Bool_t AliITSHandleDaSSD::RelocateModules()
621 {
622 // Relocate memory for AliITSModuleDaSSD object array
623   Int_t         nm = 0;
624   AliITSModuleDaSSD **marray = NULL;
625   for (Int_t modind = 0; modind < fNumberOfModules; modind++)
626     if (fModules[modind]) nm += 1;
627   if (nm == fNumberOfModules) return kTRUE;
628   marray = new (nothrow) AliITSModuleDaSSD* [nm];
629   if (!marray) {
630     AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
631     return kFALSE;
632   }
633   nm = 0;
634   for (Int_t modind = 0; modind < fNumberOfModules; modind++)  
635     if (fModules[modind]) marray[nm++] = fModules[modind];
636   delete [] fModules;
637   fModules = marray;
638   fNumberOfModules = fModIndRead = nm;
639   return kTRUE;
640 }
641
642
643
644 //______________________________________________________________________________
645 Bool_t AliITSHandleDaSSD::AddFeromCm(AliITSModuleDaSSD *const module)
646 // Restore the original signal value adding CM calculated and subtracted in ferom
647 {
648   AliITSChannelDaSSD *strip;
649   Short_t            *signal, *cmferom;
650
651   if (!module) return kFALSE;
652   if (!module->GetCMFerom()) return kTRUE;
653   for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
654     if (!(cmferom = module->GetCMFerom(chipind))) {
655       AliWarning(Form("AliITSHandleDaSSD: There is no Ferom CM values for chip %i, module %i!", chipind, module->GetModuleId()));
656       continue;
657     }
658     for (Int_t strind = (chipind * AliITSModuleDaSSD::GetStripsPerChip()); 
659                strind < ((chipind + 1) * AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
660       if (!(strip = module->GetStrip(strind))) continue;
661       if (!(signal = strip->GetSignal())) continue;
662 //      if (strip->GetEventsNumber() != module->GetEventsNumber()) return kFALSE;
663       Long_t ovev = 0;
664       for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
665         if (SignalOutOfRange(signal[ev]) || SignalOutOfRange(cmferom[ev])) ovev += 1;
666         else {
667           Short_t signal1 = signal[ev] + cmferom[ev];
668           strip->SetSignal(ev, signal1);
669             }  
670       } 
671     } 
672   }  
673   return kTRUE;
674 }
675
676
677
678 //______________________________________________________________________________
679 Bool_t AliITSHandleDaSSD::CalculatePedestal(AliITSModuleDaSSD *const module)
680 {
681 // Calculates Pedestal
682   AliITSChannelDaSSD *strip;
683   Float_t             pedestal, noise;
684   Short_t            *signal;
685   Long_t              ovev, ev, n;
686   if (!module) return kFALSE;
687   for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
688     if (!(strip = module->GetStrip(strind))) continue;
689     if (!(signal = strip->GetSignal())) {
690       AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
691                      module->GetModuleId(), strind));
692       continue; 
693     }
694 //************* pedestal first pass ****************
695     pedestal = 0.0f;
696     ovev = 0l;
697     for (ev = 0; ev < strip->GetEventsNumber(); ev++)
698       if (SignalOutOfRange(signal[ev])) ovev += 1;
699       else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
700     if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
701     strip->SetPedestal(pedestal);       
702 //************* noise *******************************
703     Double_t nsum = 0.0L;
704     ovev = 0l;
705     for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
706       if (SignalOutOfRange(signal[ev])) ovev += 1;
707       else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
708     } 
709     if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise =  sqrt(nsum / (Float_t)(n));
710     else  noise = AliITSChannelDaSSD::GetUndefinedValue();
711     strip->SetNoise(noise);
712 //************* pedestal second pass ****************
713     pedestal = 0.0f;
714     ovev = 0l;
715     for (ev = 0; ev < strip->GetEventsNumber(); ev++)
716       if (   SignalOutOfRange(signal[ev]) 
717           || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
718       else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
719     if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
720     strip->SetPedestal(pedestal);       
721     strip->SetOverflowNumber(ovev);     
722   }
723   return kTRUE;
724 }
725
726
727 //______________________________________________________________________________
728 Bool_t AliITSHandleDaSSD::CalculateNoise(AliITSModuleDaSSD *const module)
729 {
730 // Calculates Noise
731   AliITSChannelDaSSD *strip;
732   Short_t    *signal;
733   Float_t     noise;
734   Long_t      ovev, n;
735   if (!module) return kFALSE;
736   for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
737     if (!(strip = module->GetStrip(strind))) continue;
738     if (!(signal = strip->GetSignal())) {
739       strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
740       AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
741                      module->GetModuleId(), strind));
742       continue;
743     }
744     Double_t nsum = 0.0L;
745     ovev = 0l;
746     for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
747       if (SignalOutOfRange(signal[ev])) ovev += 1;
748       else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
749     } 
750     if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise =  sqrt(nsum / (Float_t)(n));
751     else  noise = AliITSChannelDaSSD::GetUndefinedValue();
752     strip->SetNoise(noise);
753   }
754   return kTRUE;
755 }
756
757
758
759 //______________________________________________________________________________
760 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
761 {
762 // Calculates Noise with CM correction
763   AliITSChannelDaSSD  *strip = NULL;
764   Short_t     *signal;
765   Float_t      noise;
766   Long_t       ovev, n;
767   if (!CalculateCM(module)) { 
768     AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
769     return kFALSE;
770   }  
771   for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
772     if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
773     if (!(signal = strip->GetSignal())) {
774       strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
775       AliError(Form("SSDDAModule: Error CalculateNoiseWithoutCM(): there are no events data for module[%i] strip[%i]->GetSignal()", 
776                      module->GetModuleId(), strind));
777       continue; //return kFALSE;
778     }
779     Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
780     Double_t nsum = 0.0L;
781     ovev = 0l;
782     for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
783       if (SignalOutOfRange(signal[ev])) ovev += 1;
784       else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
785     } 
786     if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise =  sqrt(nsum / (Float_t)(n));
787     else  noise = AliITSChannelDaSSD::GetUndefinedValue();
788     strip->SetNoiseCM(noise);
789   }
790   return kTRUE;
791 }
792
793
794
795 //______________________________________________________________________________
796 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
797 {
798 // Calculates CM
799   AliITSChannelDaSSD  *strip = NULL;
800   Short_t             *signal;
801   Long_t               ovstr, n;
802   Int_t                stripind;
803   module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
804   for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
805     stripind = chipind * module->GetStripsPerChip();
806     module->GetCM()[chipind].Set(fNumberOfEvents);
807     module->GetCM()[chipind].Reset(0.0f);
808     for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
809     // calculate firs approximation of CM.
810       Double_t cm0 = 0.0L;
811       ovstr = 0l;
812       for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
813         if (!(strip = module->GetStrip(strind))) continue; //return kFALSE; 
814         if (!(signal = strip->GetSignal())) {
815           AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()", 
816                         module->GetModuleId(), strind));
817           return kFALSE;
818         }
819         if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
820         else cm0 += (signal[ev] - strip->GetPedestal());
821       }
822       if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
823       else { module->SetCM(0.0f, chipind, ev); continue; }
824     // calculate avarage (cm - (signal - pedestal)) over the chip
825       Double_t cmsigma = 0.0L;
826       ovstr = 0l;
827       for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
828         if (!(strip = module->GetStrip(strind))) continue;
829         if (!(signal = strip->GetSignal())) {
830           AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
831                          module->GetModuleId(), strind));
832           return kFALSE;
833         }
834         if ((SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
835         else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
836       }
837       if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = sqrt(cmsigma / (Float_t)(n));
838       else { module->SetCM(0.0f, chipind, ev); continue; }
839    // calculate cm with threshold
840       Double_t cmsum = 0.0L;
841       ovstr = 0l;
842       for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
843         if (!(strip = module->GetStrip(strind))) continue;
844         signal = strip->GetSignal();
845         if ( (SignalOutOfRange(signal[ev])) || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue()) 
846                || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
847         else cmsum += (signal[ev] - strip->GetPedestal());
848       }
849       if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
850       else cmsum = 0.0L;
851       if (!(module->SetCM(cmsum, chipind, ev))) 
852         AliError(Form("AliITSHandleDaSSD: Error, module->SetCM(...) returned kFALSE module:chip:event : [%i]:[%i]:[%i]\n",
853                            module->GetModuleId(), chipind, ev));
854     } 
855   }
856   return kTRUE; 
857 }
858
859
860 //______________________________________________________________________________
861 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread)
862 {
863 // Performs calculation of calibration parameters (pedestal, noise, ...) 
864   Int_t nm = 0;
865   if (nmread <= 0) return kFALSE;
866   if (!fModules) return kFALSE;
867   while ((nm = ReadModuleRawData(nmread)) > 0) {
868     cout << "Processing next " << nm << " modules;" << endl;  
869     for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
870       if (!fModules[modind]) {
871         AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
872                        modind));
873         return kFALSE;
874       }
875       AddFeromCm(fModules[modind]);
876       CalculatePedestal(fModules[modind]);
877       CalculateNoise(fModules[modind]);
878       CalculateNoiseCM(fModules[modind]);
879     }
880     DeleteSignal();
881     DeleteCM();
882     DeleteCMFerom();
883     fModIndProcessed = fModIndRead;
884     cout << fModIndProcessed << " - done" << endl;
885   }
886   return kTRUE;  
887 }
888
889
890 //______________________________________________________________________________
891 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
892 {
893 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
894   if (!fDDLModuleMap) {
895     AliError("Error DDLMap is not initialized, return 0!");
896         return 0;
897   }
898   Int_t mddli = ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
899   if ((ddlID < fgkNumberOfSSDDDLs) && (mddli < fgkNumberOfSSDModulesPerDdl)) {
900     mddli = fDDLModuleMap[ddlID * fgkNumberOfSSDModulesPerDdl + mddli];
901   }  
902   else {
903     AliWarning(Form("Module index  = %d or ddlID = %d is out of range 0 is rturned", ddlID, mddli));
904     mddli = 0;
905   }
906   if (mddli > SHRT_MAX) return SHRT_MAX;
907   else return (Short_t)mddli;
908 }
909
910
911
912 //______________________________________________________________________________
913 AliITSNoiseSSDv2* AliITSHandleDaSSD::GetCalibrationOCDBNoise() const
914 {
915 // Fill in the array for OCDB 
916   AliITSNoiseSSDv2         *ldcn = NULL;
917   AliITSModuleDaSSD      *module = NULL;
918   AliITSChannelDaSSD     *strip = NULL; 
919   if (!fModules) return NULL;
920   ldcn = new AliITSNoiseSSDv2;
921   if (!ldcn) {
922     AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
923     return NULL;
924   }
925   for (Int_t i = 0; i < fNumberOfModules; i++) {
926     if (!(module = fModules[i])) continue;
927     if (module->GetModuleId() < fgkMinSSDModuleId) continue;
928     for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
929       if (!(strip = module->GetStrip(strind))) continue;
930       Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
931       if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) 
932         ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
933       else
934         ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
935     }
936   }
937   return ldcn;
938 }
939
940
941 //______________________________________________________________________________
942 AliITSBadChannelsSSDv2* AliITSHandleDaSSD::GetCalibrationBadChannels() const
943 {
944 // Fill in the TObjArray with the list of bad channels 
945   AliITSBadChannelsSSDv2   *ldcbc = NULL;
946   AliITSModuleDaSSD      *module = NULL;
947   AliITSChannelDaSSD     *strip = NULL; 
948   if (!fModules) return NULL;
949   ldcbc = new AliITSBadChannelsSSDv2;
950   if (!ldcbc) {
951     AliError("Error allocation mamory for AliITSBadChannelsSSDv2 object, return NULL!");
952     return NULL;
953   }
954   for (Int_t i = 0; i < fNumberOfModules; i++) {
955     if (!(module = fModules[i])) continue;
956     if (module->GetModuleId() < fgkMinSSDModuleId) continue;
957     for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
958       if (!(strip = module->GetStrip(strind))) continue;
959       Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
960       if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() )
961         ldcbc->AddBadChannelP(modid, strip->GetStripId(), module->CheckIfBad(strip->GetStripId()));
962       else 
963         ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), 
964                                      module->CheckIfBad(strip->GetStripId()));
965     }
966   }
967   return ldcbc;
968 }
969
970
971
972 //______________________________________________________________________________
973 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname)
974 {
975 // Save Calibration data locally
976   AliITSBadChannelsSSDv2   *ldcbc = NULL;
977   AliITSPedestalSSDv2      *ldcp = NULL;
978   AliITSNoiseSSDv2         *ldcn = NULL;
979   AliITSModuleDaSSD      *module = NULL;
980   AliITSChannelDaSSD     *strip = NULL; 
981   Char_t         *tmpfname;
982   TString         dadatafilename("");
983   if (!fModules) return kFALSE;
984   ldcn = new AliITSNoiseSSDv2;
985   ldcp = new AliITSPedestalSSDv2;
986   ldcbc = new AliITSBadChannelsSSDv2;
987   if ((!ldcn) || (!ldcp) || (!ldcp)) {
988     AliError("Error allocation mamory for calibration objects, return kFALSE!");
989     return kFALSE;
990   }
991   for (Int_t i = 0; i < fNumberOfModules; i++) {
992     if (!(module = fModules[i])) continue;
993     if (module->GetModuleId() < fgkMinSSDModuleId) continue;
994     for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
995       if (!(strip = module->GetStrip(strind))) continue;
996       Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
997       if (strip->GetStripId() < AliITSModuleDaSSD::GetPNStripsPerModule() ) {
998         ldcn->AddNoiseP(modid, strip->GetStripId(), strip->GetNoiseCM());
999         ldcp->AddPedestalP(modid, strip->GetStripId(), strip->GetPedestal());
1000         ldcbc->AddBadChannelP(modid, strip->GetStripId(), module->CheckIfBad(strip->GetStripId()));
1001       } else {
1002         ldcn->AddNoiseN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetNoiseCM());
1003         ldcp->AddPedestalN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), strip->GetPedestal()); 
1004         ldcbc->AddBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strip->GetStripId()), 
1005                                      module->CheckIfBad(strip->GetStripId()));
1006       }
1007     }
1008   }
1009   if (dafname) dadatafilename.Form("%s/", dafname);
1010   dadatafilename += TString::Format("ITSSSDda_%i.root", fLdcId);
1011   tmpfname = new Char_t[dadatafilename.Length()+1];
1012   dafname = strcpy(tmpfname, dadatafilename.Data());
1013   TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
1014   if (fileRun->IsZombie()) {
1015     AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
1016     ldcn->Delete();
1017     delete fileRun;
1018     delete ldcn;
1019     delete ldcp;
1020     delete ldcbc;
1021     return kFALSE;
1022   }
1023   fileRun->WriteTObject(ldcn);
1024   fileRun->WriteTObject(ldcp);
1025   if (fBadChannelsList) 
1026     if (fMergeBCLists) {
1027       MergeBadChannels(ldcbc);
1028       fileRun->WriteTObject(ldcbc);
1029     } else fileRun->WriteTObject(fBadChannelsList);
1030   else fileRun->WriteTObject(ldcbc);
1031   fileRun->Close();
1032   delete fileRun;
1033   delete ldcn;
1034   delete ldcp;
1035   delete ldcbc;
1036   return kTRUE;
1037 }
1038
1039
1040 //______________________________________________________________________________
1041 Int_t AliITSHandleDaSSD::MergeBadChannels(AliITSBadChannelsSSDv2*&  bcl) const
1042 {
1043 // Merges the statick bad channels list with bad channels got upon calibration
1044   AliITSModuleDaSSD     *module = 0;
1045   Int_t                  nmpch = 0, nmnch = 0, ngpch = 0, ngnch = 0;
1046   if (!fBadChannelsList || !bcl) {
1047     AliWarning("Either fBadChannelsList == NULL or bad_channels_list == NULL, there is nothing to merge!");
1048         return -1;
1049   }
1050   for (Int_t modind = 0; modind < GetNumberOfModules(); modind++) {
1051     if (!(module = fModules[modind])) continue;
1052     if (module->GetModuleId() < fgkMinSSDModuleId) continue;
1053     Short_t modid = module->GetModuleId() - fgkMinSSDModuleId;
1054     for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetPNStripsPerModule(); strind++) {
1055       if ( (!(fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask)) 
1056           && (bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) 
1057         ngpch++;
1058       if ( (!(fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask)) 
1059           && (bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) 
1060         ngnch++;
1061       if ( (!(bcl->GetBadChannelP(modid, strind) & fgkBadChannelMask)) 
1062           && (fBadChannelsList->GetBadChannelP(modid, strind) & fgkBadChannelMask) ) {
1063         bcl->AddBadChannelP(modid, strind, fBadChannelsList->GetBadChannelP(modid, strind));
1064         nmpch++;  
1065       }    
1066       if ( (!(bcl->GetBadChannelN(modid, strind) & fgkBadChannelMask)) 
1067           && (fBadChannelsList->GetBadChannelN(modid, strind) & fgkBadChannelMask) ) {
1068         bcl->AddBadChannelN(modid, strind, fBadChannelsList->GetBadChannelN(modid, strind));
1069         nmnch++;  
1070       }
1071     }     
1072   }
1073   AliInfo(Form("Static bad, dynamic good: P%d,  N%d", nmpch, nmnch));
1074   AliInfo(Form("Static good, dynamic bad: P%d,  N%d", ngpch, ngnch));
1075   return (nmnch + nmpch);
1076 }
1077
1078
1079
1080 //______________________________________________________________________________
1081 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
1082 {
1083 // Dump calibration parameters
1084   AliITSModuleDaSSD    *mod;
1085   AliITSChannelDaSSD   *strip;
1086   if (!fModules) {
1087     cout << "SSDDALDC::DumpModInfo():  Error, no modules are allocated!" << endl;
1088     return kFALSE;
1089   }  
1090   cout << "Modules with MeanNoise > " << meannosethreshold << endl;
1091   for (Int_t i = 0; i < fNumberOfModules; i++) {
1092     if (!(mod = fModules[i])) continue;
1093     Float_t  maxnoise = 0.0f, meannoise = 0.0f, maxped = 0.0f;
1094     Int_t    maxstrind = 0, novfstr = 0;  
1095     for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
1096       if (!(strip = mod->GetStrip(strind))) {novfstr++;  continue; }
1097       if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++;  continue; }
1098       if (maxnoise < strip->GetNoiseCM()) { 
1099         maxnoise = strip->GetNoiseCM();
1100         maxstrind = strind;
1101       } 
1102       meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Float_t>(strind - novfstr + 1) 
1103                                     : strip->GetNoiseCM();
1104       if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal();                     
1105     } 
1106     if (meannoise > meannosethreshold)
1107       cout << "Mod: " << i << ";  DDl: " << (int)mod->GetDdlId() << ";  AD: " << (int)mod->GetAD()  
1108                            << ";  ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped
1109                            << ";  MeanNoise = " << meannoise 
1110                            << ";  NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
1111   }
1112   return kTRUE;
1113 }
1114
1115
1116
1117 //______________________________________________________________________________
1118 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
1119 {
1120 // Print Module calibration data whether in file or in cout
1121    AliITSChannelDaSSD  *strip;
1122    ofstream             datafile;
1123    ostream             *outputfile;
1124    if (!fname) { outputfile = &cout; }
1125    else {
1126      datafile.open(fname, ios::out);
1127      if  (datafile.fail()) return kFALSE;
1128      outputfile = dynamic_cast<ostream*>(&datafile); 
1129    }
1130    *outputfile  << "DDL = " << (int)ddlID << ";  AD = " << (int)ad << ";  ADC = " << (int)adc << endl;
1131    for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1132      if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
1133        *outputfile << "Str = " << strind << ";  ped = " << strip->GetPedestal() 
1134                    << ";  noise = " << strip->GetNoiseCM() << endl;
1135      }
1136      else continue;
1137    }
1138   if (datafile.is_open()) datafile.close(); 
1139   return kTRUE;
1140 }
1141
1142
1143
1144 //______________________________________________________________________________
1145 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
1146 {
1147 // Print general information retrieved from raw data file
1148   cout << "Raw data file: " << fRawDataFileName << endl
1149        << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
1150        << "Number of physics events: " << fNumberOfEvents << endl
1151        << str;
1152 }
1153
1154
1155 //______________________________________________________________________________
1156 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
1157 {
1158 // Used to allocate simulated modules to test the performance  
1159   AliITSModuleDaSSD *module;
1160   UChar_t      ad, adc, ddlID;
1161   ad = adc = ddlID = 0;
1162   if (!(fModules[copymodind])) return kFALSE;
1163   for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
1164     if (!fModules[modind]) {
1165       module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
1166       if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
1167       else if (adc == 5) adc = 8;
1168       else if (adc == 13) {
1169         adc = 0;
1170         if (ad < 8) ad += 1;
1171         else {
1172           ad = 0;
1173           ddlID +=1;
1174         }
1175       }
1176       if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
1177       fModules[modind] = module;
1178       for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1179         AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
1180         Long_t      eventsnumber = cstrip->GetEventsNumber();
1181         AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
1182         for (Long_t evind = 0; evind < eventsnumber; evind++) {
1183           Short_t sign = cstrip->GetSignal(evind);
1184           if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
1185         }
1186         module->SetStrip(strip, strind);
1187       }
1188     }
1189     else {
1190       ddlID = fModules[modind]->GetDdlId();
1191       ad    = fModules[modind]->GetAD();
1192       adc   = fModules[modind]->GetADC();
1193     }
1194   }
1195   for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);  
1196   return kTRUE;
1197 }
1198
1199
1200     
1201 //___________________________________________________________________________________________
1202 Bool_t AliITSHandleDaSSD::AdDataPresent(const Int_t ddl, const Int_t ad) const
1203 {
1204 // Check if there are calibration data for given ddl and slot
1205   for (Int_t modind = 0; modind < fNumberOfModules; modind++)
1206     if ((GetModule(modind)->GetAD() == ad) && (GetModule(modind)->GetDdlId() == ddl)) return kTRUE;
1207   return kFALSE;
1208 }
1209
1210    
1211
1212 //___________________________________________________________________________________________
1213 Bool_t AliITSHandleDaSSD::SaveEqSlotCalibrationData(const Int_t ddl, const Int_t ad, const Char_t *fname) const
1214 // Saves calibration files for selected equipment (DDL)
1215 {
1216   fstream    feefile;
1217   Int_t      zsml, offsetml;
1218   ULong_t    zsth, offset, zsoffset;
1219   if (!fname) {
1220     AliError("File name must be specified!");
1221     return kFALSE;   
1222   }
1223   if (!AdDataPresent(ddl, ad)) {
1224     AliError(Form("Error SaveEqSlotCalibrationData(ddl = %i, ad = %i) no data present", ddl, ad)); 
1225     return kFALSE;
1226   }
1227   feefile.open(fname, ios::out);
1228   if (!feefile.is_open()) {
1229         AliError(Form("Can not open the file %s for output!", fname)); 
1230     return kFALSE;
1231   }
1232   for (zsml = 0; fgkZsBitMask >> zsml; zsml++) ;
1233   for (offsetml = 0; fgkOffSetBitMask >> offsetml; offsetml++) ;
1234   for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
1235     for (Int_t adcb = 0; adcb < fgkAdcPerDBlock; adcb++) {
1236       zsoffset = 0x0;
1237       for (Int_t j = 0; j < 2; j++) {
1238         Int_t adc = adcb + j * 8;
1239         zsth = ZsThreshold(ddl, ad, adc, strind);
1240         offset = OffsetValue(ddl, ad, adc, strind);
1241         zsoffset = zsoffset | (((zsth << offsetml) | offset) << ((j == 0) ? (offsetml + zsml) : 0));
1242       }
1243       feefile << "0x" << ConvBase(static_cast<unsigned long>(zsoffset), 16) << endl;
1244     }
1245   }
1246   feefile.close();
1247   return kTRUE;
1248 }
1249
1250
1251 //______________________________________________________________________________
1252 Int_t AliITSHandleDaSSD::ChannelIsBad(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1253 {
1254 // Check if the channel is bad
1255   AliITSModuleDaSSD     *module = NULL;
1256   Int_t                  modn = -1;
1257   if (fBadChannelsList && fDDLModuleMap) {
1258     modn = RetrieveModuleId(ddl, ad, adc);
1259     if (modn < 0) return -1;
1260     if (modn < fgkMinSSDModuleId) {
1261       AliWarning(Form("Module ddl/ad/adc: %i/%i/%i has number %i which is wrong for SSD module", ddl, ad, adc, strn, modn));
1262           return -1;
1263     }
1264     Short_t modid = modn - fgkMinSSDModuleId;
1265     if (strn < AliITSModuleDaSSD::GetPNStripsPerModule()) 
1266       return (fBadChannelsList->GetBadChannelP(modid, strn)  & fgkBadChannelMask);
1267     else return (fBadChannelsList->GetBadChannelN(modid, (AliITSChannelDaSSD::GetMaxStripIdConst() - strn)) & fgkBadChannelMask);
1268   } else {
1269     AliError("Error ether bad channels list or DDLMap is not initialized or both, AliITSModuleDaSSD::CheckIfBad(str) is used!");
1270     if ((module = GetModule(ddl, ad, adc))) {
1271       return (module->CheckIfBad(strn) & fgkBadChannelMask);
1272     } else {
1273       AliWarning(Form("There is no calibration data for ddl = %i,  ad = %i,  adc = %i, 0 is used!", ddl, ad, adc));
1274       return 0ul;
1275     }  
1276         return 0;
1277   }
1278 }
1279
1280
1281
1282 //______________________________________________________________________________
1283 Int_t AliITSHandleDaSSD::LadderIsOff(const UChar_t ddl, const UChar_t ad, const UChar_t adc) const
1284 {
1285 //Checks if the module with given ddl, ad, adc is on the ladder which is in the list of ladders which are off
1286   const Int_t nm5 =  500;
1287   const Int_t nm6 =  1248;
1288   const Int_t nml5a = 12;
1289   const Int_t nml5c = 10;
1290   const Int_t nml6a = 12;
1291   const Int_t nml6c = 13;
1292   Int_t               modn, ladder, layer, side;
1293   AliITSModuleDaSSD  *module;
1294   if (!(module = GetModule(ddl, ad, adc))) return 0;
1295   if ((modn = module->GetModuleId()) <= 0)  modn = RetrieveModuleId(ddl, ad, adc);
1296   if (modn <= 0) return 0;
1297   layer = modn >= nm6 ? 1 : 0;     // 6 : 5
1298   ladder = (modn - (layer ? nm6 : nm5)) / (layer ? (nml6a + nml6c) : (nml5a + nml5c));
1299   if ( ((modn - (layer ? nm6 : nm5)) % (layer ? (nml6a + nml6c) : (nml5a + nml5c))) < (layer ? nml6a : nml5a))
1300     side = 0;      // A
1301   else side = 1;   // C
1302   ladder += (layer ? 600 : 500);
1303   layer += 5;
1304   if (side)
1305     if (fCLaddersOff.GetSize()) {
1306       for(Int_t i = 0; i < fCLaddersOff.GetSize(); i++) 
1307         if (fCLaddersOff.At(i) == ladder) return fCLaddersOff.At(i);
1308       return 0;
1309     } else return 0;
1310   else
1311     if (fALaddersOff.GetSize()) {
1312       for(Int_t i = 0; i < fALaddersOff.GetSize(); i++) 
1313         if (fALaddersOff.At(i) == ladder) return fALaddersOff.At(i);
1314       return 0;
1315     } else return 0;
1316   return 0;  
1317 }
1318
1319
1320         
1321 //______________________________________________________________________________
1322 ULong_t AliITSHandleDaSSD::OffsetValue(const AliITSChannelDaSSD *strip, 
1323                                        const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1324 {
1325 // Calculate the offset value to be upload to FEROM     
1326   Int_t  pedint;
1327   if (fOffsetDefault < INT_MAX) pedint = fOffsetDefault;
1328   else pedint = TMath::Nint(strip->GetPedestal());
1329   if (pedint > static_cast<Int_t>((fgkOffSetBitMask >> 1))) {
1330     if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (GetModule(ddl, ad, adc)->CheckIfBad(strn)))) 
1331       AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i  can not be represented with mask 0x%s, Offset = %i",
1332                    pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), (fgkOffSetBitMask >> 1)));
1333     return (fgkOffSetBitMask >> 1);
1334   }  
1335   if ((-pedint) > static_cast<Int_t>(((fgkOffSetBitMask + 1) >> 1))) {
1336     if (!ChannelIsBad(ddl, ad, adc, strn) && !((fMergeBCLists) && (GetModule(ddl, ad, adc)->CheckIfBad(strn)))) 
1337       AliError(Form("Offset %i, channel(ddl/ad/adc/strip) %i/%i/%i/%i  can not be represented with mask 0x%s, Offset = %i", 
1338                pedint, ddl, ad, adc, strn, ConvBase(fgkOffSetBitMask, 16).c_str(), 
1339                ((fgkOffSetBitMask & (~fgkOffSetBitMask >> 1)) - fgkOffSetBitMask - 1)));
1340     return fgkOffSetBitMask & (~fgkOffSetBitMask >> 1);
1341   }
1342   return fgkOffSetBitMask & (pedint >= 0 ? pedint : pedint + fgkOffSetBitMask + 1);
1343 }
1344
1345
1346
1347 //______________________________________________________________________________
1348 ULong_t AliITSHandleDaSSD::OffsetValue(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1349 {
1350 // Calculate the offset value to be upload to FEROM     
1351   AliITSChannelDaSSD    *strip = NULL;
1352   AliITSModuleDaSSD     *module = NULL;
1353   if ((module = GetModule(ddl, ad, adc))) {
1354     if ((strip = module->GetStrip(strn))) return OffsetValue(strip, ddl, ad, adc, strn);
1355     else {
1356       AliWarning(Form("There is no calibration data for ddl = %i,  ad = %i,  adc = %i,  strip = %i, 0 is used!", ddl, ad, adc, strn));
1357       return 0ul;
1358     }
1359   } else {
1360     AliWarning(Form("There is no calibration data for ddl = %i,  ad = %i,  adc = %i, 0 is used!", ddl, ad, adc));
1361     return 0ul;
1362   }  
1363 }
1364
1365
1366
1367 //______________________________________________________________________________
1368 ULong_t AliITSHandleDaSSD::ZsThreshold(AliITSChannelDaSSD *strip) const
1369
1370 // Calculate the value of zero suppression threshold to be upload to FEROM
1371   ULong_t zs;
1372   if (fZsDefault < 0) {
1373     zs = TMath::Nint(fZsFactor * strip->GetNoiseCM());
1374     if (zs < static_cast<ULong_t>(fZsMinimum)) zs = static_cast<ULong_t>(fZsMinimum);
1375   }
1376   else zs = fZsDefault;
1377   return (zs < fgkZsBitMask) ? (zs & fgkZsBitMask) : fgkZsBitMask;
1378 }
1379
1380
1381 //______________________________________________________________________________
1382 ULong_t AliITSHandleDaSSD::ZsThreshold(const UChar_t ddl, const UChar_t ad, const UChar_t adc, const Int_t strn) const
1383 {
1384 // Calculate the value of zero suppression threshold to be upload to FEROM, account bad channels list
1385   AliITSChannelDaSSD    *strip = NULL;
1386   AliITSModuleDaSSD     *module = NULL;
1387   if (ChannelIsBad(ddl, ad, adc, strn)) return fgkZsBitMask;
1388   if (LadderIsOff(ddl, ad, adc)) return fgkZsBitMask;
1389   if ((module = GetModule(ddl, ad, adc))) {
1390         if (fMergeBCLists) if (module->CheckIfBad(strn)) return fgkZsBitMask;
1391     if ((strip = module->GetStrip(strn)))  return ZsThreshold(strip);
1392     else {
1393       AliWarning(Form("There is no calibration data for ddl = %i,  ad = %i,  adc = %i,  strip = %i, 0 is used!", ddl, ad, adc, strn));
1394       return 0ul;
1395     }
1396   } else {
1397     AliWarning(Form("There is no calibration data for ddl = %i,  ad = %i,  adc = %i, 0 is used!", ddl, ad, adc));
1398     return 0ul;
1399   }
1400 }
1401
1402             
1403 //______________________________________________________________________________
1404 string AliITSHandleDaSSD::ConvBase(const unsigned long value, const long base) const
1405 {
1406 // Converts the unsigned long number into that in another base 
1407   string digits = "0123456789ABCDEF";
1408   string result;
1409   unsigned long v = value;
1410   if((base < 2) || (base > 16)) {
1411     result = "Error: base out of range.";
1412   }
1413   else {
1414     int i = 0;
1415     do {
1416       result = digits[v % base] + result;
1417       v /= base;
1418       i++;
1419     }
1420     while((v) || (i<8));
1421   }
1422   return result;
1423 }
1424
1425
1426
1427 //______________________________________________________________________________
1428 Int_t AliITSHandleDaSSD::CheckOffChips() const
1429 {
1430 // Check if the chip, module are off
1431   AliITSChannelDaSSD *strip;
1432   Int_t       offthreshold;
1433   Int_t       strnd, chipnd, modnd, stroff, chipoff, modoff;
1434   offthreshold = TMath::Nint(fZsMinimum/fZsFactor);
1435   modnd = modoff = 0;
1436   for (Int_t mi = 0; mi < fNumberOfModules; mi++) {
1437     if (!fModules[mi]) { modnd++; continue; }
1438     if (fModules[mi]->GetModuleId() < 0) continue;
1439     if (LadderIsOff(fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()) ) continue;
1440     chipoff = chipnd = 0;
1441     for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
1442       strnd = stroff = 0;
1443       Int_t stripind = chipind * AliITSModuleDaSSD::GetStripsPerChip();
1444       for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
1445         if (!(strip = fModules[mi]->GetStrip(strind))) { strnd++;  continue; }
1446         if (strip->GetNoiseCM() < offthreshold ) stroff++;
1447       }
1448       if (strnd == AliITSModuleDaSSD::GetStripsPerChip()) chipnd++;
1449       else if (stroff == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1450       else if ((stroff + strnd) == AliITSModuleDaSSD::GetStripsPerChip()) chipoff++;
1451     }
1452     if ((!chipoff) && (!chipnd)) continue;
1453     if (chipnd == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1454       AliInfo(Form("Module: (ddl/ad/adc) %i/%i/%i seems to be off and it is not on the ladders which are off!", 
1455                fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1456       modnd++;
1457     }
1458     if (chipoff == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1459       AliInfo(Form("Module (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!", 
1460                fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1461       modoff++;
1462     }
1463     else if ((chipoff + chipnd) == AliITSModuleDaSSD::GetChipsPerModuleConst()) {
1464       AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i seems to be off and it is not on the ladders which are off!", 
1465                fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC()));
1466       modoff++;
1467     }
1468     else if (chipoff) {
1469       AliInfo(Form("Module: (ddl/ad/adc): %i/%i/%i has %i chips which are off!", 
1470                fModules[mi]->GetDdlId(), fModules[mi]->GetAD(), fModules[mi]->GetADC(), chipoff));
1471       modoff++;
1472     }
1473   }
1474   return (modoff + modnd);
1475 }
1476