]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliGRPPreprocessor.cxx
Protection against div. by 0 in the Set(xyz,p..) for tracks with momentum along X...
[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
6ecb073a 532 Log("STANDALONE partition for current run, using LTU configuration dummy value");
533 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
534 if (!cdbEntry) {
535 Log(Form("No dummy LTU Config entry found, going into error..."));
536 error |= 2048;
537 }
538 else{
539 TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
540 if (!ltuConfig){
541 Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
542 error |= 2048;
543 }
544 else {
545 AliCDBMetaData metadata;
546 metadata.SetResponsible("Roman Lietava");
547 metadata.SetComment("LTU Config from dummy entry in OCDB");
548 if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
549 Log("Unable to store the dummy LTU Config object to OCDB!");
550 error |= 2048;
551 }
552 }
553 }
6ecb073a 554 }
555
556 else if (!partition.IsNull() && detector.IsNull()){ // global partition
557
558 Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
559 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
560 Printf ("detectormask = %d",detectorMask);
561 TObjArray * ltuarray = new TObjArray();
562 ltuarray->SetOwner(1);
563 Bool_t isLTUok = kTRUE;
564 for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
565 if ((detectorMask >> i) & 0x1) {
566 TString det = AliDAQ::OfflineModuleName(i);
567 TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
f3ada855 568 if (detCTPName == "CTP") {
569 detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors
570 Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
571 continue;
572 }
6ecb073a 573 Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
574 TString* ltu = GetLTUConfig(detCTPName.Data());
575 if (!ltu){
576 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()));
577 error |= 2048;
578 isLTUok = kFALSE;
579 break;
580 }
581 else{
582 Float_t ltuFineDelay1 = ltu[0].Atof();
583 Float_t ltuFineDelay2 = ltu[1].Atof();
584 Float_t ltuBCDelayAdd = ltu[2].Atof();
585 const char* name = AliDAQ::DetectorName(i);
586 AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
587 ltuarray->AddAtAndExpand(ltuConfig,i);
588 }
589 }
590 }
591 if (isLTUok){
592 AliCDBMetaData metadata;
593 metadata.SetBeamPeriod(0);
594 metadata.SetResponsible("Roman Lietava");
595 metadata.SetComment("LTU Configuration for current run");
596 if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
597 Log("Unable to store the LTU Config object to OCDB!");
598 error |= 2048;
599 }
600 }
24f67180 601 delete ltuarray;
6ecb073a 602 }
603
604 else {
605 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
606 error |= 32;
607 }
608
0254e751 609
610 //=================//
611 // LHC Data //
612 //=================//
613
e07d2728 614 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
615 Log("*************** Processing LHC Data");
616
617 UInt_t iLHCData = ProcessLHCData(grpobj);
618
619 if( iLHCData == 0 ) {
620 Log(Form("LHC Data from DCS FXS, successful!"));
621 } else if (iLHCData == 1) {
622 Log(Form("LHC Data, problems with DCS FXS!"));
623 error |= 256;
da0e365e 624 } else if (iLHCData == 2) {
625 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
626 error |= 512;
e07d2728 627 } else if (iLHCData ==3){
da0e365e 628 Log(Form("Problems in storing LHC Phase - going into Error"));
629 error |= 1024;
e07d2728 630 } else if (iLHCData ==4){
da0e365e 631 Log(Form("Problems with LHC Phase - going into Error"));
632 error |= 1024;
e07d2728 633 } else{
634 Log(Form("LHC Data problems"));
635 error |= 512;
636 }
44e45fac 637
e07d2728 638 }
639
6a150f83 640 //==================//
641 // SPD Mean Vertex //
642 //==================//
e3a2ac48 643
644 Log("*************** Processing SPD Mean Vertex");
645
62d2c16a 646 if (runType == "PHYSICS"){
647 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
648 if( iSPDMeanVertex == 1 ) {
649 Log(Form("SPD Mean Vertex, successful!"));
650 } else {
651 Log(Form("SPD Mean Vertex failed!!!"));
652 error |= 128;
653 }
6a150f83 654 }
62d2c16a 655 else {
656 Log("SPD Mean Vertex not processed since runType != PHYSICS");
657 }
658
0254e751 659 // storing AliGRPObject in OCDB
660
661 AliCDBMetaData md;
662 md.SetResponsible("Chiara Zampolli");
663 md.SetComment("Output parameters from the GRP preprocessor.");
664
665 Bool_t result = kTRUE;
666 result = Store("GRP", "Data", grpobj, &md);
667 delete grpobj;
668
44e45fac 669 if (result && !error ) {
670 Log("GRP Preprocessor Success");
671 return 0;
672 } else {
6ecb073a 673 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s",
44e45fac 674 kppError[(error&1)?1:0],
675 kppError[(error&2)?2:0],
676 kppError[(error&4)?3:0],
677 kppError[(error&8)?4:0],
e75e6e01 678 kppError[(error&16)?5:0],
6614fa48 679 kppError[(error&32)?6:0],
6a150f83 680 kppError[(error&64)?7:0],
0254e751 681 kppError[(error&128)?8:0],
682 kppError[(error&256)?9:0],
da0e365e 683 kppError[(error&512)?10:0],
6ecb073a 684 kppError[(error&1024)?11:0],
685 kppError[(error&2048)?12:0]
44e45fac 686 ));
687 return error;
688 }
0254e751 689
690
691}
692
693//_______________________________________________________________
694
695UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
696{
697 //
698 //Getting the LHC Data from DCS FXS
699 //
700
701 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
702 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
e541e2aa 703 if (timeStartString.IsNull() || timeEndString.IsNull()){
0254e751 704 if (timeStartString.IsNull()){
705 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
706 }
e541e2aa 707 else if (timeEndString.IsNull()){
0254e751 708 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
709 }
710 return 2;
711 }
712
713 Double_t timeStart = timeStartString.Atof();
714 Double_t timeEnd = timeEndString.Atof();
715
0254e751 716 TString fileName = GetFile(kDCS, "LHCData","");
717 if (fileName.Length()>0){
718 AliInfo("Got The LHC Data file");
e541e2aa 719 AliLHCReader lhcReader;
49822138 720
721 // Processing data to be put in AliGRPObject
722
723 // Energy
79350b54 724 Log("*************Energy ");
49822138 725 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
726 if (energyArray){
4cbf81c1 727 Float_t energy = ProcessEnergy(energyArray,timeStart);
ac152fdd 728 if (energy != -1.) {
49822138 729 grpobj->SetBeamEnergy(energy);
730 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
0254e751 731 }
49822138 732 delete energyArray;
733 }
734 else {
735 AliError("Energy not found in LHC Data file!!!");
736 }
737
4cbf81c1 738 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
739 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
740 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
741 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
742 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
743 Double_t timeBeamStart = -1; // min validity for Beam Type
744 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
745 Int_t indexMachineMode = -1; // index of measurement used to set Beam Mode
746 Int_t indexBeam = -1; // index of measurement used to set Beam Mode
747 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
748 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
749 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
750 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
751 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
752 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
49822138 753
754 // BeamMode
79350b54 755 Log("*************BeamMode (LHCState) ");
49822138 756 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
757 Int_t nBeamMode = -1;
758 if (beamModeArray){
759 nBeamMode = beamModeArray->GetEntries();
760 if (nBeamMode==0){
79350b54 761 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
49822138 762 }
763 else{
4cbf81c1 764 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
765 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
766 if (beamMode){
767 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
768 timeBeamModeStart = beamMode->GetTimeStamp();
769 indexBeamMode = iBeamMode;
770 foundBeamModeStart = kTRUE;
79350b54 771 }
4cbf81c1 772 else {
773 break;
774
79350b54 775 }
49822138 776 }
4cbf81c1 777 }
778 if (!foundBeamModeStart){
779 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
40e422c8 780 }
49822138 781 else {
4cbf81c1 782 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
783 TObjString* beamModeString = beamMode->GetStringArray(0);
784 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
785 grpobj->SetLHCState(beamModeString->String());
786 if (indexBeamMode < nBeamMode-1){
787 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
788 if (beamMode1){
789 if (beamMode1->GetTimeStamp()<=timeStart){
790 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
791 }
792 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
793 timeBeamModeEnd = beamMode1->GetTimeStamp();
794 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
795 TString bmString0 = beamModeString->String();
796 TString bmString1 = beamModeString1->String();
797 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
6720fa1f 798 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 799 flagBeamMode = kTRUE;
79350b54 800 }
49822138 801 }
79350b54 802 }
803 else {
4cbf81c1 804 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 805 }
806 }
40e422c8 807 }
0d361338 808 }
49822138 809 delete beamModeArray;
810 }
811 else{
812 AliError("Beam mode array not found in LHC Data file!!!");
813 }
814
815 // MachineMode
79350b54 816 Log("*************MachineMode ");
49822138 817 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
818 Int_t nMachineMode = -1;
819 if (machineModeArray){
820 nMachineMode = machineModeArray->GetEntries();
821 if (nMachineMode==0){
822 AliInfo("No Machine Mode found, leaving it empty");
0254e751 823 }
49822138 824 else{
4cbf81c1 825 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
826 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
79350b54 827 if (machineMode){
4cbf81c1 828 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
829 timeMachineModeStart = machineMode->GetTimeStamp();
830 indexMachineMode = iMachineMode;
831 foundMachineModeStart = kTRUE;
79350b54 832 }
833 else{
4cbf81c1 834 break;
79350b54 835 }
49822138 836 }
4cbf81c1 837 }
838 if (!foundMachineModeStart){
839 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
40e422c8 840 }
49822138 841 else {
4cbf81c1 842 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
843 TObjString* machineModeString = machineMode->GetStringArray(0);
844 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
845 grpobj->SetMachineMode(machineModeString->String());
846 if (indexMachineMode < nMachineMode-1){
847 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
848 if (machineMode1){
849 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
850 timeMachineModeEnd = machineMode1->GetTimeStamp();
851 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
852 TString mmString0 = machineModeString->String();
853 TString mmString1 = machineModeString1->String();
854 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
6720fa1f 855 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 856 flagMachineMode = kTRUE;
79350b54 857 }
49822138 858 }
79350b54 859 }
4cbf81c1 860 else {
861 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 862 }
863 }
49822138 864 }
865 }
866 delete machineModeArray;
867 }
4cbf81c1 868 else{
49822138 869 AliError("Machine mode array not found in LHC Data file!!!");
4cbf81c1 870 }
49822138 871
872 // BeamType1 and BeamType2 - both put in the same string
79350b54 873 Log("*************BeamType ");
49822138 874 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
875 if (beamArray){
876 Int_t nBeam = beamArray->GetEntries();
877 if (nBeam==0){
878 AliInfo("No Beam Type found, leaving it empty");
879 }
880 else{
4cbf81c1 881 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
882 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
79350b54 883 if (beam){
4cbf81c1 884 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
885 timeBeamStart = beam->GetTimeStamp();
886 indexBeam = iBeam;
887 foundBeamStart = kTRUE;
79350b54 888 }
4cbf81c1 889 else{
890 break;
79350b54 891 }
892 }
4cbf81c1 893 }
894 if (!foundBeamStart){
5755755a 895 AliInfo("No value for the Beam Type found before start of run, the Machine Mode will remain empty");
4cbf81c1 896 }
897 else {
898 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
899 TObjString* beamString = beam->GetStringArray(0);
900 TString beamType = beamString->String();
901 AliInfo(Form("Beam Type = %s",beamType.Data()));
902 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
903 AliInfo("Setting beam type to p-p");
904 grpobj->SetBeamType("p-p");
905 }
5755755a 906 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
907 AliInfo("Setting beam type to A-A");
908 grpobj->SetBeamType("A-A");
909 }
910 /*
911 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
4cbf81c1 912 AliInfo("Setting beam type to Pb-Pb");
913 grpobj->SetBeamType("Pb-Pb");
914 }
79350b54 915 else{
4cbf81c1 916 AliError("Beam Type not known, leaving it empty");
79350b54 917 }
5755755a 918 */
4cbf81c1 919 if (indexBeam < nBeam-1){
920 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
921 if (beam1){
922 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
923 timeBeamEnd = beam1->GetTimeStamp();
924 TObjString* beamString1 = beam1->GetStringArray(0);
925 TString beamType1 = beamString1->String();
926 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
6720fa1f 927 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 928 flagBeam = kTRUE;
79350b54 929 }
79350b54 930 }
931 }
4cbf81c1 932 else {
933 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 934 }
935 }
e07d2728 936 }
937 }
49822138 938 delete beamArray;
939 }
940 else{
4cbf81c1 941 AliError("Beam Type array not found in LHC Data file!!!");
942 }
49822138 943
944 // Setting minTimeLHCValidity
4cbf81c1 945 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
49822138 946 Double_t minTimeLHCValidity;
4cbf81c1 947 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true
948 minTimeLHCValidity = timeBeamEnd;
49822138 949 }
4cbf81c1 950 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
951 minTimeLHCValidity = timeMachineModeEnd;
49822138 952 }
4cbf81c1 953 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
954 minTimeLHCValidity = timeBeamModeEnd;
49822138 955 }
4cbf81c1 956 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
957 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
49822138 958 }
4cbf81c1 959 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
960 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
49822138 961 }
4cbf81c1 962 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
963 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
0254e751 964 }
49822138 965 else {
4cbf81c1 966 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
49822138 967 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
968 }
969 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
970 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
971 }
972
973 // Processing data to go to AliLHCData object
63bd40f4 974 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
975 // storing AliLHCData in OCDB
976 if (dt){
977 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
978 AliCDBMetaData md;
979 md.SetResponsible("Ruben Shahoyan");
980 md.SetComment("LHC data from the GRP preprocessor.");
981 Bool_t result = kTRUE;
982 result = Store("GRP", "LHCData", dt, &md);
983 delete dt;
da0e365e 984 if (!result){
985 Log(Form("Problems in storing LHC Data - but not going into Error"));
986 }
987 }
988
989 // processing LHC Phase
990
991 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
992 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
993 if (beam1phase == 0x0 || beam2phase == 0x0){
994 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
995 return 4;
996 }
17fd2848 997 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
da0e365e 998 if (phaseObj){
999 AliInfo(Form("LHC Phase found"));
1000 AliCDBMetaData mdPhase;
1001 mdPhase.SetResponsible("Cvetan Cheshkov");
1002 mdPhase.SetComment("LHC Clock Phase");
1003 Bool_t result = kTRUE;
1004 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
1005 delete phaseObj;
1006 if (!result) return 3;
0254e751 1007 }
da0e365e 1008 else return 4;
0254e751 1009 }
49822138 1010
0254e751 1011 else {
1012 AliError("No LHCData file found in DCS FXS");
1013 return 1;
1014 }
79350b54 1015
1016 return 0;
17984b61 1017}
1018
6a150f83 1019//_______________________________________________________________
1020
1021UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
1022{
0254e751 1023 //
6a150f83 1024 //Getting the SPD Mean Vertex
0254e751 1025 //
1026
6a150f83 1027 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
1028 Bool_t storeResult = kTRUE;
1029 if (list !=0x0 && list->GetEntries()!=0)
1030 {
1031 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
1032 list->Print();
1033 for (Int_t jj=0;jj<list->GetEntries();jj++){
24f67180 1034 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1035 if (!str){
1036 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1037 continue;
1038 }
6a150f83 1039 AliInfo(Form("found source %s", str->String().Data()));
1040 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
1041 if (fileNameRun.Length()>0){
1042 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1043 TFile daqFile(fileNameRun.Data(),"READ");
1044 if (daqFile.IsOpen()) {
1045 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
1046 if (meanVtx){
1047 meanVtx->Print();
1048 // storing in the OCDB
1049 AliCDBMetaData md;
1050 md.SetResponsible("Cvetan Cheshkov");
1051 md.SetComment("SPD Mean Vertex");
295c54b0 1052 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
6a150f83 1053 }
1054 else{
1055 AliWarning("No SPD Mean Vertex object found in file");
1056 }
1057 }
1058 else {
1059 AliError("Can't open file");
1060 storeResult = kFALSE;
1061 }
1062 }
1063 else{
1064 AliWarning("No file found for current source for SPD Mean Vertex");
1065 }
1066 }
1067 }
1068 else {
1069 AliWarning("No list found for SPD Mean Vertex");
1070 }
1071
1072 if (list) delete list;
1073
1074 return storeResult;
1075}
1076
1077
17984b61 1078//_______________________________________________________________
17984b61 1079
e75e6e01 1080Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
44e45fac 1081{
1082 //Getting the DAQ lb information
1083
e75e6e01 1084 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
1085 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
1086 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
44e45fac 1087 TString beamType = (TString)GetRunParameter("beamType");
1088 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
e75e6e01 1089 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
44e45fac 1090 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
1091 TString runType = (TString)GetRunType();
1092
e75e6e01 1093 UInt_t nparameter = 0;
44e45fac 1094 if (timeStart != 0){
1095 grpObj->SetTimeStart(timeStart);
1096 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
e75e6e01 1097 nparameter++;
44e45fac 1098 }
1099 else {
e3a2ac48 1100 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1101 }
1102
1103 if (timeEnd != 0){
1104 grpObj->SetTimeEnd(timeEnd);
1105 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
e75e6e01 1106 nparameter++;
44e45fac 1107 }
1108 else {
e3a2ac48 1109 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1110 }
1111
1112 if (beamEnergy != 0){
e3a2ac48 1113 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 1114 }
1115 else {
e3a2ac48 1116 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
44e45fac 1117 }
1118
44e45fac 1119
1120 if (beamType.Length() != 0){
e3a2ac48 1121 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 1122 }
1123 else {
e3a2ac48 1124 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
44e45fac 1125 }
1126
1127 if (numberOfDetectors != 0){
1128 grpObj->SetNumberOfDetectors(numberOfDetectors);
1129 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
e75e6e01 1130 nparameter++;
44e45fac 1131 }
1132 else {
e3a2ac48 1133 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1134 }
1135
1136 if (detectorMask != 0){
1137 grpObj->SetDetectorMask(detectorMask);
1138 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
e75e6e01 1139 nparameter++;
44e45fac 1140 }
1141 else {
e3a2ac48 1142 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1143 }
1144
1145 if (lhcPeriod.Length() != 0) {
1146 grpObj->SetLHCPeriod(lhcPeriod);
1147 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
e75e6e01 1148 nparameter++;
1149 }
1150 else {
e3a2ac48 1151 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1152 }
1153 if (runType.Length() != 0) {
1154 grpObj->SetRunType(runType);
1155 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
e75e6e01 1156 nparameter++;
1157 }
1158 else {
e3a2ac48 1159 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
44e45fac 1160 }
1161
e75e6e01 1162 return nparameter;
44e45fac 1163}
17984b61 1164
44e45fac 1165//_______________________________________________________________
17984b61 1166
44e45fac 1167UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1168{
1169 //======DAQ FXS======//
1170
ea4a87ee 1171 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
f3590649 1172 AliRawEventHeaderV3_11::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_11 - temporary fix
44e45fac 1173 TList* list = GetFileSources(kDAQ);
1174 if (!list) {
1175 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1176 return 1;
1177 }
1178
1179 if (list->GetEntries() == 0) {
1180 Log("no raw data tags in this run: nothing to merge!");
1181 delete list; list=0;
1182 return 0;
1183 }
1184
1185 TChain *fRawTagChain = new TChain("T");
1186 Int_t nFiles=0;
1187 TIterator* iter = list->MakeIterator();
1188 TObject* obj = 0;
1189 while ((obj = iter->Next())) {
1190 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1191 if (objStr) {
1192 Log(Form("Found source %s", objStr->String().Data()));
1193 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1194 if (!list2) {
1195 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1196 delete fRawTagChain; fRawTagChain=0;
1197 return 1;
1198 }
1199 Log(Form("Number of ids: %d",list2->GetEntries()));
1200 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1201 TObjString *idStr = (TObjString *)list2->At(i);
1202 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1203 if (fileName.Length() > 0) {
1204 Log(Form("Adding file in the chain: %s",fileName.Data()));
1205 fRawTagChain->Add(fileName.Data());
1206 nFiles++;
1207 } else {
1208 Log(Form("Could not retrieve file with id %s from source %s: "
1209 "connection problems with DAQ FXS!",
1210 idStr->String().Data(), objStr->String().Data()));
1211 delete list; list=0;
1212 delete list2; list2=0;
1213 delete fRawTagChain; fRawTagChain=0;
1214 return 2;
1215 }
1216 }
1217 delete list2;
1218 }
1219 }
1220
1221 TString fRawDataFileName = "GRP_Merged.tag.root";
1222 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
7e6f5523 1223
44e45fac 1224 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1225 Log("Error merging raw data files!!!");
1226 return 3;
1227 }
7e6f5523 1228
44e45fac 1229 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1230 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1231
1232 if (!result) {
1233 Log("Problem storing raw data tags in local file!!!");
1234 } else {
1235 Log("Raw data tags merged successfully!!");
1236 }
1237
1238 delete iter;
1239 delete list;
1240 delete fRawTagChain; fRawTagChain=0;
1241
1242 if (result == kFALSE) {
1243 return 4;
1244 }
1245
1246 return 0;
1247
1248}
17984b61 1249
44e45fac 1250//_______________________________________________________________
e75e6e01 1251UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
44e45fac 1252{
39e3007b 1253
1254 // processing the info
1255 // stored in the DCS FXS
1256 // coming from the trigger
1257
e75e6e01 1258 // Get the CTP counters information
1259
1260 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
161a4dc3 1261 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
e75e6e01 1262 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1263 if (!cdbEntry) {
1264 Log(Form("No dummy CTP scalers entry found, going into error..."));
44e45fac 1265 return 1;
1266 }
e75e6e01 1267 else{
1268 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1269 if (!scalers){
1270 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1271 return 1;
1272 }
1273 else {
1274 AliCDBMetaData metaData;
1275 metaData.SetResponsible("Roman Lietava");
1276 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1277 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1278 Log("Unable to store the dummy CTP scalers object to OCDB!");
1279 return 1;
1280 }
1281 }
1282 }
1283 }
1284
1285 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1286 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1287 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1288 if (countersfile.IsNull()) {
1289 Log("No CTP counters files has been found: empty source!");
44e45fac 1290 return 1;
1291 }
1292 else {
e75e6e01 1293 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1294 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1295 if (!scalers) {
1296 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1297 return 1;
1298 }
1299 else {
1300 AliCDBMetaData metaData;
1301 metaData.SetBeamPeriod(0);
1302 metaData.SetResponsible("Roman Lietava");
1303 metaData.SetComment("CTP scalers");
1304 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1305 Log("Unable to store the CTP scalers object to OCDB!");
e541e2aa 1306 delete scalers;
e75e6e01 1307 return 1;
44e45fac 1308 }
1309 }
e541e2aa 1310 delete scalers;
44e45fac 1311 }
44e45fac 1312 }
1313
e75e6e01 1314
1315 else{
1316 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1317 return 2;
1318 }
1319
44e45fac 1320 return 0;
e75e6e01 1321
44e45fac 1322}
1323//_______________________________________________________________
17984b61 1324
44e45fac 1325Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1326{
17984b61 1327
44e45fac 1328 //
1329 // processing DCS DPs
1330 //
1331
26c1dff2 1332 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
44e45fac 1333 Int_t nL3Entries = 0;
1334 Int_t nDipoleEntries = 0;
1335 Int_t nEnvEntries = 0;
1336 Int_t nHallProbesEntries = 0;
44e45fac 1337 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1338 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1339 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1340 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
fab61587 1341 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
0254e751 1342 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1343 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
44e45fac 1344 return entries;
17984b61 1345
17984b61 1346}
1347
1348//_______________________________________________________________
29cc8704 1349
39e3007b 1350Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 1351{
39e3007b 1352
1353 // processing DPs
1354 // related to
1355 // L3 info
1356
44e45fac 1357 Int_t nL3Entries = 0;
c5340e82 1358
44e45fac 1359 TObjArray *array = 0x0;
1360 Int_t indexDP = -1;
fe726709 1361 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
44e45fac 1362
fe726709 1363 AliInfo(Form("==========L3Current==========="));
1364 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1365 indexDP = kL3Current;
44e45fac 1366 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1367 if(!array) {
1368 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1369 }
1370 else {
26c1dff2 1371 if (array->GetEntries() == 0){
fe726709 1372 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
26c1dff2 1373 }
1374 else {
fe726709 1375 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1376 if (floatDCS != NULL){
1377 grpObj->SetL3Current(floatDCS);
1378 }
1379 else{
1380 outOfRange = kTRUE;
1381 }
03672227 1382 if (floatDCS){
1383 delete[] floatDCS;
1384 floatDCS = 0x0;
1385 }
26c1dff2 1386 }
c5340e82 1387 if (!outOfRange) {
1388 nL3Entries++;
1389 ffailedDPs->RemoveAt(indexDP);
1390 }
44e45fac 1391 }
1392
1393 if (array) array = 0x0;
1394
fe726709 1395 AliInfo(Form("==========L3Polarity==========="));
1396 indexDP = kL3Polarity;
44e45fac 1397 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1398 if(!array) {
1399 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1400 }
1401 else {
26c1dff2 1402 if (array->GetEntries() == 0){
fe726709 1403 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
26c1dff2 1404 }
1405 else {
fe726709 1406 Bool_t change = kFALSE;
1407 Char_t charDCS = ProcessBool(array,change);
01920f0c 1408 if (change == kFALSE){
fe726709 1409 grpObj->SetL3Polarity(charDCS);
1410 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
c5340e82 1411 ffailedDPs->RemoveAt(indexDP);
fe726709 1412 nL3Entries++;
1413 }
1414 else if (isZero){
ac833e7a 1415 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
c5340e82 1416 ffailedDPs->RemoveAt(indexDP);
fe726709 1417 nL3Entries++;
1418 }
1419 else {
ac833e7a 1420 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 1421 }
26c1dff2 1422 }
44e45fac 1423 }
1424
1425 return nL3Entries;
e7a6790f 1426
44e45fac 1427}
1428//_______________________________________________________________
ff97356e 1429
39e3007b 1430Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 1431{
39e3007b 1432 // processing DPs
1433 // related to
1434 // the Dipole info
1435
44e45fac 1436 Int_t nDipoleEntries = 0;
1437 TObjArray *array = 0x0;
1438 Int_t indexDP = -1;
fe726709 1439 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
44e45fac 1440
fe726709 1441 AliInfo(Form("==========DipoleCurrent==========="));
1442 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1443 indexDP = kDipoleCurrent;
44e45fac 1444 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
44e45fac 1445 if(!array) {
1446 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1447 }
1448 else {
26c1dff2 1449 if (array->GetEntries() == 0){
1450 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1451 }
1452 else {
fe726709 1453 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1454 if (floatDCS != NULL){
1455 grpObj->SetDipoleCurrent(floatDCS);
1456 }
1457 else{
1458 outOfRange=kTRUE;
1459 }
03672227 1460 if (floatDCS){
1461 delete[] floatDCS;
1462 floatDCS = 0x0;
1463 }
26c1dff2 1464 }
c5340e82 1465 if (!outOfRange) {
1466 nDipoleEntries++;
1467 ffailedDPs->RemoveAt(indexDP);
1468 }
44e45fac 1469 }
1470
1471 if (array) array = 0x0;
1472
fe726709 1473 AliInfo(Form("==========DipolePolarity==========="));
1474 indexDP = kDipolePolarity;
44e45fac 1475 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1476 if(!array) {
1477 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1478 }
1479 else {
26c1dff2 1480 if (array->GetEntries() == 0){
1481 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1482 }
1483 else {
fe726709 1484 Bool_t change = kFALSE;
1485 Char_t charDCS = ProcessBool(array,change);
1486 if (!change){
1487 grpObj->SetDipolePolarity(charDCS);
1488 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
c5340e82 1489 ffailedDPs->RemoveAt(indexDP);
fe726709 1490 nDipoleEntries++;
1491 }
1492 else if (isZero){
ac833e7a 1493 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
c5340e82 1494 ffailedDPs->RemoveAt(indexDP);
fe726709 1495 nDipoleEntries++;
1496 }
1497 else{
ac833e7a 1498 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 1499 }
26c1dff2 1500 }
44e45fac 1501 }
1502
1503 return nDipoleEntries;
e7a6790f 1504
44e45fac 1505}
1506//_______________________________________________________________
e7a6790f 1507
44e45fac 1508Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1509{
39e3007b 1510 // processing DPs
1511 // related to
1512 // evironment conditions (temperature, pressure) info
1513
44e45fac 1514 Int_t nEnvEntries = 0;
1515 TObjArray *array = 0x0;
1516 Int_t indexDP = -1;
1517
1518 AliInfo(Form("==========CavernTemperature==========="));
fe726709 1519 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
44e45fac 1520 indexDP = kCavernTemperature;
1521 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1522 if(!array) {
1523 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1524 }
1525 else {
26c1dff2 1526 if (array->GetEntries() == 0){
1527 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1528 }
1529 else {
1530 Float_t *floatDCS = ProcessFloatAll(array);
fe726709 1531 if (floatDCS != NULL){
1532 grpObj->SetCavernTemperature(floatDCS);
1533 }
1534 else{
1535 outOfRange = kTRUE;
1536 }
03672227 1537 if (floatDCS){
1538 delete[] floatDCS;
1539 floatDCS = 0x0;
1540 }
26c1dff2 1541 }
c5340e82 1542 if (!outOfRange) {
1543 ffailedDPs->RemoveAt(indexDP);
1544 nEnvEntries++;
1545 }
44e45fac 1546 }
1547
1548 if (array) array = 0x0;
1549
ce996d13 1550 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
44e45fac 1551 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
ce996d13 1552 //dcsSensorArray->Print();
1553 if( fPressure->NumFits()<kNumSensors ) {
d7edf69d 1554 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
44e45fac 1555 }
d7edf69d 1556 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1557
1558 AliInfo(Form("==========CavernAtmosPressure==========="));
1559 indexDP = kCavernAtmosPressure;
1560 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1561 TGraph* graph = sensorCavernP2->GetGraph();
3343d11b 1562 AliDebug(3,Form("index = %d",indexDP));
1563 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 1564 AliDebug(2,Form("graph = %p",graph));
1565 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
2a0b175e 1566 if(sensorCavernP2->GetFit() || graph) {
d7edf69d 1567 if (sensorCavernP2->GetFit()){
2a0b175e 1568 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 1569 }
44e45fac 1570 else {
2a0b175e 1571 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 1572 }
1573 grpObj->SetCavernAtmosPressure(sensorCavernP2);
c5340e82 1574 ffailedDPs->RemoveAt(indexDP);
d7edf69d 1575 nEnvEntries++;
1576 }
1577 //if (sensorP2) delete sensorP2;
1578 else {
2a0b175e 1579 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 1580 }
2a0b175e 1581
d7edf69d 1582 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1583 indexDP = kSurfaceAtmosPressure;
1584 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1585 graph = sensorP2->GetGraph();
3343d11b 1586 AliDebug(3,Form("index = %d",indexDP));
1587 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 1588 AliDebug(2,Form("graph = %p",graph));
1589 AliDebug(3,Form("sensorP2 = %p", sensorP2));
2a0b175e 1590 if(sensorP2->GetFit() || graph) {
d7edf69d 1591 if (sensorP2->GetFit()){
2a0b175e 1592 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 1593 }
44e45fac 1594 else {
2a0b175e 1595 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 1596 }
1597 grpObj->SetSurfaceAtmosPressure(sensorP2);
c5340e82 1598 ffailedDPs->RemoveAt(indexDP);
d7edf69d 1599 nEnvEntries++;
1600 }
1601 //if (sensorP2) delete sensorP2;
1602 else {
2a0b175e 1603 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 1604 }
1605
d7edf69d 1606 AliInfo(Form("==========CavernAtmosPressure2==========="));
1607 indexDP = kCavernAtmosPressure2;
1608 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
8976336c 1609 graph = sensorCavernP22->GetGraph();
3343d11b 1610 AliDebug(3,Form("index = %d",indexDP));
1611 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
d7edf69d 1612 AliDebug(2,Form("graph = %p",graph));
1613 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
2a0b175e 1614 if(sensorCavernP22->GetFit() || graph) {
d7edf69d 1615 if (sensorCavernP22->GetFit()){
2a0b175e 1616 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
d7edf69d 1617 }
1618 else {
2a0b175e 1619 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
d7edf69d 1620 }
1621 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
c5340e82 1622 ffailedDPs->RemoveAt(indexDP);
d7edf69d 1623 nEnvEntries++;
1624 }
1625 //if (sensorP2) delete sensorP2;
1626 else {
2a0b175e 1627 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 1628 }
1629
1630
44e45fac 1631 return nEnvEntries;
1632}
1633//_______________________________________________________________
e7a6790f 1634
39e3007b 1635Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 1636{
39e3007b 1637 // processing DPs
1638 // related to
1639 // Hall Probes info
1640
44e45fac 1641 Int_t nHPEntries = 0;
1642 TObjArray *array = 0x0;
1643 Int_t indexDP = -1;
fe726709 1644 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
44e45fac 1645
39e3007b 1646 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1647 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 1648 }
1649 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
fe726709 1650 outOfRange = kFALSE; // resetting outOfRange flag at each HP
44e45fac 1651 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1652 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1653 if(!array) {
1654 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1655 }
1656 else {
26c1dff2 1657 if (array->GetEntries() == 0){
1658 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1659 }
1660 else {
1661 Float_t *floatDCS = ProcessFloatAll(array);
fe726709 1662 if (floatDCS != NULL){
1663 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]));
1664 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1665 for (Int_t kk = 0 ; kk< 5; kk++){
1666 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1667 }
1668 }
1669 else{
1670 outOfRange = kTRUE;
26c1dff2 1671 }
03672227 1672 if (floatDCS){
1673 delete[] floatDCS;
1674 floatDCS = 0x0;
1675 }
44e45fac 1676 }
c5340e82 1677 if (!outOfRange) {
4bb7c769 1678 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
c5340e82 1679 nHPEntries++;
1680 }
44e45fac 1681 }
1682 }
1683
7e6f5523 1684 Log(Form("Hall Probes = %d ", nHPEntries));
1685 return nHPEntries;
17984b61 1686}
1687
44e45fac 1688//_________________________________________________________________________
1689
39e3007b 1690AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1691
1692
1693 //
1694 // returning Spline Fit
1695 //
44e45fac 1696
1697 Int_t entriesarray = array->GetEntries();
1698 Float_t* value = new Float_t[entriesarray];
1699 Float_t* time = new Float_t[entriesarray];
1700 AliDCSValue* v = 0x0;
1701 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1702 v = (AliDCSValue*)array->At(iarray);
1703 value[iarray] = v->GetFloat();
1704 time[iarray] = v->GetTimeStamp();
e75e6e01 1705 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
44e45fac 1706 }
1707 TGraph* gr = new TGraph(entriesarray,value,time);
1708 if (!gr ) {
1709 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1710 return NULL;
1711 }
1712 AliSplineFit *fit = new AliSplineFit();
1713 fit->SetMinPoints(10);
1714 fit->InitKnots(gr,10,10,0.0);
1715 fit->SplineFit(2);
1716 fit->Cleanup();
44e45fac 1717 return fit;
48b1b444 1718}
1719
44e45fac 1720//_________________________________________________________________________
1721
39e3007b 1722TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
e7a6790f 1723{
17984b61 1724
44e45fac 1725 //
1726 // processing char
1727 //
1728
1729 TString aDCSString="";
1730
1731 AliDCSValue *v = 0x0;
1732 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1733 v = (AliDCSValue *)array->At(iCount);
26c1dff2 1734 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 1735 AliError(Form("DCS values for the parameter outside the queried interval"));
1736 continue;
1737 }
1738 if (iCount > 0) {
7e6f5523 1739 if (aDCSString != v->GetChar())
44e45fac 1740 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1741 }
1742 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1743 }
1744 return aDCSString;
1745}
e7a6790f 1746
44e45fac 1747//__________________________________________________________________________________________________________________
e7a6790f 1748
39e3007b 1749Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
44e45fac 1750{
1751 //
1752 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1753 //
1754 // parameters[0] = mean
1755 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1756 // parameters[2] = median
1757 // parameters[3] = standard deviation wrt mean
1758 // parameters[4] = standard deviation wrt median
1759 //
1760
28131b57 1761 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1762 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1763 if (timeStartString.IsNull() || timeStartString.IsNull()){
1764 if (timeStartString.IsNull()){
1765 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1766 }
1767 else if (timeStartString.IsNull()){
1768 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1769 }
5fbf7677 1770 fdaqStartEndTimeOk = kFALSE;
28131b57 1771 return 0;
1772 }
1773
1774 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1775 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
5138cd05 1776 Float_t* parameters = new Float_t[5];
44e45fac 1777 Int_t iCounts = 0;
28131b57 1778 Int_t iCountsRun = 0;
44e45fac 1779 Int_t nCounts = array->GetEntries();
28131b57 1780 Float_t valueBeforeSOR = 0;
1781 Float_t valueAfterEOR = 0;
1782 Int_t timestampBeforeSOR = -1;
1783 Int_t timestampAfterEOR = -1;
1784 Int_t ientrySOR = -1;
1785 Int_t ientryEOR = -1;
1786 Float_t* arrayValues = 0x0;
1787 Double_t* arrayWeights = 0x0;
1788 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
5fbf7677 1789 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1790
44e45fac 1791 for(Int_t i = 0; i < nCounts; i++) {
1792 AliDCSValue *v = (AliDCSValue *)array->At(i);
fe726709 1793 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1794 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1795 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1796 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
24f67180 1797 delete [] parameters;
fe726709 1798 return NULL;
1799 }
1800 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 1801 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
fe726709 1802 iCounts += 1;
28131b57 1803 // look for the last value before SOR and the first value before EOR
1804 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1805 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1806 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1807 valueBeforeSOR = v->GetFloat();
1808 }
1809 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1810 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1811 valueAfterEOR = v->GetFloat();
1812 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1813 }
1814 // check if there are DPs between DAQ_time_start and DAQ_time_end
1815 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1816 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1817 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1818 AliDebug(2,Form("entry between SOR and EOR"));
1819 iCountsRun += 1;
1820 }
fe726709 1821 }
1822 else {
28131b57 1823 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
fe726709 1824 }
1825 }
1826
28131b57 1827 if (timestampBeforeSOR == -1){
df1faeb3 1828 AliWarning("No value found before SOR");
28131b57 1829 }
1830 if (timestampAfterEOR == -1){
df1faeb3 1831 AliWarning("No value found after EOR");
28131b57 1832 }
1833
1834 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1835 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1836 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1837 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1838 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1839 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1840
1841 Int_t nentriesUsed = 0;
1842 if (iCountsRun > 1){
1843 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1844 AliDebug(2,"Calculating (weighted) Mean and Median");
1845 arrayValues = new Float_t[iCountsRun];
1846 arrayWeights = new Double_t[iCountsRun];
1847 nentriesUsed = iCountsRun;
1848 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
fe726709 1849 AliDCSValue *v = (AliDCSValue *)array->At(i);
28131b57 1850 Int_t timestamp2 = 0;
1851 if (i < ientryEOR){
1852 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1853 timestamp2 = (Int_t)v1->GetTimeStamp();
fe726709 1854 }
28131b57 1855 else {
1856 timestamp2 = timeEnd+1;
1857 }
1858 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1859 arrayValues[i-ientrySOR] = v->GetFloat();
fe726709 1860 }
28131b57 1861 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1862 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1863 }
1864 else if (iCountsRun == 1){
1865 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1866 nentriesUsed = 2;
1867 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1868 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.");
1869 arrayValues = new Float_t[2];
1870 arrayWeights = new Double_t[2];
1871 arrayValues[0] = valueBeforeSOR;
1872 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1873 arrayValues[1] = v->GetFloat();
1874 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1875 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1876 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1877 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1878 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1879 truncMeanFlag = kFALSE;
fe726709 1880 }
1881 else{
28131b57 1882 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");
1883 parameters[0] = AliGRPObject::GetInvalidFloat();
1884 parameters[1] = AliGRPObject::GetInvalidFloat();
1885 parameters[2] = AliGRPObject::GetInvalidFloat();
1886 parameters[3] = AliGRPObject::GetInvalidFloat();
1887 parameters[4] = AliGRPObject::GetInvalidFloat();
1888 return parameters;
fe726709 1889 }
1890 }
5fbf7677 1891 else { // iCountsRun == 0, using only the point immediately before SOR
1892 if (timestampBeforeSOR == -1){
1893 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 1894 parameters[0] = AliGRPObject::GetInvalidFloat();
1895 parameters[1] = AliGRPObject::GetInvalidFloat();
1896 parameters[2] = AliGRPObject::GetInvalidFloat();
1897 parameters[3] = AliGRPObject::GetInvalidFloat();
1898 parameters[4] = AliGRPObject::GetInvalidFloat();
1899 return parameters;
1900 }
1901 else {
5fbf7677 1902 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1903 AliDebug(2,Form("value = %f",valueBeforeSOR));
1904 parameters[0] = valueBeforeSOR;
1905 parameters[2] = valueBeforeSOR;
28131b57 1906 truncMeanFlag = kFALSE;
5fbf7677 1907 sdFlag = kFALSE;
28131b57 1908 }
1909 }
1910
1911 Float_t temp = 0;
1912 Float_t temp1 = 0;
1913 Float_t sumweights = 0;
1914 Int_t entriesTruncMean = 0;
1915 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1916 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1917
1918 // calculating SD wrt Mean and Median
1919 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
5fbf7677 1920 if (sdFlag){
1921 for (Int_t i =0; i< nentriesUsed; i++){
df1faeb3 1922 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
5fbf7677 1923 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1924 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1925 sumweights += arrayWeights[i];
1926 }
1927 // setting SD wrt Mean
1928 if (sumweights != 0 ){
1929 parameters[3] = TMath::Sqrt(temp1/sumweights);
1930 }
1931 else {
1932 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1933 parameters[3] = AliGRPObject::GetInvalidFloat();
1934 }
1935 // setting SD wrt Median
1936 if (nentriesUsed != 0){
1937 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1938 }
1939 else{
1940 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1941 parameters[4] = AliGRPObject::GetInvalidFloat();
1942 }
28131b57 1943 }
fe726709 1944 else {
28131b57 1945 parameters[3] = AliGRPObject::GetInvalidFloat();
28131b57 1946 parameters[4] = AliGRPObject::GetInvalidFloat();
5fbf7677 1947 }
fe726709 1948
28131b57 1949 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1950 if (truncMeanFlag){
1951 AliDebug(2,"Calculating Truncated Mean");
1952 for (Int_t i =0; i< nentriesUsed; i++){
df1faeb3 1953 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
28131b57 1954 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
df1faeb3 1955 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1956 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1957 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
28131b57 1958 entriesTruncMean++;
df1faeb3 1959 }
1960 else{
1961 AliDebug(2,"Discarding entry");
28131b57 1962 }
1963 }
1964 // setting truncated mean
1965 if (entriesTruncMean >1){
1966 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1967 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1968 }
1969 else{
1970 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1971 parameters[1] = AliGRPObject::GetInvalidFloat();
1972 }
1973 }
1974 else{
1975 parameters[1] = AliGRPObject::GetInvalidFloat();
1976 }
fe726709 1977
24f67180 1978 if (arrayValues){
1979 delete [] arrayValues;
1980 }
1981 if (arrayWeights){
1982 delete [] arrayWeights;
1983 }
1984 delete [] arrayValuesTruncMean;
1985 delete [] arrayWeightsTruncMean;
1986
28131b57 1987 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1988 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1a3ac627 1989 AliInfo(Form("median = %f ",parameters[2]));
28131b57 1990 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1991 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1992
fe726709 1993 return parameters;
1994}
1995
fe726709 1996//__________________________________________________________________________________________________________________
1997
1998Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1999{
2000 //
2001 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2002 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
ac833e7a 2003 // the flag is set according to the L3/Dipole current value
2004 // current threshold for L3 = 350 A (value provided by DCS)
2005 // current threshold for Dipole = 450 A (value provided by DCS)
fe726709 2006 //
2007 // parameters[0] = mean
2008 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2009 // parameters[2] = median
2010 // parameters[3] = standard deviation wrt mean
2011 // parameters[4] = standard deviation wrt median
2012 //
2013
2014 AliInfo(Form("indexDP = %d",indexDP));
28131b57 2015
fe726709 2016 Int_t nCounts = array->GetEntries();
fe726709 2017 for(Int_t i = 0; i < nCounts; i++) {
2018 AliDCSValue *v = (AliDCSValue *)array->At(i);
2019 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2020 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
535c05eb 2021 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2022 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
fe726709 2023 return NULL;
2024 }
26c1dff2 2025 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2026 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
ac833e7a 2027 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2028 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
fe726709 2029 }
2030 else {
2031 AliError(Form("DCS values for the parameter outside the queried interval"));
44e45fac 2032 }
2033 }
2034
28131b57 2035 return ProcessFloatAll(array);
44e45fac 2036}
125567f8 2037
e97cc90e 2038
44e45fac 2039//_______________________________________________________________
e97cc90e 2040
fe726709 2041Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
44e45fac 2042{
2043 //
2044 // processing Boolean values
2045 //
2046
2047 Bool_t aDCSBool = kTRUE;
2048
2049 AliDCSValue *v = 0x0;
26c1dff2 2050
44e45fac 2051 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2052 v = (AliDCSValue *)array->At(iCount);
26c1dff2 2053 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 2054 AliError(Form("DCS values for the parameter outside the queried interval"));
2055 continue;
2056 }
2057 if (iCount > 0) {
01920f0c 2058 if (aDCSBool != v->GetBool()) {
2059 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2060 change = kTRUE;
2061 }
44e45fac 2062 }
2063 aDCSBool = v->GetBool(); // always keeping last value
26c1dff2 2064 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
44e45fac 2065 }
2066
26c1dff2 2067 Char_t caDCSBool = (Char_t) aDCSBool;
44e45fac 2068 return caDCSBool;
2069
2070}
e97cc90e 2071
44e45fac 2072//_______________________________________________________________
e97cc90e 2073
39e3007b 2074Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
44e45fac 2075{
2076 //
2077 // processing Int values, returning mean
fe726709 2078 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2079 // are outside the queried time interval or their value is out of range
44e45fac 2080 //
2081
28131b57 2082 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2083 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2084 if (timeStartString.IsNull() || timeStartString.IsNull()){
2085 if (timeStartString.IsNull()){
2086 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2087 }
2088 else if (timeStartString.IsNull()){
2089 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2090 }
2091 return 0;
2092 }
2093
2094 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2095 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
44e45fac 2096 Float_t aDCSArrayMean = 0.0;
2097 Int_t iCounts = 0;
28131b57 2098 Float_t valueBeforeSOR = 0;
2099 Float_t valueAfterEOR = 0;
2100 Int_t timestampBeforeSOR = -1;
2101 Int_t timestampAfterEOR = -1;
2102 Int_t ientrySOR = -1;
2103 Int_t ientryEOR = -1;
2104 Float_t* arrayValues = 0x0;
2105 Double_t* arrayWeights = 0x0;
2106 Int_t iCountsRun = 0;
2107 Int_t nCounts = array->GetEntries();
44e45fac 2108
28131b57 2109 for(Int_t i = 0; i < nCounts; i++) {
dd5ac86b 2110 AliDCSValue* v = (AliDCSValue *)array->At(i);
fe726709 2111 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
28131b57 2112 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
fe726709 2113 return AliGRPObject::GetInvalidFloat();
2114 }
26c1dff2 2115 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2116 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
44e45fac 2117 iCounts += 1;
28131b57 2118 // look for the last value before SOR and the first value before EOR
2119 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2120 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2121 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2122 valueBeforeSOR = (Float_t) v->GetInt();
2123 }
2124 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2125 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2126 valueAfterEOR = (Float_t) v->GetInt();
2127 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2128 }
2129 // check if there are DPs between DAQ_time_start and DAQ_time_end
2130 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2131 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2132 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2133 AliDebug(2,Form("entry between SOR and EOR"));
2134 iCountsRun += 1;
2135 }
2136 }
2137 else {
2138 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
44e45fac 2139 }
2140 }
2141
28131b57 2142 if (timestampBeforeSOR == -1){
2143 AliWarning("No value found before SOR!");
2144 }
2145 if (timestampAfterEOR == -1){
2146 AliWarning("No value found after EOR!");
2147 }
2148
2149 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2150 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2151 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2152 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2153 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2154 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2155
2156 Int_t nentriesUsed = 0;
2157 if (iCountsRun > 1){
2158 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2159 AliDebug(2,"Calculating (weighted) Mean");
2160 arrayValues = new Float_t[iCountsRun];
2161 arrayWeights = new Double_t[iCountsRun];
2162 nentriesUsed = iCountsRun;
2163 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2164 AliDCSValue *v = (AliDCSValue *)array->At(i);
2165 Int_t timestamp2 = 0;
2166 if (i < ientryEOR){
2167 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2168 timestamp2 = (Int_t)v1->GetTimeStamp();
2169 }
2170 else {
2171 timestamp2 = timeEnd+1;
2172 }
2173 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2174 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2175 }
2176 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
24f67180 2177 delete [] arrayValues;
2178 delete [] arrayWeights;
28131b57 2179 }
2180 else if (iCountsRun == 1){
2181 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2182 nentriesUsed = 2;
2183 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2184 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2185 arrayValues = new Float_t[2];
2186 arrayWeights = new Double_t[2];
2187 arrayValues[0] = valueBeforeSOR;
2188 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2189 arrayValues[1] = (Float_t)v->GetInt();
2190 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2191 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2192 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2193 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
24f67180 2194 delete [] arrayValues;
2195 delete [] arrayWeights;
28131b57 2196 }
2197 else{
2198 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2199 return AliGRPObject::GetInvalidFloat();
2200 }
2201 }
2202 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2203 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2204 if (timestampBeforeSOR == -1){
2205 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2206 }
2207 if (timestampAfterEOR == -1){
2208 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2209 }
2210 return AliGRPObject::GetInvalidFloat();
2211 }
2212 else {
2213 AliWarning("Using last entry before SOR and first entry after EOR.");
2214 nentriesUsed = 2;
2215 arrayValues = new Float_t[2];
2216 arrayWeights = new Double_t[2];
2217 arrayValues[0] = valueBeforeSOR;
2218 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2219 arrayValues[1] = valueAfterEOR;
2220 arrayWeights[1] = 1.;
2221 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2222 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2223 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
24f67180 2224 delete [] arrayValues;
2225 delete [] arrayWeights;
28131b57 2226 }
2227 }
2228
2229 AliInfo(Form("mean = %f ", aDCSArrayMean));
44e45fac 2230 return aDCSArrayMean;
e97cc90e 2231
44e45fac 2232}
2233//_______________________________________________________________
e7a6790f 2234
39e3007b 2235Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
44e45fac 2236{
2237 //
fe726709 2238 // processing Int values, returning mean
2239 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2240 // are outside the queried time interval or their value is out of range
44e45fac 2241 //
2242
28131b57 2243 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2244 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2245 if (timeStartString.IsNull() || timeStartString.IsNull()){
2246 if (timeStartString.IsNull()){
2247 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2248 }
2249 else if (timeStartString.IsNull()){
2250 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2251 }
2252 return 0;
2253 }
2254
2255 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2256 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
44e45fac 2257 Float_t aDCSArrayMean = 0.0;
2258 Int_t iCounts = 0;
28131b57 2259 Float_t valueBeforeSOR = 0;
2260 Float_t valueAfterEOR = 0;
2261 Int_t timestampBeforeSOR = -1;
2262 Int_t timestampAfterEOR = -1;
2263 Int_t ientrySOR = -1;
2264 Int_t ientryEOR = -1;
2265 Float_t* arrayValues = 0x0;
2266 Double_t* arrayWeights = 0x0;
2267 Int_t iCountsRun = 0;
2268 Int_t nCounts = array->GetEntries();
44e45fac 2269
28131b57 2270 for(Int_t i = 0; i < nCounts; i++) {
dd5ac86b 2271 AliDCSValue* v = (AliDCSValue *)array->At(i);
fe726709 2272 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
28131b57 2273 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
fe726709 2274 return AliGRPObject::GetInvalidFloat();
2275 }
26c1dff2 2276 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
28131b57 2277 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
44e45fac 2278 iCounts += 1;
28131b57 2279 // look for the last value before SOR and the first value before EOR
2280 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2281 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2282 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2283 valueBeforeSOR = (Float_t)v->GetUInt();
2284 }
2285 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2286 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2287 valueAfterEOR = (Float_t)v->GetUInt();
2288 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2289 }
2290 // check if there are DPs between DAQ_time_start and DAQ_time_end
2291 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2292 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2293 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2294 AliDebug(2,Form("entry between SOR and EOR"));
2295 iCountsRun += 1;
2296 }
2297 }
2298 else {
2299 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
44e45fac 2300 }
2301 }
2302
28131b57 2303 if (timestampBeforeSOR == -1){
2304 AliWarning("No value found before SOR!");
2305 }
2306 if (timestampAfterEOR == -1){
2307 AliWarning("No value found after EOR!");
2308 }
2309
2310 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2311 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2312 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2313 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2314 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2315 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2316
2317 Int_t nentriesUsed = 0;
2318 if (iCountsRun > 1){
2319 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2320 AliDebug(2,"Calculating (weighted) Mean");
2321 arrayValues = new Float_t[iCountsRun];
2322 arrayWeights = new Double_t[iCountsRun];
2323 nentriesUsed = iCountsRun;
2324 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2325 AliDCSValue *v = (AliDCSValue *)array->At(i);
2326 Int_t timestamp2 = 0;
2327 if (i < ientryEOR){
2328 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2329 timestamp2 = (Int_t)v1->GetTimeStamp();
2330 }
2331 else {
2332 timestamp2 = timeEnd+1;
2333 }
2334 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2335 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2336 }
611435c2 2337 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
84c9e12a 2338 delete [] arrayValues;
2339 delete [] arrayWeights;
28131b57 2340 }
2341 else if (iCountsRun == 1){
2342 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2343 nentriesUsed = 2;
2344 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2345 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2346 arrayValues = new Float_t[2];
2347 arrayWeights = new Double_t[2];
2348 arrayValues[0] = valueBeforeSOR;
2349 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2350 arrayValues[1] = (Float_t)v->GetUInt();
2351 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2352 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2353 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2354 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
24f67180 2355 delete [] arrayValues;
2356 delete [] arrayWeights;
28131b57 2357 }
2358 else{
2359 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2360 return AliGRPObject::GetInvalidFloat();
2361 }
2362 }
2363 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2364 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2365 if (timestampBeforeSOR == -1){
2366 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2367 }
2368 if (timestampAfterEOR == -1){
2369 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2370 }
2371 return AliGRPObject::GetInvalidFloat();
2372 }
2373 else {
2374 AliWarning("Using last entry before SOR and first entry after EOR.");
2375 nentriesUsed = 2;
2376 arrayValues = new Float_t[2];
2377 arrayWeights = new Double_t[2];
2378 arrayValues[0] = valueBeforeSOR;
2379 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2380 arrayValues[1] = valueAfterEOR;
2381 arrayWeights[1] = 1.;
2382 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2383 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2384 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
24f67180 2385 delete [] arrayValues;
2386 delete [] arrayWeights;
28131b57 2387 }
2388 }
2389
2390 AliInfo(Form("mean = %f ",aDCSArrayMean));
44e45fac 2391 return aDCSArrayMean;
e7a6790f 2392
17984b61 2393}
125567f8 2394
44e45fac 2395
17984b61 2396//_______________________________________________________________
44e45fac 2397
3ba92a38 2398AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
e7a6790f 2399{
44e45fac 2400 // extract DCS pressure maps. Perform fits to save space
2401
44e45fac 2402 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2403 if (map) {
d7edf69d 2404 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
44e45fac 2405 fPressure->MakeSplineFit(map);
2406 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2407 if (fitFraction > kFitFraction ) {
ce996d13 2408 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
44e45fac 2409 } else {
2410 AliInfo("Too few pressure maps fitted!!!");
2411 }
2412 } else {
2413 AliInfo("no atmospheric pressure map extracted!!!");
2414 }
2415 delete map;
2416
2417 return fPressure;
17984b61 2418}
e97cc90e 2419
1e27bb6b 2420
2421
2422//_______________________________________________________________
03e5ee4f 2423Int_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 2424{
44e45fac 2425 //
2426 // Retrieves logbook and trigger information from the online logbook
2427 // This information is needed for prompt reconstruction
2428 //
2429 // Parameters are:
2430 // Run number
2431 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2432 // cdbRoot
2433 //
2434 // returns:
2435 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2436 // 0 on success and no run was found
2437 // negative on error
2438 //
2439 // This function is NOT called during the preprocessor run in the Shuttle!
2440 //
2441
2442 // defaults
2443 if (dbPort == 0)
2444 dbPort = 3306;
2445
2446 // CDB connection
2447 AliCDBManager* cdb = AliCDBManager::Instance();
2448 cdb->SetDefaultStorage(cdbRoot);
2449
2450 // SQL connection
2451 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2452
2453 if (!server)
2454 {
2455 Printf("ERROR: Could not connect to DAQ LB");
2456 return -1;
2457 }
2458
2459 // main logbook
2460 TString sqlQuery;
5d43966f 2461 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
44e45fac 2462 TSQLResult* result = server->Query(sqlQuery);
2463 if (!result)
2464 {
2465 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2466 return -2;
2467 }
2468
2469 if (result->GetRowCount() == 0)
2470 {
2471 Printf("ERROR: Run %d not found", run);
2472 delete result;
2473 return -3;
2474 }
2475
2476 TSQLRow* row = result->Next();
2477 if (!row)
2478 {
2479 Printf("ERROR: Could not receive data from run %d", run);
2480 delete result;
2481 return -4;
2482 }
2483
26c1dff2 2484 TString timeStartString(row->GetField(0));
44e45fac 2485 TString runType(row->GetField(1));
26c1dff2 2486 TString detectorMaskString(row->GetField(2));
2487 TString l3CurrentString(row->GetField(3));
2488 TString dipoleCurrentString(row->GetField(4));
5d43966f 2489 TString beamTypeString(row->GetField(5));
26c1dff2 2490 time_t timeStart = (time_t)(timeStartString.Atoi());
2491 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2492 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2493 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
03e5ee4f 2494 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2495 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
9f08228b 2496 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
2497 beamTypeString="A-A";
2498 }
44e45fac 2499
26c1dff2 2500 AliGRPObject * grpObj = new AliGRPObject();
2501 grpObj->SetTimeStart(timeStart);
2502 grpObj->SetRunType((TString)(row->GetField(1)));
2503 grpObj->SetDetectorMask(detectorMask);
2504 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2505 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
03e5ee4f 2506 grpObj->SetL3Polarity(l3Polarity);
2507 grpObj->SetDipolePolarity(dipolePolarity);
48fcacdc 2508 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
9f08228b 2509 grpObj->SetBeamType(beamTypeString);
26c1dff2 2510
44e45fac 2511 delete row;
2512 row = 0;
2513
2514 delete result;
2515 result = 0;
2516
2517 Printf("Storing GRP/GRP/Data object with the following content");
26c1dff2 2518 grpObj->Dump();
44e45fac 2519
2520 AliCDBMetaData metadata;
26c1dff2 2521 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
44e45fac 2522 metadata.SetComment("GRP Output parameters received during online running");
2523
2524 AliCDBId id("GRP/GRP/Data", run, run);
26c1dff2 2525 Bool_t success = cdb->Put(grpObj, id, &metadata);
44e45fac 2526
26c1dff2 2527 delete grpObj;
44e45fac 2528
2529 if (!success)
2530 {
2531 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2532 return -5;
2533 }
2534
2535 // Receive trigger information
2536 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2537 result = server->Query(sqlQuery);
2538 if (!result)
2539 {
2540 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2541 return -11;
2542 }
2543
2544 if (result->GetRowCount() == 0)
2545 {
2546 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2547 delete result;
2548 return -12;
2549 }
2550
2551 row = result->Next();
2552 if (!row)
2553 {
2554 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2555 delete result;
2556 return -13;
2557 }
2558
2559 TString triggerConfig(row->GetField(0));
2560
2561 delete row;
2562 row = 0;
2563
2564 delete result;
2565 result = 0;
2566
2567 Printf("Found trigger configuration: %s", triggerConfig.Data());
2568
2569 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2570 if (!runcfg)
2571 {
2572 Printf("ERROR: Could not create CTP configuration object");
2573 return -14;
2574 }
2575
2576 metadata.SetComment("CTP run configuration received during online running");
2577
2578 AliCDBId id2("GRP/CTP/Config", run, run);
2579 success = cdb->Put(runcfg, id2, &metadata);
2580
2581 delete runcfg;
2582 runcfg = 0;
2583
2584 if (!success)
2585 {
2586 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2587 return -15;
2588 }
2589
03e5ee4f 2590
2591 // Receive list of GDCs for this run
2592 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2593 result = server->Query(sqlQuery);
2594 if (!result)
2595 {
2596 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2597 return -24;
2598 }
2599
2600 if (result->GetRowCount() == 0)
2601 {
2602 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2603 delete result;
2604 return -25;
2605 }
2b81b7d0 2606
2607 gdc = "";
2608 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2609 row = result->Next();
2610 if (!row)
2611 {
2612 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2613 delete result;
2614 return -26;
2615 }
2616 gdc += row->GetField(0);
2617 gdc += " ";
2618 }
2619
03e5ee4f 2620 delete row;
2621 row = 0;
2622
2623 delete result;
2624 result = 0;
2625
2626 Printf("Found GDC: %s", gdc.Data());
2627
44e45fac 2628 // get last run with same run type that was already processed by the SHUTTLE
2629
2630 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());
2631 result = server->Query(sqlQuery);
2632 if (!result)
2633 {
2634 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2635 return -21;
2636 }
2637
2638 if (result->GetRowCount() == 0)
2639 {
2640 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2641 delete result;
2642 return -22;
2643 }
2644
2645 row = result->Next();
2646 if (!row)
2647 {
2648 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2649 delete result;
2650 return -23;
2651 }
2652
2653 TString lastRunStr(row->GetField(0));
2654 Int_t lastRun = lastRunStr.Atoi();
2655
2656 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2657
2658 delete row;
2659 row = 0;
2660
2661 delete result;
2662 result = 0;
2663
2664 server->Close();
2665 delete server;
2666 server = 0;
2667
2668 return lastRun;
1e27bb6b 2669}
0254e751 2670//------------------------------------------------------------------------------------------------------
4cbf81c1 2671Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
0254e751 2672
2673 //
2674 // Method to processo LHC Energy information
2675 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2676 //
2677
2678 Int_t nCounts = array->GetEntries();
2679 Float_t energy = -1;
4cbf81c1 2680 Double_t timeEnergy = -1;
2681 Int_t indexEnergy = -1;
2682 Bool_t foundEnergy = kFALSE;
2683
0254e751 2684 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
0d361338 2685 if (nCounts ==0){
2686 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2687 }
2688 else{
4cbf81c1 2689 for (Int_t i = 0; i < nCounts; i++){
0d361338 2690 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
4cbf81c1 2691 if (dcs){
2692 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
2693 timeEnergy = dcs->GetTimeStamp();
2694 indexEnergy = i;
2695 foundEnergy = kTRUE;
2696 }
2697 else{
2698 break;
2699 }
0d361338 2700 }
0254e751 2701 }
4cbf81c1 2702 if (!foundEnergy){
2703 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
2704 }
2705 else {
2706 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
2707 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2708 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
e541e2aa 2709 }
0254e751 2710 }
2711
2712 return energy;
2713}
8c1f1006 2714//------------------------------------------------------------------------------------------------------
17fd2848 2715AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
8c1f1006 2716{
2717 //
2718 // Method to process LHC-Clock Phase data
2719 // Only the values between DAQ_time_start and DAQ_time_end are kept
2720 //
2721 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
2722
2723 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
0c191635 2724 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
8c1f1006 2725
17fd2848 2726 TString timeCreatedStr = GetRunParameter("time_created");
2727 Double_t timeCreated = timeCreatedStr.Atof();
2728
8c1f1006 2729 Int_t nCounts = beam1phase->GetEntries();
2730 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
2731 if (nCounts ==0){
2732 AliWarning("No beam1 LHC clock phase values found!");
2733 delete phaseObj;
2734 return NULL;
2735 }
2736 else{
0c191635 2737 Double_t prevPhase = 0;
8c1f1006 2738 for (Int_t i = 0; i < nCounts; i++){
2739 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
2740 if (dcs){
f1226569 2741 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
2742 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
0c191635 2743 if ((i == 0) || (i == (nCounts-1)) ||
2744 !foundBeam1Phase ||
2745 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2746 prevPhase = dcs->GetDouble(0);
2747 foundBeam1Phase = kTRUE;
2748 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
2749 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2750 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2751 }
8c1f1006 2752 }
2753 }
2754 }
2755 if (!foundBeam1Phase){
2756 AliError("No beam1 LHC clock phase values found within the run!");
2757 delete phaseObj;
2758 return NULL;
2759 }
2760 }
2761
2762 nCounts = beam2phase->GetEntries();
2763 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
2764 if (nCounts ==0){
2765 AliWarning("No beam2 LHC clock phase values found!");
2766 delete phaseObj;
2767 return NULL;
2768 }
2769 else{
0c191635 2770 Double_t prevPhase = 0;
8c1f1006 2771 for (Int_t i = 0; i < nCounts; i++){
2772 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
2773 if (dcs){
17fd2848 2774 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
0c191635 2775 if ((i == 0) || (i == (nCounts-1)) ||
2776 !foundBeam2Phase ||
2777 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2778 prevPhase = dcs->GetDouble(0);
2779 foundBeam2Phase = kTRUE;
2780 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
2781 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2782 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2783 }
8c1f1006 2784 }
2785 }
2786 }
2787 if (!foundBeam2Phase){
2788 AliError("No beam2 LHC clock phase values found within the run!");
2789 delete phaseObj;
2790 return NULL;
2791 }
2792 }
2793
2794 return phaseObj;
2795}