Remove the dollar-id-dollar in the responsible name which interfere with CDB_MD metad...
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibrationData.cxx
CommitLineData
c5bdf179 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#include "AliMUONCalibrationData.h"
19
20#include "AliCDBEntry.h"
21#include "AliCDBManager.h"
4bec0403 22#include "AliCodeTimer.h"
32f1b761 23#include "AliDCSValue.h"
c5bdf179 24#include "AliLog.h"
32f1b761 25#include "AliMpDCSNamer.h"
b37b9546 26#include "AliMpIntPair.h"
32f1b761 27#include "AliMUONGlobalCrateConfig.h"
28#include "AliMUONRegionalTriggerConfig.h"
0045b488 29#include "AliMUONRejectList.h"
e7d7fa47 30#include "AliMUONTriggerEfficiencyCells.h"
31#include "AliMUONTriggerLut.h"
32f1b761 32#include "AliMUONVCalibParam.h"
a0eca509 33#include "AliMUONVStore.h"
34#include "AliMUONVStore.h"
92c23b09 35
4bec0403 36#include <Riostream.h>
37#include <TClass.h>
38#include <TMap.h>
b37b9546 39#include <TMath.h>
c5bdf179 40
3d1463c8 41//-----------------------------------------------------------------------------
5398f946 42/// \class AliMUONCalibrationData
43///
48ed403b 44/// For the moment, this class stores pedestals, gains, hv (for tracker)
45/// and lut, masks and efficiencies (for trigger) that are fetched from the CDB.
e7d7fa47 46///
47/// This class is to be considered as a convenience class.
48/// Its aim is to ease retrieval of calibration data from the
49/// condition database.
50///
51/// It acts as a "facade" to a bunch of underlying
52/// containers/calibration classes.
53///
5398f946 54/// \author Laurent Aphecetche
3d1463c8 55//-----------------------------------------------------------------------------
e7d7fa47 56
b80faac0 57using std::cout;
58using std::endl;
5398f946 59/// \cond CLASSIMP
c5bdf179 60ClassImp(AliMUONCalibrationData)
5398f946 61/// \endcond
c5bdf179 62
9ee1d6ff 63AliMUONVStore* AliMUONCalibrationData::fgBypassPedestals(0x0);
64AliMUONVStore* AliMUONCalibrationData::fgBypassGains(0x0);
8f29b706 65
b37b9546 66namespace
67{
68 void MarkForDeletion(Int_t* indices, Int_t first, Int_t last)
69 {
70 for ( Int_t i = first; i <= last; ++i )
71 {
72 indices[i] = 1;
73 }
74 }
75}
76
c5bdf179 77//_____________________________________________________________________________
78AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber,
79 Bool_t deferredInitialization)
80: TObject(),
81fIsValid(kTRUE),
82fRunNumber(runNumber),
83fGains(0x0),
c3ce65fd 84fPedestals(0x0),
48ed403b 85fHV(0x0),
49e110ec 86fTriggerDCS(0x0),
e7d7fa47 87fLocalTriggerBoardMasks(0x0),
92c23b09 88fRegionalTriggerConfig(0x0),
89fGlobalTriggerCrateConfig(0x0),
e7d7fa47 90fTriggerLut(0x0),
c1bbaf66 91fTriggerEfficiency(0x0),
d067ba7c 92fCapacitances(0x0),
2b8a1212 93fNeighbours(0x0),
0045b488 94fOccupancyMap(0x0),
6c870207 95fRejectList(0x0),
96fConfig(0x0)
c5bdf179 97{
5398f946 98/// Default ctor.
99
c3ce65fd 100 // If deferredInitialization is false, we read *all* calibrations
101 // at once.
102 // So when using this class to access only one kind of calibrations (e.g.
103 // only pedestals), you should put deferredInitialization to kTRUE, which
104 // will instruct this object to fetch the data only when neeeded.
5398f946 105
c5bdf179 106 if ( deferredInitialization == kFALSE )
107 {
5562688f 108 Gains();
109 Pedestals();
7eafe398 110 OccupancyMap();
0045b488 111 RejectList();
5562688f 112 HV();
49e110ec 113 TriggerDCS();
5562688f 114 LocalTriggerBoardMasks(0);
92c23b09 115 RegionalTriggerConfig();
116 GlobalTriggerCrateConfig();
5562688f 117 TriggerLut();
118 TriggerEfficiency();
119 Capacitances();
120 Neighbours();
6c870207 121 Config();
c5bdf179 122 }
123}
124
e7d7fa47 125//_____________________________________________________________________________
c5bdf179 126AliMUONCalibrationData::~AliMUONCalibrationData()
127{
f436adf2 128 /// Destructor. Note that we're the owner of our pointers if the OCDB cache
129 /// is not set. Otherwise the cache is supposed to take care of them...
130 if (!(AliCDBManager::Instance()->GetCacheFlag())) Reset();
c3ce65fd 131}
c3ce65fd 132
133//_____________________________________________________________________________
5562688f 134AliMUONVStore*
135AliMUONCalibrationData::Capacitances() const
c3ce65fd 136{
5562688f 137 /// Create (if needed) and return the internal store for capacitances.
138
139 if (!fCapacitances)
c3ce65fd 140 {
5562688f 141 fCapacitances = CreateCapacitances(fRunNumber);
c3ce65fd 142 }
5562688f 143 return fCapacitances;
c5bdf179 144}
145
146//_____________________________________________________________________________
5562688f 147AliMUONVStore*
143cd71a 148AliMUONCalibrationData::CreateCapacitances(Int_t runNumber, Int_t* startOfValidity)
c5bdf179 149{
5562688f 150 /// Create capa store from OCDB for a given run
151
143cd71a 152 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances",startOfValidity));
5562688f 153}
5398f946 154
5562688f 155//_____________________________________________________________________________
156AliMUONVStore*
143cd71a 157AliMUONCalibrationData::CreateGains(Int_t runNumber, Int_t* startOfValidity)
5562688f 158{
159 /// Create a new gain store from the OCDB for a given run
143cd71a 160 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains",startOfValidity));
c5bdf179 161}
162
163//_____________________________________________________________________________
92c23b09 164AliMUONGlobalCrateConfig*
143cd71a 165AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity)
c5bdf179 166{
92c23b09 167 /// Create the internal store for GlobalTriggerCrateConfig from OCDB
48ed403b 168
143cd71a 169 return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig",startOfValidity));
48ed403b 170}
171
92c23b09 172
32f1b761 173//______________________________________________________________________________
b37b9546 174Bool_t AliMUONCalibrationData::CheckHVGroup(TObjArray& values, Int_t first, Int_t last, Double_t& value, Int_t& slope, TString* msg)
32f1b761 175{
b37b9546 176 // Get the HV of the values between first and last indices
177 // return the HV slope (in Volt per second) and a message
178 // Return kFALSE if we must discard the group
179 //
32f1b761 180
b37b9546 181 if (msg) *msg="";
32f1b761 182
b37b9546 183 if ( last < first ) return kFALSE;
184 if ( last - first < 2 ) return kFALSE;
32f1b761 185
b37b9546 186 Double_t a(0.0);
187 Double_t b(0.0);
188
189 Float_t HVSAME(1); // 1 volts
190
191 AliDCSValue* vfirst = static_cast<AliDCSValue*>(values.UncheckedAt(first));
192 AliDCSValue* vlast = static_cast<AliDCSValue*>(values.UncheckedAt(last));
193
194 Int_t deltaHV = TMath::Nint(TMath::Abs(vfirst->GetFloat()-vlast->GetFloat()));
32f1b761 195
b37b9546 196 if ( deltaHV < HVSAME ) return kFALSE;
197
198 for ( Int_t i = first; i <= last; ++i )
199 {
200 AliDCSValue* v = static_cast<AliDCSValue*>(values.UncheckedAt(i));
201
202 Double_t y = v->GetFloat() - vfirst->GetFloat();
203 Double_t x = v->GetTimeStamp() - vfirst->GetTimeStamp();
32f1b761 204
b37b9546 205 a += x*y;
206 b += x*x;
207 }
32f1b761 208
b37b9546 209 value = a/b;
210 slope = value > 0 ? 1 : -1;
211 value = TMath::Abs(value);
32f1b761 212
b37b9546 213 UInt_t deltaTime = vlast->GetTimeStamp() - vfirst->GetTimeStamp();
32f1b761 214
b37b9546 215 if (msg)
32f1b761 216 {
b37b9546 217 if (slope>0) (*msg) = Form("RU%d[%d:%d](%d)",TMath::Nint(value),first,last,deltaTime);
218 if (slope<0) (*msg) = Form("RD%d[%d:%d](%d)",TMath::Nint(value),first,last,deltaTime);
32f1b761 219
b37b9546 220 if ( TMath::Nint(value) == 0 )
32f1b761 221 {
b37b9546 222 // this is to protect for the few cases
223 // (see e.g. MchHvLvLeft/Chamber00Left/Quad2Sect0.actual.vMon in run 134497)
224 // where we can have *lots* of values (2483 in this example) but that
225 // are more or less constant...
226 //
227 // or simply to remove small ramps
228 //
229 slope = 0;
230 value = (vfirst->GetFloat()+vlast->GetFloat())/2.0;
231 *msg = Form("FLUCT%d[%d:%d]",TMath::Nint(value),first,last);
32f1b761 232 }
233 }
234
b37b9546 235 return kTRUE;
236}
237
238//______________________________________________________________________________
239Bool_t AliMUONCalibrationData::PatchHVValues(TObjArray& values,
240 TString* msg)
241{
242 /// We do here a little bit of massaging of the HV values, if needed.
243 ///
244 /// The main point is to "gather" values that are within a given small amount
245 /// of time (typically 60 seconds) and infer a slope from those values
246 /// slope > 0 means it is a ramp-up, slope < 0 that's a ramp-down
247 ///
248 /// This is to avoid both the "ramp-down-before-end-of-run" and the
249 /// "ramp-up-after-start-of-run" syndroms...
250 ///
251 /// Return kFALSE is the kind of HV (trouble) case we have here
252 /// has not been identified...
253 ///
254
255 UInt_t DELTATIME(60); // in seconds
256 Int_t IENDRU(60); // in seconds
257
258 // Start by finding groups of values which are not separated (each) by more than
259 // deltaTime
260
261 Bool_t gather(kFALSE);
262 Int_t ifirst(0);
263 Int_t ilast(0);
264 TObjArray groups;
265 groups.SetOwner(kTRUE);
266
267 for ( Int_t i = values.GetLast(); i > 0; --i )
32f1b761 268 {
b37b9546 269 AliDCSValue* vi = static_cast<AliDCSValue*>(values.UncheckedAt(i));
270 AliDCSValue* vj = static_cast<AliDCSValue*>(values.UncheckedAt(i-1));
271
272 if ( vi->GetTimeStamp() - vj->GetTimeStamp() < DELTATIME )
32f1b761 273 {
b37b9546 274 if ( !gather )
275 {
276 gather = kTRUE;
277 ifirst = i;
278 }
279 ilast=i;
32f1b761 280 }
b37b9546 281 else
32f1b761 282 {
b37b9546 283 if ( gather )
284 {
285 ilast=i;
286
287 groups.Add(new AliMpIntPair(ilast,ifirst));
288 }
289 gather = kFALSE;
32f1b761 290 }
32f1b761 291 }
292
b37b9546 293 if (gather)
32f1b761 294 {
b37b9546 295 groups.Add(new AliMpIntPair(0,ifirst));
32f1b761 296 }
b37b9546 297
298 TIter nextGroup(&groups,kIterBackward);
299 AliMpIntPair* p;
300 TString internalMsg;
301 Int_t ngroups(0);
302
303 Int_t nRU(0);
304 Int_t nRD(0);
305 Int_t nStartRU(0);
306 Int_t nEndAndShortRU(0);
307 Int_t nEndRD(0);
308 Int_t nTripRD(0);
309 Int_t nFluct(0);
32f1b761 310
b37b9546 311 while ( ( p = static_cast<AliMpIntPair*>(nextGroup()) ) )
32f1b761 312 {
b37b9546 313 Double_t value;
314 Int_t slope;
32f1b761 315
b37b9546 316 TString groupMsg;
317
318 AliDebugClass(1,Form("group %d:%d",p->GetFirst(),p->GetSecond()));
319
320 Bool_t ok = CheckHVGroup(values,p->GetFirst(),p->GetSecond(),value,slope,&groupMsg);
321
322 if (!ok) continue;
323
324 ++ngroups;
325
326 if ( slope > 0 )
327 {
328 if ( p->GetFirst() == 0 )
329 {
330 // start with a ramp-up
331 ++nStartRU;
332 }
333 else if ( p->GetSecond() == values.GetLast() && TMath::Nint(value) < IENDRU )
334 {
335 ++nEndAndShortRU;
336 }
337 else
338 {
339 // ramp-up in the middle of nowhere...
340 ++nRU;
341 }
342 }
343 else if ( slope < 0 )
32f1b761 344 {
b37b9546 345 if ( p->GetSecond() == values.GetLast() )
346 {
347 // end with a ramp-down
348 ++nEndRD;
349 }
350 else
351 {
352 // ramp-down in the middle of nowhere
353 ++nRD;
354 }
355
356 AliDCSValue* d = static_cast<AliDCSValue*>(values.At(p->GetSecond()));
357
358 if ( d->GetFloat() < AliMpDCSNamer::TrackerHVOFF() )
359 {
360 ++nTripRD;
361 }
32f1b761 362 }
b37b9546 363 else
32f1b761 364 {
b37b9546 365 ++nFluct;
32f1b761 366 }
b37b9546 367
368 internalMsg += groupMsg;
369 internalMsg += " ";
32f1b761 370 }
371
b37b9546 372 /*
373
374 Once we have "decoded" the groups we try to find out which of
375 the following cases we're facing :
376
377 case A = -------- = OK(1)
378
379 case B = ----
380 \
381 \ = OK, once we have removed the ramp-down (2)
382
383 case C = -----
384 /
385 / = OK, once we have removed the ramp-up (3)
386
387 case D = -----
388 / \
389 / \ = OK, once we have removed the ramp-down (2) and the ramp-up (3)
390
391 case E = ----
392 \
393 \____ = TRIP = BAD (here the ramp-down slope should be bigger than in case C)
394
395 case F = ----
396 \ ----- = BAD (trip + ramp-up at end of run)
397 \____/
398
399 case G = fluctuations (within a range defined in CheckHVGroup...)
400
401 case H =
402 /
403 / = ramp-up right at the end-of-run = OK (4)
404 ------
405
406 (1) OK means the group is identified correctly, still the value can be below ready...
407 (2) ramp-down values will be removed if the ramp is indeed the last values in the serie
408 i.e. it's really an end-of-run problem (otherwise it's not case B)
409 (3) ramp-up values will be removed if the ramp is indeed the first values in the serie
410 i.e. it's really a start-of-run problem (otherwise it's not case C)
411 (4) OK if short enough...
412
413 Any other case is unknown and we'll :
414 a) return kFALSE
415 b) assume the channel is OFF.
416
417
418 */
419
420 AliDebugClass(1,Form("msg=%s ngroupds=%d",internalMsg.Data(),ngroups));
421 AliDebugClass(1,Form("nRU %d nRD %d nStartRU %d nEndRD %d nTripRD %d nFluct %d",
422 nRU,nRD,nStartRU,nEndRD,nTripRD,nFluct));
423
424 TString hvCase("OTHER");
425 int dummy(0),a(-1),b(-1);
8763322f 426 char r[81];
b37b9546 427 Int_t nvalues = values.GetSize();
428 Int_t* indices = new Int_t[nvalues];
429 memset(indices,0,nvalues*sizeof(Int_t));
430
431 AliDCSValue* vfirst = static_cast<AliDCSValue*>(values.UncheckedAt(0));
432 AliDCSValue* vlast = static_cast<AliDCSValue*>(values.UncheckedAt(values.GetLast()));
433
434 UInt_t meanTimeStamp = ( vfirst->GetTimeStamp() + vlast->GetTimeStamp() ) / 2;
435
436 if ( ngroups == 0 )
32f1b761 437 {
b37b9546 438 hvCase = "A";
439 }
440 else if ( nTripRD > 0 )
441 {
442 if ( nRU > 0 && nRD > 0 )
32f1b761 443 {
b37b9546 444 hvCase = "F";
32f1b761 445 }
446 else
447 {
b37b9546 448 hvCase = "E";
32f1b761 449 }
b37b9546 450 internalMsg += "TRIP ";
451 MarkForDeletion(indices,0,values.GetLast());
452 values.Add(new AliDCSValue(static_cast<Float_t>(0),meanTimeStamp));
453 }
454 else if ( nStartRU > 0 && nRU == 0 && nRD == 0 && nEndRD == 0 )
455 {
456 hvCase = "C";
457 sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
458 MarkForDeletion(indices,a,b);
459 }
460 else if ( nStartRU > 0 && nEndRD > 0 && nRD == 0 && nRU == 0 )
461 {
462 hvCase = "D";
463 sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
464 MarkForDeletion(indices,a,b-1);
465 Int_t i = internalMsg.Index("RD",strlen("RD"),0,TString::kExact);
466 sscanf(internalMsg(i,internalMsg.Length()-i).Data(),
467 "RD%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
468 MarkForDeletion(indices,a+1,b);
469 }
470 else if ( nEndRD > 0 && nStartRU == 0 && nRU == 0 && nRD == 0 )
471 {
472 hvCase = "B";
473 Int_t i = internalMsg.Index("RD",strlen("RD"),0,TString::kExact);
474 sscanf(internalMsg(i,internalMsg.Length()-i).Data(),
475 "RD%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
476 MarkForDeletion(indices,a,b);
477 }
478 else if ( nFluct > 0 )
479 {
480 hvCase = "G";
481 TObjArray* af = internalMsg.Tokenize(" ");
482 TIter next(af);
483 TObjString* str;
484 while ( ( str = static_cast<TObjString*>(next()) ) )
485 {
486 TString s(str->String());
487 if ( s.BeginsWith("FLUCT") )
488 {
489 sscanf(s.Data(),"FLUCT%d[%d:%d]",&dummy,&a,&b);
490 MarkForDeletion(indices,a,b);
491 }
492 }
493 delete af;
494 }
495 else if ( nEndAndShortRU > 0 && nStartRU == 0 && nRU == 0 && nRD == 0 && nEndRD == 0 )
496 {
497 hvCase = "H";
498 sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
499 MarkForDeletion(indices,a,b);
500 }
501 else
502 {
503 // last chance...
504 // here we know it's not a trip, so let's assume everything is OK
505 // if first and last value are in the same ballpark
506
507 const Double_t HVFLUCT(20); // volts
508
509 if ( TMath::Abs(vfirst->GetFloat() - vlast->GetFloat()) < HVFLUCT )
510 {
511 hvCase = "Z";
512 }
513 MarkForDeletion(indices,1,nvalues-1);
32f1b761 514 }
515
b37b9546 516 for ( Int_t i = 0; i < nvalues; ++i )
32f1b761 517 {
b37b9546 518 if ( indices[i] )
519 {
520 values.RemoveAt(i);
521 }
522 }
32f1b761 523
b37b9546 524 values.Compress();
525
526 delete[] indices;
527
528 if ( !values.GetEntries() )
529 {
530 AliErrorClass(Form("No value left after patch... Check that !!! initial # of values=%d msg=%s",
531 nvalues,internalMsg.Data()));
532 hvCase = "OTHER";
533 }
534
535 // take the max of the remaining values
536 TIter nextA(&values);
537 AliDCSValue* val;
538 Float_t maxval(-9999);
539
540 while ( ( val = static_cast<AliDCSValue*>(nextA()) ) )
541 {
542 if ( val->GetFloat() > maxval )
543 {
544 maxval = val->GetFloat();
545 }
546 }
547
548 values.Clear();
549
550 values.Add(new AliDCSValue(maxval,meanTimeStamp));
551
552 // once the case is inferred, add a "CASE:%10d",hvCase.Data()
553 // to the msg
554 // so we can them sum up for all channels and get a summary per run...
555
556 internalMsg += Form("CASE:%s",hvCase.Data());
557
558 if (msg) *msg = internalMsg.Data();
559
560 return hvCase=="OTHER" ? kFALSE : kTRUE;
32f1b761 561}
92c23b09 562
48ed403b 563//_____________________________________________________________________________
5562688f 564TMap*
b37b9546 565AliMUONCalibrationData::CreateHV(Int_t runNumber,
566 Int_t* startOfValidity,
567 Bool_t patched,
568 TList* messages)
c1bbaf66 569{
5562688f 570 /// Create a new HV map from the OCDB for a given run
32f1b761 571 TMap* hvMap = dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
b37b9546 572
8763322f 573 if (!hvMap) return 0x0;
574
32f1b761 575 if (patched)
576 {
577 TIter next(hvMap);
578 TObjString* hvChannelName;
579
580 while ( ( hvChannelName = static_cast<TObjString*>(next()) ) )
581 {
582 TString name(hvChannelName->String());
583
584 if ( name.Contains("sw") ) continue; // skip switches
585
586 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(name.Data()));
587 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
588 if (!values)
589 {
590 AliErrorClass(Form("Could not get values for alias %s",name.Data()));
591 }
592 else
593 {
b37b9546 594 TString msg;
595
596 AliDebugClass(1,Form("channel %s",name.Data()));
597 Bool_t ok = PatchHVValues(*values,&msg);
598
599 if ( messages )
600 {
601 messages->Add(new TObjString(Form("%s:%s",hvChannelName->String().Data(),msg.Data())));
602 }
32f1b761 603
b37b9546 604 if (!ok)
32f1b761 605 {
b37b9546 606 AliErrorClass(Form("PatchHVValue was not successfull ! This is serious ! "
607 "You'll have to check the logic for channel %s in run %09d",
608 name.Data(),runNumber));
32f1b761 609 }
610 }
611 }
612
613 }
b37b9546 614
615 if ( messages )
616 {
617 Int_t a(0),b(0),c(0),d(0),e(0),f(0),g(0),h(0),u(0),z(0);
618 TIter next(messages);
619 TObjString* msg;
6350d0c0 620 char hvCase('u');
b37b9546 621
622 while ( ( msg = static_cast<TObjString*>(next()) ) )
623 {
624 Int_t i = msg->String().Index("CASE",strlen("CASE"),0,TString::kExact);
625
626 if ( i >= 0 )
627 {
8763322f 628 sscanf(msg->String()(i,msg->String().Length()-i).Data(),"CASE:%10c",&hvCase);
b37b9546 629 }
630
631 switch (hvCase)
632 {
633 case 'A': ++a; break;
634 case 'B': ++b; break;
635 case 'C': ++c; break;
636 case 'D': ++d; break;
637 case 'E': ++e; break;
638 case 'F': ++f; break;
639 case 'G': ++g; break;
640 case 'H': ++h; break;
641 case 'Z': ++z; break;
642 default: ++u; break;
643 }
644 }
645
646 messages->Add(new TObjString(Form("SUMMARY : # of cases A(%3d) B(%3d) C(%3d) D(%3d) E(%3d) F(%3d) G(%3d) H(%3d) Z(%3d) OTHER(%3d)",
647 a,b,c,d,e,f,g,h,z,u)));
648 }
649
32f1b761 650 return hvMap;
c1bbaf66 651}
652
653//_____________________________________________________________________________
49e110ec 654TMap*
655AliMUONCalibrationData::CreateTriggerDCS(Int_t runNumber, Int_t* startOfValidity)
656{
657 /// Create a new Trigger HV and curent map from the OCDB for a given run
658 return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/TriggerDCS",startOfValidity));
659}
660
661//_____________________________________________________________________________
a0eca509 662AliMUONVStore*
143cd71a 663AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
d067ba7c 664{
5562688f 665 /// Get the internal store for LocalTriggerBoardMasks from OCDB
666
143cd71a 667 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
d067ba7c 668}
669
670//_____________________________________________________________________________
a0eca509 671AliMUONVStore*
143cd71a 672AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
48ed403b 673{
5562688f 674 /// Create a neighbour store from the OCDB for a given run
143cd71a 675 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
c5bdf179 676}
677
678//_____________________________________________________________________________
5562688f 679TObject*
143cd71a 680AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
d067ba7c 681{
5562688f 682 /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
683 /// and return the corresponding TObject.
d067ba7c 684
b37b9546 685 AliCodeTimerAutoClass(Form("%09d : %s",runNumber,path),0);
4bec0403 686
5562688f 687 AliCDBManager* man = AliCDBManager::Instance();
688
465302eb 689 AliCDBEntry* entry = man->Get(path,runNumber);
5562688f 690
5562688f 691 if (entry)
d067ba7c 692 {
143cd71a 693 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
694
4bec0403 695 TObject* object = entry->GetObject();
82586209 696 if (!(man->GetCacheFlag()))
697 {
698 entry->SetOwner(kFALSE);
699 delete entry;
700 }
cdffeaea 701// else
702// {
703// entry->SetOwner(kTRUE); //FIXME : this should be done but is causing problems with RecoParams at the end of the reco : investigate why...
704// }
4bec0403 705 return object;
706 }
143cd71a 707 else
708 {
709 if ( startOfValidity ) *startOfValidity = AliCDBRunRange::Infinity();
710 }
711
0045b488 712 {
713
b37b9546 714 AliCodeTimerAutoClass(Form("Failed to get %s for run %09d",path,runNumber),1);
0045b488 715
716 }
717
5562688f 718 return 0x0;
d067ba7c 719}
720
721//_____________________________________________________________________________
a0eca509 722AliMUONVStore*
7eafe398 723AliMUONCalibrationData::CreateOccupancyMap(Int_t runNumber, Int_t* startOfValidity)
2b8a1212 724{
7eafe398 725 /// Create a new occupancy map store from the OCDB for a given run
726 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/OccupancyMap",startOfValidity));
2b8a1212 727}
728
729//_____________________________________________________________________________
0045b488 730AliMUONRejectList*
731AliMUONCalibrationData::CreateRejectList(Int_t runNumber, Int_t* startOfValidity)
732{
733 /// Create a new rejectlist store from the OCDB for a given run
734 return dynamic_cast<AliMUONRejectList*>(CreateObject(runNumber,"MUON/Calib/RejectList",startOfValidity));
735}
736
737//_____________________________________________________________________________
2b8a1212 738AliMUONVStore*
143cd71a 739AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
c1bbaf66 740{
5562688f 741 /// Create a new pedestal store from the OCDB for a given run
143cd71a 742 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
c1bbaf66 743}
744
6c870207 745//_____________________________________________________________________________
746AliMUONVStore*
747AliMUONCalibrationData::CreateConfig(Int_t runNumber, Int_t* startOfValidity)
748{
749 /// Create a new config store from the OCDB for a given run
750 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Config",startOfValidity));
751}
752
92c23b09 753
c1bbaf66 754//_____________________________________________________________________________
92c23b09 755AliMUONRegionalTriggerConfig*
143cd71a 756AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
5562688f 757{
92c23b09 758 /// Create the internal store for RegionalTriggerConfig from OCDB
5562688f 759
143cd71a 760 return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
5562688f 761}
762
763//_____________________________________________________________________________
764AliMUONTriggerEfficiencyCells*
143cd71a 765AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
c5bdf179 766{
5562688f 767 /// Create trigger efficiency object from OCBD
768
143cd71a 769 return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
5562688f 770}
5398f946 771
5562688f 772//_____________________________________________________________________________
773AliMUONTriggerLut*
143cd71a 774AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
5562688f 775{
776 /// Create trigger LUT from OCDB
777
143cd71a 778 return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
5562688f 779}
780
781//_____________________________________________________________________________
782AliMUONVStore*
783AliMUONCalibrationData::Gains() const
784{
785 /// Create (if needed) and return the internal store for gains.
9ee1d6ff 786 if (fgBypassGains) return fgBypassGains;
8f29b706 787
c5bdf179 788 if (!fGains)
789 {
5562688f 790 fGains = CreateGains(fRunNumber);
c5bdf179 791 }
792 return fGains;
793}
b37b9546 794
c5bdf179 795//_____________________________________________________________________________
5562688f 796AliMUONVCalibParam*
797AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
e7d7fa47 798{
5562688f 799/// Return the gains for a given (detElemId, manuId) pair
800/// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
801/// error (meaning that we should get gains for all channels).
5398f946 802
5562688f 803 AliMUONVStore* gains = Gains();
804 if (!gains)
805 {
806 return 0x0;
807 }
808
809 return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
e7d7fa47 810}
811
812//_____________________________________________________________________________
92c23b09 813AliMUONGlobalCrateConfig*
814AliMUONCalibrationData::GlobalTriggerCrateConfig() const
e7d7fa47 815{
92c23b09 816 /// Return the config for the global trigger board.
5562688f 817
92c23b09 818 if (!fGlobalTriggerCrateConfig)
e7d7fa47 819 {
92c23b09 820 fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
e7d7fa47 821 }
92c23b09 822 return fGlobalTriggerCrateConfig;
e7d7fa47 823}
824
92c23b09 825
e7d7fa47 826//_____________________________________________________________________________
5562688f 827TMap*
32f1b761 828AliMUONCalibrationData::HV(Bool_t patched) const
e7d7fa47 829{
5562688f 830 /// Return the calibration for a given (detElemId, manuId) pair
48ed403b 831
5562688f 832 if (!fHV)
e7d7fa47 833 {
32f1b761 834 fHV = CreateHV(fRunNumber,0,patched);
e7d7fa47 835 }
5562688f 836 return fHV;
e7d7fa47 837}
838
839//_____________________________________________________________________________
49e110ec 840TMap*
841AliMUONCalibrationData::TriggerDCS() const
842{
843 /// Return the calibration for a given (detElemId, manuId) pair
844
845 if (!fTriggerDCS)
846 {
847 fTriggerDCS = CreateTriggerDCS(fRunNumber);
848 }
849 return fTriggerDCS;
850}
851
852//_____________________________________________________________________________
a0eca509 853AliMUONVStore*
5562688f 854AliMUONCalibrationData::Neighbours() const
e7d7fa47 855{
5562688f 856 /// Create (if needed) and return the internal store for neighbours.
857 if (!fNeighbours)
858 {
859 fNeighbours = CreateNeighbours(fRunNumber);
860 }
861 return fNeighbours;
862}
863
864//_____________________________________________________________________________
865AliMUONVCalibParam*
866AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
867{
868/// Return the masks for a given trigger local board.
5398f946 869
e7d7fa47 870 if (!fLocalTriggerBoardMasks)
871 {
5562688f 872 fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
873 }
874
875 if ( fLocalTriggerBoardMasks )
876 {
877 AliMUONVCalibParam* ltbm =
878 static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
879 if (!ltbm)
e7d7fa47 880 {
5562688f 881 AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
e7d7fa47 882 }
5562688f 883 return ltbm;
e7d7fa47 884 }
5562688f 885 return 0x0;
e7d7fa47 886}
887
888//_____________________________________________________________________________
a0eca509 889AliMUONVStore*
7eafe398 890AliMUONCalibrationData::OccupancyMap() const
2b8a1212 891{
7eafe398 892 /// Get occupancy map
893 if (!fOccupancyMap)
2b8a1212 894 {
7eafe398 895 fOccupancyMap = CreateOccupancyMap(fRunNumber);
2b8a1212 896 }
7eafe398 897 return fOccupancyMap;
2b8a1212 898}
899
900//_____________________________________________________________________________
0045b488 901AliMUONRejectList*
902AliMUONCalibrationData::RejectList() const
903{
904 /// Get reject list
905 if (!fRejectList)
906 {
907 fRejectList = CreateRejectList(fRunNumber);
908 }
909 return fRejectList;
910}
911
912//_____________________________________________________________________________
8f29b706 913void
914AliMUONCalibrationData::BypassStores(AliMUONVStore* ped, AliMUONVStore* gain)
915{
916 /// Force the use of those pedestals and gains
9ee1d6ff 917 fgBypassPedestals = ped;
918 fgBypassGains = gain;
8f29b706 919
920}
921
922//_____________________________________________________________________________
2b8a1212 923AliMUONVStore*
5562688f 924AliMUONCalibrationData::Pedestals() const
c5bdf179 925{
5562688f 926 /// Return pedestals
8f29b706 927
9ee1d6ff 928 if (fgBypassPedestals) return fgBypassPedestals;
8f29b706 929
c5bdf179 930 if (!fPedestals)
931 {
5562688f 932 fPedestals = CreatePedestals(fRunNumber);
c5bdf179 933 }
934 return fPedestals;
935}
936
937//_____________________________________________________________________________
6c870207 938AliMUONVStore*
939AliMUONCalibrationData::Config() const
940{
941 /// Return config
942
943 if (!fConfig)
944 {
945 fConfig = CreateConfig(fRunNumber);
946 }
947 return fConfig;
948}
949
950//_____________________________________________________________________________
5562688f 951AliMUONVCalibParam*
952AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
953{
954 /// Return the pedestals for a given (detElemId, manuId) pair.
955 /// A return value of 0x0 is considered an error, meaning we should get
956 /// pedestals for all channels.
957
958 AliMUONVStore* pedestals = Pedestals();
959 if (!pedestals)
960 {
961 return 0x0;
962 }
963
964 return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
965}
966
967//_____________________________________________________________________________
c5bdf179 968void
969AliMUONCalibrationData::Print(Option_t*) const
970{
5562688f 971 /// A very basic dump of our guts.
5398f946 972
c5bdf179 973 cout << "RunNumber " << RunNumber()
e7d7fa47 974 << " fGains=" << fGains
975 << " fPedestals=" << fPedestals
6c870207 976 << " fConfig=" << fConfig
48ed403b 977 << " fHV=" << fHV
49e110ec 978 << " fTriggerDCS=" << fTriggerDCS
e7d7fa47 979 << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
92c23b09 980 << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
981 << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
e7d7fa47 982 << " fTriggerLut=" << fTriggerLut
c5bdf179 983 << endl;
984}
985
92c23b09 986
48ed403b 987//_____________________________________________________________________________
92c23b09 988AliMUONRegionalTriggerConfig*
989AliMUONCalibrationData::RegionalTriggerConfig() const
e7d7fa47 990{
92c23b09 991 /// Return the config for the regional trigger board.
48ed403b 992
92c23b09 993 if (!fRegionalTriggerConfig)
e7d7fa47 994 {
92c23b09 995 fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
e7d7fa47 996 }
92c23b09 997 return fRegionalTriggerConfig;
e7d7fa47 998}
999
92c23b09 1000
e7d7fa47 1001//_____________________________________________________________________________
1002AliMUONTriggerEfficiencyCells*
1003AliMUONCalibrationData::TriggerEfficiency() const
1004{
5398f946 1005/// Return the trigger efficiency.
1006
e7d7fa47 1007 if (!fTriggerEfficiency)
1008 {
5562688f 1009 fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
e7d7fa47 1010 }
1011 return fTriggerEfficiency;
1012}
1013
5562688f 1014
e7d7fa47 1015//_____________________________________________________________________________
1016AliMUONTriggerLut*
1017AliMUONCalibrationData::TriggerLut() const
1018{
5398f946 1019/// Return the trigger look up table.
1020
e7d7fa47 1021 if (!fTriggerLut)
1022 {
5562688f 1023 fTriggerLut = CreateTriggerLut(fRunNumber);
e7d7fa47 1024 }
1025 return fTriggerLut;
1026}
1027
c1bbaf66 1028//_____________________________________________________________________________
1029void
1030AliMUONCalibrationData::Reset()
1031{
1032/// Reset all data
1033
82586209 1034 AliCodeTimerAuto("",0);
1035
6c870207 1036 delete fConfig;
1037 fConfig = 0x0;
c1bbaf66 1038 delete fPedestals;
1039 fPedestals = 0x0;
1040 delete fGains;
1041 fGains = 0x0;
1042 delete fHV;
1043 fHV = 0x0;
49e110ec 1044 delete fTriggerDCS;
1045 fTriggerDCS = 0x0;
c1bbaf66 1046 delete fLocalTriggerBoardMasks;
1047 fLocalTriggerBoardMasks = 0x0;
92c23b09 1048 delete fRegionalTriggerConfig;
1049 fRegionalTriggerConfig = 0x0;
1050 delete fGlobalTriggerCrateConfig;
1051 fGlobalTriggerCrateConfig = 0x0;
1052
c1bbaf66 1053 delete fTriggerLut;
1054 fTriggerLut = 0x0;
1055 delete fTriggerEfficiency;
1056 fTriggerEfficiency = 0x0;
1057 delete fCapacitances;
1058 fCapacitances = 0x0;
d067ba7c 1059 delete fNeighbours;
1060 fNeighbours = 0x0;
c1bbaf66 1061}
1062
630711ed 1063//_____________________________________________________________________________
1064void
1065AliMUONCalibrationData::Check(Int_t runNumber)
1066{
1067 /// Self-check to see if we can read all data for a given run
1068 /// from the current OCDB...
1069
1070 if ( ! CreateCapacitances(runNumber) )
1071 {
1072 AliErrorClass("Could not read capacitances");
1073 }
1074 else
1075 {
1076 AliInfoClass("Capacitances read OK");
1077 }
1078
1079 if ( ! CreateGains(runNumber) )
1080 {
1081 AliErrorClass("Could not read gains");
1082 }
1083 else
1084 {
1085 AliInfoClass("Gains read OK");
1086 }
1087
1088 if ( ! CreateGlobalTriggerCrateConfig(runNumber) )
1089 {
1090 AliErrorClass("Could not read Trigger Crate Config");
1091 }
1092 else
1093 {
1094 AliInfoClass("TriggerBoardMasks read OK");
1095 }
1096
1097 if ( ! CreateHV(runNumber) )
1098 {
1099 AliErrorClass("Could not read HV");
1100 }
1101 else
1102 {
1103 AliInfoClass("HV read OK");
49e110ec 1104 }
1105
1106 if ( ! CreateTriggerDCS(runNumber) )
1107 {
1108 AliErrorClass("Could not read Trigger HV and Currents");
1109 }
1110 else
1111 {
1112 AliInfoClass("Trigger HV and Currents read OK");
630711ed 1113 }
1114
1115 if ( ! CreateNeighbours(runNumber) )
1116 {
1117 AliErrorClass("Could not read Neighbours");
1118 }
1119 else
1120 {
1121 AliInfoClass("Neighbours read OK");
1122 }
1123
1124 if ( ! CreateLocalTriggerBoardMasks(runNumber) )
1125 {
1126 AliErrorClass("Could not read LocalTriggerBoardMasks");
1127 }
1128 else
1129 {
1130 AliInfoClass("LocalTriggerBoardMasks read OK");
1131 }
1132
1133 if ( ! CreatePedestals(runNumber) )
1134 {
1135 AliErrorClass("Could not read pedestals");
1136 }
1137 else
1138 {
1139 AliInfoClass("Pedestals read OK");
1140 }
6c870207 1141
1142 if ( ! CreateConfig(runNumber) )
1143 {
1144 AliErrorClass("Could not read config");
1145 }
1146 else
1147 {
1148 AliInfoClass("Config read OK");
1149 }
630711ed 1150
1151 if ( ! CreateRegionalTriggerConfig(runNumber) )
1152 {
1153 AliErrorClass("Could not read RegionalTriggerConfig");
1154 }
1155 else
1156 {
1157 AliInfoClass("RegionalTriggerBoardMasks read OK");
1158 }
1159
1160 if ( ! CreateTriggerLut(runNumber) )
1161 {
1162 AliErrorClass("Could not read TriggerLut");
1163 }
1164 else
1165 {
1166 AliInfoClass("TriggerLut read OK");
1167 }
1168
1169 if ( ! CreateTriggerEfficiency(runNumber) )
1170 {
1171 AliErrorClass("Could not read TriggerEfficiency");
1172 }
1173 else
1174 {
1175 AliInfoClass("TriggerEfficiency read OK");
1176 }
1177}