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