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 Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
80 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
81 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
89 "L3_BSF17_Temperature",
93 "L3_BSF4_Temperature",
97 "L3_BKF17_Temperature",
101 "L3_BKF4_Temperature",
105 "L3_BSF13_Temperature",
109 "L3_BSF8_Temperature",
113 "L3_BKF13_Temperature",
117 "L3_BKF8_Temperature",
121 "Dipole_Inside_Temperature",
125 "Dipole_Outside_Temperature",
127 "CavernAtmosPressure",
128 "SurfaceAtmosPressure",
129 "CavernAtmosPressure2"
132 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
136 "L3_BSF17_Temperature",
140 "L3_BSF4_Temperature",
144 "L3_BKF17_Temperature",
148 "L3_BKF4_Temperature",
152 "L3_BSF13_Temperature",
156 "L3_BSF8_Temperature",
160 "L3_BKF13_Temperature",
164 "L3_BKF8_Temperature",
168 "Dipole_Inside_Temperature",
172 "Dipole_Outside_Temperature"
175 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
176 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
179 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
183 "dip/acc/LHC/RunControl/BeamType/Beam1.payload",
184 "dip/acc/LHC/RunControl/BeamType/Beam2.payload"
186 const char* kppError[] = {
188 "(DAQ logbook ERROR)",
190 "(Trigger Scalers not found in DCS FXS - ERROR)",
191 "(DCS data points ERROR)",
192 "(Trigger Configuration ERROR)",
193 "(DAQ logbook ERROR determining partition of the run)",
194 "(CTP timing ERROR)",
195 "(SPD Mean Vertex ERROR)",
196 "(DCS FXS Error for LHC Data)",
200 //_______________________________________________________________
202 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
203 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))
205 // constructor - shuttle must be instantiated!
207 AddRunType("COSMIC");
209 AddRunType("PHYSICS");
210 AddRunType("CALIBRATION_BC");
211 AddRunType("CALIBRATION_CENTRAL");
212 AddRunType("CALIBRATION_EMD");
213 AddRunType("CALIBRATION_MB");
214 AddRunType("CALIBRATION_SEMICENTRAL");
215 AddRunType("CALIBRATION");
216 AddRunType("PEDESTAL");
217 AddRunType("STANDALONE");
220 AddRunType("PULSER");
221 AddRunType("STANDALONE_PULSER");
222 AddRunType("STANDALONE_BC");
225 fminFloat = -FLT_MAX;
226 fmaxDouble = DBL_MAX;
227 fminDouble = -DBL_MAX;
233 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
234 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
235 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
236 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
237 AliInfo(Form("Max allowed integer = %d",fmaxInt));
238 AliInfo(Form("Min allowed integer = %d",fminInt));
239 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
240 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
242 ffailedDPs->SetOwner(kTRUE);
245 //_______________________________________________________________
247 AliGRPPreprocessor::~AliGRPPreprocessor()
256 //_______________________________________________________________
258 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
260 // Initialize preprocessor
262 AliPreprocessor::Initialize(run, startTime, endTime);
264 AliInfo("Initialization of the GRP preprocessor.");
265 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
266 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
267 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
268 for(Int_t j = 0; j < kNumSensors; j++) {
269 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
270 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
272 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
274 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
276 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
277 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
278 ffailedDPs->AddAt(dp,iDP);
283 //_______________________________________________________________
285 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
287 // process data retrieved by the Shuttle
289 // retrieving "partition" and "detector" fields from DAQ logbook to
290 // determine the partition in which the run was taken
291 // the partition is used to decide how to react in case of errors for CTP
293 TString partition = (TString)GetRunParameter("partition");
294 TString detector = (TString)GetRunParameter("detector");
296 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
297 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
299 //=================//
301 //=================//
304 Int_t iDaqLB = ProcessDaqLB(grpobj);
305 TString runType = (TString)GetRunType();
306 TString beamType = (TString)GetRunParameter("beamType");
307 //if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
308 if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && !beamType.IsNull()) || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType.IsNull()) || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
309 Log(Form("DAQ Logbook, successful!"));
311 Log(Form("DAQ Logbook, could not get all expected entries!!!"));
315 //=================//
317 //=================//
318 UInt_t iDaqFxs = ProcessDaqFxs();
320 Log(Form("DAQ FXS, successful!"));
322 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
326 //=================//
328 //=================//
329 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
331 Log(Form("DCS FXS, successful!"));
332 } else if (iDcsFxs ==1) {
333 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
336 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
340 //=================//
341 // DCS data points //
342 //=================//
343 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
344 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
345 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
346 if (fdaqStartEndTimeOk){
347 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
348 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
349 Log(Form("The DPs giving problems were:"));
350 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
351 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
353 TString name = dpString->String();
354 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
355 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
358 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()));
364 else Log(Form("DCS data points, successful!"));
366 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"));
368 //=======================//
369 // Trigger Configuration //
370 //=======================//
372 const char * triggerConf = GetTriggerConfiguration();
374 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
375 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
376 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
378 Log(Form("No dummy CTP configuration entry found, going into error..."));
382 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
384 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
388 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
389 runcfg->SetTitle(titleCTPcfg);
390 AliCDBMetaData metaData;
391 metaData.SetResponsible("Roman Lietava");
392 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
393 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
394 Log("Unable to store the dummy CTP run configuration object to OCDB!");
401 else if (!partition.IsNull() && detector.IsNull()){ // global partition
402 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
403 if (triggerConf!= NULL) {
404 Log("Found trigger configuration in DAQ logbook");
405 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
407 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
411 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
412 runcfg->SetTitle(titleCTPcfg);
413 AliCDBMetaData metaData;
414 metaData.SetBeamPeriod(0);
415 metaData.SetResponsible("Roman Lietava");
416 metaData.SetComment("CTP run configuration from DAQ logbook");
417 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
418 Log("Unable to store the CTP run configuration object to OCDB!");
425 Log("Trigger configuration NULL in DAQ logbook");
431 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
435 //===========================//
436 // Trigger Timing Parameters //
437 //===========================//
440 const char * triggerCTPtiming = GetCTPTimeParams();
442 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
443 Log("STANDALONE partition for current run, using CTP timing params dummy value");
444 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
446 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
450 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
452 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
456 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
457 runCTPtiming->SetTitle(titleCTPtiming);
458 AliCDBMetaData metadata;
459 metadata.SetResponsible("Roman Lietava");
460 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
461 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
462 Log("Unable to store the dummy CTP timing params object to OCDB!");
469 else if (!partition.IsNull() && detector.IsNull()){ // global partition
470 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
471 if (triggerCTPtiming!= NULL) {
472 Log("Found trigger timing params in DAQ logbook");
473 AliDebug(2,Form("%s",triggerCTPtiming));
474 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
476 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
480 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
481 runCTPtiming->SetTitle(titleCTPtiming);
482 AliCDBMetaData metadata;
483 metadata.SetBeamPeriod(0);
484 metadata.SetResponsible("Roman Lietava");
485 metadata.SetComment("CTP timing params from DAQ logbook");
486 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
487 Log("Unable to store the CTP timing params object to OCDB!");
494 Log("Trigger timing params NULL in DAQ logbook");
500 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
505 //=================//
507 //=================//
509 UInt_t iLHCData = ProcessLHCData(grpobj);
511 if( iLHCData == 0 ) {
512 Log(Form("LHC Data from DCS FXS, successful!"));
513 } else if (iLHCData == 1) {
514 Log(Form("LHC Data, problems with DCS FXS!"));
516 } else if (iLHCData ==3){
517 Log(Form("Problems in storing LHC Data - but not going into Error"));
518 } else if (iLHCData ==4){
519 Log(Form("Problems with LHC Data to be put in /GRP/GRP/LHCData - but not going into Error"));
521 Log(Form("LHC Data problems"));
525 //==================//
526 // SPD Mean Vertex //
527 //==================//
528 if (runType == "PHYSICS"){
529 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
530 if( iSPDMeanVertex == 1 ) {
531 Log(Form("SPD Mean Vertex, successful!"));
533 Log(Form("SPD Mean Vertex failed!!!"));
538 Log("SPD Mean Vertex not processed since runType != PHYSICS");
541 // storing AliGRPObject in OCDB
544 md.SetResponsible("Chiara Zampolli");
545 md.SetComment("Output parameters from the GRP preprocessor.");
547 Bool_t result = kTRUE;
548 result = Store("GRP", "Data", grpobj, &md);
551 if (result && !error ) {
552 Log("GRP Preprocessor Success");
555 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s",
556 kppError[(error&1)?1:0],
557 kppError[(error&2)?2:0],
558 kppError[(error&4)?3:0],
559 kppError[(error&8)?4:0],
560 kppError[(error&16)?5:0],
561 kppError[(error&32)?6:0],
562 kppError[(error&64)?7:0],
563 kppError[(error&128)?8:0],
564 kppError[(error&256)?9:0],
565 kppError[(error&512)?10:0]
573 //_______________________________________________________________
575 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
578 //Getting the LHC Data from DCS FXS
581 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
582 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
583 if (timeStartString.IsNull() || timeEndString.IsNull()){
584 if (timeStartString.IsNull()){
585 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
587 else if (timeEndString.IsNull()){
588 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
593 Double_t timeStart = timeStartString.Atof();
594 Double_t timeEnd = timeEndString.Atof();
596 TString fileName = GetFile(kDCS, "LHCData","");
597 if (fileName.Length()>0){
598 AliInfo("Got The LHC Data file");
599 AliLHCReader lhcReader;
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]);
608 Float_t energy = ProcessEnergy(energyArray,timeStart,timeEnd);
610 grpobj->SetBeamEnergy(energy);
611 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
615 AliError("Energy not found in LHC Data file!!!");
617 Double_t timeBeamMode = 0;
618 Double_t timeMachineMode = 0;
619 Bool_t flagBeamMode = kFALSE; //flag set true if at least one BeamMode measurement is found within DAQ_time_start and DAQ_time_end
620 Bool_t flagMachineMode = kFALSE; //flag set true if at least one MachineMode measurement is found within DAQ_time_start and DAQ_time_end
622 TObjArray* beamModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[2]);
623 Int_t nBeamMode = -1;
625 nBeamMode = beamModeArray->GetEntries();
627 AliInfo("Found zero entries for the Beam Mode, setting it to UNKNOWN");
628 grpobj->SetLHCState("UNKNOWN");
632 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(0);
633 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
634 TObjString* beamModeString = beamMode->GetStringArray(0);
635 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
636 grpobj->SetLHCState(beamModeString->String());
639 AliInfo("No Beam Mode found within DAQ_time_start and DAQ_time_end, setting it to UNKNOWN");
640 grpobj->SetLHCState("UNKNOWN");
644 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
645 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
646 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
647 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(iBeamMode+1);
648 if (beamMode1->GetTimeStamp()>=timeStart && beamMode1->GetTimeStamp()<=timeEnd){
649 timeBeamMode = beamMode1->GetTimeStamp();
650 AliWarning(Form("The beam mode changed at timestamp %f! Setting it to the first value found and keeping track of the time of the change to set MaxTimeLHCValidity afterward",timeBeamMode));
652 TObjString* beamModeString = beamMode->GetStringArray(0);
653 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
654 grpobj->SetLHCState(beamModeString->String());
655 flagBeamMode = kTRUE;
660 AliError("Found values for BeamMode, but none within DAQ_time_start and DAQ_time_end, setting BeamMode to UNKNOWN");
661 grpobj->SetLHCState("UNKONWN");
667 AliError("Beam mode array not found in LHC Data file!!!");
671 TObjArray* machineModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[1]);
672 Int_t nMachineMode = -1;
673 if (machineModeArray){
674 nMachineMode = machineModeArray->GetEntries();
675 if (nMachineMode==0){
676 AliInfo("No Machine Mode found, setting it to UNKNOWN");
677 grpobj->SetMachineMode("UNKNOWN");
680 if (nMachineMode ==1) {
681 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(0);
682 if (machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
683 TObjString* machineModeString = machineMode->GetStringArray(0);
684 AliInfo(Form("Machine Mode = %s",(machineModeString->String()).Data()));
685 grpobj->SetMachineMode(machineModeString->String());
688 AliInfo("No Machine Mode found within DAQ_time_start and DAQ_time_end, setting it to UNKNOWN");
689 grpobj->SetMachineMode("UNKNOWN");
693 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
694 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
695 if (machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
696 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(iMachineMode+1);
697 if (machineMode1->GetTimeStamp()>=timeStart && machineMode1->GetTimeStamp()<=timeEnd){
698 timeMachineMode = machineMode1->GetTimeStamp();
699 AliWarning(Form("The machine mode changed at timestamp %f! Setting it to the first value found and keeping track of the time of the change to set MaxTimeLHCValidity afterwards",timeMachineMode));
701 TObjString* machineModeString = machineMode->GetStringArray(0);
702 AliInfo(Form("Machine mode = %s",(machineModeString->String()).Data()));
703 grpobj->SetMachineMode(machineModeString->String());
704 flagMachineMode = kTRUE;
708 if (!flagMachineMode){
709 AliError("Found values for MachineMode, but none within DAQ_time_start and DAQ_time_end, setting MachineMode to UNKNOWN");
710 grpobj->SetMachineMode("UNKONWN");
716 AliError("Machine mode array not found in LHC Data file!!!");
719 // Setting minTimeLHCValidity
720 if (timeBeamMode!=0 || timeMachineMode!=0){
721 Double_t minTimeLHCValidity;
722 if (timeBeamMode == 0){
723 minTimeLHCValidity = timeMachineMode;
725 else if (timeMachineMode == 0){
726 minTimeLHCValidity = timeBeamMode;
729 minTimeLHCValidity= TMath::Min(timeBeamMode,timeMachineMode);
731 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
732 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
735 // BeamType1 and BeamType2
736 TObjArray* beam1Array = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[3]);
738 AliInfo(Form("%d entries for Beam1",beam1Array->GetEntries()));
741 AliError("Beam1 array not found in LHC data file!!!");
743 TObjArray* beam2Array =
744 (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[4]);
746 AliInfo(Form("%d entries for Beam2",beam2Array->GetEntries()));
749 AliError("Beam2 array not found in LHC data file!!!");
751 // Processing data to go to AliLHCData object
752 AliLHCData* dt = new AliLHCData(lhcMap,timeStart,timeEnd);
754 // storing AliLHCData in OCDB
757 md.SetResponsible("Ruben Shahoyan");
758 md.SetComment("LHC data from the GRP preprocessor.");
760 Bool_t result = kTRUE;
761 result = Store("GRP", "LHCData", dt, &md);
763 if (result) return 0;
770 AliError("Cannot read correctly LHCData file");
776 AliError("No LHCData file found in DCS FXS");
782 //_______________________________________________________________
784 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
787 //Getting the SPD Mean Vertex
790 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
791 Bool_t storeResult = kTRUE;
792 if (list !=0x0 && list->GetEntries()!=0)
794 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
796 for (Int_t jj=0;jj<list->GetEntries();jj++){
797 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
798 AliInfo(Form("found source %s", str->String().Data()));
799 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
800 if (fileNameRun.Length()>0){
801 AliInfo(Form("Got the file %s", fileNameRun.Data()));
802 TFile daqFile(fileNameRun.Data(),"READ");
803 if (daqFile.IsOpen()) {
804 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
807 // storing in the OCDB
809 md.SetResponsible("Cvetan Cheshkov");
810 md.SetComment("SPD Mean Vertex");
811 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
814 AliWarning("No SPD Mean Vertex object found in file");
818 AliError("Can't open file");
819 storeResult = kFALSE;
823 AliWarning("No file found for current source for SPD Mean Vertex");
828 AliWarning("No list found for SPD Mean Vertex");
831 if (list) delete list;
837 //_______________________________________________________________
839 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
841 //Getting the DAQ lb information
843 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
844 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
845 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
846 TString beamType = (TString)GetRunParameter("beamType");
847 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
848 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
849 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
850 TString runType = (TString)GetRunType();
852 UInt_t nparameter = 0;
854 grpObj->SetTimeStart(timeStart);
855 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
859 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
863 grpObj->SetTimeEnd(timeEnd);
864 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
868 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
871 if (beamEnergy != 0){
872 grpObj->SetBeamEnergy(beamEnergy);
873 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
874 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
875 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
876 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
880 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
881 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
882 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()));
885 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()));
890 if (beamType.Length() != 0){
891 grpObj->SetBeamType(beamType);
892 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
896 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
900 if (numberOfDetectors != 0){
901 grpObj->SetNumberOfDetectors(numberOfDetectors);
902 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
906 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
909 if (detectorMask != 0){
910 grpObj->SetDetectorMask(detectorMask);
911 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
915 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
918 if (lhcPeriod.Length() != 0) {
919 grpObj->SetLHCPeriod(lhcPeriod);
920 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
924 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
926 if (runType.Length() != 0) {
927 grpObj->SetRunType(runType);
928 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
932 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
938 //_______________________________________________________________
940 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
942 //======DAQ FXS======//
944 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
945 TList* list = GetFileSources(kDAQ);
947 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
951 if (list->GetEntries() == 0) {
952 Log("no raw data tags in this run: nothing to merge!");
957 TChain *fRawTagChain = new TChain("T");
959 TIterator* iter = list->MakeIterator();
961 while ((obj = iter->Next())) {
962 TObjString* objStr = dynamic_cast<TObjString*> (obj);
964 Log(Form("Found source %s", objStr->String().Data()));
965 TList* list2 = GetFileIDs(kDAQ, objStr->String());
967 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
968 delete fRawTagChain; fRawTagChain=0;
971 Log(Form("Number of ids: %d",list2->GetEntries()));
972 for(Int_t i = 0; i < list2->GetEntries(); i++) {
973 TObjString *idStr = (TObjString *)list2->At(i);
974 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
975 if (fileName.Length() > 0) {
976 Log(Form("Adding file in the chain: %s",fileName.Data()));
977 fRawTagChain->Add(fileName.Data());
980 Log(Form("Could not retrieve file with id %s from source %s: "
981 "connection problems with DAQ FXS!",
982 idStr->String().Data(), objStr->String().Data()));
984 delete list2; list2=0;
985 delete fRawTagChain; fRawTagChain=0;
993 TString fRawDataFileName = "GRP_Merged.tag.root";
994 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
996 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
997 Log("Error merging raw data files!!!");
1001 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1002 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1005 Log("Problem storing raw data tags in local file!!!");
1007 Log("Raw data tags merged successfully!!");
1012 delete fRawTagChain; fRawTagChain=0;
1014 if (result == kFALSE) {
1022 //_______________________________________________________________
1023 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1026 // processing the info
1027 // stored in the DCS FXS
1028 // coming from the trigger
1030 // Get the CTP counters information
1032 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1033 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1034 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1036 Log(Form("No dummy CTP scalers entry found, going into error..."));
1040 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1042 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1046 AliCDBMetaData metaData;
1047 metaData.SetResponsible("Roman Lietava");
1048 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1049 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1050 Log("Unable to store the dummy CTP scalers object to OCDB!");
1057 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1058 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1059 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1060 if (countersfile.IsNull()) {
1061 Log("No CTP counters files has been found: empty source!");
1065 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1066 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1068 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1072 AliCDBMetaData metaData;
1073 metaData.SetBeamPeriod(0);
1074 metaData.SetResponsible("Roman Lietava");
1075 metaData.SetComment("CTP scalers");
1076 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1077 Log("Unable to store the CTP scalers object to OCDB!");
1088 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1095 //_______________________________________________________________
1097 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1101 // processing DCS DPs
1104 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1105 Int_t nL3Entries = 0;
1106 Int_t nDipoleEntries = 0;
1107 Int_t nEnvEntries = 0;
1108 Int_t nHallProbesEntries = 0;
1109 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1110 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1111 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1112 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1113 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1114 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1115 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1120 //_______________________________________________________________
1122 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1129 Int_t nL3Entries = 0;
1131 TObjArray *array = 0x0;
1133 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1135 AliInfo(Form("==========L3Current==========="));
1136 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1137 indexDP = kL3Current;
1138 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1140 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1143 if (array->GetEntries() == 0){
1144 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1147 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1148 if (floatDCS != NULL){
1149 grpObj->SetL3Current(floatDCS);
1161 ffailedDPs->RemoveAt(indexDP);
1165 if (array) array = 0x0;
1167 AliInfo(Form("==========L3Polarity==========="));
1168 indexDP = kL3Polarity;
1169 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1171 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1174 if (array->GetEntries() == 0){
1175 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1178 Bool_t change = kFALSE;
1179 Char_t charDCS = ProcessBool(array,change);
1180 if (change == kFALSE){
1181 grpObj->SetL3Polarity(charDCS);
1182 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1183 ffailedDPs->RemoveAt(indexDP);
1187 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1188 ffailedDPs->RemoveAt(indexDP);
1192 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]));
1200 //_______________________________________________________________
1202 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1208 Int_t nDipoleEntries = 0;
1209 TObjArray *array = 0x0;
1211 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1213 AliInfo(Form("==========DipoleCurrent==========="));
1214 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1215 indexDP = kDipoleCurrent;
1216 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1218 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1221 if (array->GetEntries() == 0){
1222 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1225 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1226 if (floatDCS != NULL){
1227 grpObj->SetDipoleCurrent(floatDCS);
1239 ffailedDPs->RemoveAt(indexDP);
1243 if (array) array = 0x0;
1245 AliInfo(Form("==========DipolePolarity==========="));
1246 indexDP = kDipolePolarity;
1247 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1249 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1252 if (array->GetEntries() == 0){
1253 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1256 Bool_t change = kFALSE;
1257 Char_t charDCS = ProcessBool(array,change);
1259 grpObj->SetDipolePolarity(charDCS);
1260 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1261 ffailedDPs->RemoveAt(indexDP);
1265 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1266 ffailedDPs->RemoveAt(indexDP);
1270 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]));
1275 return nDipoleEntries;
1278 //_______________________________________________________________
1280 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1284 // evironment conditions (temperature, pressure) info
1286 Int_t nEnvEntries = 0;
1287 TObjArray *array = 0x0;
1290 AliInfo(Form("==========CavernTemperature==========="));
1291 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1292 indexDP = kCavernTemperature;
1293 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1295 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1298 if (array->GetEntries() == 0){
1299 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1302 Float_t *floatDCS = ProcessFloatAll(array);
1303 if (floatDCS != NULL){
1304 grpObj->SetCavernTemperature(floatDCS);
1315 ffailedDPs->RemoveAt(indexDP);
1320 if (array) array = 0x0;
1322 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1323 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1324 //dcsSensorArray->Print();
1325 if( fPressure->NumFits()<kNumSensors ) {
1326 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1328 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1330 AliInfo(Form("==========CavernAtmosPressure==========="));
1331 indexDP = kCavernAtmosPressure;
1332 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1333 TGraph* graph = sensorCavernP2->GetGraph();
1334 AliDebug(3,Form("index = %d",indexDP));
1335 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1336 AliDebug(2,Form("graph = %p",graph));
1337 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1338 if(sensorCavernP2->GetFit() || graph) {
1339 if (sensorCavernP2->GetFit()){
1340 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1343 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1345 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1346 ffailedDPs->RemoveAt(indexDP);
1349 //if (sensorP2) delete sensorP2;
1351 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] ));
1354 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1355 indexDP = kSurfaceAtmosPressure;
1356 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1357 graph = sensorP2->GetGraph();
1358 AliDebug(3,Form("index = %d",indexDP));
1359 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1360 AliDebug(2,Form("graph = %p",graph));
1361 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1362 if(sensorP2->GetFit() || graph) {
1363 if (sensorP2->GetFit()){
1364 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1367 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1369 grpObj->SetSurfaceAtmosPressure(sensorP2);
1370 ffailedDPs->RemoveAt(indexDP);
1373 //if (sensorP2) delete sensorP2;
1375 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] ));
1378 AliInfo(Form("==========CavernAtmosPressure2==========="));
1379 indexDP = kCavernAtmosPressure2;
1380 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1381 graph = sensorCavernP22->GetGraph();
1382 AliDebug(3,Form("index = %d",indexDP));
1383 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1384 AliDebug(2,Form("graph = %p",graph));
1385 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1386 if(sensorCavernP22->GetFit() || graph) {
1387 if (sensorCavernP22->GetFit()){
1388 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1391 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1393 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1394 ffailedDPs->RemoveAt(indexDP);
1397 //if (sensorP2) delete sensorP2;
1399 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] ));
1405 //_______________________________________________________________
1407 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1413 Int_t nHPEntries = 0;
1414 TObjArray *array = 0x0;
1416 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1418 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1419 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()));
1421 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1422 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1423 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1424 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1426 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1429 if (array->GetEntries() == 0){
1430 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1433 Float_t *floatDCS = ProcessFloatAll(array);
1434 if (floatDCS != NULL){
1435 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]));
1436 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1437 for (Int_t kk = 0 ; kk< 5; kk++){
1438 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1450 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1456 Log(Form("Hall Probes = %d ", nHPEntries));
1460 //_________________________________________________________________________
1462 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1466 // returning Spline Fit
1469 Int_t entriesarray = array->GetEntries();
1470 Float_t* value = new Float_t[entriesarray];
1471 Float_t* time = new Float_t[entriesarray];
1472 AliDCSValue* v = 0x0;
1473 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1474 v = (AliDCSValue*)array->At(iarray);
1475 value[iarray] = v->GetFloat();
1476 time[iarray] = v->GetTimeStamp();
1477 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1479 TGraph* gr = new TGraph(entriesarray,value,time);
1481 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1484 AliSplineFit *fit = new AliSplineFit();
1485 fit->SetMinPoints(10);
1486 fit->InitKnots(gr,10,10,0.0);
1490 AliWarning(Form("%s: no fit performed",stringID.Data()));
1496 //_________________________________________________________________________
1498 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1505 TString aDCSString="";
1507 AliDCSValue *v = 0x0;
1508 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1509 v = (AliDCSValue *)array->At(iCount);
1510 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1511 AliError(Form("DCS values for the parameter outside the queried interval"));
1515 if (aDCSString != v->GetChar())
1516 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1518 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1523 //__________________________________________________________________________________________________________________
1525 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1528 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1530 // parameters[0] = mean
1531 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1532 // parameters[2] = median
1533 // parameters[3] = standard deviation wrt mean
1534 // parameters[4] = standard deviation wrt median
1537 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1538 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1539 if (timeStartString.IsNull() || timeStartString.IsNull()){
1540 if (timeStartString.IsNull()){
1541 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1543 else if (timeStartString.IsNull()){
1544 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1546 fdaqStartEndTimeOk = kFALSE;
1550 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1551 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1552 Float_t* parameters = new Float_t[5];
1554 Int_t iCountsRun = 0;
1555 Int_t nCounts = array->GetEntries();
1556 Float_t valueBeforeSOR = 0;
1557 Float_t valueAfterEOR = 0;
1558 Int_t timestampBeforeSOR = -1;
1559 Int_t timestampAfterEOR = -1;
1560 Int_t ientrySOR = -1;
1561 Int_t ientryEOR = -1;
1562 Float_t* arrayValues = 0x0;
1563 Double_t* arrayWeights = 0x0;
1564 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1565 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1567 for(Int_t i = 0; i < nCounts; i++) {
1568 AliDCSValue *v = (AliDCSValue *)array->At(i);
1569 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1570 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1571 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1572 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1575 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1576 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1578 // look for the last value before SOR and the first value before EOR
1579 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1580 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1581 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1582 valueBeforeSOR = v->GetFloat();
1584 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1585 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1586 valueAfterEOR = v->GetFloat();
1587 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1589 // check if there are DPs between DAQ_time_start and DAQ_time_end
1590 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1591 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1592 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1593 AliDebug(2,Form("entry between SOR and EOR"));
1598 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1602 if (timestampBeforeSOR == -1){
1603 AliWarning("No value found before SOR");
1605 if (timestampAfterEOR == -1){
1606 AliWarning("No value found after EOR");
1609 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1610 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1611 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1612 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1613 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1614 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1616 Int_t nentriesUsed = 0;
1617 if (iCountsRun > 1){
1618 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1619 AliDebug(2,"Calculating (weighted) Mean and Median");
1620 arrayValues = new Float_t[iCountsRun];
1621 arrayWeights = new Double_t[iCountsRun];
1622 nentriesUsed = iCountsRun;
1623 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1624 AliDCSValue *v = (AliDCSValue *)array->At(i);
1625 Int_t timestamp2 = 0;
1627 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1628 timestamp2 = (Int_t)v1->GetTimeStamp();
1631 timestamp2 = timeEnd+1;
1633 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1634 arrayValues[i-ientrySOR] = v->GetFloat();
1636 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1637 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1639 else if (iCountsRun == 1){
1640 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1642 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1643 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.");
1644 arrayValues = new Float_t[2];
1645 arrayWeights = new Double_t[2];
1646 arrayValues[0] = valueBeforeSOR;
1647 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1648 arrayValues[1] = v->GetFloat();
1649 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1650 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1651 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1652 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1653 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1654 truncMeanFlag = kFALSE;
1657 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");
1658 parameters[0] = AliGRPObject::GetInvalidFloat();
1659 parameters[1] = AliGRPObject::GetInvalidFloat();
1660 parameters[2] = AliGRPObject::GetInvalidFloat();
1661 parameters[3] = AliGRPObject::GetInvalidFloat();
1662 parameters[4] = AliGRPObject::GetInvalidFloat();
1666 else { // iCountsRun == 0, using only the point immediately before SOR
1667 if (timestampBeforeSOR == -1){
1668 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");
1669 parameters[0] = AliGRPObject::GetInvalidFloat();
1670 parameters[1] = AliGRPObject::GetInvalidFloat();
1671 parameters[2] = AliGRPObject::GetInvalidFloat();
1672 parameters[3] = AliGRPObject::GetInvalidFloat();
1673 parameters[4] = AliGRPObject::GetInvalidFloat();
1677 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1678 AliDebug(2,Form("value = %f",valueBeforeSOR));
1679 parameters[0] = valueBeforeSOR;
1680 parameters[2] = valueBeforeSOR;
1681 truncMeanFlag = kFALSE;
1688 Float_t sumweights = 0;
1689 Int_t entriesTruncMean = 0;
1690 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1691 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1693 // calculating SD wrt Mean and Median
1694 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1696 for (Int_t i =0; i< nentriesUsed; i++){
1697 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1698 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1699 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1700 sumweights += arrayWeights[i];
1702 // setting SD wrt Mean
1703 if (sumweights != 0 ){
1704 parameters[3] = TMath::Sqrt(temp1/sumweights);
1707 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1708 parameters[3] = AliGRPObject::GetInvalidFloat();
1710 // setting SD wrt Median
1711 if (nentriesUsed != 0){
1712 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1715 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1716 parameters[4] = AliGRPObject::GetInvalidFloat();
1720 parameters[3] = AliGRPObject::GetInvalidFloat();
1721 parameters[4] = AliGRPObject::GetInvalidFloat();
1724 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1726 AliDebug(2,"Calculating Truncated Mean");
1727 for (Int_t i =0; i< nentriesUsed; i++){
1728 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1729 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1730 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1731 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1732 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1736 AliDebug(2,"Discarding entry");
1739 // setting truncated mean
1740 if (entriesTruncMean >1){
1741 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1742 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1745 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1746 parameters[1] = AliGRPObject::GetInvalidFloat();
1750 parameters[1] = AliGRPObject::GetInvalidFloat();
1753 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1754 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1755 AliInfo(Form("median = %f ",parameters[2]));
1756 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1757 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1762 //__________________________________________________________________________________________________________________
1764 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1767 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1768 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1769 // the flag is set according to the L3/Dipole current value
1770 // current threshold for L3 = 350 A (value provided by DCS)
1771 // current threshold for Dipole = 450 A (value provided by DCS)
1773 // parameters[0] = mean
1774 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1775 // parameters[2] = median
1776 // parameters[3] = standard deviation wrt mean
1777 // parameters[4] = standard deviation wrt median
1780 AliInfo(Form("indexDP = %d",indexDP));
1782 Int_t nCounts = array->GetEntries();
1783 for(Int_t i = 0; i < nCounts; i++) {
1784 AliDCSValue *v = (AliDCSValue *)array->At(i);
1785 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1786 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1787 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1788 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1791 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1792 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1793 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1794 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1797 AliError(Form("DCS values for the parameter outside the queried interval"));
1801 return ProcessFloatAll(array);
1805 //_______________________________________________________________
1807 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1810 // processing Boolean values
1813 Bool_t aDCSBool = kTRUE;
1815 AliDCSValue *v = 0x0;
1817 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1818 v = (AliDCSValue *)array->At(iCount);
1819 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1820 AliError(Form("DCS values for the parameter outside the queried interval"));
1824 if (aDCSBool != v->GetBool()) {
1825 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1829 aDCSBool = v->GetBool(); // always keeping last value
1830 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1833 Char_t caDCSBool = (Char_t) aDCSBool;
1838 //_______________________________________________________________
1840 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1843 // processing Int values, returning mean
1844 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1845 // are outside the queried time interval or their value is out of range
1848 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1849 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1850 if (timeStartString.IsNull() || timeStartString.IsNull()){
1851 if (timeStartString.IsNull()){
1852 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1854 else if (timeStartString.IsNull()){
1855 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1860 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1861 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1862 Float_t aDCSArrayMean = 0.0;
1864 Float_t valueBeforeSOR = 0;
1865 Float_t valueAfterEOR = 0;
1866 Int_t timestampBeforeSOR = -1;
1867 Int_t timestampAfterEOR = -1;
1868 Int_t ientrySOR = -1;
1869 Int_t ientryEOR = -1;
1870 Float_t* arrayValues = 0x0;
1871 Double_t* arrayWeights = 0x0;
1872 Int_t iCountsRun = 0;
1873 Int_t nCounts = array->GetEntries();
1875 for(Int_t i = 0; i < nCounts; i++) {
1876 AliDCSValue* v = (AliDCSValue *)array->At(i);
1877 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1878 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1879 return AliGRPObject::GetInvalidFloat();
1881 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1882 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1884 // look for the last value before SOR and the first value before EOR
1885 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1886 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1887 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1888 valueBeforeSOR = (Float_t) v->GetInt();
1890 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1891 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1892 valueAfterEOR = (Float_t) v->GetInt();
1893 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1895 // check if there are DPs between DAQ_time_start and DAQ_time_end
1896 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1897 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1898 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1899 AliDebug(2,Form("entry between SOR and EOR"));
1904 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1908 if (timestampBeforeSOR == -1){
1909 AliWarning("No value found before SOR!");
1911 if (timestampAfterEOR == -1){
1912 AliWarning("No value found after EOR!");
1915 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1916 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1917 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1918 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1919 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1920 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1922 Int_t nentriesUsed = 0;
1923 if (iCountsRun > 1){
1924 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1925 AliDebug(2,"Calculating (weighted) Mean");
1926 arrayValues = new Float_t[iCountsRun];
1927 arrayWeights = new Double_t[iCountsRun];
1928 nentriesUsed = iCountsRun;
1929 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1930 AliDCSValue *v = (AliDCSValue *)array->At(i);
1931 Int_t timestamp2 = 0;
1933 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1934 timestamp2 = (Int_t)v1->GetTimeStamp();
1937 timestamp2 = timeEnd+1;
1939 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1940 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1942 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1944 else if (iCountsRun == 1){
1945 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1947 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1948 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1949 arrayValues = new Float_t[2];
1950 arrayWeights = new Double_t[2];
1951 arrayValues[0] = valueBeforeSOR;
1952 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1953 arrayValues[1] = (Float_t)v->GetInt();
1954 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1955 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1956 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1957 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1960 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1961 return AliGRPObject::GetInvalidFloat();
1964 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1965 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1966 if (timestampBeforeSOR == -1){
1967 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1969 if (timestampAfterEOR == -1){
1970 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1972 return AliGRPObject::GetInvalidFloat();
1975 AliWarning("Using last entry before SOR and first entry after EOR.");
1977 arrayValues = new Float_t[2];
1978 arrayWeights = new Double_t[2];
1979 arrayValues[0] = valueBeforeSOR;
1980 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1981 arrayValues[1] = valueAfterEOR;
1982 arrayWeights[1] = 1.;
1983 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1984 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1985 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1989 AliInfo(Form("mean = %f ", aDCSArrayMean));
1990 return aDCSArrayMean;
1993 //_______________________________________________________________
1995 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1998 // processing Int values, returning mean
1999 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2000 // are outside the queried time interval or their value is out of range
2003 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2004 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2005 if (timeStartString.IsNull() || timeStartString.IsNull()){
2006 if (timeStartString.IsNull()){
2007 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2009 else if (timeStartString.IsNull()){
2010 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2015 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2016 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2017 Float_t aDCSArrayMean = 0.0;
2019 Float_t valueBeforeSOR = 0;
2020 Float_t valueAfterEOR = 0;
2021 Int_t timestampBeforeSOR = -1;
2022 Int_t timestampAfterEOR = -1;
2023 Int_t ientrySOR = -1;
2024 Int_t ientryEOR = -1;
2025 Float_t* arrayValues = 0x0;
2026 Double_t* arrayWeights = 0x0;
2027 Int_t iCountsRun = 0;
2028 Int_t nCounts = array->GetEntries();
2030 for(Int_t i = 0; i < nCounts; i++) {
2031 AliDCSValue* v = (AliDCSValue *)array->At(i);
2032 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2033 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2034 return AliGRPObject::GetInvalidFloat();
2036 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2037 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2039 // look for the last value before SOR and the first value before EOR
2040 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2041 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2042 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2043 valueBeforeSOR = (Float_t)v->GetUInt();
2045 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2046 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2047 valueAfterEOR = (Float_t)v->GetUInt();
2048 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2050 // check if there are DPs between DAQ_time_start and DAQ_time_end
2051 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2052 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2053 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2054 AliDebug(2,Form("entry between SOR and EOR"));
2059 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2063 if (timestampBeforeSOR == -1){
2064 AliWarning("No value found before SOR!");
2066 if (timestampAfterEOR == -1){
2067 AliWarning("No value found after EOR!");
2070 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2071 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2072 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2073 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2074 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2075 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2077 Int_t nentriesUsed = 0;
2078 if (iCountsRun > 1){
2079 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2080 AliDebug(2,"Calculating (weighted) Mean");
2081 arrayValues = new Float_t[iCountsRun];
2082 arrayWeights = new Double_t[iCountsRun];
2083 nentriesUsed = iCountsRun;
2084 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2085 AliDCSValue *v = (AliDCSValue *)array->At(i);
2086 Int_t timestamp2 = 0;
2088 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2089 timestamp2 = (Int_t)v1->GetTimeStamp();
2092 timestamp2 = timeEnd+1;
2094 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2095 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2097 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2099 else if (iCountsRun == 1){
2100 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2102 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2103 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2104 arrayValues = new Float_t[2];
2105 arrayWeights = new Double_t[2];
2106 arrayValues[0] = valueBeforeSOR;
2107 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2108 arrayValues[1] = (Float_t)v->GetUInt();
2109 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2110 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2111 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2112 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2115 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2116 return AliGRPObject::GetInvalidFloat();
2119 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2120 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2121 if (timestampBeforeSOR == -1){
2122 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2124 if (timestampAfterEOR == -1){
2125 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2127 return AliGRPObject::GetInvalidFloat();
2130 AliWarning("Using last entry before SOR and first entry after EOR.");
2132 arrayValues = new Float_t[2];
2133 arrayWeights = new Double_t[2];
2134 arrayValues[0] = valueBeforeSOR;
2135 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2136 arrayValues[1] = valueAfterEOR;
2137 arrayWeights[1] = 1.;
2138 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2139 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2140 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2144 AliInfo(Form("mean = %f ",aDCSArrayMean));
2145 return aDCSArrayMean;
2150 //_______________________________________________________________
2152 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2154 // extract DCS pressure maps. Perform fits to save space
2156 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2158 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2159 fPressure->MakeSplineFit(map);
2160 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2161 if (fitFraction > kFitFraction ) {
2162 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2164 AliInfo("Too few pressure maps fitted!!!");
2167 AliInfo("no atmospheric pressure map extracted!!!");
2176 //_______________________________________________________________
2177 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)
2180 // Retrieves logbook and trigger information from the online logbook
2181 // This information is needed for prompt reconstruction
2185 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2189 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2190 // 0 on success and no run was found
2191 // negative on error
2193 // This function is NOT called during the preprocessor run in the Shuttle!
2201 AliCDBManager* cdb = AliCDBManager::Instance();
2202 cdb->SetDefaultStorage(cdbRoot);
2205 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2209 Printf("ERROR: Could not connect to DAQ LB");
2215 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2216 TSQLResult* result = server->Query(sqlQuery);
2219 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2223 if (result->GetRowCount() == 0)
2225 Printf("ERROR: Run %d not found", run);
2230 TSQLRow* row = result->Next();
2233 Printf("ERROR: Could not receive data from run %d", run);
2238 TString timeStartString(row->GetField(0));
2239 TString runType(row->GetField(1));
2240 TString detectorMaskString(row->GetField(2));
2241 TString l3CurrentString(row->GetField(3));
2242 TString dipoleCurrentString(row->GetField(4));
2243 time_t timeStart = (time_t)(timeStartString.Atoi());
2244 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2245 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2246 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2247 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2248 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2250 AliGRPObject * grpObj = new AliGRPObject();
2251 grpObj->SetTimeStart(timeStart);
2252 grpObj->SetRunType((TString)(row->GetField(1)));
2253 grpObj->SetDetectorMask(detectorMask);
2254 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2255 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2256 grpObj->SetL3Polarity(l3Polarity);
2257 grpObj->SetDipolePolarity(dipolePolarity);
2258 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2266 Printf("Storing GRP/GRP/Data object with the following content");
2269 AliCDBMetaData metadata;
2270 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2271 metadata.SetComment("GRP Output parameters received during online running");
2273 AliCDBId id("GRP/GRP/Data", run, run);
2274 Bool_t success = cdb->Put(grpObj, id, &metadata);
2280 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2284 // Receive trigger information
2285 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2286 result = server->Query(sqlQuery);
2289 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2293 if (result->GetRowCount() == 0)
2295 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2300 row = result->Next();
2303 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2308 TString triggerConfig(row->GetField(0));
2316 Printf("Found trigger configuration: %s", triggerConfig.Data());
2318 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2321 Printf("ERROR: Could not create CTP configuration object");
2325 metadata.SetComment("CTP run configuration received during online running");
2327 AliCDBId id2("GRP/CTP/Config", run, run);
2328 success = cdb->Put(runcfg, id2, &metadata);
2335 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2340 // Receive list of GDCs for this run
2341 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2342 result = server->Query(sqlQuery);
2345 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2349 if (result->GetRowCount() == 0)
2351 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2357 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2358 row = result->Next();
2361 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2365 gdc += row->GetField(0);
2375 Printf("Found GDC: %s", gdc.Data());
2377 // get last run with same run type that was already processed by the SHUTTLE
2379 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());
2380 result = server->Query(sqlQuery);
2383 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2387 if (result->GetRowCount() == 0)
2389 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2394 row = result->Next();
2397 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2402 TString lastRunStr(row->GetField(0));
2403 Int_t lastRun = lastRunStr.Atoi();
2405 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2419 //-----------------------------------------------------------------
2420 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* array){
2423 // Calculating mean over TObjArray from LHC Data
2426 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2427 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2428 if (timeStartString.IsNull() || timeStartString.IsNull()){
2429 if (timeStartString.IsNull()){
2430 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2432 else if (timeStartString.IsNull()){
2433 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2438 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2439 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2440 timeStart = 1260646960;
2441 timeEnd = 1260652740;
2442 Double_t* parameters = new Double_t[5];
2443 parameters[0] = -1.;
2444 parameters[1] = -1.;
2445 parameters[2] = -1.;
2446 parameters[3] = -1.;
2447 parameters[4] = -1.;
2449 Int_t iCountsRun = 0;
2450 Int_t nCounts = array->GetEntries();
2451 printf("ncounts = %d\n",nCounts);
2452 Double_t valueBeforeSOR = 0;
2453 Double_t valueAfterEOR = 0;
2454 Double_t timestampBeforeSOR = -1.;
2455 Double_t timestampAfterEOR = -1.;
2456 Int_t ientrySOR = -1;
2457 Int_t ientryEOR = -1;
2458 Double_t* arrayValues = 0x0;
2459 Double_t* arrayWeights = 0x0;
2460 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2461 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2463 for(Int_t i = 0; i < nCounts; i++) {
2464 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2465 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2466 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2468 // look for the last value before SOR and the first value before EOR
2469 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2470 timestampBeforeSOR = dcs->GetTimeStamp();
2471 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2472 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2474 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2475 timestampAfterEOR = dcs->GetTimeStamp();
2476 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2477 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2479 // check if there are DPs between DAQ_time_start and DAQ_time_end
2480 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2481 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2482 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2483 AliDebug(2,Form("entry between SOR and EOR\n"));
2488 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2492 if (timestampBeforeSOR == -1.){
2493 printf("No value found before SOR\n");
2495 if (timestampAfterEOR == -1.){
2496 printf("No value found after EOR\n");
2499 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2500 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2501 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2502 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2503 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2504 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2506 Int_t nentriesUsed = 0;
2507 if (iCountsRun > 1){
2508 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2509 printf("Calculating (weighted) Mean and Median\n" );
2510 arrayValues = new Double_t[iCountsRun];
2511 arrayWeights = new Double_t[iCountsRun];
2512 nentriesUsed = iCountsRun;
2513 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2514 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2515 Double_t timestamp2 = 0;
2517 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2518 timestamp2 = dcs1->GetTimeStamp();
2521 timestamp2 = (Double_t)timeEnd+1;
2523 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2524 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2525 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2527 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2528 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2530 else if (iCountsRun == 1){
2531 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2533 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2534 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");
2535 arrayValues = new Double_t[2];
2536 arrayWeights = new Double_t[2];
2537 arrayValues[0] = valueBeforeSOR;
2538 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2539 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2540 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2541 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2542 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2543 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2544 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2545 truncMeanFlag = kFALSE;
2548 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");
2554 return parameters[0];
2557 else { // iCountsRun == 0, using only the point immediately before SOR
2558 if (timestampBeforeSOR == -1.){
2559 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");
2565 return parameters[0];
2568 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2569 printf("value = %f\n",valueBeforeSOR);
2570 parameters[0] = valueBeforeSOR;
2571 parameters[2] = valueBeforeSOR;
2572 truncMeanFlag = kFALSE;
2579 Double_t sumweights = 0;
2580 Int_t entriesTruncMean = 0;
2581 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2582 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2584 // calculating SD wrt Mean and Median
2585 printf("Calculating SD wrt Mean and SD wrt Median\n");
2587 for (Int_t i =0; i< nentriesUsed; i++){
2588 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2589 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2590 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2591 sumweights += arrayWeights[i];
2593 // setting SD wrt Mean
2594 if (sumweights != 0 ){
2595 parameters[3] = TMath::Sqrt(temp1/sumweights);
2598 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2601 // setting SD wrt Median
2602 if (nentriesUsed != 0){
2603 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2606 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2615 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2617 printf("Calculating Truncated Mean\n");
2618 for (Int_t i =0; i< nentriesUsed; i++){
2619 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2620 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2621 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2622 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2623 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2627 printf("Discarding entry\n");
2630 // setting truncated mean
2631 if (entriesTruncMean >1){
2632 printf("%d entries used for truncated mean\n",entriesTruncMean);
2633 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2636 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2644 printf("(weighted) mean = %f \n",parameters[0]);
2645 printf("(weighted) truncated mean = %f \n",parameters[1]);
2646 printf("median = %f \n",parameters[2]);
2647 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2648 printf("standard deviation with median = %f \n",parameters[4]);
2650 return (parameters[0]);
2652 //------------------------------------------------------------------------------------------------------
2653 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* array, Double_t timeStart, Double_t timeEnd){
2656 // Method to processo LHC Energy information
2657 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2660 Int_t nCounts = array->GetEntries();
2661 Float_t energy = -1;
2662 Bool_t inRange = kFALSE;
2663 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2665 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2668 for(Int_t i = 0; i < nCounts; i++) {
2669 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2670 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2671 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2672 AliInfo(Form("Energy value found = %d, converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),energy));
2677 if (inRange == kFALSE){
2678 AliInfo("No Energy value found between DAQ_time_start and DAQ_time_end - energy will remain invalid!");