]>
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 | /* $Id$ */ | |
17 | ||
18 | //------------------------------------------------------------------------- | |
19 | // Class AliGRPPreprocessor | |
20 | // Global Run Parameters (GRP) preprocessor | |
21 | // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch | |
22 | // Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN | |
23 | // Modified: Chiara.Zampolli@cern.ch CERN | |
24 | //------------------------------------------------------------------------- | |
25 | ||
26 | #include <TChain.h> | |
27 | #include <TList.h> | |
28 | #include <TMap.h> | |
29 | #include <TObjString.h> | |
30 | #include <TGraph.h> | |
31 | ||
32 | #include <float.h> | |
33 | ||
34 | #include "AliGRPPreprocessor.h" | |
35 | #include "AliGRPObject.h" | |
36 | #include "AliDCSSensor.h" | |
37 | #include "AliSplineFit.h" | |
38 | #include "AliDCSSensorArray.h" | |
39 | #include "AliRawEventHeaderVersions.h" | |
40 | ||
41 | #include "AliTriggerConfiguration.h" | |
42 | #include "AliTriggerRunScalers.h" | |
43 | ||
44 | #include "AliCDBMetaData.h" | |
45 | #include "AliLog.h" | |
46 | ||
47 | class AliDCSValue; | |
48 | class AliShuttleInterface; | |
49 | ||
50 | // needed for ReceivePromptRecoParameters | |
51 | ||
52 | #include <TSQLServer.h> | |
53 | #include <TSQLResult.h> | |
54 | #include <TSQLRow.h> | |
55 | #include <AliCDBManager.h> | |
56 | #include <AliCDBMetaData.h> | |
57 | #include <AliCDBId.h> | |
58 | #include <AliTriggerConfiguration.h> | |
59 | ||
60 | const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required | |
61 | ||
62 | ClassImp(AliGRPPreprocessor) | |
63 | ||
64 | //_______________________________________________________________ | |
65 | ||
66 | const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook for PHYSICS runs, when beamType from DAQ logbook == NULL | |
67 | const Int_t AliGRPPreprocessor::fgknDAQLbParReduced = 7; // num parameters in the logbook for the other cases | |
68 | const Int_t AliGRPPreprocessor::fgknDCSDP = 50; // number of dcs dps | |
69 | const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps | |
70 | const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = { | |
71 | "LHCState", // missing in DCS | |
72 | "L3Polarity", | |
73 | "DipolePolarity", | |
74 | "LHCLuminosity", // missing in DCS | |
75 | "BeamIntensity", // missing in DCS | |
76 | "L3Current", | |
77 | "DipoleCurrent", | |
78 | "L3_BSF17_H1", | |
79 | "L3_BSF17_H2", | |
80 | "L3_BSF17_H3", | |
81 | "L3_BSF17_Temperature", | |
82 | "L3_BSF4_H1", | |
83 | "L3_BSF4_H2", | |
84 | "L3_BSF4_H3", | |
85 | "L3_BSF4_Temperature", | |
86 | "L3_BKF17_H1", | |
87 | "L3_BKF17_H2", | |
88 | "L3_BKF17_H3", | |
89 | "L3_BKF17_Temperature", | |
90 | "L3_BKF4_H1", | |
91 | "L3_BKF4_H2", | |
92 | "L3_BKF4_H3", | |
93 | "L3_BKF4_Temperature", | |
94 | "L3_BSF13_H1", | |
95 | "L3_BSF13_H2", | |
96 | "L3_BSF13_H3", | |
97 | "L3_BSF13_Temperature", | |
98 | "L3_BSF8_H1", | |
99 | "L3_BSF8_H2", | |
100 | "L3_BSF8_H3", | |
101 | "L3_BSF8_Temperature", | |
102 | "L3_BKF13_H1", | |
103 | "L3_BKF13_H2", | |
104 | "L3_BKF13_H3", | |
105 | "L3_BKF13_Temperature", | |
106 | "L3_BKF8_H1", | |
107 | "L3_BKF8_H2", | |
108 | "L3_BKF8_H3", | |
109 | "L3_BKF8_Temperature", | |
110 | "Dipole_Inside_H1", | |
111 | "Dipole_Inside_H2", | |
112 | "Dipole_Inside_H3", | |
113 | "Dipole_Inside_Temperature", | |
114 | "Dipole_Outside_H1", | |
115 | "Dipole_Outside_H2", | |
116 | "Dipole_Outside_H3", | |
117 | "Dipole_Outside_Temperature", | |
118 | "CavernTemperature", | |
119 | "CavernAtmosPressure", | |
120 | "SurfaceAtmosPressure" | |
121 | }; | |
122 | ||
123 | const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = { | |
124 | "L3_BSF17_H1", | |
125 | "L3_BSF17_H2", | |
126 | "L3_BSF17_H3", | |
127 | "L3_BSF17_Temperature", | |
128 | "L3_BSF4_H1", | |
129 | "L3_BSF4_H2", | |
130 | "L3_BSF4_H3", | |
131 | "L3_BSF4_Temperature", | |
132 | "L3_BKF17_H1", | |
133 | "L3_BKF17_H2", | |
134 | "L3_BKF17_H3", | |
135 | "L3_BKF17_Temperature", | |
136 | "L3_BKF4_H1", | |
137 | "L3_BKF4_H2", | |
138 | "L3_BKF4_H3", | |
139 | "L3_BKF4_Temperature", | |
140 | "L3_BSF13_H1", | |
141 | "L3_BSF13_H2", | |
142 | "L3_BSF13_H3", | |
143 | "L3_BSF13_Temperature", | |
144 | "L3_BSF8_H1", | |
145 | "L3_BSF8_H2", | |
146 | "L3_BSF8_H3", | |
147 | "L3_BSF8_Temperature", | |
148 | "L3_BKF13_H1", | |
149 | "L3_BKF13_H2", | |
150 | "L3_BKF13_H3", | |
151 | "L3_BKF13_Temperature", | |
152 | "L3_BKF8_H1", | |
153 | "L3_BKF8_H2", | |
154 | "L3_BKF8_H3", | |
155 | "L3_BKF8_Temperature", | |
156 | "Dipole_Inside_H1", | |
157 | "Dipole_Inside_H2", | |
158 | "Dipole_Inside_H3", | |
159 | "Dipole_Inside_Temperature", | |
160 | "Dipole_Outside_H1", | |
161 | "Dipole_Outside_H2", | |
162 | "Dipole_Outside_H3", | |
163 | "Dipole_Outside_Temperature", | |
164 | }; | |
165 | ||
166 | const Short_t kSensors = 48; // start index position of sensor in DCS DPs | |
167 | const Short_t kNumSensors = 2; // Number of sensors in DCS DPs | |
168 | ||
169 | const char* AliGRPPreprocessor::fgkLHCState[20] = { | |
170 | "P", "PREPARE", | |
171 | "J", "PREINJECTION", | |
172 | "I", "INJECTION", | |
173 | "F", "FILLING", | |
174 | "A", "ADJUST", | |
175 | "U", "UNSTABLE BEAMS", | |
176 | "S", "STABLE BEAMS", | |
177 | "D", "BEAM DUMP", | |
178 | "R", "RECOVER", | |
179 | "C", "PRECYCLE" | |
180 | }; | |
181 | ||
182 | const char* kppError[] = { | |
183 | "", | |
184 | "(DAQ logbook ERROR)", | |
185 | "(DAQ FXS ERROR)", | |
186 | "(Trigger Scalers not found in DCS FXS - ERROR)", | |
187 | "(DCS data points ERROR)", | |
188 | "(Trigger Configuration ERROR)", | |
189 | "(DAQ logbook ERROR determining partition of the run)" | |
190 | }; | |
191 | ||
192 | //_______________________________________________________________ | |
193 | ||
194 | AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle): | |
195 | AliPreprocessor("GRP",shuttle), fPressure(0), fmaxFloat(0), fminFloat(0),fmaxDouble(0), fminDouble(0), fmaxInt(0), fminInt(0), fmaxUInt(0), fminUInt(0) | |
196 | { | |
197 | // constructor - shuttle must be instantiated! | |
198 | ||
199 | AddRunType("COSMIC"); | |
200 | AddRunType("LASER"); | |
201 | AddRunType("PHYSICS"); | |
202 | AddRunType("CALIBRATION_BC"); | |
203 | AddRunType("CALIBRATION_CENTRAL"); | |
204 | AddRunType("CALIBRATION_EMD"); | |
205 | AddRunType("CALIBRATION_MB"); | |
206 | AddRunType("CALIBRATION_SEMICENTRAL"); | |
207 | AddRunType("CALIBRATION"); | |
208 | AddRunType("PEDESTAL"); | |
209 | AddRunType("STANDALONE"); | |
210 | AddRunType("GAIN"); | |
211 | AddRunType("NOISE"); | |
212 | AddRunType("PULSER"); | |
213 | AddRunType("STANDALONE_PULSER"); | |
214 | ||
215 | fmaxFloat = FLT_MAX; | |
216 | fminFloat = -FLT_MAX; | |
217 | fmaxDouble = DBL_MAX; | |
218 | fminDouble = -DBL_MAX; | |
219 | fmaxInt = kMaxInt; | |
220 | fminInt = kMinInt; | |
221 | fmaxUInt = kMaxUInt; | |
222 | fminUInt = 0; | |
223 | ||
224 | AliInfo(Form("Max allowed float = %6.5e",fmaxFloat)); | |
225 | AliInfo(Form("Min allowed float = %6.5e",fminFloat)); | |
226 | AliInfo(Form("Max allowed double = %6.5e",fmaxDouble)); | |
227 | AliInfo(Form("Min allowed double = %6.5e",fminDouble)); | |
228 | AliInfo(Form("Max allowed integer = %d",fmaxInt)); | |
229 | AliInfo(Form("Min allowed integer = %d",fminInt)); | |
230 | AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt)); | |
231 | AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt)); | |
232 | ||
233 | } | |
234 | ||
235 | //_______________________________________________________________ | |
236 | ||
237 | AliGRPPreprocessor::~AliGRPPreprocessor() | |
238 | { | |
239 | //destructor | |
240 | ||
241 | delete fPressure; | |
242 | } | |
243 | ||
244 | //_______________________________________________________________ | |
245 | ||
246 | void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) | |
247 | { | |
248 | // Initialize preprocessor | |
249 | ||
250 | AliPreprocessor::Initialize(run, startTime, endTime); | |
251 | ||
252 | AliInfo("Initialization of the GRP preprocessor."); | |
253 | AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery())); | |
254 | AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery())); | |
255 | TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors); | |
256 | for(Int_t j = 0; j < kNumSensors; j++) { | |
257 | AliDCSSensor * sens = new ((*array)[j])AliDCSSensor; | |
258 | sens->SetStringID(fgkDCSDataPoints[j+kSensors]); | |
259 | } | |
260 | AliInfo(Form("Pressure Entries: %d",array->GetEntries())); | |
261 | ||
262 | fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array); | |
263 | } | |
264 | ||
265 | //_______________________________________________________________ | |
266 | ||
267 | UInt_t AliGRPPreprocessor::Process(TMap* valueMap) | |
268 | { | |
269 | // process data retrieved by the Shuttle | |
270 | ||
271 | // retrieving "partition" and "detector" fields from DAQ logbook to | |
272 | // determine the partition in which the run was taken | |
273 | // the partition is used to decide how to react in case of errors for CTP | |
274 | ||
275 | TString partition = (TString)GetRunParameter("partition"); | |
276 | TString detector = (TString)GetRunParameter("detector"); | |
277 | ||
278 | AliGRPObject *grpobj = new AliGRPObject(); // object to store data | |
279 | ||
280 | //=================// | |
281 | // DAQ logbook // | |
282 | //=================// | |
283 | UInt_t error = 0; | |
284 | ||
285 | Int_t iDaqLB = ProcessDaqLB(grpobj); | |
286 | TString runType = (TString)GetRunType(); | |
287 | TString beamType = (TString)GetRunParameter("beamType"); | |
288 | //if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) { | |
289 | if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && !beamType.IsNull()) || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType.IsNull()) || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) { | |
290 | Log(Form("DAQ Logbook, successful!")); | |
291 | } else { | |
292 | Log(Form("DAQ Logbook, could not get all expected entries!!!")); | |
293 | error |= 1; | |
294 | } | |
295 | ||
296 | //=================// | |
297 | // DAQ FXS // | |
298 | //=================// | |
299 | UInt_t iDaqFxs = ProcessDaqFxs(); | |
300 | if( iDaqFxs == 0 ) { | |
301 | Log(Form("DAQ FXS, successful!")); | |
302 | } else { | |
303 | Log(Form("DAQ FXS, could not store run raw tag file!!!")); | |
304 | error |= 2; | |
305 | } | |
306 | ||
307 | //=================// | |
308 | // DCS FXS // | |
309 | //=================// | |
310 | UInt_t iDcsFxs = ProcessDcsFxs(partition, detector); | |
311 | if( iDcsFxs == 0 ) { | |
312 | Log(Form("DCS FXS, successful!")); | |
313 | } else if (iDcsFxs ==1) { | |
314 | Log(Form("DCS FXS, Could not store CTP scalers!!!")); | |
315 | error |= 4; | |
316 | } else{ | |
317 | Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data())); | |
318 | error |= 32; | |
319 | } | |
320 | ||
321 | //=================// | |
322 | // DCS data points // | |
323 | //=================// | |
324 | Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery())); | |
325 | Int_t entries = ProcessDcsDPs( valueMap, grpobj ); | |
326 | Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-4)); | |
327 | if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, LH3_BSF4_H3 are not working yet... | |
328 | Log(Form("Problem with the DCS data points!!! Only %d/%d entries found",entries,fgknDCSDP-4)); | |
329 | error |= 8; | |
330 | } else Log(Form("DCS data points, successful!")); | |
331 | ||
332 | //=======================// | |
333 | // Trigger Configuration // | |
334 | //=======================// | |
335 | ||
336 | const char * triggerConf = GetTriggerConfiguration(); | |
337 | ||
338 | if (partition.IsNull() && !detector.IsNull()){ // standalone partition | |
339 | Log("STANDALONE partition for current run, using Trigger Configuration dummy value"); | |
340 | AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig"); | |
341 | if (!cdbEntry) { | |
342 | Log(Form("No dummy CTP configuration entry found, going into error...")); | |
343 | error |= 16; | |
344 | } | |
345 | else{ | |
346 | AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject(); | |
347 | if (!runcfg){ | |
348 | Log(Form("dummy CTP config not found in OCDB entry, going into error...")); | |
349 | error |= 16; | |
350 | } | |
351 | else { | |
352 | TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun); | |
353 | runcfg->SetTitle(titleCTPcfg); | |
354 | AliCDBMetaData metaData; | |
355 | metaData.SetResponsible("Roman Lietava"); | |
356 | metaData.SetComment("CTP run configuration from dummy entry in OCDB"); | |
357 | if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) { | |
358 | Log("Unable to store the dummy CTP run configuration object to OCDB!"); | |
359 | error |= 16; | |
360 | } | |
361 | } | |
362 | } | |
363 | } | |
364 | ||
365 | else if (!partition.IsNull() && detector.IsNull()){ // global partition | |
366 | Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook"); | |
367 | if (triggerConf!= NULL) { | |
368 | Log("Found trigger configuration in DAQ logbook"); | |
369 | AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf); | |
370 | if (!runcfg) { | |
371 | Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!"); | |
372 | error |= 16; | |
373 | } | |
374 | else { | |
375 | TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun); | |
376 | runcfg->SetTitle(titleCTPcfg); | |
377 | AliCDBMetaData metaData; | |
378 | metaData.SetBeamPeriod(0); | |
379 | metaData.SetResponsible("Roman Lietava"); | |
380 | metaData.SetComment("CTP run configuration from DAQ logbook"); | |
381 | if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) { | |
382 | Log("Unable to store the CTP run configuration object to OCDB!"); | |
383 | error |= 16; | |
384 | } | |
385 | } | |
386 | } | |
387 | ||
388 | else { | |
389 | Log("Trigger configuration NULL in DAQ logbook"); | |
390 | error |= 16; | |
391 | } | |
392 | } | |
393 | ||
394 | else { | |
395 | Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data())); | |
396 | error |= 32; | |
397 | } | |
398 | ||
399 | // storing AliGRPObject in OCDB | |
400 | ||
401 | AliCDBMetaData md; | |
402 | md.SetResponsible("Chiara Zampolli"); | |
403 | md.SetComment("Output parameters from the GRP preprocessor."); | |
404 | ||
405 | Bool_t result = kTRUE; | |
406 | result = Store("GRP", "Data", grpobj, &md); | |
407 | delete grpobj; | |
408 | ||
409 | if (result && !error ) { | |
410 | Log("GRP Preprocessor Success"); | |
411 | return 0; | |
412 | } else { | |
413 | Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s", | |
414 | kppError[(error&1)?1:0], | |
415 | kppError[(error&2)?2:0], | |
416 | kppError[(error&4)?3:0], | |
417 | kppError[(error&8)?4:0], | |
418 | kppError[(error&16)?5:0], | |
419 | kppError[(error&32)?6:0] | |
420 | )); | |
421 | return error; | |
422 | } | |
423 | } | |
424 | ||
425 | //_______________________________________________________________ | |
426 | ||
427 | Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj) | |
428 | { | |
429 | //Getting the DAQ lb information | |
430 | ||
431 | time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi()); | |
432 | time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi()); | |
433 | Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof()); | |
434 | TString beamType = (TString)GetRunParameter("beamType"); | |
435 | Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi()); | |
436 | UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi()); | |
437 | TString lhcPeriod = (TString)GetRunParameter("LHCperiod"); | |
438 | TString runType = (TString)GetRunType(); | |
439 | ||
440 | UInt_t nparameter = 0; | |
441 | if (timeStart != 0){ | |
442 | grpObj->SetTimeStart(timeStart); | |
443 | Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart)); | |
444 | nparameter++; | |
445 | } | |
446 | else { | |
447 | Log(Form("Start time not put in logbook, setting to invalid in GRP entry!")); | |
448 | } | |
449 | ||
450 | if (timeEnd != 0){ | |
451 | grpObj->SetTimeEnd(timeEnd); | |
452 | Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd)); | |
453 | nparameter++; | |
454 | } | |
455 | else { | |
456 | Log(Form("End time not put in logbook, setting to invalid in GRP entry!")); | |
457 | } | |
458 | ||
459 | if (beamEnergy != 0){ | |
460 | grpObj->SetBeamEnergy(beamEnergy); | |
461 | Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy)); | |
462 | //if ((runType == "PHYSICS" && beamType!="Cosmics")){ | |
463 | if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run | |
464 | nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL | |
465 | } | |
466 | } | |
467 | else { | |
468 | //if ((runType == "PHYSICS" && beamType!="Cosmics")){ | |
469 | if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run | |
470 | Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, and producing an error (beamType = %s, runType = %s)",beamType.Data(), runType.Data())); | |
471 | } | |
472 | else{ | |
473 | Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, but not producing any error (beamType = NULL, runType = %s)", runType.Data())); | |
474 | } | |
475 | } | |
476 | ||
477 | ||
478 | if (beamType.Length() != 0){ | |
479 | grpObj->SetBeamType(beamType); | |
480 | Log(Form("Beam Type for run %d: %s",fRun, beamType.Data())); | |
481 | nparameter++; | |
482 | } | |
483 | else { | |
484 | Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run")); | |
485 | nparameter++; | |
486 | } | |
487 | ||
488 | if (numberOfDetectors != 0){ | |
489 | grpObj->SetNumberOfDetectors(numberOfDetectors); | |
490 | Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors)); | |
491 | nparameter++; | |
492 | } | |
493 | else { | |
494 | Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!")); | |
495 | } | |
496 | ||
497 | if (detectorMask != 0){ | |
498 | grpObj->SetDetectorMask(detectorMask); | |
499 | Log(Form("Detector Mask for run %d: %d",fRun, detectorMask)); | |
500 | nparameter++; | |
501 | } | |
502 | else { | |
503 | Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!")); | |
504 | } | |
505 | ||
506 | if (lhcPeriod.Length() != 0) { | |
507 | grpObj->SetLHCPeriod(lhcPeriod); | |
508 | Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data())); | |
509 | nparameter++; | |
510 | } | |
511 | else { | |
512 | Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!")); | |
513 | } | |
514 | if (runType.Length() != 0) { | |
515 | grpObj->SetRunType(runType); | |
516 | Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data())); | |
517 | nparameter++; | |
518 | } | |
519 | else { | |
520 | Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!")); | |
521 | } | |
522 | ||
523 | return nparameter; | |
524 | } | |
525 | ||
526 | //_______________________________________________________________ | |
527 | ||
528 | UInt_t AliGRPPreprocessor::ProcessDaqFxs() | |
529 | { | |
530 | //======DAQ FXS======// | |
531 | ||
532 | AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix | |
533 | TList* list = GetFileSources(kDAQ); | |
534 | if (!list) { | |
535 | Log("No raw data tag list: connection problems with DAQ FXS logbook!"); | |
536 | return 1; | |
537 | } | |
538 | ||
539 | if (list->GetEntries() == 0) { | |
540 | Log("no raw data tags in this run: nothing to merge!"); | |
541 | delete list; list=0; | |
542 | return 0; | |
543 | } | |
544 | ||
545 | TChain *fRawTagChain = new TChain("T"); | |
546 | Int_t nFiles=0; | |
547 | TIterator* iter = list->MakeIterator(); | |
548 | TObject* obj = 0; | |
549 | while ((obj = iter->Next())) { | |
550 | TObjString* objStr = dynamic_cast<TObjString*> (obj); | |
551 | if (objStr) { | |
552 | Log(Form("Found source %s", objStr->String().Data())); | |
553 | TList* list2 = GetFileIDs(kDAQ, objStr->String()); | |
554 | if (!list2) { | |
555 | Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!"); | |
556 | delete fRawTagChain; fRawTagChain=0; | |
557 | return 1; | |
558 | } | |
559 | Log(Form("Number of ids: %d",list2->GetEntries())); | |
560 | for(Int_t i = 0; i < list2->GetEntries(); i++) { | |
561 | TObjString *idStr = (TObjString *)list2->At(i); | |
562 | TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data()); | |
563 | if (fileName.Length() > 0) { | |
564 | Log(Form("Adding file in the chain: %s",fileName.Data())); | |
565 | fRawTagChain->Add(fileName.Data()); | |
566 | nFiles++; | |
567 | } else { | |
568 | Log(Form("Could not retrieve file with id %s from source %s: " | |
569 | "connection problems with DAQ FXS!", | |
570 | idStr->String().Data(), objStr->String().Data())); | |
571 | delete list; list=0; | |
572 | delete list2; list2=0; | |
573 | delete fRawTagChain; fRawTagChain=0; | |
574 | return 2; | |
575 | } | |
576 | } | |
577 | delete list2; | |
578 | } | |
579 | } | |
580 | ||
581 | TString fRawDataFileName = "GRP_Merged.tag.root"; | |
582 | Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data())); | |
583 | ||
584 | if( fRawTagChain->Merge(fRawDataFileName) < 1 ) { | |
585 | Log("Error merging raw data files!!!"); | |
586 | return 3; | |
587 | } | |
588 | ||
589 | TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun); | |
590 | Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data()); | |
591 | ||
592 | if (!result) { | |
593 | Log("Problem storing raw data tags in local file!!!"); | |
594 | } else { | |
595 | Log("Raw data tags merged successfully!!"); | |
596 | } | |
597 | ||
598 | delete iter; | |
599 | delete list; | |
600 | delete fRawTagChain; fRawTagChain=0; | |
601 | ||
602 | if (result == kFALSE) { | |
603 | return 4; | |
604 | } | |
605 | ||
606 | return 0; | |
607 | ||
608 | } | |
609 | ||
610 | //_______________________________________________________________ | |
611 | UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector) | |
612 | { | |
613 | ||
614 | // processing the info | |
615 | // stored in the DCS FXS | |
616 | // coming from the trigger | |
617 | ||
618 | // Get the CTP counters information | |
619 | ||
620 | if (partition.IsNull() && !detector.IsNull()){ // standalone partition | |
621 | Log("STANDALONE partition for current run, using Trigger Scalers dummy value"); | |
622 | AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers"); | |
623 | if (!cdbEntry) { | |
624 | Log(Form("No dummy CTP scalers entry found, going into error...")); | |
625 | return 1; | |
626 | } | |
627 | else{ | |
628 | AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject(); | |
629 | if (!scalers){ | |
630 | Log(Form("CTP dummy scalers not found in OCDB entry, going into error...")); | |
631 | return 1; | |
632 | } | |
633 | else { | |
634 | AliCDBMetaData metaData; | |
635 | metaData.SetResponsible("Roman Lietava"); | |
636 | metaData.SetComment("CTP scalers from dummy entry in OCDB"); | |
637 | if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) { | |
638 | Log("Unable to store the dummy CTP scalers object to OCDB!"); | |
639 | return 1; | |
640 | } | |
641 | } | |
642 | } | |
643 | } | |
644 | ||
645 | else if (!partition.IsNull() && detector.IsNull()){ // global partition | |
646 | Log("GLOBAL partition for current run, using CTP scalers from DCS FXS"); | |
647 | TString countersfile = GetFile(kDCS, "CTP_xcounters",""); | |
648 | if (countersfile.IsNull()) { | |
649 | Log("No CTP counters files has been found: empty source!"); | |
650 | return 1; | |
651 | } | |
652 | else { | |
653 | Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data())); | |
654 | AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile); | |
655 | if (!scalers) { | |
656 | Log("Bad CTP counters file! The corresponding CDB entry will not be filled!"); | |
657 | return 1; | |
658 | } | |
659 | else { | |
660 | AliCDBMetaData metaData; | |
661 | metaData.SetBeamPeriod(0); | |
662 | metaData.SetResponsible("Roman Lietava"); | |
663 | metaData.SetComment("CTP scalers"); | |
664 | if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) { | |
665 | Log("Unable to store the CTP scalers object to OCDB!"); | |
666 | return 1; | |
667 | } | |
668 | } | |
669 | } | |
670 | } | |
671 | ||
672 | ||
673 | else{ | |
674 | Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data())); | |
675 | return 2; | |
676 | } | |
677 | ||
678 | return 0; | |
679 | ||
680 | } | |
681 | //_______________________________________________________________ | |
682 | ||
683 | Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj) | |
684 | { | |
685 | ||
686 | // | |
687 | // processing DCS DPs | |
688 | // | |
689 | ||
690 | Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not | |
691 | Int_t nLHCEntries = 0; | |
692 | Int_t nL3Entries = 0; | |
693 | Int_t nDipoleEntries = 0; | |
694 | Int_t nEnvEntries = 0; | |
695 | Int_t nHallProbesEntries = 0; | |
696 | nLHCEntries = ProcessLHCDPs(valueMap, grpObj); | |
697 | nL3Entries = ProcessL3DPs(valueMap, grpObj); | |
698 | nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj); | |
699 | nEnvEntries = ProcessEnvDPs(valueMap, grpObj); | |
700 | nHallProbesEntries = ProcessHPDPs(valueMap, grpObj); | |
701 | grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention | |
702 | entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries; | |
703 | return entries; | |
704 | ||
705 | } | |
706 | ||
707 | //_______________________________________________________________ | |
708 | ||
709 | Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj) | |
710 | { | |
711 | ||
712 | // processing DPs | |
713 | // related to | |
714 | // L3 info | |
715 | ||
716 | Int_t nL3Entries = 0; | |
717 | TObjArray *array = 0x0; | |
718 | Int_t indexDP = -1; | |
719 | Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change | |
720 | ||
721 | AliInfo(Form("==========L3Current===========")); | |
722 | Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range | |
723 | indexDP = kL3Current; | |
724 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
725 | if(!array) { | |
726 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
727 | } | |
728 | else { | |
729 | if (array->GetEntries() == 0){ | |
730 | AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP])); | |
731 | } | |
732 | else { | |
733 | Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero); | |
734 | if (floatDCS != NULL){ | |
735 | grpObj->SetL3Current(floatDCS); | |
736 | } | |
737 | else{ | |
738 | outOfRange = kTRUE; | |
739 | } | |
740 | if (floatDCS){ | |
741 | delete[] floatDCS; | |
742 | floatDCS = 0x0; | |
743 | } | |
744 | } | |
745 | if (!outOfRange) nL3Entries++; | |
746 | } | |
747 | ||
748 | if (array) array = 0x0; | |
749 | ||
750 | AliInfo(Form("==========L3Polarity===========")); | |
751 | indexDP = kL3Polarity; | |
752 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
753 | if(!array) { | |
754 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
755 | } | |
756 | else { | |
757 | if (array->GetEntries() == 0){ | |
758 | AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP])); | |
759 | } | |
760 | else { | |
761 | Bool_t change = kFALSE; | |
762 | Char_t charDCS = ProcessBool(array,change); | |
763 | if (change == kFALSE){ | |
764 | grpObj->SetL3Polarity(charDCS); | |
765 | AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity()))); | |
766 | nL3Entries++; | |
767 | } | |
768 | else if (isZero){ | |
769 | AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP])); | |
770 | nL3Entries++; | |
771 | } | |
772 | else { | |
773 | AliError(Form("%s value changed within the run, while the magnet was ON (according to the current), setting it to invalid and considering the DP as wrong",fgkDCSDataPoints[indexDP])); | |
774 | } | |
775 | } | |
776 | } | |
777 | ||
778 | return nL3Entries; | |
779 | ||
780 | } | |
781 | //_______________________________________________________________ | |
782 | ||
783 | Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj) | |
784 | { | |
785 | // processing DPs | |
786 | // related to | |
787 | // the Dipole info | |
788 | ||
789 | Int_t nDipoleEntries = 0; | |
790 | TObjArray *array = 0x0; | |
791 | Int_t indexDP = -1; | |
792 | Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change | |
793 | ||
794 | AliInfo(Form("==========DipoleCurrent===========")); | |
795 | Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range | |
796 | indexDP = kDipoleCurrent; | |
797 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
798 | if(!array) { | |
799 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
800 | } | |
801 | else { | |
802 | if (array->GetEntries() == 0){ | |
803 | AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP])); | |
804 | } | |
805 | else { | |
806 | Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero); | |
807 | if (floatDCS != NULL){ | |
808 | grpObj->SetDipoleCurrent(floatDCS); | |
809 | } | |
810 | else{ | |
811 | outOfRange=kTRUE; | |
812 | } | |
813 | if (floatDCS){ | |
814 | delete[] floatDCS; | |
815 | floatDCS = 0x0; | |
816 | } | |
817 | } | |
818 | if (!outOfRange) nDipoleEntries++; | |
819 | } | |
820 | ||
821 | if (array) array = 0x0; | |
822 | ||
823 | AliInfo(Form("==========DipolePolarity===========")); | |
824 | indexDP = kDipolePolarity; | |
825 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
826 | if(!array) { | |
827 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
828 | } | |
829 | else { | |
830 | if (array->GetEntries() == 0){ | |
831 | AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP])); | |
832 | } | |
833 | else { | |
834 | Bool_t change = kFALSE; | |
835 | Char_t charDCS = ProcessBool(array,change); | |
836 | if (!change){ | |
837 | grpObj->SetDipolePolarity(charDCS); | |
838 | AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity()))); | |
839 | nDipoleEntries++; | |
840 | } | |
841 | else if (isZero){ | |
842 | AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP])); | |
843 | nDipoleEntries++; | |
844 | } | |
845 | else{ | |
846 | AliError(Form("%s value changed within the run while the magnet was ON (according to the current), setting it to invalid and considering the DP as wrong", fgkDCSDataPoints[indexDP])); | |
847 | } | |
848 | } | |
849 | } | |
850 | ||
851 | return nDipoleEntries; | |
852 | ||
853 | } | |
854 | //_______________________________________________________________ | |
855 | ||
856 | Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj) | |
857 | { | |
858 | // processing DPs | |
859 | // related to | |
860 | // evironment conditions (temperature, pressure) info | |
861 | ||
862 | Int_t nEnvEntries = 0; | |
863 | TObjArray *array = 0x0; | |
864 | Int_t indexDP = -1; | |
865 | ||
866 | AliInfo(Form("==========CavernTemperature===========")); | |
867 | Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range | |
868 | indexDP = kCavernTemperature; | |
869 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
870 | if(!array) { | |
871 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
872 | } | |
873 | else { | |
874 | if (array->GetEntries() == 0){ | |
875 | AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP])); | |
876 | } | |
877 | else { | |
878 | Float_t *floatDCS = ProcessFloatAll(array); | |
879 | if (floatDCS != NULL){ | |
880 | grpObj->SetCavernTemperature(floatDCS); | |
881 | } | |
882 | else{ | |
883 | outOfRange = kTRUE; | |
884 | } | |
885 | if (floatDCS){ | |
886 | delete[] floatDCS; | |
887 | floatDCS = 0x0; | |
888 | } | |
889 | } | |
890 | if (!outOfRange) nEnvEntries++; | |
891 | } | |
892 | ||
893 | if (array) array = 0x0; | |
894 | ||
895 | AliInfo(Form("==========AtmosPressures (Cavern + Surface)===========")); | |
896 | AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap); | |
897 | dcsSensorArray->Print(); | |
898 | if( fPressure->NumFits()==0 ) { | |
899 | Log("Problem with the pressure sensor values!!!"); | |
900 | } | |
901 | else { | |
902 | AliInfo(Form("==========CavernAtmosPressure===========")); | |
903 | indexDP = kCavernAtmosPressure; | |
904 | AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]); | |
905 | AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2)); | |
906 | if( sensorCavernP2->GetFit() ) { | |
907 | Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun)); | |
908 | grpObj->SetCavernAtmosPressure(sensorCavernP2); | |
909 | nEnvEntries++; | |
910 | } | |
911 | //if (sensorP2) delete sensorP2; | |
912 | else { | |
913 | Log(Form("ERROR Sensor Fit for %s not found ", fgkDCSDataPoints[indexDP] )); | |
914 | } | |
915 | AliInfo(Form("==========SurfaceAtmosPressure===========")); | |
916 | indexDP = kSurfaceAtmosPressure; | |
917 | AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]); | |
918 | AliDebug(2,Form("sensorP2 = %p", sensorP2)); | |
919 | if( sensorP2->GetFit() ) { | |
920 | Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun)); | |
921 | grpObj->SetSurfaceAtmosPressure(sensorP2); | |
922 | nEnvEntries++; | |
923 | } | |
924 | //if (sensorP2) delete sensorP2; | |
925 | else { | |
926 | Log(Form("ERROR Sensor Fit for %s not found ", fgkDCSDataPoints[indexDP] )); | |
927 | } | |
928 | ||
929 | } | |
930 | ||
931 | return nEnvEntries; | |
932 | } | |
933 | //_______________________________________________________________ | |
934 | ||
935 | Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj) | |
936 | { | |
937 | // processing DPs | |
938 | // related to | |
939 | // Hall Probes info | |
940 | ||
941 | Int_t nHPEntries = 0; | |
942 | TObjArray *array = 0x0; | |
943 | Int_t indexDP = -1; | |
944 | Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range | |
945 | ||
946 | if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){ | |
947 | AliError(Form("Number of Hall probes expected in GRP Preprocessor (i.e. %d) different from number of Hall Probes foreseen in GRP object (i.e. %d). Looping on entries from GRP object anyway.", fgknDCSDPHallProbes, AliGRPObject::GetNumberOfHP())); | |
948 | } | |
949 | for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){ | |
950 | outOfRange = kFALSE; // resetting outOfRange flag at each HP | |
951 | AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP))); | |
952 | array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP)); | |
953 | if(!array) { | |
954 | Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP))); | |
955 | } | |
956 | else { | |
957 | if (array->GetEntries() == 0){ | |
958 | AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP))); | |
959 | } | |
960 | else { | |
961 | Float_t *floatDCS = ProcessFloatAll(array); | |
962 | if (floatDCS != NULL){ | |
963 | AliDebug(2,Form("value[0] = %f, value[1] = %f, value[2] = %f, value[3] = %f, value[4] = %f",floatDCS[0],floatDCS[1],floatDCS[2],floatDCS[3],floatDCS[4])); | |
964 | grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS); | |
965 | for (Int_t kk = 0 ; kk< 5; kk++){ | |
966 | AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk))); | |
967 | } | |
968 | } | |
969 | else{ | |
970 | outOfRange = kTRUE; | |
971 | } | |
972 | if (floatDCS){ | |
973 | delete[] floatDCS; | |
974 | floatDCS = 0x0; | |
975 | } | |
976 | } | |
977 | if (!outOfRange) nHPEntries++; | |
978 | } | |
979 | } | |
980 | ||
981 | Log(Form("Hall Probes = %d ", nHPEntries)); | |
982 | return nHPEntries; | |
983 | } | |
984 | ||
985 | //_______________________________________________________________ | |
986 | ||
987 | Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj) | |
988 | { | |
989 | ||
990 | // | |
991 | // processing of LHC related DCS DPs, i.e.: | |
992 | // LHCState | |
993 | // LHCLuminosity | |
994 | // BeamIntensity | |
995 | // | |
996 | ||
997 | Int_t nLHCEntries = 0; | |
998 | TObjArray *array = 0x0; | |
999 | Int_t indexDP = -1; | |
1000 | ||
1001 | AliInfo(Form("==========LHCState===========")); | |
1002 | indexDP = kLHCState; | |
1003 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
1004 | if(!array) { | |
1005 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
1006 | } | |
1007 | else { | |
1008 | if (array->GetEntries() == 0){ | |
1009 | AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP])); | |
1010 | } | |
1011 | else { | |
1012 | TString stringDCS = ProcessChar(array); | |
1013 | if (stringDCS.Length()!=0) { | |
1014 | Bool_t found = kFALSE; | |
1015 | for( Int_t i=0; i<20; i+=2 ) { | |
1016 | if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) { | |
1017 | stringDCS = fgkLHCState[i+1]; | |
1018 | found = kTRUE; | |
1019 | break; | |
1020 | } | |
1021 | } | |
1022 | if (found){ | |
1023 | Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data())); | |
1024 | grpObj->SetLHCState(stringDCS); | |
1025 | } | |
1026 | else{ | |
1027 | Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP])); | |
1028 | grpObj->SetLHCState(AliGRPObject::GetInvalidString()); | |
1029 | } | |
1030 | } | |
1031 | else { | |
1032 | Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP])); | |
1033 | grpObj->SetLHCState(AliGRPObject::GetInvalidString()); | |
1034 | } | |
1035 | } | |
1036 | nLHCEntries++; | |
1037 | } | |
1038 | ||
1039 | if (array) array = 0x0; | |
1040 | ||
1041 | AliInfo(Form("==========LHCLuminosity===========")); | |
1042 | Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range | |
1043 | indexDP = kLHCLuminosity; | |
1044 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
1045 | if(!array) { | |
1046 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
1047 | } | |
1048 | else { | |
1049 | if (array->GetEntries() == 0){ | |
1050 | AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP])); | |
1051 | } | |
1052 | else { | |
1053 | Float_t *floatDCS = ProcessFloatAll(array); | |
1054 | if (floatDCS != NULL){ | |
1055 | grpObj->SetLHCLuminosity(floatDCS); | |
1056 | AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]); | |
1057 | grpObj->SetLHCLuminositySplineFit(splfit); | |
1058 | // delete splfit; | |
1059 | } | |
1060 | else { | |
1061 | outOfRange = kTRUE; | |
1062 | } | |
1063 | if (floatDCS){ | |
1064 | delete[] floatDCS; | |
1065 | floatDCS = 0x0; | |
1066 | } | |
1067 | } | |
1068 | if (!outOfRange) nLHCEntries++; | |
1069 | } | |
1070 | ||
1071 | if (array) array = 0x0; | |
1072 | ||
1073 | AliInfo(Form("==========BeamIntensity===========")); | |
1074 | if (outOfRange) outOfRange = kFALSE; // resetting outOfRange if needed | |
1075 | indexDP = kBeamIntensity; | |
1076 | array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]); | |
1077 | if(!array) { | |
1078 | Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP])); | |
1079 | } | |
1080 | else { | |
1081 | if (array->GetEntries() == 0){ | |
1082 | AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP])); | |
1083 | } | |
1084 | else { | |
1085 | Float_t *floatDCS = ProcessFloatAll(array); | |
1086 | if (floatDCS != NULL){ | |
1087 | grpObj->SetBeamIntensity(floatDCS); | |
1088 | AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]); | |
1089 | grpObj->SetBeamIntensitySplineFit(splfit1); | |
1090 | //delete splfit; | |
1091 | } | |
1092 | else{ | |
1093 | outOfRange = kTRUE; | |
1094 | } | |
1095 | if (floatDCS){ | |
1096 | delete[] floatDCS; | |
1097 | floatDCS = 0x0; | |
1098 | } | |
1099 | } | |
1100 | if (!outOfRange) nLHCEntries++; | |
1101 | } | |
1102 | ||
1103 | return nLHCEntries; | |
1104 | } | |
1105 | //_________________________________________________________________________ | |
1106 | ||
1107 | AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){ | |
1108 | ||
1109 | ||
1110 | // | |
1111 | // returning Spline Fit | |
1112 | // | |
1113 | ||
1114 | Int_t entriesarray = array->GetEntries(); | |
1115 | Float_t* value = new Float_t[entriesarray]; | |
1116 | Float_t* time = new Float_t[entriesarray]; | |
1117 | AliDCSValue* v = 0x0; | |
1118 | for (Int_t iarray = 0; iarray < entriesarray; iarray++){ | |
1119 | v = (AliDCSValue*)array->At(iarray); | |
1120 | value[iarray] = v->GetFloat(); | |
1121 | time[iarray] = v->GetTimeStamp(); | |
1122 | AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray])); | |
1123 | } | |
1124 | TGraph* gr = new TGraph(entriesarray,value,time); | |
1125 | if (!gr ) { | |
1126 | AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data())); | |
1127 | return NULL; | |
1128 | } | |
1129 | AliSplineFit *fit = new AliSplineFit(); | |
1130 | fit->SetMinPoints(10); | |
1131 | fit->InitKnots(gr,10,10,0.0); | |
1132 | fit->SplineFit(2); | |
1133 | fit->Cleanup(); | |
1134 | if (!fit) { | |
1135 | AliWarning(Form("%s: no fit performed",stringID.Data())); | |
1136 | return NULL; | |
1137 | } | |
1138 | return fit; | |
1139 | } | |
1140 | ||
1141 | //_________________________________________________________________________ | |
1142 | ||
1143 | TString AliGRPPreprocessor::ProcessChar(const TObjArray *array) | |
1144 | { | |
1145 | ||
1146 | // | |
1147 | // processing char | |
1148 | // | |
1149 | ||
1150 | TString aDCSString=""; | |
1151 | ||
1152 | AliDCSValue *v = 0x0; | |
1153 | for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) { | |
1154 | v = (AliDCSValue *)array->At(iCount); | |
1155 | if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) { | |
1156 | AliError(Form("DCS values for the parameter outside the queried interval")); | |
1157 | continue; | |
1158 | } | |
1159 | if (iCount > 0) { | |
1160 | if (aDCSString != v->GetChar()) | |
1161 | AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar())); | |
1162 | } | |
1163 | aDCSString = (TString)v->GetChar(); // keeping always last value in the array | |
1164 | } | |
1165 | return aDCSString; | |
1166 | } | |
1167 | ||
1168 | //__________________________________________________________________________________________________________________ | |
1169 | ||
1170 | Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array) | |
1171 | { | |
1172 | // | |
1173 | // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median | |
1174 | // | |
1175 | // parameters[0] = mean | |
1176 | // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean | |
1177 | // parameters[2] = median | |
1178 | // parameters[3] = standard deviation wrt mean | |
1179 | // parameters[4] = standard deviation wrt median | |
1180 | // | |
1181 | ||
1182 | Float_t* parameters = new Float_t[5]; | |
1183 | Double_t aDCSArrayMean = 0; // Mean | |
1184 | Double_t aDCSArrayTruncMean = 0;// Truncated Mean | |
1185 | Double_t aDCSArrayMedian = 0; // Median | |
1186 | Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean | |
1187 | Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median | |
1188 | Float_t aDCSArraySum = 0.0; | |
1189 | Int_t iCounts = 0; | |
1190 | Int_t iCounts1 = 0; | |
1191 | Float_t temp = 0; | |
1192 | Float_t temp1 = 0; | |
1193 | Int_t nCounts = array->GetEntries(); | |
1194 | Float_t *tempArray = new Float_t[nCounts]; | |
1195 | for(Int_t i = 0; i < nCounts; i++) { | |
1196 | AliDCSValue *v = (AliDCSValue *)array->At(i); | |
1197 | if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) { | |
1198 | AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat())); | |
1199 | if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat)); | |
1200 | if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat)); | |
1201 | return NULL; | |
1202 | } | |
1203 | if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) { | |
1204 | aDCSArraySum += v->GetFloat(); | |
1205 | tempArray[i] = v->GetFloat(); | |
1206 | AliDebug(2,Form("%d-th entry = %f",i,tempArray[i])); | |
1207 | iCounts += 1; | |
1208 | } | |
1209 | else { | |
1210 | AliError(Form("DCS values for the parameter outside the queried interval")); | |
1211 | } | |
1212 | } | |
1213 | ||
1214 | AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts)); | |
1215 | if(iCounts != 0) { | |
1216 | aDCSArrayMean = TMath::Mean(iCounts,tempArray); | |
1217 | aDCSArrayMedian = TMath::Median(iCounts,tempArray); | |
1218 | aDCSArraySDMean = TMath::RMS(iCounts,tempArray); | |
1219 | AliDebug(2,Form("SD = %f",aDCSArraySDMean)); | |
1220 | // computing standard deviation wrt median | |
1221 | AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean)); | |
1222 | for (Int_t i = 0; i < iCounts; i++){ | |
1223 | AliDCSValue *v = (AliDCSValue *)array->At(i); | |
1224 | AliDebug(3,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean)); | |
1225 | AliDebug(3,Form("%i-th entry = %f",i, v->GetFloat())); | |
1226 | if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){ | |
1227 | temp1+=v->GetFloat(); | |
1228 | iCounts1++; | |
1229 | AliDebug(3,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1)); | |
1230 | } | |
1231 | temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian); | |
1232 | } | |
1233 | AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts)); | |
1234 | temp/=iCounts; | |
1235 | AliDebug(3,Form("temp after the ratio = %f", temp)); | |
1236 | if (temp>0) { | |
1237 | aDCSArraySDMedian = TMath::Sqrt(temp); | |
1238 | } | |
1239 | else if (temp==0) { | |
1240 | AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero....")); | |
1241 | aDCSArraySDMedian = 0; | |
1242 | } | |
1243 | else{ | |
1244 | AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid....")); | |
1245 | aDCSArraySDMedian = AliGRPObject::GetInvalidFloat(); | |
1246 | } | |
1247 | } | |
1248 | else { | |
1249 | aDCSArrayMean = AliGRPObject::GetInvalidFloat(); | |
1250 | aDCSArrayMedian = AliGRPObject::GetInvalidFloat(); | |
1251 | aDCSArraySDMean = AliGRPObject::GetInvalidFloat(); | |
1252 | } | |
1253 | AliDebug(3,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1)); | |
1254 | if (iCounts1 > 0) { | |
1255 | aDCSArrayTruncMean = temp1/iCounts1; | |
1256 | } | |
1257 | else{ | |
1258 | aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat(); | |
1259 | } | |
1260 | ||
1261 | ||
1262 | ||
1263 | AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean)); | |
1264 | AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1)); | |
1265 | AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian)); | |
1266 | AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean)); | |
1267 | AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian)); | |
1268 | ||
1269 | parameters[0] = aDCSArrayMean; | |
1270 | parameters[1] = aDCSArrayTruncMean; | |
1271 | parameters[2] = aDCSArrayMedian; | |
1272 | parameters[3] = aDCSArraySDMean; | |
1273 | parameters[4] = aDCSArraySDMedian; | |
1274 | ||
1275 | AliDebug(2,Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4])); | |
1276 | //AliInfo(Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4])); | |
1277 | ||
1278 | return parameters; | |
1279 | } | |
1280 | ||
1281 | ||
1282 | ||
1283 | //__________________________________________________________________________________________________________________ | |
1284 | ||
1285 | Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero) | |
1286 | { | |
1287 | // | |
1288 | // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median | |
1289 | // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON | |
1290 | // the flag is set according to the L3/Dipole current value | |
1291 | // current threshold for L3 = 350 A (value provided by DCS) | |
1292 | // current threshold for Dipole = 450 A (value provided by DCS) | |
1293 | // | |
1294 | // parameters[0] = mean | |
1295 | // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean | |
1296 | // parameters[2] = median | |
1297 | // parameters[3] = standard deviation wrt mean | |
1298 | // parameters[4] = standard deviation wrt median | |
1299 | // | |
1300 | ||
1301 | AliInfo(Form("indexDP = %d",indexDP)); | |
1302 | Float_t* parameters = new Float_t[5]; | |
1303 | Double_t aDCSArrayMean = 0; // Mean | |
1304 | Double_t aDCSArrayTruncMean = 0;// Truncated Mean | |
1305 | Double_t aDCSArrayMedian = 0; // Median | |
1306 | Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean | |
1307 | Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median | |
1308 | Float_t aDCSArraySum = 0.0; | |
1309 | Int_t iCounts = 0; | |
1310 | Int_t iCounts1 = 0; | |
1311 | Float_t temp = 0; | |
1312 | Float_t temp1 = 0; | |
1313 | Int_t nCounts = array->GetEntries(); | |
1314 | Float_t *tempArray = new Float_t[nCounts]; | |
1315 | for(Int_t i = 0; i < nCounts; i++) { | |
1316 | AliDCSValue *v = (AliDCSValue *)array->At(i); | |
1317 | if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) { | |
1318 | AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat())); | |
1319 | if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat)); | |
1320 | if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat)); | |
1321 | return NULL; | |
1322 | } | |
1323 | if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) { | |
1324 | aDCSArraySum += v->GetFloat(); | |
1325 | tempArray[i] = v->GetFloat(); | |
1326 | AliDebug(2,Form("%d-th entry = %f",i,tempArray[i])); | |
1327 | iCounts += 1; | |
1328 | if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE; | |
1329 | if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE; | |
1330 | } | |
1331 | else { | |
1332 | AliError(Form("DCS values for the parameter outside the queried interval")); | |
1333 | } | |
1334 | } | |
1335 | ||
1336 | AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts)); | |
1337 | if(iCounts != 0) { | |
1338 | aDCSArrayMean = TMath::Mean(iCounts,tempArray); | |
1339 | aDCSArrayMedian = TMath::Median(iCounts,tempArray); | |
1340 | aDCSArraySDMean = TMath::RMS(iCounts,tempArray); | |
1341 | AliDebug(2,Form("SD = %f",aDCSArraySDMean)); | |
1342 | // computing standard deviation wrt median | |
1343 | AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean)); | |
1344 | for (Int_t i = 0; i < iCounts; i++){ | |
1345 | AliDCSValue *v = (AliDCSValue *)array->At(i); | |
1346 | AliDebug(3,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean)); | |
1347 | AliDebug(3,Form("%i-th entry = %f",i, v->GetFloat())); | |
1348 | if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){ | |
1349 | temp1+=v->GetFloat(); | |
1350 | iCounts1++; | |
1351 | AliDebug(3,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1)); | |
1352 | } | |
1353 | temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian); | |
1354 | } | |
1355 | AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts)); | |
1356 | temp/=iCounts; | |
1357 | AliDebug(3,Form("temp after the ratio = %f", temp)); | |
1358 | if (temp>0) { | |
1359 | aDCSArraySDMedian = TMath::Sqrt(temp); | |
1360 | } | |
1361 | else if (temp==0) { | |
1362 | AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero....")); | |
1363 | aDCSArraySDMedian = 0; | |
1364 | } | |
1365 | else{ | |
1366 | AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid....")); | |
1367 | aDCSArraySDMedian = AliGRPObject::GetInvalidFloat(); | |
1368 | } | |
1369 | } | |
1370 | else { | |
1371 | aDCSArrayMean = AliGRPObject::GetInvalidFloat(); | |
1372 | aDCSArrayMedian = AliGRPObject::GetInvalidFloat(); | |
1373 | aDCSArraySDMean = AliGRPObject::GetInvalidFloat(); | |
1374 | } | |
1375 | AliDebug(3,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1)); | |
1376 | if (iCounts1 > 0) { | |
1377 | aDCSArrayTruncMean = temp1/iCounts1; | |
1378 | } | |
1379 | else{ | |
1380 | aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat(); | |
1381 | } | |
1382 | ||
1383 | ||
1384 | ||
1385 | AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean)); | |
1386 | AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1)); | |
1387 | AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian)); | |
1388 | AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean)); | |
1389 | AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian)); | |
1390 | ||
1391 | parameters[0] = aDCSArrayMean; | |
1392 | parameters[1] = aDCSArrayTruncMean; | |
1393 | parameters[2] = aDCSArrayMedian; | |
1394 | parameters[3] = aDCSArraySDMean; | |
1395 | parameters[4] = aDCSArraySDMedian; | |
1396 | ||
1397 | AliDebug(2,Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4])); | |
1398 | //AliInfo(Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4])); | |
1399 | ||
1400 | return parameters; | |
1401 | } | |
1402 | ||
1403 | ||
1404 | //_______________________________________________________________ | |
1405 | ||
1406 | Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change) | |
1407 | { | |
1408 | // | |
1409 | // processing Boolean values | |
1410 | // | |
1411 | ||
1412 | Bool_t aDCSBool = kTRUE; | |
1413 | ||
1414 | AliDCSValue *v = 0x0; | |
1415 | ||
1416 | for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) { | |
1417 | v = (AliDCSValue *)array->At(iCount); | |
1418 | if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) { | |
1419 | AliError(Form("DCS values for the parameter outside the queried interval")); | |
1420 | continue; | |
1421 | } | |
1422 | if (iCount > 0) { | |
1423 | if (aDCSBool != v->GetBool()) { | |
1424 | AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool())); | |
1425 | change = kTRUE; | |
1426 | } | |
1427 | } | |
1428 | aDCSBool = v->GetBool(); // always keeping last value | |
1429 | AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool)); | |
1430 | } | |
1431 | ||
1432 | Char_t caDCSBool = (Char_t) aDCSBool; | |
1433 | return caDCSBool; | |
1434 | ||
1435 | } | |
1436 | ||
1437 | //_______________________________________________________________ | |
1438 | ||
1439 | Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array) | |
1440 | { | |
1441 | // | |
1442 | // processing Int values, returning mean | |
1443 | // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values | |
1444 | // are outside the queried time interval or their value is out of range | |
1445 | // | |
1446 | ||
1447 | Float_t aDCSArraySum = 0.0; | |
1448 | Float_t aDCSArrayMean = 0.0; | |
1449 | Int_t iCounts = 0; | |
1450 | AliDCSValue* v = 0x0; | |
1451 | ||
1452 | for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) { | |
1453 | v = (AliDCSValue *)array->At(iCount); | |
1454 | if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) { | |
1455 | AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",iCount, v->GetInt())); | |
1456 | return AliGRPObject::GetInvalidFloat(); | |
1457 | } | |
1458 | if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) { | |
1459 | aDCSArraySum += v->GetInt(); | |
1460 | iCounts += 1; | |
1461 | } | |
1462 | } | |
1463 | ||
1464 | if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts; | |
1465 | else aDCSArrayMean = AliGRPObject::GetInvalidFloat(); | |
1466 | ||
1467 | return aDCSArrayMean; | |
1468 | ||
1469 | } | |
1470 | //_______________________________________________________________ | |
1471 | ||
1472 | Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array) | |
1473 | { | |
1474 | // | |
1475 | // processing Int values, returning mean | |
1476 | // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values | |
1477 | // are outside the queried time interval or their value is out of range | |
1478 | // | |
1479 | ||
1480 | Float_t aDCSArraySum = 0.0; | |
1481 | Float_t aDCSArrayMean = 0.0; | |
1482 | Int_t iCounts = 0; | |
1483 | AliDCSValue* v = 0x0; | |
1484 | ||
1485 | for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) { | |
1486 | v = (AliDCSValue *)array->At(iCount); | |
1487 | if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) { | |
1488 | AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",iCount,v->GetUInt())); | |
1489 | return AliGRPObject::GetInvalidFloat(); | |
1490 | } | |
1491 | if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) { | |
1492 | aDCSArraySum += v->GetUInt(); | |
1493 | iCounts += 1; | |
1494 | } | |
1495 | } | |
1496 | ||
1497 | if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts; | |
1498 | else aDCSArrayMean = AliGRPObject::GetInvalidFloat(); | |
1499 | ||
1500 | return aDCSArrayMean; | |
1501 | ||
1502 | } | |
1503 | ||
1504 | ||
1505 | //_______________________________________________________________ | |
1506 | ||
1507 | AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap) | |
1508 | { | |
1509 | // extract DCS pressure maps. Perform fits to save space | |
1510 | ||
1511 | TMap *map = fPressure->ExtractDCS(dcsAliasMap); | |
1512 | if (map) { | |
1513 | fPressure->MakeSplineFit(map); | |
1514 | Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors(); | |
1515 | if (fitFraction > kFitFraction ) { | |
1516 | AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits())); | |
1517 | } else { | |
1518 | AliInfo("Too few pressure maps fitted!!!"); | |
1519 | } | |
1520 | } else { | |
1521 | AliInfo("no atmospheric pressure map extracted!!!"); | |
1522 | } | |
1523 | delete map; | |
1524 | ||
1525 | return fPressure; | |
1526 | } | |
1527 | ||
1528 | ||
1529 | ||
1530 | //_______________________________________________________________ | |
1531 | Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* dbHost, Int_t dbPort, const char* dbName, const char* user, const char* password, const char *cdbRoot, TString &gdc) | |
1532 | { | |
1533 | // | |
1534 | // Retrieves logbook and trigger information from the online logbook | |
1535 | // This information is needed for prompt reconstruction | |
1536 | // | |
1537 | // Parameters are: | |
1538 | // Run number | |
1539 | // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable | |
1540 | // cdbRoot | |
1541 | // | |
1542 | // returns: | |
1543 | // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE | |
1544 | // 0 on success and no run was found | |
1545 | // negative on error | |
1546 | // | |
1547 | // This function is NOT called during the preprocessor run in the Shuttle! | |
1548 | // | |
1549 | ||
1550 | // defaults | |
1551 | if (dbPort == 0) | |
1552 | dbPort = 3306; | |
1553 | ||
1554 | // CDB connection | |
1555 | AliCDBManager* cdb = AliCDBManager::Instance(); | |
1556 | cdb->SetDefaultStorage(cdbRoot); | |
1557 | ||
1558 | // SQL connection | |
1559 | TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password); | |
1560 | ||
1561 | if (!server) | |
1562 | { | |
1563 | Printf("ERROR: Could not connect to DAQ LB"); | |
1564 | return -1; | |
1565 | } | |
1566 | ||
1567 | // main logbook | |
1568 | TString sqlQuery; | |
1569 | sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run); | |
1570 | TSQLResult* result = server->Query(sqlQuery); | |
1571 | if (!result) | |
1572 | { | |
1573 | Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data()); | |
1574 | return -2; | |
1575 | } | |
1576 | ||
1577 | if (result->GetRowCount() == 0) | |
1578 | { | |
1579 | Printf("ERROR: Run %d not found", run); | |
1580 | delete result; | |
1581 | return -3; | |
1582 | } | |
1583 | ||
1584 | TSQLRow* row = result->Next(); | |
1585 | if (!row) | |
1586 | { | |
1587 | Printf("ERROR: Could not receive data from run %d", run); | |
1588 | delete result; | |
1589 | return -4; | |
1590 | } | |
1591 | ||
1592 | TString timeStartString(row->GetField(0)); | |
1593 | TString runType(row->GetField(1)); | |
1594 | TString detectorMaskString(row->GetField(2)); | |
1595 | TString l3CurrentString(row->GetField(3)); | |
1596 | TString dipoleCurrentString(row->GetField(4)); | |
1597 | time_t timeStart = (time_t)(timeStartString.Atoi()); | |
1598 | UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi()); | |
1599 | Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof())); | |
1600 | Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof())); | |
1601 | Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0; | |
1602 | Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0; | |
1603 | ||
1604 | AliGRPObject * grpObj = new AliGRPObject(); | |
1605 | grpObj->SetTimeStart(timeStart); | |
1606 | grpObj->SetRunType((TString)(row->GetField(1))); | |
1607 | grpObj->SetDetectorMask(detectorMask); | |
1608 | grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0); | |
1609 | grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0); | |
1610 | grpObj->SetL3Polarity(l3Polarity); | |
1611 | grpObj->SetDipolePolarity(dipolePolarity); | |
1612 | ||
1613 | delete row; | |
1614 | row = 0; | |
1615 | ||
1616 | delete result; | |
1617 | result = 0; | |
1618 | ||
1619 | Printf("Storing GRP/GRP/Data object with the following content"); | |
1620 | grpObj->Dump(); | |
1621 | ||
1622 | AliCDBMetaData metadata; | |
1623 | metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli"); | |
1624 | metadata.SetComment("GRP Output parameters received during online running"); | |
1625 | ||
1626 | AliCDBId id("GRP/GRP/Data", run, run); | |
1627 | Bool_t success = cdb->Put(grpObj, id, &metadata); | |
1628 | ||
1629 | delete grpObj; | |
1630 | ||
1631 | if (!success) | |
1632 | { | |
1633 | Printf("ERROR: Could not store GRP/GRP/Data into OCDB"); | |
1634 | return -5; | |
1635 | } | |
1636 | ||
1637 | // Receive trigger information | |
1638 | sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run); | |
1639 | result = server->Query(sqlQuery); | |
1640 | if (!result) | |
1641 | { | |
1642 | Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data()); | |
1643 | return -11; | |
1644 | } | |
1645 | ||
1646 | if (result->GetRowCount() == 0) | |
1647 | { | |
1648 | Printf("ERROR: Run %d not found in logbook_trigger_config", run); | |
1649 | delete result; | |
1650 | return -12; | |
1651 | } | |
1652 | ||
1653 | row = result->Next(); | |
1654 | if (!row) | |
1655 | { | |
1656 | Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run); | |
1657 | delete result; | |
1658 | return -13; | |
1659 | } | |
1660 | ||
1661 | TString triggerConfig(row->GetField(0)); | |
1662 | ||
1663 | delete row; | |
1664 | row = 0; | |
1665 | ||
1666 | delete result; | |
1667 | result = 0; | |
1668 | ||
1669 | Printf("Found trigger configuration: %s", triggerConfig.Data()); | |
1670 | ||
1671 | AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig); | |
1672 | if (!runcfg) | |
1673 | { | |
1674 | Printf("ERROR: Could not create CTP configuration object"); | |
1675 | return -14; | |
1676 | } | |
1677 | ||
1678 | metadata.SetComment("CTP run configuration received during online running"); | |
1679 | ||
1680 | AliCDBId id2("GRP/CTP/Config", run, run); | |
1681 | success = cdb->Put(runcfg, id2, &metadata); | |
1682 | ||
1683 | delete runcfg; | |
1684 | runcfg = 0; | |
1685 | ||
1686 | if (!success) | |
1687 | { | |
1688 | Printf("ERROR: Could not store GRP/CTP/Config into OCDB"); | |
1689 | return -15; | |
1690 | } | |
1691 | ||
1692 | ||
1693 | // Receive list of GDCs for this run | |
1694 | sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run); | |
1695 | result = server->Query(sqlQuery); | |
1696 | if (!result) | |
1697 | { | |
1698 | Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data()); | |
1699 | return -24; | |
1700 | } | |
1701 | ||
1702 | if (result->GetRowCount() == 0) | |
1703 | { | |
1704 | Printf("ERROR: Run %d not found in logbook_stats_GDC", run); | |
1705 | delete result; | |
1706 | return -25; | |
1707 | } | |
1708 | ||
1709 | gdc = ""; | |
1710 | for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) { | |
1711 | row = result->Next(); | |
1712 | if (!row) | |
1713 | { | |
1714 | Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run); | |
1715 | delete result; | |
1716 | return -26; | |
1717 | } | |
1718 | gdc += row->GetField(0); | |
1719 | gdc += " "; | |
1720 | } | |
1721 | ||
1722 | delete row; | |
1723 | row = 0; | |
1724 | ||
1725 | delete result; | |
1726 | result = 0; | |
1727 | ||
1728 | Printf("Found GDC: %s", gdc.Data()); | |
1729 | ||
1730 | // get last run with same run type that was already processed by the SHUTTLE | |
1731 | ||
1732 | sqlQuery.Form("SELECT max(logbook.run) FROM logbook LEFT JOIN logbook_shuttle ON logbook_shuttle.run = logbook.run WHERE run_type = '%s' AND shuttle_done = 1", runType.Data()); | |
1733 | result = server->Query(sqlQuery); | |
1734 | if (!result) | |
1735 | { | |
1736 | Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data()); | |
1737 | return -21; | |
1738 | } | |
1739 | ||
1740 | if (result->GetRowCount() == 0) | |
1741 | { | |
1742 | Printf("ERROR: No result with query <%s>", sqlQuery.Data()); | |
1743 | delete result; | |
1744 | return -22; | |
1745 | } | |
1746 | ||
1747 | row = result->Next(); | |
1748 | if (!row) | |
1749 | { | |
1750 | Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data()); | |
1751 | delete result; | |
1752 | return -23; | |
1753 | } | |
1754 | ||
1755 | TString lastRunStr(row->GetField(0)); | |
1756 | Int_t lastRun = lastRunStr.Atoi(); | |
1757 | ||
1758 | Printf("Last run with same run type %s is %d", runType.Data(), lastRun); | |
1759 | ||
1760 | delete row; | |
1761 | row = 0; | |
1762 | ||
1763 | delete result; | |
1764 | result = 0; | |
1765 | ||
1766 | server->Close(); | |
1767 | delete server; | |
1768 | server = 0; | |
1769 | ||
1770 | return lastRun; | |
1771 | } |