1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 /// \file loadFromOCDB.C
20 /// \brief Load magnetic field, mapping and reconstruction parameters from OCDB
21 /// \author Philippe Pillot, SUBATECH
24 #include <TObjArray.h>
25 #include <TGeoGlobalMagField.h>
28 #include "AliCDBManager.h"
29 #include "AliCDBEntry.h"
30 #include "AliGRPManager.h"
34 #include "AliMUONRecoParam.h"
37 Bool_t setupOCDB(const TString ocdbPath = "local://$ALICE_ROOT/OCDB", Int_t runNumber = 0);
41 AliMUONRecoParam* loadRecoParam();
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)
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.
52 AliMUONRecoParam* recoParam = 0x0;
54 if (!setupOCDB(ocdbPath, runNumber)) exit(-1);
56 if (ldField && !loadField()) exit(-1);
58 if (ldMapping && !loadMapping()) exit(-1);
60 if (ldRecoParam && !(recoParam = loadRecoParam())) exit(-1);
66 //----------------------------------------------------------------------------------------
67 Bool_t setupOCDB(const TString ocdbPath, Int_t runNumber)
69 /// Set the default OCDB storage and run number (overload the existing ones if already set).
71 Info("setupOCDB","setting OCDB path...");
74 Error("setupOCDB", "runNumber must be a positive value");
78 if (ocdbPath.BeginsWith("alien://")) TGrid::Connect("alien://");
80 AliCDBManager* man = AliCDBManager::Instance();
82 man->SetDefaultStorage(ocdbPath.Data());
83 if (!man->IsDefaultStorageSet()) return kFALSE;
85 man->SetRun(runNumber);
91 //----------------------------------------------------------------------------------------
94 /// Check that OCDB path and run number are properly set
96 AliCDBManager* man = AliCDBManager::Instance();
97 if (!man->IsDefaultStorageSet() || man->GetRun() < 0) {
98 Error("checkOCDB", "OCDB path and runNumber must be properly set");
106 //----------------------------------------------------------------------------------------
109 /// Load magnetic field (existing field will be deleted).
110 /// OCDB path is supposed to be set.
112 Info("loadField","Loading field map from GRP...");
114 if (!checkOCDB()) return kFALSE;
116 AliGRPManager grpMan;
118 // in case it has already been set
119 TGeoGlobalMagField::Instance()->Unlock();
121 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
122 Error("loadField", "failed to load magnetic field from OCDB");
130 //----------------------------------------------------------------------------------------
133 /// Load mapping (existing mapping will be unloaded).
134 /// OCDB path is supposed to be set.
136 Info("loadMapping","Loading mapping from OCDB...");
138 if (!checkOCDB()) return kFALSE;
140 // in case it has already been set
141 AliMpCDB::UnloadAll();
143 if (!AliMpCDB::LoadAll(kTRUE)) {
144 Error("loadMapping","failed to load mapping from OCDB");
152 //----------------------------------------------------------------------------------------
153 AliMUONRecoParam* loadRecoParam()
155 /// Load and return reconstruction parameters.
156 /// OCDB path is supposed to be set.
158 Info("loadRecoParam","Loading RecoParam from OCDB...");
160 if (!checkOCDB()) return kFALSE;
162 AliMUONRecoParam* recoParam = 0x0;
163 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
167 // load recoParam according OCDB content (single or array)
168 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
170 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
172 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
173 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
174 if (recoParam->IsDefault()) break;
182 if (!recoParam) Error("loadRecoParam", "failed to load RecoParam from OCDB");