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