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