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 = 6; // num parameters in the logbook used to fill the GRP object
75 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
76 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
77 const Int_t AliGRPPreprocessor::fgknLHCDP = 5; // number of dcs dps from LHC data
78 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
79 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
80 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
88 "L3_BSF17_Temperature",
92 "L3_BSF4_Temperature",
96 "L3_BKF17_Temperature",
100 "L3_BKF4_Temperature",
104 "L3_BSF13_Temperature",
108 "L3_BSF8_Temperature",
112 "L3_BKF13_Temperature",
116 "L3_BKF8_Temperature",
120 "Dipole_Inside_Temperature",
124 "Dipole_Outside_Temperature",
126 "CavernAtmosPressure",
127 "SurfaceAtmosPressure",
128 "CavernAtmosPressure2"
131 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
135 "L3_BSF17_Temperature",
139 "L3_BSF4_Temperature",
143 "L3_BKF17_Temperature",
147 "L3_BKF4_Temperature",
151 "L3_BSF13_Temperature",
155 "L3_BSF8_Temperature",
159 "L3_BKF13_Temperature",
163 "L3_BKF8_Temperature",
167 "Dipole_Inside_Temperature",
171 "Dipole_Outside_Temperature"
174 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
175 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
178 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
182 "dip/acc/LHC/RunControl/BeamType/Beam1.payload",
183 "dip/acc/LHC/RunControl/BeamType/Beam2.payload"
185 const char* kppError[] = {
187 "(DAQ logbook ERROR)",
189 "(Trigger Scalers not found in DCS FXS - ERROR)",
190 "(DCS data points ERROR)",
191 "(Trigger Configuration ERROR)",
192 "(DAQ logbook ERROR determining partition of the run)",
193 "(CTP timing ERROR)",
194 "(SPD Mean Vertex ERROR)",
195 "(DCS FXS Error for LHC Data)",
199 //_______________________________________________________________
201 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
202 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))
204 // constructor - shuttle must be instantiated!
206 AddRunType("COSMIC");
208 AddRunType("PHYSICS");
209 AddRunType("CALIBRATION_BC");
210 AddRunType("CALIBRATION_CENTRAL");
211 AddRunType("CALIBRATION_EMD");
212 AddRunType("CALIBRATION_MB");
213 AddRunType("CALIBRATION_SEMICENTRAL");
214 AddRunType("CALIBRATION");
215 AddRunType("PEDESTAL");
216 AddRunType("STANDALONE");
219 AddRunType("PULSER");
220 AddRunType("STANDALONE_PULSER");
221 AddRunType("STANDALONE_BC");
224 fminFloat = -FLT_MAX;
225 fmaxDouble = DBL_MAX;
226 fminDouble = -DBL_MAX;
232 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
233 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
234 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
235 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
236 AliInfo(Form("Max allowed integer = %d",fmaxInt));
237 AliInfo(Form("Min allowed integer = %d",fminInt));
238 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
239 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
241 ffailedDPs->SetOwner(kTRUE);
244 //_______________________________________________________________
246 AliGRPPreprocessor::~AliGRPPreprocessor()
255 //_______________________________________________________________
257 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
259 // Initialize preprocessor
261 AliPreprocessor::Initialize(run, startTime, endTime);
263 AliInfo("Initialization of the GRP preprocessor.");
264 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
265 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
266 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
267 for(Int_t j = 0; j < kNumSensors; j++) {
268 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
269 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
271 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
273 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
275 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
276 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
277 ffailedDPs->AddAt(dp,iDP);
282 //_______________________________________________________________
284 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
286 // process data retrieved by the Shuttle
288 // retrieving "partition" and "detector" fields from DAQ logbook to
289 // determine the partition in which the run was taken
290 // the partition is used to decide how to react in case of errors for CTP
292 TString partition = (TString)GetRunParameter("partition");
293 TString detector = (TString)GetRunParameter("detector");
295 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
296 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
298 //=================//
300 //=================//
302 Log("*************** Processing DAQ logbook");
306 Int_t iDaqLB = ProcessDaqLB(grpobj);
307 TString runType = (TString)GetRunType();
308 TString beamType = (TString)GetRunParameter("beamType");
309 if(iDaqLB == fgknDAQLbPar) {
310 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
312 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
316 //=================//
318 //=================//
320 Log("*************** Processing DAQ FXS");
322 UInt_t iDaqFxs = ProcessDaqFxs();
324 Log(Form("DAQ FXS, successful!"));
326 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
330 //=================//
332 //=================//
334 Log("*************** Processing DCS FXS");
336 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
338 Log(Form("DCS FXS, successful!"));
339 } else if (iDcsFxs ==1) {
340 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
343 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
347 //=================//
348 // DCS data points //
349 //=================//
351 Log("*************** Processing DCS DPs");
353 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
354 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
355 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
356 if (fdaqStartEndTimeOk){
357 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
358 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
359 Log(Form("The DPs giving problems were:"));
360 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
361 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
363 TString name = dpString->String();
364 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
365 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
368 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()));
374 else Log(Form("DCS data points, successful!"));
376 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"));
378 //=======================//
379 // Trigger Configuration //
380 //=======================//
382 Log("*************** Processing Trigger Configuration");
384 const char * triggerConf = GetTriggerConfiguration();
386 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
387 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
388 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
390 Log(Form("No dummy CTP configuration entry found, going into error..."));
394 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
396 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
400 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
401 runcfg->SetTitle(titleCTPcfg);
402 AliCDBMetaData metaData;
403 metaData.SetResponsible("Roman Lietava");
404 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
405 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
406 Log("Unable to store the dummy CTP run configuration object to OCDB!");
413 else if (!partition.IsNull() && detector.IsNull()){ // global partition
414 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
415 if (triggerConf!= NULL) {
416 Log("Found trigger configuration in DAQ logbook");
417 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
419 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
423 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
424 runcfg->SetTitle(titleCTPcfg);
425 AliCDBMetaData metaData;
426 metaData.SetBeamPeriod(0);
427 metaData.SetResponsible("Roman Lietava");
428 metaData.SetComment("CTP run configuration from DAQ logbook");
429 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
430 Log("Unable to store the CTP run configuration object to OCDB!");
437 Log("Trigger configuration NULL in DAQ logbook");
443 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
447 //===========================//
448 // Trigger Timing Parameters //
449 //===========================//
451 Log("*************** Processing Trigger Time Params");
453 const char * triggerCTPtiming = GetCTPTimeParams();
455 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
456 Log("STANDALONE partition for current run, using CTP timing params dummy value");
457 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
459 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
463 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
465 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
469 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
470 runCTPtiming->SetTitle(titleCTPtiming);
471 AliCDBMetaData metadata;
472 metadata.SetResponsible("Roman Lietava");
473 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
474 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
475 Log("Unable to store the dummy CTP timing params object to OCDB!");
482 else if (!partition.IsNull() && detector.IsNull()){ // global partition
483 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
484 if (triggerCTPtiming!= NULL) {
485 Log("Found trigger timing params in DAQ logbook");
486 AliDebug(2,Form("%s",triggerCTPtiming));
487 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
489 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
493 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
494 runCTPtiming->SetTitle(titleCTPtiming);
495 AliCDBMetaData metadata;
496 metadata.SetBeamPeriod(0);
497 metadata.SetResponsible("Roman Lietava");
498 metadata.SetComment("CTP timing params from DAQ logbook");
499 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
500 Log("Unable to store the CTP timing params object to OCDB!");
507 Log("Trigger timing params NULL in DAQ logbook");
513 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
518 //=================//
520 //=================//
522 Log("*************** Processing LHC Data");
524 UInt_t iLHCData = ProcessLHCData(grpobj);
526 if( iLHCData == 0 ) {
527 Log(Form("LHC Data from DCS FXS, successful!"));
528 } else if (iLHCData == 1) {
529 Log(Form("LHC Data, problems with DCS FXS!"));
531 } else if (iLHCData ==3){
532 Log(Form("Problems in storing LHC Data - but not going into Error"));
533 } else if (iLHCData ==4){
534 Log(Form("Problems with LHC Data to be put in /GRP/GRP/LHCData - but not going into Error"));
536 Log(Form("LHC Data problems"));
540 //==================//
541 // SPD Mean Vertex //
542 //==================//
544 Log("*************** Processing SPD Mean Vertex");
546 if (runType == "PHYSICS"){
547 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
548 if( iSPDMeanVertex == 1 ) {
549 Log(Form("SPD Mean Vertex, successful!"));
551 Log(Form("SPD Mean Vertex failed!!!"));
556 Log("SPD Mean Vertex not processed since runType != PHYSICS");
559 // storing AliGRPObject in OCDB
562 md.SetResponsible("Chiara Zampolli");
563 md.SetComment("Output parameters from the GRP preprocessor.");
565 Bool_t result = kTRUE;
566 result = Store("GRP", "Data", grpobj, &md);
569 if (result && !error ) {
570 Log("GRP Preprocessor Success");
573 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s",
574 kppError[(error&1)?1:0],
575 kppError[(error&2)?2:0],
576 kppError[(error&4)?3:0],
577 kppError[(error&8)?4:0],
578 kppError[(error&16)?5:0],
579 kppError[(error&32)?6:0],
580 kppError[(error&64)?7:0],
581 kppError[(error&128)?8:0],
582 kppError[(error&256)?9:0],
583 kppError[(error&512)?10:0]
591 //_______________________________________________________________
593 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
596 //Getting the LHC Data from DCS FXS
599 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
600 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
601 if (timeStartString.IsNull() || timeEndString.IsNull()){
602 if (timeStartString.IsNull()){
603 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
605 else if (timeEndString.IsNull()){
606 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
611 Double_t timeStart = timeStartString.Atof();
612 Double_t timeEnd = timeEndString.Atof();
614 TString fileName = GetFile(kDCS, "LHCData","");
615 if (fileName.Length()>0){
616 AliInfo("Got The LHC Data file");
617 AliLHCReader lhcReader;
618 TMap* lhcMap = (TMap*)lhcReader.ReadLHCDP(fileName.Data());
620 Log(Form("LHCData map entries = %d",lhcMap->GetEntries()));
622 // Processing data to be put in AliGRPObject
624 TObjArray* energyArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[0]);
626 Float_t energy = ProcessEnergy(energyArray,timeStart,timeEnd);
628 grpobj->SetBeamEnergy(energy);
629 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
633 AliError("Energy not found in LHC Data file!!!");
635 Double_t timeBeamMode = 0;
636 Double_t timeMachineMode = 0;
637 Bool_t flagBeamMode = kFALSE; //flag set true if at least one BeamMode measurement is found within DAQ_time_start and DAQ_time_end
638 Bool_t flagMachineMode = kFALSE; //flag set true if at least one MachineMode measurement is found within DAQ_time_start and DAQ_time_end
640 TObjArray* beamModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[2]);
641 Int_t nBeamMode = -1;
643 nBeamMode = beamModeArray->GetEntries();
645 AliInfo("Found zero entries for the Beam Mode, setting it to UNKNOWN");
646 grpobj->SetLHCState("UNKNOWN");
650 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(0);
651 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
652 TObjString* beamModeString = beamMode->GetStringArray(0);
653 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
654 grpobj->SetLHCState(beamModeString->String());
657 AliInfo("No Beam Mode found within DAQ_time_start and DAQ_time_end, setting it to UNKNOWN");
658 grpobj->SetLHCState("UNKNOWN");
662 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
663 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
664 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
665 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(iBeamMode+1);
666 if (beamMode1->GetTimeStamp()>=timeStart && beamMode1->GetTimeStamp()<=timeEnd){
667 timeBeamMode = beamMode1->GetTimeStamp();
668 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));
670 TObjString* beamModeString = beamMode->GetStringArray(0);
671 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
672 grpobj->SetLHCState(beamModeString->String());
673 flagBeamMode = kTRUE;
678 AliError("Found values for BeamMode, but none within DAQ_time_start and DAQ_time_end, setting BeamMode to UNKNOWN");
679 grpobj->SetLHCState("UNKONWN");
685 AliError("Beam mode array not found in LHC Data file!!!");
689 TObjArray* machineModeArray = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[1]);
690 Int_t nMachineMode = -1;
691 if (machineModeArray){
692 nMachineMode = machineModeArray->GetEntries();
693 if (nMachineMode==0){
694 AliInfo("No Machine Mode found, setting it to UNKNOWN");
695 grpobj->SetMachineMode("UNKNOWN");
698 if (nMachineMode ==1) {
699 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(0);
700 if (machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
701 TObjString* machineModeString = machineMode->GetStringArray(0);
702 AliInfo(Form("Machine Mode = %s",(machineModeString->String()).Data()));
703 grpobj->SetMachineMode(machineModeString->String());
706 AliInfo("No Machine Mode found within DAQ_time_start and DAQ_time_end, setting it to UNKNOWN");
707 grpobj->SetMachineMode("UNKNOWN");
711 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
712 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
713 if (machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
714 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(iMachineMode+1);
715 if (machineMode1->GetTimeStamp()>=timeStart && machineMode1->GetTimeStamp()<=timeEnd){
716 timeMachineMode = machineMode1->GetTimeStamp();
717 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));
719 TObjString* machineModeString = machineMode->GetStringArray(0);
720 AliInfo(Form("Machine mode = %s",(machineModeString->String()).Data()));
721 grpobj->SetMachineMode(machineModeString->String());
722 flagMachineMode = kTRUE;
726 if (!flagMachineMode){
727 AliError("Found values for MachineMode, but none within DAQ_time_start and DAQ_time_end, setting MachineMode to UNKNOWN");
728 grpobj->SetMachineMode("UNKONWN");
734 AliError("Machine mode array not found in LHC Data file!!!");
737 // Setting minTimeLHCValidity
738 if (timeBeamMode!=0 || timeMachineMode!=0){
739 Double_t minTimeLHCValidity;
740 if (timeBeamMode == 0){
741 minTimeLHCValidity = timeMachineMode;
743 else if (timeMachineMode == 0){
744 minTimeLHCValidity = timeBeamMode;
747 minTimeLHCValidity= TMath::Min(timeBeamMode,timeMachineMode);
749 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
750 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
753 // BeamType1 and BeamType2
754 TObjArray* beam1Array = (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[3]);
756 AliInfo(Form("%d entries for Beam1",beam1Array->GetEntries()));
759 AliError("Beam1 array not found in LHC data file!!!");
761 TObjArray* beam2Array =
762 (TObjArray*)lhcMap->GetValue(fgkLHCDataPoints[4]);
764 AliInfo(Form("%d entries for Beam2",beam2Array->GetEntries()));
767 AliError("Beam2 array not found in LHC data file!!!");
769 // Processing data to go to AliLHCData object
770 AliLHCData* dt = new AliLHCData(lhcMap,timeStart,timeEnd);
772 // storing AliLHCData in OCDB
775 md.SetResponsible("Ruben Shahoyan");
776 md.SetComment("LHC data from the GRP preprocessor.");
778 Bool_t result = kTRUE;
779 result = Store("GRP", "LHCData", dt, &md);
781 if (result) return 0;
788 AliError("Cannot read correctly LHCData file");
794 AliError("No LHCData file found in DCS FXS");
800 //_______________________________________________________________
802 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
805 //Getting the SPD Mean Vertex
808 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
809 Bool_t storeResult = kTRUE;
810 if (list !=0x0 && list->GetEntries()!=0)
812 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
814 for (Int_t jj=0;jj<list->GetEntries();jj++){
815 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
816 AliInfo(Form("found source %s", str->String().Data()));
817 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
818 if (fileNameRun.Length()>0){
819 AliInfo(Form("Got the file %s", fileNameRun.Data()));
820 TFile daqFile(fileNameRun.Data(),"READ");
821 if (daqFile.IsOpen()) {
822 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
825 // storing in the OCDB
827 md.SetResponsible("Cvetan Cheshkov");
828 md.SetComment("SPD Mean Vertex");
829 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
832 AliWarning("No SPD Mean Vertex object found in file");
836 AliError("Can't open file");
837 storeResult = kFALSE;
841 AliWarning("No file found for current source for SPD Mean Vertex");
846 AliWarning("No list found for SPD Mean Vertex");
849 if (list) delete list;
855 //_______________________________________________________________
857 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
859 //Getting the DAQ lb information
861 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
862 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
863 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
864 TString beamType = (TString)GetRunParameter("beamType");
865 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
866 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
867 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
868 TString runType = (TString)GetRunType();
870 UInt_t nparameter = 0;
872 grpObj->SetTimeStart(timeStart);
873 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
877 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
881 grpObj->SetTimeEnd(timeEnd);
882 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
886 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
889 if (beamEnergy != 0){
890 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
893 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
897 if (beamType.Length() != 0){
898 Log(Form("Beam Type for run %d: %s (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamType.Data()));
901 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
904 if (numberOfDetectors != 0){
905 grpObj->SetNumberOfDetectors(numberOfDetectors);
906 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
910 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
913 if (detectorMask != 0){
914 grpObj->SetDetectorMask(detectorMask);
915 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
919 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
922 if (lhcPeriod.Length() != 0) {
923 grpObj->SetLHCPeriod(lhcPeriod);
924 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
928 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
930 if (runType.Length() != 0) {
931 grpObj->SetRunType(runType);
932 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
936 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
942 //_______________________________________________________________
944 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
946 //======DAQ FXS======//
948 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
949 TList* list = GetFileSources(kDAQ);
951 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
955 if (list->GetEntries() == 0) {
956 Log("no raw data tags in this run: nothing to merge!");
961 TChain *fRawTagChain = new TChain("T");
963 TIterator* iter = list->MakeIterator();
965 while ((obj = iter->Next())) {
966 TObjString* objStr = dynamic_cast<TObjString*> (obj);
968 Log(Form("Found source %s", objStr->String().Data()));
969 TList* list2 = GetFileIDs(kDAQ, objStr->String());
971 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
972 delete fRawTagChain; fRawTagChain=0;
975 Log(Form("Number of ids: %d",list2->GetEntries()));
976 for(Int_t i = 0; i < list2->GetEntries(); i++) {
977 TObjString *idStr = (TObjString *)list2->At(i);
978 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
979 if (fileName.Length() > 0) {
980 Log(Form("Adding file in the chain: %s",fileName.Data()));
981 fRawTagChain->Add(fileName.Data());
984 Log(Form("Could not retrieve file with id %s from source %s: "
985 "connection problems with DAQ FXS!",
986 idStr->String().Data(), objStr->String().Data()));
988 delete list2; list2=0;
989 delete fRawTagChain; fRawTagChain=0;
997 TString fRawDataFileName = "GRP_Merged.tag.root";
998 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1000 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1001 Log("Error merging raw data files!!!");
1005 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1006 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1009 Log("Problem storing raw data tags in local file!!!");
1011 Log("Raw data tags merged successfully!!");
1016 delete fRawTagChain; fRawTagChain=0;
1018 if (result == kFALSE) {
1026 //_______________________________________________________________
1027 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1030 // processing the info
1031 // stored in the DCS FXS
1032 // coming from the trigger
1034 // Get the CTP counters information
1036 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1037 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1038 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1040 Log(Form("No dummy CTP scalers entry found, going into error..."));
1044 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1046 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1050 AliCDBMetaData metaData;
1051 metaData.SetResponsible("Roman Lietava");
1052 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1053 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1054 Log("Unable to store the dummy CTP scalers object to OCDB!");
1061 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1062 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1063 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1064 if (countersfile.IsNull()) {
1065 Log("No CTP counters files has been found: empty source!");
1069 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1070 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1072 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1076 AliCDBMetaData metaData;
1077 metaData.SetBeamPeriod(0);
1078 metaData.SetResponsible("Roman Lietava");
1079 metaData.SetComment("CTP scalers");
1080 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1081 Log("Unable to store the CTP scalers object to OCDB!");
1092 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1099 //_______________________________________________________________
1101 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1105 // processing DCS DPs
1108 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1109 Int_t nL3Entries = 0;
1110 Int_t nDipoleEntries = 0;
1111 Int_t nEnvEntries = 0;
1112 Int_t nHallProbesEntries = 0;
1113 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1114 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1115 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1116 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1117 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1118 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1119 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1124 //_______________________________________________________________
1126 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1133 Int_t nL3Entries = 0;
1135 TObjArray *array = 0x0;
1137 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1139 AliInfo(Form("==========L3Current==========="));
1140 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1141 indexDP = kL3Current;
1142 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1144 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1147 if (array->GetEntries() == 0){
1148 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1151 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1152 if (floatDCS != NULL){
1153 grpObj->SetL3Current(floatDCS);
1165 ffailedDPs->RemoveAt(indexDP);
1169 if (array) array = 0x0;
1171 AliInfo(Form("==========L3Polarity==========="));
1172 indexDP = kL3Polarity;
1173 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1175 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1178 if (array->GetEntries() == 0){
1179 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1182 Bool_t change = kFALSE;
1183 Char_t charDCS = ProcessBool(array,change);
1184 if (change == kFALSE){
1185 grpObj->SetL3Polarity(charDCS);
1186 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1187 ffailedDPs->RemoveAt(indexDP);
1191 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1192 ffailedDPs->RemoveAt(indexDP);
1196 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]));
1204 //_______________________________________________________________
1206 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1212 Int_t nDipoleEntries = 0;
1213 TObjArray *array = 0x0;
1215 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1217 AliInfo(Form("==========DipoleCurrent==========="));
1218 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1219 indexDP = kDipoleCurrent;
1220 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1222 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1225 if (array->GetEntries() == 0){
1226 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1229 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1230 if (floatDCS != NULL){
1231 grpObj->SetDipoleCurrent(floatDCS);
1243 ffailedDPs->RemoveAt(indexDP);
1247 if (array) array = 0x0;
1249 AliInfo(Form("==========DipolePolarity==========="));
1250 indexDP = kDipolePolarity;
1251 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1253 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1256 if (array->GetEntries() == 0){
1257 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1260 Bool_t change = kFALSE;
1261 Char_t charDCS = ProcessBool(array,change);
1263 grpObj->SetDipolePolarity(charDCS);
1264 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1265 ffailedDPs->RemoveAt(indexDP);
1269 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1270 ffailedDPs->RemoveAt(indexDP);
1274 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]));
1279 return nDipoleEntries;
1282 //_______________________________________________________________
1284 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1288 // evironment conditions (temperature, pressure) info
1290 Int_t nEnvEntries = 0;
1291 TObjArray *array = 0x0;
1294 AliInfo(Form("==========CavernTemperature==========="));
1295 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1296 indexDP = kCavernTemperature;
1297 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1299 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1302 if (array->GetEntries() == 0){
1303 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1306 Float_t *floatDCS = ProcessFloatAll(array);
1307 if (floatDCS != NULL){
1308 grpObj->SetCavernTemperature(floatDCS);
1319 ffailedDPs->RemoveAt(indexDP);
1324 if (array) array = 0x0;
1326 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1327 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1328 //dcsSensorArray->Print();
1329 if( fPressure->NumFits()<kNumSensors ) {
1330 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1332 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1334 AliInfo(Form("==========CavernAtmosPressure==========="));
1335 indexDP = kCavernAtmosPressure;
1336 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1337 TGraph* graph = sensorCavernP2->GetGraph();
1338 AliDebug(3,Form("index = %d",indexDP));
1339 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1340 AliDebug(2,Form("graph = %p",graph));
1341 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1342 if(sensorCavernP2->GetFit() || graph) {
1343 if (sensorCavernP2->GetFit()){
1344 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1347 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1349 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1350 ffailedDPs->RemoveAt(indexDP);
1353 //if (sensorP2) delete sensorP2;
1355 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] ));
1358 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1359 indexDP = kSurfaceAtmosPressure;
1360 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1361 graph = sensorP2->GetGraph();
1362 AliDebug(3,Form("index = %d",indexDP));
1363 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1364 AliDebug(2,Form("graph = %p",graph));
1365 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1366 if(sensorP2->GetFit() || graph) {
1367 if (sensorP2->GetFit()){
1368 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1371 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1373 grpObj->SetSurfaceAtmosPressure(sensorP2);
1374 ffailedDPs->RemoveAt(indexDP);
1377 //if (sensorP2) delete sensorP2;
1379 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] ));
1382 AliInfo(Form("==========CavernAtmosPressure2==========="));
1383 indexDP = kCavernAtmosPressure2;
1384 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1385 graph = sensorCavernP22->GetGraph();
1386 AliDebug(3,Form("index = %d",indexDP));
1387 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1388 AliDebug(2,Form("graph = %p",graph));
1389 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1390 if(sensorCavernP22->GetFit() || graph) {
1391 if (sensorCavernP22->GetFit()){
1392 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1395 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1397 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1398 ffailedDPs->RemoveAt(indexDP);
1401 //if (sensorP2) delete sensorP2;
1403 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] ));
1409 //_______________________________________________________________
1411 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1417 Int_t nHPEntries = 0;
1418 TObjArray *array = 0x0;
1420 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1422 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1423 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()));
1425 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1426 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1427 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1428 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1430 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1433 if (array->GetEntries() == 0){
1434 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1437 Float_t *floatDCS = ProcessFloatAll(array);
1438 if (floatDCS != NULL){
1439 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]));
1440 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1441 for (Int_t kk = 0 ; kk< 5; kk++){
1442 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1454 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1460 Log(Form("Hall Probes = %d ", nHPEntries));
1464 //_________________________________________________________________________
1466 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1470 // returning Spline Fit
1473 Int_t entriesarray = array->GetEntries();
1474 Float_t* value = new Float_t[entriesarray];
1475 Float_t* time = new Float_t[entriesarray];
1476 AliDCSValue* v = 0x0;
1477 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1478 v = (AliDCSValue*)array->At(iarray);
1479 value[iarray] = v->GetFloat();
1480 time[iarray] = v->GetTimeStamp();
1481 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1483 TGraph* gr = new TGraph(entriesarray,value,time);
1485 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1488 AliSplineFit *fit = new AliSplineFit();
1489 fit->SetMinPoints(10);
1490 fit->InitKnots(gr,10,10,0.0);
1494 AliWarning(Form("%s: no fit performed",stringID.Data()));
1500 //_________________________________________________________________________
1502 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1509 TString aDCSString="";
1511 AliDCSValue *v = 0x0;
1512 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1513 v = (AliDCSValue *)array->At(iCount);
1514 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1515 AliError(Form("DCS values for the parameter outside the queried interval"));
1519 if (aDCSString != v->GetChar())
1520 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1522 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1527 //__________________________________________________________________________________________________________________
1529 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1532 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1534 // parameters[0] = mean
1535 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1536 // parameters[2] = median
1537 // parameters[3] = standard deviation wrt mean
1538 // parameters[4] = standard deviation wrt median
1541 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1542 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1543 if (timeStartString.IsNull() || timeStartString.IsNull()){
1544 if (timeStartString.IsNull()){
1545 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1547 else if (timeStartString.IsNull()){
1548 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1550 fdaqStartEndTimeOk = kFALSE;
1554 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1555 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1556 Float_t* parameters = new Float_t[5];
1558 Int_t iCountsRun = 0;
1559 Int_t nCounts = array->GetEntries();
1560 Float_t valueBeforeSOR = 0;
1561 Float_t valueAfterEOR = 0;
1562 Int_t timestampBeforeSOR = -1;
1563 Int_t timestampAfterEOR = -1;
1564 Int_t ientrySOR = -1;
1565 Int_t ientryEOR = -1;
1566 Float_t* arrayValues = 0x0;
1567 Double_t* arrayWeights = 0x0;
1568 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1569 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1571 for(Int_t i = 0; i < nCounts; i++) {
1572 AliDCSValue *v = (AliDCSValue *)array->At(i);
1573 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1574 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1575 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1576 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1579 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1580 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1582 // look for the last value before SOR and the first value before EOR
1583 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1584 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1585 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1586 valueBeforeSOR = v->GetFloat();
1588 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1589 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1590 valueAfterEOR = v->GetFloat();
1591 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1593 // check if there are DPs between DAQ_time_start and DAQ_time_end
1594 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1595 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1596 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1597 AliDebug(2,Form("entry between SOR and EOR"));
1602 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1606 if (timestampBeforeSOR == -1){
1607 AliWarning("No value found before SOR");
1609 if (timestampAfterEOR == -1){
1610 AliWarning("No value found after EOR");
1613 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1614 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1615 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1616 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1617 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1618 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1620 Int_t nentriesUsed = 0;
1621 if (iCountsRun > 1){
1622 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1623 AliDebug(2,"Calculating (weighted) Mean and Median");
1624 arrayValues = new Float_t[iCountsRun];
1625 arrayWeights = new Double_t[iCountsRun];
1626 nentriesUsed = iCountsRun;
1627 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1628 AliDCSValue *v = (AliDCSValue *)array->At(i);
1629 Int_t timestamp2 = 0;
1631 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1632 timestamp2 = (Int_t)v1->GetTimeStamp();
1635 timestamp2 = timeEnd+1;
1637 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1638 arrayValues[i-ientrySOR] = v->GetFloat();
1640 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1641 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1643 else if (iCountsRun == 1){
1644 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1646 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1647 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.");
1648 arrayValues = new Float_t[2];
1649 arrayWeights = new Double_t[2];
1650 arrayValues[0] = valueBeforeSOR;
1651 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1652 arrayValues[1] = v->GetFloat();
1653 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1654 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1655 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1656 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1657 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1658 truncMeanFlag = kFALSE;
1661 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");
1662 parameters[0] = AliGRPObject::GetInvalidFloat();
1663 parameters[1] = AliGRPObject::GetInvalidFloat();
1664 parameters[2] = AliGRPObject::GetInvalidFloat();
1665 parameters[3] = AliGRPObject::GetInvalidFloat();
1666 parameters[4] = AliGRPObject::GetInvalidFloat();
1670 else { // iCountsRun == 0, using only the point immediately before SOR
1671 if (timestampBeforeSOR == -1){
1672 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");
1673 parameters[0] = AliGRPObject::GetInvalidFloat();
1674 parameters[1] = AliGRPObject::GetInvalidFloat();
1675 parameters[2] = AliGRPObject::GetInvalidFloat();
1676 parameters[3] = AliGRPObject::GetInvalidFloat();
1677 parameters[4] = AliGRPObject::GetInvalidFloat();
1681 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1682 AliDebug(2,Form("value = %f",valueBeforeSOR));
1683 parameters[0] = valueBeforeSOR;
1684 parameters[2] = valueBeforeSOR;
1685 truncMeanFlag = kFALSE;
1692 Float_t sumweights = 0;
1693 Int_t entriesTruncMean = 0;
1694 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1695 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1697 // calculating SD wrt Mean and Median
1698 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1700 for (Int_t i =0; i< nentriesUsed; i++){
1701 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1702 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1703 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1704 sumweights += arrayWeights[i];
1706 // setting SD wrt Mean
1707 if (sumweights != 0 ){
1708 parameters[3] = TMath::Sqrt(temp1/sumweights);
1711 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1712 parameters[3] = AliGRPObject::GetInvalidFloat();
1714 // setting SD wrt Median
1715 if (nentriesUsed != 0){
1716 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1719 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1720 parameters[4] = AliGRPObject::GetInvalidFloat();
1724 parameters[3] = AliGRPObject::GetInvalidFloat();
1725 parameters[4] = AliGRPObject::GetInvalidFloat();
1728 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1730 AliDebug(2,"Calculating Truncated Mean");
1731 for (Int_t i =0; i< nentriesUsed; i++){
1732 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1733 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1734 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1735 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1736 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1740 AliDebug(2,"Discarding entry");
1743 // setting truncated mean
1744 if (entriesTruncMean >1){
1745 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1746 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1749 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1750 parameters[1] = AliGRPObject::GetInvalidFloat();
1754 parameters[1] = AliGRPObject::GetInvalidFloat();
1757 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1758 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1759 AliInfo(Form("median = %f ",parameters[2]));
1760 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1761 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1766 //__________________________________________________________________________________________________________________
1768 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1771 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1772 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1773 // the flag is set according to the L3/Dipole current value
1774 // current threshold for L3 = 350 A (value provided by DCS)
1775 // current threshold for Dipole = 450 A (value provided by DCS)
1777 // parameters[0] = mean
1778 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1779 // parameters[2] = median
1780 // parameters[3] = standard deviation wrt mean
1781 // parameters[4] = standard deviation wrt median
1784 AliInfo(Form("indexDP = %d",indexDP));
1786 Int_t nCounts = array->GetEntries();
1787 for(Int_t i = 0; i < nCounts; i++) {
1788 AliDCSValue *v = (AliDCSValue *)array->At(i);
1789 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1790 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1791 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1792 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1795 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1796 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1797 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1798 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1801 AliError(Form("DCS values for the parameter outside the queried interval"));
1805 return ProcessFloatAll(array);
1809 //_______________________________________________________________
1811 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1814 // processing Boolean values
1817 Bool_t aDCSBool = kTRUE;
1819 AliDCSValue *v = 0x0;
1821 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1822 v = (AliDCSValue *)array->At(iCount);
1823 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1824 AliError(Form("DCS values for the parameter outside the queried interval"));
1828 if (aDCSBool != v->GetBool()) {
1829 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1833 aDCSBool = v->GetBool(); // always keeping last value
1834 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1837 Char_t caDCSBool = (Char_t) aDCSBool;
1842 //_______________________________________________________________
1844 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1847 // processing Int values, returning mean
1848 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1849 // are outside the queried time interval or their value is out of range
1852 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1853 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1854 if (timeStartString.IsNull() || timeStartString.IsNull()){
1855 if (timeStartString.IsNull()){
1856 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1858 else if (timeStartString.IsNull()){
1859 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1864 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1865 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1866 Float_t aDCSArrayMean = 0.0;
1868 Float_t valueBeforeSOR = 0;
1869 Float_t valueAfterEOR = 0;
1870 Int_t timestampBeforeSOR = -1;
1871 Int_t timestampAfterEOR = -1;
1872 Int_t ientrySOR = -1;
1873 Int_t ientryEOR = -1;
1874 Float_t* arrayValues = 0x0;
1875 Double_t* arrayWeights = 0x0;
1876 Int_t iCountsRun = 0;
1877 Int_t nCounts = array->GetEntries();
1879 for(Int_t i = 0; i < nCounts; i++) {
1880 AliDCSValue* v = (AliDCSValue *)array->At(i);
1881 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1882 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1883 return AliGRPObject::GetInvalidFloat();
1885 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1886 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1888 // look for the last value before SOR and the first value before EOR
1889 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1890 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1891 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1892 valueBeforeSOR = (Float_t) v->GetInt();
1894 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1895 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1896 valueAfterEOR = (Float_t) v->GetInt();
1897 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1899 // check if there are DPs between DAQ_time_start and DAQ_time_end
1900 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1901 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1902 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1903 AliDebug(2,Form("entry between SOR and EOR"));
1908 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1912 if (timestampBeforeSOR == -1){
1913 AliWarning("No value found before SOR!");
1915 if (timestampAfterEOR == -1){
1916 AliWarning("No value found after EOR!");
1919 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1920 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1921 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1922 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1923 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1924 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1926 Int_t nentriesUsed = 0;
1927 if (iCountsRun > 1){
1928 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1929 AliDebug(2,"Calculating (weighted) Mean");
1930 arrayValues = new Float_t[iCountsRun];
1931 arrayWeights = new Double_t[iCountsRun];
1932 nentriesUsed = iCountsRun;
1933 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1934 AliDCSValue *v = (AliDCSValue *)array->At(i);
1935 Int_t timestamp2 = 0;
1937 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1938 timestamp2 = (Int_t)v1->GetTimeStamp();
1941 timestamp2 = timeEnd+1;
1943 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1944 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1946 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1948 else if (iCountsRun == 1){
1949 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1951 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1952 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1953 arrayValues = new Float_t[2];
1954 arrayWeights = new Double_t[2];
1955 arrayValues[0] = valueBeforeSOR;
1956 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1957 arrayValues[1] = (Float_t)v->GetInt();
1958 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1959 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1960 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1961 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1964 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1965 return AliGRPObject::GetInvalidFloat();
1968 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1969 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1970 if (timestampBeforeSOR == -1){
1971 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1973 if (timestampAfterEOR == -1){
1974 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1976 return AliGRPObject::GetInvalidFloat();
1979 AliWarning("Using last entry before SOR and first entry after EOR.");
1981 arrayValues = new Float_t[2];
1982 arrayWeights = new Double_t[2];
1983 arrayValues[0] = valueBeforeSOR;
1984 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1985 arrayValues[1] = valueAfterEOR;
1986 arrayWeights[1] = 1.;
1987 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1988 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1989 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1993 AliInfo(Form("mean = %f ", aDCSArrayMean));
1994 return aDCSArrayMean;
1997 //_______________________________________________________________
1999 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2002 // processing Int values, returning mean
2003 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2004 // are outside the queried time interval or their value is out of range
2007 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2008 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2009 if (timeStartString.IsNull() || timeStartString.IsNull()){
2010 if (timeStartString.IsNull()){
2011 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2013 else if (timeStartString.IsNull()){
2014 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2019 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2020 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2021 Float_t aDCSArrayMean = 0.0;
2023 Float_t valueBeforeSOR = 0;
2024 Float_t valueAfterEOR = 0;
2025 Int_t timestampBeforeSOR = -1;
2026 Int_t timestampAfterEOR = -1;
2027 Int_t ientrySOR = -1;
2028 Int_t ientryEOR = -1;
2029 Float_t* arrayValues = 0x0;
2030 Double_t* arrayWeights = 0x0;
2031 Int_t iCountsRun = 0;
2032 Int_t nCounts = array->GetEntries();
2034 for(Int_t i = 0; i < nCounts; i++) {
2035 AliDCSValue* v = (AliDCSValue *)array->At(i);
2036 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2037 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2038 return AliGRPObject::GetInvalidFloat();
2040 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2041 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2043 // look for the last value before SOR and the first value before EOR
2044 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2045 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2046 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2047 valueBeforeSOR = (Float_t)v->GetUInt();
2049 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2050 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2051 valueAfterEOR = (Float_t)v->GetUInt();
2052 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2054 // check if there are DPs between DAQ_time_start and DAQ_time_end
2055 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2056 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2057 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2058 AliDebug(2,Form("entry between SOR and EOR"));
2063 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2067 if (timestampBeforeSOR == -1){
2068 AliWarning("No value found before SOR!");
2070 if (timestampAfterEOR == -1){
2071 AliWarning("No value found after EOR!");
2074 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2075 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2076 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2077 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2078 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2079 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2081 Int_t nentriesUsed = 0;
2082 if (iCountsRun > 1){
2083 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2084 AliDebug(2,"Calculating (weighted) Mean");
2085 arrayValues = new Float_t[iCountsRun];
2086 arrayWeights = new Double_t[iCountsRun];
2087 nentriesUsed = iCountsRun;
2088 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2089 AliDCSValue *v = (AliDCSValue *)array->At(i);
2090 Int_t timestamp2 = 0;
2092 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2093 timestamp2 = (Int_t)v1->GetTimeStamp();
2096 timestamp2 = timeEnd+1;
2098 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2099 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2101 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2103 else if (iCountsRun == 1){
2104 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2106 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2107 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2108 arrayValues = new Float_t[2];
2109 arrayWeights = new Double_t[2];
2110 arrayValues[0] = valueBeforeSOR;
2111 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2112 arrayValues[1] = (Float_t)v->GetUInt();
2113 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2114 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2115 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2116 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2119 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2120 return AliGRPObject::GetInvalidFloat();
2123 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2124 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2125 if (timestampBeforeSOR == -1){
2126 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2128 if (timestampAfterEOR == -1){
2129 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2131 return AliGRPObject::GetInvalidFloat();
2134 AliWarning("Using last entry before SOR and first entry after EOR.");
2136 arrayValues = new Float_t[2];
2137 arrayWeights = new Double_t[2];
2138 arrayValues[0] = valueBeforeSOR;
2139 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2140 arrayValues[1] = valueAfterEOR;
2141 arrayWeights[1] = 1.;
2142 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2143 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2144 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2148 AliInfo(Form("mean = %f ",aDCSArrayMean));
2149 return aDCSArrayMean;
2154 //_______________________________________________________________
2156 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2158 // extract DCS pressure maps. Perform fits to save space
2160 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2162 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2163 fPressure->MakeSplineFit(map);
2164 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2165 if (fitFraction > kFitFraction ) {
2166 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2168 AliInfo("Too few pressure maps fitted!!!");
2171 AliInfo("no atmospheric pressure map extracted!!!");
2180 //_______________________________________________________________
2181 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)
2184 // Retrieves logbook and trigger information from the online logbook
2185 // This information is needed for prompt reconstruction
2189 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2193 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2194 // 0 on success and no run was found
2195 // negative on error
2197 // This function is NOT called during the preprocessor run in the Shuttle!
2205 AliCDBManager* cdb = AliCDBManager::Instance();
2206 cdb->SetDefaultStorage(cdbRoot);
2209 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2213 Printf("ERROR: Could not connect to DAQ LB");
2219 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2220 TSQLResult* result = server->Query(sqlQuery);
2223 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2227 if (result->GetRowCount() == 0)
2229 Printf("ERROR: Run %d not found", run);
2234 TSQLRow* row = result->Next();
2237 Printf("ERROR: Could not receive data from run %d", run);
2242 TString timeStartString(row->GetField(0));
2243 TString runType(row->GetField(1));
2244 TString detectorMaskString(row->GetField(2));
2245 TString l3CurrentString(row->GetField(3));
2246 TString dipoleCurrentString(row->GetField(4));
2247 time_t timeStart = (time_t)(timeStartString.Atoi());
2248 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2249 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2250 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2251 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2252 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2254 AliGRPObject * grpObj = new AliGRPObject();
2255 grpObj->SetTimeStart(timeStart);
2256 grpObj->SetRunType((TString)(row->GetField(1)));
2257 grpObj->SetDetectorMask(detectorMask);
2258 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2259 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2260 grpObj->SetL3Polarity(l3Polarity);
2261 grpObj->SetDipolePolarity(dipolePolarity);
2262 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2270 Printf("Storing GRP/GRP/Data object with the following content");
2273 AliCDBMetaData metadata;
2274 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2275 metadata.SetComment("GRP Output parameters received during online running");
2277 AliCDBId id("GRP/GRP/Data", run, run);
2278 Bool_t success = cdb->Put(grpObj, id, &metadata);
2284 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2288 // Receive trigger information
2289 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2290 result = server->Query(sqlQuery);
2293 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2297 if (result->GetRowCount() == 0)
2299 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2304 row = result->Next();
2307 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2312 TString triggerConfig(row->GetField(0));
2320 Printf("Found trigger configuration: %s", triggerConfig.Data());
2322 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2325 Printf("ERROR: Could not create CTP configuration object");
2329 metadata.SetComment("CTP run configuration received during online running");
2331 AliCDBId id2("GRP/CTP/Config", run, run);
2332 success = cdb->Put(runcfg, id2, &metadata);
2339 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2344 // Receive list of GDCs for this run
2345 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2346 result = server->Query(sqlQuery);
2349 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2353 if (result->GetRowCount() == 0)
2355 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2361 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2362 row = result->Next();
2365 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2369 gdc += row->GetField(0);
2379 Printf("Found GDC: %s", gdc.Data());
2381 // get last run with same run type that was already processed by the SHUTTLE
2383 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());
2384 result = server->Query(sqlQuery);
2387 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2391 if (result->GetRowCount() == 0)
2393 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2398 row = result->Next();
2401 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2406 TString lastRunStr(row->GetField(0));
2407 Int_t lastRun = lastRunStr.Atoi();
2409 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2423 //-----------------------------------------------------------------
2424 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* array){
2427 // Calculating mean over TObjArray from LHC Data
2430 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2431 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2432 if (timeStartString.IsNull() || timeStartString.IsNull()){
2433 if (timeStartString.IsNull()){
2434 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2436 else if (timeStartString.IsNull()){
2437 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2442 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2443 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2444 timeStart = 1260646960;
2445 timeEnd = 1260652740;
2446 Double_t* parameters = new Double_t[5];
2447 parameters[0] = -1.;
2448 parameters[1] = -1.;
2449 parameters[2] = -1.;
2450 parameters[3] = -1.;
2451 parameters[4] = -1.;
2453 Int_t iCountsRun = 0;
2454 Int_t nCounts = array->GetEntries();
2455 printf("ncounts = %d\n",nCounts);
2456 Double_t valueBeforeSOR = 0;
2457 Double_t valueAfterEOR = 0;
2458 Double_t timestampBeforeSOR = -1.;
2459 Double_t timestampAfterEOR = -1.;
2460 Int_t ientrySOR = -1;
2461 Int_t ientryEOR = -1;
2462 Double_t* arrayValues = 0x0;
2463 Double_t* arrayWeights = 0x0;
2464 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2465 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2467 for(Int_t i = 0; i < nCounts; i++) {
2468 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2469 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2470 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2472 // look for the last value before SOR and the first value before EOR
2473 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2474 timestampBeforeSOR = dcs->GetTimeStamp();
2475 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2476 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2478 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2479 timestampAfterEOR = dcs->GetTimeStamp();
2480 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2481 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2483 // check if there are DPs between DAQ_time_start and DAQ_time_end
2484 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2485 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2486 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2487 AliDebug(2,Form("entry between SOR and EOR\n"));
2492 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2496 if (timestampBeforeSOR == -1.){
2497 printf("No value found before SOR\n");
2499 if (timestampAfterEOR == -1.){
2500 printf("No value found after EOR\n");
2503 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2504 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2505 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2506 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2507 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2508 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2510 Int_t nentriesUsed = 0;
2511 if (iCountsRun > 1){
2512 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2513 printf("Calculating (weighted) Mean and Median\n" );
2514 arrayValues = new Double_t[iCountsRun];
2515 arrayWeights = new Double_t[iCountsRun];
2516 nentriesUsed = iCountsRun;
2517 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2518 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2519 Double_t timestamp2 = 0;
2521 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2522 timestamp2 = dcs1->GetTimeStamp();
2525 timestamp2 = (Double_t)timeEnd+1;
2527 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2528 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2529 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2531 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2532 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2534 else if (iCountsRun == 1){
2535 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2537 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2538 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");
2539 arrayValues = new Double_t[2];
2540 arrayWeights = new Double_t[2];
2541 arrayValues[0] = valueBeforeSOR;
2542 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2543 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2544 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2545 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2546 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2547 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2548 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2549 truncMeanFlag = kFALSE;
2552 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");
2558 return parameters[0];
2561 else { // iCountsRun == 0, using only the point immediately before SOR
2562 if (timestampBeforeSOR == -1.){
2563 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");
2569 return parameters[0];
2572 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2573 printf("value = %f\n",valueBeforeSOR);
2574 parameters[0] = valueBeforeSOR;
2575 parameters[2] = valueBeforeSOR;
2576 truncMeanFlag = kFALSE;
2583 Double_t sumweights = 0;
2584 Int_t entriesTruncMean = 0;
2585 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2586 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2588 // calculating SD wrt Mean and Median
2589 printf("Calculating SD wrt Mean and SD wrt Median\n");
2591 for (Int_t i =0; i< nentriesUsed; i++){
2592 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2593 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2594 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2595 sumweights += arrayWeights[i];
2597 // setting SD wrt Mean
2598 if (sumweights != 0 ){
2599 parameters[3] = TMath::Sqrt(temp1/sumweights);
2602 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2605 // setting SD wrt Median
2606 if (nentriesUsed != 0){
2607 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2610 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2619 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2621 printf("Calculating Truncated Mean\n");
2622 for (Int_t i =0; i< nentriesUsed; i++){
2623 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2624 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2625 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2626 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2627 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2631 printf("Discarding entry\n");
2634 // setting truncated mean
2635 if (entriesTruncMean >1){
2636 printf("%d entries used for truncated mean\n",entriesTruncMean);
2637 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2640 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2648 printf("(weighted) mean = %f \n",parameters[0]);
2649 printf("(weighted) truncated mean = %f \n",parameters[1]);
2650 printf("median = %f \n",parameters[2]);
2651 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2652 printf("standard deviation with median = %f \n",parameters[4]);
2654 return (parameters[0]);
2656 //------------------------------------------------------------------------------------------------------
2657 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* array, Double_t timeStart, Double_t timeEnd){
2660 // Method to processo LHC Energy information
2661 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2664 Int_t nCounts = array->GetEntries();
2665 Float_t energy = -1;
2666 Bool_t inRange = kFALSE;
2667 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2669 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2672 for(Int_t i = 0; i < nCounts; i++) {
2673 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2674 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2675 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2676 AliInfo(Form("Energy value found = %d, converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),energy));
2681 if (inRange == kFALSE){
2682 AliInfo("No Energy value found between DAQ_time_start and DAQ_time_end - energy will remain invalid!");