]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/loadFromOCDB.C
Introducing new DP CavernAtmosPressure2.
[u/mrichter/AliRoot.git] / MUON / loadFromOCDB.C
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 /// \ingroup macros
19 /// \file loadFromOCDB.C
20 /// \brief Load magnetic field, mapping and reconstruction parameters from OCDB
21 /// \author Philippe Pillot, SUBATECH
22
23 #include <TString.h>
24 #include <TObjArray.h>
25 #include <TGeoGlobalMagField.h>
26 #include <TGrid.h>
27
28 #include "AliCDBManager.h"
29 #include "AliCDBEntry.h"
30 #include "AliGRPManager.h"
31
32 #include "AliMpCDB.h"
33
34 #include "AliMUONRecoParam.h"
35
36 // prototypes
37 Bool_t setupOCDB(const TString ocdbPath = "local://$ALICE_ROOT/OCDB", Int_t runNumber = 0);
38 Bool_t checkOCDB();
39 Bool_t loadField();
40 Bool_t loadMapping();
41 AliMUONRecoParam* loadRecoParam();
42
43 //----------------------------------------------------------------------------------------
44 AliMUONRecoParam* loadFromOCDB(const TString ocdbPath = "local://$ALICE_ROOT/OCDB", Int_t runNumber = 0,
45                                Bool_t ldField = kTRUE, Bool_t ldMapping = kTRUE, Bool_t ldRecoParam = kTRUE)
46 {
47   /// Set the default OCDB path and run number (overload the existing ones if already set).
48   /// Load magnetic field, mapping and reconstruction parameters from OCDB as requested by the flags.
49   /// Return the AliMUONRecoParam object if loaded (0x0 otherwise).
50   /// Exit in case of any failure.
51   
52   AliMUONRecoParam* recoParam = 0x0;
53   
54   if (!setupOCDB(ocdbPath, runNumber)) exit(-1);
55   
56   if (ldField && !loadField()) exit(-1);
57   
58   if (ldMapping && !loadMapping()) exit(-1);
59   
60   if (ldRecoParam && !(recoParam = loadRecoParam())) exit(-1);
61   
62   return recoParam;
63   
64 }
65
66 //----------------------------------------------------------------------------------------
67 Bool_t setupOCDB(const TString ocdbPath, Int_t runNumber)
68 {
69   /// Set the default OCDB storage and run number (overload the existing ones if already set).
70   
71   Info("setupOCDB","setting OCDB path...");
72   
73   if (runNumber < 0) {
74     Error("setupOCDB", "runNumber must be a positive value");
75     return kFALSE;
76   }
77   
78   if (ocdbPath.BeginsWith("alien://")) TGrid::Connect("alien://");
79   
80   AliCDBManager* man = AliCDBManager::Instance();
81   
82   man->SetDefaultStorage(ocdbPath.Data());
83   if (!man->IsDefaultStorageSet()) return kFALSE;
84   
85   man->SetRun(runNumber);
86   
87   return kTRUE;
88   
89 }
90
91 //----------------------------------------------------------------------------------------
92 Bool_t checkOCDB()
93 {
94   /// Check that OCDB path and run number are properly set
95   
96   AliCDBManager* man = AliCDBManager::Instance();
97   if (!man->IsDefaultStorageSet() || man->GetRun() < 0) {
98     Error("checkOCDB", "OCDB path and runNumber must be properly set");
99     return kFALSE;
100   }
101   
102   return kTRUE;
103   
104 }
105
106 //----------------------------------------------------------------------------------------
107 Bool_t loadField()
108 {
109   /// Load magnetic field (existing field will be deleted).
110   /// OCDB path is supposed to be set.
111   
112   Info("loadField","Loading field map from GRP...");
113   
114   if (!checkOCDB()) return kFALSE;
115   
116   AliGRPManager grpMan;
117   
118   // in case it has already been set
119   TGeoGlobalMagField::Instance()->Unlock();
120   
121   if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
122     Error("loadField", "failed to load magnetic field from OCDB");
123     return kFALSE;
124   }
125   
126   return kTRUE;
127   
128 }
129
130 //----------------------------------------------------------------------------------------
131 Bool_t loadMapping()
132 {
133   /// Load mapping (existing mapping will be unloaded).
134   /// OCDB path is supposed to be set.
135   
136   Info("loadMapping","Loading mapping from OCDB...");
137   
138   if (!checkOCDB()) return kFALSE;
139   
140   // in case it has already been set
141   AliMpCDB::UnloadAll();
142   
143   if (!AliMpCDB::LoadAll(kTRUE)) {
144     Error("loadMapping","failed to load mapping from OCDB");
145     return kFALSE;
146   }
147   
148   return kTRUE;
149   
150 }
151
152 //----------------------------------------------------------------------------------------
153 AliMUONRecoParam* loadRecoParam()
154 {
155   /// Load and return reconstruction parameters.
156   /// OCDB path is supposed to be set.
157   
158   Info("loadRecoParam","Loading RecoParam from OCDB...");
159   
160   if (!checkOCDB()) return kFALSE;
161   
162   AliMUONRecoParam* recoParam = 0x0;
163   AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
164   
165   if(entry) {
166     
167     // load recoParam according OCDB content (single or array)
168     if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
169       
170       TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
171       
172       for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
173         recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
174         if (recoParam->IsDefault()) break;
175         recoParam = 0x0;
176       }
177       
178     }
179     
180   }
181   
182   if (!recoParam) Error("loadRecoParam", "failed to load RecoParam from OCDB");
183   
184   return recoParam;
185   
186 }
187