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