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