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