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 **************************************************************************/
16 ////////////////////////////////////////////////////////////////////////////
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. //
24 // cvetan.cheshkov@cern.ch 15/06/2009 //
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 //
33 // Note: CDB manager should be initialized beforehand //
34 ////////////////////////////////////////////////////////////////////////////
36 #include <TGeoGlobalMagField.h>
38 #include "AliGRPManager.h"
40 #include "AliRunInfo.h"
41 #include "AliGRPObject.h"
42 #include "AliCDBManager.h"
43 #include "AliCDBEntry.h"
46 ClassImp(AliGRPManager)
48 //_____________________________________________________________________________
49 AliGRPManager::AliGRPManager() :
53 // Default constructor
56 //_____________________________________________________________________________
57 AliGRPManager::~AliGRPManager()
60 if (fGRPData) delete fGRPData;
63 //_____________________________________________________________________________
64 Bool_t AliGRPManager::ReadGRPEntry()
66 //------------------------------------
67 // Initialization of the GRP entry.
68 // Returns kTRUE in case of success.
69 //------------------------------------
71 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
75 TMap* m = dynamic_cast<TMap*>(entry->GetObject()); // old GRP entry
78 AliInfo("Found a TMap in GRP/GRP/Data, converting it into an AliGRPObject");
80 fGRPData = new AliGRPObject();
81 fGRPData->ReadValuesFromMap(m);
85 AliInfo("Found an AliGRPObject in GRP/GRP/Data, reading it");
86 fGRPData = dynamic_cast<AliGRPObject*>(entry->GetObject()); // new GRP entry
90 AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
94 AliError("No GRP entry found in OCDB!");
101 //_____________________________________________________________________________
102 Bool_t AliGRPManager::SetMagField()
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
108 if ( TGeoGlobalMagField::Instance()->IsLocked() ) {
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 !");
115 AliInfo("Destroying existing B field instance!");
116 delete TGeoGlobalMagField::Instance();
121 AliError("GRP Data is not loaded");
125 // Construct the field map out of the information retrieved from GRP.
128 Float_t l3Current = fGRPData->GetL3Current((AliGRPObject::Stats)0);
129 if (l3Current == AliGRPObject::GetInvalidFloat()) {
130 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
134 Char_t l3Polarity = fGRPData->GetL3Polarity();
135 if (l3Polarity == AliGRPObject::GetInvalidChar()) {
136 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
141 Float_t diCurrent = fGRPData->GetDipoleCurrent((AliGRPObject::Stats)0);
142 if (diCurrent == AliGRPObject::GetInvalidFloat()) {
143 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
147 Char_t diPolarity = fGRPData->GetDipolePolarity();
148 if (diPolarity == AliGRPObject::GetInvalidChar()) {
149 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
153 TString beamType = fGRPData->GetBeamType();
154 if (beamType==AliGRPObject::GetInvalidString()) {
155 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
156 beamType = "UNKNOWN";
157 //ok = kFALSE; // temprorary suppressed to make read cosmics data
160 Float_t beamEnergy = fGRPData->GetBeamEnergy();
161 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
162 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
164 //ok = kFALSE; // temprorary suppressed to make read cosmics data
167 // read special bits for the polarity convention and map type
168 Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008;
169 Bool_t uniformB = fGRPData->IsUniformBMap();
172 AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1),
173 TMath::Abs(diCurrent) * (diPolarity ? -1:1),
174 polConvention,uniformB,beamEnergy, beamType.Data());
176 TGeoGlobalMagField::Instance()->SetField( fld );
177 TGeoGlobalMagField::Instance()->Lock();
178 AliInfo("Running with the B field constructed out of GRP !");
181 AliError("Failed to create a B field map !");
186 AliError("B field is neither set nor constructed from GRP ! Exitig...");
192 //_____________________________________________________________________________
193 AliRunInfo* AliGRPManager::GetRunInfo()
195 // Constructs and returns an object
196 // containing the run information
197 // The user code is the owner of the object
199 TString lhcState = fGRPData->GetLHCState();
200 if (lhcState==AliGRPObject::GetInvalidString()) {
201 AliError("GRP/GRP/Data entry: missing value for the LHC state ! Using UNKNOWN");
202 lhcState = "UNKNOWN";
205 TString beamType = fGRPData->GetBeamType();
206 if (beamType==AliGRPObject::GetInvalidString()) {
207 AliError("GRP/GRP/Data entry: missing value for the beam type ! Using UNKNOWN");
208 beamType = "UNKNOWN";
211 Float_t beamEnergy = fGRPData->GetBeamEnergy();
212 if (beamEnergy==AliGRPObject::GetInvalidFloat()) {
213 AliError("GRP/GRP/Data entry: missing value for the beam energy ! Using 0");
216 // energy is provided in MeV*120
219 TString runType = fGRPData->GetRunType();
220 if (runType==AliGRPObject::GetInvalidString()) {
221 AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN");
225 Int_t activeDetectors = fGRPData->GetDetectorMask();
226 if (activeDetectors==AliGRPObject::GetInvalidUInt()) {
227 AliError("GRP/GRP/Data entry: missing value for the detector mask ! Using 1074790399");
228 activeDetectors = 1074790399;
231 return new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors);
234 //_____________________________________________________________________________
235 void AliGRPManager::SetGRPEntry(AliGRPObject* source)
237 // Create a GRP entry from the extrnaly provide GRP object
238 // To be used by HLT to create an online GRP instance
240 if (fGRPData) delete fGRPData;
241 fGRPData = new AliGRPObject(*source);
242 AliInfo("Created GRP Data from external object");