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