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