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