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