]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliGRPManager.cxx
ESD can init the Bfield via AliESDRun::InitMagneticField()
[u/mrichter/AliRoot.git] / STEER / AliGRPManager.cxx
CommitLineData
10c2f85a 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////////////////////////////////////////////////////////////////////////////
17// //
18// AliGRPManager class //
19// The class can be used in order to access and read the Global Run //
20// Parameters entry from OCDB. //
21// It has a methods to set the magnetic field instanton and return //
22// the run and event info objects. //
23// //
24// cvetan.cheshkov@cern.ch 15/06/2009 //
25// //
26// Usage: //
27// AliGRPManager grpMan; //
28// Bool_t status = kTRUE; //
29// status = grpMan.ReadGRPEntry(); // Read the corresponding OCDB entry //
30// status = grpMan.SetMagField(); // Set global field instanton //
31// AliRunInfo *runInfo = grpMan.GetRunInfo();// Get instance of run info //
32// //
33// Note: CDB manager should be initialized beforehand //
34////////////////////////////////////////////////////////////////////////////
35
36#include <TGeoGlobalMagField.h>
10c2f85a 37
38#include "AliGRPManager.h"
39#include "AliLog.h"
40#include "AliRunInfo.h"
41#include "AliGRPObject.h"
42#include "AliCDBManager.h"
43#include "AliCDBEntry.h"
44#include "AliMagF.h"
45
46ClassImp(AliGRPManager)
47
48//_____________________________________________________________________________
49AliGRPManager::AliGRPManager() :
50 TObject(),
51 fGRPData(NULL)
52{
53 // Default constructor
54}
55
56//_____________________________________________________________________________
57AliGRPManager::~AliGRPManager()
58{
59 // Destructor
60 if (fGRPData) delete fGRPData;
61}
62
63//_____________________________________________________________________________
64Bool_t AliGRPManager::ReadGRPEntry()
65{
66 //------------------------------------
67 // Initialization of the GRP entry.
68 // Returns kTRUE in case of success.
69 //------------------------------------
70
71 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
72
73 if (entry) {
74
75 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
76
77 if (m) {
78 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
79 m->Print();
80 fGRPData = new AliGRPObject();
81 fGRPData->ReadValuesFromMap(m);
82 }
83
84 else {
85 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
86 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
87 entry->SetOwner(0);
88 }
89
90 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
91 }
92
93 if (!fGRPData) {
94 AliError("No GRP entry found in OCDB!");
95 return kFALSE;
96 }
97
98 return kTRUE;
99}
100
101//_____________________________________________________________________________
102Bool_t AliGRPManager::SetMagField()
103{
104 // Dealing with the magnetic field map
105 // Construct the mag field map from the data in GRP
106 // Set the global mag field instance
107
108 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
5a004fb4 109 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
110 AliInfo("ExpertMode!!! GRP information will be ignored !");
111 AliInfo("ExpertMode!!! Running with the externally locked B field !");
112 return kTRUE;
10c2f85a 113 }
5a004fb4 114 else {
115 AliInfo("Destroying existing B field instance!");
116 delete TGeoGlobalMagField::Instance();
99c7d495 117 }
5a004fb4 118 }
119 //
120 // Construct the field map out of the information retrieved from GRP.
121 Bool_t ok = kTRUE;
122 // L3
123 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
124 if (l3Current == AliGRPObject::GetInvalidFloat()) {
125 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
126 ok = kFALSE;
127 }
0c976228 128
5a004fb4 129 Char_t l3Polarity = fGRPData->GetL3Polarity();
130 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
131 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
132 ok = kFALSE;
133 }
134
135 // Dipole
136 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
137 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
138 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
139 ok = kFALSE;
140 }
141
142 Char_t diPolarity = fGRPData->GetDipolePolarity();
143 if (diPolarity == AliGRPObject::GetInvalidChar()) {
144 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
145 ok = kFALSE;
146 }
147
148 TString beamType = fGRPData->GetBeamType();
149 if (beamType==AliGRPObject::GetInvalidString()) {
150 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
151 beamType = "UNKNOWN";
152 //ok = kFALSE; // temprorary suppressed to make read cosmics data
153 }
154
155 Float_t beamEnergy = fGRPData->GetBeamEnergy();
156 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
157 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
158 beamEnergy = 0;
159 //ok = kFALSE; // temprorary suppressed to make read cosmics data
160 }
161 // LHC: "multiply by 120 to get the energy in MeV"
162 beamEnergy *= 0.120;
163
164 // read special bits for the polarity convention and map type
165 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
166 Bool_t uniformB = fGRPData->IsUniformBMap();
167
168 if (ok) {
33fe5eb1 169 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
170 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
171 polConvention,uniformB,beamEnergy, beamType.Data());
172 if (fld) {
173 TGeoGlobalMagField::Instance()->SetField( fld );
174 TGeoGlobalMagField::Instance()->Lock();
175 AliInfo("Running with the B field constructed out of GRP !");
176 }
177 else {
5a004fb4 178 AliError("Failed to create a B field map !");
179 ok = kFALSE;
10c2f85a 180 }
10c2f85a 181 }
5a004fb4 182 else {
183 AliError("B field is neither set nor constructed from GRP ! Exitig...");
184 }
185
186 return ok;
10c2f85a 187}
188
189//_____________________________________________________________________________
190AliRunInfo* AliGRPManager::GetRunInfo()
191{
192 // Constructs and returns an object
193 // containing the run information
194 // The user code is the owner of the object
195
196 TString lhcState = fGRPData->GetLHCState();
197 if (lhcState==AliGRPObject::GetInvalidString()) {
198 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
199 lhcState = "UNKNOWN";
200 }
201
202 TString beamType = fGRPData->GetBeamType();
203 if (beamType==AliGRPObject::GetInvalidString()) {
204 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
205 beamType = "UNKNOWN";
206 }
207
208 Float_t beamEnergy = fGRPData->GetBeamEnergy();
209 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
210 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
211 beamEnergy = 0;
212 }
213 // energy is provided in MeV*120
214 beamEnergy /= 120E3;
215
216 TString runType = fGRPData->GetRunType();
217 if (runType==AliGRPObject::GetInvalidString()) {
218 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
219 runType = "UNKNOWN";
220 }
221
222 Int_t activeDetectors = fGRPData->GetDetectorMask();
223 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
224 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
225 activeDetectors = 1074790399;
226 }
227
228 return new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
229}