]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDcalibDB.cxx
correct also single distributions N+ and N-
[u/mrichter/AliRoot.git] / TRD / AliTRDcalibDB.cxx
CommitLineData
3551db50 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Class providing the calibration parameters by accessing the CDB //
21// //
2745a409 22// Request an instance with AliTRDcalibDB::Instance() //
3551db50 23// If a new event is processed set the event number with SetRun //
24// Then request the calibration data //
25// //
2745a409 26// Author: //
27// Jan Fiete Grosse-Oetringhaus (Jan.Fiete.Grosse-Oetringhaus@cern.ch) //
28// //
3551db50 29///////////////////////////////////////////////////////////////////////////////
30
f2391aef 31#include <TROOT.h>
a7ac01d2 32#include <TClonesArray.h>
e232d349 33#include <TObjArray.h>
3551db50 34
2745a409 35#include "AliCDBManager.h"
2745a409 36#include "AliCDBEntry.h"
37#include "AliLog.h"
3551db50 38
51a0ce25 39#include "AliTRDPIDReference.h"
121fadea 40#include "AliTRDPIDResponseObject.h"
3551db50 41#include "AliTRDcalibDB.h"
a9e22145 42#include "AliTRDtrapConfig.h"
43#include "AliTRDtrapConfigHandler.h"
eda91732 44#include "AliTRDCommonParam.h"
3551db50 45
7754cd1f 46#include "Cal/AliTRDCalROC.h"
7754cd1f 47#include "Cal/AliTRDCalPad.h"
48#include "Cal/AliTRDCalDet.h"
e232d349 49#include "Cal/AliTRDCalDCS.h"
d6a1ec13 50#include "Cal/AliTRDCalDCSv2.h"
ea3eaa08 51#include "Cal/AliTRDCalDCSFEEv2.h"
720a0a16 52#include "Cal/AliTRDCalPID.h"
7754cd1f 53#include "Cal/AliTRDCalMonitoring.h"
7754cd1f 54#include "Cal/AliTRDCalChamberStatus.h"
7754cd1f 55#include "Cal/AliTRDCalPadStatus.h"
56#include "Cal/AliTRDCalSingleChamberStatus.h"
9dcc64cc 57#include "Cal/AliTRDCalTrkAttach.h"
ea3eaa08 58#include "Cal/AliTRDCalOnlineGainTable.h"
3551db50 59
60ClassImp(AliTRDcalibDB)
61
2745a409 62AliTRDcalibDB *AliTRDcalibDB::fgInstance = 0;
63Bool_t AliTRDcalibDB::fgTerminated = kFALSE;
3551db50 64
65//_ singleton implementation __________________________________________________
66AliTRDcalibDB* AliTRDcalibDB::Instance()
67{
68 //
69 // Singleton implementation
70 // Returns an instance of this class, it is created if neccessary
63a700c6 71 //
3551db50 72
6d50f529 73 if (fgTerminated != kFALSE) {
3551db50 74 return 0;
6d50f529 75 }
3551db50 76
6d50f529 77 if (fgInstance == 0) {
3551db50 78 fgInstance = new AliTRDcalibDB();
6d50f529 79 }
e254cad1 80
3551db50 81 return fgInstance;
4e009ce4 82
3551db50 83}
84
2745a409 85//_____________________________________________________________________________
3551db50 86void AliTRDcalibDB::Terminate()
87{
88 //
89 // Singleton implementation
6bf5f0ce 90 // Deletes the instance of this class and sets the terminated flag,
91 // instances cannot be requested anymore
3551db50 92 // This function can be called several times.
93 //
94
95 fgTerminated = kTRUE;
96
6d50f529 97 if (fgInstance != 0) {
3551db50 98 delete fgInstance;
99 fgInstance = 0;
100 }
2745a409 101
3551db50 102}
103
104//_____________________________________________________________________________
105AliTRDcalibDB::AliTRDcalibDB()
2745a409 106 :TObject()
107 ,fRun(-1)
6d50f529 108 ,fPRFsmp(0)
109 ,fPRFbin(0)
110 ,fPRFlo(0)
111 ,fPRFhi(0)
112 ,fPRFwid(0)
113 ,fPRFpad(0)
9dcc64cc 114 ,fPIDResponse(NULL)
ea3eaa08 115 ,fOnlineGainTableID(0)
a9e22145 116 ,fTrapConfig(0x0)
f16844ef 117 ,fTrapConfigName("")
118 ,fTrapConfigVersion("")
3551db50 119{
120 //
2745a409 121 // Default constructor
3551db50 122 //
2745a409 123 // TODO Default runnumber is set to 0, this should be changed later
124 // to an invalid value (e.g. -1) to prevent
3551db50 125 // TODO invalid calibration data to be used.
2745a409 126 //
127
95867fd1 128 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
2745a409 129 fCDBCache[i] = 0;
130 fCDBEntries[i] = 0;
131 }
3551db50 132
2745a409 133 // Create the sampled PRF
134 SamplePRF();
d4c6453d 135
2745a409 136}
137
138//_____________________________________________________________________________
139AliTRDcalibDB::AliTRDcalibDB(const AliTRDcalibDB &c)
140 :TObject(c)
6d50f529 141 ,fRun(-1)
142 ,fPRFsmp(0)
143 ,fPRFbin(0)
144 ,fPRFlo(0)
145 ,fPRFhi(0)
146 ,fPRFwid(0)
147 ,fPRFpad(0)
9dcc64cc 148 ,fPIDResponse(NULL)
ea3eaa08 149 ,fOnlineGainTableID(0)
a9e22145 150 ,fTrapConfig(0x0)
f16844ef 151 ,fTrapConfigName("")
152 ,fTrapConfigVersion("")
2745a409 153{
154 //
155 // Copy constructor (not that it make any sense for a singleton...)
156 //
157
95867fd1 158 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
2745a409 159 fCDBCache[i] = 0;
3551db50 160 fCDBEntries[i] = 0;
161 }
6a739e92 162
163 // Create the sampled PRF
164 SamplePRF();
2745a409 165
166}
167
168//_____________________________________________________________________________
169AliTRDcalibDB &AliTRDcalibDB::operator=(const AliTRDcalibDB &c)
170{
171 //
172 // Assignment operator (same as above ...)
173 //
174
175 if (this != &c) {
176 AliFatal("No assignment operator defined");
177 }
4e009ce4 178
2745a409 179 return *this;
180
acba9bad 181}
3551db50 182
183//_____________________________________________________________________________
184AliTRDcalibDB::~AliTRDcalibDB()
185{
186 //
187 // destructor
188 //
189
6d50f529 190 if (fPRFsmp) {
191 delete [] fPRFsmp;
192 fPRFsmp = 0;
6a739e92 193 }
ea3eaa08 194
195 if (fPIDResponse) {
196 delete fPIDResponse;
197 fPIDResponse = 0x0;
198 }
6a739e92 199
3551db50 200 Invalidate();
2745a409 201
acba9bad 202}
3551db50 203
63a700c6 204//_caching functions____________________________________________________________
95867fd1 205const TObject *AliTRDcalibDB::GetCachedCDBObject(Int_t id)
63a700c6 206{
2745a409 207 //
208 // Retrieves a cdb object with the given id. The objects are cached as
209 // long as the run number is not changed.
210 //
211 // Put together the available objects here by using the lines
212 // a) For usual calibration objects:
213 // case kID<Name> :
214 // return CacheCDBEntry(kID<Name>,"TRD/Calib/<Path>");
215 // break;
216 // See function CacheCDBEntry for details.
217 // and
218 // b) For calibration data which depends on two objects: One containing
219 // a value per detector and one the local fluctuations per pad:
220 // case kID<Name> :
221 // return CacheMergeCDBEntry(kID<Name>,"TRD/Calib/<padPath>","TRD/Calib/<chamberPath>");
222 // break;
223 // See function CacheMergeCDBEntry for details.
224 //
63a700c6 225
6d50f529 226 switch (id) {
2745a409 227
228 // Parameters defined per pad and chamber
229 case kIDVdriftPad :
6d50f529 230 return CacheCDBEntry(kIDVdriftPad ,"TRD/Calib/LocalVdrift");
2745a409 231 break;
232 case kIDVdriftChamber :
6d50f529 233 return CacheCDBEntry(kIDVdriftChamber ,"TRD/Calib/ChamberVdrift");
2745a409 234 break;
eda91732 235 case kIDExBChamber :
236 return CacheCDBEntry(kIDExBChamber ,"TRD/Calib/ChamberExB");
237 break;
2745a409 238 case kIDT0Pad :
6d50f529 239 return CacheCDBEntry(kIDT0Pad ,"TRD/Calib/LocalT0");
2745a409 240 break;
241 case kIDT0Chamber :
6d50f529 242 return CacheCDBEntry(kIDT0Chamber ,"TRD/Calib/ChamberT0");
2745a409 243 break;
244 case kIDGainFactorPad :
6d50f529 245 return CacheCDBEntry(kIDGainFactorPad ,"TRD/Calib/LocalGainFactor");
2745a409 246 break;
247 case kIDGainFactorChamber :
6d50f529 248 return CacheCDBEntry(kIDGainFactorChamber ,"TRD/Calib/ChamberGainFactor");
2745a409 249 break;
ea3eaa08 250
251 case kIDOnlineGainFactor :
252 switch(GetOnlineGainTableID()) {
253 case 0:
254 // For testing purposes only !!!
255 AliInfo("No gain table name from OCDB. Use default table!");
256 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-01");
257 break;
258 case 1:
259 // Online gain table ID 1
260 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-01");
261 break;
412d07b9 262 case 2:
263 // Online gain table ID 2
264 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN0_2011-01");
265 break;
266 case 3:
267 // Online gain table ID 3
268 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN8_2011-01");
269 break;
3abf1c06 270 case 4:
271 // Online gain table ID 4
272 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-02");
273 break;
4a05be5f 274 case 5:
275 // Online gain table ID 5
276 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2011-03");
277 break;
278 case 6:
279 // Online gain table ID 6
280 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN0_2012-01");
281 break;
282 case 7:
283 // Online gain table ID 7
d9e5ae00 284 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Gaintbl_Uniform_FGAN8_2012-01");
285 break;
286 case 8:
287 // Online gain table ID 8
288 return CacheCDBEntry(kIDOnlineGainFactor ,"TRD/Calib/Krypton_2012-01");
4a05be5f 289 break;
ea3eaa08 290 }
291 break;
292
df83a620 293 case kIDNoiseChamber :
ea3eaa08 294 return CacheCDBEntry(kIDNoiseChamber ,"TRD/Calib/DetNoise");
df83a620 295 break;
296 case kIDNoisePad :
ea3eaa08 297 return CacheCDBEntry(kIDNoisePad ,"TRD/Calib/PadNoise");
df83a620 298 break;
299
2745a409 300 // Parameters defined per pad
301 case kIDPRFWidth :
6d50f529 302 return CacheCDBEntry(kIDPRFWidth ,"TRD/Calib/PRFWidth");
2745a409 303 break;
304
305 // Status values
2745a409 306 case kIDChamberStatus :
6d50f529 307 return CacheCDBEntry(kIDChamberStatus ,"TRD/Calib/ChamberStatus");
2745a409 308 break;
2745a409 309 case kIDPadStatus :
6d50f529 310 return CacheCDBEntry(kIDPadStatus ,"TRD/Calib/PadStatus");
2745a409 311 break;
312
313 // Global parameters
314 case kIDMonitoringData :
6d50f529 315 return CacheCDBEntry(kIDMonitoringData ,"TRD/Calib/MonitoringData");
2745a409 316 break;
aa617684 317 case kIDFEE :
318 return CacheCDBEntry(kIDFEE ,"TRD/Calib/FEE");
2745a409 319 break;
a9e22145 320 case kIDTrapConfig :
321 return CacheCDBEntry(kIDFEE ,"TRD/Calib/TrapConfig");
322 break;
e232d349 323 case kIDDCS :
5f481838 324 return CacheCDBEntry(kIDDCS ,"TRD/Calib/DCS");
e232d349 325 break;
44dbae42 326 case kIDPIDNN :
327 return CacheCDBEntry(kIDPIDNN ,"TRD/Calib/PIDNN");
ea3eaa08 328 break;
2745a409 329 case kIDPIDLQ :
6d50f529 330 return CacheCDBEntry(kIDPIDLQ ,"TRD/Calib/PIDLQ");
2745a409 331 break;
9dcc64cc 332 case kIDPIDLQ1D:
333 return CacheCDBEntry(kIDPIDLQ1D ,"TRD/Calib/PIDLQ1D");
334 break;
a7ac01d2 335 case kIDRecoParam :
9dcc64cc 336 return CacheCDBEntry(kIDRecoParam ,"TRD/Calib/RecoParam");
337 break;
338 case kIDAttach :
339 return CacheCDBEntry(kIDAttach ,"TRD/Calib/TrkAttach");
a7ac01d2 340 break;
e2a1c98b 341 case kIDPHQ :
342 return CacheCDBEntry(kIDPHQ ,"TRD/Calib/PHQ");
343 break;
2745a409 344 }
345
346 return 0;
347
63a700c6 348}
349
350//_____________________________________________________________________________
95867fd1 351AliCDBEntry *AliTRDcalibDB::GetCDBEntry(const char *cdbPath)
63a700c6 352{
353 //
354 // Retrieves an entry with path <cdbPath> from the CDB.
355 //
356
95867fd1 357 AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
2745a409 358 if (!entry) {
a7ac01d2 359 AliError(Form("Failed to get entry: %s",cdbPath));
63a700c6 360 return 0;
361 }
362
63a700c6 363 return entry;
2745a409 364
63a700c6 365}
366
367//_____________________________________________________________________________
95867fd1 368const TObject *AliTRDcalibDB::CacheCDBEntry(Int_t id, const char *cdbPath)
63a700c6 369{
370 //
371 // Caches the entry <id> with cdb path <cdbPath>
372 //
d6a1ec13 373
2745a409 374 if (!fCDBCache[id]) {
63a700c6 375 fCDBEntries[id] = GetCDBEntry(cdbPath);
95867fd1 376 if (fCDBEntries[id]) {
63a700c6 377 fCDBCache[id] = fCDBEntries[id]->GetObject();
95867fd1 378 }
d6a1ec13 379 }
380
63a700c6 381 return fCDBCache[id];
ea3eaa08 382
63a700c6 383}
384
3551db50 385//_____________________________________________________________________________
386void AliTRDcalibDB::SetRun(Long64_t run)
387{
388 //
7754cd1f 389 // Sets current run number. Calibration data is read from the corresponding file.
3551db50 390 // When the run number changes the caching is invalidated.
391 //
7754cd1f 392
6d50f529 393 if (fRun == run) {
3551db50 394 return;
6d50f529 395 }
7754cd1f 396
3551db50 397 fRun = run;
95867fd1 398
3551db50 399 Invalidate();
2745a409 400
3551db50 401}
7754cd1f 402
3551db50 403//_____________________________________________________________________________
404void AliTRDcalibDB::Invalidate()
405{
406 //
407 // Invalidates cache (when run number is changed).
408 //
409
95867fd1 410 for (Int_t i = 0; i < kCDBCacheSize; ++i) {
2745a409 411 if (fCDBEntries[i]) {
412 if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE) {
11f5dd43 413 if ((fCDBEntries[i]->IsOwner() == kFALSE) &&
414 (fCDBCache[i])) {
e254cad1 415 delete fCDBCache[i];
2745a409 416 }
e254cad1 417 delete fCDBEntries[i];
418 }
3551db50 419 fCDBEntries[i] = 0;
2745a409 420 fCDBCache[i] = 0;
3551db50 421 }
422 }
2745a409 423
ea3eaa08 424 fOnlineGainTableID = 0;
425
df83a620 426}
ea3eaa08 427
df83a620 428//_____________________________________________________________________________
429Float_t AliTRDcalibDB::GetNoise(Int_t det, Int_t col, Int_t row)
430{
431 //
432 // Returns the noise level in ADC counts for the given pad.
433 //
434
435 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
436 (GetCachedCDBObject(kIDNoisePad));
437 if (!calPad) {
438 return -1;
439 }
440
441 AliTRDCalROC *roc = calPad->GetCalROC(det);
442 if (!roc) {
443 return -1;
444 }
445
446 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
447 (GetCachedCDBObject(kIDNoiseChamber));
448 if (!calChamber) {
449 return -1;
450 }
451
452 return calChamber->GetValue(det) * roc->GetValue(col,row);
453
454}
455
456//_____________________________________________________________________________
457AliTRDCalROC *AliTRDcalibDB::GetNoiseROC(Int_t det)
458{
459 //
460 // Returns the Vdrift calibration object for a given ROC
461 // containing one number per pad
462 //
463
464 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
465 (GetCachedCDBObject(kIDNoisePad));
466 if (!calPad) {
467 return 0;
468 }
469
470 AliTRDCalROC *roc = calPad->GetCalROC(det);
471 if (!roc) {
472 return 0;
473 }
474 else {
475 return roc;
476 }
477
478}
479
480//_____________________________________________________________________________
481const AliTRDCalDet *AliTRDcalibDB::GetNoiseDet()
482{
483 //
484 // Returns the Vdrift calibration object
485 // containing one number per detector
486 //
487
488 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
489 (GetCachedCDBObject(kIDNoiseChamber));
490 if (!calChamber) {
491 return 0;
492 }
493 else {
494 return calChamber;
495 }
496
3551db50 497}
498
3551db50 499//_____________________________________________________________________________
500Float_t AliTRDcalibDB::GetVdrift(Int_t det, Int_t col, Int_t row)
501{
502 //
503 // Returns the drift velocity for the given pad.
504 //
7754cd1f 505
95867fd1 506 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
6d50f529 507 (GetCachedCDBObject(kIDVdriftPad));
508 if (!calPad) {
3551db50 509 return -1;
6d50f529 510 }
3551db50 511
95867fd1 512 AliTRDCalROC *roc = calPad->GetCalROC(det);
6d50f529 513 if (!roc) {
3551db50 514 return -1;
6d50f529 515 }
3551db50 516
95867fd1 517 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
6d50f529 518 (GetCachedCDBObject(kIDVdriftChamber));
519 if (!calChamber) {
7754cd1f 520 return -1;
6d50f529 521 }
7754cd1f 522
95867fd1 523 return calChamber->GetValue(det) * roc->GetValue(col,row);
2745a409 524
7754cd1f 525}
afb9f880 526
527//_____________________________________________________________________________
528AliTRDCalROC *AliTRDcalibDB::GetVdriftROC(Int_t det)
529{
530 //
531 // Returns the Vdrift calibration object for a given ROC
532 // containing one number per pad
533 //
534
535 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
536 (GetCachedCDBObject(kIDVdriftPad));
537 if (!calPad) {
538 return 0;
539 }
540
541 AliTRDCalROC *roc = calPad->GetCalROC(det);
542 if (!roc) {
543 return 0;
544 }
545 else {
546 return roc;
547 }
548
549}
550
551//_____________________________________________________________________________
552const AliTRDCalDet *AliTRDcalibDB::GetVdriftDet()
553{
554 //
555 // Returns the Vdrift calibration object
556 // containing one number per detector
557 //
558
559 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
560 (GetCachedCDBObject(kIDVdriftChamber));
561 if (!calChamber) {
562 return 0;
563 }
564 else {
565 return calChamber;
566 }
567
568}
7754cd1f 569
e2a1c98b 570//_____________________________________________________________________________
571TObjArray * AliTRDcalibDB::GetPHQ()
572{
573 //
574 //return PHQ calibration object
575 //
576 TObjArray *arr = (TObjArray *) (GetCachedCDBObject(kIDPHQ));
577 return arr;
578}
579
7754cd1f 580//_____________________________________________________________________________
581Float_t AliTRDcalibDB::GetVdriftAverage(Int_t det)
582{
583 //
584 // Returns the average drift velocity for the given detector
585 //
586
95867fd1 587 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
6d50f529 588 (GetCachedCDBObject(kIDVdriftChamber));
589 if (!calDet) {
7754cd1f 590 return -1;
6d50f529 591 }
7754cd1f 592
593 return calDet->GetValue(det);
2745a409 594
acba9bad 595}
eda91732 596//_____________________________________________________________________________
597const AliTRDCalDet *AliTRDcalibDB::GetExBDet()
598{
599 //
600 // Returns the exB calibration object
601 // containing one number per detector
602 //
603
604 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *> (GetCachedCDBObject(kIDExBChamber));
605
606 Double_t meanexb = 100.0;
607 if (calChamber) meanexb = calChamber->GetMean();
608 //printf("mean %f\n",meanexb);
3551db50 609
eda91732 610 if ((!calChamber) || (meanexb > 70.0)) {
611
612 const AliTRDCalDet *calChambervdrift = dynamic_cast<const AliTRDCalDet *>
613 (GetCachedCDBObject(kIDVdriftChamber));
614 if (!calChambervdrift) {
615 return 0;
616 }
617 else {
618 AliTRDCalDet *calDetExB = new AliTRDCalDet("lorentz angle tan","lorentz angle tan (detector value)");
619 for(Int_t k = 0; k < 540; k++){
620 calDetExB->SetValue(k,AliTRDCommonParam::Instance()->GetOmegaTau(calChambervdrift->GetValue(k)));
eda91732 621 }
622 return calDetExB;
623 }
624 }
625 else return calChamber;
626
627}
3551db50 628//_____________________________________________________________________________
629Float_t AliTRDcalibDB::GetT0(Int_t det, Int_t col, Int_t row)
630{
631 //
632 // Returns t0 for the given pad.
633 //
634
d4c6453d 635 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
636 (GetCachedCDBObject(kIDT0Pad));
6d50f529 637 if (!calPad) {
3551db50 638 return -1;
6d50f529 639 }
3551db50 640
d4c6453d 641 AliTRDCalROC *roc = calPad->GetCalROC(det);
6d50f529 642 if (!roc) {
3551db50 643 return -1;
6d50f529 644 }
3551db50 645
d4c6453d 646 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
647 (GetCachedCDBObject(kIDT0Chamber));
6d50f529 648 if (!calChamber) {
7754cd1f 649 return -1;
6d50f529 650 }
7754cd1f 651
8d786fb8 652 return calChamber->GetValue(det) + roc->GetValue(col,row);
2745a409 653
7754cd1f 654}
afb9f880 655
56178ff4 656//_____________________________________________________________________________
657AliTRDCalROC *AliTRDcalibDB::GetT0ROC(Int_t det)
658{
659 //
660 // Returns the t0 calibration object for a given ROC
661 // containing one number per pad
662 //
663
664 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
665 (GetCachedCDBObject(kIDT0Pad));
666 if (!calPad) {
667 return 0;
668 }
669
670 AliTRDCalROC *roc = calPad->GetCalROC(det);
671 if (!roc) {
672 return 0;
673 }
674 else {
675 return roc;
676 }
677
678}
679
680//_____________________________________________________________________________
681const AliTRDCalDet *AliTRDcalibDB::GetT0Det()
682{
683 //
684 // Returns the t0 calibration object
685 // containing one number per detector
686 //
687
688 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
689 (GetCachedCDBObject(kIDT0Chamber));
690 if (!calChamber) {
691 return 0;
692 }
693 else {
694 return calChamber;
695 }
696
697}
698
7754cd1f 699//_____________________________________________________________________________
700Float_t AliTRDcalibDB::GetT0Average(Int_t det)
701{
702 //
703 // Returns the average t0 for the given detector
704 //
705
5aba4f09 706 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
707 (GetCachedCDBObject(kIDT0Pad));
708 if (!calPad) {
709 return -1;
710 }
711
712 AliTRDCalROC *roc = calPad->GetCalROC(det);
713 if (!roc) {
714 return -1;
715 }
716
95867fd1 717 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
6d50f529 718 (GetCachedCDBObject(kIDT0Chamber));
719 if (!calDet) {
7754cd1f 720 return -1;
6d50f529 721 }
7754cd1f 722
4eb02ab1 723 Double_t sum = 0.0;
5aba4f09 724 for (Int_t channel = 0; channel < roc->GetNchannels(); ++channel) {
4eb02ab1 725 sum += roc->GetValue(channel);
5aba4f09 726 }
4eb02ab1 727 sum /= roc->GetNchannels();
728 sum += calDet->GetValue(det);
729 return sum;
2745a409 730
acba9bad 731}
3551db50 732
ea3eaa08 733//_____________________________________________________________________________
734AliTRDCalOnlineGainTableROC* AliTRDcalibDB::GetOnlineGainTableROC(Int_t det)
735{
736 //
737 // Returns the online gain factor table for a given ROC.
738 //
c36ddf52 739
740 if (!HasOnlineFilterGain()) {
741 return 0x0;
742 }
ea3eaa08 743
744 const AliTRDCalOnlineGainTable *calOnline
745 = dynamic_cast<const AliTRDCalOnlineGainTable *>
746 (GetCachedCDBObject(kIDOnlineGainFactor));
747 if (!calOnline) {
748 return 0x0;
749 }
750
751 return calOnline->GetGainTableROC(det);
752
753}
754
755//_____________________________________________________________________________
756Float_t AliTRDcalibDB::GetOnlineGainFactor(Int_t det, Int_t col, Int_t row)
757{
758 //
759 // Returns the online gain factor for the given pad.
760 //
c36ddf52 761
762 if (!HasOnlineFilterGain()) {
6c3e7ad0 763 return -1;
c36ddf52 764 }
ea3eaa08 765
766 const AliTRDCalOnlineGainTable *calOnline
767 = dynamic_cast<const AliTRDCalOnlineGainTable *>
768 (GetCachedCDBObject(kIDOnlineGainFactor));
769 if (!calOnline) {
770 return -1;
771 }
772
773 return calOnline->GetGainCorrectionFactor(det,row,col);
774
775}
776
56178ff4 777//_____________________________________________________________________________
778AliTRDCalROC *AliTRDcalibDB::GetGainFactorROC(Int_t det)
779{
780 //
781 // Returns the gain factor calibration object for a given ROC
56178ff4 782 //
783
784 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
785 (GetCachedCDBObject(kIDGainFactorPad));
786 if (!calPad) {
787 return 0;
788 }
789
790 AliTRDCalROC *roc = calPad->GetCalROC(det);
791 if (!roc) {
792 return 0;
793 }
794 else {
795 return roc;
796 }
797
798}
799
c36ddf52 800//_____________________________________________________________________________
801Float_t AliTRDcalibDB::GetGainFactor(Int_t det, Int_t col, Int_t row)
802{
803 //
804 // Returns the gain factor for the given pad.
805 //
806
807 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
808 (GetCachedCDBObject(kIDGainFactorPad));
809 if (!calPad) {
810 return -1;
811 }
812
813 AliTRDCalROC *roc = calPad->GetCalROC(det);
814 if (!roc) {
815 return -1;
816 }
817
818 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
819 (GetCachedCDBObject(kIDGainFactorChamber));
820 if (!calChamber) {
821 return -1;
822 }
823
824 return calChamber->GetValue(det) * roc->GetValue(col,row);
825
826}
827
56178ff4 828//_____________________________________________________________________________
829const AliTRDCalDet *AliTRDcalibDB::GetGainFactorDet()
830{
831 //
832 // Returns the gain factor calibration object
833 // containing one number per detector
834 //
835
836 const AliTRDCalDet *calChamber = dynamic_cast<const AliTRDCalDet *>
837 (GetCachedCDBObject(kIDGainFactorChamber));
838 if (!calChamber) {
839 return 0;
840 }
841 else {
842 return calChamber;
843 }
844
845}
846
7754cd1f 847//_____________________________________________________________________________
848Float_t AliTRDcalibDB::GetGainFactorAverage(Int_t det)
849{
850 //
851 // Returns the average gain factor for the given detector
852 //
853
95867fd1 854 const AliTRDCalDet *calDet = dynamic_cast<const AliTRDCalDet *>
6d50f529 855 (GetCachedCDBObject(kIDGainFactorChamber));
856 if (!calDet) {
7754cd1f 857 return -1;
6d50f529 858 }
7754cd1f 859
860 return calDet->GetValue(det);
2745a409 861
acba9bad 862}
6a739e92 863
524fc8fa 864//_____________________________________________________________________________
865AliTRDCalROC *AliTRDcalibDB::GetPRFROC(Int_t det)
866{
867 //
868 // Returns the PRF calibration object for a given ROC
869 // containing one number per pad
870 //
871
872 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
873 (GetCachedCDBObject(kIDPRFWidth));
874 if (!calPad) {
875 return 0;
876 }
877
878 AliTRDCalROC *roc = calPad->GetCalROC(det);
879 if (!roc) {
880 return 0;
881 }
882 else {
883 return roc;
884 }
885
886}
887
6a739e92 888//_____________________________________________________________________________
889Float_t AliTRDcalibDB::GetPRFWidth(Int_t det, Int_t col, Int_t row)
890{
891 //
892 // Returns the PRF width for the given pad.
893 //
894
95867fd1 895 const AliTRDCalPad *calPad = dynamic_cast<const AliTRDCalPad *>
6d50f529 896 (GetCachedCDBObject(kIDPRFWidth));
897 if (!calPad) {
6a739e92 898 return -1;
6d50f529 899 }
6a739e92 900
95867fd1 901 AliTRDCalROC *roc = calPad->GetCalROC(det);
6d50f529 902 if (!roc) {
6a739e92 903 return -1;
6d50f529 904 }
6a739e92 905
95867fd1 906 return roc->GetValue(col,row);
2745a409 907
acba9bad 908}
3551db50 909
910//_____________________________________________________________________________
5b7ccf04 911Int_t AliTRDcalibDB::ExtractTimeBinsFromString(TString tbstr)
3551db50 912{
a835b5d7 913 // Check if there is any content in the string first
914 if (tbstr.Length() == 0) {
915 AliError("Parameter for number of timebins is empty!");
6c3e7ad0 916 return -1;
e232d349 917 }
c6f7c6cb 918
a835b5d7 919 // Check if we have the correct config parameter
920 TString tbident = "tb";
921 TString tbsubstr = tbstr(0,2);
922 if (!tbsubstr.EqualTo(tbident)) {
923 AliError(Form("Parameter for number of timebins is corrupted (%s)!", tbstr.Data()));
6c3e7ad0 924 return -1;
a835b5d7 925 }
c6f7c6cb 926
a835b5d7 927 tbstr.Remove(0,2);
928 // check if there is more than a number
929 if (!tbstr.IsDigit()) {
930 AliError(Form("Parameter for number of timebins is corrupted (%s)!", tbstr.Data()));
6c3e7ad0 931 return -1;
e232d349 932 }
d6a1ec13 933
5b7ccf04 934 return tbstr.Atoi();
c6f7c6cb 935
5b7ccf04 936}
937
938//_____________________________________________________________________________
939Int_t AliTRDcalibDB::GetNumberOfTimeBinsDCS()
940{
941 //
942 // Returns number of time bins from the DCS
943 //
944
945 // Get the corresponding parameter
946 TString cfgstr = "", cfgname = "";
947 GetGlobalConfiguration(cfgname);
6c3e7ad0 948 if(cfgname.Length()==0)
949 return -1;
5b7ccf04 950 GetDCSConfigParOption(cfgname, kTimebin, 0, cfgstr);
6c3e7ad0 951 if(cfgstr.Length()==0)
952 return -1;
5b7ccf04 953 return ExtractTimeBinsFromString(cfgstr);
ea3eaa08 954
e232d349 955}
956
957//_____________________________________________________________________________
f1dcad37 958void AliTRDcalibDB::GetFilterType(TString &filterType)
959{
960 //
961 // Returns the filter type
962 //
963
5b7ccf04 964 TString cfgname = "";
965 GetGlobalConfiguration(cfgname);
966 GetDCSConfigParOption(cfgname, kFltrSet, 0, filterType);
d6a1ec13 967
af086c5e 968}
969
970//_____________________________________________________________________________
ea3eaa08 971Int_t AliTRDcalibDB::GetOnlineGainTableID()
972{
973 //
974 // Get the gain table ID from the DCS
975 //
976
977 if (fOnlineGainTableID > 0) {
978 return fOnlineGainTableID;
979 }
980
981 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
982 if (!dcsArr){
983 return -1;
984 }
985
986 Int_t esor = 0; // Take SOR
987 Int_t calver = 0; // Check CalDCS version
988 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
989 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
990
991 if (calver == 1) {
992
993 // No data for old DCS object available, anyway
994 return -1;
995
996 }
997 else if (calver == 2) {
998
999 // DCSv2 object
1000 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
1001 if(!calDCSv2){
1002 return -1;
1003 }
1004
1005 TString tableName = "";
1006 for (Int_t i = 0; i < 540; i++) {
1007 const AliTRDCalDCSFEEv2 *calDCSFEEv2 = calDCSv2->GetCalDCSFEEObj(0);
1008 tableName = calDCSFEEv2->GetGainTableName();
1009 if (tableName.Length() > 0) {
1010 break;
1011 }
1012 }
412d07b9 1013 if (tableName.CompareTo("Krypton_2011-01") == 0) {
ea3eaa08 1014 fOnlineGainTableID = 1;
1015 return fOnlineGainTableID;
1016 }
412d07b9 1017 if (tableName.CompareTo("Gaintbl_Uniform_FGAN0_2011-01") == 0) {
1018 fOnlineGainTableID = 2;
1019 return fOnlineGainTableID;
1020 }
1021 if (tableName.CompareTo("Gaintbl_Uniform_FGAN8_2011-01") == 0) {
1022 fOnlineGainTableID = 3;
1023 return fOnlineGainTableID;
1024 }
3abf1c06 1025 if (tableName.CompareTo("Krypton_2011-02") == 0) {
1026 fOnlineGainTableID = 4;
1027 return fOnlineGainTableID;
1028 }
4a05be5f 1029 if (tableName.CompareTo("Krypton_2011-03") == 0) {
1030 fOnlineGainTableID = 5;
1031 return fOnlineGainTableID;
1032 }
1033 if (tableName.CompareTo("Gaintbl_Uniform_FGAN0_2012-01") == 0) {
1034 fOnlineGainTableID = 6;
1035 return fOnlineGainTableID;
1036 }
1037 if (tableName.CompareTo("Gaintbl_Uniform_FGAN8_2012-01") == 0) {
1038 fOnlineGainTableID = 7;
1039 return fOnlineGainTableID;
1040 }
d9e5ae00 1041 if (tableName.CompareTo("Krypton_2011-03") == 0) {
1042 fOnlineGainTableID = 8;
1043 return fOnlineGainTableID;
1044 }
ea3eaa08 1045
1046 }
1047 else {
1048
1049 AliError("NO DCS/DCSv2 OCDB entry found!");
1050 return -1;
1051
1052 }
1053
45b38fb0 1054 return -1;
1055
ea3eaa08 1056}
1057
1058//_____________________________________________________________________________
1059void AliTRDcalibDB::GetGlobalConfiguration(TString &config)
1060{
af086c5e 1061 //
1062 // Get Configuration from the DCS
1063 //
d6a1ec13 1064
af086c5e 1065 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1066 if(!dcsArr){
a835b5d7 1067 AliError("No DCS CDB Object available!");
af086c5e 1068 config = "";
1069 return;
1070 }
d6a1ec13 1071
a835b5d7 1072 Int_t idSOR = 0, idEOR=1; // The index of SOR and EOR
1073 Bool_t hasSOR = (dcsArr->At(idSOR));
1074 Bool_t hasEOR = (dcsArr->At(idEOR));
1075 TString cfgSOR = "", cfgEOR = ""; // The configuration at SOR/EOR
d6a1ec13 1076
a835b5d7 1077 // The SOR object is mandatory
1078 if (!hasSOR) {
1079 AliError("NO SOR object found in CDB file!");
1080 config = "";
1081 return;
1082 }
1083 if (!hasEOR) AliWarning("NO EOR object found in CDB file!");
ea3eaa08 1084
a835b5d7 1085 // Check CalDCS version
1086 Int_t calver = 0;
1087 if (!strcmp(dcsArr->At(idSOR)->ClassName(),"AliTRDCalDCS")) calver = 1;
1088 else if (!strcmp(dcsArr->At(idSOR)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
ea3eaa08 1089
a835b5d7 1090 // Get the configuration strings
1091 if (calver == 1) {
1092 // DCS object
1093 const AliTRDCalDCS *calSOR = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(idSOR));
1094 cfgSOR = calSOR->GetGlobalConfigName();
1095 if (hasEOR) {
1096 const AliTRDCalDCS *calEOR = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(idEOR));
1097 cfgEOR = calEOR->GetGlobalConfigName();
1098 }
ea3eaa08 1099 }
1100 else if (calver == 2) {
d6a1ec13 1101 // DCSv2 object
a835b5d7 1102 const AliTRDCalDCSv2 *calv2SOR = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(idSOR));
1103 cfgSOR = calv2SOR->GetGlobalConfigName();
1104 if (hasEOR) {
1105 const AliTRDCalDCSv2 *calv2EOR = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(idEOR));
1106 cfgEOR = calv2EOR->GetGlobalConfigName();
1107 }
ea3eaa08 1108 }
1109 else {
ea3eaa08 1110 AliError("NO DCS/DCSv2 OCDB entry found!");
a835b5d7 1111 config = "";
1112 return;
1113 }
ea3eaa08 1114
a835b5d7 1115 // If there is no EOR entry, return the SOR value
1116 if (!hasEOR || cfgEOR.Length()==0) {
1117 config = cfgSOR;
1118 return;
ea3eaa08 1119 }
d6a1ec13 1120
a835b5d7 1121 // Check if the configuration is the same for both
1122 if (cfgSOR.EqualTo(cfgEOR)) {
1123 config = cfgSOR;
1124 return;
1125 }
1126
1127 // When both SOR and EOR have an entry but are different, the config is not defined
1128 AliError("Inconsistent configuration at start and end of run found!");
1129 config = "";
1130 return;
1131
af086c5e 1132}
f1dcad37 1133
f8059b39 1134//_____________________________________________________________________________
1135void AliTRDcalibDB::GetGlobalConfigurationVersion(TString &version)
1136{
1137 //
1138 // Get Version of Configuration from the DCS
1139 //
1140
1141 const TObjArray *dcsArr = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDDCS));
1142 if(!dcsArr){
1143 version = "";
1144 return;
1145 }
1146
1147 Int_t esor = 0; // Take SOR
1148 Int_t calver = 0; // Check CalDCS version
1149 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCS")) calver = 1;
1150 if (!strcmp(dcsArr->At(0)->ClassName(),"AliTRDCalDCSv2")) calver = 2;
1151
1152 if (calver == 1) {
1153
1154 // DCS object
1155 const AliTRDCalDCS *calDCS = dynamic_cast<const AliTRDCalDCS *>(dcsArr->At(esor));
1156 if(!calDCS){
1157 version = "";
1158 return;
1159 }
1160 version = calDCS->GetGlobalConfigVersion();
1161
1162 }
1163 else if (calver == 2) {
1164
1165 // DCSv2 object
1166 const AliTRDCalDCSv2 *calDCSv2 = dynamic_cast<const AliTRDCalDCSv2 *>(dcsArr->At(esor));
1167 if(!calDCSv2){
1168 version = "";
1169 return;
1170 }
1171 version = calDCSv2->GetGlobalConfigVersion();
1172
1173 }
1174 else {
1175
1176 AliError("NO DCS/DCSv2 OCDB entry found!");
1177
1178 }
1179
1180}
1181
af086c5e 1182//_____________________________________________________________________________
5b7ccf04 1183Int_t AliTRDcalibDB::GetNumberOfParsDCS(TString cname)
1184{
1185 // Get the number of configuration parameters from the DCS config
1186
1187 TString cdelim = "_";
1188 TObjArray *carr = cname.Tokenize(cdelim);
1189 return carr->GetEntries() - 1; // -1 for the "cf"
1190
1191}
1192
1193//_____________________________________________________________________________
1194Int_t AliTRDcalibDB::GetNumberOfOptsDCS(TString cname, Int_t cfgType)
1195{
1196 // Get the number of options of a given configuration parameter from DCS
1197
1198 TString cdelim = "_";
1199 TString odelim = "-";
1200
1201 TObjArray *carr = cname.Tokenize(cdelim);
1202 Int_t nconfig = carr->GetEntries();
1203
1204 // protect
1205 if ((nconfig == 0) || ((nconfig-1) < cfgType)) {
1206 AliError("Not enough parameters in DCS configuration name!");
1207 return 0;
1208 }
1209
1210 TString fullcfg = ((TObjString*)carr->At(cfgType))->GetString();
1211 TObjArray *oarr = fullcfg.Tokenize(odelim);
1212 return oarr->GetEntries() -1; // -1 for the parameter name
1213
1214}
1215
1216//_____________________________________________________________________________
1217void AliTRDcalibDB::GetDCSConfigParOption(TString cname, Int_t cfgType, Int_t option, TString &cfgo)
af086c5e 1218{
1219 //
fc358d0f 1220 // Get a configuration (see enum in header file) or the options of a configuration
1221 // option == 0 returns the configuration itself
1222 // option > 0 returns the optional parameter Nr. (option) of the configuration (cfgType)
af086c5e 1223 //
ea3eaa08 1224
fc358d0f 1225 // define the delimiters
1226 TString cdelim = "_";
1227 TString odelim = "-";
ea3eaa08 1228
fc358d0f 1229 TObjArray *carr = cname.Tokenize(cdelim);
1230 Int_t nconfig = carr->GetEntries();
1231
1232 // protect
1233 if (nconfig == 0) {
5b7ccf04 1234 AliError("DCS configuration name empty!");
fc358d0f 1235 cfgo = "";
1236 return;
1237 } else if ((nconfig-1) < cfgType) {
5b7ccf04 1238 AliError("Not enough parameters in DCS configuration name!");
fc358d0f 1239 cfgo = "";
1240 return;
1241 }
1242
1243 TString fullcfg = ((TObjString*)carr->At(cfgType))->GetString();
5b7ccf04 1244 TObjArray *oarr = fullcfg.Tokenize(odelim);
1245 Int_t noptions = oarr->GetEntries();
fc358d0f 1246
5b7ccf04 1247 // protect
1248 if ((noptions-1) < option) {
1249 AliError("Not enough options in DCS configuration name!");
1250 cfgo = "";
fc358d0f 1251 return;
fc358d0f 1252 }
fc358d0f 1253
5b7ccf04 1254 cfgo = ((TObjString*)oarr->At(option))->GetString();
1255 return;
fc358d0f 1256
1257}
1258
1259//_____________________________________________________________________________
1260Bool_t AliTRDcalibDB::HasOnlineFilterPedestal()
1261{
1262 //
1263 // Checks whether pedestal filter was applied online
1264 //
1265
1266 TString filterconfig;
1267 GetFilterType(filterconfig);
ea3eaa08 1268
af086c5e 1269 return filterconfig.Contains("p");
ea3eaa08 1270
af086c5e 1271}
1272
1273//_____________________________________________________________________________
ea3eaa08 1274Bool_t AliTRDcalibDB::HasOnlineFilterGain()
1275{
af086c5e 1276 //
1277 // Checks whether online gain filter was applied
1278 //
ea3eaa08 1279
fc358d0f 1280 TString filterconfig;
1281 GetFilterType(filterconfig);
ea3eaa08 1282
af086c5e 1283 return filterconfig.Contains("g");
ea3eaa08 1284
af086c5e 1285}
1286
1287//_____________________________________________________________________________
ea3eaa08 1288Bool_t AliTRDcalibDB::HasOnlineTailCancellation()
1289{
af086c5e 1290 //
1291 // Checks whether online tail cancellation was applied
1292 //
ea3eaa08 1293
fc358d0f 1294 TString filterconfig;
1295 GetFilterType(filterconfig);
ea3eaa08 1296
af086c5e 1297 return filterconfig.Contains("t");
ea3eaa08 1298
e232d349 1299}
1300
7754cd1f 1301//_____________________________________________________________________________
1302Char_t AliTRDcalibDB::GetPadStatus(Int_t det, Int_t col, Int_t row)
1303{
1304 //
1305 // Returns the status of the given pad
1306 //
1307
aa617684 1308 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1309 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1310 if (!cal) {
7754cd1f 1311 return -1;
6d50f529 1312 }
7754cd1f 1313
95867fd1 1314 const AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
6d50f529 1315 if (!roc) {
7754cd1f 1316 return -1;
6d50f529 1317 }
7754cd1f 1318
95867fd1 1319 return roc->GetStatus(col,row);
2745a409 1320
7754cd1f 1321}
1322
0e09df31 1323//_____________________________________________________________________________
1324AliTRDCalSingleChamberStatus* AliTRDcalibDB::GetPadStatusROC(Int_t det)
1325{
1326 //
1327 // Returns the pad status calibration object for a given ROC
1328 //
1329
1330 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1331 (GetCachedCDBObject(kIDPadStatus));
1332 if (!cal) {
1333 return 0;
1334 }
1335
1336 AliTRDCalSingleChamberStatus *roc = cal->GetCalROC(det);
1337 if (!roc) {
1338 return 0;
1339 }
1340 else {
1341 return roc;
1342 }
1343
1344}
1345
7754cd1f 1346//_____________________________________________________________________________
1347Char_t AliTRDcalibDB::GetChamberStatus(Int_t det)
1348{
1349 //
1350 // Returns the status of the given chamber
1351 //
1352
95867fd1 1353 const AliTRDCalChamberStatus *cal = dynamic_cast<const AliTRDCalChamberStatus *>
6d50f529 1354 (GetCachedCDBObject(kIDChamberStatus));
1355 if (!cal) {
7754cd1f 1356 return -1;
6d50f529 1357 }
7754cd1f 1358
1359 return cal->GetStatus(det);
2745a409 1360
7754cd1f 1361}
1362
a7ac01d2 1363//_____________________________________________________________________________
1364AliTRDrecoParam* AliTRDcalibDB::GetRecoParam(Int_t */*eventtype*/)
1365{
be28462a 1366 //
1367 // Returns the TRD reconstruction parameters from the OCDB
1368 //
1369
a7ac01d2 1370 const TClonesArray *recos = dynamic_cast<const TClonesArray*>(GetCachedCDBObject(kIDRecoParam));
be28462a 1371 if (!recos) return 0x0;
a7ac01d2 1372
1373 // calculate entry based on event type info
1374 Int_t n = 0; //f(eventtype[0], eventtype[1], ....)
be28462a 1375
ea3eaa08 1376 return (AliTRDrecoParam *) recos->UncheckedAt(n);
a7ac01d2 1377
be28462a 1378}
a7ac01d2 1379
7754cd1f 1380//_____________________________________________________________________________
1381Bool_t AliTRDcalibDB::IsPadMasked(Int_t det, Int_t col, Int_t row)
1382{
1383 //
1384 // Returns status, see name of functions for details ;-)
1385 //
1386
95867fd1 1387 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1388 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1389 if (!cal) {
7754cd1f 1390 return -1;
6d50f529 1391 }
7754cd1f 1392
95867fd1 1393 return cal->IsMasked(det,col,row);
2745a409 1394
7754cd1f 1395}
1396
1397//_____________________________________________________________________________
1398Bool_t AliTRDcalibDB::IsPadBridgedLeft(Int_t det, Int_t col, Int_t row)
1399{
1400 //
1401 // Returns status, see name of functions for details ;-)
1402 //
1403
95867fd1 1404 const AliTRDCalPadStatus *cal = dynamic_cast<const AliTRDCalPadStatus *>
1405 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1406 if (!cal) {
7754cd1f 1407 return -1;
6d50f529 1408 }
7754cd1f 1409
95867fd1 1410 return cal->IsBridgedLeft(det,col,row);
2745a409 1411
7754cd1f 1412}
1413
1414//_____________________________________________________________________________
1415Bool_t AliTRDcalibDB::IsPadBridgedRight(Int_t det, Int_t col, Int_t row)
1416{
1417 //
1418 // Returns status, see name of functions for details ;-)
1419 //
1420
95867fd1 1421 const AliTRDCalPadStatus * cal = dynamic_cast<const AliTRDCalPadStatus *>
1422 (GetCachedCDBObject(kIDPadStatus));
6d50f529 1423 if (!cal) {
7754cd1f 1424 return -1;
6d50f529 1425 }
7754cd1f 1426
95867fd1 1427 return cal->IsBridgedRight(det,col,row);
2745a409 1428
7754cd1f 1429}
1430
fa7427d0 1431//_____________________________________________________________________________
1432Bool_t AliTRDcalibDB::IsPadNotConnected(Int_t det, Int_t col, Int_t row)
1433{
1434 //
1435 // Returns status, see name of functions for details ;-)
1436 //
f1dcad37 1437
fa7427d0 1438 const AliTRDCalPadStatus * cal = dynamic_cast<const AliTRDCalPadStatus *>
1439 (GetCachedCDBObject(kIDPadStatus));
1440 if (!cal) {
1441 return -1;
1442 }
1443
1444 return cal->IsNotConnected(det,col,row);
1445
1446}
1447
7754cd1f 1448//_____________________________________________________________________________
eda91732 1449Bool_t AliTRDcalibDB::IsChamberGood(Int_t det)
1450{
1451 //
1452 // Returns status, see name of functions for details ;-)
1453 //
1454
1455 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1456 (GetCachedCDBObject(kIDChamberStatus));
1457 if (!cal) {
1458 return -1;
1459 }
1460
1461 return cal->IsGood(det);
1462
1463}
1464
1465//_____________________________________________________________________________
1466Bool_t AliTRDcalibDB::IsChamberNoData(Int_t det)
7754cd1f 1467{
1468 //
1469 // Returns status, see name of functions for details ;-)
1470 //
1471
95867fd1 1472 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1473 (GetCachedCDBObject(kIDChamberStatus));
6d50f529 1474 if (!cal) {
7754cd1f 1475 return -1;
6d50f529 1476 }
7754cd1f 1477
eda91732 1478 return cal->IsNoData(det);
2745a409 1479
7754cd1f 1480}
1481
1482//_____________________________________________________________________________
eda91732 1483Bool_t AliTRDcalibDB::IsHalfChamberNoData(Int_t det, Int_t side)
7754cd1f 1484{
1485 //
1486 // Returns status, see name of functions for details ;-)
1487 //
1488
95867fd1 1489 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1490 (GetCachedCDBObject(kIDChamberStatus));
6d50f529 1491 if (!cal) {
7754cd1f 1492 return -1;
6d50f529 1493 }
7754cd1f 1494
eda91732 1495 return side > 0 ? cal->IsNoDataSideB(det) : cal->IsNoDataSideA(det);
2745a409 1496
7754cd1f 1497}
ea3eaa08 1498
7a6352a6 1499//_____________________________________________________________________________
eda91732 1500Bool_t AliTRDcalibDB::IsChamberBadCalibrated(Int_t det)
ea3eaa08 1501{
7a6352a6 1502 //
1503 // Returns status, see name of functions for details ;-)
1504 //
7754cd1f 1505
7a6352a6 1506 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1507 (GetCachedCDBObject(kIDChamberStatus));
1508 if (!cal) {
1509 return -1;
1510 }
1511
eda91732 1512 return cal->IsBadCalibrated(det);
7a6352a6 1513
1514}
ea3eaa08 1515
67abca5c 1516//_____________________________________________________________________________
1517Bool_t AliTRDcalibDB::IsChamberNotCalibrated(Int_t det)
1518{
1519 //
1520 // Returns status, see name of functions for details ;-)
1521 //
1522
1523 const AliTRDCalChamberStatus * cal = dynamic_cast<const AliTRDCalChamberStatus *>
1524 (GetCachedCDBObject(kIDChamberStatus));
1525 if (!cal) {
1526 return -1;
1527 }
1528
1529 return cal->IsNotCalibrated(det);
1530
1531}
1532
cc7cef99 1533//_____________________________________________________________________________
0d83b3a5 1534const AliTRDCalPID *AliTRDcalibDB::GetPIDObject(AliTRDpidUtil::ETRDPIDMethod method)
cc7cef99 1535{
1536 //
1537 // Returns the object storing the distributions for PID with likelihood
1538 //
9a96f175 1539
1540 switch(method) {
0d83b3a5 1541 case AliTRDpidUtil::kLQ:
4ba1d6ae 1542 return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDLQ));
0d83b3a5 1543 case AliTRDpidUtil::kNN:
4ba1d6ae 1544 return dynamic_cast<const AliTRDCalPID *>(GetCachedCDBObject(kIDPIDNN));
543691ea 1545 case AliTRDpidUtil::kESD:
1546 return 0x0; // To avoid compiler warnings
9a96f175 1547 }
1548
10f75631 1549 return 0x0;
2745a409 1550
cc7cef99 1551}
1552
9dcc64cc 1553//_____________________________________________________________________________
f2391aef 1554AliTRDPIDResponse *AliTRDcalibDB::GetPIDResponse(AliTRDPIDResponse::ETRDPIDMethod /*method*/)
ea3eaa08 1555{
1556 //
1557 // Returns the PID response object for 1D-LQ
1558 //
1559
1560 if (!fPIDResponse) {
f2391aef 1561 AliDebug(2, "Setting new PID response.");
ea3eaa08 1562
9dcc64cc 1563 fPIDResponse = new AliTRDPIDResponse;
ea3eaa08 1564
9dcc64cc 1565 // Load Reference Histos from OCDB
f2391aef 1566// if(method == AliTRDPIDResponse::kLQ1D){
1567 fPIDResponse->SetPIDmethod(AliTRDPIDResponse::kLQ1D);
1568 const TObjArray *references = dynamic_cast<const TObjArray *>(GetCachedCDBObject(kIDPIDLQ1D));
1569
1570 TIter refs(references);
1571 TObject *obj = NULL;
1572 AliTRDPIDReference *ref = NULL;
1573 Bool_t hasReference = kFALSE;
1574 while ((obj = refs())){
1575 if ((ref = dynamic_cast<AliTRDPIDReference *>(obj))){
1576 AliDebug(2, "Setting new PID response object.");
1577 TDirectory *bkpdir = gDirectory;
1578 gROOT->cd();
1579 AliTRDPIDResponseObject *ro = new AliTRDPIDResponseObject;
1580 ro->SetPIDReference(ref);
1581 fPIDResponse->SetPIDResponseObject(ro);
1582 hasReference = kTRUE;
1583 gDirectory = bkpdir;
1584 break;
121fadea 1585 }
ea3eaa08 1586 }
1587
f2391aef 1588 if (!hasReference) {
1589 AliError("Reference histograms not found in the OCDB");
1590 }
9dcc64cc 1591 }
ea3eaa08 1592
f2391aef 1593// }
1594
9dcc64cc 1595 return fPIDResponse;
ea3eaa08 1596
9dcc64cc 1597}
1598
1599//_____________________________________________________________________________
1600const AliTRDCalTrkAttach* AliTRDcalibDB::GetAttachObject()
1601{
1602 //
1603 // Returns the object storing likelihood distributions for cluster to track attachment
1604 //
ea3eaa08 1605
9dcc64cc 1606 return dynamic_cast<const AliTRDCalTrkAttach*>(GetCachedCDBObject(kIDAttach));
9dcc64cc 1607
ea3eaa08 1608}
9dcc64cc 1609
7754cd1f 1610//_____________________________________________________________________________
d4c6453d 1611const AliTRDCalMonitoring *AliTRDcalibDB::GetMonitoringObject()
7754cd1f 1612{
1613 //
1614 // Returns the object storing the monitoring data
1615 //
1616
d4c6453d 1617 return dynamic_cast<const AliTRDCalMonitoring *>
1618 (GetCachedCDBObject(kIDMonitoringData));
1b95a37b 1619
7754cd1f 1620}
1621
6a739e92 1622//_____________________________________________________________________________
1623void AliTRDcalibDB::SamplePRF()
1624{
1625 //
2745a409 1626 // Samples the pad response function (should maybe go somewhere else ...)
6a739e92 1627 //
1628
1629 const Int_t kPRFbin = 61;
1630
053767a4 1631 Float_t prf[kNlayer][kPRFbin] = {
6d50f529 1632 {2.9037e-02, 3.3608e-02, 3.9020e-02, 4.5292e-02,
6a739e92 1633 5.2694e-02, 6.1362e-02, 7.1461e-02, 8.3362e-02,
1634 9.7063e-02, 1.1307e-01, 1.3140e-01, 1.5235e-01,
1635 1.7623e-01, 2.0290e-01, 2.3294e-01, 2.6586e-01,
1636 3.0177e-01, 3.4028e-01, 3.8077e-01, 4.2267e-01,
1637 4.6493e-01, 5.0657e-01, 5.4655e-01, 5.8397e-01,
1638 6.1767e-01, 6.4744e-01, 6.7212e-01, 6.9188e-01,
1639 7.0627e-01, 7.1499e-01, 7.1851e-01, 7.1499e-01,
1640 7.0627e-01, 6.9188e-01, 6.7212e-01, 6.4744e-01,
1641 6.1767e-01, 5.8397e-01, 5.4655e-01, 5.0657e-01,
1642 4.6493e-01, 4.2267e-01, 3.8077e-01, 3.4028e-01,
1643 3.0177e-01, 2.6586e-01, 2.3294e-01, 2.0290e-01,
1644 1.7623e-01, 1.5235e-01, 1.3140e-01, 1.1307e-01,
1645 9.7063e-02, 8.3362e-02, 7.1461e-02, 6.1362e-02,
1646 5.2694e-02, 4.5292e-02, 3.9020e-02, 3.3608e-02,
1647 2.9037e-02},
1648 {2.5478e-02, 2.9695e-02, 3.4655e-02, 4.0454e-02,
1649 4.7342e-02, 5.5487e-02, 6.5038e-02, 7.6378e-02,
1650 8.9696e-02, 1.0516e-01, 1.2327e-01, 1.4415e-01,
1651 1.6794e-01, 1.9516e-01, 2.2573e-01, 2.5959e-01,
1652 2.9694e-01, 3.3719e-01, 3.7978e-01, 4.2407e-01,
1653 4.6889e-01, 5.1322e-01, 5.5569e-01, 5.9535e-01,
1654 6.3141e-01, 6.6259e-01, 6.8882e-01, 7.0983e-01,
1655 7.2471e-01, 7.3398e-01, 7.3761e-01, 7.3398e-01,
1656 7.2471e-01, 7.0983e-01, 6.8882e-01, 6.6259e-01,
1657 6.3141e-01, 5.9535e-01, 5.5569e-01, 5.1322e-01,
1658 4.6889e-01, 4.2407e-01, 3.7978e-01, 3.3719e-01,
1659 2.9694e-01, 2.5959e-01, 2.2573e-01, 1.9516e-01,
1660 1.6794e-01, 1.4415e-01, 1.2327e-01, 1.0516e-01,
1661 8.9696e-02, 7.6378e-02, 6.5038e-02, 5.5487e-02,
1662 4.7342e-02, 4.0454e-02, 3.4655e-02, 2.9695e-02,
1663 2.5478e-02},
1664 {2.2363e-02, 2.6233e-02, 3.0782e-02, 3.6140e-02,
1665 4.2535e-02, 5.0157e-02, 5.9197e-02, 6.9900e-02,
1666 8.2707e-02, 9.7811e-02, 1.1548e-01, 1.3601e-01,
1667 1.5998e-01, 1.8739e-01, 2.1840e-01, 2.5318e-01,
1668 2.9182e-01, 3.3373e-01, 3.7837e-01, 4.2498e-01,
1669 4.7235e-01, 5.1918e-01, 5.6426e-01, 6.0621e-01,
1670 6.4399e-01, 6.7700e-01, 7.0472e-01, 7.2637e-01,
1671 7.4206e-01, 7.5179e-01, 7.5551e-01, 7.5179e-01,
1672 7.4206e-01, 7.2637e-01, 7.0472e-01, 6.7700e-01,
1673 6.4399e-01, 6.0621e-01, 5.6426e-01, 5.1918e-01,
1674 4.7235e-01, 4.2498e-01, 3.7837e-01, 3.3373e-01,
1675 2.9182e-01, 2.5318e-01, 2.1840e-01, 1.8739e-01,
1676 1.5998e-01, 1.3601e-01, 1.1548e-01, 9.7811e-02,
1677 8.2707e-02, 6.9900e-02, 5.9197e-02, 5.0157e-02,
1678 4.2535e-02, 3.6140e-02, 3.0782e-02, 2.6233e-02,
1679 2.2363e-02},
1680 {1.9635e-02, 2.3167e-02, 2.7343e-02, 3.2293e-02,
1681 3.8224e-02, 4.5335e-02, 5.3849e-02, 6.4039e-02,
1682 7.6210e-02, 9.0739e-02, 1.0805e-01, 1.2841e-01,
1683 1.5216e-01, 1.7960e-01, 2.1099e-01, 2.4671e-01,
1684 2.8647e-01, 3.2996e-01, 3.7660e-01, 4.2547e-01,
1685 4.7536e-01, 5.2473e-01, 5.7215e-01, 6.1632e-01,
1686 6.5616e-01, 6.9075e-01, 7.1939e-01, 7.4199e-01,
1687 7.5838e-01, 7.6848e-01, 7.7227e-01, 7.6848e-01,
1688 7.5838e-01, 7.4199e-01, 7.1939e-01, 6.9075e-01,
1689 6.5616e-01, 6.1632e-01, 5.7215e-01, 5.2473e-01,
1690 4.7536e-01, 4.2547e-01, 3.7660e-01, 3.2996e-01,
1691 2.8647e-01, 2.4671e-01, 2.1099e-01, 1.7960e-01,
1692 1.5216e-01, 1.2841e-01, 1.0805e-01, 9.0739e-02,
1693 7.6210e-02, 6.4039e-02, 5.3849e-02, 4.5335e-02,
1694 3.8224e-02, 3.2293e-02, 2.7343e-02, 2.3167e-02,
1695 1.9635e-02},
1696 {1.7224e-02, 2.0450e-02, 2.4286e-02, 2.8860e-02,
1697 3.4357e-02, 4.0979e-02, 4.8966e-02, 5.8612e-02,
1698 7.0253e-02, 8.4257e-02, 1.0102e-01, 1.2094e-01,
1699 1.4442e-01, 1.7196e-01, 2.0381e-01, 2.4013e-01,
1700 2.8093e-01, 3.2594e-01, 3.7450e-01, 4.2563e-01,
1701 4.7796e-01, 5.2991e-01, 5.7974e-01, 6.2599e-01,
1702 6.6750e-01, 7.0344e-01, 7.3329e-01, 7.5676e-01,
1703 7.7371e-01, 7.8410e-01, 7.8793e-01, 7.8410e-01,
1704 7.7371e-01, 7.5676e-01, 7.3329e-01, 7.0344e-01,
1705 6.6750e-01, 6.2599e-01, 5.7974e-01, 5.2991e-01,
1706 4.7796e-01, 4.2563e-01, 3.7450e-01, 3.2594e-01,
1707 2.8093e-01, 2.4013e-01, 2.0381e-01, 1.7196e-01,
1708 1.4442e-01, 1.2094e-01, 1.0102e-01, 8.4257e-02,
1709 7.0253e-02, 5.8612e-02, 4.8966e-02, 4.0979e-02,
1710 3.4357e-02, 2.8860e-02, 2.4286e-02, 2.0450e-02,
1711 1.7224e-02},
1712 {1.5096e-02, 1.8041e-02, 2.1566e-02, 2.5793e-02,
1713 3.0886e-02, 3.7044e-02, 4.4515e-02, 5.3604e-02,
1714 6.4668e-02, 7.8109e-02, 9.4364e-02, 1.1389e-01,
1715 1.3716e-01, 1.6461e-01, 1.9663e-01, 2.3350e-01,
1716 2.7527e-01, 3.2170e-01, 3.7214e-01, 4.2549e-01,
1717 4.8024e-01, 5.3460e-01, 5.8677e-01, 6.3512e-01,
1718 6.7838e-01, 7.1569e-01, 7.4655e-01, 7.7071e-01,
1719 7.8810e-01, 7.9871e-01, 8.0255e-01, 7.9871e-01,
1720 7.8810e-01, 7.7071e-01, 7.4655e-01, 7.1569e-01,
1721 6.7838e-01, 6.3512e-01, 5.8677e-01, 5.3460e-01,
1722 4.8024e-01, 4.2549e-01, 3.7214e-01, 3.2170e-01,
1723 2.7527e-01, 2.3350e-01, 1.9663e-01, 1.6461e-01,
1724 1.3716e-01, 1.1389e-01, 9.4364e-02, 7.8109e-02,
1725 6.4668e-02, 5.3604e-02, 4.4515e-02, 3.7044e-02,
1726 3.0886e-02, 2.5793e-02, 2.1566e-02, 1.8041e-02,
1727 1.5096e-02}};
1728
1729 // More sampling precision with linear interpolation
6d50f529 1730 fPRFlo = -1.5;
1731 fPRFhi = 1.5;
6a739e92 1732 Float_t pad[kPRFbin];
1733 Int_t sPRFbin = kPRFbin;
6d50f529 1734 Float_t sPRFwid = (fPRFhi - fPRFlo) / ((Float_t) sPRFbin);
6a739e92 1735 for (Int_t iPad = 0; iPad < sPRFbin; iPad++) {
6d50f529 1736 pad[iPad] = ((Float_t) iPad + 0.5) * sPRFwid + fPRFlo;
6a739e92 1737 }
6d50f529 1738 fPRFbin = 500;
1739 fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
1740 fPRFpad = ((Int_t) (1.0 / fPRFwid));
6a739e92 1741
6d50f529 1742 if (fPRFsmp) delete [] fPRFsmp;
053767a4 1743 fPRFsmp = new Float_t[kNlayer*fPRFbin];
6a739e92 1744
1745 Int_t ipos1;
1746 Int_t ipos2;
1747 Float_t diff;
1748
053767a4 1749 for (Int_t iLayer = 0; iLayer < kNlayer; iLayer++) {
6a739e92 1750
6d50f529 1751 for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
6a739e92 1752
6d50f529 1753 Float_t bin = (((Float_t) iBin) + 0.5) * fPRFwid + fPRFlo;
6a739e92 1754 ipos1 = ipos2 = 0;
1755 diff = 0;
1756 do {
1757 diff = bin - pad[ipos2++];
1758 } while ((diff > 0) && (ipos2 < kPRFbin));
1759 if (ipos2 == kPRFbin) {
053767a4 1760 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
6a739e92 1761 }
1762 else if (ipos2 == 1) {
053767a4 1763 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2-1];
6a739e92 1764 }
1765 else {
1766 ipos2--;
1767 if (ipos2 >= kPRFbin) ipos2 = kPRFbin - 1;
1768 ipos1 = ipos2 - 1;
053767a4 1769 fPRFsmp[iLayer*fPRFbin+iBin] = prf[iLayer][ipos2]
1770 + diff * (prf[iLayer][ipos2] - prf[iLayer][ipos1])
1771 / sPRFwid;
6a739e92 1772 }
1773
1774 }
1775 }
1776
1777}
1778
1779//_____________________________________________________________________________
1780Int_t AliTRDcalibDB::PadResponse(Double_t signal, Double_t dist
eb52b657 1781 , Int_t layer, Double_t *pad) const
6a739e92 1782{
1783 //
1784 // Applies the pad response
56178ff4 1785 // So far this is the fixed parametrization and should be replaced by
1786 // something dependent on calibration values
6a739e92 1787 //
1788
eb52b657 1789 Int_t iBin = ((Int_t) ((-dist - fPRFlo) / fPRFwid));
053767a4 1790 Int_t iOff = layer * fPRFbin;
6a739e92 1791
6d50f529 1792 Int_t iBin0 = iBin - fPRFpad + iOff;
6a739e92 1793 Int_t iBin1 = iBin + iOff;
6d50f529 1794 Int_t iBin2 = iBin + fPRFpad + iOff;
6a739e92 1795
1796 pad[0] = 0.0;
1797 pad[1] = 0.0;
1798 pad[2] = 0.0;
053767a4 1799 if ((iBin1 >= 0) && (iBin1 < (fPRFbin*kNlayer))) {
6a739e92 1800
1801 if (iBin0 >= 0) {
6d50f529 1802 pad[0] = signal * fPRFsmp[iBin0];
6a739e92 1803 }
6d50f529 1804 pad[1] = signal * fPRFsmp[iBin1];
053767a4 1805 if (iBin2 < (fPRFbin*kNlayer)) {
6d50f529 1806 pad[2] = signal * fPRFsmp[iBin2];
6a739e92 1807 }
1808
1809 return 1;
1810
1811 }
1812 else {
1813
1814 return 0;
1815
1816 }
ab0a4106 1817
3551db50 1818}
7a6352a6 1819
1820
a9e22145 1821AliTRDtrapConfig* AliTRDcalibDB::GetTrapConfig()
1822{
1823 // return an existing TRAPconfig or load it from the OCDB
1824 // in case of failure, a default TRAPconfig is created
1825
1826 if (fTrapConfig)
1827 return fTrapConfig;
1828 else {
1b1afdd3 1829 if ((fTrapConfigName.Length() <= 0) || (fTrapConfigVersion.Length() <= 0)) {
1830 // query the configuration to be used
1831 TString configName;
1832 this->GetGlobalConfiguration(configName);
1833 TString configVersion;
1834 this->GetGlobalConfigurationVersion(configVersion);
1835 }
a9e22145 1836
1b1afdd3 1837 // try to load the requested configuration
1838 this->LoadTrapConfig(fTrapConfigName, fTrapConfigVersion);
a9e22145 1839
1840 // if we still don't have a valid TRAPconfig, create a default one
1841 if (!fTrapConfig) {
1842 AliWarning("Falling back to default configuration");
1843 fTrapConfig = new AliTRDtrapConfig("default", "default TRAP configuration");
1844 AliTRDtrapConfigHandler cfgHandler(fTrapConfig);
1845 cfgHandler.Init();
1846 cfgHandler.LoadConfig();
1847 }
1848
1849 AliInfo(Form("using TRAPconfig \"%s\"", fTrapConfig->GetTitle()));
1850
1851 return fTrapConfig;
1852 }
1853}
1854
1855
1856AliTRDtrapConfig* AliTRDcalibDB::LoadTrapConfig(const TString &name, const TString &version)
1857{
1858 // try to load the specified configuration from the OCDB
1859 // if it fails, or it does not exist, return null
1860
1861 AliInfo(Form("looking for TRAPconfig \"%s.%s\"", name.Data(), version.Data()));
1862
1863 const AliTRDCalTrapConfig *caltrap = dynamic_cast<const AliTRDCalTrapConfig*> (GetCachedCDBObject(kIDTrapConfig));
1864
1865 if (caltrap) {
1866 TString configName(name);
1867 configName.Append(".");
1868 configName.Append(version);
1869 fTrapConfig = caltrap->Get(configName);
1870 }
1871 else {
1872 fTrapConfig = 0x0;
1873 AliError("No TRAPconfig entry found!");
1874 }
1875
1876 return fTrapConfig;
1877}