]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
Add a new variable, that is the radial position of the track at the end
[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 "AliLog.h"
24 #include "AliMUONRejectList.h"
25 #include "AliMUONTriggerEfficiencyCells.h"
26 #include "AliMUONTriggerLut.h"
27 #include "AliMUONVStore.h"
28 #include "AliMUONVStore.h"
29 #include "AliMUONVCalibParam.h"
30 #include "AliMUONGlobalCrateConfig.h"
31 #include "AliMUONRegionalTriggerConfig.h"
32
33 #include <Riostream.h>
34 #include <TClass.h>
35 #include <TMap.h>
36
37 //-----------------------------------------------------------------------------
38 /// \class AliMUONCalibrationData
39 ///
40 /// For the moment, this class stores pedestals, gains, hv (for tracker)
41 /// and lut, masks and efficiencies (for trigger) that are fetched from the CDB.
42 ///
43 /// This class is to be considered as a convenience class.
44 /// Its aim is to ease retrieval of calibration data from the 
45 /// condition database.
46 ///
47 /// It acts as a "facade" to a bunch of underlying 
48 /// containers/calibration classes.
49 ///
50 /// \author Laurent Aphecetche
51 //-----------------------------------------------------------------------------
52
53 /// \cond CLASSIMP
54 ClassImp(AliMUONCalibrationData)
55 /// \endcond
56
57 AliMUONVStore* AliMUONCalibrationData::fBypassPedestals(0x0);
58 AliMUONVStore* AliMUONCalibrationData::fBypassGains(0x0);
59
60 //_____________________________________________________________________________
61 AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
62                                                Bool_t deferredInitialization) 
63 : TObject(), 
64 fIsValid(kTRUE),
65 fRunNumber(runNumber), 
66 fGains(0x0), 
67 fPedestals(0x0),
68 fHV(0x0),
69 fTriggerDCS(0x0),
70 fLocalTriggerBoardMasks(0x0),
71 fRegionalTriggerConfig(0x0),
72 fGlobalTriggerCrateConfig(0x0),
73 fTriggerLut(0x0),
74 fTriggerEfficiency(0x0),
75 fCapacitances(0x0),
76 fNeighbours(0x0),
77 fOccupancyMap(0x0),
78 fRejectList(0x0),
79 fConfig(0x0)
80 {
81 /// Default ctor.
82
83   // If deferredInitialization is false, we read *all* calibrations
84   // at once.
85   // So when using this class to access only one kind of calibrations (e.g.
86   // only pedestals), you should put deferredInitialization to kTRUE, which
87   // will instruct this object to fetch the data only when neeeded.
88
89   if ( deferredInitialization == kFALSE )
90   {
91     Gains();
92     Pedestals();
93     OccupancyMap();
94     RejectList();
95     HV();
96     TriggerDCS();
97     LocalTriggerBoardMasks(0);
98     RegionalTriggerConfig();
99     GlobalTriggerCrateConfig();
100     TriggerLut();
101     TriggerEfficiency();
102     Capacitances();
103     Neighbours();
104     Config();
105   }
106 }
107
108 //_____________________________________________________________________________
109 AliMUONCalibrationData::~AliMUONCalibrationData()
110 {
111   /// Destructor. Note that we're the owner of our pointers.
112   //PH The owner of the objects is CDB, do not delete them!
113   //  Reset();
114 }
115
116 //_____________________________________________________________________________
117 AliMUONVStore*
118 AliMUONCalibrationData::Capacitances() const
119 {
120   /// Create (if needed) and return the internal store for capacitances.
121   
122   if (!fCapacitances)
123   {
124     fCapacitances = CreateCapacitances(fRunNumber);
125   }
126   return fCapacitances;
127 }
128
129 //_____________________________________________________________________________
130 AliMUONVStore*
131 AliMUONCalibrationData::CreateCapacitances(Int_t runNumber, Int_t* startOfValidity)
132 {
133   /// Create capa store from OCDB for a given run
134   
135   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances",startOfValidity));
136 }
137
138 //_____________________________________________________________________________
139 AliMUONVStore*
140 AliMUONCalibrationData::CreateGains(Int_t runNumber, Int_t* startOfValidity)
141 {
142   /// Create a new gain store from the OCDB for a given run
143   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains",startOfValidity));
144 }
145
146 //_____________________________________________________________________________
147 AliMUONGlobalCrateConfig*
148 AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity)
149 {
150   /// Create the internal store for GlobalTriggerCrateConfig from OCDB
151   
152   return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig",startOfValidity));
153 }
154
155
156
157 //_____________________________________________________________________________
158 TMap*
159 AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity)
160 {
161   /// Create a new HV map from the OCDB for a given run
162   return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
163 }
164
165 //_____________________________________________________________________________
166 TMap*
167 AliMUONCalibrationData::CreateTriggerDCS(Int_t runNumber, Int_t* startOfValidity)
168 {
169   /// Create a new Trigger HV and curent map from the OCDB for a given run
170   return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/TriggerDCS",startOfValidity));
171 }
172
173 //_____________________________________________________________________________
174 AliMUONVStore*
175 AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
176 {
177   /// Get the internal store for LocalTriggerBoardMasks from OCDB
178   
179   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
180 }
181
182 //_____________________________________________________________________________
183 AliMUONVStore*
184 AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
185 {
186   /// Create a neighbour store from the OCDB for a given run
187   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
188 }
189
190 //_____________________________________________________________________________
191 TObject*
192 AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
193 {
194   /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
195   /// and return the corresponding TObject.
196   
197   AliCodeTimerAutoClass(Form("%d : %s",runNumber,path),0);
198   
199   AliCDBManager* man = AliCDBManager::Instance();
200   
201   AliCDBEntry* entry =  man->Get(path,runNumber);
202   
203   if (entry)
204   {
205                 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
206                 
207     TObject* object = entry->GetObject();
208     entry->SetOwner(kFALSE);
209     if (!(man->GetCacheFlag())) delete entry;
210     return object;
211   }
212         else
213         {
214                 if ( startOfValidity )  *startOfValidity = AliCDBRunRange::Infinity();
215   }
216         
217   {
218     
219     AliCodeTimerAutoClass(Form("Failed to get %s for run %d",path,runNumber),1);
220
221   }
222   
223   return 0x0;
224 }
225
226 //_____________________________________________________________________________
227 AliMUONVStore*
228 AliMUONCalibrationData::CreateOccupancyMap(Int_t runNumber, Int_t* startOfValidity)
229 {
230   /// Create a new occupancy map store from the OCDB for a given run
231   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/OccupancyMap",startOfValidity));
232 }
233
234 //_____________________________________________________________________________
235 AliMUONRejectList*
236 AliMUONCalibrationData::CreateRejectList(Int_t runNumber, Int_t* startOfValidity)
237 {
238   /// Create a new rejectlist store from the OCDB for a given run
239   return dynamic_cast<AliMUONRejectList*>(CreateObject(runNumber,"MUON/Calib/RejectList",startOfValidity));
240 }
241
242 //_____________________________________________________________________________
243 AliMUONVStore*
244 AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
245 {
246   /// Create a new pedestal store from the OCDB for a given run
247   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
248 }
249
250 //_____________________________________________________________________________
251 AliMUONVStore*
252 AliMUONCalibrationData::CreateConfig(Int_t runNumber, Int_t* startOfValidity)
253 {
254   /// Create a new config store from the OCDB for a given run
255   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Config",startOfValidity));
256 }
257
258
259 //_____________________________________________________________________________
260 AliMUONRegionalTriggerConfig*
261 AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
262 {
263   /// Create the internal store for RegionalTriggerConfig from OCDB
264   
265   return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
266 }
267
268 //_____________________________________________________________________________
269 AliMUONTriggerEfficiencyCells* 
270 AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
271 {
272   /// Create trigger efficiency object from OCBD
273   
274   return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
275 }
276
277 //_____________________________________________________________________________
278 AliMUONTriggerLut* 
279 AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
280 {
281   /// Create trigger LUT from OCDB
282   
283   return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
284 }
285
286 //_____________________________________________________________________________
287 AliMUONVStore*
288 AliMUONCalibrationData::Gains() const
289 {
290   /// Create (if needed) and return the internal store for gains.
291   if (fBypassGains) return fBypassGains;
292   
293   if (!fGains)
294   {
295     fGains = CreateGains(fRunNumber);
296   }
297   return fGains;
298 }
299
300 //_____________________________________________________________________________
301 AliMUONVCalibParam*
302 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
303 {
304 /// Return the gains for a given (detElemId, manuId) pair
305 /// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
306 /// error (meaning that we should get gains for all channels).
307
308   AliMUONVStore* gains = Gains();
309   if (!gains)
310   {
311     return 0x0;
312   }
313   
314   return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
315 }
316
317 //_____________________________________________________________________________
318 AliMUONGlobalCrateConfig* 
319 AliMUONCalibrationData::GlobalTriggerCrateConfig() const
320 {
321   /// Return the config for the global trigger board.
322   
323   if (!fGlobalTriggerCrateConfig)
324   {
325     fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
326   }
327   return fGlobalTriggerCrateConfig;
328 }
329
330
331 //_____________________________________________________________________________
332 TMap*
333 AliMUONCalibrationData::HV() const
334 {
335   /// Return the calibration for a given (detElemId, manuId) pair
336   
337   if (!fHV)
338   {
339     fHV = CreateHV(fRunNumber);
340   }
341   return fHV;
342 }
343
344 //_____________________________________________________________________________
345 TMap*
346 AliMUONCalibrationData::TriggerDCS() const
347 {
348   /// Return the calibration for a given (detElemId, manuId) pair
349   
350   if (!fTriggerDCS)
351   {
352     fTriggerDCS = CreateTriggerDCS(fRunNumber);
353   }
354   return fTriggerDCS;
355 }
356
357 //_____________________________________________________________________________
358 AliMUONVStore*
359 AliMUONCalibrationData::Neighbours() const
360 {
361   /// Create (if needed) and return the internal store for neighbours.
362   if (!fNeighbours)
363   {
364     fNeighbours = CreateNeighbours(fRunNumber);
365   }
366   return fNeighbours;
367 }
368
369 //_____________________________________________________________________________
370 AliMUONVCalibParam* 
371 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
372 {
373 /// Return the masks for a given trigger local board.
374
375   if (!fLocalTriggerBoardMasks)
376   {
377     fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
378   }
379
380   if ( fLocalTriggerBoardMasks ) 
381   {
382     AliMUONVCalibParam* ltbm = 
383       static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
384     if (!ltbm)
385     {
386       AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
387     }
388     return ltbm;  
389   }
390   return 0x0;
391 }
392
393 //_____________________________________________________________________________
394 AliMUONVStore*
395 AliMUONCalibrationData::OccupancyMap() const
396 {
397   /// Get occupancy map
398   if (!fOccupancyMap)
399   {
400     fOccupancyMap = CreateOccupancyMap(fRunNumber);
401   }
402   return fOccupancyMap;
403 }
404
405 //_____________________________________________________________________________
406 AliMUONRejectList*
407 AliMUONCalibrationData::RejectList() const
408 {
409   /// Get reject list
410   if (!fRejectList)
411   {
412     fRejectList = CreateRejectList(fRunNumber);
413   }
414   return fRejectList;
415 }
416
417 //_____________________________________________________________________________
418 void
419 AliMUONCalibrationData::BypassStores(AliMUONVStore* ped, AliMUONVStore* gain)
420 {
421   /// Force the use of those pedestals and gains
422   fBypassPedestals = ped;
423   fBypassGains = gain;
424   
425 }
426
427 //_____________________________________________________________________________
428 AliMUONVStore*
429 AliMUONCalibrationData::Pedestals() const
430 {
431   /// Return pedestals
432   
433   if (fBypassPedestals) return fBypassPedestals;
434   
435   if (!fPedestals)
436   {
437     fPedestals = CreatePedestals(fRunNumber);
438   }
439   return fPedestals;
440 }
441
442 //_____________________________________________________________________________
443 AliMUONVStore*
444 AliMUONCalibrationData::Config() const
445 {
446   /// Return config
447   
448   if (!fConfig)
449   {
450     fConfig = CreateConfig(fRunNumber);
451   }
452   return fConfig;
453 }
454
455 //_____________________________________________________________________________
456 AliMUONVCalibParam*
457 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
458 {
459   /// Return the pedestals for a given (detElemId, manuId) pair.
460   /// A return value of 0x0 is considered an error, meaning we should get
461   /// pedestals for all channels.
462   
463   AliMUONVStore* pedestals = Pedestals();
464   if (!pedestals) 
465   {
466     return 0x0;
467   }
468   
469   return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
470 }
471
472 //_____________________________________________________________________________
473 void
474 AliMUONCalibrationData::Print(Option_t*) const
475 {
476   /// A very basic dump of our guts.
477
478   cout << "RunNumber " << RunNumber()
479   << " fGains=" << fGains
480   << " fPedestals=" << fPedestals
481   << " fConfig=" << fConfig
482   << " fHV=" << fHV
483   << " fTriggerDCS=" << fTriggerDCS
484   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
485   << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
486   << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
487   << " fTriggerLut=" << fTriggerLut
488   << endl;
489 }
490
491
492 //_____________________________________________________________________________
493 AliMUONRegionalTriggerConfig* 
494 AliMUONCalibrationData::RegionalTriggerConfig() const
495 {
496   /// Return the config for the regional trigger board.
497   
498   if (!fRegionalTriggerConfig)
499   {
500     fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
501     }
502   return fRegionalTriggerConfig;
503 }
504
505
506 //_____________________________________________________________________________
507 AliMUONTriggerEfficiencyCells*
508 AliMUONCalibrationData::TriggerEfficiency() const
509 {
510 /// Return the trigger efficiency.
511
512   if (!fTriggerEfficiency)
513   {
514     fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
515   }
516   return fTriggerEfficiency;
517 }
518
519
520 //_____________________________________________________________________________
521 AliMUONTriggerLut*
522 AliMUONCalibrationData::TriggerLut() const
523 {
524 /// Return the trigger look up table.
525
526   if (!fTriggerLut)
527   {
528     fTriggerLut = CreateTriggerLut(fRunNumber);
529   }
530   return fTriggerLut;
531 }
532
533 //_____________________________________________________________________________
534 void
535 AliMUONCalibrationData::Reset()
536 {
537 /// Reset all data
538
539   delete fConfig;
540   fConfig = 0x0;
541   delete fPedestals;
542   fPedestals = 0x0;
543   delete fGains;
544   fGains = 0x0;
545   delete fHV;
546   fHV = 0x0;
547   delete fTriggerDCS;
548   fTriggerDCS = 0x0;
549   delete fLocalTriggerBoardMasks;
550   fLocalTriggerBoardMasks = 0x0;
551   delete fRegionalTriggerConfig;
552   fRegionalTriggerConfig = 0x0;
553   delete fGlobalTriggerCrateConfig;
554   fGlobalTriggerCrateConfig = 0x0;
555   
556   delete fTriggerLut;
557   fTriggerLut = 0x0;
558   delete fTriggerEfficiency;
559   fTriggerEfficiency = 0x0;
560   delete fCapacitances;
561   fCapacitances = 0x0;
562   delete fNeighbours;
563   fNeighbours = 0x0;
564 }
565
566 //_____________________________________________________________________________
567 void
568 AliMUONCalibrationData::Check(Int_t runNumber)
569 {
570   /// Self-check to see if we can read all data for a given run 
571   /// from the current OCDB...
572   
573   if ( ! CreateCapacitances(runNumber) )
574   {
575     AliErrorClass("Could not read capacitances");
576   }
577   else
578   {
579     AliInfoClass("Capacitances read OK");
580   }
581
582   if ( ! CreateGains(runNumber) ) 
583   {
584     AliErrorClass("Could not read gains");
585   }
586   else
587   {
588     AliInfoClass("Gains read OK");
589   }
590
591   if ( ! CreateGlobalTriggerCrateConfig(runNumber) ) 
592   {
593     AliErrorClass("Could not read Trigger Crate Config");
594   }
595   else
596   {
597     AliInfoClass("TriggerBoardMasks read OK");
598   }
599
600   if ( !  CreateHV(runNumber) )
601   {
602     AliErrorClass("Could not read HV");
603   }
604   else
605   {
606     AliInfoClass("HV read OK");
607   }
608
609   if ( !  CreateTriggerDCS(runNumber) )
610   {
611     AliErrorClass("Could not read Trigger HV and Currents");
612   }
613   else
614   {
615     AliInfoClass("Trigger HV and Currents read OK");
616   }
617
618   if ( ! CreateNeighbours(runNumber) )
619   {
620     AliErrorClass("Could not read Neighbours");
621   }
622   else
623   {
624     AliInfoClass("Neighbours read OK");
625   }
626
627   if ( !  CreateLocalTriggerBoardMasks(runNumber) )
628   {
629     AliErrorClass("Could not read LocalTriggerBoardMasks");
630   }
631   else
632   {
633     AliInfoClass("LocalTriggerBoardMasks read OK");
634   }
635   
636   if ( ! CreatePedestals(runNumber) )
637   {
638     AliErrorClass("Could not read pedestals");
639   }
640   else
641   {
642     AliInfoClass("Pedestals read OK");
643   }
644
645   if ( ! CreateConfig(runNumber) )
646   {
647     AliErrorClass("Could not read config");
648   }
649   else
650   {
651     AliInfoClass("Config read OK");
652   }
653   
654   if ( ! CreateRegionalTriggerConfig(runNumber) )
655   {
656     AliErrorClass("Could not read RegionalTriggerConfig");
657   }
658   else
659   {
660     AliInfoClass("RegionalTriggerBoardMasks read OK");
661   }
662   
663   if ( ! CreateTriggerLut(runNumber) )
664   {
665     AliErrorClass("Could not read TriggerLut");
666   }
667   else
668   {
669     AliInfoClass("TriggerLut read OK");
670   }
671
672   if ( ! CreateTriggerEfficiency(runNumber) )
673   {
674     AliErrorClass("Could not read TriggerEfficiency");
675   }
676   else    
677   {
678     AliInfoClass("TriggerEfficiency read OK");
679   }
680 }
681
682