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