]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEER/AliGRPManager.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / STEER / 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
f944f125 36#include <THashTable.h>
10c2f85a 37#include <TGeoGlobalMagField.h>
10c2f85a 38
39#include "AliGRPManager.h"
40#include "AliLog.h"
41#include "AliRunInfo.h"
42#include "AliGRPObject.h"
43#include "AliCDBManager.h"
44#include "AliCDBEntry.h"
45#include "AliMagF.h"
46
47ClassImp(AliGRPManager)
48
49//_____________________________________________________________________________
50AliGRPManager::AliGRPManager() :
51 TObject(),
52 fGRPData(NULL)
53{
54 // Default constructor
55}
56
57//_____________________________________________________________________________
58AliGRPManager::~AliGRPManager()
59{
60 // Destructor
61 if (fGRPData) delete fGRPData;
62}
63
64//_____________________________________________________________________________
65Bool_t AliGRPManager::ReadGRPEntry()
66{
67 //------------------------------------
68 // Initialization of the GRP entry.
69 // Returns kTRUE in case of success.
70 //------------------------------------
71
72 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
73
74 if (entry) {
75
76 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
77
78 if (m) {
79 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
80 m->Print();
81 fGRPData = new AliGRPObject();
82 fGRPData->ReadValuesFromMap(m);
83 }
84
85 else {
86 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
87 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
88 entry->SetOwner(0);
89 }
90
91 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
92 }
93
94 if (!fGRPData) {
95 AliError("No GRP entry found in OCDB!");
96 return kFALSE;
97 }
98
99 return kTRUE;
100}
101
102//_____________________________________________________________________________
103Bool_t AliGRPManager::SetMagField()
104{
105 // Dealing with the magnetic field map
106 // Construct the mag field map from the data in GRP
107 // Set the global mag field instance
108
109 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
5a004fb4 110 if (TGeoGlobalMagField::Instance()->GetField()->TestBit(AliMagF::kOverrideGRP)) {
111 AliInfo("ExpertMode!!! GRP information will be ignored !");
112 AliInfo("ExpertMode!!! Running with the externally locked B field !");
113 return kTRUE;
10c2f85a 114 }
5a004fb4 115 else {
116 AliInfo("Destroying existing B field instance!");
117 delete TGeoGlobalMagField::Instance();
99c7d495 118 }
5a004fb4 119 }
120 //
f6e611f0 121 if (!fGRPData) {
122 AliError("GRP Data is not loaded");
123 return kFALSE;
124 }
125 //
5a004fb4 126 // Construct the field map out of the information retrieved from GRP.
127 Bool_t ok = kTRUE;
128 // L3
129 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
130 if (l3Current == AliGRPObject::GetInvalidFloat()) {
131 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
132 ok = kFALSE;
133 }
0c976228 134
5a004fb4 135 Char_t l3Polarity = fGRPData->GetL3Polarity();
136 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
137 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
138 ok = kFALSE;
139 }
140
141 // Dipole
142 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
143 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
144 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
145 ok = kFALSE;
146 }
147
148 Char_t diPolarity = fGRPData->GetDipolePolarity();
149 if (diPolarity == AliGRPObject::GetInvalidChar()) {
150 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
151 ok = kFALSE;
152 }
153
154 TString beamType = fGRPData->GetBeamType();
155 if (beamType==AliGRPObject::GetInvalidString()) {
156 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
157 beamType = "UNKNOWN";
158 //ok = kFALSE; // temprorary suppressed to make read cosmics data
159 }
160
161 Float_t beamEnergy = fGRPData->GetBeamEnergy();
162 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
163 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
164 beamEnergy = 0;
165 //ok = kFALSE; // temprorary suppressed to make read cosmics data
166 }
5a004fb4 167
168 // read special bits for the polarity convention and map type
169 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
170 Bool_t uniformB = fGRPData->IsUniformBMap();
171
172 if (ok) {
33fe5eb1 173 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
174 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
175 polConvention,uniformB,beamEnergy, beamType.Data());
176 if (fld) {
177 TGeoGlobalMagField::Instance()->SetField( fld );
178 TGeoGlobalMagField::Instance()->Lock();
179 AliInfo("Running with the B field constructed out of GRP !");
180 }
181 else {
5a004fb4 182 AliError("Failed to create a B field map !");
183 ok = kFALSE;
10c2f85a 184 }
10c2f85a 185 }
5a004fb4 186 else {
187 AliError("B field is neither set nor constructed from GRP ! Exitig...");
188 }
189
190 return ok;
10c2f85a 191}
192
193//_____________________________________________________________________________
194AliRunInfo* AliGRPManager::GetRunInfo()
195{
196 // Constructs and returns an object
197 // containing the run information
198 // The user code is the owner of the object
f944f125 199 if(!fGRPData) ReadGRPEntry();
10c2f85a 200
201 TString lhcState = fGRPData->GetLHCState();
202 if (lhcState==AliGRPObject::GetInvalidString()) {
203 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
204 lhcState = "UNKNOWN";
205 }
206
207 TString beamType = fGRPData->GetBeamType();
208 if (beamType==AliGRPObject::GetInvalidString()) {
209 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
210 beamType = "UNKNOWN";
211 }
212
213 Float_t beamEnergy = fGRPData->GetBeamEnergy();
214 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
215 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
216 beamEnergy = 0;
217 }
218 // energy is provided in MeV*120
219 beamEnergy /= 120E3;
220
221 TString runType = fGRPData->GetRunType();
222 if (runType==AliGRPObject::GetInvalidString()) {
223 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
224 runType = "UNKNOWN";
225 }
226
227 Int_t activeDetectors = fGRPData->GetDetectorMask();
228 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
229 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
230 activeDetectors = 1074790399;
231 }
232
233 return new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
234}
f6e611f0 235
f944f125 236THashTable* AliGRPManager::GetCosmicTriggers()
237{
238 THashTable* listOfCosmicTriggers = 0;
239 AliCDBEntry* entry = 0;
240
241 entry = AliCDBManager::Instance()->Get("GRP/Calib/CosmicTriggers");
242 if (entry) {
243 listOfCosmicTriggers = dynamic_cast<THashTable*>(entry->GetObject());
244 entry->SetOwner(0);
245 }
246
247 if (!listOfCosmicTriggers) {
248 AliWarning("Can not get list of cosmic triggers from OCDB! Cosmic event specie will be effectively disabled!");
249 }
250
251 return listOfCosmicTriggers;
252}
253
254
f6e611f0 255//_____________________________________________________________________________
339fbe23 256void AliGRPManager::SetGRPEntry(const AliGRPObject* source)
f6e611f0 257{
258 // Create a GRP entry from the extrnaly provide GRP object
259 // To be used by HLT to create an online GRP instance
260 if (!source) return;
261 if (fGRPData) delete fGRPData;
262 fGRPData = new AliGRPObject(*source);
263 AliInfo("Created GRP Data from external object");
264 //
265}
266