]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCalibrationData.cxx
Fixing memory leak.
[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
c5bdf179 125//_____________________________________________________________________________
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);
084cc733 310 UInt_t tripTime(0);
32f1b761 311
b37b9546 312 while ( ( p = static_cast<AliMpIntPair*>(nextGroup()) ) )
32f1b761 313 {
b37b9546 314 Double_t value;
315 Int_t slope;
32f1b761 316
b37b9546 317 TString groupMsg;
318
319 AliDebugClass(1,Form("group %d:%d",p->GetFirst(),p->GetSecond()));
320
321 Bool_t ok = CheckHVGroup(values,p->GetFirst(),p->GetSecond(),value,slope,&groupMsg);
322
323 if (!ok) continue;
324
325 ++ngroups;
326
327 if ( slope > 0 )
328 {
329 if ( p->GetFirst() == 0 )
330 {
331 // start with a ramp-up
332 ++nStartRU;
333 }
334 else if ( p->GetSecond() == values.GetLast() && TMath::Nint(value) < IENDRU )
335 {
336 ++nEndAndShortRU;
337 }
338 else
339 {
340 // ramp-up in the middle of nowhere...
341 ++nRU;
342 }
343 }
344 else if ( slope < 0 )
32f1b761 345 {
b37b9546 346 if ( p->GetSecond() == values.GetLast() )
347 {
348 // end with a ramp-down
349 ++nEndRD;
350 }
351 else
352 {
353 // ramp-down in the middle of nowhere
354 ++nRD;
355 }
356
357 AliDCSValue* d = static_cast<AliDCSValue*>(values.At(p->GetSecond()));
358
359 if ( d->GetFloat() < AliMpDCSNamer::TrackerHVOFF() )
360 {
361 ++nTripRD;
084cc733 362 AliDCSValue* tripStart = static_cast<AliDCSValue*>(values.At(p->GetFirst()));
363 tripTime = tripStart->GetTimeStamp();
b37b9546 364 }
32f1b761 365 }
b37b9546 366 else
32f1b761 367 {
b37b9546 368 ++nFluct;
32f1b761 369 }
b37b9546 370
371 internalMsg += groupMsg;
372 internalMsg += " ";
32f1b761 373 }
374
b37b9546 375 /*
376
377 Once we have "decoded" the groups we try to find out which of
378 the following cases we're facing :
379
380 case A = -------- = OK(1)
381
382 case B = ----
383 \
384 \ = OK, once we have removed the ramp-down (2)
385
386 case C = -----
387 /
388 / = OK, once we have removed the ramp-up (3)
389
390 case D = -----
391 / \
392 / \ = OK, once we have removed the ramp-down (2) and the ramp-up (3)
393
394 case E = ----
395 \
396 \____ = TRIP = BAD (here the ramp-down slope should be bigger than in case C)
397
398 case F = ----
399 \ ----- = BAD (trip + ramp-up at end of run)
400 \____/
401
402 case G = fluctuations (within a range defined in CheckHVGroup...)
403
404 case H =
405 /
406 / = ramp-up right at the end-of-run = OK (4)
407 ------
408
409 (1) OK means the group is identified correctly, still the value can be below ready...
410 (2) ramp-down values will be removed if the ramp is indeed the last values in the serie
411 i.e. it's really an end-of-run problem (otherwise it's not case B)
412 (3) ramp-up values will be removed if the ramp is indeed the first values in the serie
413 i.e. it's really a start-of-run problem (otherwise it's not case C)
414 (4) OK if short enough...
415
416 Any other case is unknown and we'll :
417 a) return kFALSE
418 b) assume the channel is OFF.
419
420
421 */
422
423 AliDebugClass(1,Form("msg=%s ngroupds=%d",internalMsg.Data(),ngroups));
424 AliDebugClass(1,Form("nRU %d nRD %d nStartRU %d nEndRD %d nTripRD %d nFluct %d",
425 nRU,nRD,nStartRU,nEndRD,nTripRD,nFluct));
426
427 TString hvCase("OTHER");
428 int dummy(0),a(-1),b(-1);
8763322f 429 char r[81];
b37b9546 430 Int_t nvalues = values.GetSize();
431 Int_t* indices = new Int_t[nvalues];
432 memset(indices,0,nvalues*sizeof(Int_t));
433
434 AliDCSValue* vfirst = static_cast<AliDCSValue*>(values.UncheckedAt(0));
435 AliDCSValue* vlast = static_cast<AliDCSValue*>(values.UncheckedAt(values.GetLast()));
436
437 UInt_t meanTimeStamp = ( vfirst->GetTimeStamp() + vlast->GetTimeStamp() ) / 2;
438
439 if ( ngroups == 0 )
32f1b761 440 {
b37b9546 441 hvCase = "A";
442 }
443 else if ( nTripRD > 0 )
444 {
445 if ( nRU > 0 && nRD > 0 )
32f1b761 446 {
b37b9546 447 hvCase = "F";
32f1b761 448 }
449 else
450 {
b37b9546 451 hvCase = "E";
32f1b761 452 }
b37b9546 453 internalMsg += "TRIP ";
454 MarkForDeletion(indices,0,values.GetLast());
455 values.Add(new AliDCSValue(static_cast<Float_t>(0),meanTimeStamp));
456 }
457 else if ( nStartRU > 0 && nRU == 0 && nRD == 0 && nEndRD == 0 )
458 {
459 hvCase = "C";
460 sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
461 MarkForDeletion(indices,a,b);
462 }
463 else if ( nStartRU > 0 && nEndRD > 0 && nRD == 0 && nRU == 0 )
464 {
465 hvCase = "D";
466 sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
467 MarkForDeletion(indices,a,b-1);
468 Int_t i = internalMsg.Index("RD",strlen("RD"),0,TString::kExact);
469 sscanf(internalMsg(i,internalMsg.Length()-i).Data(),
470 "RD%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
471 MarkForDeletion(indices,a+1,b);
472 }
473 else if ( nEndRD > 0 && nStartRU == 0 && nRU == 0 && nRD == 0 )
474 {
475 hvCase = "B";
476 Int_t i = internalMsg.Index("RD",strlen("RD"),0,TString::kExact);
477 sscanf(internalMsg(i,internalMsg.Length()-i).Data(),
478 "RD%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
479 MarkForDeletion(indices,a,b);
480 }
481 else if ( nFluct > 0 )
482 {
483 hvCase = "G";
484 TObjArray* af = internalMsg.Tokenize(" ");
485 TIter next(af);
486 TObjString* str;
487 while ( ( str = static_cast<TObjString*>(next()) ) )
488 {
489 TString s(str->String());
490 if ( s.BeginsWith("FLUCT") )
491 {
492 sscanf(s.Data(),"FLUCT%d[%d:%d]",&dummy,&a,&b);
493 MarkForDeletion(indices,a,b);
494 }
495 }
496 delete af;
497 }
498 else if ( nEndAndShortRU > 0 && nStartRU == 0 && nRU == 0 && nRD == 0 && nEndRD == 0 )
499 {
500 hvCase = "H";
501 sscanf(internalMsg.Data(),"RU%10d[%10d:%10d]%80s",&dummy,&a,&b,r);
502 MarkForDeletion(indices,a,b);
503 }
504 else
505 {
506 // last chance...
507 // here we know it's not a trip, so let's assume everything is OK
508 // if first and last value are in the same ballpark
509
510 const Double_t HVFLUCT(20); // volts
511
512 if ( TMath::Abs(vfirst->GetFloat() - vlast->GetFloat()) < HVFLUCT )
513 {
514 hvCase = "Z";
515 }
516 MarkForDeletion(indices,1,nvalues-1);
32f1b761 517 }
518
b37b9546 519 for ( Int_t i = 0; i < nvalues; ++i )
32f1b761 520 {
b37b9546 521 if ( indices[i] )
522 {
523 values.RemoveAt(i);
524 }
525 }
32f1b761 526
b37b9546 527 values.Compress();
528
529 delete[] indices;
530
531 if ( !values.GetEntries() )
532 {
533 AliErrorClass(Form("No value left after patch... Check that !!! initial # of values=%d msg=%s",
534 nvalues,internalMsg.Data()));
535 hvCase = "OTHER";
536 }
537
538 // take the max of the remaining values
539 TIter nextA(&values);
540 AliDCSValue* val;
541 Float_t maxval(-9999);
542
543 while ( ( val = static_cast<AliDCSValue*>(nextA()) ) )
544 {
545 if ( val->GetFloat() > maxval )
546 {
547 maxval = val->GetFloat();
548 }
549 }
550
551 values.Clear();
552
553 values.Add(new AliDCSValue(maxval,meanTimeStamp));
554
555 // once the case is inferred, add a "CASE:%10d",hvCase.Data()
556 // to the msg
557 // so we can them sum up for all channels and get a summary per run...
558
559 internalMsg += Form("CASE:%s",hvCase.Data());
560
084cc733 561 if ( tripTime > 0 )
562 {
563 internalMsg += Form(" TS:%u",tripTime);
564 }
565
b37b9546 566 if (msg) *msg = internalMsg.Data();
567
568 return hvCase=="OTHER" ? kFALSE : kTRUE;
32f1b761 569}
92c23b09 570
c1bbaf66 571//_____________________________________________________________________________
5562688f 572TMap*
b37b9546 573AliMUONCalibrationData::CreateHV(Int_t runNumber,
574 Int_t* startOfValidity,
575 Bool_t patched,
576 TList* messages)
c1bbaf66 577{
5562688f 578 /// Create a new HV map from the OCDB for a given run
32f1b761 579 TMap* hvMap = dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
b37b9546 580
8763322f 581 if (!hvMap) return 0x0;
582
32f1b761 583 if (patched)
584 {
585 TIter next(hvMap);
586 TObjString* hvChannelName;
587
588 while ( ( hvChannelName = static_cast<TObjString*>(next()) ) )
589 {
590 TString name(hvChannelName->String());
591
592 if ( name.Contains("sw") ) continue; // skip switches
593
594 TPair* hvPair = static_cast<TPair*>(hvMap->FindObject(name.Data()));
595 TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
596 if (!values)
597 {
598 AliErrorClass(Form("Could not get values for alias %s",name.Data()));
599 }
600 else
601 {
b37b9546 602 TString msg;
603
604 AliDebugClass(1,Form("channel %s",name.Data()));
605 Bool_t ok = PatchHVValues(*values,&msg);
606
607 if ( messages )
608 {
609 messages->Add(new TObjString(Form("%s:%s",hvChannelName->String().Data(),msg.Data())));
610 }
32f1b761 611
b37b9546 612 if (!ok)
32f1b761 613 {
b37b9546 614 AliErrorClass(Form("PatchHVValue was not successfull ! This is serious ! "
615 "You'll have to check the logic for channel %s in run %09d",
616 name.Data(),runNumber));
32f1b761 617 }
618 }
619 }
620
621 }
b37b9546 622
623 if ( messages )
624 {
625 Int_t a(0),b(0),c(0),d(0),e(0),f(0),g(0),h(0),u(0),z(0);
626 TIter next(messages);
627 TObjString* msg;
6350d0c0 628 char hvCase('u');
b37b9546 629
630 while ( ( msg = static_cast<TObjString*>(next()) ) )
631 {
632 Int_t i = msg->String().Index("CASE",strlen("CASE"),0,TString::kExact);
633
634 if ( i >= 0 )
635 {
8763322f 636 sscanf(msg->String()(i,msg->String().Length()-i).Data(),"CASE:%10c",&hvCase);
b37b9546 637 }
638
639 switch (hvCase)
640 {
641 case 'A': ++a; break;
642 case 'B': ++b; break;
643 case 'C': ++c; break;
644 case 'D': ++d; break;
645 case 'E': ++e; break;
646 case 'F': ++f; break;
647 case 'G': ++g; break;
648 case 'H': ++h; break;
649 case 'Z': ++z; break;
650 default: ++u; break;
651 }
652 }
653
654 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)",
655 a,b,c,d,e,f,g,h,z,u)));
656 }
657
32f1b761 658 return hvMap;
c1bbaf66 659}
660
49e110ec 661//_____________________________________________________________________________
662TMap*
663AliMUONCalibrationData::CreateTriggerDCS(Int_t runNumber, Int_t* startOfValidity)
664{
665 /// Create a new Trigger HV and curent map from the OCDB for a given run
666 return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/TriggerDCS",startOfValidity));
667}
668
d067ba7c 669//_____________________________________________________________________________
a0eca509 670AliMUONVStore*
143cd71a 671AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
d067ba7c 672{
5562688f 673 /// Get the internal store for LocalTriggerBoardMasks from OCDB
674
143cd71a 675 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
d067ba7c 676}
677
48ed403b 678//_____________________________________________________________________________
a0eca509 679AliMUONVStore*
143cd71a 680AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
48ed403b 681{
5562688f 682 /// Create a neighbour store from the OCDB for a given run
143cd71a 683 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
c5bdf179 684}
685
d067ba7c 686//_____________________________________________________________________________
5562688f 687TObject*
143cd71a 688AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
d067ba7c 689{
5562688f 690 /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
691 /// and return the corresponding TObject.
d067ba7c 692
b37b9546 693 AliCodeTimerAutoClass(Form("%09d : %s",runNumber,path),0);
4bec0403 694
5562688f 695 AliCDBManager* man = AliCDBManager::Instance();
696
465302eb 697 AliCDBEntry* entry = man->Get(path,runNumber);
5562688f 698
5562688f 699 if (entry)
d067ba7c 700 {
143cd71a 701 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
702
4bec0403 703 TObject* object = entry->GetObject();
82586209 704 if (!(man->GetCacheFlag()))
705 {
706 entry->SetOwner(kFALSE);
707 delete entry;
708 }
cdffeaea 709// else
710// {
711// entry->SetOwner(kTRUE); //FIXME : this should be done but is causing problems with RecoParams at the end of the reco : investigate why...
712// }
4bec0403 713 return object;
714 }
143cd71a 715 else
716 {
717 if ( startOfValidity ) *startOfValidity = AliCDBRunRange::Infinity();
718 }
719
0045b488 720 {
721
b37b9546 722 AliCodeTimerAutoClass(Form("Failed to get %s for run %09d",path,runNumber),1);
0045b488 723
724 }
725
5562688f 726 return 0x0;
d067ba7c 727}
728
2b8a1212 729//_____________________________________________________________________________
730AliMUONVStore*
7eafe398 731AliMUONCalibrationData::CreateOccupancyMap(Int_t runNumber, Int_t* startOfValidity)
2b8a1212 732{
7eafe398 733 /// Create a new occupancy map store from the OCDB for a given run
734 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/OccupancyMap",startOfValidity));
2b8a1212 735}
736
0045b488 737//_____________________________________________________________________________
738AliMUONRejectList*
739AliMUONCalibrationData::CreateRejectList(Int_t runNumber, Int_t* startOfValidity)
740{
741 /// Create a new rejectlist store from the OCDB for a given run
742 return dynamic_cast<AliMUONRejectList*>(CreateObject(runNumber,"MUON/Calib/RejectList",startOfValidity));
743}
744
c1bbaf66 745//_____________________________________________________________________________
a0eca509 746AliMUONVStore*
143cd71a 747AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
c1bbaf66 748{
5562688f 749 /// Create a new pedestal store from the OCDB for a given run
143cd71a 750 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
c1bbaf66 751}
752
6c870207 753//_____________________________________________________________________________
754AliMUONVStore*
755AliMUONCalibrationData::CreateConfig(Int_t runNumber, Int_t* startOfValidity)
756{
757 /// Create a new config store from the OCDB for a given run
758 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Config",startOfValidity));
759}
760
92c23b09 761
c5bdf179 762//_____________________________________________________________________________
92c23b09 763AliMUONRegionalTriggerConfig*
143cd71a 764AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
5562688f 765{
92c23b09 766 /// Create the internal store for RegionalTriggerConfig from OCDB
5562688f 767
143cd71a 768 return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
5562688f 769}
770
771//_____________________________________________________________________________
772AliMUONTriggerEfficiencyCells*
143cd71a 773AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
c5bdf179 774{
5562688f 775 /// Create trigger efficiency object from OCBD
776
143cd71a 777 return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
5562688f 778}
5398f946 779
5562688f 780//_____________________________________________________________________________
781AliMUONTriggerLut*
143cd71a 782AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
5562688f 783{
784 /// Create trigger LUT from OCDB
785
143cd71a 786 return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
5562688f 787}
788
789//_____________________________________________________________________________
790AliMUONVStore*
791AliMUONCalibrationData::Gains() const
792{
793 /// Create (if needed) and return the internal store for gains.
9ee1d6ff 794 if (fgBypassGains) return fgBypassGains;
8f29b706 795
c5bdf179 796 if (!fGains)
797 {
5562688f 798 fGains = CreateGains(fRunNumber);
c5bdf179 799 }
800 return fGains;
801}
b37b9546 802
e7d7fa47 803//_____________________________________________________________________________
5562688f 804AliMUONVCalibParam*
805AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
e7d7fa47 806{
5562688f 807/// Return the gains for a given (detElemId, manuId) pair
808/// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
809/// error (meaning that we should get gains for all channels).
5398f946 810
5562688f 811 AliMUONVStore* gains = Gains();
812 if (!gains)
813 {
814 return 0x0;
815 }
816
817 return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
e7d7fa47 818}
819
820//_____________________________________________________________________________
92c23b09 821AliMUONGlobalCrateConfig*
822AliMUONCalibrationData::GlobalTriggerCrateConfig() const
e7d7fa47 823{
92c23b09 824 /// Return the config for the global trigger board.
5562688f 825
92c23b09 826 if (!fGlobalTriggerCrateConfig)
e7d7fa47 827 {
92c23b09 828 fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
e7d7fa47 829 }
92c23b09 830 return fGlobalTriggerCrateConfig;
e7d7fa47 831}
832
92c23b09 833
e7d7fa47 834//_____________________________________________________________________________
5562688f 835TMap*
32f1b761 836AliMUONCalibrationData::HV(Bool_t patched) const
e7d7fa47 837{
5562688f 838 /// Return the calibration for a given (detElemId, manuId) pair
48ed403b 839
5562688f 840 if (!fHV)
e7d7fa47 841 {
32f1b761 842 fHV = CreateHV(fRunNumber,0,patched);
e7d7fa47 843 }
5562688f 844 return fHV;
e7d7fa47 845}
846
49e110ec 847//_____________________________________________________________________________
848TMap*
849AliMUONCalibrationData::TriggerDCS() const
850{
851 /// Return the calibration for a given (detElemId, manuId) pair
852
853 if (!fTriggerDCS)
854 {
855 fTriggerDCS = CreateTriggerDCS(fRunNumber);
856 }
857 return fTriggerDCS;
858}
859
e7d7fa47 860//_____________________________________________________________________________
a0eca509 861AliMUONVStore*
5562688f 862AliMUONCalibrationData::Neighbours() const
e7d7fa47 863{
5562688f 864 /// Create (if needed) and return the internal store for neighbours.
865 if (!fNeighbours)
866 {
867 fNeighbours = CreateNeighbours(fRunNumber);
868 }
869 return fNeighbours;
870}
871
872//_____________________________________________________________________________
873AliMUONVCalibParam*
874AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
875{
876/// Return the masks for a given trigger local board.
5398f946 877
e7d7fa47 878 if (!fLocalTriggerBoardMasks)
879 {
5562688f 880 fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
881 }
882
883 if ( fLocalTriggerBoardMasks )
884 {
885 AliMUONVCalibParam* ltbm =
886 static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
887 if (!ltbm)
e7d7fa47 888 {
5562688f 889 AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
e7d7fa47 890 }
5562688f 891 return ltbm;
e7d7fa47 892 }
5562688f 893 return 0x0;
e7d7fa47 894}
895
2b8a1212 896//_____________________________________________________________________________
897AliMUONVStore*
7eafe398 898AliMUONCalibrationData::OccupancyMap() const
2b8a1212 899{
7eafe398 900 /// Get occupancy map
901 if (!fOccupancyMap)
2b8a1212 902 {
7eafe398 903 fOccupancyMap = CreateOccupancyMap(fRunNumber);
2b8a1212 904 }
7eafe398 905 return fOccupancyMap;
2b8a1212 906}
907
0045b488 908//_____________________________________________________________________________
909AliMUONRejectList*
910AliMUONCalibrationData::RejectList() const
911{
912 /// Get reject list
913 if (!fRejectList)
914 {
915 fRejectList = CreateRejectList(fRunNumber);
916 }
917 return fRejectList;
918}
919
8f29b706 920//_____________________________________________________________________________
921void
922AliMUONCalibrationData::BypassStores(AliMUONVStore* ped, AliMUONVStore* gain)
923{
924 /// Force the use of those pedestals and gains
9ee1d6ff 925 fgBypassPedestals = ped;
926 fgBypassGains = gain;
8f29b706 927
928}
929
c5bdf179 930//_____________________________________________________________________________
a0eca509 931AliMUONVStore*
5562688f 932AliMUONCalibrationData::Pedestals() const
c5bdf179 933{
5562688f 934 /// Return pedestals
8f29b706 935
9ee1d6ff 936 if (fgBypassPedestals) return fgBypassPedestals;
8f29b706 937
c5bdf179 938 if (!fPedestals)
939 {
5562688f 940 fPedestals = CreatePedestals(fRunNumber);
c5bdf179 941 }
942 return fPedestals;
943}
944
6c870207 945//_____________________________________________________________________________
946AliMUONVStore*
947AliMUONCalibrationData::Config() const
948{
949 /// Return config
950
951 if (!fConfig)
952 {
953 fConfig = CreateConfig(fRunNumber);
954 }
955 return fConfig;
956}
957
5562688f 958//_____________________________________________________________________________
959AliMUONVCalibParam*
960AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
961{
962 /// Return the pedestals for a given (detElemId, manuId) pair.
963 /// A return value of 0x0 is considered an error, meaning we should get
964 /// pedestals for all channels.
965
966 AliMUONVStore* pedestals = Pedestals();
967 if (!pedestals)
968 {
969 return 0x0;
970 }
971
972 return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
973}
974
c5bdf179 975//_____________________________________________________________________________
976void
977AliMUONCalibrationData::Print(Option_t*) const
978{
5562688f 979 /// A very basic dump of our guts.
5398f946 980
c5bdf179 981 cout << "RunNumber " << RunNumber()
e7d7fa47 982 << " fGains=" << fGains
983 << " fPedestals=" << fPedestals
6c870207 984 << " fConfig=" << fConfig
48ed403b 985 << " fHV=" << fHV
49e110ec 986 << " fTriggerDCS=" << fTriggerDCS
e7d7fa47 987 << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
92c23b09 988 << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
989 << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
e7d7fa47 990 << " fTriggerLut=" << fTriggerLut
c5bdf179 991 << endl;
992}
993
92c23b09 994
e7d7fa47 995//_____________________________________________________________________________
92c23b09 996AliMUONRegionalTriggerConfig*
997AliMUONCalibrationData::RegionalTriggerConfig() const
e7d7fa47 998{
92c23b09 999 /// Return the config for the regional trigger board.
48ed403b 1000
92c23b09 1001 if (!fRegionalTriggerConfig)
e7d7fa47 1002 {
92c23b09 1003 fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
e7d7fa47 1004 }
92c23b09 1005 return fRegionalTriggerConfig;
e7d7fa47 1006}
1007
92c23b09 1008
e7d7fa47 1009//_____________________________________________________________________________
1010AliMUONTriggerEfficiencyCells*
1011AliMUONCalibrationData::TriggerEfficiency() const
1012{
5398f946 1013/// Return the trigger efficiency.
1014
e7d7fa47 1015 if (!fTriggerEfficiency)
1016 {
5562688f 1017 fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
e7d7fa47 1018 }
1019 return fTriggerEfficiency;
1020}
1021
5562688f 1022
e7d7fa47 1023//_____________________________________________________________________________
1024AliMUONTriggerLut*
1025AliMUONCalibrationData::TriggerLut() const
1026{
5398f946 1027/// Return the trigger look up table.
1028
e7d7fa47 1029 if (!fTriggerLut)
1030 {
5562688f 1031 fTriggerLut = CreateTriggerLut(fRunNumber);
e7d7fa47 1032 }
1033 return fTriggerLut;
1034}
1035
c1bbaf66 1036//_____________________________________________________________________________
1037void
1038AliMUONCalibrationData::Reset()
1039{
1040/// Reset all data
1041
82586209 1042 AliCodeTimerAuto("",0);
1043
6c870207 1044 delete fConfig;
1045 fConfig = 0x0;
c1bbaf66 1046 delete fPedestals;
1047 fPedestals = 0x0;
1048 delete fGains;
1049 fGains = 0x0;
1050 delete fHV;
1051 fHV = 0x0;
49e110ec 1052 delete fTriggerDCS;
1053 fTriggerDCS = 0x0;
c1bbaf66 1054 delete fLocalTriggerBoardMasks;
1055 fLocalTriggerBoardMasks = 0x0;
92c23b09 1056 delete fRegionalTriggerConfig;
1057 fRegionalTriggerConfig = 0x0;
1058 delete fGlobalTriggerCrateConfig;
1059 fGlobalTriggerCrateConfig = 0x0;
1060
c1bbaf66 1061 delete fTriggerLut;
1062 fTriggerLut = 0x0;
1063 delete fTriggerEfficiency;
1064 fTriggerEfficiency = 0x0;
1065 delete fCapacitances;
1066 fCapacitances = 0x0;
d067ba7c 1067 delete fNeighbours;
1068 fNeighbours = 0x0;
c1bbaf66 1069}
1070
630711ed 1071//_____________________________________________________________________________
1072void
1073AliMUONCalibrationData::Check(Int_t runNumber)
1074{
1075 /// Self-check to see if we can read all data for a given run
1076 /// from the current OCDB...
1077
1078 if ( ! CreateCapacitances(runNumber) )
1079 {
1080 AliErrorClass("Could not read capacitances");
1081 }
1082 else
1083 {
1084 AliInfoClass("Capacitances read OK");
1085 }
1086
1087 if ( ! CreateGains(runNumber) )
1088 {
1089 AliErrorClass("Could not read gains");
1090 }
1091 else
1092 {
1093 AliInfoClass("Gains read OK");
1094 }
1095
1096 if ( ! CreateGlobalTriggerCrateConfig(runNumber) )
1097 {
1098 AliErrorClass("Could not read Trigger Crate Config");
1099 }
1100 else
1101 {
1102 AliInfoClass("TriggerBoardMasks read OK");
1103 }
1104
1105 if ( ! CreateHV(runNumber) )
1106 {
1107 AliErrorClass("Could not read HV");
1108 }
1109 else
1110 {
1111 AliInfoClass("HV read OK");
49e110ec 1112 }
1113
1114 if ( ! CreateTriggerDCS(runNumber) )
1115 {
1116 AliErrorClass("Could not read Trigger HV and Currents");
1117 }
1118 else
1119 {
1120 AliInfoClass("Trigger HV and Currents read OK");
630711ed 1121 }
1122
1123 if ( ! CreateNeighbours(runNumber) )
1124 {
1125 AliErrorClass("Could not read Neighbours");
1126 }
1127 else
1128 {
1129 AliInfoClass("Neighbours read OK");
1130 }
1131
1132 if ( ! CreateLocalTriggerBoardMasks(runNumber) )
1133 {
1134 AliErrorClass("Could not read LocalTriggerBoardMasks");
1135 }
1136 else
1137 {
1138 AliInfoClass("LocalTriggerBoardMasks read OK");
1139 }
1140
1141 if ( ! CreatePedestals(runNumber) )
1142 {
1143 AliErrorClass("Could not read pedestals");
1144 }
1145 else
1146 {
1147 AliInfoClass("Pedestals read OK");
1148 }
6c870207 1149
1150 if ( ! CreateConfig(runNumber) )
1151 {
1152 AliErrorClass("Could not read config");
1153 }
1154 else
1155 {
1156 AliInfoClass("Config read OK");
1157 }
630711ed 1158
1159 if ( ! CreateRegionalTriggerConfig(runNumber) )
1160 {
1161 AliErrorClass("Could not read RegionalTriggerConfig");
1162 }
1163 else
1164 {
1165 AliInfoClass("RegionalTriggerBoardMasks read OK");
1166 }
1167
1168 if ( ! CreateTriggerLut(runNumber) )
1169 {
1170 AliErrorClass("Could not read TriggerLut");
1171 }
1172 else
1173 {
1174 AliInfoClass("TriggerLut read OK");
1175 }
1176
1177 if ( ! CreateTriggerEfficiency(runNumber) )
1178 {
1179 AliErrorClass("Could not read TriggerEfficiency");
1180 }
1181 else
1182 {
1183 AliInfoClass("TriggerEfficiency read OK");
1184 }
1185}