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