]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEER/AliGRPPreprocessor.cxx
Not mentioning explicitly DCS when errors come from missing LHC Data or CTP scalres...
[u/mrichter/AliRoot.git] / STEER / STEER / AliGRPPreprocessor.cxx
CommitLineData
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>
c5340e82 30#include <TObjArray.h>
44e45fac 31#include <TGraph.h>
c5340e82 32#include <TString.h>
6a150f83 33#include <TFile.h>
ef6fb101 34#include <TPRegexp.h>
7ca4655f 35
fe726709 36#include <float.h>
37
3dedb44a 38#include "AliGRPPreprocessor.h"
44e45fac 39#include "AliGRPObject.h"
40#include "AliDCSSensor.h"
41#include "AliSplineFit.h"
17984b61 42#include "AliDCSSensorArray.h"
ea4a87ee 43#include "AliRawEventHeaderVersions.h"
3dedb44a 44
48b1b444 45#include "AliTriggerConfiguration.h"
46#include "AliTriggerRunScalers.h"
6ecb073a 47#include "AliTriggerInput.h"
48b1b444 48
3dedb44a 49#include "AliCDBMetaData.h"
6a150f83 50#include "AliESDVertex.h"
0254e751 51#include "AliLHCReader.h"
52#include "AliLHCData.h"
53#include "AliDCSArray.h"
6ecb073a 54#include "AliDAQ.h"
55#include "AliLTUConfig.h"
59fef0d0 56#include "AliQAThresholds.h"
3dedb44a 57
ac152fdd 58class AliLog;
3dedb44a 59class AliDCSValue;
60class AliShuttleInterface;
61
1e27bb6b 62// needed for ReceivePromptRecoParameters
39e3007b 63
1e27bb6b 64#include <TSQLServer.h>
65#include <TSQLResult.h>
66#include <TSQLRow.h>
67#include <AliCDBManager.h>
68#include <AliCDBMetaData.h>
69#include <AliCDBId.h>
26fd9395 70#include <AliTriggerConfiguration.h>
d54ad8d4 71#include "AliCTPTimeParams.h"
72#include "AliLHCClockPhase.h"
1e27bb6b 73
eae7586f 74ClassImp(AliGRPPreprocessor)
17984b61 75
ef6fb101 76
eae7586f 77const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
3dedb44a 78
17984b61 79//_______________________________________________________________
44e45fac 80
e3a2ac48 81 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 6; // num parameters in the logbook used to fill the GRP object
0254e751 82 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
39e3007b 83 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
26fd9395 84 const Int_t AliGRPPreprocessor::fgknLHCDP = 9; // number of dcs dps from LHC data
4bb7c769 85 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
9fae6417 86 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
e7a6790f 87 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
e7a6790f 88 "L3Polarity",
89 "DipolePolarity",
e7a6790f 90 "L3Current",
91 "DipoleCurrent",
44e45fac 92 "L3_BSF17_H1",
93 "L3_BSF17_H2",
94 "L3_BSF17_H3",
95 "L3_BSF17_Temperature",
96 "L3_BSF4_H1",
97 "L3_BSF4_H2",
98 "L3_BSF4_H3",
99 "L3_BSF4_Temperature",
100 "L3_BKF17_H1",
101 "L3_BKF17_H2",
102 "L3_BKF17_H3",
103 "L3_BKF17_Temperature",
104 "L3_BKF4_H1",
105 "L3_BKF4_H2",
106 "L3_BKF4_H3",
107 "L3_BKF4_Temperature",
108 "L3_BSF13_H1",
109 "L3_BSF13_H2",
110 "L3_BSF13_H3",
111 "L3_BSF13_Temperature",
112 "L3_BSF8_H1",
113 "L3_BSF8_H2",
114 "L3_BSF8_H3",
115 "L3_BSF8_Temperature",
116 "L3_BKF13_H1",
117 "L3_BKF13_H2",
118 "L3_BKF13_H3",
119 "L3_BKF13_Temperature",
120 "L3_BKF8_H1",
121 "L3_BKF8_H2",
122 "L3_BKF8_H3",
123 "L3_BKF8_Temperature",
124 "Dipole_Inside_H1",
125 "Dipole_Inside_H2",
126 "Dipole_Inside_H3",
127 "Dipole_Inside_Temperature",
128 "Dipole_Outside_H1",
129 "Dipole_Outside_H2",
130 "Dipole_Outside_H3",
131 "Dipole_Outside_Temperature",
e7a6790f 132 "CavernTemperature",
133 "CavernAtmosPressure",
ce996d13 134 "SurfaceAtmosPressure",
3343d11b 135 "CavernAtmosPressure2"
e7a6790f 136 };
44e45fac 137
39e3007b 138 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
44e45fac 139 "L3_BSF17_H1",
140 "L3_BSF17_H2",
141 "L3_BSF17_H3",
142 "L3_BSF17_Temperature",
143 "L3_BSF4_H1",
144 "L3_BSF4_H2",
145 "L3_BSF4_H3",
146 "L3_BSF4_Temperature",
147 "L3_BKF17_H1",
148 "L3_BKF17_H2",
149 "L3_BKF17_H3",
150 "L3_BKF17_Temperature",
151 "L3_BKF4_H1",
152 "L3_BKF4_H2",
153 "L3_BKF4_H3",
154 "L3_BKF4_Temperature",
155 "L3_BSF13_H1",
156 "L3_BSF13_H2",
157 "L3_BSF13_H3",
158 "L3_BSF13_Temperature",
159 "L3_BSF8_H1",
160 "L3_BSF8_H2",
161 "L3_BSF8_H3",
162 "L3_BSF8_Temperature",
163 "L3_BKF13_H1",
164 "L3_BKF13_H2",
165 "L3_BKF13_H3",
166 "L3_BKF13_Temperature",
167 "L3_BKF8_H1",
168 "L3_BKF8_H2",
169 "L3_BKF8_H3",
170 "L3_BKF8_Temperature",
171 "Dipole_Inside_H1",
172 "Dipole_Inside_H2",
173 "Dipole_Inside_H3",
174 "Dipole_Inside_Temperature",
175 "Dipole_Outside_H1",
176 "Dipole_Outside_H2",
177 "Dipole_Outside_H3",
3343d11b 178 "Dipole_Outside_Temperature"
44e45fac 179 };
e7a6790f 180
0254e751 181 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
ce996d13 182 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
183
e7a6790f 184
0254e751 185 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
5fb8d1a1 186 "LHC_Beam_Energy",
187 "LHC_MachineMode",
188 "LHC_BeamMode",
da0e365e 189 "LHC_Beams_Particle_Type",
190 "BPTX_Phase_Shift_B1",
53b0ec45 191 "BPTX_Phase_Shift_B2",
192 "LHC_Particle_Type_B1",
26fd9395 193 "LHC_Particle_Type_B2",
194 "LHC_Data_Quality_Flag"
0254e751 195 };
e07d2728 196
e7a6790f 197 const char* kppError[] = {
198 "",
199 "(DAQ logbook ERROR)",
200 "(DAQ FXS ERROR)",
aab08fd4 201 "(Trigger Scalers not found in FXS - ERROR)",
7e1a6c0b 202 "(DCS data points ERROR)",
e75e6e01 203 "(Trigger Configuration ERROR)",
6614fa48 204 "(DAQ logbook ERROR determining partition of the run)",
6a150f83 205 "(CTP timing ERROR)",
0254e751 206 "(SPD Mean Vertex ERROR)",
aab08fd4 207 "(FXS Error for LHC Data)",
da0e365e 208 "(LHC Data Error)",
6ecb073a 209 "(LHC Clock Phase Error (from LHC Data))",
efec19bd 210 "(LTU Configuration Error)",
211 "(DQM Failure)"
e7a6790f 212 };
17984b61 213
3dedb44a 214//_______________________________________________________________
44e45fac 215
3dedb44a 216AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
c5340e82 217 AliPreprocessor("GRP",shuttle), fPressure(0), fmaxFloat(0), fminFloat(0),fmaxDouble(0), fminDouble(0), fmaxInt(0), fminInt(0), fmaxUInt(0), fminUInt(0),fdaqStartEndTimeOk(kTRUE),ffailedDPs(new TObjArray(fgknDCSDP))
e7a6790f 218{
44e45fac 219 // constructor - shuttle must be instantiated!
ad103e84 220
7eaa854b 221 AddRunType("COSMIC");
222 AddRunType("LASER");
44e45fac 223 AddRunType("PHYSICS");
c2ad5069 224 AddRunType("CALIBRATION_BC");
225 AddRunType("CALIBRATION_CENTRAL");
226 AddRunType("CALIBRATION_EMD");
227 AddRunType("CALIBRATION_MB");
228 AddRunType("CALIBRATION_SEMICENTRAL");
69bf9b19 229 AddRunType("CALIBRATION");
230 AddRunType("PEDESTAL");
7be24dea 231 AddRunType("STANDALONE");
232 AddRunType("GAIN");
3242245e 233 AddRunType("NOISE");
234 AddRunType("PULSER");
b7a928fe 235 AddRunType("STANDALONE_PULSER");
52439816 236 AddRunType("STANDALONE_BC");
fe726709 237
238 fmaxFloat = FLT_MAX;
239 fminFloat = -FLT_MAX;
240 fmaxDouble = DBL_MAX;
241 fminDouble = -DBL_MAX;
242 fmaxInt = kMaxInt;
243 fminInt = kMinInt;
244 fmaxUInt = kMaxUInt;
245 fminUInt = 0;
246
247 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
248 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
249 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
250 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
251 AliInfo(Form("Max allowed integer = %d",fmaxInt));
252 AliInfo(Form("Min allowed integer = %d",fminInt));
253 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
254 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
255
c5340e82 256 ffailedDPs->SetOwner(kTRUE);
3dedb44a 257}
258
259//_______________________________________________________________
44e45fac 260
e7a6790f 261AliGRPPreprocessor::~AliGRPPreprocessor()
262{
44e45fac 263 //destructor
264
265 delete fPressure;
c5340e82 266 delete ffailedDPs;
267
3dedb44a 268}
269
270//_______________________________________________________________
44e45fac 271
e7a6790f 272void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
273{
ce996d13 274 // Initialize preprocessor
17984b61 275
ce996d13 276 AliPreprocessor::Initialize(run, startTime, endTime);
277
278 AliInfo("Initialization of the GRP preprocessor.");
279 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
280 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
281 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
282 for(Int_t j = 0; j < kNumSensors; j++) {
283 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
284 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
285 }
286 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
287
288 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
c5340e82 289
00ea8709 290 ffailedDPs->Clear(); // cleaning ffailedDPs for current run
c5340e82 291 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
292 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
293 ffailedDPs->AddAt(dp,iDP);
294 }
295
3dedb44a 296}
297
298//_______________________________________________________________
44e45fac 299
e7a6790f 300UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
301{
44e45fac 302 // process data retrieved by the Shuttle
303
e75e6e01 304 // retrieving "partition" and "detector" fields from DAQ logbook to
305 // determine the partition in which the run was taken
306 // the partition is used to decide how to react in case of errors for CTP
307
308 TString partition = (TString)GetRunParameter("partition");
309 TString detector = (TString)GetRunParameter("detector");
310
44e45fac 311 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
5cf76849 312 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
0254e751 313
44e45fac 314 //=================//
315 // DAQ logbook //
316 //=================//
e3a2ac48 317
318 Log("*************** Processing DAQ logbook");
319
44e45fac 320 UInt_t error = 0;
321
e75e6e01 322 Int_t iDaqLB = ProcessDaqLB(grpobj);
323 TString runType = (TString)GetRunType();
324 TString beamType = (TString)GetRunParameter("beamType");
e3a2ac48 325 if(iDaqLB == fgknDAQLbPar) {
326 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
e75e6e01 327 } else {
e3a2ac48 328 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
e75e6e01 329 error |= 1;
330 }
44e45fac 331
332 //=================//
333 // DAQ FXS //
334 //=================//
e3a2ac48 335
336 Log("*************** Processing DAQ FXS");
337
44e45fac 338 UInt_t iDaqFxs = ProcessDaqFxs();
339 if( iDaqFxs == 0 ) {
340 Log(Form("DAQ FXS, successful!"));
341 } else {
342 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
343 error |= 2;
344 }
345
346 //=================//
347 // DCS FXS //
348 //=================//
e3a2ac48 349
350 Log("*************** Processing DCS FXS");
351
e75e6e01 352 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
44e45fac 353 if( iDcsFxs == 0 ) {
354 Log(Form("DCS FXS, successful!"));
e75e6e01 355 } else if (iDcsFxs ==1) {
aab08fd4 356 Log(Form("Could not store CTP scalers!!!"));
44e45fac 357 error |= 4;
e75e6e01 358 } else{
359 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
360 error |= 32;
44e45fac 361 }
362
363 //=================//
364 // DCS data points //
365 //=================//
e3a2ac48 366
367 Log("*************** Processing DCS DPs");
368
7e6f5523 369 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
44e45fac 370 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
9fae6417 371 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
5fbf7677 372 if (fdaqStartEndTimeOk){
9fae6417 373 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
374 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
c5340e82 375 Log(Form("The DPs giving problems were:"));
376 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
377 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
378 if (dpString){
379 TString name = dpString->String();
9fae6417 380 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
c5340e82 381 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
382 }
383 else {
384 Log(Form(" %s is not present, but was not generating any error since it is not ready in DCS - check the other DPs in this list!",name.Data()));
385 }
386 }
387 }
5fbf7677 388 error |= 8;
389 }
390 else Log(Form("DCS data points, successful!"));
391 }
392 else Log(Form("Statistical values for DCS DPs could not be computed due to missing DAQ_time_start and DAQ_time_end fields in DAQ logbook"));
44e45fac 393
394 //=======================//
395 // Trigger Configuration //
396 //=======================//
e75e6e01 397
e3a2ac48 398 Log("*************** Processing Trigger Configuration");
399
44e45fac 400 const char * triggerConf = GetTriggerConfiguration();
e75e6e01 401
402 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
403 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
404 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
405 if (!cdbEntry) {
406 Log(Form("No dummy CTP configuration entry found, going into error..."));
44e45fac 407 error |= 16;
408 }
e75e6e01 409 else{
410 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
411 if (!runcfg){
412 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
44e45fac 413 error |= 16;
414 }
e75e6e01 415 else {
416 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
417 runcfg->SetTitle(titleCTPcfg);
418 AliCDBMetaData metaData;
419 metaData.SetResponsible("Roman Lietava");
420 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
421 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
422 Log("Unable to store the dummy CTP run configuration object to OCDB!");
423 error |= 16;
424 }
425 }
44e45fac 426 }
427 }
a453acbf 428
e75e6e01 429 else if (!partition.IsNull() && detector.IsNull()){ // global partition
430 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
431 if (triggerConf!= NULL) {
432 Log("Found trigger configuration in DAQ logbook");
433 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
44e45fac 434 if (!runcfg) {
e75e6e01 435 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
436 error |= 16;
44e45fac 437 }
438 else {
e75e6e01 439 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
44e45fac 440 runcfg->SetTitle(titleCTPcfg);
441 AliCDBMetaData metaData;
442 metaData.SetBeamPeriod(0);
443 metaData.SetResponsible("Roman Lietava");
e75e6e01 444 metaData.SetComment("CTP run configuration from DAQ logbook");
44e45fac 445 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
446 Log("Unable to store the CTP run configuration object to OCDB!");
447 error |= 16;
448 }
449 }
450 }
e75e6e01 451
452 else {
453 Log("Trigger configuration NULL in DAQ logbook");
454 error |= 16;
455 }
456 }
457
458 else {
459 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
460 error |= 32;
44e45fac 461 }
e75e6e01 462
6614fa48 463 //===========================//
464 // Trigger Timing Parameters //
465 //===========================//
466
e3a2ac48 467 Log("*************** Processing Trigger Time Params");
6614fa48 468
469 const char * triggerCTPtiming = GetCTPTimeParams();
470
471 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
472 Log("STANDALONE partition for current run, using CTP timing params dummy value");
473 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
474 if (!cdbEntry) {
475 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
476 error |= 64;
477 }
478 else{
479 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
480 if (!runCTPtiming){
481 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
482 error |= 64;
483 }
484 else {
485 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
486 runCTPtiming->SetTitle(titleCTPtiming);
487 AliCDBMetaData metadata;
488 metadata.SetResponsible("Roman Lietava");
489 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
490 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
491 Log("Unable to store the dummy CTP timing params object to OCDB!");
492 error |= 64;
493 }
494 }
495 }
496 }
497
498 else if (!partition.IsNull() && detector.IsNull()){ // global partition
499 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
500 if (triggerCTPtiming!= NULL) {
501 Log("Found trigger timing params in DAQ logbook");
502 AliDebug(2,Form("%s",triggerCTPtiming));
dd5ac86b 503 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
6614fa48 504 if (!runCTPtiming) {
505 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
506 error |= 64;
507 }
508 else {
509 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
510 runCTPtiming->SetTitle(titleCTPtiming);
511 AliCDBMetaData metadata;
512 metadata.SetBeamPeriod(0);
513 metadata.SetResponsible("Roman Lietava");
514 metadata.SetComment("CTP timing params from DAQ logbook");
515 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
516 Log("Unable to store the CTP timing params object to OCDB!");
517 error |= 64;
518 }
519 }
520 }
521
522 else {
523 Log("Trigger timing params NULL in DAQ logbook");
524 error |= 64;
525 }
526 }
527
528 else {
529 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
530 error |= 32;
531 }
e75e6e01 532
6ecb073a 533 //===========================//
534 // LTU Configuration //
535 //===========================//
536
537 Log("*************** Processing LTU Configuration");
538
539 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
6ecb073a 540 Log("STANDALONE partition for current run, using LTU configuration dummy value");
541 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
542 if (!cdbEntry) {
543 Log(Form("No dummy LTU Config entry found, going into error..."));
544 error |= 2048;
545 }
546 else{
547 TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
548 if (!ltuConfig){
549 Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
550 error |= 2048;
551 }
552 else {
553 AliCDBMetaData metadata;
554 metadata.SetResponsible("Roman Lietava");
555 metadata.SetComment("LTU Config from dummy entry in OCDB");
556 if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
557 Log("Unable to store the dummy LTU Config object to OCDB!");
558 error |= 2048;
559 }
560 }
561 }
6ecb073a 562 }
563
564 else if (!partition.IsNull() && detector.IsNull()){ // global partition
565
566 Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
567 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
568 Printf ("detectormask = %d",detectorMask);
569 TObjArray * ltuarray = new TObjArray();
570 ltuarray->SetOwner(1);
571 Bool_t isLTUok = kTRUE;
572 for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
573 if ((detectorMask >> i) & 0x1) {
574 TString det = AliDAQ::OfflineModuleName(i);
575 TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
f3ada855 576 if (detCTPName == "CTP") {
577 detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors
578 Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
579 continue;
580 }
6ecb073a 581 Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
582 TString* ltu = GetLTUConfig(detCTPName.Data());
583 if (!ltu){
584 Log(Form("No LTU Configuration from DAQ logbook for detector %s (BUT it was expected)! The corresponding CDB entry will not be filled!",detCTPName.Data()));
585 error |= 2048;
586 isLTUok = kFALSE;
587 break;
588 }
589 else{
590 Float_t ltuFineDelay1 = ltu[0].Atof();
591 Float_t ltuFineDelay2 = ltu[1].Atof();
592 Float_t ltuBCDelayAdd = ltu[2].Atof();
593 const char* name = AliDAQ::DetectorName(i);
594 AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
595 ltuarray->AddAtAndExpand(ltuConfig,i);
596 }
597 }
598 }
599 if (isLTUok){
600 AliCDBMetaData metadata;
601 metadata.SetBeamPeriod(0);
602 metadata.SetResponsible("Roman Lietava");
603 metadata.SetComment("LTU Configuration for current run");
604 if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
605 Log("Unable to store the LTU Config object to OCDB!");
606 error |= 2048;
607 }
608 }
24f67180 609 delete ltuarray;
6ecb073a 610 }
611
612 else {
613 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
614 error |= 32;
615 }
616
0254e751 617
618 //=================//
619 // LHC Data //
620 //=================//
621
e07d2728 622 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
623 Log("*************** Processing LHC Data");
624
625 UInt_t iLHCData = ProcessLHCData(grpobj);
626
627 if( iLHCData == 0 ) {
aab08fd4 628 Log(Form("LHC Data from FXS, successful!"));
e07d2728 629 } else if (iLHCData == 1) {
aab08fd4 630 Log(Form("LHC Data, problems with FXS!"));
e07d2728 631 error |= 256;
da0e365e 632 } else if (iLHCData == 2) {
633 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
634 error |= 512;
e07d2728 635 } else if (iLHCData ==3){
da0e365e 636 Log(Form("Problems in storing LHC Phase - going into Error"));
637 error |= 1024;
e07d2728 638 } else if (iLHCData ==4){
da0e365e 639 Log(Form("Problems with LHC Phase - going into Error"));
640 error |= 1024;
e07d2728 641 } else{
642 Log(Form("LHC Data problems"));
643 error |= 512;
644 }
44e45fac 645
e07d2728 646 }
647
6a150f83 648 //==================//
649 // SPD Mean Vertex //
650 //==================//
e3a2ac48 651
652 Log("*************** Processing SPD Mean Vertex");
653
62d2c16a 654 if (runType == "PHYSICS"){
655 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
656 if( iSPDMeanVertex == 1 ) {
657 Log(Form("SPD Mean Vertex, successful!"));
658 } else {
659 Log(Form("SPD Mean Vertex failed!!!"));
660 error |= 128;
661 }
6a150f83 662 }
62d2c16a 663 else {
664 Log("SPD Mean Vertex not processed since runType != PHYSICS");
665 }
666
efec19bd 667 //=================//
668 // DQM FXS //
669 //=================//
670
671 Log("*************** Processing DQM FXS");
672
673 UInt_t iDqmFxs = ProcessDqmFxs();
674 if( iDqmFxs == 1 ) {
675 Log(Form("DQM FXS, successful!"));
676 } else {
677 Log(Form("DQM FXS failed!!!"));
678 error |= 4096;
679 }
680
0254e751 681 // storing AliGRPObject in OCDB
682
683 AliCDBMetaData md;
684 md.SetResponsible("Chiara Zampolli");
685 md.SetComment("Output parameters from the GRP preprocessor.");
686
687 Bool_t result = kTRUE;
688 result = Store("GRP", "Data", grpobj, &md);
689 delete grpobj;
690
44e45fac 691 if (result && !error ) {
692 Log("GRP Preprocessor Success");
693 return 0;
694 } else {
efec19bd 695 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s%s",
44e45fac 696 kppError[(error&1)?1:0],
697 kppError[(error&2)?2:0],
698 kppError[(error&4)?3:0],
699 kppError[(error&8)?4:0],
e75e6e01 700 kppError[(error&16)?5:0],
6614fa48 701 kppError[(error&32)?6:0],
6a150f83 702 kppError[(error&64)?7:0],
0254e751 703 kppError[(error&128)?8:0],
704 kppError[(error&256)?9:0],
da0e365e 705 kppError[(error&512)?10:0],
6ecb073a 706 kppError[(error&1024)?11:0],
efec19bd 707 kppError[(error&2048)?12:0],
708 kppError[(error&4096)?12:0]
44e45fac 709 ));
710 return error;
711 }
0254e751 712
713
714}
715
716//_______________________________________________________________
717
718UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
719{
720 //
721 //Getting the LHC Data from DCS FXS
722 //
723
724 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
725 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
e541e2aa 726 if (timeStartString.IsNull() || timeEndString.IsNull()){
0254e751 727 if (timeStartString.IsNull()){
728 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
729 }
e541e2aa 730 else if (timeEndString.IsNull()){
0254e751 731 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
732 }
733 return 2;
734 }
735
736 Double_t timeStart = timeStartString.Atof();
737 Double_t timeEnd = timeEndString.Atof();
738
0254e751 739 TString fileName = GetFile(kDCS, "LHCData","");
740 if (fileName.Length()>0){
741 AliInfo("Got The LHC Data file");
e541e2aa 742 AliLHCReader lhcReader;
49822138 743
744 // Processing data to be put in AliGRPObject
745
746 // Energy
79350b54 747 Log("*************Energy ");
49822138 748 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
749 if (energyArray){
4cbf81c1 750 Float_t energy = ProcessEnergy(energyArray,timeStart);
ac152fdd 751 if (energy != -1.) {
49822138 752 grpobj->SetBeamEnergy(energy);
753 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
0254e751 754 }
49822138 755 delete energyArray;
756 }
757 else {
758 AliError("Energy not found in LHC Data file!!!");
759 }
760
4cbf81c1 761 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
762 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
53b0ec45 763 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
764 Double_t timeBeamTypeEnd[2] = {timeEnd, timeEnd}; // max validity for Beam Type1,2
4cbf81c1 765 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
766 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
767 Double_t timeBeamStart = -1; // min validity for Beam Type
53b0ec45 768 Double_t timeBeamTypeStart[2] = {-1,-1}; // min validity for Beam Type1,2
4cbf81c1 769 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
53b0ec45 770 Int_t indexMachineMode = -1; // index of measurement used to set Machine Mode
771 Int_t indexBeam = -1; // index of measurement used to set Beam Type
772 Int_t indexBeamType[2] = {-1, -1}; // index of measurement used to set Beam Type1,2
4cbf81c1 773 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
53b0ec45 774 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Machine Mode is found before (or at) SOR
775 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Type is found before (or at) SOR
776 Bool_t foundBeamTypeStart[2] = {kFALSE, kFALSE}; // flag to be set in case an entry for the Beam Type1,2 is found before (or at) SOR
4cbf81c1 777 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
778 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
779 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
53b0ec45 780 Bool_t flagBeamType[2] = {kFALSE, kFALSE}; //flag set true if a changed occurred in BeamType1,2
49822138 781
53b0ec45 782 Double_t arrayTimes[5]={2.E9, 2.E9, 2.E9, 2.E9, 2.E9}; // array to keep track of the times of the possible changes of the LHC DPs; each entry set to Wed May 18 2033, 03:33:20 GMT (ALICE should not be running anymore...)
783 // arrayTimes elements order correspond to the one used in the array of the strings fgkLHCDataPoints, i.e.:
784 // arrayTimes[0] --> MachineMode
785 // arrayTimes[1] --> BeamMode
786 // arrayTimes[2] --> BeamType (when written together)
787 // arrayTimes[3] --> BeamType1 (when written separate)
788 // arrayTimes[4] --> BeamType2 (when written separate)
789
49822138 790 // BeamMode
79350b54 791 Log("*************BeamMode (LHCState) ");
49822138 792 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
793 Int_t nBeamMode = -1;
794 if (beamModeArray){
795 nBeamMode = beamModeArray->GetEntries();
796 if (nBeamMode==0){
79350b54 797 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
49822138 798 }
799 else{
4cbf81c1 800 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
801 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
802 if (beamMode){
803 if (beamMode->GetTimeStamp()<=timeStart && beamMode->GetTimeStamp()>=timeBeamModeStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
804 timeBeamModeStart = beamMode->GetTimeStamp();
805 indexBeamMode = iBeamMode;
806 foundBeamModeStart = kTRUE;
79350b54 807 }
4cbf81c1 808 else {
809 break;
810
79350b54 811 }
49822138 812 }
4cbf81c1 813 }
814 if (!foundBeamModeStart){
815 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
40e422c8 816 }
49822138 817 else {
4cbf81c1 818 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
819 TObjString* beamModeString = beamMode->GetStringArray(0);
820 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
821 grpobj->SetLHCState(beamModeString->String());
822 if (indexBeamMode < nBeamMode-1){
823 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
824 if (beamMode1){
825 if (beamMode1->GetTimeStamp()<=timeStart){
826 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
827 }
828 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
829 timeBeamModeEnd = beamMode1->GetTimeStamp();
830 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
831 TString bmString0 = beamModeString->String();
832 TString bmString1 = beamModeString1->String();
833 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
6720fa1f 834 AliWarning(Form("The beam mode changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",bmString0.Data(), bmString1.Data(), timeBeamModeEnd, bmString0.Data()));
4cbf81c1 835 flagBeamMode = kTRUE;
53b0ec45 836 arrayTimes[1]=timeBeamModeEnd;
837
79350b54 838 }
49822138 839 }
79350b54 840 }
841 else {
4cbf81c1 842 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
5fb8d1a1 843 }
844 }
40e422c8 845 }
0d361338 846 }
49822138 847 delete beamModeArray;
848 }
849 else{
850 AliError("Beam mode array not found in LHC Data file!!!");
851 }
852
853 // MachineMode
79350b54 854 Log("*************MachineMode ");
49822138 855 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
856 Int_t nMachineMode = -1;
857 if (machineModeArray){
858 nMachineMode = machineModeArray->GetEntries();
859 if (nMachineMode==0){
860 AliInfo("No Machine Mode found, leaving it empty");
0254e751 861 }
49822138 862 else{
4cbf81c1 863 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
864 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
79350b54 865 if (machineMode){
4cbf81c1 866 if (machineMode->GetTimeStamp()<=timeStart && machineMode->GetTimeStamp()>=timeMachineModeStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
867 timeMachineModeStart = machineMode->GetTimeStamp();
868 indexMachineMode = iMachineMode;
869 foundMachineModeStart = kTRUE;
79350b54 870 }
871 else{
4cbf81c1 872 break;
79350b54 873 }
49822138 874 }
4cbf81c1 875 }
876 if (!foundMachineModeStart){
877 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
40e422c8 878 }
49822138 879 else {
4cbf81c1 880 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
881 TObjString* machineModeString = machineMode->GetStringArray(0);
882 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
883 grpobj->SetMachineMode(machineModeString->String());
884 if (indexMachineMode < nMachineMode-1){
885 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
886 if (machineMode1){
887 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
888 timeMachineModeEnd = machineMode1->GetTimeStamp();
889 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
890 TString mmString0 = machineModeString->String();
891 TString mmString1 = machineModeString1->String();
892 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
6720fa1f 893 AliWarning(Form("The machine mode changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",mmString0.Data(),mmString1.Data(),timeMachineModeEnd,mmString0.Data()));
4cbf81c1 894 flagMachineMode = kTRUE;
53b0ec45 895 arrayTimes[0]=timeMachineModeEnd;
79350b54 896 }
49822138 897 }
79350b54 898 }
4cbf81c1 899 else {
900 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
49822138 901 }
902 }
49822138 903 }
904 }
905 delete machineModeArray;
906 }
4cbf81c1 907 else{
49822138 908 AliError("Machine mode array not found in LHC Data file!!!");
4cbf81c1 909 }
49822138 910
911 // BeamType1 and BeamType2 - both put in the same string
79350b54 912 Log("*************BeamType ");
49822138 913 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
914 if (beamArray){
915 Int_t nBeam = beamArray->GetEntries();
916 if (nBeam==0){
917 AliInfo("No Beam Type found, leaving it empty");
918 }
919 else{
4cbf81c1 920 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
921 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
79350b54 922 if (beam){
4cbf81c1 923 if (beam->GetTimeStamp()<=timeStart && beam->GetTimeStamp()>=timeBeamStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
924 timeBeamStart = beam->GetTimeStamp();
925 indexBeam = iBeam;
926 foundBeamStart = kTRUE;
79350b54 927 }
4cbf81c1 928 else{
929 break;
79350b54 930 }
931 }
4cbf81c1 932 }
933 if (!foundBeamStart){
53b0ec45 934 AliInfo("No value for the Beam Type found before start of run, the (common) Beam Type will remain empty");
4cbf81c1 935 }
936 else {
937 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
938 TObjString* beamString = beam->GetStringArray(0);
939 TString beamType = beamString->String();
940 AliInfo(Form("Beam Type = %s",beamType.Data()));
941 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
942 AliInfo("Setting beam type to p-p");
943 grpobj->SetBeamType("p-p");
944 }
5755755a 945 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
946 AliInfo("Setting beam type to A-A");
947 grpobj->SetBeamType("A-A");
948 }
949 /*
950 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
4cbf81c1 951 AliInfo("Setting beam type to Pb-Pb");
952 grpobj->SetBeamType("Pb-Pb");
953 }
79350b54 954 else{
4cbf81c1 955 AliError("Beam Type not known, leaving it empty");
79350b54 956 }
5755755a 957 */
4cbf81c1 958 if (indexBeam < nBeam-1){
959 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
960 if (beam1){
961 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
962 timeBeamEnd = beam1->GetTimeStamp();
963 TObjString* beamString1 = beam1->GetStringArray(0);
964 TString beamType1 = beamString1->String();
965 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
6720fa1f 966 AliWarning(Form("The Beam Type changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",beamType.Data(),(beamString1->String()).Data(),timeBeamEnd,beamType.Data()));
4cbf81c1 967 flagBeam = kTRUE;
53b0ec45 968 arrayTimes[2] = timeBeamEnd;
79350b54 969 }
79350b54 970 }
971 }
4cbf81c1 972 else {
973 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
e07d2728 974 }
975 }
e07d2728 976 }
977 }
49822138 978 delete beamArray;
979 }
980 else{
4cbf81c1 981 AliError("Beam Type array not found in LHC Data file!!!");
982 }
53b0ec45 983
984 // BeamType1 and BeamType2 - in separete string
985 Log("*************BeamType, 1 and 2 ");
986 Int_t indexBeamTypeString = 6; // index of the string with the alias of BeanType1 in the array fgkLHCDataPoints
81a1addb 987 TString combinedBeamType = "-"; // combined beam type, built from beam type 1 and beam type 2
988 TString combinedBeamTypeFromLHC = "-"; // combined beam type, built from beam type 1 and beam type 2 AS SENT FROM LHC
53b0ec45 989 for (Int_t ibeamType = 0; ibeamType<2; ibeamType++){
990 beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[indexBeamTypeString+ibeamType]);
991 if (beamArray){
992 Int_t nBeam = beamArray->GetEntries();
993 if (nBeam==0){
994 AliInfo(Form("No Beam Type %s found, leaving it empty",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
995 }
996 else{
997 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
998 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
999 if (beam){
1000 if (beam->GetTimeStamp()<=timeStart && beam->GetTimeStamp()>=timeBeamTypeStart[ibeamType]){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
1001 timeBeamTypeStart[ibeamType] = beam->GetTimeStamp();
1002 indexBeamType[ibeamType] = iBeam;
1003 foundBeamTypeStart[ibeamType] = kTRUE;
1004 }
1005 else{
1006 break;
1007 }
1008 }
1009 }
1010 if (!foundBeamTypeStart[ibeamType]){
1011 AliInfo(Form("No value for the Beam Type %s found before start of run, the Beam Type %d will remain empty", fgkLHCDataPoints[indexBeamTypeString+ibeamType], ibeamType));
1012 }
1013 else {
1014 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
1015 TObjString* beamString = beam->GetStringArray(0);
1016 TString beamType = beamString->String();
81a1addb 1017 AliInfo(Form("Beam Type (for %s) = %s", fgkLHCDataPoints[indexBeamTypeString+ibeamType], beamType.Data()));
1018 TString singleBeam = ParseBeamTypeString(beamType,ibeamType);
1019 AliInfo(Form("Single Beam Type for beam %d set to %s", ibeamType, singleBeam.Data()));
1020 grpobj->SetSingleBeamType(ibeamType, singleBeam);
53b0ec45 1021 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
81a1addb 1022 AliInfo(Form("Setting beam %d for combined beam type to p", ibeamType));
1023 if (ibeamType == 0) combinedBeamType.Prepend("p");
53b0ec45 1024 else combinedBeamType.Append("p");
1025 }
1026 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
81a1addb 1027 AliInfo(Form("Setting beam %d for combined beam type to A",ibeamType));
53b0ec45 1028 if (ibeamType == 0) combinedBeamType.Prepend("A");
1029 else combinedBeamType.Append("A");
1030 }
81a1addb 1031 if (ibeamType == 0) combinedBeamTypeFromLHC.Prepend(beamType);
1032 else combinedBeamTypeFromLHC.Append(beamType);
53b0ec45 1033 /*
1034 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
1035 AliInfo("Setting beam type to Pb-Pb");
1036 grpobj->SetSingleBeamType(ibeamType, "Pb-Pb");
1037 }
1038 else{
1039 AliError("Beam Type not known, leaving it empty");
1040 }
1041 */
1042 if (indexBeamType[ibeamType] < nBeam-1){
1043 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
1044 if (beam1){
1045 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
1046 timeBeamTypeEnd[ibeamType] = beam1->GetTimeStamp();
1047 TObjString* beamString1 = beam1->GetStringArray(0);
1048 TString beamType1 = beamString1->String();
1049 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
1050 AliWarning(Form("The Beam Type for %s changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",fgkLHCDataPoints[indexBeamTypeString+ibeamType],beamType.Data(),(beamString1->String()).Data(),timeBeamEnd,beamType.Data()));
1051 flagBeamType[ibeamType] = kTRUE;
1052 arrayTimes[3+ibeamType] = timeBeamTypeEnd[ibeamType];
1053 }
1054 }
1055 }
1056 else {
1057 AliInfo(Form("Invalid pointer for the first entry for Beam Type %s after the first valid one, not considering anything after what has already been found",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1058 }
1059 }
1060 }
1061 }
1062 delete beamArray;
1063 }
1064 else{
1065 AliError(Form("Beam Type %s array not found in LHC Data file!!!",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1066 }
1067 }
1068 AliInfo(Form("Setting combined beam type to %s",combinedBeamType.Data()));
1069 grpobj->SetBeamType(combinedBeamType);
81a1addb 1070 AliInfo(Form("Setting combined beam type form LHC to %s",combinedBeamTypeFromLHC.Data()));
1071 grpobj->SetBeamTypeFromLHC(combinedBeamTypeFromLHC);
49822138 1072
1073 // Setting minTimeLHCValidity
53b0ec45 1074 if (flagBeamMode == kTRUE || flagMachineMode == kTRUE || flagBeam == kTRUE || flagBeamType[0] == kTRUE || flagBeamType[1] == kTRUE){
1075 Double_t minTimeLHCValidity= TMath::MinElement(5,arrayTimes);
1076 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1077 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1078 }
26fd9395 1079 /*
1080 // Old way to determine the Maximum Time during which the LHC info is valid
4cbf81c1 1081 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
49822138 1082 Double_t minTimeLHCValidity;
53b0ec45 1083 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true --> it is the only one that changed
4cbf81c1 1084 minTimeLHCValidity = timeBeamEnd;
49822138 1085 }
4cbf81c1 1086 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
1087 minTimeLHCValidity = timeMachineModeEnd;
49822138 1088 }
4cbf81c1 1089 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
1090 minTimeLHCValidity = timeBeamModeEnd;
49822138 1091 }
4cbf81c1 1092 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
1093 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
49822138 1094 }
4cbf81c1 1095 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
1096 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
49822138 1097 }
4cbf81c1 1098 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
1099 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
0254e751 1100 }
49822138 1101 else {
4cbf81c1 1102 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
49822138 1103 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
1104 }
1105 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1106 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1107 }
53b0ec45 1108 */
49822138 1109
26fd9395 1110 // Data Quality Flag --> storing start and end values of periods within the run during which the value was found to be FALSE
1111 Log("*************Data Quality Flag ");
1112 TObjArray* dataQualityArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[8]);
1113 Int_t nDataQuality = -1;
1114 Double_t timeDataQualityStart = -1; // min validity for Data Quality Flag
1115 Int_t indexDataQuality = -1; // index of first measurement used to set Data Quality Flag
1116 Bool_t foundDataQualityStart = kFALSE; // flag to be set in case an entry for the Data Quality Flag is found before (or at) SOR
1117
1118 if (dataQualityArray){
1119 nDataQuality = dataQualityArray->GetEntries();
1120 if (nDataQuality==0){
1121 AliInfo("No Data Quality Flag found, leaving it empty");
1122 }
1123 else{
1124 for (Int_t iDataQuality = 0; iDataQuality<nDataQuality; iDataQuality++){
1125 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1126 if (dataQuality){
1127 if (dataQuality->GetTimeStamp()<=timeStart && dataQuality->GetTimeStamp()>=timeDataQualityStart){// taking always the very last entry: if two measurements have the same timestamp, the last one is taken
1128 timeDataQualityStart = dataQuality->GetTimeStamp();
1129 indexDataQuality = iDataQuality;
1130 foundDataQualityStart = kTRUE;
1131 }
1132 else{
1133 // we suppose here that if the first measurement is not before SOR, then none will be (they MUST be in chronological order!!!)
1134 break;
1135 }
1136 }
1137 }
1138 if (!foundDataQualityStart){
1139 // The Data Quality Flag should be found and TRUE at the start of the run. For the time being, if it is not found, don't do anything, but it means there is a problem..
1140 AliInfo("No value for the Data Quality Flag found before start of run, the Data Quality Flag will remain empty");
1141 }
1142 else {
1143 // counting how many FALSE values there are
1144 Bool_t foundEndOfFalse = kFALSE;
1145 Int_t nFalse = 0;
1146 for (Int_t iDataQuality = indexDataQuality; iDataQuality < nDataQuality; iDataQuality ++){
1147 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1148 AliDebug(4,Form("dataQuality->GetTimeStamp() = %f, timeDataQualityStart = %f, timeEnd = %f", dataQuality->GetTimeStamp(), timeDataQualityStart, timeEnd ));
1149 if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
1150 Bool_t dataQualityFlag = dataQuality->GetBool(0);
1151 AliDebug(3,Form("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp()));
1152 if (dataQualityFlag != kTRUE){
1153 if (iDataQuality == indexDataQuality) { // the first Data Quality value should be TRUE, but ignoring the problem now...
1154 AliError("The first value for the Data Quality MUST be TRUE! Ignoring for now...");
1155 }
1156 nFalse++;
1157 }
1158 }
1159 }
1160
1161 AliInfo(Form("Found %d FALSE values for the Data Quality Flag",nFalse));
1162 Double_t falses[nFalse*2]; // dimensioning this to the maximum possible, as if each false value was followed by a true one --> the false periods correspond to the number of falses
1163
1164 Int_t iDataQuality = indexDataQuality;
1165 if (nFalse > 0){
1166 Int_t iFalse = 0;
1167 // filling the info about the periods when the flag was set to FALSE
1168 // starting, like for the other DPS, from the measurement closest to SOR (the index of which is iDataQuality)
1169 while (iDataQuality < nDataQuality){
1170 AliDebug(3,Form("iDataQuality = %d",iDataQuality));
1171 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1172 if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
1173 Bool_t dataQualityFlag = dataQuality->GetBool(0);
1174 AliDebug(3,Form("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp()));
1175 if (dataQualityFlag == kTRUE){
1176 // found TRUE value, continuing
1177 iDataQuality++;
1178 continue;
1179 }
1180 else{
1181 /*
1182 // the check was already done before
1183 if (iDataQuality == indexDataQuality) { // the first Data Quality value should be TRUE, but ignoring the problem now...
1184 AliError("The first value for the Data Quality MUST be TRUE! Ignoring for now...");
1185 }
1186 */
1187 falses[iFalse*2] = dataQuality->GetTimeStamp();
1188 foundEndOfFalse = kFALSE;
1189 Int_t iDataQualityNext = iDataQuality+1;
1190 while (iDataQualityNext < nDataQuality){
1191 AliDCSArray* dataQualityNext = (AliDCSArray*)dataQualityArray->At(iDataQualityNext);
1192 if (dataQualityNext->GetTimeStamp()>timeDataQualityStart && dataQualityNext->GetTimeStamp()<=timeEnd && dataQualityNext->GetTimeStamp() > dataQuality->GetTimeStamp()){ // considering only values between the first valid and the end of the run, and subsequent to the current value
1193 Bool_t dataQualityFlagNext = dataQualityNext->GetBool(0);
1194 AliDebug(3,Form("DataQualityNext = %d (set at %f)",(Int_t)dataQualityFlagNext,dataQualityNext->GetTimeStamp()));
1195 if (dataQualityFlagNext == kTRUE){
1196 // found TRUE value, first FALSE period completed
1197 foundEndOfFalse = kTRUE;
1198 falses[iFalse*2+1] = dataQualityNext->GetTimeStamp();
1199 iFalse++;
1200 break;
1201 }
1202 iDataQualityNext++;
1203 }
1204 }
1205 if (!foundEndOfFalse) {
1206 AliInfo("Please, note that the last FALSE value lasted until the end of the run");
1207 falses[iFalse*2+1] = timeEnd;
1208 iFalse++;
1209 break;
1210 }
1211 iDataQuality = iDataQualityNext+1;
1212 }
1213 }
1214 }
1215 grpobj->SetNFalseDataQualityFlag(iFalse);
1216 grpobj->SetFalseDataQualityFlagPeriods(falses);
1217 }
1218 }
1219 }
1220 delete dataQualityArray;
1221 }
1222 else{
1223 AliError("Data Quality Flag array not found in LHC Data file!!!");
1224 }
1225
49822138 1226 // Processing data to go to AliLHCData object
63bd40f4 1227 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
1228 // storing AliLHCData in OCDB
1229 if (dt){
1230 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
1231 AliCDBMetaData md;
1232 md.SetResponsible("Ruben Shahoyan");
1233 md.SetComment("LHC data from the GRP preprocessor.");
1234 Bool_t result = kTRUE;
1235 result = Store("GRP", "LHCData", dt, &md);
1236 delete dt;
da0e365e 1237 if (!result){
1238 Log(Form("Problems in storing LHC Data - but not going into Error"));
1239 }
1240 }
1241
1242 // processing LHC Phase
1243
1244 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
1245 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
1246 if (beam1phase == 0x0 || beam2phase == 0x0){
1247 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
1248 return 4;
1249 }
17fd2848 1250 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
ca84e838 1251 delete beam1phase;
1252 delete beam2phase;
da0e365e 1253 if (phaseObj){
1254 AliInfo(Form("LHC Phase found"));
1255 AliCDBMetaData mdPhase;
1256 mdPhase.SetResponsible("Cvetan Cheshkov");
1257 mdPhase.SetComment("LHC Clock Phase");
1258 Bool_t result = kTRUE;
1259 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
1260 delete phaseObj;
1261 if (!result) return 3;
0254e751 1262 }
da0e365e 1263 else return 4;
0254e751 1264 }
49822138 1265
0254e751 1266 else {
aab08fd4 1267 AliError("No LHCData file found in FXS");
0254e751 1268 return 1;
1269 }
79350b54 1270
1271 return 0;
17984b61 1272}
1273
6a150f83 1274//_______________________________________________________________
1275
1276UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
1277{
0254e751 1278 //
6a150f83 1279 //Getting the SPD Mean Vertex
0254e751 1280 //
1281
6a150f83 1282 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
1283 Bool_t storeResult = kTRUE;
1284 if (list !=0x0 && list->GetEntries()!=0)
1285 {
1286 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
1287 list->Print();
1288 for (Int_t jj=0;jj<list->GetEntries();jj++){
24f67180 1289 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1290 if (!str){
1291 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1292 continue;
1293 }
6a150f83 1294 AliInfo(Form("found source %s", str->String().Data()));
1295 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
1296 if (fileNameRun.Length()>0){
1297 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1298 TFile daqFile(fileNameRun.Data(),"READ");
1299 if (daqFile.IsOpen()) {
1300 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
1301 if (meanVtx){
1302 meanVtx->Print();
1303 // storing in the OCDB
1304 AliCDBMetaData md;
1305 md.SetResponsible("Cvetan Cheshkov");
1306 md.SetComment("SPD Mean Vertex");
295c54b0 1307 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
6a150f83 1308 }
1309 else{
1310 AliWarning("No SPD Mean Vertex object found in file");
1311 }
1312 }
1313 else {
1314 AliError("Can't open file");
1315 storeResult = kFALSE;
1316 }
1317 }
1318 else{
1319 AliWarning("No file found for current source for SPD Mean Vertex");
1320 }
1321 }
1322 }
1323 else {
1324 AliWarning("No list found for SPD Mean Vertex");
1325 }
1326
1327 if (list) delete list;
1328
1329 return storeResult;
1330}
efec19bd 1331//_______________________________________________________________
1332
1333UInt_t AliGRPPreprocessor::ProcessDqmFxs()
1334{
1335 //
1336 // Processing DQM fxs information
1337 //
1338
59fef0d0 1339 // TriggerClassesAndHistosToClone
efec19bd 1340 TList* list = GetFileSources(kDQM, "TriggerClassesAndHistosToClone");
1341 Bool_t storeResult = kTRUE;
59fef0d0 1342 Bool_t storeResultQAThr = kTRUE;
efec19bd 1343 if (list !=0x0 && list->GetEntries()!=0){
1344 AliInfo("The following sources produced files with the id TriggerClassesAndHistosToClone for GRP");
1345 list->Print();
1346 for (Int_t jj=0;jj<list->GetEntries();jj++){
1347 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1348 if (!str){
1349 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1350 continue;
1351 }
1352 AliInfo(Form("found source %s", str->String().Data()));
1353 TString fileNameRun = GetFile(kDQM, "TriggerClassesAndHistosToClone", str->GetName());
1354 if (fileNameRun.Length()>0){
1355 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1356 TFile dqmFile(fileNameRun.Data(),"READ");
1357 if (dqmFile.IsOpen()) {
1358 dqmFile.ls();
1359 }
1360 else {
1361 AliError("Can't open file");
1362 storeResult = kFALSE;
1363 }
1364 }
1365 else{
1366 AliWarning("No file found for current source for DQM TriggerClassesAndHistosToClone");
1367 }
1368 }
1369 }
1370 else {
1371 AliWarning("No list found for DQM TriggerClassesAndHistosToClone");
1372 }
1373
1374 if (list) delete list;
59fef0d0 1375
1376 // QAThresholds
1377 TObjArray* qaThrArray = new TObjArray();
1378 for (Int_t idet = 0; idet < AliDAQ::kNDetectors; idet++){
1379 TString detName = AliDAQ::OnlineName(idet);
1380 if (detName == "TRI" || detName == "HLT" || detName == "TST") continue; // skipping TRI, HLT, TST since they do not produce QAThresholds
1381 AliDebug(2, Form("Processing QAThreshold for detector %s",detName.Data()));
1382 TList* listQAThr = GetForeignFileSources(detName.Data(), kDQM, "QAThresholds");
1383 if (listQAThr !=0x0){
1384 if (listQAThr->GetEntries() > 1){
1385 AliError(Form("More than one sources found for QAThresholds from detector %s, skipping",detName.Data()));
1386 continue;
1387 }
1388 else if (listQAThr->GetEntries()==1){
1389 AliInfo(Form("The following source produced files with the id QAThresholds for GRP, coming from detector %s:",detName.Data()));
1390 listQAThr->Print();
1391 TObjString * str = dynamic_cast<TObjString*> (listQAThr->At(0));
1392 if (!str){
1393 AliError(Form("Expecting a TObjString in the list for detector %s, but something else was found.",detName.Data()));
1394 delete listQAThr;
1395 continue;
1396 }
1397 AliInfo(Form("found source %s", str->String().Data()));
1398 TString fileNameRun = GetForeignFile(detName.Data(), kDQM, "QAThresholds", str->GetName());
1399 if (fileNameRun.Length()>0){
1400 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1401 TFile dqmFile(fileNameRun.Data(),"READ");
1402 if (dqmFile.IsOpen()) {
b5c790a4 1403 AliQAThresholds* qaThr = dynamic_cast<AliQAThresholds*>(dqmFile.Get(detName.Data()));
59fef0d0 1404 if (qaThr){
1405 Int_t qaThrId = qaThr->GetDetectorId();
1406 if (qaThrId != idet){
1407 AliError(Form("Expecting QA threshold for detector %s, but found that for detector %s, skipping",detName.Data(), AliDAQ::OnlineName(qaThrId)));
1408 delete listQAThr;
1409 continue;
1410 }
1411 else{
1412 qaThrArray->AddAtAndExpand(qaThr, qaThrId);
1413 delete listQAThr;
1414 }
1415 }
1416 else {
1417 AliError(Form("No QAThresholds object found in the file for detector %s, skipping",detName.Data()));
1418 delete listQAThr;
1419 continue;
1420 }
1421 }
1422 else {
1423 AliError(Form("Can't open QAThreshold file for detector %s, skipping",detName.Data()));
1424 delete listQAThr;
1425 continue;
1426 }
1427 }
1428 else{
1429 AliWarning(Form("No file found for DQM QAThreshold for detector %s, skipping",detName.Data()));
1430 delete listQAThr;
1431 continue;
1432 }
1433 }
1434 else {
1435 AliError(Form("No sources found for QAThresholds from detector %s, skipping",detName.Data()));
1436 delete listQAThr;
1437 continue;
1438 }
1439 }
1440 else {
1441 AliWarning(Form("No list found for DQM QAThreshold for detector %s, skipping",detName.Data()));
1442 continue;
1443 }
1444 }
1445 if (qaThrArray->GetEntries() > 0){
1446 AliCDBMetaData md;
1447 md.SetResponsible("Barthélémy von Haller");
1448 md.SetComment("QA Threshold TObjArray");
1449 storeResultQAThr = Store("Calib", "QAThresholds", qaThrArray, &md, 0, kTRUE);
1450 }
1451 else{
1452 Printf("No valid QAThresholds entries found, storing nothing in the OCDB");
1453 }
1454
efec19bd 1455 // return storeResult;
1456 return kTRUE; // temporary!!
1457}
6a150f83 1458
1459
17984b61 1460//_______________________________________________________________
17984b61 1461
e75e6e01 1462Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
44e45fac 1463{
1464 //Getting the DAQ lb information
1465
e75e6e01 1466 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
1467 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
1468 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
44e45fac 1469 TString beamType = (TString)GetRunParameter("beamType");
1470 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
e75e6e01 1471 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
44e45fac 1472 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
1473 TString runType = (TString)GetRunType();
1474
53b0ec45 1475 if (timeEnd >= 2.E9) AliFatal("ALICE run finshed later than Wed May 18 2033, 03:33:20 GMT, maximum time allowed for LHC data --> fix the GRP preprocessor!!!");
1476
e75e6e01 1477 UInt_t nparameter = 0;
44e45fac 1478 if (timeStart != 0){
1479 grpObj->SetTimeStart(timeStart);
1480 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
e75e6e01 1481 nparameter++;
44e45fac 1482 }
1483 else {
e3a2ac48 1484 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1485 }
1486
1487 if (timeEnd != 0){
1488 grpObj->SetTimeEnd(timeEnd);
1489 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
e75e6e01 1490 nparameter++;
44e45fac 1491 }
1492 else {
e3a2ac48 1493 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1494 }
1495
1496 if (beamEnergy != 0){
e3a2ac48 1497 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
44e45fac 1498 }
1499 else {
e3a2ac48 1500 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
44e45fac 1501 }
1502
44e45fac 1503
1504 if (beamType.Length() != 0){
e3a2ac48 1505 Log(Form("Beam Type for run %d: %s (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamType.Data()));
44e45fac 1506 }
1507 else {
e3a2ac48 1508 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
44e45fac 1509 }
1510
1511 if (numberOfDetectors != 0){
1512 grpObj->SetNumberOfDetectors(numberOfDetectors);
1513 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
e75e6e01 1514 nparameter++;
44e45fac 1515 }
1516 else {
e3a2ac48 1517 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1518 }
1519
1520 if (detectorMask != 0){
1521 grpObj->SetDetectorMask(detectorMask);
1522 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
e75e6e01 1523 nparameter++;
44e45fac 1524 }
1525 else {
e3a2ac48 1526 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1527 }
1528
1529 if (lhcPeriod.Length() != 0) {
1530 grpObj->SetLHCPeriod(lhcPeriod);
1531 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
e75e6e01 1532 nparameter++;
1533 }
1534 else {
e3a2ac48 1535 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1536 }
1537 if (runType.Length() != 0) {
1538 grpObj->SetRunType(runType);
1539 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
e75e6e01 1540 nparameter++;
1541 }
1542 else {
e3a2ac48 1543 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1544 }
1545
e75e6e01 1546 return nparameter;
44e45fac 1547}
44e45fac 1548//_______________________________________________________________
17984b61 1549
44e45fac 1550UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1551{
1552 //======DAQ FXS======//
1553
ea4a87ee 1554 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
f3590649 1555 AliRawEventHeaderV3_11::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_11 - temporary fix
e01c025f 1556 AliRawEventHeaderV3_12::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_12 - temporary fix
16c237c6 1557 Log("Processing DAQ FXS");
1558 TList* list = GetFileSources(kDAQ);
44e45fac 1559 if (!list) {
1560 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1561 return 1;
1562 }
1563
1564 if (list->GetEntries() == 0) {
1565 Log("no raw data tags in this run: nothing to merge!");
1566 delete list; list=0;
1567 return 0;
1568 }
1569
1570 TChain *fRawTagChain = new TChain("T");
1571 Int_t nFiles=0;
1572 TIterator* iter = list->MakeIterator();
1573 TObject* obj = 0;
1574 while ((obj = iter->Next())) {
1575 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1576 if (objStr) {
1577 Log(Form("Found source %s", objStr->String().Data()));
1578 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1579 if (!list2) {
1580 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1581 delete fRawTagChain; fRawTagChain=0;
1582 return 1;
1583 }
1584 Log(Form("Number of ids: %d",list2->GetEntries()));
1585 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1586 TObjString *idStr = (TObjString *)list2->At(i);
5bc3c20c 1587 if (idStr->String().CompareTo("QAThreshold") == 0 || idStr->String().CompareTo("TriggerClassesAndHistosToClone") == 0) {
1588 Log(Form("Skipping file with Id %s",idStr->String().Data()));
1589 continue;
1590 }
44e45fac 1591 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1592 if (fileName.Length() > 0) {
1593 Log(Form("Adding file in the chain: %s",fileName.Data()));
1594 fRawTagChain->Add(fileName.Data());
1595 nFiles++;
1596 } else {
1597 Log(Form("Could not retrieve file with id %s from source %s: "
1598 "connection problems with DAQ FXS!",
1599 idStr->String().Data(), objStr->String().Data()));
1600 delete list; list=0;
1601 delete list2; list2=0;
1602 delete fRawTagChain; fRawTagChain=0;
1603 return 2;
1604 }
1605 }
1606 delete list2;
1607 }
1608 }
16c237c6 1609
1610 if (nFiles == 0){
1611 Log("no raw data tags in this run: it could be that one or more files were found in the DAQ FXS, but they were ignored, since not interesting for the raw data tag: nothing to merge!");
166b08b9 1612 delete iter;
1613 iter = 0;
1614 delete list;
1615 list = 0;
1616 delete fRawTagChain;
1617 fRawTagChain=0;
16c237c6 1618 return 0;
1619 }
44e45fac 1620
1621 TString fRawDataFileName = "GRP_Merged.tag.root";
1622 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
7e6f5523 1623
16c237c6 1624 if (fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1625 Log(Form("Error merging %d raw data files!!!",nFiles));
166b08b9 1626 delete iter;
1627 iter = 0;
1628 delete list;
1629 list = 0;
1630 delete fRawTagChain;
1631 fRawTagChain=0;
44e45fac 1632 return 3;
1633 }
16c237c6 1634
44e45fac 1635 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1636 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1637
1638 if (!result) {
1639 Log("Problem storing raw data tags in local file!!!");
1640 } else {
1641 Log("Raw data tags merged successfully!!");
1642 }
1643
1644 delete iter;
166b08b9 1645 iter = 0;
44e45fac 1646 delete list;
166b08b9 1647 list = 0;
44e45fac 1648 delete fRawTagChain; fRawTagChain=0;
1649
1650 if (result == kFALSE) {
1651 return 4;
1652 }
1653
1654 return 0;
1655
1656}
17984b61 1657
44e45fac 1658//_______________________________________________________________
e75e6e01 1659UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
44e45fac 1660{
39e3007b 1661
1662 // processing the info
1663 // stored in the DCS FXS
1664 // coming from the trigger
1665
e75e6e01 1666 // Get the CTP counters information
1667
1668 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
161a4dc3 1669 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
e75e6e01 1670 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1671 if (!cdbEntry) {
1672 Log(Form("No dummy CTP scalers entry found, going into error..."));
44e45fac 1673 return 1;
1674 }
e75e6e01 1675 else{
1676 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1677 if (!scalers){
1678 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1679 return 1;
1680 }
1681 else {
1682 AliCDBMetaData metaData;
1683 metaData.SetResponsible("Roman Lietava");
1684 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1685 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1686 Log("Unable to store the dummy CTP scalers object to OCDB!");
1687 return 1;
1688 }
1689 }
1690 }
1691 }
1692
1693 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1694 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1695 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1696 if (countersfile.IsNull()) {
1697 Log("No CTP counters files has been found: empty source!");
44e45fac 1698 return 1;
1699 }
1700 else {
e75e6e01 1701 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1702 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1703 if (!scalers) {
1704 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1705 return 1;
1706 }
1707 else {
1708 AliCDBMetaData metaData;
1709 metaData.SetBeamPeriod(0);
1710 metaData.SetResponsible("Roman Lietava");
1711 metaData.SetComment("CTP scalers");
1712 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1713 Log("Unable to store the CTP scalers object to OCDB!");
e541e2aa 1714 delete scalers;
e75e6e01 1715 return 1;
44e45fac 1716 }
1717 }
e541e2aa 1718 delete scalers;
44e45fac 1719 }
44e45fac 1720 }
1721
e75e6e01 1722
1723 else{
1724 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1725 return 2;
1726 }
1727
44e45fac 1728 return 0;
e75e6e01 1729
44e45fac 1730}
1731//_______________________________________________________________
17984b61 1732
44e45fac 1733Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1734{
17984b61 1735
44e45fac 1736 //
1737 // processing DCS DPs
1738 //
1739
26c1dff2 1740 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
44e45fac 1741 Int_t nL3Entries = 0;
1742 Int_t nDipoleEntries = 0;
1743 Int_t nEnvEntries = 0;
1744 Int_t nHallProbesEntries = 0;
44e45fac 1745 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1746 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1747 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1748 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
fab61587 1749 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
0254e751 1750 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1751 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
44e45fac 1752 return entries;
17984b61 1753
17984b61 1754}
1755
1756//_______________________________________________________________
29cc8704 1757
39e3007b 1758Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 1759{
39e3007b 1760
1761 // processing DPs
1762 // related to
1763 // L3 info
1764
44e45fac 1765 Int_t nL3Entries = 0;
c5340e82 1766
44e45fac 1767 TObjArray *array = 0x0;
1768 Int_t indexDP = -1;
fe726709 1769 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
44e45fac 1770
fe726709 1771 AliInfo(Form("==========L3Current==========="));
1772 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1773 indexDP = kL3Current;
44e45fac 1774 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1775 if(!array) {
1776 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1777 }
1778 else {
26c1dff2 1779 if (array->GetEntries() == 0){
fe726709 1780 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
26c1dff2 1781 }
1782 else {
fe726709 1783 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1784 if (floatDCS != NULL){
1785 grpObj->SetL3Current(floatDCS);
1786 }
1787 else{
1788 outOfRange = kTRUE;
1789 }
03672227 1790 if (floatDCS){
1791 delete[] floatDCS;
1792 floatDCS = 0x0;
1793 }
26c1dff2 1794 }
c5340e82 1795 if (!outOfRange) {
1796 nL3Entries++;
1797 ffailedDPs->RemoveAt(indexDP);
1798 }
44e45fac 1799 }
1800
1801 if (array) array = 0x0;
1802
fe726709 1803 AliInfo(Form("==========L3Polarity==========="));
1804 indexDP = kL3Polarity;
44e45fac 1805 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1806 if(!array) {
1807 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1808 }
1809 else {
26c1dff2 1810 if (array->GetEntries() == 0){
fe726709 1811 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
26c1dff2 1812 }
1813 else {
fe726709 1814 Bool_t change = kFALSE;
1815 Char_t charDCS = ProcessBool(array,change);
01920f0c 1816 if (change == kFALSE){
fe726709 1817 grpObj->SetL3Polarity(charDCS);
1818 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
c5340e82 1819 ffailedDPs->RemoveAt(indexDP);
fe726709 1820 nL3Entries++;
1821 }
1822 else if (isZero){
ac833e7a 1823 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
c5340e82 1824 ffailedDPs->RemoveAt(indexDP);
fe726709 1825 nL3Entries++;
1826 }
1827 else {
ac833e7a 1828 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 1829 }
26c1dff2 1830 }
44e45fac 1831 }
1832
1833 return nL3Entries;
e7a6790f 1834
44e45fac 1835}
1836//_______________________________________________________________
ff97356e 1837
39e3007b 1838Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 1839{
39e3007b 1840 // processing DPs
1841 // related to
1842 // the Dipole info
1843
44e45fac 1844 Int_t nDipoleEntries = 0;
1845 TObjArray *array = 0x0;
1846 Int_t indexDP = -1;
fe726709 1847 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
44e45fac 1848
fe726709 1849 AliInfo(Form("==========DipoleCurrent==========="));
1850 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1851 indexDP = kDipoleCurrent;
44e45fac 1852 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
44e45fac 1853 if(!array) {
1854 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1855 }
1856 else {
26c1dff2 1857 if (array->GetEntries() == 0){
1858 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1859 }
1860 else {
fe726709 1861 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1862 if (floatDCS != NULL){
1863 grpObj->SetDipoleCurrent(floatDCS);
1864 }
1865 else{
1866 outOfRange=kTRUE;
1867 }
03672227 1868 if (floatDCS){
1869 delete[] floatDCS;
1870 floatDCS = 0x0;
1871 }
26c1dff2 1872 }
c5340e82 1873 if (!outOfRange) {
1874 nDipoleEntries++;
1875 ffailedDPs->RemoveAt(indexDP);
1876 }
44e45fac 1877 }
1878
1879 if (array) array = 0x0;
1880
fe726709 1881 AliInfo(Form("==========DipolePolarity==========="));
1882 indexDP = kDipolePolarity;
44e45fac 1883 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1884 if(!array) {
1885 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1886 }
1887 else {
26c1dff2 1888 if (array->GetEntries() == 0){
1889 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1890 }
1891 else {
fe726709 1892 Bool_t change = kFALSE;
1893 Char_t charDCS = ProcessBool(array,change);
1894 if (!change){
1895 grpObj->SetDipolePolarity(charDCS);
1896 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
c5340e82 1897 ffailedDPs->RemoveAt(indexDP);
fe726709 1898 nDipoleEntries++;
1899 }
1900 else if (isZero){
ac833e7a 1901 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
c5340e82 1902 ffailedDPs->RemoveAt(indexDP);
fe726709 1903 nDipoleEntries++;
1904 }
1905 else{
ac833e7a 1906 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 1907 }
26c1dff2 1908 }
44e45fac 1909 }
1910
1911 return nDipoleEntries;
e7a6790f 1912
44e45fac 1913}
1914//_______________________________________________________________
e7a6790f 1915
44e45fac 1916Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1917{
39e3007b 1918 // processing DPs
1919 // related to
1920 // evironment conditions (temperature, pressure) info
1921
44e45fac 1922 Int_t nEnvEntries = 0;
1923 TObjArray *array = 0x0;
1924 Int_t indexDP = -1;
1925
1926 AliInfo(Form("==========CavernTemperature==========="));
fe726709 1927 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
44e45fac 1928 indexDP = kCavernTemperature;
1929 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1930 if(!array) {
1931 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1932 }
1933 else {
26c1dff2 1934 if (array->GetEntries() == 0){
1935 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1936 }
1937 else {
1938 Float_t *floatDCS = ProcessFloatAll(array);
fe726709 1939 if (floatDCS != NULL){
1940 grpObj->SetCavernTemperature(floatDCS);
1941 }
1942 else{
1943 outOfRange = kTRUE;
1944 }
03672227 1945 if (floatDCS){
1946 delete[] floatDCS;
1947 floatDCS = 0x0;
1948 }
26c1dff2 1949 }
c5340e82 1950 if (!outOfRange) {
1951 ffailedDPs->RemoveAt(indexDP);
1952 nEnvEntries++;
1953 }
44e45fac 1954 }
1955
1956 if (array) array = 0x0;
1957
ce996d13 1958 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
44e45fac 1959 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
ce996d13 1960 //dcsSensorArray->Print();
1961 if( fPressure->NumFits()<kNumSensors ) {
d7edf69d 1962 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
44e45fac 1963 }
d7edf69d 1964 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1965
1966 AliInfo(Form("==========CavernAtmosPressure==========="));
1967 indexDP = kCavernAtmosPressure;
1968 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1969 TGraph* graph = sensorCavernP2->GetGraph();
3343d11b 1970 AliDebug(3,Form("index = %d",indexDP));
1971 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 1972 AliDebug(2,Form("graph = %p",graph));
1973 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
2a0b175e 1974 if(sensorCavernP2->GetFit() || graph) {
d7edf69d 1975 if (sensorCavernP2->GetFit()){
2a0b175e 1976 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 1977 }
44e45fac 1978 else {
2a0b175e 1979 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 1980 }
1981 grpObj->SetCavernAtmosPressure(sensorCavernP2);
c5340e82 1982 ffailedDPs->RemoveAt(indexDP);
d7edf69d 1983 nEnvEntries++;
1984 }
1985 //if (sensorP2) delete sensorP2;
1986 else {
2a0b175e 1987 Log(Form("ERROR!!! Neither graph nor fit found for sensor %s - this will not increase the number of found DCS DPs and will cause an error", fgkDCSDataPoints[indexDP] ));
d7edf69d 1988 }
2a0b175e 1989
d7edf69d 1990 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1991 indexDP = kSurfaceAtmosPressure;
1992 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1993 graph = sensorP2->GetGraph();
3343d11b 1994 AliDebug(3,Form("index = %d",indexDP));
1995 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 1996 AliDebug(2,Form("graph = %p",graph));
1997 AliDebug(3,Form("sensorP2 = %p", sensorP2));
2a0b175e 1998 if(sensorP2->GetFit() || graph) {
d7edf69d 1999 if (sensorP2->GetFit()){
2a0b175e 2000 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 2001 }
44e45fac 2002 else {
2a0b175e 2003 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 2004 }
2005 grpObj->SetSurfaceAtmosPressure(sensorP2);
c5340e82 2006 ffailedDPs->RemoveAt(indexDP);
d7edf69d 2007 nEnvEntries++;
2008 }
2009 //if (sensorP2) delete sensorP2;
2010 else {
2a0b175e 2011 Log(Form("ERROR!!! Neither graph nor fit found for sensor %s - this will not increase the number of found DCS DPs and will cause an error", fgkDCSDataPoints[indexDP] ));
44e45fac 2012 }
2013
d7edf69d 2014 AliInfo(Form("==========CavernAtmosPressure2==========="));
2015 indexDP = kCavernAtmosPressure2;
2016 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
8976336c 2017 graph = sensorCavernP22->GetGraph();
3343d11b 2018 AliDebug(3,Form("index = %d",indexDP));
2019 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 2020 AliDebug(2,Form("graph = %p",graph));
2021 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
2a0b175e 2022 if(sensorCavernP22->GetFit() || graph) {
d7edf69d 2023 if (sensorCavernP22->GetFit()){
2a0b175e 2024 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 2025 }
2026 else {
2a0b175e 2027 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 2028 }
2029 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
c5340e82 2030 ffailedDPs->RemoveAt(indexDP);
d7edf69d 2031 nEnvEntries++;
2032 }
2033 //if (sensorP2) delete sensorP2;
2034 else {
2a0b175e 2035 Log(Form("ERROR!!! Neither graph nor fit found for sensor %s - this will not increase the number of found DCS DPs and will cause an error", fgkDCSDataPoints[indexDP] ));
d7edf69d 2036 }
2037
2038
44e45fac 2039 return nEnvEntries;
2040}
2041//_______________________________________________________________
e7a6790f 2042
39e3007b 2043Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 2044{
39e3007b 2045 // processing DPs
2046 // related to
2047 // Hall Probes info
2048
44e45fac 2049 Int_t nHPEntries = 0;
2050 TObjArray *array = 0x0;
2051 Int_t indexDP = -1;
fe726709 2052 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
44e45fac 2053
39e3007b 2054 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
2055 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 2056 }
2057 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
fe726709 2058 outOfRange = kFALSE; // resetting outOfRange flag at each HP
44e45fac 2059 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
2060 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
2061 if(!array) {
2062 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
2063 }
2064 else {
26c1dff2 2065 if (array->GetEntries() == 0){
2066 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
2067 }
2068 else {
2069 Float_t *floatDCS = ProcessFloatAll(array);
fe726709 2070 if (floatDCS != NULL){
2071 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]));
2072 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
2073 for (Int_t kk = 0 ; kk< 5; kk++){
2074 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
2075 }
2076 }
2077 else{
2078 outOfRange = kTRUE;
26c1dff2 2079 }
03672227 2080 if (floatDCS){
2081 delete[] floatDCS;
2082 floatDCS = 0x0;
2083 }
44e45fac 2084 }
c5340e82 2085 if (!outOfRange) {
4bb7c769 2086 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
c5340e82 2087 nHPEntries++;
2088 }
44e45fac 2089 }
2090 }
2091
7e6f5523 2092 Log(Form("Hall Probes = %d ", nHPEntries));
2093 return nHPEntries;
17984b61 2094}
2095
44e45fac 2096//_________________________________________________________________________
2097
39e3007b 2098AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
2099
2100
2101 //
2102 // returning Spline Fit
2103 //
44e45fac 2104
2105 Int_t entriesarray = array->GetEntries();
2106 Float_t* value = new Float_t[entriesarray];
2107 Float_t* time = new Float_t[entriesarray];
2108 AliDCSValue* v = 0x0;
2109 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
2110 v = (AliDCSValue*)array->At(iarray);
2111 value[iarray] = v->GetFloat();
2112 time[iarray] = v->GetTimeStamp();
e75e6e01 2113 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
44e45fac 2114 }
2115 TGraph* gr = new TGraph(entriesarray,value,time);
2116 if (!gr ) {
2117 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
2118 return NULL;
2119 }
2120 AliSplineFit *fit = new AliSplineFit();
2121 fit->SetMinPoints(10);
2122 fit->InitKnots(gr,10,10,0.0);
2123 fit->SplineFit(2);
2124 fit->Cleanup();
44e45fac 2125 return fit;
48b1b444 2126}
2127
44e45fac 2128//_________________________________________________________________________
2129
39e3007b 2130TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
e7a6790f 2131{
17984b61 2132
44e45fac 2133 //
2134 // processing char
2135 //
2136
2137 TString aDCSString="";
2138
2139 AliDCSValue *v = 0x0;
2140 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2141 v = (AliDCSValue *)array->At(iCount);
26c1dff2 2142 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 2143 AliError(Form("DCS values for the parameter outside the queried interval"));
2144 continue;
2145 }
2146 if (iCount > 0) {
7e6f5523 2147 if (aDCSString != v->GetChar())
44e45fac 2148 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
2149 }
2150 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
2151 }
2152 return aDCSString;
2153}
e7a6790f 2154
44e45fac 2155//__________________________________________________________________________________________________________________
e7a6790f 2156
39e3007b 2157Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
44e45fac 2158{
2159 //
2160 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2161 //
2162 // parameters[0] = mean
2163 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2164 // parameters[2] = median
2165 // parameters[3] = standard deviation wrt mean
2166 // parameters[4] = standard deviation wrt median
2167 //
2168
28131b57 2169 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2170 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2171 if (timeStartString.IsNull() || timeStartString.IsNull()){
2172 if (timeStartString.IsNull()){
2173 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2174 }
2175 else if (timeStartString.IsNull()){
2176 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2177 }
5fbf7677 2178 fdaqStartEndTimeOk = kFALSE;
28131b57 2179 return 0;
2180 }
2181
2182 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2183 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
5138cd05 2184 Float_t* parameters = new Float_t[5];
44e45fac 2185 Int_t iCounts = 0;
28131b57 2186 Int_t iCountsRun = 0;
44e45fac 2187 Int_t nCounts = array->GetEntries();
28131b57 2188 Float_t valueBeforeSOR = 0;
2189 Float_t valueAfterEOR = 0;
2190 Int_t timestampBeforeSOR = -1;
2191 Int_t timestampAfterEOR = -1;
2192 Int_t ientrySOR = -1;
2193 Int_t ientryEOR = -1;
2194 Float_t* arrayValues = 0x0;
2195 Double_t* arrayWeights = 0x0;
2196 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
5fbf7677 2197 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2198
44e45fac 2199 for(Int_t i = 0; i < nCounts; i++) {
2200 AliDCSValue *v = (AliDCSValue *)array->At(i);
fe726709 2201 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2202 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2203 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2204 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
24f67180 2205 delete [] parameters;
fe726709 2206 return NULL;
2207 }
2208 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2209 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
fe726709 2210 iCounts += 1;
28131b57 2211 // look for the last value before SOR and the first value before EOR
2212 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2213 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2214 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2215 valueBeforeSOR = v->GetFloat();
2216 }
2217 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2218 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2219 valueAfterEOR = v->GetFloat();
2220 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2221 }
2222 // check if there are DPs between DAQ_time_start and DAQ_time_end
2223 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2224 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2225 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2226 AliDebug(2,Form("entry between SOR and EOR"));
2227 iCountsRun += 1;
2228 }
fe726709 2229 }
2230 else {
28131b57 2231 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
fe726709 2232 }
2233 }
2234
28131b57 2235 if (timestampBeforeSOR == -1){
df1faeb3 2236 AliWarning("No value found before SOR");
28131b57 2237 }
2238 if (timestampAfterEOR == -1){
df1faeb3 2239 AliWarning("No value found after EOR");
28131b57 2240 }
2241
2242 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
2243 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2244 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2245 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2246 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2247 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2248
2249 Int_t nentriesUsed = 0;
2250 if (iCountsRun > 1){
2251 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2252 AliDebug(2,"Calculating (weighted) Mean and Median");
2253 arrayValues = new Float_t[iCountsRun];
2254 arrayWeights = new Double_t[iCountsRun];
2255 nentriesUsed = iCountsRun;
2256 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
fe726709 2257 AliDCSValue *v = (AliDCSValue *)array->At(i);
28131b57 2258 Int_t timestamp2 = 0;
2259 if (i < ientryEOR){
2260 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2261 timestamp2 = (Int_t)v1->GetTimeStamp();
fe726709 2262 }
28131b57 2263 else {
2264 timestamp2 = timeEnd+1;
2265 }
2266 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2267 arrayValues[i-ientrySOR] = v->GetFloat();
fe726709 2268 }
28131b57 2269 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2270 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2271 }
2272 else if (iCountsRun == 1){
2273 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2274 nentriesUsed = 2;
2275 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2276 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.");
2277 arrayValues = new Float_t[2];
2278 arrayWeights = new Double_t[2];
2279 arrayValues[0] = valueBeforeSOR;
2280 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2281 arrayValues[1] = v->GetFloat();
2282 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2283 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2284 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2285 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2286 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2287 truncMeanFlag = kFALSE;
fe726709 2288 }
2289 else{
28131b57 2290 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");
2291 parameters[0] = AliGRPObject::GetInvalidFloat();
2292 parameters[1] = AliGRPObject::GetInvalidFloat();
2293 parameters[2] = AliGRPObject::GetInvalidFloat();
2294 parameters[3] = AliGRPObject::GetInvalidFloat();
2295 parameters[4] = AliGRPObject::GetInvalidFloat();
2296 return parameters;
fe726709 2297 }
2298 }
5fbf7677 2299 else { // iCountsRun == 0, using only the point immediately before SOR
2300 if (timestampBeforeSOR == -1){
2301 AliError("Cannot set mean, truncated mean, median, SD wrt mean, SD wrt median for current DP - no points during the run collected, and point before SOR missing");
28131b57 2302 parameters[0] = AliGRPObject::GetInvalidFloat();
2303 parameters[1] = AliGRPObject::GetInvalidFloat();
2304 parameters[2] = AliGRPObject::GetInvalidFloat();
2305 parameters[3] = AliGRPObject::GetInvalidFloat();
2306 parameters[4] = AliGRPObject::GetInvalidFloat();
2307 return parameters;
2308 }
2309 else {
5fbf7677 2310 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
2311 AliDebug(2,Form("value = %f",valueBeforeSOR));
2312 parameters[0] = valueBeforeSOR;
2313 parameters[2] = valueBeforeSOR;
28131b57 2314 truncMeanFlag = kFALSE;
5fbf7677 2315 sdFlag = kFALSE;
28131b57 2316 }
2317 }
2318
2319 Float_t temp = 0;
2320 Float_t temp1 = 0;
2321 Float_t sumweights = 0;
2322 Int_t entriesTruncMean = 0;
2323 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
2324 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2325
2326 // calculating SD wrt Mean and Median
2327 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
5fbf7677 2328 if (sdFlag){
2329 for (Int_t i =0; i< nentriesUsed; i++){
df1faeb3 2330 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
5fbf7677 2331 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2332 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2333 sumweights += arrayWeights[i];
2334 }
2335 // setting SD wrt Mean
2336 if (sumweights != 0 ){
2337 parameters[3] = TMath::Sqrt(temp1/sumweights);
2338 }
2339 else {
2340 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
2341 parameters[3] = AliGRPObject::GetInvalidFloat();
2342 }
2343 // setting SD wrt Median
2344 if (nentriesUsed != 0){
2345 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2346 }
2347 else{
2348 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
2349 parameters[4] = AliGRPObject::GetInvalidFloat();
2350 }
28131b57 2351 }
fe726709 2352 else {
28131b57 2353 parameters[3] = AliGRPObject::GetInvalidFloat();
28131b57 2354 parameters[4] = AliGRPObject::GetInvalidFloat();
5fbf7677 2355 }
fe726709 2356
28131b57 2357 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2358 if (truncMeanFlag){
2359 AliDebug(2,"Calculating Truncated Mean");
2360 for (Int_t i =0; i< nentriesUsed; i++){
df1faeb3 2361 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
28131b57 2362 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
df1faeb3 2363 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2364 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2365 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
28131b57 2366 entriesTruncMean++;
df1faeb3 2367 }
2368 else{
2369 AliDebug(2,"Discarding entry");
28131b57 2370 }
2371 }
2372 // setting truncated mean
2373 if (entriesTruncMean >1){
2374 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
2375 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2376 }
2377 else{
2378 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
2379 parameters[1] = AliGRPObject::GetInvalidFloat();
2380 }
2381 }
2382 else{
2383 parameters[1] = AliGRPObject::GetInvalidFloat();
2384 }
fe726709 2385
24f67180 2386 if (arrayValues){
2387 delete [] arrayValues;
2388 }
2389 if (arrayWeights){
2390 delete [] arrayWeights;
2391 }
2392 delete [] arrayValuesTruncMean;
2393 delete [] arrayWeightsTruncMean;
2394
28131b57 2395 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
2396 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1a3ac627 2397 AliInfo(Form("median = %f ",parameters[2]));
28131b57 2398 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
2399 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
2400
fe726709 2401 return parameters;
2402}
2403
fe726709 2404//__________________________________________________________________________________________________________________
2405
2406Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
2407{
2408 //
2409 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2410 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
ac833e7a 2411 // the flag is set according to the L3/Dipole current value
2412 // current threshold for L3 = 350 A (value provided by DCS)
2413 // current threshold for Dipole = 450 A (value provided by DCS)
fe726709 2414 //
2415 // parameters[0] = mean
2416 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2417 // parameters[2] = median
2418 // parameters[3] = standard deviation wrt mean
2419 // parameters[4] = standard deviation wrt median
2420 //
2421
2422 AliInfo(Form("indexDP = %d",indexDP));
28131b57 2423
fe726709 2424 Int_t nCounts = array->GetEntries();
fe726709 2425 for(Int_t i = 0; i < nCounts; i++) {
2426 AliDCSValue *v = (AliDCSValue *)array->At(i);
2427 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2428 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
535c05eb 2429 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2430 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
fe726709 2431 return NULL;
2432 }
26c1dff2 2433 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2434 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
ac833e7a 2435 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2436 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
fe726709 2437 }
2438 else {
2439 AliError(Form("DCS values for the parameter outside the queried interval"));
44e45fac 2440 }
2441 }
2442
28131b57 2443 return ProcessFloatAll(array);
44e45fac 2444}
125567f8 2445
e97cc90e 2446
44e45fac 2447//_______________________________________________________________
e97cc90e 2448
fe726709 2449Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
44e45fac 2450{
2451 //
2452 // processing Boolean values
2453 //
2454
2455 Bool_t aDCSBool = kTRUE;
2456
2457 AliDCSValue *v = 0x0;
26c1dff2 2458
44e45fac 2459 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2460 v = (AliDCSValue *)array->At(iCount);
26c1dff2 2461 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 2462 AliError(Form("DCS values for the parameter outside the queried interval"));
2463 continue;
2464 }
2465 if (iCount > 0) {
01920f0c 2466 if (aDCSBool != v->GetBool()) {
2467 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2468 change = kTRUE;
2469 }
44e45fac 2470 }
2471 aDCSBool = v->GetBool(); // always keeping last value
26c1dff2 2472 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
44e45fac 2473 }
2474
26c1dff2 2475 Char_t caDCSBool = (Char_t) aDCSBool;
44e45fac 2476 return caDCSBool;
2477
2478}
e97cc90e 2479
44e45fac 2480//_______________________________________________________________
e97cc90e 2481
39e3007b 2482Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
44e45fac 2483{
2484 //
2485 // processing Int values, returning mean
fe726709 2486 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2487 // are outside the queried time interval or their value is out of range
44e45fac 2488 //
2489
28131b57 2490 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2491 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2492 if (timeStartString.IsNull() || timeStartString.IsNull()){
2493 if (timeStartString.IsNull()){
2494 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2495 }
2496 else if (timeStartString.IsNull()){
2497 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2498 }
2499 return 0;
2500 }
2501
2502 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2503 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
44e45fac 2504 Float_t aDCSArrayMean = 0.0;
2505 Int_t iCounts = 0;
28131b57 2506 Float_t valueBeforeSOR = 0;
2507 Float_t valueAfterEOR = 0;
2508 Int_t timestampBeforeSOR = -1;
2509 Int_t timestampAfterEOR = -1;
2510 Int_t ientrySOR = -1;
2511 Int_t ientryEOR = -1;
2512 Float_t* arrayValues = 0x0;
2513 Double_t* arrayWeights = 0x0;
2514 Int_t iCountsRun = 0;
2515 Int_t nCounts = array->GetEntries();
44e45fac 2516
28131b57 2517 for(Int_t i = 0; i < nCounts; i++) {
dd5ac86b 2518 AliDCSValue* v = (AliDCSValue *)array->At(i);
fe726709 2519 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
28131b57 2520 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
fe726709 2521 return AliGRPObject::GetInvalidFloat();
2522 }
26c1dff2 2523 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2524 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
44e45fac 2525 iCounts += 1;
28131b57 2526 // look for the last value before SOR and the first value before EOR
2527 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2528 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2529 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2530 valueBeforeSOR = (Float_t) v->GetInt();
2531 }
2532 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2533 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2534 valueAfterEOR = (Float_t) v->GetInt();
2535 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2536 }
2537 // check if there are DPs between DAQ_time_start and DAQ_time_end
2538 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2539 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2540 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2541 AliDebug(2,Form("entry between SOR and EOR"));
2542 iCountsRun += 1;
2543 }
2544 }
2545 else {
2546 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
44e45fac 2547 }
2548 }
2549
28131b57 2550 if (timestampBeforeSOR == -1){
2551 AliWarning("No value found before SOR!");
2552 }
2553 if (timestampAfterEOR == -1){
2554 AliWarning("No value found after EOR!");
2555 }
2556
2557 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2558 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2559 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2560 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2561 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2562 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2563
2564 Int_t nentriesUsed = 0;
2565 if (iCountsRun > 1){
2566 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2567 AliDebug(2,"Calculating (weighted) Mean");
2568 arrayValues = new Float_t[iCountsRun];
2569 arrayWeights = new Double_t[iCountsRun];
2570 nentriesUsed = iCountsRun;
2571 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2572 AliDCSValue *v = (AliDCSValue *)array->At(i);
2573 Int_t timestamp2 = 0;
2574 if (i < ientryEOR){
2575 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2576 timestamp2 = (Int_t)v1->GetTimeStamp();
2577 }
2578 else {
2579 timestamp2 = timeEnd+1;
2580 }
2581 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2582 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2583 }
2584 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
24f67180 2585 delete [] arrayValues;
2586 delete [] arrayWeights;
28131b57 2587 }
2588 else if (iCountsRun == 1){
2589 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2590 nentriesUsed = 2;
2591 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2592 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2593 arrayValues = new Float_t[2];
2594 arrayWeights = new Double_t[2];
2595 arrayValues[0] = valueBeforeSOR;
2596 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2597 arrayValues[1] = (Float_t)v->GetInt();
2598 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2599 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2600 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2601 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
24f67180 2602 delete [] arrayValues;
2603 delete [] arrayWeights;
28131b57 2604 }
2605 else{
2606 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2607 return AliGRPObject::GetInvalidFloat();
2608 }
2609 }
2610 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2611 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2612 if (timestampBeforeSOR == -1){
2613 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2614 }
2615 if (timestampAfterEOR == -1){
2616 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2617 }
2618 return AliGRPObject::GetInvalidFloat();
2619 }
2620 else {
2621 AliWarning("Using last entry before SOR and first entry after EOR.");
2622 nentriesUsed = 2;
2623 arrayValues = new Float_t[2];
2624 arrayWeights = new Double_t[2];
2625 arrayValues[0] = valueBeforeSOR;
2626 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2627 arrayValues[1] = valueAfterEOR;
2628 arrayWeights[1] = 1.;
2629 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2630 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2631 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
24f67180 2632 delete [] arrayValues;
2633 delete [] arrayWeights;
28131b57 2634 }
2635 }
2636
2637 AliInfo(Form("mean = %f ", aDCSArrayMean));
44e45fac 2638 return aDCSArrayMean;
e97cc90e 2639
44e45fac 2640}
2641//_______________________________________________________________
e7a6790f 2642
39e3007b 2643Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
44e45fac 2644{
2645 //
fe726709 2646 // processing Int values, returning mean
2647 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2648 // are outside the queried time interval or their value is out of range
44e45fac 2649 //
2650
28131b57 2651 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2652 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2653 if (timeStartString.IsNull() || timeStartString.IsNull()){
2654 if (timeStartString.IsNull()){
2655 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2656 }
2657 else if (timeStartString.IsNull()){
2658 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2659 }
2660 return 0;
2661 }
2662
2663 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2664 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
44e45fac 2665 Float_t aDCSArrayMean = 0.0;
2666 Int_t iCounts = 0;
28131b57 2667 Float_t valueBeforeSOR = 0;
2668 Float_t valueAfterEOR = 0;
2669 Int_t timestampBeforeSOR = -1;
2670 Int_t timestampAfterEOR = -1;
2671 Int_t ientrySOR = -1;
2672 Int_t ientryEOR = -1;
2673 Float_t* arrayValues = 0x0;
2674 Double_t* arrayWeights = 0x0;
2675 Int_t iCountsRun = 0;
2676 Int_t nCounts = array->GetEntries();
44e45fac 2677
28131b57 2678 for(Int_t i = 0; i < nCounts; i++) {
dd5ac86b 2679 AliDCSValue* v = (AliDCSValue *)array->At(i);
fe726709 2680 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
28131b57 2681 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
fe726709 2682 return AliGRPObject::GetInvalidFloat();
2683 }
26c1dff2 2684 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2685 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
44e45fac 2686 iCounts += 1;
28131b57 2687 // look for the last value before SOR and the first value before EOR
2688 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2689 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2690 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2691 valueBeforeSOR = (Float_t)v->GetUInt();
2692 }
2693 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2694 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2695 valueAfterEOR = (Float_t)v->GetUInt();
2696 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2697 }
2698 // check if there are DPs between DAQ_time_start and DAQ_time_end
2699 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2700 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2701 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2702 AliDebug(2,Form("entry between SOR and EOR"));
2703 iCountsRun += 1;
2704 }
2705 }
2706 else {
2707 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
44e45fac 2708 }
2709 }
2710
28131b57 2711 if (timestampBeforeSOR == -1){
2712 AliWarning("No value found before SOR!");
2713 }
2714 if (timestampAfterEOR == -1){
2715 AliWarning("No value found after EOR!");
2716 }
2717
2718 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2719 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2720 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2721 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2722 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2723 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2724
2725 Int_t nentriesUsed = 0;
2726 if (iCountsRun > 1){
2727 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2728 AliDebug(2,"Calculating (weighted) Mean");
2729 arrayValues = new Float_t[iCountsRun];
2730 arrayWeights = new Double_t[iCountsRun];
2731 nentriesUsed = iCountsRun;
2732 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2733 AliDCSValue *v = (AliDCSValue *)array->At(i);
2734 Int_t timestamp2 = 0;
2735 if (i < ientryEOR){
2736 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2737 timestamp2 = (Int_t)v1->GetTimeStamp();
2738 }
2739 else {
2740 timestamp2 = timeEnd+1;
2741 }
2742 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2743 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2744 }
611435c2 2745 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
84c9e12a 2746 delete [] arrayValues;
2747 delete [] arrayWeights;
28131b57 2748 }
2749 else if (iCountsRun == 1){
2750 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2751 nentriesUsed = 2;
2752 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2753 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2754 arrayValues = new Float_t[2];
2755 arrayWeights = new Double_t[2];
2756 arrayValues[0] = valueBeforeSOR;
2757 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2758 arrayValues[1] = (Float_t)v->GetUInt();
2759 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2760 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2761 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2762 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
24f67180 2763 delete [] arrayValues;
2764 delete [] arrayWeights;
28131b57 2765 }
2766 else{
2767 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2768 return AliGRPObject::GetInvalidFloat();
2769 }
2770 }
2771 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2772 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2773 if (timestampBeforeSOR == -1){
2774 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2775 }
2776 if (timestampAfterEOR == -1){
2777 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2778 }
2779 return AliGRPObject::GetInvalidFloat();
2780 }
2781 else {
2782 AliWarning("Using last entry before SOR and first entry after EOR.");
2783 nentriesUsed = 2;
2784 arrayValues = new Float_t[2];
2785 arrayWeights = new Double_t[2];
2786 arrayValues[0] = valueBeforeSOR;
2787 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2788 arrayValues[1] = valueAfterEOR;
2789 arrayWeights[1] = 1.;
2790 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2791 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2792 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
24f67180 2793 delete [] arrayValues;
2794 delete [] arrayWeights;
28131b57 2795 }
2796 }
2797
2798 AliInfo(Form("mean = %f ",aDCSArrayMean));
44e45fac 2799 return aDCSArrayMean;
e7a6790f 2800
17984b61 2801}
125567f8 2802
44e45fac 2803
17984b61 2804//_______________________________________________________________
44e45fac 2805
3ba92a38 2806AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
e7a6790f 2807{
44e45fac 2808 // extract DCS pressure maps. Perform fits to save space
2809
44e45fac 2810 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2811 if (map) {
d7edf69d 2812 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
44e45fac 2813 fPressure->MakeSplineFit(map);
2814 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2815 if (fitFraction > kFitFraction ) {
ce996d13 2816 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
44e45fac 2817 } else {
2818 AliInfo("Too few pressure maps fitted!!!");
2819 }
2820 } else {
2821 AliInfo("no atmospheric pressure map extracted!!!");
2822 }
2823 delete map;
2824
2825 return fPressure;
17984b61 2826}
e97cc90e 2827
1e27bb6b 2828
2829
2830//_______________________________________________________________
03e5ee4f 2831Int_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 2832{
44e45fac 2833 //
2834 // Retrieves logbook and trigger information from the online logbook
2835 // This information is needed for prompt reconstruction
2836 //
2837 // Parameters are:
2838 // Run number
2839 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2840 // cdbRoot
2841 //
2842 // returns:
2843 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2844 // 0 on success and no run was found
2845 // negative on error
2846 //
2847 // This function is NOT called during the preprocessor run in the Shuttle!
2848 //
2849
2850 // defaults
2851 if (dbPort == 0)
2852 dbPort = 3306;
2853
2854 // CDB connection
2855 AliCDBManager* cdb = AliCDBManager::Instance();
2856 cdb->SetDefaultStorage(cdbRoot);
2857
2858 // SQL connection
2859 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2860
2861 if (!server)
2862 {
2863 Printf("ERROR: Could not connect to DAQ LB");
2864 return -1;
2865 }
2866
2867 // main logbook
2868 TString sqlQuery;
5d43966f 2869 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
44e45fac 2870 TSQLResult* result = server->Query(sqlQuery);
2871 if (!result)
2872 {
2873 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2874 return -2;
2875 }
2876
2877 if (result->GetRowCount() == 0)
2878 {
2879 Printf("ERROR: Run %d not found", run);
2880 delete result;
2881 return -3;
2882 }
2883
2884 TSQLRow* row = result->Next();
2885 if (!row)
2886 {
2887 Printf("ERROR: Could not receive data from run %d", run);
2888 delete result;
2889 return -4;
2890 }
2891
26c1dff2 2892 TString timeStartString(row->GetField(0));
44e45fac 2893 TString runType(row->GetField(1));
26c1dff2 2894 TString detectorMaskString(row->GetField(2));
2895 TString l3CurrentString(row->GetField(3));
2896 TString dipoleCurrentString(row->GetField(4));
5d43966f 2897 TString beamTypeString(row->GetField(5));
26c1dff2 2898 time_t timeStart = (time_t)(timeStartString.Atoi());
2899 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2900 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2901 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
03e5ee4f 2902 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2903 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
9f08228b 2904 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
2905 beamTypeString="A-A";
2906 }
44e45fac 2907
26c1dff2 2908 AliGRPObject * grpObj = new AliGRPObject();
2909 grpObj->SetTimeStart(timeStart);
2910 grpObj->SetRunType((TString)(row->GetField(1)));
2911 grpObj->SetDetectorMask(detectorMask);
2912 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2913 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
03e5ee4f 2914 grpObj->SetL3Polarity(l3Polarity);
2915 grpObj->SetDipolePolarity(dipolePolarity);
48fcacdc 2916 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
9f08228b 2917 grpObj->SetBeamType(beamTypeString);
26c1dff2 2918
44e45fac 2919 delete row;
2920 row = 0;
2921
2922 delete result;
2923 result = 0;
2924
2925 Printf("Storing GRP/GRP/Data object with the following content");
26c1dff2 2926 grpObj->Dump();
44e45fac 2927
2928 AliCDBMetaData metadata;
26c1dff2 2929 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
44e45fac 2930 metadata.SetComment("GRP Output parameters received during online running");
2931
2932 AliCDBId id("GRP/GRP/Data", run, run);
26c1dff2 2933 Bool_t success = cdb->Put(grpObj, id, &metadata);
44e45fac 2934
26c1dff2 2935 delete grpObj;
44e45fac 2936
2937 if (!success)
2938 {
2939 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2940 return -5;
2941 }
2942
2943 // Receive trigger information
2944 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2945 result = server->Query(sqlQuery);
2946 if (!result)
2947 {
2948 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2949 return -11;
2950 }
2951
2952 if (result->GetRowCount() == 0)
2953 {
2954 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2955 delete result;
2956 return -12;
2957 }
2958
2959 row = result->Next();
2960 if (!row)
2961 {
2962 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2963 delete result;
2964 return -13;
2965 }
2966
2967 TString triggerConfig(row->GetField(0));
2968
2969 delete row;
2970 row = 0;
2971
2972 delete result;
2973 result = 0;
2974
2975 Printf("Found trigger configuration: %s", triggerConfig.Data());
2976
2977 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2978 if (!runcfg)
2979 {
2980 Printf("ERROR: Could not create CTP configuration object");
2981 return -14;
2982 }
2983
2984 metadata.SetComment("CTP run configuration received during online running");
2985
2986 AliCDBId id2("GRP/CTP/Config", run, run);
2987 success = cdb->Put(runcfg, id2, &metadata);
2988
2989 delete runcfg;
2990 runcfg = 0;
2991
2992 if (!success)
2993 {
2994 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2995 return -15;
2996 }
2997
03e5ee4f 2998
2999 // Receive list of GDCs for this run
3000 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
3001 result = server->Query(sqlQuery);
3002 if (!result)
3003 {
3004 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3005 return -24;
3006 }
3007
3008 if (result->GetRowCount() == 0)
3009 {
3010 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
3011 delete result;
3012 return -25;
3013 }
2b81b7d0 3014
3015 gdc = "";
3016 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
3017 row = result->Next();
3018 if (!row)
3019 {
3020 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
3021 delete result;
3022 return -26;
3023 }
3024 gdc += row->GetField(0);
3025 gdc += " ";
3026 }
3027
03e5ee4f 3028 delete row;
3029 row = 0;
3030
3031 delete result;
3032 result = 0;
3033
3034 Printf("Found GDC: %s", gdc.Data());
3035
44e45fac 3036 // get last run with same run type that was already processed by the SHUTTLE
3037
3038 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());
3039 result = server->Query(sqlQuery);
3040 if (!result)
3041 {
3042 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3043 return -21;
3044 }
3045
3046 if (result->GetRowCount() == 0)
3047 {
3048 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
3049 delete result;
3050 return -22;
3051 }
3052
3053 row = result->Next();
3054 if (!row)
3055 {
3056 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
3057 delete result;
3058 return -23;
3059 }
3060
3061 TString lastRunStr(row->GetField(0));
3062 Int_t lastRun = lastRunStr.Atoi();
3063
3064 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
3065
3066 delete row;
3067 row = 0;
3068
3069 delete result;
3070 result = 0;
3071
3072 server->Close();
3073 delete server;
3074 server = 0;
3075
3076 return lastRun;
1e27bb6b 3077}
0254e751 3078//------------------------------------------------------------------------------------------------------
4cbf81c1 3079Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
0254e751 3080
3081 //
3082 // Method to processo LHC Energy information
3083 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
3084 //
3085
3086 Int_t nCounts = array->GetEntries();
3087 Float_t energy = -1;
4cbf81c1 3088 Double_t timeEnergy = -1;
3089 Int_t indexEnergy = -1;
3090 Bool_t foundEnergy = kFALSE;
3091
0254e751 3092 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
0d361338 3093 if (nCounts ==0){
3094 AliWarning("No Energy values found! Beam Energy remaining invalid!");
3095 }
3096 else{
4cbf81c1 3097 for (Int_t i = 0; i < nCounts; i++){
0d361338 3098 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
4cbf81c1 3099 if (dcs){
3100 if (dcs->GetTimeStamp()<=timeStart && dcs->GetTimeStamp()>=timeEnergy){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
3101 timeEnergy = dcs->GetTimeStamp();
3102 indexEnergy = i;
3103 foundEnergy = kTRUE;
3104 }
3105 else{
3106 break;
3107 }
0d361338 3108 }
0254e751 3109 }
4cbf81c1 3110 if (!foundEnergy){
3111 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
3112 }
3113 else {
3114 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
3115 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
3116 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
e541e2aa 3117 }
0254e751 3118 }
3119
3120 return energy;
3121}
8c1f1006 3122//------------------------------------------------------------------------------------------------------
17fd2848 3123AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
8c1f1006 3124{
3125 //
3126 // Method to process LHC-Clock Phase data
3127 // Only the values between DAQ_time_start and DAQ_time_end are kept
3128 //
3129 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
3130
3131 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
0c191635 3132 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
8c1f1006 3133
17fd2848 3134 TString timeCreatedStr = GetRunParameter("time_created");
3135 Double_t timeCreated = timeCreatedStr.Atof();
3136
8c1f1006 3137 Int_t nCounts = beam1phase->GetEntries();
3138 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
3139 if (nCounts ==0){
3140 AliWarning("No beam1 LHC clock phase values found!");
3141 delete phaseObj;
3142 return NULL;
3143 }
3144 else{
0c191635 3145 Double_t prevPhase = 0;
8c1f1006 3146 for (Int_t i = 0; i < nCounts; i++){
3147 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
3148 if (dcs){
f1226569 3149 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
3150 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
0c191635 3151 if ((i == 0) || (i == (nCounts-1)) ||
3152 !foundBeam1Phase ||
3153 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3154 prevPhase = dcs->GetDouble(0);
3155 foundBeam1Phase = kTRUE;
3156 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
3157 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3158 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3159 }
8c1f1006 3160 }
3161 }
3162 }
3163 if (!foundBeam1Phase){
3164 AliError("No beam1 LHC clock phase values found within the run!");
3165 delete phaseObj;
3166 return NULL;
3167 }
3168 }
3169
3170 nCounts = beam2phase->GetEntries();
3171 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
3172 if (nCounts ==0){
3173 AliWarning("No beam2 LHC clock phase values found!");
3174 delete phaseObj;
3175 return NULL;
3176 }
3177 else{
0c191635 3178 Double_t prevPhase = 0;
8c1f1006 3179 for (Int_t i = 0; i < nCounts; i++){
3180 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
3181 if (dcs){
17fd2848 3182 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
0c191635 3183 if ((i == 0) || (i == (nCounts-1)) ||
3184 !foundBeam2Phase ||
3185 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3186 prevPhase = dcs->GetDouble(0);
3187 foundBeam2Phase = kTRUE;
3188 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
3189 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3190 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3191 }
8c1f1006 3192 }
3193 }
3194 }
3195 if (!foundBeam2Phase){
3196 AliError("No beam2 LHC clock phase values found within the run!");
3197 delete phaseObj;
3198 return NULL;
3199 }
3200 }
3201
3202 return phaseObj;
3203}
81a1addb 3204//------------------------------------------------------------------------------------------------------
3205TString AliGRPPreprocessor::ParseBeamTypeString(TString beamType, Int_t iBeamType)
3206{
3207 // Method to return the convention for the separate beam type
3208 // in the form A*1000+Z
3209 // e.g.: Pb82 --> 208000 + 82 = 208082
3210 // p --> 1000 + 1 = 1001
3211
3212 Int_t a = 0;
3213 Int_t z = 0;
3214 TString separateString("");
3215 Log(Form("Setting Beam Type for beam %d to A*1000+Z",iBeamType));
3216 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
3217 Log(Form("Beam type %d is PROTON --> The single beam type will be set to 1001 (A = 1, Z = 1)",iBeamType));
3218 separateString = "1001";
3219 return separateString;
3220 }
3221 else {
3222 TPRegexp regexpA("\\D+");
3223 TPRegexp regexpZ("\\d+");
3224 TObjArray* arrayA = regexpA.MatchS(beamType);
3225 TObjArray* arrayZ = regexpZ.MatchS(beamType);
3226 if (arrayA->GetEntries() != 1 || arrayZ->GetEntries() != 1){
3227 Log(Form("The beamType string for beam %d does not contain the necessary information! Returning the info as published by LHC (i.e. %s)",iBeamType, beamType.Data()));
3228 return beamType;
3229 }
3230 else{
3231 TString strA = ((TObjString*)(arrayA->At(0)))->String();
3232 TString strZ = ((TObjString*)(arrayZ->At(0)))->String();
3233 if (strA.CompareTo("LEAD",TString::kIgnoreCase) == 0 || strA.CompareTo("PB",TString::kIgnoreCase) == 0){
3234 Log(Form("Beam %d is %s --> A = 208",iBeamType, strA.Data()));
3235 a = 208;
3236 }
3237 else{
3238 Log(Form("This beam was not foreseen so far, leaving A=0"));
3239 }
3240 z = strZ.Atoi();
3241 Log(Form("Beam %d has Z = %d",iBeamType, z));
3242 separateString = Form("%d",a*1000+z);
3243 return separateString;
3244 }
3245 }
3246
3247 return separateString;
3248
3249}
3250