]>
Commit | Line | Data |
---|---|---|
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 | ||
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() ) { | |
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 | // | |
f6e611f0 | 120 | if (!fGRPData) { |
121 | AliError("GRP Data is not loaded"); | |
122 | return kFALSE; | |
123 | } | |
124 | // | |
5a004fb4 | 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 | } | |
0c976228 | 133 | |
5a004fb4 | 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 | } | |
5a004fb4 | 166 | |
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(); | |
170 | ||
171 | if (ok) { | |
33fe5eb1 | 172 | AliMagF* fld = AliMagF::CreateFieldMap(TMath::Abs(l3Current) * (l3Polarity ? -1:1), |
173 | TMath::Abs(diCurrent) * (diPolarity ? -1:1), | |
174 | polConvention,uniformB,beamEnergy, beamType.Data()); | |
175 | if (fld) { | |
176 | TGeoGlobalMagField::Instance()->SetField( fld ); | |
177 | TGeoGlobalMagField::Instance()->Lock(); | |
178 | AliInfo("Running with the B field constructed out of GRP !"); | |
179 | } | |
180 | else { | |
5a004fb4 | 181 | AliError("Failed to create a B field map !"); |
182 | ok = kFALSE; | |
10c2f85a | 183 | } |
10c2f85a | 184 | } |
5a004fb4 | 185 | else { |
186 | AliError("B field is neither set nor constructed from GRP ! Exitig..."); | |
187 | } | |
188 | ||
189 | return ok; | |
10c2f85a | 190 | } |
191 | ||
192 | //_____________________________________________________________________________ | |
193 | AliRunInfo* AliGRPManager::GetRunInfo() | |
194 | { | |
195 | // Constructs and returns an object | |
196 | // containing the run information | |
197 | // The user code is the owner of the object | |
198 | ||
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"; | |
203 | } | |
204 | ||
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"; | |
209 | } | |
210 | ||
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"); | |
214 | beamEnergy = 0; | |
215 | } | |
216 | // energy is provided in MeV*120 | |
217 | beamEnergy /= 120E3; | |
218 | ||
219 | TString runType = fGRPData->GetRunType(); | |
220 | if (runType==AliGRPObject::GetInvalidString()) { | |
221 | AliError("GRP/GRP/Data entry: missing value for the run type ! Using UNKNOWN"); | |
222 | runType = "UNKNOWN"; | |
223 | } | |
224 | ||
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; | |
229 | } | |
230 | ||
231 | return new AliRunInfo(lhcState, beamType, beamEnergy, runType, activeDetectors); | |
232 | } | |
f6e611f0 | 233 | |
234 | //_____________________________________________________________________________ | |
235 | void AliGRPManager::SetGRPEntry(AliGRPObject* source) | |
236 | { | |
237 | // Create a GRP entry from the extrnaly provide GRP object | |
238 | // To be used by HLT to create an online GRP instance | |
239 | if (!source) return; | |
240 | if (fGRPData) delete fGRPData; | |
241 | fGRPData = new AliGRPObject(*source); | |
242 | AliInfo("Created GRP Data from external object"); | |
243 | // | |
244 | } | |
245 |