]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
https://savannah.cern.ch/bugs/index.php?98544
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibrationData.cxx
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"
22 #include "AliCodeTimer.h"
23 #include "AliDCSValue.h"
24 #include "AliLog.h"
25 #include "AliMpDCSNamer.h"
26 #include "AliMpIntPair.h"
27 #include "AliMUONGlobalCrateConfig.h"
28 #include "AliMUONRegionalTriggerConfig.h"
29 #include "AliMUONRejectList.h"
30 #include "AliMUONTriggerEfficiencyCells.h"
31 #include "AliMUONTriggerLut.h"
32 #include "AliMUONVCalibParam.h"
33 #include "AliMUONVStore.h"
34 #include "AliMUONVStore.h"
35
36 #include <Riostream.h>
37 #include <TClass.h>
38 #include <TMap.h>
39 #include <TMath.h>
40
41 //-----------------------------------------------------------------------------
42 /// \class AliMUONCalibrationData
43 ///
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.
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 ///
54 /// \author Laurent Aphecetche
55 //-----------------------------------------------------------------------------
56
57 using std::cout;
58 using std::endl;
59 /// \cond CLASSIMP
60 ClassImp(AliMUONCalibrationData)
61 /// \endcond
62
63 AliMUONVStore* AliMUONCalibrationData::fgBypassPedestals(0x0);
64 AliMUONVStore* AliMUONCalibrationData::fgBypassGains(0x0);
65
66 namespace  
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
77 //_____________________________________________________________________________
78 AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
79                                                Bool_t deferredInitialization) 
80 : TObject(), 
81 fIsValid(kTRUE),
82 fRunNumber(runNumber), 
83 fGains(0x0), 
84 fPedestals(0x0),
85 fHV(0x0),
86 fTriggerDCS(0x0),
87 fLocalTriggerBoardMasks(0x0),
88 fRegionalTriggerConfig(0x0),
89 fGlobalTriggerCrateConfig(0x0),
90 fTriggerLut(0x0),
91 fTriggerEfficiency(0x0),
92 fCapacitances(0x0),
93 fNeighbours(0x0),
94 fOccupancyMap(0x0),
95 fRejectList(0x0),
96 fConfig(0x0)
97 {
98 /// Default ctor.
99
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.
105
106   if ( deferredInitialization == kFALSE )
107   {
108     Gains();
109     Pedestals();
110     OccupancyMap();
111     RejectList();
112     HV();
113     TriggerDCS();
114     LocalTriggerBoardMasks(0);
115     RegionalTriggerConfig();
116     GlobalTriggerCrateConfig();
117     TriggerLut();
118     TriggerEfficiency();
119     Capacitances();
120     Neighbours();
121     Config();
122   }
123 }
124
125 //_____________________________________________________________________________
126 AliMUONCalibrationData::~AliMUONCalibrationData()
127 {
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();
131 }
132
133 //_____________________________________________________________________________
134 AliMUONVStore*
135 AliMUONCalibrationData::Capacitances() const
136 {
137   /// Create (if needed) and return the internal store for capacitances.
138   
139   if (!fCapacitances)
140   {
141     fCapacitances = CreateCapacitances(fRunNumber);
142   }
143   return fCapacitances;
144 }
145
146 //_____________________________________________________________________________
147 AliMUONVStore*
148 AliMUONCalibrationData::CreateCapacitances(Int_t runNumber, Int_t* startOfValidity)
149 {
150   /// Create capa store from OCDB for a given run
151   
152   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances",startOfValidity));
153 }
154
155 //_____________________________________________________________________________
156 AliMUONVStore*
157 AliMUONCalibrationData::CreateGains(Int_t runNumber, Int_t* startOfValidity)
158 {
159   /// Create a new gain store from the OCDB for a given run
160   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains",startOfValidity));
161 }
162
163 //_____________________________________________________________________________
164 AliMUONGlobalCrateConfig*
165 AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity)
166 {
167   /// Create the internal store for GlobalTriggerCrateConfig from OCDB
168   
169   return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig",startOfValidity));
170 }
171
172
173 //______________________________________________________________________________
174 Bool_t AliMUONCalibrationData::CheckHVGroup(TObjArray& values, Int_t first, Int_t last, Double_t& value, Int_t& slope, TString* msg)
175 {
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   //
180   
181   if (msg) *msg="";
182   
183   if ( last < first ) return kFALSE;
184   if ( last - first < 2 ) return kFALSE;
185   
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()));
195   
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();
204   
205     a += x*y;
206     b += x*x;
207   }
208   
209   value = a/b;
210   slope = value > 0 ? 1 : -1;
211   value = TMath::Abs(value);
212   
213   UInt_t deltaTime = vlast->GetTimeStamp() - vfirst->GetTimeStamp();
214   
215   if (msg)
216   {
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);
219     
220     if ( TMath::Nint(value) == 0 )
221     {
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);
232     }
233   }
234   
235   return kTRUE;
236 }
237
238 //______________________________________________________________________________
239 Bool_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 ) 
268   {
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 )
273     {
274       if ( !gather ) 
275       {
276         gather = kTRUE;
277         ifirst = i;    
278       }
279       ilast=i;
280     }
281     else
282     {
283       if ( gather ) 
284       {
285         ilast=i;
286         
287         groups.Add(new AliMpIntPair(ilast,ifirst));
288       }
289       gather = kFALSE;
290     }
291   }
292   
293   if (gather)
294   {
295     groups.Add(new AliMpIntPair(0,ifirst));
296   }
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);
310   
311   while ( ( p = static_cast<AliMpIntPair*>(nextGroup()) ) )
312   {
313     Double_t value;
314     Int_t slope;
315     
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 )
344     {
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       }
362     }
363     else
364     {
365       ++nFluct;
366     }
367     
368     internalMsg += groupMsg;
369     internalMsg += " ";    
370   }
371   
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);
426   char r[81];
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 ) 
437   {
438     hvCase = "A"; 
439   }
440   else if ( nTripRD > 0 )
441   {
442     if ( nRU > 0 && nRD > 0 )
443     {
444       hvCase = "F";
445     }
446     else
447     {
448       hvCase = "E";
449     }
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);
514   }
515   
516   for ( Int_t i = 0; i < nvalues; ++i ) 
517   {
518     if ( indices[i] )
519     {
520       values.RemoveAt(i);
521     }
522   }
523   
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;
561 }
562
563 //_____________________________________________________________________________
564 TMap*
565 AliMUONCalibrationData::CreateHV(Int_t runNumber, 
566                                  Int_t* startOfValidity, 
567                                  Bool_t patched,
568                                  TList* messages)
569 {
570   /// Create a new HV map from the OCDB for a given run
571   TMap* hvMap = dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
572
573   if (!hvMap) return 0x0;
574   
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       {
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         }
603         
604         if (!ok)
605         {
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));
609         }
610       }
611     }
612     
613   }
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;
620     char hvCase('u');
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       {
628         sscanf(msg->String()(i,msg->String().Length()-i).Data(),"CASE:%10c",&hvCase);
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   
650   return hvMap;
651 }
652
653 //_____________________________________________________________________________
654 TMap*
655 AliMUONCalibrationData::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 //_____________________________________________________________________________
662 AliMUONVStore*
663 AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
664 {
665   /// Get the internal store for LocalTriggerBoardMasks from OCDB
666   
667   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
668 }
669
670 //_____________________________________________________________________________
671 AliMUONVStore*
672 AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
673 {
674   /// Create a neighbour store from the OCDB for a given run
675   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
676 }
677
678 //_____________________________________________________________________________
679 TObject*
680 AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
681 {
682   /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
683   /// and return the corresponding TObject.
684   
685   AliCodeTimerAutoClass(Form("%09d : %s",runNumber,path),0);
686   
687   AliCDBManager* man = AliCDBManager::Instance();
688   
689   AliCDBEntry* entry =  man->Get(path,runNumber);
690   
691   if (entry)
692   {
693                 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
694                 
695     TObject* object = entry->GetObject();
696     if (!(man->GetCacheFlag()))
697     {
698       entry->SetOwner(kFALSE);
699       delete entry;      
700     }
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 //    }
705     return object;
706   }
707         else
708         {
709                 if ( startOfValidity )  *startOfValidity = AliCDBRunRange::Infinity();
710   }
711         
712   {
713     
714     AliCodeTimerAutoClass(Form("Failed to get %s for run %09d",path,runNumber),1);
715
716   }
717   
718   return 0x0;
719 }
720
721 //_____________________________________________________________________________
722 AliMUONVStore*
723 AliMUONCalibrationData::CreateOccupancyMap(Int_t runNumber, Int_t* startOfValidity)
724 {
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));
727 }
728
729 //_____________________________________________________________________________
730 AliMUONRejectList*
731 AliMUONCalibrationData::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 //_____________________________________________________________________________
738 AliMUONVStore*
739 AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
740 {
741   /// Create a new pedestal store from the OCDB for a given run
742   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
743 }
744
745 //_____________________________________________________________________________
746 AliMUONVStore*
747 AliMUONCalibrationData::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
753
754 //_____________________________________________________________________________
755 AliMUONRegionalTriggerConfig*
756 AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
757 {
758   /// Create the internal store for RegionalTriggerConfig from OCDB
759   
760   return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
761 }
762
763 //_____________________________________________________________________________
764 AliMUONTriggerEfficiencyCells* 
765 AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
766 {
767   /// Create trigger efficiency object from OCBD
768   
769   return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
770 }
771
772 //_____________________________________________________________________________
773 AliMUONTriggerLut* 
774 AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
775 {
776   /// Create trigger LUT from OCDB
777   
778   return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
779 }
780
781 //_____________________________________________________________________________
782 AliMUONVStore*
783 AliMUONCalibrationData::Gains() const
784 {
785   /// Create (if needed) and return the internal store for gains.
786   if (fgBypassGains) return fgBypassGains;
787   
788   if (!fGains)
789   {
790     fGains = CreateGains(fRunNumber);
791   }
792   return fGains;
793 }
794  
795 //_____________________________________________________________________________
796 AliMUONVCalibParam*
797 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
798 {
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).
802
803   AliMUONVStore* gains = Gains();
804   if (!gains)
805   {
806     return 0x0;
807   }
808   
809   return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
810 }
811
812 //_____________________________________________________________________________
813 AliMUONGlobalCrateConfig* 
814 AliMUONCalibrationData::GlobalTriggerCrateConfig() const
815 {
816   /// Return the config for the global trigger board.
817   
818   if (!fGlobalTriggerCrateConfig)
819   {
820     fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
821   }
822   return fGlobalTriggerCrateConfig;
823 }
824
825
826 //_____________________________________________________________________________
827 TMap*
828 AliMUONCalibrationData::HV(Bool_t patched) const
829 {
830   /// Return the calibration for a given (detElemId, manuId) pair
831   
832   if (!fHV)
833   {
834     fHV = CreateHV(fRunNumber,0,patched);
835   }
836   return fHV;
837 }
838
839 //_____________________________________________________________________________
840 TMap*
841 AliMUONCalibrationData::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 //_____________________________________________________________________________
853 AliMUONVStore*
854 AliMUONCalibrationData::Neighbours() const
855 {
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 //_____________________________________________________________________________
865 AliMUONVCalibParam* 
866 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
867 {
868 /// Return the masks for a given trigger local board.
869
870   if (!fLocalTriggerBoardMasks)
871   {
872     fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
873   }
874
875   if ( fLocalTriggerBoardMasks ) 
876   {
877     AliMUONVCalibParam* ltbm = 
878       static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
879     if (!ltbm)
880     {
881       AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
882     }
883     return ltbm;  
884   }
885   return 0x0;
886 }
887
888 //_____________________________________________________________________________
889 AliMUONVStore*
890 AliMUONCalibrationData::OccupancyMap() const
891 {
892   /// Get occupancy map
893   if (!fOccupancyMap)
894   {
895     fOccupancyMap = CreateOccupancyMap(fRunNumber);
896   }
897   return fOccupancyMap;
898 }
899
900 //_____________________________________________________________________________
901 AliMUONRejectList*
902 AliMUONCalibrationData::RejectList() const
903 {
904   /// Get reject list
905   if (!fRejectList)
906   {
907     fRejectList = CreateRejectList(fRunNumber);
908   }
909   return fRejectList;
910 }
911
912 //_____________________________________________________________________________
913 void
914 AliMUONCalibrationData::BypassStores(AliMUONVStore* ped, AliMUONVStore* gain)
915 {
916   /// Force the use of those pedestals and gains
917   fgBypassPedestals = ped;
918   fgBypassGains = gain;
919   
920 }
921
922 //_____________________________________________________________________________
923 AliMUONVStore*
924 AliMUONCalibrationData::Pedestals() const
925 {
926   /// Return pedestals
927   
928   if (fgBypassPedestals) return fgBypassPedestals;
929   
930   if (!fPedestals)
931   {
932     fPedestals = CreatePedestals(fRunNumber);
933   }
934   return fPedestals;
935 }
936
937 //_____________________________________________________________________________
938 AliMUONVStore*
939 AliMUONCalibrationData::Config() const
940 {
941   /// Return config
942   
943   if (!fConfig)
944   {
945     fConfig = CreateConfig(fRunNumber);
946   }
947   return fConfig;
948 }
949
950 //_____________________________________________________________________________
951 AliMUONVCalibParam*
952 AliMUONCalibrationData::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 //_____________________________________________________________________________
968 void
969 AliMUONCalibrationData::Print(Option_t*) const
970 {
971   /// A very basic dump of our guts.
972
973   cout << "RunNumber " << RunNumber()
974   << " fGains=" << fGains
975   << " fPedestals=" << fPedestals
976   << " fConfig=" << fConfig
977   << " fHV=" << fHV
978   << " fTriggerDCS=" << fTriggerDCS
979   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
980   << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
981   << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
982   << " fTriggerLut=" << fTriggerLut
983   << endl;
984 }
985
986
987 //_____________________________________________________________________________
988 AliMUONRegionalTriggerConfig* 
989 AliMUONCalibrationData::RegionalTriggerConfig() const
990 {
991   /// Return the config for the regional trigger board.
992   
993   if (!fRegionalTriggerConfig)
994   {
995     fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
996     }
997   return fRegionalTriggerConfig;
998 }
999
1000
1001 //_____________________________________________________________________________
1002 AliMUONTriggerEfficiencyCells*
1003 AliMUONCalibrationData::TriggerEfficiency() const
1004 {
1005 /// Return the trigger efficiency.
1006
1007   if (!fTriggerEfficiency)
1008   {
1009     fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
1010   }
1011   return fTriggerEfficiency;
1012 }
1013
1014
1015 //_____________________________________________________________________________
1016 AliMUONTriggerLut*
1017 AliMUONCalibrationData::TriggerLut() const
1018 {
1019 /// Return the trigger look up table.
1020
1021   if (!fTriggerLut)
1022   {
1023     fTriggerLut = CreateTriggerLut(fRunNumber);
1024   }
1025   return fTriggerLut;
1026 }
1027
1028 //_____________________________________________________________________________
1029 void
1030 AliMUONCalibrationData::Reset()
1031 {
1032 /// Reset all data
1033
1034   AliCodeTimerAuto("",0);
1035   
1036   delete fConfig;
1037   fConfig = 0x0;
1038   delete fPedestals;
1039   fPedestals = 0x0;
1040   delete fGains;
1041   fGains = 0x0;
1042   delete fHV;
1043   fHV = 0x0;
1044   delete fTriggerDCS;
1045   fTriggerDCS = 0x0;
1046   delete fLocalTriggerBoardMasks;
1047   fLocalTriggerBoardMasks = 0x0;
1048   delete fRegionalTriggerConfig;
1049   fRegionalTriggerConfig = 0x0;
1050   delete fGlobalTriggerCrateConfig;
1051   fGlobalTriggerCrateConfig = 0x0;
1052   
1053   delete fTriggerLut;
1054   fTriggerLut = 0x0;
1055   delete fTriggerEfficiency;
1056   fTriggerEfficiency = 0x0;
1057   delete fCapacitances;
1058   fCapacitances = 0x0;
1059   delete fNeighbours;
1060   fNeighbours = 0x0;
1061 }
1062
1063 //_____________________________________________________________________________
1064 void
1065 AliMUONCalibrationData::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");
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");
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   }
1141
1142   if ( ! CreateConfig(runNumber) )
1143   {
1144     AliErrorClass("Could not read config");
1145   }
1146   else
1147   {
1148     AliInfoClass("Config read OK");
1149   }
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 }