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