]>
Commit | Line | Data |
---|---|---|
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> | |
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 | ||
46 | ClassImp(AliGRPManager) | |
47 | ||
48 | //_____________________________________________________________________________ | |
49 | AliGRPManager::AliGRPManager() : | |
50 | TObject(), | |
51 | fGRPData(NULL) | |
52 | { | |
53 | // Default constructor | |
54 | } | |
55 | ||
56 | //_____________________________________________________________________________ | |
57 | AliGRPManager::~AliGRPManager() | |
58 | { | |
59 | // Destructor | |
60 | if (fGRPData) delete fGRPData; | |
61 | } | |
62 | ||
63 | //_____________________________________________________________________________ | |
64 | Bool_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 | //_____________________________________________________________________________ | |
102 | Bool_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() ) { | |
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; | |
113 | } | |
114 | else { | |
115 | AliInfo("Destroying existing B field instance!"); | |
116 | delete TGeoGlobalMagField::Instance(); | |
117 | } | |
118 | } | |
119 | // | |
120 | if (!fGRPData) { | |
121 | AliError("GRP Data is not loaded"); | |
122 | return kFALSE; | |
123 | } | |
124 | // | |
125 | // Construct the field map out of the information retrieved from GRP. | |
126 | Bool_t ok = kTRUE; | |
127 | // L3 | |
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 !"); | |
131 | ok = kFALSE; | |
132 | } | |
133 | ||
134 | Char_t l3Polarity = fGRPData->GetL3Polarity(); | |
135 | if (l3Polarity == AliGRPObject::GetInvalidChar()) { | |
136 | AliError("GRP/GRP/Data entry: missing value for the L3 polarity !"); | |
137 | ok = kFALSE; | |
138 | } | |
139 | ||
140 | // Dipole | |
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 !"); | |
144 | ok = kFALSE; | |
145 | } | |
146 | ||
147 | Char_t diPolarity = fGRPData->GetDipolePolarity(); | |
148 | if (diPolarity == AliGRPObject::GetInvalidChar()) { | |
149 | AliError("GRP/GRP/Data entry: missing value for the dipole polarity !"); | |
150 | ok = kFALSE; | |
151 | } | |
152 | ||
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 | |
158 | } | |
159 | ||
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"); | |
163 | beamEnergy = 0; | |
164 | //ok = kFALSE; // temprorary suppressed to make read cosmics data | |
165 | } | |
166 | // LHC: "multiply by 120 to get the energy in MeV" | |
167 | beamEnergy *= 0.120; | |
168 | ||
169 | // read special bits for the polarity convention and map type | |
170 | Int_t polConvention = fGRPData->IsPolarityConventionLHC() ? AliMagF::kConvLHC : AliMagF::kConvDCS2008; | |
171 | Bool_t uniformB = fGRPData->IsUniformBMap(); | |
172 | ||
173 | if (ok) { | |
174 | AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1), | |
175 | TMath::Abs(diCurrent) * (diPolarity ? -1:1), | |
176 | polConvention,uniformB,beamEnergy, beamType.Data()); | |
177 | if (fld) { | |
178 | TGeoGlobalMagField::Instance()->SetField( fld ); | |
179 | TGeoGlobalMagField::Instance()->Lock(); | |
180 | AliInfo("Running with the B field constructed out of GRP !"); | |
181 | } | |
182 | else { | |
183 | AliError("Failed to create a B field map !"); | |
184 | ok = kFALSE; | |
185 | } | |
186 | } | |
187 | else { | |
188 | AliError("B field is neither set nor constructed from GRP ! Exitig..."); | |
189 | } | |
190 | ||
191 | return ok; | |
192 | } | |
193 | ||
194 | //_____________________________________________________________________________ | |
195 | AliRunInfo* AliGRPManager::GetRunInfo() | |
196 | { | |
197 | // Constructs and returns an object | |
198 | // containing the run information | |
199 | // The user code is the owner of the object | |
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 | } | |
235 | ||
236 | //_____________________________________________________________________________ | |
237 | void AliGRPManager::SetGRPEntry(AliGRPObject* source) | |
238 | { | |
239 | // Create a GRP entry from the extrnaly provide GRP object | |
240 | // To be used by HLT to create an online GRP instance | |
241 | if (!source) return; | |
242 | if (fGRPData) delete fGRPData; | |
243 | fGRPData = new AliGRPObject(*source); | |
244 | AliInfo("Created GRP Data from external object"); | |
245 | // | |
246 | } | |
247 |