1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Class AliGRPPreprocessor
20 // Global Run Parameters (GRP) preprocessor
21 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 // Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN
23 // Modified: Chiara.Zampolli@cern.ch CERN
24 //-------------------------------------------------------------------------
29 #include <TObjString.h>
30 #include <TObjArray.h>
37 #include "AliGRPPreprocessor.h"
38 #include "AliGRPObject.h"
39 #include "AliDCSSensor.h"
40 #include "AliSplineFit.h"
41 #include "AliDCSSensorArray.h"
42 #include "AliRawEventHeaderVersions.h"
44 #include "AliTriggerConfiguration.h"
45 #include "AliTriggerRunScalers.h"
47 #include "AliCDBMetaData.h"
49 #include "AliESDVertex.h"
50 #include "AliLHCReader.h"
51 #include "AliLHCData.h"
52 #include "AliDCSArray.h"
55 class AliShuttleInterface;
57 // needed for ReceivePromptRecoParameters
59 #include <TSQLServer.h>
60 #include <TSQLResult.h>
62 #include <AliCDBManager.h>
63 #include <AliCDBMetaData.h>
65 #include <AliTriggerConfiguration.h>
66 #include <AliCTPTimeParams.h>
68 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
70 ClassImp(AliGRPPreprocessor)
72 //_______________________________________________________________
74 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook for PHYSICS runs, when beamType from DAQ logbook == NULL
75 const Int_t AliGRPPreprocessor::fgknDAQLbParReduced = 7; // num parameters in the logbook for the other cases
76 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
77 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
78 const Int_t AliGRPPreprocessor::fgknLHCDP = 5; // number of dcs dps from LHC data
79 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
87 "L3_BSF17_Temperature",
91 "L3_BSF4_Temperature",
95 "L3_BKF17_Temperature",
99 "L3_BKF4_Temperature",
103 "L3_BSF13_Temperature",
107 "L3_BSF8_Temperature",
111 "L3_BKF13_Temperature",
115 "L3_BKF8_Temperature",
119 "Dipole_Inside_Temperature",
123 "Dipole_Outside_Temperature",
125 "CavernAtmosPressure",
126 "SurfaceAtmosPressure",
127 "CavernAtmosPressure2"
130 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
134 "L3_BSF17_Temperature",
138 "L3_BSF4_Temperature",
142 "L3_BKF17_Temperature",
146 "L3_BKF4_Temperature",
150 "L3_BSF13_Temperature",
154 "L3_BSF8_Temperature",
158 "L3_BKF13_Temperature",
162 "L3_BKF8_Temperature",
166 "Dipole_Inside_Temperature",
170 "Dipole_Outside_Temperature"
173 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
174 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
177 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
178 "dip/acc/LHC/Beam/Energy.Energy",
179 "dip/acc/LHC/RunControl/MachineMode.value",
180 "dip/acc/LHC/RunControl/BeamMode.value",
181 "dip/acc/LHC/RunControl/BeamType/Beam1.payload",
182 "dip/acc/LHC/RunControl/BeamType/Beam2.payload"
184 const char* kppError[] = {
186 "(DAQ logbook ERROR)",
188 "(Trigger Scalers not found in DCS FXS - ERROR)",
189 "(DCS data points ERROR)",
190 "(Trigger Configuration ERROR)",
191 "(DAQ logbook ERROR determining partition of the run)",
192 "(CTP timing ERROR)",
193 "(SPD Mean Vertex ERROR)",
194 "(DCS FXS Error for LHC Data)",
198 //_______________________________________________________________
200 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
201 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))
203 // constructor - shuttle must be instantiated!
205 AddRunType("COSMIC");
207 AddRunType("PHYSICS");
208 AddRunType("CALIBRATION_BC");
209 AddRunType("CALIBRATION_CENTRAL");
210 AddRunType("CALIBRATION_EMD");
211 AddRunType("CALIBRATION_MB");
212 AddRunType("CALIBRATION_SEMICENTRAL");
213 AddRunType("CALIBRATION");
214 AddRunType("PEDESTAL");
215 AddRunType("STANDALONE");
218 AddRunType("PULSER");
219 AddRunType("STANDALONE_PULSER");
220 AddRunType("STANDALONE_BC");
223 fminFloat = -FLT_MAX;
224 fmaxDouble = DBL_MAX;
225 fminDouble = -DBL_MAX;
231 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
232 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
233 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
234 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
235 AliInfo(Form("Max allowed integer = %d",fmaxInt));
236 AliInfo(Form("Min allowed integer = %d",fminInt));
237 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
238 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
240 ffailedDPs->SetOwner(kTRUE);
243 //_______________________________________________________________
245 AliGRPPreprocessor::~AliGRPPreprocessor()
254 //_______________________________________________________________
256 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
258 // Initialize preprocessor
260 AliPreprocessor::Initialize(run, startTime, endTime);
262 AliInfo("Initialization of the GRP preprocessor.");
263 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
264 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
265 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
266 for(Int_t j = 0; j < kNumSensors; j++) {
267 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
268 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
270 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
272 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
274 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
275 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
276 ffailedDPs->AddAt(dp,iDP);
281 //_______________________________________________________________
283 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
285 // process data retrieved by the Shuttle
287 // retrieving "partition" and "detector" fields from DAQ logbook to
288 // determine the partition in which the run was taken
289 // the partition is used to decide how to react in case of errors for CTP
291 TString partition = (TString)GetRunParameter("partition");
292 TString detector = (TString)GetRunParameter("detector");
294 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
295 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
297 //=================//
299 //=================//
302 Int_t iDaqLB = ProcessDaqLB(grpobj);
303 TString runType = (TString)GetRunType();
304 TString beamType = (TString)GetRunParameter("beamType");
305 //if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
306 if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && !beamType.IsNull()) || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType.IsNull()) || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
307 Log(Form("DAQ Logbook, successful!"));
309 Log(Form("DAQ Logbook, could not get all expected entries!!!"));
313 //=================//
315 //=================//
316 UInt_t iDaqFxs = ProcessDaqFxs();
318 Log(Form("DAQ FXS, successful!"));
320 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
324 //=================//
326 //=================//
327 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
329 Log(Form("DCS FXS, successful!"));
330 } else if (iDcsFxs ==1) {
331 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
334 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
338 //=================//
339 // DCS data points //
340 //=================//
341 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
342 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
343 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-1));
344 if (fdaqStartEndTimeOk){
345 if( entries < fgknDCSDP-1 ) { // FIXME (!= ) L3_BSF4_H3 are not working yet...
346 Log(Form("Problem with the DCS data points!!! Only %d/%d entries found",entries,fgknDCSDP-4));
347 Log(Form("The DPs giving problems were:"));
348 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
349 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
351 TString name = dpString->String();
352 if (name != "L3_BSF4_H3"){
353 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
356 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()));
362 else Log(Form("DCS data points, successful!"));
364 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"));
366 //=======================//
367 // Trigger Configuration //
368 //=======================//
370 const char * triggerConf = GetTriggerConfiguration();
372 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
373 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
374 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
376 Log(Form("No dummy CTP configuration entry found, going into error..."));
380 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
382 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
386 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
387 runcfg->SetTitle(titleCTPcfg);
388 AliCDBMetaData metaData;
389 metaData.SetResponsible("Roman Lietava");
390 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
391 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
392 Log("Unable to store the dummy CTP run configuration object to OCDB!");
399 else if (!partition.IsNull() && detector.IsNull()){ // global partition
400 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
401 if (triggerConf!= NULL) {
402 Log("Found trigger configuration in DAQ logbook");
403 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
405 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
409 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
410 runcfg->SetTitle(titleCTPcfg);
411 AliCDBMetaData metaData;
412 metaData.SetBeamPeriod(0);
413 metaData.SetResponsible("Roman Lietava");
414 metaData.SetComment("CTP run configuration from DAQ logbook");
415 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
416 Log("Unable to store the CTP run configuration object to OCDB!");
423 Log("Trigger configuration NULL in DAQ logbook");
429 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
433 //===========================//
434 // Trigger Timing Parameters //
435 //===========================//
438 const char * triggerCTPtiming = GetCTPTimeParams();
440 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
441 Log("STANDALONE partition for current run, using CTP timing params dummy value");
442 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
444 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
448 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
450 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
454 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
455 runCTPtiming->SetTitle(titleCTPtiming);
456 AliCDBMetaData metadata;
457 metadata.SetResponsible("Roman Lietava");
458 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
459 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
460 Log("Unable to store the dummy CTP timing params object to OCDB!");
467 else if (!partition.IsNull() && detector.IsNull()){ // global partition
468 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
469 if (triggerCTPtiming!= NULL) {
470 Log("Found trigger timing params in DAQ logbook");
471 AliDebug(2,Form("%s",triggerCTPtiming));
472 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
474 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
478 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
479 runCTPtiming->SetTitle(titleCTPtiming);
480 AliCDBMetaData metadata;
481 metadata.SetBeamPeriod(0);
482 metadata.SetResponsible("Roman Lietava");
483 metadata.SetComment("CTP timing params from DAQ logbook");
484 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
485 Log("Unable to store the CTP timing params object to OCDB!");
492 Log("Trigger timing params NULL in DAQ logbook");
498 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
503 //=================//
505 //=================//
507 UInt_t iLHCData = ProcessLHCData(grpobj);
508 if( iLHCData == 0 ) {
509 Log(Form("LHC Data from DCS FXS, successful!"));
510 } else if (iLHCData == 1) {
511 Log(Form("LHC Data, problems with DCS FXS!"));
513 } else if (iLHCData ==3){
514 Log(Form("Problems in storing LHC Data - but not going into Error"));
516 Log(Form("LHC Data problems"));
520 //==================//
521 // SPD Mean Vertex //
522 //==================//
523 if (runType == "PHYSICS"){
524 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
525 if( iSPDMeanVertex == 1 ) {
526 Log(Form("SPD Mean Vertex, successful!"));
528 Log(Form("SPD Mean Vertex failed!!!"));
533 Log("SPD Mean Vertex not processed since runType != PHYSICS");
536 // storing AliGRPObject in OCDB
539 md.SetResponsible("Chiara Zampolli");
540 md.SetComment("Output parameters from the GRP preprocessor.");
542 Bool_t result = kTRUE;
543 result = Store("GRP", "Data", grpobj, &md);
546 if (result && !error ) {
547 Log("GRP Preprocessor Success");
550 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s",
551 kppError[(error&1)?1:0],
552 kppError[(error&2)?2:0],
553 kppError[(error&4)?3:0],
554 kppError[(error&8)?4:0],
555 kppError[(error&16)?5:0],
556 kppError[(error&32)?6:0],
557 kppError[(error&64)?7:0],
558 kppError[(error&128)?8:0],
559 kppError[(error&256)?9:0],
560 kppError[(error&512)?10:0]
568 //_______________________________________________________________
570 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
573 //Getting the LHC Data from DCS FXS
576 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
577 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
578 if (timeStartString.IsNull() || timeStartString.IsNull()){
579 if (timeStartString.IsNull()){
580 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
582 else if (timeStartString.IsNull()){
583 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
588 Double_t timeStart = timeStartString.Atof();
589 Double_t timeEnd = timeEndString.Atof();
591 // timeStart = 1260646960;
592 //timeEnd = 1260652740;
594 TString fileName = GetFile(kDCS, "LHCData","");
595 if (fileName.Length()>0){
596 AliInfo("Got The LHC Data file");
597 AliLHCReader* lhcReader = new AliLHCReader();
598 TMap* lhcMap = (TMap*)lhcReader->ReadLHCDP(fileName.Data());
600 Log(Form("LHCData map entries = %d",lhcMap->GetEntries()));
602 // Processing data to be put in AliGRPObject
603 TObjArray* energyArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[0]);
604 Float_t energy = ProcessEnergy(energyArray,timeStart,timeEnd);
606 grpobj->SetBeamEnergy(energy);
607 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
610 TObjArray* machineModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[1]);
611 TObjArray* beamModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[2]);
612 if (beamModeArray->GetEntries()!=1){
613 AliWarning("The beam mode changed! Setting it to UNKNOWN and storing array of strings");
614 grpobj->SetLHCState("UNKNOWN");
615 grpobj->SetLHCStateArray(beamModeArray);
618 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(0);
619 TObjString* beamModeString = beamMode->GetStringArray(0);
620 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
621 grpobj->SetLHCState(beamModeString->String());
624 if (machineModeArray->GetEntries()!=1){
625 AliWarning("The machine mode changed! Setting it to UNKNOWN and storing array of strings");
626 grpobj->SetMachineMode("UNKNOWN");
627 grpobj->SetMachineModeArray(machineModeArray);
630 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(0);
631 TObjString* machineModeString = machineMode->GetStringArray(0);
632 AliInfo(Form("Machine Mode = %s",(machineModeString->String()).Data()));
633 grpobj->SetMachineMode(machineModeString->String());
635 TObjArray* beam1Array = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[3]);
636 TObjArray* beam2Array = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[4]);
638 // Processing data to go to AliLHCData object
639 AliLHCData* dt = new AliLHCData(lhcMap,timeStart,timeEnd);
641 // storing AliLHCData in OCDB
644 md.SetResponsible("Ruben Shahoyan");
645 md.SetComment("LHC data from the GRP preprocessor.");
647 Bool_t result = kTRUE;
648 result = Store("GRP", "LHCData", dt, &md);
650 if (result) return 0;
654 AliError("Cannot read correctly LHCData file");
660 AliError("No LHCData file found in DCS FXS");
666 //_______________________________________________________________
668 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
671 //Getting the SPD Mean Vertex
674 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
675 Bool_t storeResult = kTRUE;
676 if (list !=0x0 && list->GetEntries()!=0)
678 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
680 for (Int_t jj=0;jj<list->GetEntries();jj++){
681 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
682 AliInfo(Form("found source %s", str->String().Data()));
683 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
684 if (fileNameRun.Length()>0){
685 AliInfo(Form("Got the file %s", fileNameRun.Data()));
686 TFile daqFile(fileNameRun.Data(),"READ");
687 if (daqFile.IsOpen()) {
688 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
691 // storing in the OCDB
693 md.SetResponsible("Cvetan Cheshkov");
694 md.SetComment("SPD Mean Vertex");
695 storeResult = Store("GRP", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
698 AliWarning("No SPD Mean Vertex object found in file");
702 AliError("Can't open file");
703 storeResult = kFALSE;
707 AliWarning("No file found for current source for SPD Mean Vertex");
712 AliWarning("No list found for SPD Mean Vertex");
715 if (list) delete list;
721 //_______________________________________________________________
723 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
725 //Getting the DAQ lb information
727 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
728 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
729 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
730 TString beamType = (TString)GetRunParameter("beamType");
731 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
732 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
733 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
734 TString runType = (TString)GetRunType();
736 UInt_t nparameter = 0;
738 grpObj->SetTimeStart(timeStart);
739 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
743 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
747 grpObj->SetTimeEnd(timeEnd);
748 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
752 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
755 if (beamEnergy != 0){
756 grpObj->SetBeamEnergy(beamEnergy);
757 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
758 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
759 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
760 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
764 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
765 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
766 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, and producing an error (beamType = %s, runType = %s)",beamType.Data(), runType.Data()));
769 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, but not producing any error (beamType = NULL, runType = %s)", runType.Data()));
774 if (beamType.Length() != 0){
775 grpObj->SetBeamType(beamType);
776 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
780 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
784 if (numberOfDetectors != 0){
785 grpObj->SetNumberOfDetectors(numberOfDetectors);
786 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
790 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
793 if (detectorMask != 0){
794 grpObj->SetDetectorMask(detectorMask);
795 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
799 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
802 if (lhcPeriod.Length() != 0) {
803 grpObj->SetLHCPeriod(lhcPeriod);
804 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
808 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
810 if (runType.Length() != 0) {
811 grpObj->SetRunType(runType);
812 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
816 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
822 //_______________________________________________________________
824 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
826 //======DAQ FXS======//
828 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
829 TList* list = GetFileSources(kDAQ);
831 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
835 if (list->GetEntries() == 0) {
836 Log("no raw data tags in this run: nothing to merge!");
841 TChain *fRawTagChain = new TChain("T");
843 TIterator* iter = list->MakeIterator();
845 while ((obj = iter->Next())) {
846 TObjString* objStr = dynamic_cast<TObjString*> (obj);
848 Log(Form("Found source %s", objStr->String().Data()));
849 TList* list2 = GetFileIDs(kDAQ, objStr->String());
851 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
852 delete fRawTagChain; fRawTagChain=0;
855 Log(Form("Number of ids: %d",list2->GetEntries()));
856 for(Int_t i = 0; i < list2->GetEntries(); i++) {
857 TObjString *idStr = (TObjString *)list2->At(i);
858 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
859 if (fileName.Length() > 0) {
860 Log(Form("Adding file in the chain: %s",fileName.Data()));
861 fRawTagChain->Add(fileName.Data());
864 Log(Form("Could not retrieve file with id %s from source %s: "
865 "connection problems with DAQ FXS!",
866 idStr->String().Data(), objStr->String().Data()));
868 delete list2; list2=0;
869 delete fRawTagChain; fRawTagChain=0;
877 TString fRawDataFileName = "GRP_Merged.tag.root";
878 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
880 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
881 Log("Error merging raw data files!!!");
885 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
886 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
889 Log("Problem storing raw data tags in local file!!!");
891 Log("Raw data tags merged successfully!!");
896 delete fRawTagChain; fRawTagChain=0;
898 if (result == kFALSE) {
906 //_______________________________________________________________
907 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
910 // processing the info
911 // stored in the DCS FXS
912 // coming from the trigger
914 // Get the CTP counters information
916 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
917 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
918 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
920 Log(Form("No dummy CTP scalers entry found, going into error..."));
924 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
926 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
930 AliCDBMetaData metaData;
931 metaData.SetResponsible("Roman Lietava");
932 metaData.SetComment("CTP scalers from dummy entry in OCDB");
933 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
934 Log("Unable to store the dummy CTP scalers object to OCDB!");
941 else if (!partition.IsNull() && detector.IsNull()){ // global partition
942 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
943 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
944 if (countersfile.IsNull()) {
945 Log("No CTP counters files has been found: empty source!");
949 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
950 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
952 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
956 AliCDBMetaData metaData;
957 metaData.SetBeamPeriod(0);
958 metaData.SetResponsible("Roman Lietava");
959 metaData.SetComment("CTP scalers");
960 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
961 Log("Unable to store the CTP scalers object to OCDB!");
970 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
977 //_______________________________________________________________
979 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
983 // processing DCS DPs
986 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
987 Int_t nL3Entries = 0;
988 Int_t nDipoleEntries = 0;
989 Int_t nEnvEntries = 0;
990 Int_t nHallProbesEntries = 0;
991 nL3Entries = ProcessL3DPs(valueMap, grpObj);
992 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
993 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
994 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
995 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
996 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
997 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1002 //_______________________________________________________________
1004 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1011 Int_t nL3Entries = 0;
1013 TObjArray *array = 0x0;
1015 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1017 AliInfo(Form("==========L3Current==========="));
1018 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1019 indexDP = kL3Current;
1020 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1022 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1025 if (array->GetEntries() == 0){
1026 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1029 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1030 if (floatDCS != NULL){
1031 grpObj->SetL3Current(floatDCS);
1043 ffailedDPs->RemoveAt(indexDP);
1047 if (array) array = 0x0;
1049 AliInfo(Form("==========L3Polarity==========="));
1050 indexDP = kL3Polarity;
1051 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1053 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1056 if (array->GetEntries() == 0){
1057 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1060 Bool_t change = kFALSE;
1061 Char_t charDCS = ProcessBool(array,change);
1062 if (change == kFALSE){
1063 grpObj->SetL3Polarity(charDCS);
1064 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1065 ffailedDPs->RemoveAt(indexDP);
1069 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1070 ffailedDPs->RemoveAt(indexDP);
1074 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]));
1082 //_______________________________________________________________
1084 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1090 Int_t nDipoleEntries = 0;
1091 TObjArray *array = 0x0;
1093 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1095 AliInfo(Form("==========DipoleCurrent==========="));
1096 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1097 indexDP = kDipoleCurrent;
1098 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1100 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1103 if (array->GetEntries() == 0){
1104 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1107 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1108 if (floatDCS != NULL){
1109 grpObj->SetDipoleCurrent(floatDCS);
1121 ffailedDPs->RemoveAt(indexDP);
1125 if (array) array = 0x0;
1127 AliInfo(Form("==========DipolePolarity==========="));
1128 indexDP = kDipolePolarity;
1129 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1131 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1134 if (array->GetEntries() == 0){
1135 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1138 Bool_t change = kFALSE;
1139 Char_t charDCS = ProcessBool(array,change);
1141 grpObj->SetDipolePolarity(charDCS);
1142 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1143 ffailedDPs->RemoveAt(indexDP);
1147 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1148 ffailedDPs->RemoveAt(indexDP);
1152 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]));
1157 return nDipoleEntries;
1160 //_______________________________________________________________
1162 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1166 // evironment conditions (temperature, pressure) info
1168 Int_t nEnvEntries = 0;
1169 TObjArray *array = 0x0;
1172 AliInfo(Form("==========CavernTemperature==========="));
1173 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1174 indexDP = kCavernTemperature;
1175 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1177 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1180 if (array->GetEntries() == 0){
1181 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1184 Float_t *floatDCS = ProcessFloatAll(array);
1185 if (floatDCS != NULL){
1186 grpObj->SetCavernTemperature(floatDCS);
1197 ffailedDPs->RemoveAt(indexDP);
1202 if (array) array = 0x0;
1204 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1205 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1206 //dcsSensorArray->Print();
1207 if( fPressure->NumFits()<kNumSensors ) {
1208 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1210 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1212 AliInfo(Form("==========CavernAtmosPressure==========="));
1213 indexDP = kCavernAtmosPressure;
1214 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1215 TGraph* graph = sensorCavernP2->GetGraph();
1216 AliDebug(3,Form("index = %d",indexDP));
1217 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1218 AliDebug(2,Form("graph = %p",graph));
1219 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1220 if(sensorCavernP2->GetFit() || graph) {
1221 if (sensorCavernP2->GetFit()){
1222 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1225 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1227 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1228 ffailedDPs->RemoveAt(indexDP);
1231 //if (sensorP2) delete sensorP2;
1233 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] ));
1236 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1237 indexDP = kSurfaceAtmosPressure;
1238 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1239 graph = sensorP2->GetGraph();
1240 AliDebug(3,Form("index = %d",indexDP));
1241 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1242 AliDebug(2,Form("graph = %p",graph));
1243 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1244 if(sensorP2->GetFit() || graph) {
1245 if (sensorP2->GetFit()){
1246 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1249 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1251 grpObj->SetSurfaceAtmosPressure(sensorP2);
1252 ffailedDPs->RemoveAt(indexDP);
1255 //if (sensorP2) delete sensorP2;
1257 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] ));
1260 AliInfo(Form("==========CavernAtmosPressure2==========="));
1261 indexDP = kCavernAtmosPressure2;
1262 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1263 graph = sensorCavernP22->GetGraph();
1264 AliDebug(3,Form("index = %d",indexDP));
1265 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1266 AliDebug(2,Form("graph = %p",graph));
1267 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1268 if(sensorCavernP22->GetFit() || graph) {
1269 if (sensorCavernP22->GetFit()){
1270 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1273 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1275 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1276 ffailedDPs->RemoveAt(indexDP);
1279 //if (sensorP2) delete sensorP2;
1281 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] ));
1287 //_______________________________________________________________
1289 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1295 Int_t nHPEntries = 0;
1296 TObjArray *array = 0x0;
1298 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1300 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1301 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()));
1303 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1304 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1305 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1306 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1308 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1311 if (array->GetEntries() == 0){
1312 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1315 Float_t *floatDCS = ProcessFloatAll(array);
1316 if (floatDCS != NULL){
1317 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]));
1318 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1319 for (Int_t kk = 0 ; kk< 5; kk++){
1320 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1332 ffailedDPs->RemoveAt(indexDP + 7); // 7 = shift in the complete list of DPs to get to the Hall Probes
1338 Log(Form("Hall Probes = %d ", nHPEntries));
1342 //_________________________________________________________________________
1344 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1348 // returning Spline Fit
1351 Int_t entriesarray = array->GetEntries();
1352 Float_t* value = new Float_t[entriesarray];
1353 Float_t* time = new Float_t[entriesarray];
1354 AliDCSValue* v = 0x0;
1355 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1356 v = (AliDCSValue*)array->At(iarray);
1357 value[iarray] = v->GetFloat();
1358 time[iarray] = v->GetTimeStamp();
1359 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1361 TGraph* gr = new TGraph(entriesarray,value,time);
1363 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1366 AliSplineFit *fit = new AliSplineFit();
1367 fit->SetMinPoints(10);
1368 fit->InitKnots(gr,10,10,0.0);
1372 AliWarning(Form("%s: no fit performed",stringID.Data()));
1378 //_________________________________________________________________________
1380 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1387 TString aDCSString="";
1389 AliDCSValue *v = 0x0;
1390 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1391 v = (AliDCSValue *)array->At(iCount);
1392 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1393 AliError(Form("DCS values for the parameter outside the queried interval"));
1397 if (aDCSString != v->GetChar())
1398 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1400 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1405 //__________________________________________________________________________________________________________________
1407 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1410 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1412 // parameters[0] = mean
1413 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1414 // parameters[2] = median
1415 // parameters[3] = standard deviation wrt mean
1416 // parameters[4] = standard deviation wrt median
1419 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1420 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1421 if (timeStartString.IsNull() || timeStartString.IsNull()){
1422 if (timeStartString.IsNull()){
1423 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1425 else if (timeStartString.IsNull()){
1426 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1428 fdaqStartEndTimeOk = kFALSE;
1432 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1433 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1434 Float_t* parameters = new Float_t[5];
1436 Int_t iCountsRun = 0;
1437 Int_t nCounts = array->GetEntries();
1438 Float_t valueBeforeSOR = 0;
1439 Float_t valueAfterEOR = 0;
1440 Int_t timestampBeforeSOR = -1;
1441 Int_t timestampAfterEOR = -1;
1442 Int_t ientrySOR = -1;
1443 Int_t ientryEOR = -1;
1444 Float_t* arrayValues = 0x0;
1445 Double_t* arrayWeights = 0x0;
1446 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1447 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1449 for(Int_t i = 0; i < nCounts; i++) {
1450 AliDCSValue *v = (AliDCSValue *)array->At(i);
1451 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1452 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1453 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1454 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1457 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1458 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1460 // look for the last value before SOR and the first value before EOR
1461 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1462 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1463 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1464 valueBeforeSOR = v->GetFloat();
1466 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1467 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1468 valueAfterEOR = v->GetFloat();
1469 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1471 // check if there are DPs between DAQ_time_start and DAQ_time_end
1472 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1473 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1474 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1475 AliDebug(2,Form("entry between SOR and EOR"));
1480 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1484 if (timestampBeforeSOR == -1){
1485 AliWarning("No value found before SOR");
1487 if (timestampAfterEOR == -1){
1488 AliWarning("No value found after EOR");
1491 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1492 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1493 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1494 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1495 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1496 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1498 Int_t nentriesUsed = 0;
1499 if (iCountsRun > 1){
1500 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1501 AliDebug(2,"Calculating (weighted) Mean and Median");
1502 arrayValues = new Float_t[iCountsRun];
1503 arrayWeights = new Double_t[iCountsRun];
1504 nentriesUsed = iCountsRun;
1505 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1506 AliDCSValue *v = (AliDCSValue *)array->At(i);
1507 Int_t timestamp2 = 0;
1509 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1510 timestamp2 = (Int_t)v1->GetTimeStamp();
1513 timestamp2 = timeEnd+1;
1515 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1516 arrayValues[i-ientrySOR] = v->GetFloat();
1518 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1519 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1521 else if (iCountsRun == 1){
1522 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1524 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1525 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.");
1526 arrayValues = new Float_t[2];
1527 arrayWeights = new Double_t[2];
1528 arrayValues[0] = valueBeforeSOR;
1529 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1530 arrayValues[1] = v->GetFloat();
1531 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1532 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1533 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1534 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1535 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1536 truncMeanFlag = kFALSE;
1539 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");
1540 parameters[0] = AliGRPObject::GetInvalidFloat();
1541 parameters[1] = AliGRPObject::GetInvalidFloat();
1542 parameters[2] = AliGRPObject::GetInvalidFloat();
1543 parameters[3] = AliGRPObject::GetInvalidFloat();
1544 parameters[4] = AliGRPObject::GetInvalidFloat();
1548 else { // iCountsRun == 0, using only the point immediately before SOR
1549 if (timestampBeforeSOR == -1){
1550 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");
1551 parameters[0] = AliGRPObject::GetInvalidFloat();
1552 parameters[1] = AliGRPObject::GetInvalidFloat();
1553 parameters[2] = AliGRPObject::GetInvalidFloat();
1554 parameters[3] = AliGRPObject::GetInvalidFloat();
1555 parameters[4] = AliGRPObject::GetInvalidFloat();
1559 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1560 AliDebug(2,Form("value = %f",valueBeforeSOR));
1561 parameters[0] = valueBeforeSOR;
1562 parameters[2] = valueBeforeSOR;
1563 truncMeanFlag = kFALSE;
1570 Float_t sumweights = 0;
1571 Int_t entriesTruncMean = 0;
1572 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1573 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1575 // calculating SD wrt Mean and Median
1576 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1578 for (Int_t i =0; i< nentriesUsed; i++){
1579 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1580 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1581 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1582 sumweights += arrayWeights[i];
1584 // setting SD wrt Mean
1585 if (sumweights != 0 ){
1586 parameters[3] = TMath::Sqrt(temp1/sumweights);
1589 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1590 parameters[3] = AliGRPObject::GetInvalidFloat();
1592 // setting SD wrt Median
1593 if (nentriesUsed != 0){
1594 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1597 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1598 parameters[4] = AliGRPObject::GetInvalidFloat();
1602 parameters[3] = AliGRPObject::GetInvalidFloat();
1603 parameters[4] = AliGRPObject::GetInvalidFloat();
1606 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1608 AliDebug(2,"Calculating Truncated Mean");
1609 for (Int_t i =0; i< nentriesUsed; i++){
1610 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1611 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1612 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1613 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1614 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1618 AliDebug(2,"Discarding entry");
1621 // setting truncated mean
1622 if (entriesTruncMean >1){
1623 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1624 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1627 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1628 parameters[1] = AliGRPObject::GetInvalidFloat();
1632 parameters[1] = AliGRPObject::GetInvalidFloat();
1635 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1636 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1637 AliInfo(Form("median = %f ",parameters[2]));
1638 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1639 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1644 //__________________________________________________________________________________________________________________
1646 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1649 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1650 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1651 // the flag is set according to the L3/Dipole current value
1652 // current threshold for L3 = 350 A (value provided by DCS)
1653 // current threshold for Dipole = 450 A (value provided by DCS)
1655 // parameters[0] = mean
1656 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1657 // parameters[2] = median
1658 // parameters[3] = standard deviation wrt mean
1659 // parameters[4] = standard deviation wrt median
1662 AliInfo(Form("indexDP = %d",indexDP));
1664 Int_t nCounts = array->GetEntries();
1665 for(Int_t i = 0; i < nCounts; i++) {
1666 AliDCSValue *v = (AliDCSValue *)array->At(i);
1667 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1668 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1669 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1670 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1673 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1674 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1675 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1676 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1679 AliError(Form("DCS values for the parameter outside the queried interval"));
1683 return ProcessFloatAll(array);
1687 //_______________________________________________________________
1689 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1692 // processing Boolean values
1695 Bool_t aDCSBool = kTRUE;
1697 AliDCSValue *v = 0x0;
1699 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1700 v = (AliDCSValue *)array->At(iCount);
1701 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1702 AliError(Form("DCS values for the parameter outside the queried interval"));
1706 if (aDCSBool != v->GetBool()) {
1707 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1711 aDCSBool = v->GetBool(); // always keeping last value
1712 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1715 Char_t caDCSBool = (Char_t) aDCSBool;
1720 //_______________________________________________________________
1722 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1725 // processing Int values, returning mean
1726 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1727 // are outside the queried time interval or their value is out of range
1730 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1731 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1732 if (timeStartString.IsNull() || timeStartString.IsNull()){
1733 if (timeStartString.IsNull()){
1734 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1736 else if (timeStartString.IsNull()){
1737 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1742 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1743 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1744 Float_t aDCSArrayMean = 0.0;
1746 Float_t valueBeforeSOR = 0;
1747 Float_t valueAfterEOR = 0;
1748 Int_t timestampBeforeSOR = -1;
1749 Int_t timestampAfterEOR = -1;
1750 Int_t ientrySOR = -1;
1751 Int_t ientryEOR = -1;
1752 Float_t* arrayValues = 0x0;
1753 Double_t* arrayWeights = 0x0;
1754 Int_t iCountsRun = 0;
1755 Int_t nCounts = array->GetEntries();
1757 for(Int_t i = 0; i < nCounts; i++) {
1758 AliDCSValue* v = (AliDCSValue *)array->At(i);
1759 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1760 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1761 return AliGRPObject::GetInvalidFloat();
1763 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1764 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1766 // look for the last value before SOR and the first value before EOR
1767 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1768 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1769 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1770 valueBeforeSOR = (Float_t) v->GetInt();
1772 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1773 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1774 valueAfterEOR = (Float_t) v->GetInt();
1775 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1777 // check if there are DPs between DAQ_time_start and DAQ_time_end
1778 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1779 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1780 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1781 AliDebug(2,Form("entry between SOR and EOR"));
1786 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1790 if (timestampBeforeSOR == -1){
1791 AliWarning("No value found before SOR!");
1793 if (timestampAfterEOR == -1){
1794 AliWarning("No value found after EOR!");
1797 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1798 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1799 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1800 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1801 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1802 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1804 Int_t nentriesUsed = 0;
1805 if (iCountsRun > 1){
1806 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1807 AliDebug(2,"Calculating (weighted) Mean");
1808 arrayValues = new Float_t[iCountsRun];
1809 arrayWeights = new Double_t[iCountsRun];
1810 nentriesUsed = iCountsRun;
1811 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1812 AliDCSValue *v = (AliDCSValue *)array->At(i);
1813 Int_t timestamp2 = 0;
1815 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1816 timestamp2 = (Int_t)v1->GetTimeStamp();
1819 timestamp2 = timeEnd+1;
1821 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1822 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1824 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1826 else if (iCountsRun == 1){
1827 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1829 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1830 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1831 arrayValues = new Float_t[2];
1832 arrayWeights = new Double_t[2];
1833 arrayValues[0] = valueBeforeSOR;
1834 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1835 arrayValues[1] = (Float_t)v->GetInt();
1836 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1837 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1838 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1839 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1842 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1843 return AliGRPObject::GetInvalidFloat();
1846 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1847 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1848 if (timestampBeforeSOR == -1){
1849 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1851 if (timestampAfterEOR == -1){
1852 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1854 return AliGRPObject::GetInvalidFloat();
1857 AliWarning("Using last entry before SOR and first entry after EOR.");
1859 arrayValues = new Float_t[2];
1860 arrayWeights = new Double_t[2];
1861 arrayValues[0] = valueBeforeSOR;
1862 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1863 arrayValues[1] = valueAfterEOR;
1864 arrayWeights[1] = 1.;
1865 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1866 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1867 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1871 AliInfo(Form("mean = %f ", aDCSArrayMean));
1872 return aDCSArrayMean;
1875 //_______________________________________________________________
1877 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1880 // processing Int values, returning mean
1881 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1882 // are outside the queried time interval or their value is out of range
1885 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1886 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1887 if (timeStartString.IsNull() || timeStartString.IsNull()){
1888 if (timeStartString.IsNull()){
1889 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1891 else if (timeStartString.IsNull()){
1892 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1897 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1898 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1899 Float_t aDCSArrayMean = 0.0;
1901 Float_t valueBeforeSOR = 0;
1902 Float_t valueAfterEOR = 0;
1903 Int_t timestampBeforeSOR = -1;
1904 Int_t timestampAfterEOR = -1;
1905 Int_t ientrySOR = -1;
1906 Int_t ientryEOR = -1;
1907 Float_t* arrayValues = 0x0;
1908 Double_t* arrayWeights = 0x0;
1909 Int_t iCountsRun = 0;
1910 Int_t nCounts = array->GetEntries();
1912 for(Int_t i = 0; i < nCounts; i++) {
1913 AliDCSValue* v = (AliDCSValue *)array->At(i);
1914 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
1915 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
1916 return AliGRPObject::GetInvalidFloat();
1918 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1919 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
1921 // look for the last value before SOR and the first value before EOR
1922 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1923 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1924 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1925 valueBeforeSOR = (Float_t)v->GetUInt();
1927 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1928 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1929 valueAfterEOR = (Float_t)v->GetUInt();
1930 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1932 // check if there are DPs between DAQ_time_start and DAQ_time_end
1933 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1934 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1935 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1936 AliDebug(2,Form("entry between SOR and EOR"));
1941 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1945 if (timestampBeforeSOR == -1){
1946 AliWarning("No value found before SOR!");
1948 if (timestampAfterEOR == -1){
1949 AliWarning("No value found after EOR!");
1952 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1953 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1954 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1955 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1956 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1957 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1959 Int_t nentriesUsed = 0;
1960 if (iCountsRun > 1){
1961 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1962 AliDebug(2,"Calculating (weighted) Mean");
1963 arrayValues = new Float_t[iCountsRun];
1964 arrayWeights = new Double_t[iCountsRun];
1965 nentriesUsed = iCountsRun;
1966 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1967 AliDCSValue *v = (AliDCSValue *)array->At(i);
1968 Int_t timestamp2 = 0;
1970 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1971 timestamp2 = (Int_t)v1->GetTimeStamp();
1974 timestamp2 = timeEnd+1;
1976 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1977 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
1979 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1981 else if (iCountsRun == 1){
1982 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1984 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1985 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1986 arrayValues = new Float_t[2];
1987 arrayWeights = new Double_t[2];
1988 arrayValues[0] = valueBeforeSOR;
1989 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1990 arrayValues[1] = (Float_t)v->GetUInt();
1991 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1992 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1993 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1994 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1997 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1998 return AliGRPObject::GetInvalidFloat();
2001 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2002 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2003 if (timestampBeforeSOR == -1){
2004 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2006 if (timestampAfterEOR == -1){
2007 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2009 return AliGRPObject::GetInvalidFloat();
2012 AliWarning("Using last entry before SOR and first entry after EOR.");
2014 arrayValues = new Float_t[2];
2015 arrayWeights = new Double_t[2];
2016 arrayValues[0] = valueBeforeSOR;
2017 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2018 arrayValues[1] = valueAfterEOR;
2019 arrayWeights[1] = 1.;
2020 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2021 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2022 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2026 AliInfo(Form("mean = %f ",aDCSArrayMean));
2027 return aDCSArrayMean;
2032 //_______________________________________________________________
2034 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2036 // extract DCS pressure maps. Perform fits to save space
2038 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2040 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2041 fPressure->MakeSplineFit(map);
2042 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2043 if (fitFraction > kFitFraction ) {
2044 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2046 AliInfo("Too few pressure maps fitted!!!");
2049 AliInfo("no atmospheric pressure map extracted!!!");
2058 //_______________________________________________________________
2059 Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* dbHost, Int_t dbPort, const char* dbName, const char* user, const char* password, const char *cdbRoot, TString &gdc)
2062 // Retrieves logbook and trigger information from the online logbook
2063 // This information is needed for prompt reconstruction
2067 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2071 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2072 // 0 on success and no run was found
2073 // negative on error
2075 // This function is NOT called during the preprocessor run in the Shuttle!
2083 AliCDBManager* cdb = AliCDBManager::Instance();
2084 cdb->SetDefaultStorage(cdbRoot);
2087 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2091 Printf("ERROR: Could not connect to DAQ LB");
2097 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2098 TSQLResult* result = server->Query(sqlQuery);
2101 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2105 if (result->GetRowCount() == 0)
2107 Printf("ERROR: Run %d not found", run);
2112 TSQLRow* row = result->Next();
2115 Printf("ERROR: Could not receive data from run %d", run);
2120 TString timeStartString(row->GetField(0));
2121 TString runType(row->GetField(1));
2122 TString detectorMaskString(row->GetField(2));
2123 TString l3CurrentString(row->GetField(3));
2124 TString dipoleCurrentString(row->GetField(4));
2125 time_t timeStart = (time_t)(timeStartString.Atoi());
2126 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2127 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2128 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2129 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2130 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2132 AliGRPObject * grpObj = new AliGRPObject();
2133 grpObj->SetTimeStart(timeStart);
2134 grpObj->SetRunType((TString)(row->GetField(1)));
2135 grpObj->SetDetectorMask(detectorMask);
2136 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2137 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2138 grpObj->SetL3Polarity(l3Polarity);
2139 grpObj->SetDipolePolarity(dipolePolarity);
2140 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2148 Printf("Storing GRP/GRP/Data object with the following content");
2151 AliCDBMetaData metadata;
2152 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2153 metadata.SetComment("GRP Output parameters received during online running");
2155 AliCDBId id("GRP/GRP/Data", run, run);
2156 Bool_t success = cdb->Put(grpObj, id, &metadata);
2162 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2166 // Receive trigger information
2167 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2168 result = server->Query(sqlQuery);
2171 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2175 if (result->GetRowCount() == 0)
2177 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2182 row = result->Next();
2185 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2190 TString triggerConfig(row->GetField(0));
2198 Printf("Found trigger configuration: %s", triggerConfig.Data());
2200 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2203 Printf("ERROR: Could not create CTP configuration object");
2207 metadata.SetComment("CTP run configuration received during online running");
2209 AliCDBId id2("GRP/CTP/Config", run, run);
2210 success = cdb->Put(runcfg, id2, &metadata);
2217 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2222 // Receive list of GDCs for this run
2223 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2224 result = server->Query(sqlQuery);
2227 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2231 if (result->GetRowCount() == 0)
2233 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2239 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2240 row = result->Next();
2243 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2247 gdc += row->GetField(0);
2257 Printf("Found GDC: %s", gdc.Data());
2259 // get last run with same run type that was already processed by the SHUTTLE
2261 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());
2262 result = server->Query(sqlQuery);
2265 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2269 if (result->GetRowCount() == 0)
2271 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2276 row = result->Next();
2279 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2284 TString lastRunStr(row->GetField(0));
2285 Int_t lastRun = lastRunStr.Atoi();
2287 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2301 //-----------------------------------------------------------------
2302 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* array){
2305 // Calculating mean over TObjArray from LHC Data
2308 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2309 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2310 if (timeStartString.IsNull() || timeStartString.IsNull()){
2311 if (timeStartString.IsNull()){
2312 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2314 else if (timeStartString.IsNull()){
2315 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2320 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2321 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2322 timeStart = 1260646960;
2323 timeEnd = 1260652740;
2324 Double_t* parameters = new Double_t[5];
2325 parameters[0] = -1.;
2326 parameters[1] = -1.;
2327 parameters[2] = -1.;
2328 parameters[3] = -1.;
2329 parameters[4] = -1.;
2331 Int_t iCountsRun = 0;
2332 Int_t nCounts = array->GetEntries();
2333 printf("ncounts = %d\n",nCounts);
2334 Double_t valueBeforeSOR = 0;
2335 Double_t valueAfterEOR = 0;
2336 Double_t timestampBeforeSOR = -1.;
2337 Double_t timestampAfterEOR = -1.;
2338 Int_t ientrySOR = -1;
2339 Int_t ientryEOR = -1;
2340 Double_t* arrayValues = 0x0;
2341 Double_t* arrayWeights = 0x0;
2342 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2343 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2345 for(Int_t i = 0; i < nCounts; i++) {
2346 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2347 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2348 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2350 // look for the last value before SOR and the first value before EOR
2351 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2352 timestampBeforeSOR = dcs->GetTimeStamp();
2353 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2354 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2356 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2357 timestampAfterEOR = dcs->GetTimeStamp();
2358 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2359 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2361 // check if there are DPs between DAQ_time_start and DAQ_time_end
2362 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2363 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2364 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2365 AliDebug(2,Form("entry between SOR and EOR\n"));
2370 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2374 if (timestampBeforeSOR == -1.){
2375 printf("No value found before SOR\n");
2377 if (timestampAfterEOR == -1.){
2378 printf("No value found after EOR\n");
2381 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2382 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2383 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2384 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2385 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2386 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2388 Int_t nentriesUsed = 0;
2389 if (iCountsRun > 1){
2390 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2391 printf("Calculating (weighted) Mean and Median\n" );
2392 arrayValues = new Double_t[iCountsRun];
2393 arrayWeights = new Double_t[iCountsRun];
2394 nentriesUsed = iCountsRun;
2395 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2396 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2397 Double_t timestamp2 = 0;
2399 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2400 timestamp2 = dcs1->GetTimeStamp();
2403 timestamp2 = (Double_t)timeEnd+1;
2405 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2406 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2407 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2409 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2410 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2412 else if (iCountsRun == 1){
2413 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2415 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2416 printf("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR. Truncated mean won't be calculated.\n");
2417 arrayValues = new Double_t[2];
2418 arrayWeights = new Double_t[2];
2419 arrayValues[0] = valueBeforeSOR;
2420 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2421 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2422 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2423 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2424 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2425 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2426 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2427 truncMeanFlag = kFALSE;
2430 printf("Cannot calculate mean, truncated mean, median, SD wrt mean, SD wrt median for current DP - only one value collected during the run, but no value before with which to calculate the statistical quantities\n");
2436 return parameters[0];
2439 else { // iCountsRun == 0, using only the point immediately before SOR
2440 if (timestampBeforeSOR == -1.){
2441 printf("Cannot set mean, truncated mean, median, SD wrt mean, SD wrt median for current DP - no points during the run collected, and point before SOR missing\n");
2447 return parameters[0];
2450 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2451 printf("value = %f\n",valueBeforeSOR);
2452 parameters[0] = valueBeforeSOR;
2453 parameters[2] = valueBeforeSOR;
2454 truncMeanFlag = kFALSE;
2461 Double_t sumweights = 0;
2462 Int_t entriesTruncMean = 0;
2463 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2464 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2466 // calculating SD wrt Mean and Median
2467 printf("Calculating SD wrt Mean and SD wrt Median\n");
2469 for (Int_t i =0; i< nentriesUsed; i++){
2470 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2471 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2472 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2473 sumweights += arrayWeights[i];
2475 // setting SD wrt Mean
2476 if (sumweights != 0 ){
2477 parameters[3] = TMath::Sqrt(temp1/sumweights);
2480 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2483 // setting SD wrt Median
2484 if (nentriesUsed != 0){
2485 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2488 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2497 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2499 printf("Calculating Truncated Mean\n");
2500 for (Int_t i =0; i< nentriesUsed; i++){
2501 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2502 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2503 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2504 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2505 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2509 printf("Discarding entry\n");
2512 // setting truncated mean
2513 if (entriesTruncMean >1){
2514 printf("%d entries used for truncated mean\n",entriesTruncMean);
2515 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2518 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2526 printf("(weighted) mean = %f \n",parameters[0]);
2527 printf("(weighted) truncated mean = %f \n",parameters[1]);
2528 printf("median = %f \n",parameters[2]);
2529 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2530 printf("standard deviation with median = %f \n",parameters[4]);
2532 return (parameters[0]);
2534 //------------------------------------------------------------------------------------------------------
2535 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* array, Double_t timeStart, Double_t timeEnd){
2538 // Method to processo LHC Energy information
2539 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2542 Int_t nCounts = array->GetEntries();
2543 Float_t energy = -1;
2544 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2545 for(Int_t i = 0; i < nCounts; i++) {
2546 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2547 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2548 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2549 AliInfo(Form("Energy value found = %d, converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),energy));
2553 AliError("No energy values found between DAQ_time_start and DAQ_time_end - energy will remain invalid!");