]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSHandleDaSSD.cxx
Handling of static DDL maps (S. Borysov)
[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: 19/05/2008
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #include <Riostream.h> 
27 #include "AliITSHandleDaSSD.h"
28 #include <math.h>
29 #include <limits.h>
30 #include "event.h"
31 #include "TFile.h"
32 #include "TString.h"
33 #include "TObjArray.h"
34 #include "AliLog.h"
35 #include "AliITSNoiseSSD.h"
36 #include "AliITSPedestalSSD.h"
37 #include "AliITSBadChannelsSSD.h"
38 #include "AliITSRawStreamSSD.h"
39 #include "AliRawReaderDate.h"
40 #include "AliITSRawStreamSSD.h"
41 #include "AliITSChannelDaSSD.h"
42
43
44 ClassImp(AliITSHandleDaSSD)
45
46 using namespace std;
47
48
49 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDModules = 1698;       // Number of SSD modules in ITS
50 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDModulesPerDdl = 108;  // Number of SSD modules in DDL
51 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDModulesPerSlot = 12;  // Number of SSD modules in Slot
52 const Int_t    AliITSHandleDaSSD::fgkNumberOfSSDDDLs = 16;            // Number of SSD modules in Slot
53 const Float_t  AliITSHandleDaSSD::fgkPedestalThresholdFactor = 3.0;   // Defalt value for fPedestalThresholdFactor 
54 const Float_t  AliITSHandleDaSSD::fgkCmThresholdFactor = 3.0;         // Defalt value for fCmThresholdFactor
55
56 //______________________________________________________________________________
57 AliITSHandleDaSSD::AliITSHandleDaSSD() :
58   fRawDataFileName(NULL),
59   fNumberOfModules(0),
60   fModules(NULL),
61   fModIndProcessed(0),
62   fModIndRead(0),
63   fModIndex(NULL),
64   fNumberOfEvents(0),
65   fStaticBadChannelsMap(NULL),
66   fDDLModuleMap(NULL),
67   fLdcId(0),
68   fRunId(0),
69   fPedestalThresholdFactor(fgkPedestalThresholdFactor),
70   fCmThresholdFactor(fgkCmThresholdFactor) 
71 {
72 // Default constructor
73 }
74
75
76 //______________________________________________________________________________
77 AliITSHandleDaSSD::AliITSHandleDaSSD(Char_t *rdfname) :
78   fRawDataFileName(NULL),
79   fNumberOfModules(0),
80   fModules(NULL),
81   fModIndProcessed(0),
82   fModIndRead(0),
83   fModIndex(NULL),
84   fNumberOfEvents(0),
85   fStaticBadChannelsMap(NULL),
86   fDDLModuleMap(NULL),
87   fLdcId(0),
88   fRunId(0),
89   fPedestalThresholdFactor(fgkPedestalThresholdFactor) ,
90   fCmThresholdFactor(fgkCmThresholdFactor) 
91 {
92   if (!Init(rdfname)) AliError("AliITSHandleDaSSD::AliITSHandleDaSSD() initialization error!");
93 }
94
95
96 //______________________________________________________________________________
97 AliITSHandleDaSSD::AliITSHandleDaSSD(const AliITSHandleDaSSD& ssdadldc) :
98   TObject(ssdadldc),
99   fRawDataFileName(ssdadldc.fRawDataFileName),
100   fNumberOfModules(ssdadldc.fNumberOfModules),
101   fModules(NULL),
102   fModIndProcessed(ssdadldc.fModIndProcessed),
103   fModIndRead(ssdadldc.fModIndRead),
104   fModIndex(NULL),
105   fNumberOfEvents(ssdadldc.fNumberOfEvents),
106   fStaticBadChannelsMap(ssdadldc.fStaticBadChannelsMap),
107   fDDLModuleMap(ssdadldc.fDDLModuleMap),
108   fLdcId(ssdadldc.fLdcId),
109   fRunId(ssdadldc.fRunId),
110   fPedestalThresholdFactor(ssdadldc.fPedestalThresholdFactor),
111   fCmThresholdFactor(ssdadldc.fCmThresholdFactor) 
112 {
113   // copy constructor
114   if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
115     fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
116     if (fModules) {
117       for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
118         if (ssdadldc.fModules[modind]) {
119           fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
120           if (!fModules[modind]) { 
121             AliError("AliITSHandleDaSSD: Error copy constructor");
122             for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
123             delete [] fModules;
124             fModules = NULL;
125             break;
126           }
127         } else fModules[modind] = NULL; 
128       }   
129     } else {
130       AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
131       fNumberOfModules = 0;
132       fModules = NULL;
133     }
134   }
135 }
136
137
138 //______________________________________________________________________________
139 AliITSHandleDaSSD& AliITSHandleDaSSD::operator = (const AliITSHandleDaSSD& ssdadldc)
140 {
141 // assignment operator
142   if (this == &ssdadldc)  return *this;
143   if (fModules) {
144     for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
145     delete [] fModules; 
146     fModules = NULL;
147   }
148   if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
149   if ((ssdadldc.fNumberOfModules > 0) && (ssdadldc.fModules)) {
150     fModules = new (nothrow) AliITSModuleDaSSD* [ssdadldc.fNumberOfModules];
151     if (fModules) {
152       for (Int_t modind = 0; modind < ssdadldc.fNumberOfModules; modind++) {
153         if (ssdadldc.fModules[modind]) {
154           fModules[modind] = new AliITSModuleDaSSD(*(ssdadldc.fModules[modind]));
155           if (!fModules[modind]) { 
156             AliError("AliITSHandleDaSSD: Error assignment operator");
157             for (Int_t i = (modind - 1); i >= 0; i--) delete fModules[modind];
158             delete [] fModules;
159             fModules = NULL;
160             break;
161           }
162         } else fModules[modind] = NULL; 
163       }   
164     } else {
165       AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", ssdadldc.fNumberOfModules));
166       fNumberOfModules = 0;
167       fModules = NULL;
168     }
169   }
170   return *this;
171 }
172
173
174 //______________________________________________________________________________
175 AliITSHandleDaSSD::~AliITSHandleDaSSD()
176 {
177 // Default destructor 
178   if (fModules) 
179   {
180     for (Int_t i = 0; i < fNumberOfModules; i++)
181     { 
182       if (fModules[i]) delete fModules[i];
183     }
184     delete [] fModules;
185   }
186   if (fModIndex) delete [] fModIndex;
187   if (fStaticBadChannelsMap) { fStaticBadChannelsMap->Delete(); delete fStaticBadChannelsMap; }
188   if (fDDLModuleMap) delete [] fDDLModuleMap;
189 }
190
191
192
193 //______________________________________________________________________________
194 void AliITSHandleDaSSD::Reset()
195 {
196 // Delete array of AliITSModuleDaSSD* objects. 
197   if (fModules) {
198     for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
199     delete [] fModules;
200     fModules = NULL;
201   }
202   if (fModIndex) { delete [] fModIndex; fModIndex = NULL; }
203 /*
204   if (fStaticBadChannelsMap) {
205     fStaticBadChannelsMap->Delete();
206     delete fStaticBadChannelsMap;
207     fStaticBadChannelsMap = NULL; 
208   }    
209   if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL; }
210 */
211   fRawDataFileName = NULL;
212   fModIndProcessed = fModIndRead = 0;
213   fNumberOfEvents = 0;
214   fLdcId = fRunId = 0;
215   fPedestalThresholdFactor = fgkPedestalThresholdFactor;
216   fCmThresholdFactor = fgkCmThresholdFactor;
217 }
218
219
220
221 //______________________________________________________________________________
222 Bool_t AliITSHandleDaSSD::Init(Char_t *rdfname, const Char_t *configfname)
223 {
224 // Read raw data file and set initial and configuration parameters
225   Long_t physeventind = 0, strn = 0, nofstripsev, nofstrips = 0;
226   Int_t  nofeqipmentev, nofeqipment = 0, eqn = 0; 
227   AliRawReaderDate  *rawreaderdate = NULL;
228   UChar_t *data = NULL;
229   Long_t datasize = 0, eqbelsize = 1;
230
231   if (configfname) ReadConfigurationFile(configfname);
232   rawreaderdate = new AliRawReaderDate(rdfname, 0);
233   if (!(rawreaderdate->GetAttributes() || rawreaderdate->GetEventId())) {
234     AliError(Form("AliITSHandleDaSSD: Error reading raw data file %s by RawReaderDate", rdfname));
235     MakeZombie();
236     return kFALSE;
237   }
238   if (rawreaderdate->NextEvent()) {
239     fRunId = rawreaderdate->GetRunNumber(); 
240     rawreaderdate->RewindEvents();
241   } else { MakeZombie(); return kFALSE; }
242   if (fModules) Reset();
243   rawreaderdate->SelectEvents(-1);
244   rawreaderdate->Select("ITSSSD");  
245   nofstrips = 0;
246   while (rawreaderdate->NextEvent()) {
247     if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
248     nofstripsev = 0;
249     nofeqipmentev = 0;
250     while (rawreaderdate->ReadNextData(data)) {
251       fLdcId = rawreaderdate->GetLDCId();
252       nofeqipmentev += 1;
253       datasize = rawreaderdate->GetDataSize();
254       eqbelsize = rawreaderdate->GetEquipmentElementSize();
255       if ( datasize % eqbelsize ) {
256         AliError(Form("AliITSHandleDaSSD: Error Init(%s): event data size %i is not an integer of equipment data size %i", 
257                                     rdfname, datasize, eqbelsize));
258         MakeZombie();
259         return kFALSE;
260       }
261       nofstripsev += (Int_t) (datasize / eqbelsize);
262     }
263     if (physeventind++) {
264       if (nofstrips != nofstripsev) AliWarning(Form("AliITSHandleDaSSD: number of strips varies from event to event, ev = %i, %i", 
265                                                      physeventind, nofstripsev));
266       if (nofeqipment != nofeqipmentev) AliWarning("AliITSHandleDaSSD: number of DDLs varies from event to event");
267     }
268     nofstrips = nofstripsev;
269     nofeqipment = nofeqipmentev;
270     if (strn < nofstrips)  strn = nofstrips;
271     if (eqn < nofeqipment) eqn = nofeqipment;
272   }
273   delete rawreaderdate;
274   if ((physeventind > 0) && (strn > 0))
275   {
276     fNumberOfEvents = physeventind;
277     fRawDataFileName = rdfname;
278     fModIndex = new (nothrow) Int_t [fgkNumberOfSSDModulesPerDdl * eqn];
279     if (fModIndex) 
280       for (Int_t i = 0; i < fgkNumberOfSSDModulesPerDdl * eqn; i++) fModIndex[i] = -1; 
281     else AliWarning(Form("AliITSHandleDaSSD: Error Init(%s): Index array for %i modules was not created", 
282                                      rdfname, fgkNumberOfSSDModulesPerDdl * eqn));
283     if (SetNumberOfModules(fgkNumberOfSSDModulesPerDdl * eqn)) {
284       TString str = TString::Format("Max number of equipment: %i, max number of channels: %i\n", eqn, strn);
285       DumpInitData(str.Data());
286       return kTRUE;
287     }  
288   }
289   MakeZombie();
290   return kFALSE;
291 }
292
293
294 //______________________________________________________________________________
295 Bool_t AliITSHandleDaSSD::ReadConfigurationFile(const Char_t * /* configfname */) 
296 const {
297 // Dowload configuration parameters from configuration file or database
298   return kFALSE;
299 }
300
301
302
303 //______________________________________________________________________________
304 AliITSModuleDaSSD* AliITSHandleDaSSD::GetModule (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
305 {
306 // Retrieve AliITSModuleDaSSD object from the array
307    if (!fModules) return NULL;
308    for (Int_t i = 0; i < fNumberOfModules; i++) {
309      if (fModules[i]) {
310        if (    (fModules[i]->GetDdlId() == ddlID)
311             && (fModules[i]->GetAD() == ad)
312             && (fModules[i]->GetADC() == adc))
313             return fModules[i];
314      }      
315    }
316    return NULL;
317 }
318
319
320 Int_t AliITSHandleDaSSD::GetModuleIndex (const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
321 {
322 // Retrieve the position of AliITSModuleDaSSD object in the array
323    if (!fModules) return -1;
324    for (Int_t i = 0; i < fNumberOfModules; i++) {
325      if (fModules[i]) {
326        if (    (fModules[i]->GetDdlId() == ddlID)
327             && (fModules[i]->GetAD() == ad)
328             && (fModules[i]->GetADC() == adc))
329             return i;
330      }      
331    }
332    return -1;
333 }
334
335
336
337 //______________________________________________________________________________
338 AliITSChannelDaSSD* AliITSHandleDaSSD::GetStrip (const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const UShort_t stripID) const
339 {
340 // Retrieve AliITSChannalDaSSD object from the array
341   for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
342     if (    (fModules[modind]->GetDdlId() == ddlID)
343          && (fModules[modind]->GetAD() == ad)
344          && (fModules[modind]->GetADC() == adc)  ) 
345         {
346        return fModules[modind]->GetStrip(stripID);
347     }
348   }
349   AliError(Form("AliITSHandleDaSSD: Error GetStrip (%i, %i, %i, %i), strip not found, returns NULL!",
350                 ddlID, ad, adc, stripID));
351   return NULL;
352 }
353
354
355
356 //______________________________________________________________________________
357 Bool_t AliITSHandleDaSSD::SetModule(AliITSModuleDaSSD *const module, const Int_t index)
358
359 // Assign array element with AliITSModuleDaSSD object
360    if ((index < fNumberOfModules) && (index >= 0)) 
361      { 
362         if (fModules[index]) delete fModules[index];
363         fModules[index] = module;
364         return kTRUE;
365       }
366    else return kFALSE;                         
367 }
368
369
370
371 //______________________________________________________________________________
372 Bool_t AliITSHandleDaSSD::SetNumberOfModules (const Int_t numberofmodules)
373 {
374 // Allocates memory for AliITSModuleDaSSD objects
375   if (numberofmodules > fgkNumberOfSSDModules)
376     AliWarning(Form("AliITSHandleDaSSD: the number of modules %i you use exceeds the maximum %i for ALICE ITS SSD", 
377                      numberofmodules, fgkNumberOfSSDModules));
378   if (fModules) {
379     for (Int_t i = 0; i < fNumberOfModules; i++) if (fModules[i]) delete fModules[i];
380     delete [] fModules; 
381     fModules = NULL;
382   }
383   fModules = new (nothrow) AliITSModuleDaSSD* [numberofmodules];
384   if (fModules) {
385     fNumberOfModules = numberofmodules;
386     memset(fModules, 0, sizeof(AliITSModuleDaSSD*) * numberofmodules);
387     return kTRUE;
388   } else {
389      AliError(Form("AliITSHandleDaSSD: Error allocating memory for %i AliITSModulesDaSSD* objects!", numberofmodules));
390      fNumberOfModules = 0;
391      fModules = NULL;
392   }
393   return kFALSE;
394 }
395
396
397
398 //______________________________________________________________________________
399 Bool_t AliITSHandleDaSSD::ReadStaticBadChannelsMap(const Char_t *filename)
400 {
401 // Reads Static Bad Channels Map from the file
402   TFile *bcfile;
403   if (!filename) {
404     AliWarning("No file name is specified for Static Bad Channels Map!");
405     return kFALSE;
406   } 
407   bcfile = new TFile(filename, "READ");
408   if (bcfile->IsZombie()) {
409     AliWarning(Form("Error reading file %s with Static Bad Channels Map!", filename));
410     return kFALSE;
411   }
412   bcfile->GetObject("BadChannels;1", fStaticBadChannelsMap);
413   if (!fStaticBadChannelsMap) {
414     AliWarning("Error fStaticBadChannelsMap == NULL!");
415     bcfile->Close();
416     delete bcfile;
417     return kFALSE;
418   }
419   bcfile->Close();
420   delete bcfile;
421   return kTRUE;
422 }
423
424
425
426 Bool_t AliITSHandleDaSSD::ReadDDLModuleMap(const Char_t *filename)
427 {
428 // Reads the SSD DDL Map from the file
429   ifstream             ddlmfile;
430   AliRawReaderDate    *rwr = NULL;
431   AliITSRawStreamSSD  *rsm = NULL;
432   void                *event = NULL;
433   if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
434   fDDLModuleMap = new (nothrow) Int_t [fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl];
435   if (!fDDLModuleMap) {
436     AliWarning("Error allocation memory for DDL Map!");
437     return kFALSE;
438   }    
439   if (!filename) {
440     AliWarning("No file name is specified for SSD DDL Map, using the one from AliITSRawStreamSSD!");
441     rwr = new AliRawReaderDate(event);
442     rsm = new AliITSRawStreamSSD(rwr);
443     rsm->Setv11HybridDDLMapping();
444     for (Int_t ddli = 0; ddli < fgkNumberOfSSDDDLs; ddli++)
445       for (Int_t mi = 0; mi < fgkNumberOfSSDModulesPerDdl; mi++)
446         fDDLModuleMap[(ddli * fgkNumberOfSSDModulesPerDdl + mi)] = rsm->GetModuleNumber(ddli, mi);
447     if (rsm) delete rsm;
448     if (rwr) delete rwr;        
449     return kTRUE;
450   } 
451   ddlmfile.open(filename, ios::in);
452   if (!ddlmfile.is_open()) {
453     AliWarning(Form("Error reading file %s with SSD DDL Map!", filename));
454     if (fDDLModuleMap) { delete [] fDDLModuleMap; fDDLModuleMap = NULL;}
455     return kFALSE;
456   }
457   Int_t ind = 0;
458   while((!ddlmfile.eof()) && (ind < (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))) {
459     ddlmfile >> fDDLModuleMap[ind++];
460   }
461   if (ind != (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl))
462     AliWarning(Form("Only %i (< %i) entries were read from DDL Map!", ind, (fgkNumberOfSSDDDLs * fgkNumberOfSSDModulesPerDdl)));
463   ddlmfile.close();
464   return kTRUE;
465 }
466
467
468
469 //______________________________________________________________________________
470 Int_t AliITSHandleDaSSD::ReadCalibrationDataFile (char* fileName, const Long_t eventsnumber)
471 {
472 // Reads raw data from file
473   if (!Init(fileName)){
474     AliError("AliITSHandleDaSSD: Error ReadCalibrationDataFile");
475     return kFALSE;
476   }
477   fNumberOfEvents = eventsnumber;
478   return ReadModuleRawData (fNumberOfModules);  
479 }
480
481
482
483 //______________________________________________________________________________
484 Int_t AliITSHandleDaSSD::ReadModuleRawData (const Int_t modulesnumber)
485 {
486 // Reads raw data from file
487   AliRawReader        *rawreaderdate = NULL;
488   AliITSRawStreamSSD  *stream = NULL;
489   AliITSModuleDaSSD   *module;
490   AliITSChannelDaSSD  *strip;
491   Long_t            eventind = 0;
492   Int_t             nofeqipmentev, equipid, prequipid;
493   UShort_t          modind;
494   if (!(rawreaderdate = new AliRawReaderDate(fRawDataFileName, 0))) return 0;
495   if (!fModules) {
496     AliError("AliITSHandleDaSSD: Error ReadModuleRawData: no structure was allocated for data");
497     return 0;
498   }
499   if (!fDDLModuleMap) if (!ReadDDLModuleMap()) AliWarning("DDL map is not defined, ModuleID will be set to 0!");
500   stream = new AliITSRawStreamSSD(rawreaderdate);
501   stream->Setv11HybridDDLMapping();
502   rawreaderdate->SelectEvents(-1);
503   modind = 0;
504   while (rawreaderdate->NextEvent()) {
505     if ((rawreaderdate->GetType() != PHYSICS_EVENT) && (rawreaderdate->GetType() != CALIBRATION_EVENT)) continue;
506     nofeqipmentev = 0;
507     prequipid = -1;
508     while (stream->Next()) {
509       equipid    = rawreaderdate->GetEquipmentId(); 
510       if ((equipid != prequipid) && (prequipid >= 0)) nofeqipmentev += 1;
511       prequipid = equipid;
512       Int_t     equiptype  = rawreaderdate->GetEquipmentType();
513       UChar_t   ddlID      = (UChar_t)rawreaderdate->GetDDLID();
514       UChar_t   ad      = stream->GetAD();
515       UChar_t   adc     = stream->GetADC();
516       UShort_t  stripID = stream->GetSideFlag() ? AliITSChannelDaSSD::GetMaxStripIdConst() - stream->GetStrip() : stream->GetStrip();
517       Short_t   signal  = stream->GetSignal();
518
519       Int_t indpos = (nofeqipmentev * fgkNumberOfSSDModulesPerDdl)
520                    + ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
521       Int_t modpos = fModIndex[indpos];
522       if (((modpos > 0) && (modpos < fModIndRead)) || ((modpos < 0) && (modind == modulesnumber))) continue;
523       if ((modpos < 0) && (modind < modulesnumber)) {
524         module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
525         Int_t mddli;
526         if (fDDLModuleMap) mddli = RetrieveModuleId(ddlID, ad, adc);
527         else  mddli = 0;
528         if (!module->SetModuleIdData (ddlID, ad, adc, mddli)) return 0;
529 //      if (!module->SetModuleIdData (ddlID, ad, adc, RetrieveModuleId(ddlID, ad, adc))) return 0;
530         module->SetModuleRorcId (equipid, equiptype);
531         module->SetCMFeromEventsNumber(fNumberOfEvents);
532         modpos = fModIndRead + modind;
533         modind += 1;
534         fModules[modpos] = module;
535         fModIndex[indpos] = modpos;
536       } 
537       if (stripID < AliITSModuleDaSSD::GetStripsPerModuleConst()) {
538         if (!(strip = fModules[modpos]->GetStrip(stripID))) {
539           strip = new AliITSChannelDaSSD(stripID, fNumberOfEvents);
540           fModules[modpos]->SetStrip(strip, stripID);
541         }
542         strip->SetSignal(eventind, signal);
543       } else  fModules[modpos]->SetCMFerom(signal, (stripID - AliITSModuleDaSSD::GetStripsPerModuleConst()), eventind);
544     }
545     if (++eventind > fNumberOfEvents) break;
546   }
547   delete stream;
548   delete rawreaderdate;
549   if (modind) cout << "The memory was allocated for " <<  modind << " modules." << endl;
550   fModIndRead += modind;
551   if (modind < modulesnumber) RelocateModules();
552   return modind;
553 }
554
555
556
557 //______________________________________________________________________________
558 Bool_t AliITSHandleDaSSD::RelocateModules()
559 {
560 // Relocate memory for AliITSModuleDaSSD object array
561   Int_t         nm = 0;
562   AliITSModuleDaSSD **marray = NULL;
563   for (Int_t modind = 0; modind < fNumberOfModules; modind++)
564     if (fModules[modind]) nm += 1;
565   if (nm == fNumberOfModules) return kTRUE;
566   marray = new (nothrow) AliITSModuleDaSSD* [nm];
567   if (!marray) {
568     AliError(Form("AliITSHandleDaSSD: Error relocating memory for %i AliITSModuleDaSSD* objects!", nm));
569     return kFALSE;
570   }
571   nm = 0;
572   for (Int_t modind = 0; modind < fNumberOfModules; modind++)  
573     if (fModules[modind]) marray[nm++] = fModules[modind];
574   delete [] fModules;
575   fModules = marray;
576   fNumberOfModules = fModIndRead = nm;
577   return kTRUE;
578 }
579
580
581
582 //______________________________________________________________________________
583 Bool_t AliITSHandleDaSSD::AddFeromCm(AliITSModuleDaSSD *const module)
584 // Restore the original signal value adding CM calculated and subtracted in ferom
585 {
586   AliITSChannelDaSSD *strip;
587   Short_t            *signal, *cmferom;
588
589   if (!module) return kFALSE;
590   for (Int_t chipind = 0; chipind < AliITSModuleDaSSD::GetChipsPerModuleConst(); chipind++) {
591     if (!(cmferom = module->GetCMFerom(chipind))) {
592       AliWarning(Form("AliITSHandleDaSSD: There is no Ferom CM values for chip %i, module %i!", chipind, module->GetModuleId()));
593       continue;
594     }
595     for (Int_t strind = (chipind * AliITSModuleDaSSD::GetStripsPerChip()); 
596                strind < ((chipind + 1) * AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
597       if (!(strip = module->GetStrip(strind))) continue;
598       if (!(signal = strip->GetSignal())) continue;
599 //      if (strip->GetEventsNumber() != module->GetEventsNumber()) return kFALSE;
600       Long_t ovev = 0;
601       for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
602         if (SignalOutOfRange(signal[ev]) || SignalOutOfRange(cmferom[ev])) ovev += 1;
603         else {
604           Short_t signal1 = signal[ev] + cmferom[ev];
605           strip->SetSignal(ev, signal1);
606         }  
607       } 
608     } 
609   }  
610   return kTRUE;
611 }
612
613
614
615 //______________________________________________________________________________
616 Bool_t AliITSHandleDaSSD::CalculatePedestal(AliITSModuleDaSSD *const module)
617 {
618 // Calculates Pedestal
619   AliITSChannelDaSSD *strip;
620   Float_t             pedestal, noise;
621   Short_t            *signal;
622   Long_t              ovev, ev, n;
623   if (!module) return kFALSE;
624   for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
625     if (!(strip = module->GetStrip(strind))) continue;
626     if (!(signal = strip->GetSignal())) {
627       AliError(Form("AliITSHandleDaSSD: Error CalculatePedestal(): there are no events data for module[%i] strip[%i]->GetSignal()",
628                      module->GetModuleId(), strind));
629       continue; 
630     }
631 //************* pedestal first pass ****************
632     pedestal = 0.0f;
633     ovev = 0l;
634     for (ev = 0; ev < strip->GetEventsNumber(); ev++)
635       if (SignalOutOfRange(signal[ev])) ovev += 1;
636       else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
637     if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
638     strip->SetPedestal(pedestal);       
639 //************* noise *******************************
640     Double_t nsum = 0.0L;
641     ovev = 0l;
642     for (ev = 0; ev < strip->GetEventsNumber(); ev++) {
643       if (SignalOutOfRange(signal[ev])) ovev += 1;
644       else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
645     } 
646     if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise =  sqrt(nsum / (Float_t)(n));
647     else  noise = AliITSChannelDaSSD::GetUndefinedValue();
648     strip->SetNoise(noise);
649 //************* pedestal second pass ****************
650     pedestal = 0.0f;
651     ovev = 0l;
652     for (ev = 0; ev < strip->GetEventsNumber(); ev++)
653       if (   SignalOutOfRange(signal[ev]) 
654           || TMath::Abs(signal[ev] - strip->GetPedestal()) > (fPedestalThresholdFactor * strip->GetNoise())) ovev += 1;
655       else pedestal = ((ev - ovev)) ? pedestal + (signal[ev] - pedestal) / static_cast<Float_t>(ev - ovev + 1) : signal[ev];
656     if (ev == ovev) pedestal = AliITSChannelDaSSD::GetUndefinedValue();
657     strip->SetPedestal(pedestal);       
658     strip->SetOverflowNumber(ovev);     
659   }
660   return kTRUE;
661 }
662
663
664 //______________________________________________________________________________
665 Bool_t AliITSHandleDaSSD::CalculateNoise(AliITSModuleDaSSD *const module)
666 {
667 // Calculates Noise
668   AliITSChannelDaSSD *strip;
669   Short_t    *signal;
670   Float_t     noise;
671   Long_t      ovev, n;
672   if (!module) return kFALSE;
673   for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
674     if (!(strip = module->GetStrip(strind))) continue;
675     if (!(signal = strip->GetSignal())) {
676       strip->SetNoise(AliITSChannelDaSSD::GetUndefinedValue());
677       AliError(Form("AliITSHandleDaSSD: Error CalculateNoise(): there are no events data for module[%i] strip[%i]->GetSignal()",
678                      module->GetModuleId(), strind));
679       continue;
680     }
681     Double_t nsum = 0.0L;
682     ovev = 0l;
683     for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
684       if (SignalOutOfRange(signal[ev])) ovev += 1;
685       else nsum += pow((signal[ev] - strip->GetPedestal()), 2);
686     } 
687     if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise =  sqrt(nsum / (Float_t)(n));
688     else  noise = AliITSChannelDaSSD::GetUndefinedValue();
689     strip->SetNoise(noise);
690   }
691   return kTRUE;
692 }
693
694
695
696 //______________________________________________________________________________
697 Bool_t AliITSHandleDaSSD::CalculateNoiseCM(AliITSModuleDaSSD *const module)
698 {
699 // Calculates Noise with CM correction
700   AliITSChannelDaSSD  *strip = NULL;
701   Short_t     *signal;
702   Float_t      noise;
703   Long_t       ovev, n;
704   if (!CalculateCM(module)) { 
705     AliError("Error: AliITSHandleDaSSD::CalculateCM() returned kFALSE");
706     return kFALSE;
707   }  
708   for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
709     if (!(strip = module->GetStrip(strind))) continue; //return kFALSE;
710     if (!(signal = strip->GetSignal())) {
711       strip->SetNoiseCM(AliITSChannelDaSSD::GetUndefinedValue());
712       AliError(Form("SSDDAModule: Error CalculateNoiseWithoutCM(): there are no events data for module[%i] strip[%i]->GetSignal()", 
713                      module->GetModuleId(), strind));
714       continue; //return kFALSE;
715     }
716     Int_t chipind = strind / AliITSModuleDaSSD::GetStripsPerChip();
717     Double_t nsum = 0.0L;
718     ovev = 0l;
719     for (Long_t ev = 0; ev < strip->GetEventsNumber(); ev++) {
720       if (SignalOutOfRange(signal[ev])) ovev += 1;
721       else nsum += pow((signal[ev] - strip->GetPedestal() - module->GetCM(chipind, ev)), 2);
722     } 
723     if ((n = strip->GetEventsNumber() - ovev - 1) > 0) noise =  sqrt(nsum / (Float_t)(n));
724     else  noise = AliITSChannelDaSSD::GetUndefinedValue();
725     strip->SetNoiseCM(noise);
726   }
727   return kTRUE;
728 }
729
730
731
732 //______________________________________________________________________________
733 Bool_t AliITSHandleDaSSD::CalculateCM(AliITSModuleDaSSD *const module)
734 {
735 // Calculates CM
736   AliITSChannelDaSSD  *strip = NULL;
737   Short_t             *signal;
738   Long_t               ovstr, n;
739   Int_t                stripind;
740   module->SetNumberOfChips(AliITSModuleDaSSD::GetChipsPerModuleConst());
741   for (Int_t chipind = 0; chipind < module->GetNumberOfChips(); chipind++) {
742     stripind = chipind * module->GetStripsPerChip();
743     module->GetCM()[chipind].Set(fNumberOfEvents);
744     module->GetCM()[chipind].Reset(0.0f);
745     for (Long_t ev = 0; ev < fNumberOfEvents; ev++) {
746     // calculate firs approximation of CM.
747       Double_t cm0 = 0.0L;
748       ovstr = 0l;
749       for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
750         if (!(strip = module->GetStrip(strind))) continue; //return kFALSE; 
751         if (!(signal = strip->GetSignal())) {
752           AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()", 
753                         module->GetModuleId(), strind));
754           return kFALSE;
755         }
756         if ((signal[ev] >= AliITSChannelDaSSD::GetOverflowConst()) || 
757             (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
758         else cm0 += (signal[ev] - strip->GetPedestal());
759       }
760       if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cm0 /= (Float_t)(n);
761       else { module->SetCM(0.0f, chipind, ev); continue; }
762     // calculate avarage (cm - (signal - pedestal)) over the chip
763       Double_t cmsigma = 0.0L;
764       ovstr = 0l;
765       for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
766         if (!(strip = module->GetStrip(strind))) continue;
767         if (!(signal = strip->GetSignal())) {
768           AliError(Form("AliITSHandleDaSSD: Error CalculateCM: there are no events data for module[%i] strip[%i]->GetSignal()\n",
769                          module->GetModuleId(), strind));
770           return kFALSE;
771         }
772         if ((signal[ev] >= AliITSChannelDaSSD::GetOverflowConst()) || 
773             (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue())) ovstr += 1;
774         else cmsigma += pow((cm0 - (signal[ev] - strip->GetPedestal())), 2);
775       }
776       if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsigma = sqrt(cmsigma / (Float_t)(n));
777       else { module->SetCM(0.0f, chipind, ev); continue; }
778    // calculate cm with threshold
779       Double_t cmsum = 0.0L;
780       ovstr = 0l;
781       for (Int_t strind = stripind; strind < (stripind + AliITSModuleDaSSD::GetStripsPerChip()); strind++) {
782         if (!(strip = module->GetStrip(strind))) continue;
783         signal = strip->GetSignal();
784         if (   (signal[ev] >= AliITSChannelDaSSD::GetOverflowConst())
785             || (strip->GetPedestal() == AliITSChannelDaSSD::GetUndefinedValue()) 
786             || (TMath::Abs(cm0 - (signal[ev] - strip->GetPedestal())) > (fCmThresholdFactor * cmsigma)) ) ovstr += 1;
787         else cmsum += (signal[ev] - strip->GetPedestal());
788       }
789       if ((n = AliITSModuleDaSSD::GetStripsPerChip() - ovstr)) cmsum /= (Float_t)(n);
790       else cmsum = 0.0L;
791       if (!module->SetCM(cmsum, chipind, ev));
792     } 
793   }
794   return kTRUE; 
795 }
796
797
798 //______________________________________________________________________________
799 Bool_t AliITSHandleDaSSD::ProcessRawData(const Int_t nmread)
800 {
801 // Performs calculation of calibration parameters (pedestal, noise, ...) 
802   Int_t nm = 0;
803   if (nmread <= 0) return kFALSE;
804   if (!fModules) return kFALSE;
805   while ((nm = ReadModuleRawData(nmread)) > 0) {
806     cout << "Processing next " << nm << " modules;" << endl;  
807     for (Int_t modind = fModIndProcessed; modind < fModIndRead; modind++) {
808       if (!fModules[modind]) {
809         AliError(Form("AliITSHandleDaSSD: Error ProcessRawData(): No AliITSModuleDaSSD object with index %i is allocated in AliITSHandleDaSSD\n",
810                        modind));
811         return kFALSE;
812       }
813       AddFeromCm(fModules[modind]);
814       CalculatePedestal(fModules[modind]);
815       CalculateNoise(fModules[modind]);
816       CalculateNoiseCM(fModules[modind]);
817     }
818     DeleteSignal();
819     DeleteCM();
820     DeleteCMFerom();
821     fModIndProcessed = fModIndRead;
822     cout << fModIndProcessed << " - done" << endl;
823   }
824   return kTRUE;  
825 }
826
827
828 //______________________________________________________________________________
829 Short_t AliITSHandleDaSSD::RetrieveModuleId(const UChar_t ddlID, const UChar_t ad, const UChar_t adc) const
830 {
831 // Retrieve ModuleId from the DDL map which is defined in AliITSRawStreamSSD class
832   if (!fDDLModuleMap) return 0;
833   Int_t mddli = ((ad - 1) * fgkNumberOfSSDModulesPerSlot) + (adc < 6 ? adc : (adc - 2));
834   if ((ddlID < fgkNumberOfSSDDDLs) && (mddli < fgkNumberOfSSDModulesPerDdl)) {
835     mddli = fDDLModuleMap[ddlID * fgkNumberOfSSDModulesPerDdl + mddli];
836   }  
837   else {
838     AliWarning(Form("Module index  = %d or ddlID = %d is out of range 0 is rturned", ddlID, mddli));
839     mddli = 0;
840   }
841   if (mddli > SHRT_MAX) return SHRT_MAX;
842   else return (Short_t)mddli;
843 }
844
845
846
847 //______________________________________________________________________________
848 TObjArray* AliITSHandleDaSSD::GetCalibrationSSDLDC() const
849 {
850 // Fill in the array for OCDB 
851   TObjArray *ldcc;
852   TObject   *modcalibobj;
853   if (!fModules) return NULL;
854   ldcc = new TObjArray(fNumberOfModules, 0);
855   for (Int_t i = 0; i < fNumberOfModules; i++) {
856     if (!fModules[i]) {
857       delete ldcc;
858       return NULL;
859     }
860     modcalibobj = dynamic_cast<TObject*>(fModules[i]->GetCalibrationNoise());
861     ldcc->AddAt(modcalibobj, i);
862   }
863   ldcc->Compress();
864   return ldcc;
865 }
866
867
868 //______________________________________________________________________________
869 Bool_t AliITSHandleDaSSD::SaveCalibrationSSDLDC(Char_t*& dafname) const
870 {
871 // Save Calibration data locally
872   TObjArray      *ldcn, *ldcp, *ldcbc;
873   TObject        *modobjn, *modobjp, *modobjbc;
874   Char_t         *tmpfname;
875   TString         dadatafilename("");
876   if (!fModules) return kFALSE;
877   ldcn = new TObjArray(fNumberOfModules, 0);
878   ldcn->SetName("Noise");
879   ldcp = new TObjArray(fNumberOfModules, 0);
880   ldcp->SetName("Pedestal");
881   ldcbc = new TObjArray(fNumberOfModules, 0);
882   ldcbc->SetName("BadChannels");
883   for (Int_t i = 0; i < fNumberOfModules; i++) {
884     if (!fModules[i]) {
885       delete ldcn;
886       return kFALSE;
887     }
888     modobjn = dynamic_cast<TObject*>(fModules[i]->GetCalibrationNoise());
889     modobjp = dynamic_cast<TObject*>(fModules[i]->GetCalibrationPedestal());
890     modobjbc = dynamic_cast<TObject*>(fModules[i]->GetCalibrationBadChannels());
891     ldcn->AddAt(modobjn, i);
892     ldcp->AddAt(modobjp, i);
893     ldcbc->AddAt(modobjbc, i);
894   }
895   ldcn->Compress();
896   ldcp->Compress();
897   ldcbc->Compress();
898   if (dafname) dadatafilename.Form("%s/", dafname);
899   dadatafilename += TString::Format("ITSSSDda_%i.root", fLdcId);
900   tmpfname = new Char_t[dadatafilename.Length()+1];
901   dafname = strcpy(tmpfname, dadatafilename.Data());
902   TFile *fileRun = new TFile (dadatafilename.Data(),"RECREATE");
903   if (fileRun->IsZombie()) {
904     AliError(Form("AliITSHandleDaSSD: SaveCalibrationSSDLDC() error open file %s", dadatafilename.Data()));
905     ldcn->Delete();
906     delete fileRun;
907     delete ldcn;
908     delete ldcp;
909     delete ldcbc;
910     return kFALSE;
911   }
912   fileRun->WriteTObject(ldcn);
913   fileRun->WriteTObject(ldcp);
914   if (fStaticBadChannelsMap) fileRun->WriteTObject(fStaticBadChannelsMap);
915   else fileRun->WriteTObject(ldcbc);
916   fileRun->Close();
917   ldcn->Delete();
918   delete fileRun;
919   delete ldcn;
920   delete ldcp;
921   delete ldcbc;
922   return kTRUE;
923 }
924
925
926
927 //______________________________________________________________________________
928 Bool_t AliITSHandleDaSSD::DumpModInfo(const Float_t meannosethreshold) const
929 {
930 // Dump calibration parameters
931   AliITSModuleDaSSD    *mod;
932   AliITSChannelDaSSD   *strip;
933   if (!fModules) {
934     cout << "SSDDALDC::DumpModInfo():  Error, no modules are allocated!" << endl;
935     return kFALSE;
936   }  
937   cout << "Modules with MeanNoise > " << meannosethreshold << endl;
938   for (Int_t i = 0; i < fNumberOfModules; i++) {
939     if (!(mod = fModules[i])) continue;
940     Float_t  maxnoise = 0.0f, meannoise = 0.0f, maxped = 0.0f;
941     Int_t    maxstrind = 0, novfstr = 0;  
942     for (Int_t strind = 0; strind < mod->GetNumberOfStrips(); strind++) {
943       if (!(strip = mod->GetStrip(strind))) {novfstr++;  continue; }
944       if (strip->GetNoiseCM() >= AliITSChannelDaSSD::GetUndefinedValue() ) {novfstr++;  continue; }
945       if (maxnoise < strip->GetNoiseCM()) { 
946         maxnoise = strip->GetNoiseCM();
947         maxstrind = strind;
948       } 
949       meannoise = (strind - novfstr) ? meannoise + (strip->GetNoiseCM() - meannoise) / static_cast<Float_t>(strind - novfstr + 1) 
950                                     : strip->GetNoiseCM();
951       if (TMath::Abs(maxped) < TMath::Abs(strip->GetPedestal())) maxped = strip->GetPedestal();                     
952     } 
953     if (meannoise > meannosethreshold)
954       cout << "Mod: " << i << ";  DDl: " << (int)mod->GetDdlId() << ";  AD: " << (int)mod->GetAD()  
955                            << ";  ADC: " << (int)mod->GetADC() << "; MaxPed = " << maxped
956                            << ";  MeanNoise = " << meannoise 
957                            << ";  NOfStrips = " << (mod->GetNumberOfStrips() - novfstr) << endl;
958   }
959   return kTRUE;
960 }
961
962
963
964 //______________________________________________________________________________
965 Bool_t AliITSHandleDaSSD::PrintModCalibrationData(const UChar_t ddlID, const UChar_t ad, const UChar_t adc, const Char_t *fname) const
966 {
967 // Print Module calibration data whether in file on in cout
968    AliITSChannelDaSSD  *strip;
969    ofstream             datafile;
970    ostream             *outputfile;
971    if (!fname) { outputfile = &cout; }
972    else {
973      datafile.open(fname, ios::out);
974      if  (datafile.fail()) return kFALSE;
975      outputfile = dynamic_cast<ostream*>(&datafile); 
976    }
977    *outputfile  << "DDL = " << (int)ddlID << ";  AD = " << (int)ad << ";  ADC = " << (int)adc << endl;
978    for (Int_t strind = 0; strind < AliITSModuleDaSSD::GetStripsPerModuleConst(); strind++) {
979      if ( (strip = GetStrip(ddlID, ad, adc, strind)) ) {
980        *outputfile << "Str = " << strind << ";  ped = " << strip->GetPedestal() 
981                    << ";  noise = " << strip->GetNoiseCM() << endl;
982      }
983      else continue;
984    }
985   if (datafile.is_open()) datafile.close(); 
986   return kTRUE;
987 }
988
989
990
991 //______________________________________________________________________________
992 void AliITSHandleDaSSD::DumpInitData(const Char_t *str) const
993 {
994 // Print general information retrieved from raw data file
995   cout << "Raw data file: " << fRawDataFileName << endl
996        << "LDC: " << (Int_t)fLdcId << "; RunId: " << fRunId << endl
997        << "Number of physics events: " << fNumberOfEvents << endl
998        << str;
999 }
1000
1001
1002 //______________________________________________________________________________
1003 Bool_t AliITSHandleDaSSD::AllocateSimulatedModules(const Int_t copymodind)
1004 {
1005 // Used to allocate simulated modules to test the performance  
1006   AliITSModuleDaSSD *module;
1007   UChar_t      ad, adc, ddlID;
1008   ad = adc = ddlID = 0;
1009   if (!(fModules[copymodind])) return kFALSE;
1010   for (Int_t modind = 0; modind < fNumberOfModules; modind++) {
1011     if (!fModules[modind]) {
1012       module = new AliITSModuleDaSSD(AliITSModuleDaSSD::GetStripsPerModuleConst());
1013       if ((adc < 5) || ((adc > 7) && (adc < 13)) ) adc += 1;
1014       else if (adc == 5) adc = 8;
1015       else if (adc == 13) {
1016         adc = 0;
1017         if (ad < 8) ad += 1;
1018         else {
1019           ad = 0;
1020           ddlID +=1;
1021         }
1022       }
1023       if (!module->SetModuleIdData (ddlID, ad, adc, modind)) return kFALSE;
1024       fModules[modind] = module;
1025       for (Int_t strind = 0; strind < module->GetNumberOfStrips(); strind++) {
1026         AliITSChannelDaSSD *cstrip = fModules[copymodind]->GetStrip(strind);
1027         Long_t      eventsnumber = cstrip->GetEventsNumber();
1028         AliITSChannelDaSSD *strip = new AliITSChannelDaSSD(strind, eventsnumber);
1029         for (Long_t evind = 0; evind < eventsnumber; evind++) {
1030           Short_t sign = *cstrip->GetSignal(evind);
1031           if (!strip->SetSignal(evind, sign)) AliError(Form("AliITSHandleDaSSD: Copy events error! mod = %i, str = %i", modind, strind));
1032         }
1033         module->SetStrip(strip, strind);
1034       }
1035     }
1036     else {
1037       ddlID = fModules[modind]->GetDdlId();
1038       ad    = fModules[modind]->GetAD();
1039       adc   = fModules[modind]->GetADC();
1040     }
1041   }
1042   for (UShort_t modind = 0; modind < fNumberOfModules; modind++) fModules[modind]->SetModuleId(modind + 1080);  
1043   return kTRUE;
1044 }