]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEER/AliGRPPreprocessor.cxx
New event header version. Has to be ported to the releases.
[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
b995faec 1557 AliRawEventHeaderV3_13::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_13 - temporary fix
16c237c6 1558 Log("Processing DAQ FXS");
1559 TList* list = GetFileSources(kDAQ);
44e45fac 1560 if (!list) {
1561 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1562 return 1;
1563 }
1564
1565 if (list->GetEntries() == 0) {
1566 Log("no raw data tags in this run: nothing to merge!");
1567 delete list; list=0;
1568 return 0;
1569 }
1570
1571 TChain *fRawTagChain = new TChain("T");
1572 Int_t nFiles=0;
1573 TIterator* iter = list->MakeIterator();
1574 TObject* obj = 0;
1575 while ((obj = iter->Next())) {
1576 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1577 if (objStr) {
1578 Log(Form("Found source %s", objStr->String().Data()));
1579 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1580 if (!list2) {
1581 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1582 delete fRawTagChain; fRawTagChain=0;
1583 return 1;
1584 }
1585 Log(Form("Number of ids: %d",list2->GetEntries()));
1586 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1587 TObjString *idStr = (TObjString *)list2->At(i);
5bc3c20c 1588 if (idStr->String().CompareTo("QAThreshold") == 0 || idStr->String().CompareTo("TriggerClassesAndHistosToClone") == 0) {
1589 Log(Form("Skipping file with Id %s",idStr->String().Data()));
1590 continue;
1591 }
44e45fac 1592 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1593 if (fileName.Length() > 0) {
1594 Log(Form("Adding file in the chain: %s",fileName.Data()));
1595 fRawTagChain->Add(fileName.Data());
1596 nFiles++;
1597 } else {
1598 Log(Form("Could not retrieve file with id %s from source %s: "
1599 "connection problems with DAQ FXS!",
1600 idStr->String().Data(), objStr->String().Data()));
1601 delete list; list=0;
1602 delete list2; list2=0;
1603 delete fRawTagChain; fRawTagChain=0;
1604 return 2;
1605 }
1606 }
1607 delete list2;
1608 }
1609 }
16c237c6 1610
1611 if (nFiles == 0){
1612 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 1613 delete iter;
1614 iter = 0;
1615 delete list;
1616 list = 0;
1617 delete fRawTagChain;
1618 fRawTagChain=0;
16c237c6 1619 return 0;
1620 }
44e45fac 1621
1622 TString fRawDataFileName = "GRP_Merged.tag.root";
1623 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
7e6f5523 1624
16c237c6 1625 if (fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1626 Log(Form("Error merging %d raw data files!!!",nFiles));
166b08b9 1627 delete iter;
1628 iter = 0;
1629 delete list;
1630 list = 0;
1631 delete fRawTagChain;
1632 fRawTagChain=0;
44e45fac 1633 return 3;
1634 }
16c237c6 1635
44e45fac 1636 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1637 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1638
1639 if (!result) {
1640 Log("Problem storing raw data tags in local file!!!");
1641 } else {
1642 Log("Raw data tags merged successfully!!");
1643 }
1644
1645 delete iter;
166b08b9 1646 iter = 0;
44e45fac 1647 delete list;
166b08b9 1648 list = 0;
44e45fac 1649 delete fRawTagChain; fRawTagChain=0;
1650
1651 if (result == kFALSE) {
1652 return 4;
1653 }
1654
1655 return 0;
1656
1657}
17984b61 1658
44e45fac 1659//_______________________________________________________________
e75e6e01 1660UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
44e45fac 1661{
39e3007b 1662
1663 // processing the info
1664 // stored in the DCS FXS
1665 // coming from the trigger
1666
e75e6e01 1667 // Get the CTP counters information
1668
1669 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
161a4dc3 1670 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
e75e6e01 1671 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1672 if (!cdbEntry) {
1673 Log(Form("No dummy CTP scalers entry found, going into error..."));
44e45fac 1674 return 1;
1675 }
e75e6e01 1676 else{
1677 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1678 if (!scalers){
1679 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1680 return 1;
1681 }
1682 else {
1683 AliCDBMetaData metaData;
1684 metaData.SetResponsible("Roman Lietava");
1685 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1686 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1687 Log("Unable to store the dummy CTP scalers object to OCDB!");
1688 return 1;
1689 }
1690 }
1691 }
1692 }
1693
1694 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1695 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1696 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1697 if (countersfile.IsNull()) {
1698 Log("No CTP counters files has been found: empty source!");
44e45fac 1699 return 1;
1700 }
1701 else {
e75e6e01 1702 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1703 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1704 if (!scalers) {
1705 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1706 return 1;
1707 }
1708 else {
1709 AliCDBMetaData metaData;
1710 metaData.SetBeamPeriod(0);
1711 metaData.SetResponsible("Roman Lietava");
1712 metaData.SetComment("CTP scalers");
1713 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1714 Log("Unable to store the CTP scalers object to OCDB!");
e541e2aa 1715 delete scalers;
e75e6e01 1716 return 1;
44e45fac 1717 }
1718 }
e541e2aa 1719 delete scalers;
44e45fac 1720 }
44e45fac 1721 }
1722
e75e6e01 1723
1724 else{
1725 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1726 return 2;
1727 }
1728
44e45fac 1729 return 0;
e75e6e01 1730
44e45fac 1731}
1732//_______________________________________________________________
17984b61 1733
44e45fac 1734Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1735{
17984b61 1736
44e45fac 1737 //
1738 // processing DCS DPs
1739 //
1740
26c1dff2 1741 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
44e45fac 1742 Int_t nL3Entries = 0;
1743 Int_t nDipoleEntries = 0;
1744 Int_t nEnvEntries = 0;
1745 Int_t nHallProbesEntries = 0;
44e45fac 1746 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1747 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1748 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1749 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
fab61587 1750 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
0254e751 1751 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1752 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
44e45fac 1753 return entries;
17984b61 1754
17984b61 1755}
1756
1757//_______________________________________________________________
29cc8704 1758
39e3007b 1759Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 1760{
39e3007b 1761
1762 // processing DPs
1763 // related to
1764 // L3 info
1765
44e45fac 1766 Int_t nL3Entries = 0;
c5340e82 1767
44e45fac 1768 TObjArray *array = 0x0;
1769 Int_t indexDP = -1;
fe726709 1770 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
44e45fac 1771
fe726709 1772 AliInfo(Form("==========L3Current==========="));
1773 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1774 indexDP = kL3Current;
44e45fac 1775 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1776 if(!array) {
1777 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1778 }
1779 else {
26c1dff2 1780 if (array->GetEntries() == 0){
fe726709 1781 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
26c1dff2 1782 }
1783 else {
fe726709 1784 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1785 if (floatDCS != NULL){
1786 grpObj->SetL3Current(floatDCS);
1787 }
1788 else{
1789 outOfRange = kTRUE;
1790 }
03672227 1791 if (floatDCS){
1792 delete[] floatDCS;
1793 floatDCS = 0x0;
1794 }
26c1dff2 1795 }
c5340e82 1796 if (!outOfRange) {
1797 nL3Entries++;
1798 ffailedDPs->RemoveAt(indexDP);
1799 }
44e45fac 1800 }
1801
1802 if (array) array = 0x0;
1803
fe726709 1804 AliInfo(Form("==========L3Polarity==========="));
1805 indexDP = kL3Polarity;
44e45fac 1806 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1807 if(!array) {
1808 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1809 }
1810 else {
26c1dff2 1811 if (array->GetEntries() == 0){
fe726709 1812 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
26c1dff2 1813 }
1814 else {
fe726709 1815 Bool_t change = kFALSE;
1816 Char_t charDCS = ProcessBool(array,change);
01920f0c 1817 if (change == kFALSE){
fe726709 1818 grpObj->SetL3Polarity(charDCS);
1819 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
c5340e82 1820 ffailedDPs->RemoveAt(indexDP);
fe726709 1821 nL3Entries++;
1822 }
1823 else if (isZero){
ac833e7a 1824 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
c5340e82 1825 ffailedDPs->RemoveAt(indexDP);
fe726709 1826 nL3Entries++;
1827 }
1828 else {
ac833e7a 1829 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 1830 }
26c1dff2 1831 }
44e45fac 1832 }
1833
1834 return nL3Entries;
e7a6790f 1835
44e45fac 1836}
1837//_______________________________________________________________
ff97356e 1838
39e3007b 1839Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 1840{
39e3007b 1841 // processing DPs
1842 // related to
1843 // the Dipole info
1844
44e45fac 1845 Int_t nDipoleEntries = 0;
1846 TObjArray *array = 0x0;
1847 Int_t indexDP = -1;
fe726709 1848 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
44e45fac 1849
fe726709 1850 AliInfo(Form("==========DipoleCurrent==========="));
1851 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1852 indexDP = kDipoleCurrent;
44e45fac 1853 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
44e45fac 1854 if(!array) {
1855 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1856 }
1857 else {
26c1dff2 1858 if (array->GetEntries() == 0){
1859 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1860 }
1861 else {
fe726709 1862 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1863 if (floatDCS != NULL){
1864 grpObj->SetDipoleCurrent(floatDCS);
1865 }
1866 else{
1867 outOfRange=kTRUE;
1868 }
03672227 1869 if (floatDCS){
1870 delete[] floatDCS;
1871 floatDCS = 0x0;
1872 }
26c1dff2 1873 }
c5340e82 1874 if (!outOfRange) {
1875 nDipoleEntries++;
1876 ffailedDPs->RemoveAt(indexDP);
1877 }
44e45fac 1878 }
1879
1880 if (array) array = 0x0;
1881
fe726709 1882 AliInfo(Form("==========DipolePolarity==========="));
1883 indexDP = kDipolePolarity;
44e45fac 1884 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1885 if(!array) {
1886 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1887 }
1888 else {
26c1dff2 1889 if (array->GetEntries() == 0){
1890 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1891 }
1892 else {
fe726709 1893 Bool_t change = kFALSE;
1894 Char_t charDCS = ProcessBool(array,change);
1895 if (!change){
1896 grpObj->SetDipolePolarity(charDCS);
1897 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
c5340e82 1898 ffailedDPs->RemoveAt(indexDP);
fe726709 1899 nDipoleEntries++;
1900 }
1901 else if (isZero){
ac833e7a 1902 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
c5340e82 1903 ffailedDPs->RemoveAt(indexDP);
fe726709 1904 nDipoleEntries++;
1905 }
1906 else{
ac833e7a 1907 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 1908 }
26c1dff2 1909 }
44e45fac 1910 }
1911
1912 return nDipoleEntries;
e7a6790f 1913
44e45fac 1914}
1915//_______________________________________________________________
e7a6790f 1916
44e45fac 1917Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1918{
39e3007b 1919 // processing DPs
1920 // related to
1921 // evironment conditions (temperature, pressure) info
1922
44e45fac 1923 Int_t nEnvEntries = 0;
1924 TObjArray *array = 0x0;
1925 Int_t indexDP = -1;
1926
1927 AliInfo(Form("==========CavernTemperature==========="));
fe726709 1928 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
44e45fac 1929 indexDP = kCavernTemperature;
1930 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1931 if(!array) {
1932 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1933 }
1934 else {
26c1dff2 1935 if (array->GetEntries() == 0){
1936 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1937 }
1938 else {
1939 Float_t *floatDCS = ProcessFloatAll(array);
fe726709 1940 if (floatDCS != NULL){
1941 grpObj->SetCavernTemperature(floatDCS);
1942 }
1943 else{
1944 outOfRange = kTRUE;
1945 }
03672227 1946 if (floatDCS){
1947 delete[] floatDCS;
1948 floatDCS = 0x0;
1949 }
26c1dff2 1950 }
c5340e82 1951 if (!outOfRange) {
1952 ffailedDPs->RemoveAt(indexDP);
1953 nEnvEntries++;
1954 }
44e45fac 1955 }
1956
1957 if (array) array = 0x0;
1958
ce996d13 1959 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
44e45fac 1960 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
ce996d13 1961 //dcsSensorArray->Print();
1962 if( fPressure->NumFits()<kNumSensors ) {
d7edf69d 1963 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
44e45fac 1964 }
d7edf69d 1965 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1966
1967 AliInfo(Form("==========CavernAtmosPressure==========="));
1968 indexDP = kCavernAtmosPressure;
1969 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1970 TGraph* graph = sensorCavernP2->GetGraph();
3343d11b 1971 AliDebug(3,Form("index = %d",indexDP));
1972 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 1973 AliDebug(2,Form("graph = %p",graph));
1974 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
2a0b175e 1975 if(sensorCavernP2->GetFit() || graph) {
d7edf69d 1976 if (sensorCavernP2->GetFit()){
2a0b175e 1977 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 1978 }
44e45fac 1979 else {
2a0b175e 1980 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 1981 }
1982 grpObj->SetCavernAtmosPressure(sensorCavernP2);
c5340e82 1983 ffailedDPs->RemoveAt(indexDP);
d7edf69d 1984 nEnvEntries++;
1985 }
1986 //if (sensorP2) delete sensorP2;
1987 else {
2a0b175e 1988 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 1989 }
2a0b175e 1990
d7edf69d 1991 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1992 indexDP = kSurfaceAtmosPressure;
1993 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1994 graph = sensorP2->GetGraph();
3343d11b 1995 AliDebug(3,Form("index = %d",indexDP));
1996 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 1997 AliDebug(2,Form("graph = %p",graph));
1998 AliDebug(3,Form("sensorP2 = %p", sensorP2));
2a0b175e 1999 if(sensorP2->GetFit() || graph) {
d7edf69d 2000 if (sensorP2->GetFit()){
2a0b175e 2001 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 2002 }
44e45fac 2003 else {
2a0b175e 2004 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 2005 }
2006 grpObj->SetSurfaceAtmosPressure(sensorP2);
c5340e82 2007 ffailedDPs->RemoveAt(indexDP);
d7edf69d 2008 nEnvEntries++;
2009 }
2010 //if (sensorP2) delete sensorP2;
2011 else {
2a0b175e 2012 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 2013 }
2014
d7edf69d 2015 AliInfo(Form("==========CavernAtmosPressure2==========="));
2016 indexDP = kCavernAtmosPressure2;
2017 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
8976336c 2018 graph = sensorCavernP22->GetGraph();
3343d11b 2019 AliDebug(3,Form("index = %d",indexDP));
2020 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 2021 AliDebug(2,Form("graph = %p",graph));
2022 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
2a0b175e 2023 if(sensorCavernP22->GetFit() || graph) {
d7edf69d 2024 if (sensorCavernP22->GetFit()){
2a0b175e 2025 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 2026 }
2027 else {
2a0b175e 2028 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 2029 }
2030 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
c5340e82 2031 ffailedDPs->RemoveAt(indexDP);
d7edf69d 2032 nEnvEntries++;
2033 }
2034 //if (sensorP2) delete sensorP2;
2035 else {
2a0b175e 2036 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 2037 }
2038
2039
44e45fac 2040 return nEnvEntries;
2041}
2042//_______________________________________________________________
e7a6790f 2043
39e3007b 2044Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 2045{
39e3007b 2046 // processing DPs
2047 // related to
2048 // Hall Probes info
2049
44e45fac 2050 Int_t nHPEntries = 0;
2051 TObjArray *array = 0x0;
2052 Int_t indexDP = -1;
fe726709 2053 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
44e45fac 2054
39e3007b 2055 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
2056 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 2057 }
2058 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
fe726709 2059 outOfRange = kFALSE; // resetting outOfRange flag at each HP
44e45fac 2060 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
2061 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
2062 if(!array) {
2063 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
2064 }
2065 else {
26c1dff2 2066 if (array->GetEntries() == 0){
2067 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
2068 }
2069 else {
2070 Float_t *floatDCS = ProcessFloatAll(array);
fe726709 2071 if (floatDCS != NULL){
2072 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]));
2073 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
2074 for (Int_t kk = 0 ; kk< 5; kk++){
2075 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
2076 }
2077 }
2078 else{
2079 outOfRange = kTRUE;
26c1dff2 2080 }
03672227 2081 if (floatDCS){
2082 delete[] floatDCS;
2083 floatDCS = 0x0;
2084 }
44e45fac 2085 }
c5340e82 2086 if (!outOfRange) {
4bb7c769 2087 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
c5340e82 2088 nHPEntries++;
2089 }
44e45fac 2090 }
2091 }
2092
7e6f5523 2093 Log(Form("Hall Probes = %d ", nHPEntries));
2094 return nHPEntries;
17984b61 2095}
2096
44e45fac 2097//_________________________________________________________________________
2098
39e3007b 2099AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
2100
2101
2102 //
2103 // returning Spline Fit
2104 //
44e45fac 2105
2106 Int_t entriesarray = array->GetEntries();
2107 Float_t* value = new Float_t[entriesarray];
2108 Float_t* time = new Float_t[entriesarray];
2109 AliDCSValue* v = 0x0;
2110 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
2111 v = (AliDCSValue*)array->At(iarray);
2112 value[iarray] = v->GetFloat();
2113 time[iarray] = v->GetTimeStamp();
e75e6e01 2114 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
44e45fac 2115 }
2116 TGraph* gr = new TGraph(entriesarray,value,time);
2117 if (!gr ) {
2118 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
2119 return NULL;
2120 }
2121 AliSplineFit *fit = new AliSplineFit();
2122 fit->SetMinPoints(10);
2123 fit->InitKnots(gr,10,10,0.0);
2124 fit->SplineFit(2);
2125 fit->Cleanup();
44e45fac 2126 return fit;
48b1b444 2127}
2128
44e45fac 2129//_________________________________________________________________________
2130
39e3007b 2131TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
e7a6790f 2132{
17984b61 2133
44e45fac 2134 //
2135 // processing char
2136 //
2137
2138 TString aDCSString="";
2139
2140 AliDCSValue *v = 0x0;
2141 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2142 v = (AliDCSValue *)array->At(iCount);
26c1dff2 2143 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 2144 AliError(Form("DCS values for the parameter outside the queried interval"));
2145 continue;
2146 }
2147 if (iCount > 0) {
7e6f5523 2148 if (aDCSString != v->GetChar())
44e45fac 2149 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
2150 }
2151 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
2152 }
2153 return aDCSString;
2154}
e7a6790f 2155
44e45fac 2156//__________________________________________________________________________________________________________________
e7a6790f 2157
39e3007b 2158Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
44e45fac 2159{
2160 //
2161 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2162 //
2163 // parameters[0] = mean
2164 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2165 // parameters[2] = median
2166 // parameters[3] = standard deviation wrt mean
2167 // parameters[4] = standard deviation wrt median
2168 //
2169
28131b57 2170 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2171 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2172 if (timeStartString.IsNull() || timeStartString.IsNull()){
2173 if (timeStartString.IsNull()){
2174 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2175 }
2176 else if (timeStartString.IsNull()){
2177 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2178 }
5fbf7677 2179 fdaqStartEndTimeOk = kFALSE;
28131b57 2180 return 0;
2181 }
2182
2183 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2184 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
5138cd05 2185 Float_t* parameters = new Float_t[5];
44e45fac 2186 Int_t iCounts = 0;
28131b57 2187 Int_t iCountsRun = 0;
44e45fac 2188 Int_t nCounts = array->GetEntries();
28131b57 2189 Float_t valueBeforeSOR = 0;
2190 Float_t valueAfterEOR = 0;
2191 Int_t timestampBeforeSOR = -1;
2192 Int_t timestampAfterEOR = -1;
2193 Int_t ientrySOR = -1;
2194 Int_t ientryEOR = -1;
2195 Float_t* arrayValues = 0x0;
2196 Double_t* arrayWeights = 0x0;
2197 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
5fbf7677 2198 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2199
44e45fac 2200 for(Int_t i = 0; i < nCounts; i++) {
2201 AliDCSValue *v = (AliDCSValue *)array->At(i);
fe726709 2202 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2203 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2204 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2205 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
24f67180 2206 delete [] parameters;
fe726709 2207 return NULL;
2208 }
2209 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2210 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
fe726709 2211 iCounts += 1;
28131b57 2212 // look for the last value before SOR and the first value before EOR
2213 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2214 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2215 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2216 valueBeforeSOR = v->GetFloat();
2217 }
2218 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2219 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2220 valueAfterEOR = v->GetFloat();
2221 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2222 }
2223 // check if there are DPs between DAQ_time_start and DAQ_time_end
2224 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2225 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2226 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2227 AliDebug(2,Form("entry between SOR and EOR"));
2228 iCountsRun += 1;
2229 }
fe726709 2230 }
2231 else {
28131b57 2232 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
fe726709 2233 }
2234 }
2235
28131b57 2236 if (timestampBeforeSOR == -1){
df1faeb3 2237 AliWarning("No value found before SOR");
28131b57 2238 }
2239 if (timestampAfterEOR == -1){
df1faeb3 2240 AliWarning("No value found after EOR");
28131b57 2241 }
2242
2243 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
2244 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2245 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2246 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2247 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2248 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2249
2250 Int_t nentriesUsed = 0;
2251 if (iCountsRun > 1){
2252 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2253 AliDebug(2,"Calculating (weighted) Mean and Median");
2254 arrayValues = new Float_t[iCountsRun];
2255 arrayWeights = new Double_t[iCountsRun];
2256 nentriesUsed = iCountsRun;
2257 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
fe726709 2258 AliDCSValue *v = (AliDCSValue *)array->At(i);
28131b57 2259 Int_t timestamp2 = 0;
2260 if (i < ientryEOR){
2261 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2262 timestamp2 = (Int_t)v1->GetTimeStamp();
fe726709 2263 }
28131b57 2264 else {
2265 timestamp2 = timeEnd+1;
2266 }
2267 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2268 arrayValues[i-ientrySOR] = v->GetFloat();
fe726709 2269 }
28131b57 2270 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2271 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2272 }
2273 else if (iCountsRun == 1){
2274 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2275 nentriesUsed = 2;
2276 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2277 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.");
2278 arrayValues = new Float_t[2];
2279 arrayWeights = new Double_t[2];
2280 arrayValues[0] = valueBeforeSOR;
2281 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2282 arrayValues[1] = v->GetFloat();
2283 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2284 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2285 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2286 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2287 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2288 truncMeanFlag = kFALSE;
fe726709 2289 }
2290 else{
28131b57 2291 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");
2292 parameters[0] = AliGRPObject::GetInvalidFloat();
2293 parameters[1] = AliGRPObject::GetInvalidFloat();
2294 parameters[2] = AliGRPObject::GetInvalidFloat();
2295 parameters[3] = AliGRPObject::GetInvalidFloat();
2296 parameters[4] = AliGRPObject::GetInvalidFloat();
2297 return parameters;
fe726709 2298 }
2299 }
5fbf7677 2300 else { // iCountsRun == 0, using only the point immediately before SOR
2301 if (timestampBeforeSOR == -1){
2302 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 2303 parameters[0] = AliGRPObject::GetInvalidFloat();
2304 parameters[1] = AliGRPObject::GetInvalidFloat();
2305 parameters[2] = AliGRPObject::GetInvalidFloat();
2306 parameters[3] = AliGRPObject::GetInvalidFloat();
2307 parameters[4] = AliGRPObject::GetInvalidFloat();
2308 return parameters;
2309 }
2310 else {
5fbf7677 2311 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
2312 AliDebug(2,Form("value = %f",valueBeforeSOR));
2313 parameters[0] = valueBeforeSOR;
2314 parameters[2] = valueBeforeSOR;
28131b57 2315 truncMeanFlag = kFALSE;
5fbf7677 2316 sdFlag = kFALSE;
28131b57 2317 }
2318 }
2319
2320 Float_t temp = 0;
2321 Float_t temp1 = 0;
2322 Float_t sumweights = 0;
2323 Int_t entriesTruncMean = 0;
2324 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
2325 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2326
2327 // calculating SD wrt Mean and Median
2328 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
5fbf7677 2329 if (sdFlag){
2330 for (Int_t i =0; i< nentriesUsed; i++){
df1faeb3 2331 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
5fbf7677 2332 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2333 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2334 sumweights += arrayWeights[i];
2335 }
2336 // setting SD wrt Mean
2337 if (sumweights != 0 ){
2338 parameters[3] = TMath::Sqrt(temp1/sumweights);
2339 }
2340 else {
2341 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
2342 parameters[3] = AliGRPObject::GetInvalidFloat();
2343 }
2344 // setting SD wrt Median
2345 if (nentriesUsed != 0){
2346 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2347 }
2348 else{
2349 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
2350 parameters[4] = AliGRPObject::GetInvalidFloat();
2351 }
28131b57 2352 }
fe726709 2353 else {
28131b57 2354 parameters[3] = AliGRPObject::GetInvalidFloat();
28131b57 2355 parameters[4] = AliGRPObject::GetInvalidFloat();
5fbf7677 2356 }
fe726709 2357
28131b57 2358 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2359 if (truncMeanFlag){
2360 AliDebug(2,"Calculating Truncated Mean");
2361 for (Int_t i =0; i< nentriesUsed; i++){
df1faeb3 2362 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
28131b57 2363 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
df1faeb3 2364 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2365 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2366 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
28131b57 2367 entriesTruncMean++;
df1faeb3 2368 }
2369 else{
2370 AliDebug(2,"Discarding entry");
28131b57 2371 }
2372 }
2373 // setting truncated mean
2374 if (entriesTruncMean >1){
2375 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
2376 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2377 }
2378 else{
2379 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
2380 parameters[1] = AliGRPObject::GetInvalidFloat();
2381 }
2382 }
2383 else{
2384 parameters[1] = AliGRPObject::GetInvalidFloat();
2385 }
fe726709 2386
24f67180 2387 if (arrayValues){
2388 delete [] arrayValues;
2389 }
2390 if (arrayWeights){
2391 delete [] arrayWeights;
2392 }
2393 delete [] arrayValuesTruncMean;
2394 delete [] arrayWeightsTruncMean;
2395
28131b57 2396 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
2397 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1a3ac627 2398 AliInfo(Form("median = %f ",parameters[2]));
28131b57 2399 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
2400 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
2401
fe726709 2402 return parameters;
2403}
2404
fe726709 2405//__________________________________________________________________________________________________________________
2406
2407Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
2408{
2409 //
2410 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2411 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
ac833e7a 2412 // the flag is set according to the L3/Dipole current value
2413 // current threshold for L3 = 350 A (value provided by DCS)
2414 // current threshold for Dipole = 450 A (value provided by DCS)
fe726709 2415 //
2416 // parameters[0] = mean
2417 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2418 // parameters[2] = median
2419 // parameters[3] = standard deviation wrt mean
2420 // parameters[4] = standard deviation wrt median
2421 //
2422
2423 AliInfo(Form("indexDP = %d",indexDP));
28131b57 2424
fe726709 2425 Int_t nCounts = array->GetEntries();
fe726709 2426 for(Int_t i = 0; i < nCounts; i++) {
2427 AliDCSValue *v = (AliDCSValue *)array->At(i);
2428 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2429 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
535c05eb 2430 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2431 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
fe726709 2432 return NULL;
2433 }
26c1dff2 2434 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2435 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
ac833e7a 2436 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2437 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
fe726709 2438 }
2439 else {
2440 AliError(Form("DCS values for the parameter outside the queried interval"));
44e45fac 2441 }
2442 }
2443
28131b57 2444 return ProcessFloatAll(array);
44e45fac 2445}
125567f8 2446
e97cc90e 2447
44e45fac 2448//_______________________________________________________________
e97cc90e 2449
fe726709 2450Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
44e45fac 2451{
2452 //
2453 // processing Boolean values
2454 //
2455
2456 Bool_t aDCSBool = kTRUE;
2457
2458 AliDCSValue *v = 0x0;
26c1dff2 2459
44e45fac 2460 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2461 v = (AliDCSValue *)array->At(iCount);
26c1dff2 2462 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 2463 AliError(Form("DCS values for the parameter outside the queried interval"));
2464 continue;
2465 }
2466 if (iCount > 0) {
01920f0c 2467 if (aDCSBool != v->GetBool()) {
2468 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2469 change = kTRUE;
2470 }
44e45fac 2471 }
2472 aDCSBool = v->GetBool(); // always keeping last value
26c1dff2 2473 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
44e45fac 2474 }
2475
26c1dff2 2476 Char_t caDCSBool = (Char_t) aDCSBool;
44e45fac 2477 return caDCSBool;
2478
2479}
e97cc90e 2480
44e45fac 2481//_______________________________________________________________
e97cc90e 2482
39e3007b 2483Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
44e45fac 2484{
2485 //
2486 // processing Int values, returning mean
fe726709 2487 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2488 // are outside the queried time interval or their value is out of range
44e45fac 2489 //
2490
28131b57 2491 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2492 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2493 if (timeStartString.IsNull() || timeStartString.IsNull()){
2494 if (timeStartString.IsNull()){
2495 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2496 }
2497 else if (timeStartString.IsNull()){
2498 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2499 }
2500 return 0;
2501 }
2502
2503 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2504 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
44e45fac 2505 Float_t aDCSArrayMean = 0.0;
2506 Int_t iCounts = 0;
28131b57 2507 Float_t valueBeforeSOR = 0;
2508 Float_t valueAfterEOR = 0;
2509 Int_t timestampBeforeSOR = -1;
2510 Int_t timestampAfterEOR = -1;
2511 Int_t ientrySOR = -1;
2512 Int_t ientryEOR = -1;
2513 Float_t* arrayValues = 0x0;
2514 Double_t* arrayWeights = 0x0;
2515 Int_t iCountsRun = 0;
2516 Int_t nCounts = array->GetEntries();
44e45fac 2517
28131b57 2518 for(Int_t i = 0; i < nCounts; i++) {
dd5ac86b 2519 AliDCSValue* v = (AliDCSValue *)array->At(i);
fe726709 2520 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
28131b57 2521 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
fe726709 2522 return AliGRPObject::GetInvalidFloat();
2523 }
26c1dff2 2524 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2525 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
44e45fac 2526 iCounts += 1;
28131b57 2527 // look for the last value before SOR and the first value before EOR
2528 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2529 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2530 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2531 valueBeforeSOR = (Float_t) v->GetInt();
2532 }
2533 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2534 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2535 valueAfterEOR = (Float_t) v->GetInt();
2536 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2537 }
2538 // check if there are DPs between DAQ_time_start and DAQ_time_end
2539 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2540 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2541 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2542 AliDebug(2,Form("entry between SOR and EOR"));
2543 iCountsRun += 1;
2544 }
2545 }
2546 else {
2547 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
44e45fac 2548 }
2549 }
2550
28131b57 2551 if (timestampBeforeSOR == -1){
2552 AliWarning("No value found before SOR!");
2553 }
2554 if (timestampAfterEOR == -1){
2555 AliWarning("No value found after EOR!");
2556 }
2557
2558 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2559 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2560 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2561 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2562 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2563 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2564
2565 Int_t nentriesUsed = 0;
2566 if (iCountsRun > 1){
2567 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2568 AliDebug(2,"Calculating (weighted) Mean");
2569 arrayValues = new Float_t[iCountsRun];
2570 arrayWeights = new Double_t[iCountsRun];
2571 nentriesUsed = iCountsRun;
2572 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2573 AliDCSValue *v = (AliDCSValue *)array->At(i);
2574 Int_t timestamp2 = 0;
2575 if (i < ientryEOR){
2576 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2577 timestamp2 = (Int_t)v1->GetTimeStamp();
2578 }
2579 else {
2580 timestamp2 = timeEnd+1;
2581 }
2582 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2583 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2584 }
2585 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
24f67180 2586 delete [] arrayValues;
2587 delete [] arrayWeights;
28131b57 2588 }
2589 else if (iCountsRun == 1){
2590 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2591 nentriesUsed = 2;
2592 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2593 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2594 arrayValues = new Float_t[2];
2595 arrayWeights = new Double_t[2];
2596 arrayValues[0] = valueBeforeSOR;
2597 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2598 arrayValues[1] = (Float_t)v->GetInt();
2599 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2600 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2601 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2602 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
24f67180 2603 delete [] arrayValues;
2604 delete [] arrayWeights;
28131b57 2605 }
2606 else{
2607 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2608 return AliGRPObject::GetInvalidFloat();
2609 }
2610 }
2611 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2612 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2613 if (timestampBeforeSOR == -1){
2614 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2615 }
2616 if (timestampAfterEOR == -1){
2617 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2618 }
2619 return AliGRPObject::GetInvalidFloat();
2620 }
2621 else {
2622 AliWarning("Using last entry before SOR and first entry after EOR.");
2623 nentriesUsed = 2;
2624 arrayValues = new Float_t[2];
2625 arrayWeights = new Double_t[2];
2626 arrayValues[0] = valueBeforeSOR;
2627 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2628 arrayValues[1] = valueAfterEOR;
2629 arrayWeights[1] = 1.;
2630 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2631 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2632 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
24f67180 2633 delete [] arrayValues;
2634 delete [] arrayWeights;
28131b57 2635 }
2636 }
2637
2638 AliInfo(Form("mean = %f ", aDCSArrayMean));
44e45fac 2639 return aDCSArrayMean;
e97cc90e 2640
44e45fac 2641}
2642//_______________________________________________________________
e7a6790f 2643
39e3007b 2644Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
44e45fac 2645{
2646 //
fe726709 2647 // processing Int values, returning mean
2648 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2649 // are outside the queried time interval or their value is out of range
44e45fac 2650 //
2651
28131b57 2652 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2653 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2654 if (timeStartString.IsNull() || timeStartString.IsNull()){
2655 if (timeStartString.IsNull()){
2656 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2657 }
2658 else if (timeStartString.IsNull()){
2659 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2660 }
2661 return 0;
2662 }
2663
2664 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2665 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
44e45fac 2666 Float_t aDCSArrayMean = 0.0;
2667 Int_t iCounts = 0;
28131b57 2668 Float_t valueBeforeSOR = 0;
2669 Float_t valueAfterEOR = 0;
2670 Int_t timestampBeforeSOR = -1;
2671 Int_t timestampAfterEOR = -1;
2672 Int_t ientrySOR = -1;
2673 Int_t ientryEOR = -1;
2674 Float_t* arrayValues = 0x0;
2675 Double_t* arrayWeights = 0x0;
2676 Int_t iCountsRun = 0;
2677 Int_t nCounts = array->GetEntries();
44e45fac 2678
28131b57 2679 for(Int_t i = 0; i < nCounts; i++) {
dd5ac86b 2680 AliDCSValue* v = (AliDCSValue *)array->At(i);
fe726709 2681 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
28131b57 2682 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
fe726709 2683 return AliGRPObject::GetInvalidFloat();
2684 }
26c1dff2 2685 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2686 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
44e45fac 2687 iCounts += 1;
28131b57 2688 // look for the last value before SOR and the first value before EOR
2689 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2690 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2691 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2692 valueBeforeSOR = (Float_t)v->GetUInt();
2693 }
2694 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2695 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2696 valueAfterEOR = (Float_t)v->GetUInt();
2697 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2698 }
2699 // check if there are DPs between DAQ_time_start and DAQ_time_end
2700 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2701 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2702 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2703 AliDebug(2,Form("entry between SOR and EOR"));
2704 iCountsRun += 1;
2705 }
2706 }
2707 else {
2708 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
44e45fac 2709 }
2710 }
2711
28131b57 2712 if (timestampBeforeSOR == -1){
2713 AliWarning("No value found before SOR!");
2714 }
2715 if (timestampAfterEOR == -1){
2716 AliWarning("No value found after EOR!");
2717 }
2718
2719 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2720 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2721 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2722 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2723 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2724 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2725
2726 Int_t nentriesUsed = 0;
2727 if (iCountsRun > 1){
2728 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2729 AliDebug(2,"Calculating (weighted) Mean");
2730 arrayValues = new Float_t[iCountsRun];
2731 arrayWeights = new Double_t[iCountsRun];
2732 nentriesUsed = iCountsRun;
2733 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2734 AliDCSValue *v = (AliDCSValue *)array->At(i);
2735 Int_t timestamp2 = 0;
2736 if (i < ientryEOR){
2737 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2738 timestamp2 = (Int_t)v1->GetTimeStamp();
2739 }
2740 else {
2741 timestamp2 = timeEnd+1;
2742 }
2743 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2744 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2745 }
611435c2 2746 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
84c9e12a 2747 delete [] arrayValues;
2748 delete [] arrayWeights;
28131b57 2749 }
2750 else if (iCountsRun == 1){
2751 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2752 nentriesUsed = 2;
2753 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2754 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2755 arrayValues = new Float_t[2];
2756 arrayWeights = new Double_t[2];
2757 arrayValues[0] = valueBeforeSOR;
2758 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2759 arrayValues[1] = (Float_t)v->GetUInt();
2760 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2761 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2762 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2763 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
24f67180 2764 delete [] arrayValues;
2765 delete [] arrayWeights;
28131b57 2766 }
2767 else{
2768 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2769 return AliGRPObject::GetInvalidFloat();
2770 }
2771 }
2772 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2773 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2774 if (timestampBeforeSOR == -1){
2775 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2776 }
2777 if (timestampAfterEOR == -1){
2778 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2779 }
2780 return AliGRPObject::GetInvalidFloat();
2781 }
2782 else {
2783 AliWarning("Using last entry before SOR and first entry after EOR.");
2784 nentriesUsed = 2;
2785 arrayValues = new Float_t[2];
2786 arrayWeights = new Double_t[2];
2787 arrayValues[0] = valueBeforeSOR;
2788 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2789 arrayValues[1] = valueAfterEOR;
2790 arrayWeights[1] = 1.;
2791 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2792 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2793 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
24f67180 2794 delete [] arrayValues;
2795 delete [] arrayWeights;
28131b57 2796 }
2797 }
2798
2799 AliInfo(Form("mean = %f ",aDCSArrayMean));
44e45fac 2800 return aDCSArrayMean;
e7a6790f 2801
17984b61 2802}
125567f8 2803
44e45fac 2804
17984b61 2805//_______________________________________________________________
44e45fac 2806
3ba92a38 2807AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
e7a6790f 2808{
44e45fac 2809 // extract DCS pressure maps. Perform fits to save space
2810
44e45fac 2811 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2812 if (map) {
d7edf69d 2813 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
44e45fac 2814 fPressure->MakeSplineFit(map);
2815 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2816 if (fitFraction > kFitFraction ) {
ce996d13 2817 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
44e45fac 2818 } else {
2819 AliInfo("Too few pressure maps fitted!!!");
2820 }
2821 } else {
2822 AliInfo("no atmospheric pressure map extracted!!!");
2823 }
2824 delete map;
2825
2826 return fPressure;
17984b61 2827}
e97cc90e 2828
1e27bb6b 2829
2830
2831//_______________________________________________________________
03e5ee4f 2832Int_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 2833{
44e45fac 2834 //
2835 // Retrieves logbook and trigger information from the online logbook
2836 // This information is needed for prompt reconstruction
2837 //
2838 // Parameters are:
2839 // Run number
2840 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2841 // cdbRoot
2842 //
2843 // returns:
2844 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2845 // 0 on success and no run was found
2846 // negative on error
2847 //
2848 // This function is NOT called during the preprocessor run in the Shuttle!
2849 //
2850
2851 // defaults
2852 if (dbPort == 0)
2853 dbPort = 3306;
2854
2855 // CDB connection
2856 AliCDBManager* cdb = AliCDBManager::Instance();
2857 cdb->SetDefaultStorage(cdbRoot);
2858
2859 // SQL connection
2860 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2861
2862 if (!server)
2863 {
2864 Printf("ERROR: Could not connect to DAQ LB");
2865 return -1;
2866 }
2867
2868 // main logbook
2869 TString sqlQuery;
5d43966f 2870 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
44e45fac 2871 TSQLResult* result = server->Query(sqlQuery);
2872 if (!result)
2873 {
2874 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2875 return -2;
2876 }
2877
2878 if (result->GetRowCount() == 0)
2879 {
2880 Printf("ERROR: Run %d not found", run);
2881 delete result;
2882 return -3;
2883 }
2884
2885 TSQLRow* row = result->Next();
2886 if (!row)
2887 {
2888 Printf("ERROR: Could not receive data from run %d", run);
2889 delete result;
2890 return -4;
2891 }
2892
26c1dff2 2893 TString timeStartString(row->GetField(0));
44e45fac 2894 TString runType(row->GetField(1));
26c1dff2 2895 TString detectorMaskString(row->GetField(2));
2896 TString l3CurrentString(row->GetField(3));
2897 TString dipoleCurrentString(row->GetField(4));
5d43966f 2898 TString beamTypeString(row->GetField(5));
26c1dff2 2899 time_t timeStart = (time_t)(timeStartString.Atoi());
2900 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2901 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2902 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
03e5ee4f 2903 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2904 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
9f08228b 2905 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
2906 beamTypeString="A-A";
2907 }
44e45fac 2908
26c1dff2 2909 AliGRPObject * grpObj = new AliGRPObject();
2910 grpObj->SetTimeStart(timeStart);
2911 grpObj->SetRunType((TString)(row->GetField(1)));
2912 grpObj->SetDetectorMask(detectorMask);
2913 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2914 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
03e5ee4f 2915 grpObj->SetL3Polarity(l3Polarity);
2916 grpObj->SetDipolePolarity(dipolePolarity);
48fcacdc 2917 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
9f08228b 2918 grpObj->SetBeamType(beamTypeString);
26c1dff2 2919
44e45fac 2920 delete row;
2921 row = 0;
2922
2923 delete result;
2924 result = 0;
2925
2926 Printf("Storing GRP/GRP/Data object with the following content");
26c1dff2 2927 grpObj->Dump();
44e45fac 2928
2929 AliCDBMetaData metadata;
26c1dff2 2930 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
44e45fac 2931 metadata.SetComment("GRP Output parameters received during online running");
2932
2933 AliCDBId id("GRP/GRP/Data", run, run);
26c1dff2 2934 Bool_t success = cdb->Put(grpObj, id, &metadata);
44e45fac 2935
26c1dff2 2936 delete grpObj;
44e45fac 2937
2938 if (!success)
2939 {
2940 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2941 return -5;
2942 }
2943
2944 // Receive trigger information
2945 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2946 result = server->Query(sqlQuery);
2947 if (!result)
2948 {
2949 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2950 return -11;
2951 }
2952
2953 if (result->GetRowCount() == 0)
2954 {
2955 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2956 delete result;
2957 return -12;
2958 }
2959
2960 row = result->Next();
2961 if (!row)
2962 {
2963 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2964 delete result;
2965 return -13;
2966 }
2967
2968 TString triggerConfig(row->GetField(0));
2969
2970 delete row;
2971 row = 0;
2972
2973 delete result;
2974 result = 0;
2975
2976 Printf("Found trigger configuration: %s", triggerConfig.Data());
2977
2978 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2979 if (!runcfg)
2980 {
2981 Printf("ERROR: Could not create CTP configuration object");
2982 return -14;
2983 }
2984
2985 metadata.SetComment("CTP run configuration received during online running");
2986
2987 AliCDBId id2("GRP/CTP/Config", run, run);
2988 success = cdb->Put(runcfg, id2, &metadata);
2989
2990 delete runcfg;
2991 runcfg = 0;
2992
2993 if (!success)
2994 {
2995 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2996 return -15;
2997 }
2998
03e5ee4f 2999
3000 // Receive list of GDCs for this run
3001 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
3002 result = server->Query(sqlQuery);
3003 if (!result)
3004 {
3005 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3006 return -24;
3007 }
3008
3009 if (result->GetRowCount() == 0)
3010 {
3011 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
3012 delete result;
3013 return -25;
3014 }
2b81b7d0 3015
3016 gdc = "";
3017 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
3018 row = result->Next();
3019 if (!row)
3020 {
3021 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
3022 delete result;
3023 return -26;
3024 }
3025 gdc += row->GetField(0);
3026 gdc += " ";
3027 }
3028
03e5ee4f 3029 delete row;
3030 row = 0;
3031
3032 delete result;
3033 result = 0;
3034
3035 Printf("Found GDC: %s", gdc.Data());
3036
44e45fac 3037 // get last run with same run type that was already processed by the SHUTTLE
3038
3039 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());
3040 result = server->Query(sqlQuery);
3041 if (!result)
3042 {
3043 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3044 return -21;
3045 }
3046
3047 if (result->GetRowCount() == 0)
3048 {
3049 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
3050 delete result;
3051 return -22;
3052 }
3053
3054 row = result->Next();
3055 if (!row)
3056 {
3057 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
3058 delete result;
3059 return -23;
3060 }
3061
3062 TString lastRunStr(row->GetField(0));
3063 Int_t lastRun = lastRunStr.Atoi();
3064
3065 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
3066
3067 delete row;
3068 row = 0;
3069
3070 delete result;
3071 result = 0;
3072
3073 server->Close();
3074 delete server;
3075 server = 0;
3076
3077 return lastRun;
1e27bb6b 3078}
0254e751 3079//------------------------------------------------------------------------------------------------------
4cbf81c1 3080Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
0254e751 3081
3082 //
3083 // Method to processo LHC Energy information
3084 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
3085 //
3086
3087 Int_t nCounts = array->GetEntries();
3088 Float_t energy = -1;
4cbf81c1 3089 Double_t timeEnergy = -1;
3090 Int_t indexEnergy = -1;
3091 Bool_t foundEnergy = kFALSE;
3092
0254e751 3093 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
0d361338 3094 if (nCounts ==0){
3095 AliWarning("No Energy values found! Beam Energy remaining invalid!");
3096 }
3097 else{
4cbf81c1 3098 for (Int_t i = 0; i < nCounts; i++){
0d361338 3099 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
4cbf81c1 3100 if (dcs){
3101 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
3102 timeEnergy = dcs->GetTimeStamp();
3103 indexEnergy = i;
3104 foundEnergy = kTRUE;
3105 }
3106 else{
3107 break;
3108 }
0d361338 3109 }
0254e751 3110 }
4cbf81c1 3111 if (!foundEnergy){
3112 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
3113 }
3114 else {
3115 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
3116 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
3117 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
e541e2aa 3118 }
0254e751 3119 }
3120
3121 return energy;
3122}
8c1f1006 3123//------------------------------------------------------------------------------------------------------
17fd2848 3124AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
8c1f1006 3125{
3126 //
3127 // Method to process LHC-Clock Phase data
3128 // Only the values between DAQ_time_start and DAQ_time_end are kept
3129 //
3130 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
3131
3132 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
0c191635 3133 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
8c1f1006 3134
17fd2848 3135 TString timeCreatedStr = GetRunParameter("time_created");
3136 Double_t timeCreated = timeCreatedStr.Atof();
3137
8c1f1006 3138 Int_t nCounts = beam1phase->GetEntries();
3139 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
3140 if (nCounts ==0){
3141 AliWarning("No beam1 LHC clock phase values found!");
3142 delete phaseObj;
3143 return NULL;
3144 }
3145 else{
0c191635 3146 Double_t prevPhase = 0;
8c1f1006 3147 for (Int_t i = 0; i < nCounts; i++){
3148 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
3149 if (dcs){
f1226569 3150 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
3151 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
0c191635 3152 if ((i == 0) || (i == (nCounts-1)) ||
3153 !foundBeam1Phase ||
3154 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3155 prevPhase = dcs->GetDouble(0);
3156 foundBeam1Phase = kTRUE;
3157 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
3158 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3159 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3160 }
8c1f1006 3161 }
3162 }
3163 }
3164 if (!foundBeam1Phase){
3165 AliError("No beam1 LHC clock phase values found within the run!");
3166 delete phaseObj;
3167 return NULL;
3168 }
3169 }
3170
3171 nCounts = beam2phase->GetEntries();
3172 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
3173 if (nCounts ==0){
3174 AliWarning("No beam2 LHC clock phase values found!");
3175 delete phaseObj;
3176 return NULL;
3177 }
3178 else{
0c191635 3179 Double_t prevPhase = 0;
8c1f1006 3180 for (Int_t i = 0; i < nCounts; i++){
3181 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
3182 if (dcs){
17fd2848 3183 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
0c191635 3184 if ((i == 0) || (i == (nCounts-1)) ||
3185 !foundBeam2Phase ||
3186 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3187 prevPhase = dcs->GetDouble(0);
3188 foundBeam2Phase = kTRUE;
3189 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
3190 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3191 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3192 }
8c1f1006 3193 }
3194 }
3195 }
3196 if (!foundBeam2Phase){
3197 AliError("No beam2 LHC clock phase values found within the run!");
3198 delete phaseObj;
3199 return NULL;
3200 }
3201 }
3202
3203 return phaseObj;
3204}
81a1addb 3205//------------------------------------------------------------------------------------------------------
3206TString AliGRPPreprocessor::ParseBeamTypeString(TString beamType, Int_t iBeamType)
3207{
3208 // Method to return the convention for the separate beam type
3209 // in the form A*1000+Z
3210 // e.g.: Pb82 --> 208000 + 82 = 208082
3211 // p --> 1000 + 1 = 1001
3212
3213 Int_t a = 0;
3214 Int_t z = 0;
3215 TString separateString("");
3216 Log(Form("Setting Beam Type for beam %d to A*1000+Z",iBeamType));
3217 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
3218 Log(Form("Beam type %d is PROTON --> The single beam type will be set to 1001 (A = 1, Z = 1)",iBeamType));
3219 separateString = "1001";
3220 return separateString;
3221 }
3222 else {
3223 TPRegexp regexpA("\\D+");
3224 TPRegexp regexpZ("\\d+");
3225 TObjArray* arrayA = regexpA.MatchS(beamType);
3226 TObjArray* arrayZ = regexpZ.MatchS(beamType);
3227 if (arrayA->GetEntries() != 1 || arrayZ->GetEntries() != 1){
3228 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()));
3229 return beamType;
3230 }
3231 else{
3232 TString strA = ((TObjString*)(arrayA->At(0)))->String();
3233 TString strZ = ((TObjString*)(arrayZ->At(0)))->String();
3234 if (strA.CompareTo("LEAD",TString::kIgnoreCase) == 0 || strA.CompareTo("PB",TString::kIgnoreCase) == 0){
3235 Log(Form("Beam %d is %s --> A = 208",iBeamType, strA.Data()));
3236 a = 208;
3237 }
3238 else{
3239 Log(Form("This beam was not foreseen so far, leaving A=0"));
3240 }
3241 z = strZ.Atoi();
3242 Log(Form("Beam %d has Z = %d",iBeamType, z));
3243 separateString = Form("%d",a*1000+z);
3244 return separateString;
3245 }
3246 }
3247
3248 return separateString;
3249
3250}
3251