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"));
515 } else if (iLHCData ==4){
516 Log(Form("Problems with LHC Data to be put in /GRP/GRP/LHCData - but not going into Error"));
518 Log(Form("LHC Data problems"));
522 //==================//
523 // SPD Mean Vertex //
524 //==================//
525 if (runType == "PHYSICS"){
526 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
527 if( iSPDMeanVertex == 1 ) {
528 Log(Form("SPD Mean Vertex, successful!"));
530 Log(Form("SPD Mean Vertex failed!!!"));
535 Log("SPD Mean Vertex not processed since runType != PHYSICS");
538 // storing AliGRPObject in OCDB
541 md.SetResponsible("Chiara Zampolli");
542 md.SetComment("Output parameters from the GRP preprocessor.");
544 Bool_t result = kTRUE;
545 result = Store("GRP", "Data", grpobj, &md);
548 if (result && !error ) {
549 Log("GRP Preprocessor Success");
552 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s",
553 kppError[(error&1)?1:0],
554 kppError[(error&2)?2:0],
555 kppError[(error&4)?3:0],
556 kppError[(error&8)?4:0],
557 kppError[(error&16)?5:0],
558 kppError[(error&32)?6:0],
559 kppError[(error&64)?7:0],
560 kppError[(error&128)?8:0],
561 kppError[(error&256)?9:0],
562 kppError[(error&512)?10:0]
570 //_______________________________________________________________
572 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
575 //Getting the LHC Data from DCS FXS
578 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
579 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
580 if (timeStartString.IsNull() || timeStartString.IsNull()){
581 if (timeStartString.IsNull()){
582 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
584 else if (timeStartString.IsNull()){
585 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
590 Double_t timeStart = timeStartString.Atof();
591 Double_t timeEnd = timeEndString.Atof();
593 // timeStart = 1260646960;
594 //timeEnd = 1260652740;
596 TString fileName = GetFile(kDCS, "LHCData","");
597 if (fileName.Length()>0){
598 AliInfo("Got The LHC Data file");
599 AliLHCReader* lhcReader = new AliLHCReader();
600 TMap* lhcMap = (TMap*)lhcReader->ReadLHCDP(fileName.Data());
602 Log(Form("LHCData map entries = %d",lhcMap->GetEntries()));
604 // Processing data to be put in AliGRPObject
606 TObjArray* energyArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[0]);
607 Float_t energy = ProcessEnergy(energyArray,timeStart,timeEnd);
609 grpobj->SetBeamEnergy(energy);
610 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
614 TObjArray* beamModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[2]);
615 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(0);
616 TObjString* beamModeString = beamMode->GetStringArray(0);
617 Double_t timeBeamMode = 0;
618 if (beamModeArray->GetEntries()!=1){
619 timeBeamMode = beamMode->GetTimeStamp();
620 AliWarning(Form("The beam mode changed at timestamp %f! Setting it to the first value found and setting MaxTimeLHCValidity",timeBeamMode));
622 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
623 grpobj->SetLHCState(beamModeString->String());
626 TObjArray* machineModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[1]);
627 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(0);
628 TObjString* machineModeString = machineMode->GetStringArray(0);
629 Double_t timeMachineMode = 0;
630 if (machineModeArray->GetEntries()!=1){
631 timeMachineMode = machineMode->GetTimeStamp();
632 AliWarning(Form("The machine mode changed at timestamp %f! Setting it to the first value found and setting MaxTimeLHCValidity",timeMachineMode));
634 AliInfo(Form("Machine Mode = %s",(machineModeString->String()).Data()));
635 grpobj->SetMachineMode(machineModeString->String());
637 if (timeBeamMode!=0 || timeMachineMode!=0){
638 Double_t minTimeLHCValidity;
639 if (timeBeamMode == 0){
640 minTimeLHCValidity = timeMachineMode;
642 else if (timeMachineMode == 0){
643 minTimeLHCValidity = timeBeamMode;
646 minTimeLHCValidity= TMath::Min(timeBeamMode,timeMachineMode);
648 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
649 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
652 // BeamType1 and BeamType2
653 TObjArray* beam1Array = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[3]);
654 AliInfo(Form("%d entries for Beam1",beam1Array->GetEntries()));
655 TObjArray* beam2Array = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[4]);
656 AliInfo(Form("%d entries for Beam2",beam2Array->GetEntries()));
658 // Processing data to go to AliLHCData object
659 AliLHCData* dt = new AliLHCData(lhcMap,timeStart,timeEnd);
661 // storing AliLHCData in OCDB
664 md.SetResponsible("Ruben Shahoyan");
665 md.SetComment("LHC data from the GRP preprocessor.");
667 Bool_t result = kTRUE;
668 result = Store("GRP", "LHCData", dt, &md);
670 if (result) return 0;
676 AliError("Cannot read correctly LHCData file");
682 AliError("No LHCData file found in DCS FXS");
688 //_______________________________________________________________
690 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
693 //Getting the SPD Mean Vertex
696 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
697 Bool_t storeResult = kTRUE;
698 if (list !=0x0 && list->GetEntries()!=0)
700 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
702 for (Int_t jj=0;jj<list->GetEntries();jj++){
703 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
704 AliInfo(Form("found source %s", str->String().Data()));
705 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
706 if (fileNameRun.Length()>0){
707 AliInfo(Form("Got the file %s", fileNameRun.Data()));
708 TFile daqFile(fileNameRun.Data(),"READ");
709 if (daqFile.IsOpen()) {
710 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
713 // storing in the OCDB
715 md.SetResponsible("Cvetan Cheshkov");
716 md.SetComment("SPD Mean Vertex");
717 storeResult = Store("GRP", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
720 AliWarning("No SPD Mean Vertex object found in file");
724 AliError("Can't open file");
725 storeResult = kFALSE;
729 AliWarning("No file found for current source for SPD Mean Vertex");
734 AliWarning("No list found for SPD Mean Vertex");
737 if (list) delete list;
743 //_______________________________________________________________
745 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
747 //Getting the DAQ lb information
749 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
750 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
751 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
752 TString beamType = (TString)GetRunParameter("beamType");
753 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
754 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
755 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
756 TString runType = (TString)GetRunType();
758 UInt_t nparameter = 0;
760 grpObj->SetTimeStart(timeStart);
761 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
765 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
769 grpObj->SetTimeEnd(timeEnd);
770 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
774 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
777 if (beamEnergy != 0){
778 grpObj->SetBeamEnergy(beamEnergy);
779 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
780 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
781 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
782 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
786 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
787 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
788 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()));
791 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()));
796 if (beamType.Length() != 0){
797 grpObj->SetBeamType(beamType);
798 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
802 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
806 if (numberOfDetectors != 0){
807 grpObj->SetNumberOfDetectors(numberOfDetectors);
808 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
812 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
815 if (detectorMask != 0){
816 grpObj->SetDetectorMask(detectorMask);
817 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
821 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
824 if (lhcPeriod.Length() != 0) {
825 grpObj->SetLHCPeriod(lhcPeriod);
826 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
830 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
832 if (runType.Length() != 0) {
833 grpObj->SetRunType(runType);
834 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
838 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
844 //_______________________________________________________________
846 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
848 //======DAQ FXS======//
850 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
851 TList* list = GetFileSources(kDAQ);
853 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
857 if (list->GetEntries() == 0) {
858 Log("no raw data tags in this run: nothing to merge!");
863 TChain *fRawTagChain = new TChain("T");
865 TIterator* iter = list->MakeIterator();
867 while ((obj = iter->Next())) {
868 TObjString* objStr = dynamic_cast<TObjString*> (obj);
870 Log(Form("Found source %s", objStr->String().Data()));
871 TList* list2 = GetFileIDs(kDAQ, objStr->String());
873 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
874 delete fRawTagChain; fRawTagChain=0;
877 Log(Form("Number of ids: %d",list2->GetEntries()));
878 for(Int_t i = 0; i < list2->GetEntries(); i++) {
879 TObjString *idStr = (TObjString *)list2->At(i);
880 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
881 if (fileName.Length() > 0) {
882 Log(Form("Adding file in the chain: %s",fileName.Data()));
883 fRawTagChain->Add(fileName.Data());
886 Log(Form("Could not retrieve file with id %s from source %s: "
887 "connection problems with DAQ FXS!",
888 idStr->String().Data(), objStr->String().Data()));
890 delete list2; list2=0;
891 delete fRawTagChain; fRawTagChain=0;
899 TString fRawDataFileName = "GRP_Merged.tag.root";
900 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
902 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
903 Log("Error merging raw data files!!!");
907 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
908 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
911 Log("Problem storing raw data tags in local file!!!");
913 Log("Raw data tags merged successfully!!");
918 delete fRawTagChain; fRawTagChain=0;
920 if (result == kFALSE) {
928 //_______________________________________________________________
929 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
932 // processing the info
933 // stored in the DCS FXS
934 // coming from the trigger
936 // Get the CTP counters information
938 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
939 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
940 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
942 Log(Form("No dummy CTP scalers entry found, going into error..."));
946 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
948 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
952 AliCDBMetaData metaData;
953 metaData.SetResponsible("Roman Lietava");
954 metaData.SetComment("CTP scalers from dummy entry in OCDB");
955 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
956 Log("Unable to store the dummy CTP scalers object to OCDB!");
963 else if (!partition.IsNull() && detector.IsNull()){ // global partition
964 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
965 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
966 if (countersfile.IsNull()) {
967 Log("No CTP counters files has been found: empty source!");
971 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
972 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
974 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
978 AliCDBMetaData metaData;
979 metaData.SetBeamPeriod(0);
980 metaData.SetResponsible("Roman Lietava");
981 metaData.SetComment("CTP scalers");
982 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
983 Log("Unable to store the CTP scalers object to OCDB!");
992 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
999 //_______________________________________________________________
1001 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1005 // processing DCS DPs
1008 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1009 Int_t nL3Entries = 0;
1010 Int_t nDipoleEntries = 0;
1011 Int_t nEnvEntries = 0;
1012 Int_t nHallProbesEntries = 0;
1013 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1014 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1015 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1016 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1017 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1018 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1019 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1024 //_______________________________________________________________
1026 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1033 Int_t nL3Entries = 0;
1035 TObjArray *array = 0x0;
1037 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1039 AliInfo(Form("==========L3Current==========="));
1040 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1041 indexDP = kL3Current;
1042 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1044 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1047 if (array->GetEntries() == 0){
1048 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1051 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1052 if (floatDCS != NULL){
1053 grpObj->SetL3Current(floatDCS);
1065 ffailedDPs->RemoveAt(indexDP);
1069 if (array) array = 0x0;
1071 AliInfo(Form("==========L3Polarity==========="));
1072 indexDP = kL3Polarity;
1073 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1075 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1078 if (array->GetEntries() == 0){
1079 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1082 Bool_t change = kFALSE;
1083 Char_t charDCS = ProcessBool(array,change);
1084 if (change == kFALSE){
1085 grpObj->SetL3Polarity(charDCS);
1086 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1087 ffailedDPs->RemoveAt(indexDP);
1091 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1092 ffailedDPs->RemoveAt(indexDP);
1096 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]));
1104 //_______________________________________________________________
1106 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1112 Int_t nDipoleEntries = 0;
1113 TObjArray *array = 0x0;
1115 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1117 AliInfo(Form("==========DipoleCurrent==========="));
1118 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1119 indexDP = kDipoleCurrent;
1120 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1122 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1125 if (array->GetEntries() == 0){
1126 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1129 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1130 if (floatDCS != NULL){
1131 grpObj->SetDipoleCurrent(floatDCS);
1143 ffailedDPs->RemoveAt(indexDP);
1147 if (array) array = 0x0;
1149 AliInfo(Form("==========DipolePolarity==========="));
1150 indexDP = kDipolePolarity;
1151 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1153 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1156 if (array->GetEntries() == 0){
1157 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1160 Bool_t change = kFALSE;
1161 Char_t charDCS = ProcessBool(array,change);
1163 grpObj->SetDipolePolarity(charDCS);
1164 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1165 ffailedDPs->RemoveAt(indexDP);
1169 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1170 ffailedDPs->RemoveAt(indexDP);
1174 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]));
1179 return nDipoleEntries;
1182 //_______________________________________________________________
1184 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1188 // evironment conditions (temperature, pressure) info
1190 Int_t nEnvEntries = 0;
1191 TObjArray *array = 0x0;
1194 AliInfo(Form("==========CavernTemperature==========="));
1195 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1196 indexDP = kCavernTemperature;
1197 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1199 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1202 if (array->GetEntries() == 0){
1203 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1206 Float_t *floatDCS = ProcessFloatAll(array);
1207 if (floatDCS != NULL){
1208 grpObj->SetCavernTemperature(floatDCS);
1219 ffailedDPs->RemoveAt(indexDP);
1224 if (array) array = 0x0;
1226 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1227 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1228 //dcsSensorArray->Print();
1229 if( fPressure->NumFits()<kNumSensors ) {
1230 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1232 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1234 AliInfo(Form("==========CavernAtmosPressure==========="));
1235 indexDP = kCavernAtmosPressure;
1236 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1237 TGraph* graph = sensorCavernP2->GetGraph();
1238 AliDebug(3,Form("index = %d",indexDP));
1239 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1240 AliDebug(2,Form("graph = %p",graph));
1241 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1242 if(sensorCavernP2->GetFit() || graph) {
1243 if (sensorCavernP2->GetFit()){
1244 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1247 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1249 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1250 ffailedDPs->RemoveAt(indexDP);
1253 //if (sensorP2) delete sensorP2;
1255 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] ));
1258 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1259 indexDP = kSurfaceAtmosPressure;
1260 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1261 graph = sensorP2->GetGraph();
1262 AliDebug(3,Form("index = %d",indexDP));
1263 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1264 AliDebug(2,Form("graph = %p",graph));
1265 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1266 if(sensorP2->GetFit() || graph) {
1267 if (sensorP2->GetFit()){
1268 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1271 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1273 grpObj->SetSurfaceAtmosPressure(sensorP2);
1274 ffailedDPs->RemoveAt(indexDP);
1277 //if (sensorP2) delete sensorP2;
1279 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] ));
1282 AliInfo(Form("==========CavernAtmosPressure2==========="));
1283 indexDP = kCavernAtmosPressure2;
1284 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1285 graph = sensorCavernP22->GetGraph();
1286 AliDebug(3,Form("index = %d",indexDP));
1287 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1288 AliDebug(2,Form("graph = %p",graph));
1289 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1290 if(sensorCavernP22->GetFit() || graph) {
1291 if (sensorCavernP22->GetFit()){
1292 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1295 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1297 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1298 ffailedDPs->RemoveAt(indexDP);
1301 //if (sensorP2) delete sensorP2;
1303 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] ));
1309 //_______________________________________________________________
1311 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1317 Int_t nHPEntries = 0;
1318 TObjArray *array = 0x0;
1320 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1322 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1323 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()));
1325 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1326 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1327 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1328 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1330 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1333 if (array->GetEntries() == 0){
1334 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1337 Float_t *floatDCS = ProcessFloatAll(array);
1338 if (floatDCS != NULL){
1339 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]));
1340 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1341 for (Int_t kk = 0 ; kk< 5; kk++){
1342 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1354 ffailedDPs->RemoveAt(indexDP + 7); // 7 = shift in the complete list of DPs to get to the Hall Probes
1360 Log(Form("Hall Probes = %d ", nHPEntries));
1364 //_________________________________________________________________________
1366 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1370 // returning Spline Fit
1373 Int_t entriesarray = array->GetEntries();
1374 Float_t* value = new Float_t[entriesarray];
1375 Float_t* time = new Float_t[entriesarray];
1376 AliDCSValue* v = 0x0;
1377 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1378 v = (AliDCSValue*)array->At(iarray);
1379 value[iarray] = v->GetFloat();
1380 time[iarray] = v->GetTimeStamp();
1381 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1383 TGraph* gr = new TGraph(entriesarray,value,time);
1385 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1388 AliSplineFit *fit = new AliSplineFit();
1389 fit->SetMinPoints(10);
1390 fit->InitKnots(gr,10,10,0.0);
1394 AliWarning(Form("%s: no fit performed",stringID.Data()));
1400 //_________________________________________________________________________
1402 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1409 TString aDCSString="";
1411 AliDCSValue *v = 0x0;
1412 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1413 v = (AliDCSValue *)array->At(iCount);
1414 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1415 AliError(Form("DCS values for the parameter outside the queried interval"));
1419 if (aDCSString != v->GetChar())
1420 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1422 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1427 //__________________________________________________________________________________________________________________
1429 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1432 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1434 // parameters[0] = mean
1435 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1436 // parameters[2] = median
1437 // parameters[3] = standard deviation wrt mean
1438 // parameters[4] = standard deviation wrt median
1441 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1442 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1443 if (timeStartString.IsNull() || timeStartString.IsNull()){
1444 if (timeStartString.IsNull()){
1445 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1447 else if (timeStartString.IsNull()){
1448 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1450 fdaqStartEndTimeOk = kFALSE;
1454 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1455 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1456 Float_t* parameters = new Float_t[5];
1458 Int_t iCountsRun = 0;
1459 Int_t nCounts = array->GetEntries();
1460 Float_t valueBeforeSOR = 0;
1461 Float_t valueAfterEOR = 0;
1462 Int_t timestampBeforeSOR = -1;
1463 Int_t timestampAfterEOR = -1;
1464 Int_t ientrySOR = -1;
1465 Int_t ientryEOR = -1;
1466 Float_t* arrayValues = 0x0;
1467 Double_t* arrayWeights = 0x0;
1468 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1469 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1471 for(Int_t i = 0; i < nCounts; i++) {
1472 AliDCSValue *v = (AliDCSValue *)array->At(i);
1473 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1474 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1475 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1476 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1479 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1480 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1482 // look for the last value before SOR and the first value before EOR
1483 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1484 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1485 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1486 valueBeforeSOR = v->GetFloat();
1488 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1489 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1490 valueAfterEOR = v->GetFloat();
1491 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1493 // check if there are DPs between DAQ_time_start and DAQ_time_end
1494 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1495 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1496 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1497 AliDebug(2,Form("entry between SOR and EOR"));
1502 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1506 if (timestampBeforeSOR == -1){
1507 AliWarning("No value found before SOR");
1509 if (timestampAfterEOR == -1){
1510 AliWarning("No value found after EOR");
1513 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1514 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1515 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1516 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1517 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1518 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1520 Int_t nentriesUsed = 0;
1521 if (iCountsRun > 1){
1522 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1523 AliDebug(2,"Calculating (weighted) Mean and Median");
1524 arrayValues = new Float_t[iCountsRun];
1525 arrayWeights = new Double_t[iCountsRun];
1526 nentriesUsed = iCountsRun;
1527 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1528 AliDCSValue *v = (AliDCSValue *)array->At(i);
1529 Int_t timestamp2 = 0;
1531 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1532 timestamp2 = (Int_t)v1->GetTimeStamp();
1535 timestamp2 = timeEnd+1;
1537 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1538 arrayValues[i-ientrySOR] = v->GetFloat();
1540 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1541 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1543 else if (iCountsRun == 1){
1544 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1546 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1547 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.");
1548 arrayValues = new Float_t[2];
1549 arrayWeights = new Double_t[2];
1550 arrayValues[0] = valueBeforeSOR;
1551 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1552 arrayValues[1] = v->GetFloat();
1553 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1554 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1555 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1556 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1557 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1558 truncMeanFlag = kFALSE;
1561 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");
1562 parameters[0] = AliGRPObject::GetInvalidFloat();
1563 parameters[1] = AliGRPObject::GetInvalidFloat();
1564 parameters[2] = AliGRPObject::GetInvalidFloat();
1565 parameters[3] = AliGRPObject::GetInvalidFloat();
1566 parameters[4] = AliGRPObject::GetInvalidFloat();
1570 else { // iCountsRun == 0, using only the point immediately before SOR
1571 if (timestampBeforeSOR == -1){
1572 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");
1573 parameters[0] = AliGRPObject::GetInvalidFloat();
1574 parameters[1] = AliGRPObject::GetInvalidFloat();
1575 parameters[2] = AliGRPObject::GetInvalidFloat();
1576 parameters[3] = AliGRPObject::GetInvalidFloat();
1577 parameters[4] = AliGRPObject::GetInvalidFloat();
1581 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1582 AliDebug(2,Form("value = %f",valueBeforeSOR));
1583 parameters[0] = valueBeforeSOR;
1584 parameters[2] = valueBeforeSOR;
1585 truncMeanFlag = kFALSE;
1592 Float_t sumweights = 0;
1593 Int_t entriesTruncMean = 0;
1594 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1595 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1597 // calculating SD wrt Mean and Median
1598 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1600 for (Int_t i =0; i< nentriesUsed; i++){
1601 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1602 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1603 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1604 sumweights += arrayWeights[i];
1606 // setting SD wrt Mean
1607 if (sumweights != 0 ){
1608 parameters[3] = TMath::Sqrt(temp1/sumweights);
1611 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1612 parameters[3] = AliGRPObject::GetInvalidFloat();
1614 // setting SD wrt Median
1615 if (nentriesUsed != 0){
1616 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1619 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1620 parameters[4] = AliGRPObject::GetInvalidFloat();
1624 parameters[3] = AliGRPObject::GetInvalidFloat();
1625 parameters[4] = AliGRPObject::GetInvalidFloat();
1628 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1630 AliDebug(2,"Calculating Truncated Mean");
1631 for (Int_t i =0; i< nentriesUsed; i++){
1632 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1633 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1634 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1635 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1636 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1640 AliDebug(2,"Discarding entry");
1643 // setting truncated mean
1644 if (entriesTruncMean >1){
1645 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1646 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1649 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1650 parameters[1] = AliGRPObject::GetInvalidFloat();
1654 parameters[1] = AliGRPObject::GetInvalidFloat();
1657 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1658 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1659 AliInfo(Form("median = %f ",parameters[2]));
1660 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1661 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1666 //__________________________________________________________________________________________________________________
1668 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1671 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1672 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1673 // the flag is set according to the L3/Dipole current value
1674 // current threshold for L3 = 350 A (value provided by DCS)
1675 // current threshold for Dipole = 450 A (value provided by DCS)
1677 // parameters[0] = mean
1678 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1679 // parameters[2] = median
1680 // parameters[3] = standard deviation wrt mean
1681 // parameters[4] = standard deviation wrt median
1684 AliInfo(Form("indexDP = %d",indexDP));
1686 Int_t nCounts = array->GetEntries();
1687 for(Int_t i = 0; i < nCounts; i++) {
1688 AliDCSValue *v = (AliDCSValue *)array->At(i);
1689 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1690 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1691 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1692 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1695 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1696 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1697 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1698 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1701 AliError(Form("DCS values for the parameter outside the queried interval"));
1705 return ProcessFloatAll(array);
1709 //_______________________________________________________________
1711 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1714 // processing Boolean values
1717 Bool_t aDCSBool = kTRUE;
1719 AliDCSValue *v = 0x0;
1721 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1722 v = (AliDCSValue *)array->At(iCount);
1723 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1724 AliError(Form("DCS values for the parameter outside the queried interval"));
1728 if (aDCSBool != v->GetBool()) {
1729 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1733 aDCSBool = v->GetBool(); // always keeping last value
1734 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1737 Char_t caDCSBool = (Char_t) aDCSBool;
1742 //_______________________________________________________________
1744 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1747 // processing Int values, returning mean
1748 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1749 // are outside the queried time interval or their value is out of range
1752 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1753 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1754 if (timeStartString.IsNull() || timeStartString.IsNull()){
1755 if (timeStartString.IsNull()){
1756 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1758 else if (timeStartString.IsNull()){
1759 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1764 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1765 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1766 Float_t aDCSArrayMean = 0.0;
1768 Float_t valueBeforeSOR = 0;
1769 Float_t valueAfterEOR = 0;
1770 Int_t timestampBeforeSOR = -1;
1771 Int_t timestampAfterEOR = -1;
1772 Int_t ientrySOR = -1;
1773 Int_t ientryEOR = -1;
1774 Float_t* arrayValues = 0x0;
1775 Double_t* arrayWeights = 0x0;
1776 Int_t iCountsRun = 0;
1777 Int_t nCounts = array->GetEntries();
1779 for(Int_t i = 0; i < nCounts; i++) {
1780 AliDCSValue* v = (AliDCSValue *)array->At(i);
1781 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1782 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1783 return AliGRPObject::GetInvalidFloat();
1785 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1786 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1788 // look for the last value before SOR and the first value before EOR
1789 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1790 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1791 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1792 valueBeforeSOR = (Float_t) v->GetInt();
1794 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1795 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1796 valueAfterEOR = (Float_t) v->GetInt();
1797 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1799 // check if there are DPs between DAQ_time_start and DAQ_time_end
1800 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1801 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1802 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1803 AliDebug(2,Form("entry between SOR and EOR"));
1808 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1812 if (timestampBeforeSOR == -1){
1813 AliWarning("No value found before SOR!");
1815 if (timestampAfterEOR == -1){
1816 AliWarning("No value found after EOR!");
1819 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1820 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1821 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1822 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1823 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1824 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1826 Int_t nentriesUsed = 0;
1827 if (iCountsRun > 1){
1828 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1829 AliDebug(2,"Calculating (weighted) Mean");
1830 arrayValues = new Float_t[iCountsRun];
1831 arrayWeights = new Double_t[iCountsRun];
1832 nentriesUsed = iCountsRun;
1833 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1834 AliDCSValue *v = (AliDCSValue *)array->At(i);
1835 Int_t timestamp2 = 0;
1837 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1838 timestamp2 = (Int_t)v1->GetTimeStamp();
1841 timestamp2 = timeEnd+1;
1843 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1844 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1846 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1848 else if (iCountsRun == 1){
1849 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1851 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1852 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1853 arrayValues = new Float_t[2];
1854 arrayWeights = new Double_t[2];
1855 arrayValues[0] = valueBeforeSOR;
1856 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1857 arrayValues[1] = (Float_t)v->GetInt();
1858 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1859 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1860 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1861 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1864 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1865 return AliGRPObject::GetInvalidFloat();
1868 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1869 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1870 if (timestampBeforeSOR == -1){
1871 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1873 if (timestampAfterEOR == -1){
1874 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1876 return AliGRPObject::GetInvalidFloat();
1879 AliWarning("Using last entry before SOR and first entry after EOR.");
1881 arrayValues = new Float_t[2];
1882 arrayWeights = new Double_t[2];
1883 arrayValues[0] = valueBeforeSOR;
1884 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1885 arrayValues[1] = valueAfterEOR;
1886 arrayWeights[1] = 1.;
1887 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1888 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1889 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1893 AliInfo(Form("mean = %f ", aDCSArrayMean));
1894 return aDCSArrayMean;
1897 //_______________________________________________________________
1899 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1902 // processing Int values, returning mean
1903 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1904 // are outside the queried time interval or their value is out of range
1907 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1908 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1909 if (timeStartString.IsNull() || timeStartString.IsNull()){
1910 if (timeStartString.IsNull()){
1911 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1913 else if (timeStartString.IsNull()){
1914 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1919 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1920 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1921 Float_t aDCSArrayMean = 0.0;
1923 Float_t valueBeforeSOR = 0;
1924 Float_t valueAfterEOR = 0;
1925 Int_t timestampBeforeSOR = -1;
1926 Int_t timestampAfterEOR = -1;
1927 Int_t ientrySOR = -1;
1928 Int_t ientryEOR = -1;
1929 Float_t* arrayValues = 0x0;
1930 Double_t* arrayWeights = 0x0;
1931 Int_t iCountsRun = 0;
1932 Int_t nCounts = array->GetEntries();
1934 for(Int_t i = 0; i < nCounts; i++) {
1935 AliDCSValue* v = (AliDCSValue *)array->At(i);
1936 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
1937 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
1938 return AliGRPObject::GetInvalidFloat();
1940 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1941 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
1943 // look for the last value before SOR and the first value before EOR
1944 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1945 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1946 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1947 valueBeforeSOR = (Float_t)v->GetUInt();
1949 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1950 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1951 valueAfterEOR = (Float_t)v->GetUInt();
1952 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1954 // check if there are DPs between DAQ_time_start and DAQ_time_end
1955 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1956 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1957 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1958 AliDebug(2,Form("entry between SOR and EOR"));
1963 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1967 if (timestampBeforeSOR == -1){
1968 AliWarning("No value found before SOR!");
1970 if (timestampAfterEOR == -1){
1971 AliWarning("No value found after EOR!");
1974 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1975 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1976 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1977 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1978 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1979 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1981 Int_t nentriesUsed = 0;
1982 if (iCountsRun > 1){
1983 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1984 AliDebug(2,"Calculating (weighted) Mean");
1985 arrayValues = new Float_t[iCountsRun];
1986 arrayWeights = new Double_t[iCountsRun];
1987 nentriesUsed = iCountsRun;
1988 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1989 AliDCSValue *v = (AliDCSValue *)array->At(i);
1990 Int_t timestamp2 = 0;
1992 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1993 timestamp2 = (Int_t)v1->GetTimeStamp();
1996 timestamp2 = timeEnd+1;
1998 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1999 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2001 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2003 else if (iCountsRun == 1){
2004 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2006 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2007 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2008 arrayValues = new Float_t[2];
2009 arrayWeights = new Double_t[2];
2010 arrayValues[0] = valueBeforeSOR;
2011 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2012 arrayValues[1] = (Float_t)v->GetUInt();
2013 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2014 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2015 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2016 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2019 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2020 return AliGRPObject::GetInvalidFloat();
2023 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2024 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2025 if (timestampBeforeSOR == -1){
2026 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2028 if (timestampAfterEOR == -1){
2029 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2031 return AliGRPObject::GetInvalidFloat();
2034 AliWarning("Using last entry before SOR and first entry after EOR.");
2036 arrayValues = new Float_t[2];
2037 arrayWeights = new Double_t[2];
2038 arrayValues[0] = valueBeforeSOR;
2039 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2040 arrayValues[1] = valueAfterEOR;
2041 arrayWeights[1] = 1.;
2042 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2043 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2044 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2048 AliInfo(Form("mean = %f ",aDCSArrayMean));
2049 return aDCSArrayMean;
2054 //_______________________________________________________________
2056 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2058 // extract DCS pressure maps. Perform fits to save space
2060 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2062 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2063 fPressure->MakeSplineFit(map);
2064 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2065 if (fitFraction > kFitFraction ) {
2066 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2068 AliInfo("Too few pressure maps fitted!!!");
2071 AliInfo("no atmospheric pressure map extracted!!!");
2080 //_______________________________________________________________
2081 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)
2084 // Retrieves logbook and trigger information from the online logbook
2085 // This information is needed for prompt reconstruction
2089 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2093 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2094 // 0 on success and no run was found
2095 // negative on error
2097 // This function is NOT called during the preprocessor run in the Shuttle!
2105 AliCDBManager* cdb = AliCDBManager::Instance();
2106 cdb->SetDefaultStorage(cdbRoot);
2109 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2113 Printf("ERROR: Could not connect to DAQ LB");
2119 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2120 TSQLResult* result = server->Query(sqlQuery);
2123 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2127 if (result->GetRowCount() == 0)
2129 Printf("ERROR: Run %d not found", run);
2134 TSQLRow* row = result->Next();
2137 Printf("ERROR: Could not receive data from run %d", run);
2142 TString timeStartString(row->GetField(0));
2143 TString runType(row->GetField(1));
2144 TString detectorMaskString(row->GetField(2));
2145 TString l3CurrentString(row->GetField(3));
2146 TString dipoleCurrentString(row->GetField(4));
2147 time_t timeStart = (time_t)(timeStartString.Atoi());
2148 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2149 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2150 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2151 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2152 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2154 AliGRPObject * grpObj = new AliGRPObject();
2155 grpObj->SetTimeStart(timeStart);
2156 grpObj->SetRunType((TString)(row->GetField(1)));
2157 grpObj->SetDetectorMask(detectorMask);
2158 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2159 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2160 grpObj->SetL3Polarity(l3Polarity);
2161 grpObj->SetDipolePolarity(dipolePolarity);
2162 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2170 Printf("Storing GRP/GRP/Data object with the following content");
2173 AliCDBMetaData metadata;
2174 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2175 metadata.SetComment("GRP Output parameters received during online running");
2177 AliCDBId id("GRP/GRP/Data", run, run);
2178 Bool_t success = cdb->Put(grpObj, id, &metadata);
2184 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2188 // Receive trigger information
2189 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2190 result = server->Query(sqlQuery);
2193 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2197 if (result->GetRowCount() == 0)
2199 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2204 row = result->Next();
2207 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2212 TString triggerConfig(row->GetField(0));
2220 Printf("Found trigger configuration: %s", triggerConfig.Data());
2222 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2225 Printf("ERROR: Could not create CTP configuration object");
2229 metadata.SetComment("CTP run configuration received during online running");
2231 AliCDBId id2("GRP/CTP/Config", run, run);
2232 success = cdb->Put(runcfg, id2, &metadata);
2239 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2244 // Receive list of GDCs for this run
2245 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2246 result = server->Query(sqlQuery);
2249 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2253 if (result->GetRowCount() == 0)
2255 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2261 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2262 row = result->Next();
2265 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2269 gdc += row->GetField(0);
2279 Printf("Found GDC: %s", gdc.Data());
2281 // get last run with same run type that was already processed by the SHUTTLE
2283 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());
2284 result = server->Query(sqlQuery);
2287 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2291 if (result->GetRowCount() == 0)
2293 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2298 row = result->Next();
2301 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2306 TString lastRunStr(row->GetField(0));
2307 Int_t lastRun = lastRunStr.Atoi();
2309 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2323 //-----------------------------------------------------------------
2324 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* array){
2327 // Calculating mean over TObjArray from LHC Data
2330 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2331 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2332 if (timeStartString.IsNull() || timeStartString.IsNull()){
2333 if (timeStartString.IsNull()){
2334 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2336 else if (timeStartString.IsNull()){
2337 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2342 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2343 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2344 timeStart = 1260646960;
2345 timeEnd = 1260652740;
2346 Double_t* parameters = new Double_t[5];
2347 parameters[0] = -1.;
2348 parameters[1] = -1.;
2349 parameters[2] = -1.;
2350 parameters[3] = -1.;
2351 parameters[4] = -1.;
2353 Int_t iCountsRun = 0;
2354 Int_t nCounts = array->GetEntries();
2355 printf("ncounts = %d\n",nCounts);
2356 Double_t valueBeforeSOR = 0;
2357 Double_t valueAfterEOR = 0;
2358 Double_t timestampBeforeSOR = -1.;
2359 Double_t timestampAfterEOR = -1.;
2360 Int_t ientrySOR = -1;
2361 Int_t ientryEOR = -1;
2362 Double_t* arrayValues = 0x0;
2363 Double_t* arrayWeights = 0x0;
2364 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2365 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2367 for(Int_t i = 0; i < nCounts; i++) {
2368 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2369 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2370 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2372 // look for the last value before SOR and the first value before EOR
2373 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2374 timestampBeforeSOR = dcs->GetTimeStamp();
2375 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2376 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2378 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2379 timestampAfterEOR = dcs->GetTimeStamp();
2380 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2381 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2383 // check if there are DPs between DAQ_time_start and DAQ_time_end
2384 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2385 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2386 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2387 AliDebug(2,Form("entry between SOR and EOR\n"));
2392 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2396 if (timestampBeforeSOR == -1.){
2397 printf("No value found before SOR\n");
2399 if (timestampAfterEOR == -1.){
2400 printf("No value found after EOR\n");
2403 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2404 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2405 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2406 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2407 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2408 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2410 Int_t nentriesUsed = 0;
2411 if (iCountsRun > 1){
2412 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2413 printf("Calculating (weighted) Mean and Median\n" );
2414 arrayValues = new Double_t[iCountsRun];
2415 arrayWeights = new Double_t[iCountsRun];
2416 nentriesUsed = iCountsRun;
2417 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2418 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2419 Double_t timestamp2 = 0;
2421 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2422 timestamp2 = dcs1->GetTimeStamp();
2425 timestamp2 = (Double_t)timeEnd+1;
2427 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2428 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2429 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2431 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2432 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2434 else if (iCountsRun == 1){
2435 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2437 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2438 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");
2439 arrayValues = new Double_t[2];
2440 arrayWeights = new Double_t[2];
2441 arrayValues[0] = valueBeforeSOR;
2442 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2443 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2444 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2445 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2446 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2447 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2448 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2449 truncMeanFlag = kFALSE;
2452 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");
2458 return parameters[0];
2461 else { // iCountsRun == 0, using only the point immediately before SOR
2462 if (timestampBeforeSOR == -1.){
2463 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");
2469 return parameters[0];
2472 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2473 printf("value = %f\n",valueBeforeSOR);
2474 parameters[0] = valueBeforeSOR;
2475 parameters[2] = valueBeforeSOR;
2476 truncMeanFlag = kFALSE;
2483 Double_t sumweights = 0;
2484 Int_t entriesTruncMean = 0;
2485 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2486 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2488 // calculating SD wrt Mean and Median
2489 printf("Calculating SD wrt Mean and SD wrt Median\n");
2491 for (Int_t i =0; i< nentriesUsed; i++){
2492 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2493 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2494 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2495 sumweights += arrayWeights[i];
2497 // setting SD wrt Mean
2498 if (sumweights != 0 ){
2499 parameters[3] = TMath::Sqrt(temp1/sumweights);
2502 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2505 // setting SD wrt Median
2506 if (nentriesUsed != 0){
2507 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2510 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2519 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2521 printf("Calculating Truncated Mean\n");
2522 for (Int_t i =0; i< nentriesUsed; i++){
2523 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2524 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2525 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2526 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2527 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2531 printf("Discarding entry\n");
2534 // setting truncated mean
2535 if (entriesTruncMean >1){
2536 printf("%d entries used for truncated mean\n",entriesTruncMean);
2537 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2540 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2548 printf("(weighted) mean = %f \n",parameters[0]);
2549 printf("(weighted) truncated mean = %f \n",parameters[1]);
2550 printf("median = %f \n",parameters[2]);
2551 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2552 printf("standard deviation with median = %f \n",parameters[4]);
2554 return (parameters[0]);
2556 //------------------------------------------------------------------------------------------------------
2557 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* array, Double_t timeStart, Double_t timeEnd){
2560 // Method to processo LHC Energy information
2561 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2564 Int_t nCounts = array->GetEntries();
2565 Float_t energy = -1;
2566 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2567 for(Int_t i = 0; i < nCounts; i++) {
2568 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2569 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2570 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2571 AliInfo(Form("Energy value found = %d, converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),energy));
2575 AliError("No energy values found between DAQ_time_start and DAQ_time_end - energy will remain invalid!");