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 = 4; // 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 "LHC_Beams_Particle_Type"
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 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
523 Log("*************** Processing LHC Data");
525 UInt_t iLHCData = ProcessLHCData(grpobj);
527 if( iLHCData == 0 ) {
528 Log(Form("LHC Data from DCS FXS, successful!"));
529 } else if (iLHCData == 1) {
530 Log(Form("LHC Data, problems with DCS FXS!"));
532 } else if (iLHCData ==3){
533 Log(Form("Problems in storing LHC Data - but not going into Error"));
534 } else if (iLHCData ==4){
535 Log(Form("Problems with LHC Data to be put in /GRP/GRP/LHCData - but not going into Error"));
537 Log(Form("LHC Data problems"));
543 //==================//
544 // SPD Mean Vertex //
545 //==================//
547 Log("*************** Processing SPD Mean Vertex");
549 if (runType == "PHYSICS"){
550 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
551 if( iSPDMeanVertex == 1 ) {
552 Log(Form("SPD Mean Vertex, successful!"));
554 Log(Form("SPD Mean Vertex failed!!!"));
559 Log("SPD Mean Vertex not processed since runType != PHYSICS");
562 // storing AliGRPObject in OCDB
565 md.SetResponsible("Chiara Zampolli");
566 md.SetComment("Output parameters from the GRP preprocessor.");
568 Bool_t result = kTRUE;
569 result = Store("GRP", "Data", grpobj, &md);
572 if (result && !error ) {
573 Log("GRP Preprocessor Success");
576 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s",
577 kppError[(error&1)?1:0],
578 kppError[(error&2)?2:0],
579 kppError[(error&4)?3:0],
580 kppError[(error&8)?4:0],
581 kppError[(error&16)?5:0],
582 kppError[(error&32)?6:0],
583 kppError[(error&64)?7:0],
584 kppError[(error&128)?8:0],
585 kppError[(error&256)?9:0],
586 kppError[(error&512)?10:0]
594 //_______________________________________________________________
596 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
599 //Getting the LHC Data from DCS FXS
602 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
603 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
604 if (timeStartString.IsNull() || timeEndString.IsNull()){
605 if (timeStartString.IsNull()){
606 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
608 else if (timeEndString.IsNull()){
609 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
614 Double_t timeStart = timeStartString.Atof();
615 Double_t timeEnd = timeEndString.Atof();
617 TString fileName = GetFile(kDCS, "LHCData","");
618 if (fileName.Length()>0){
619 AliInfo("Got The LHC Data file");
620 AliLHCReader lhcReader;
622 // Processing data to be put in AliGRPObject
625 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
627 Float_t energy = ProcessEnergy(energyArray,timeStart,timeEnd);
629 grpobj->SetBeamEnergy(energy);
630 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
635 AliError("Energy not found in LHC Data file!!!");
638 Double_t timeBeamMode = 0;
639 Double_t timeMachineMode = 0;
640 Double_t timeBeam = 0;
641 Bool_t flagBeamMode = kFALSE; //flag set true if at least one BeamMode measurement is found within DAQ_time_start and DAQ_time_end
642 Bool_t flagMachineMode = kFALSE; //flag set true if at least one MachineMode measurement is found within DAQ_time_start and DAQ_time_end
643 Bool_t flagBeam = kFALSE; //flag set true if at least one Beam Type measurement is found within DAQ_time_start and DAQ_time_end
646 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
647 Int_t nBeamMode = -1;
649 nBeamMode = beamModeArray->GetEntries();
651 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
655 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(0);
656 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
657 TObjString* beamModeString = beamMode->GetStringArray(0);
658 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
659 grpobj->SetLHCState(beamModeString->String());
662 AliInfo("No Beam Mode found within DAQ_time_start and DAQ_time_end, leaving it empty");
666 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
667 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
668 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
669 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(iBeamMode+1);
670 if (beamMode1->GetTimeStamp()>=timeStart && beamMode1->GetTimeStamp()<=timeEnd){
671 timeBeamMode = beamMode1->GetTimeStamp();
672 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));
674 TObjString* beamModeString = beamMode->GetStringArray(0);
675 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
676 grpobj->SetLHCState(beamModeString->String());
677 flagBeamMode = kTRUE;
682 AliError("Found values for BeamMode, but none within DAQ_time_start and DAQ_time_end, leaving it empty");
686 delete beamModeArray;
689 AliError("Beam mode array not found in LHC Data file!!!");
693 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
694 Int_t nMachineMode = -1;
695 if (machineModeArray){
696 nMachineMode = machineModeArray->GetEntries();
697 if (nMachineMode==0){
698 AliInfo("No Machine Mode found, leaving it empty");
701 if (nMachineMode ==1) {
702 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(0);
703 if (machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
704 TObjString* machineModeString = machineMode->GetStringArray(0);
705 AliInfo(Form("Machine Mode = %s",(machineModeString->String()).Data()));
706 grpobj->SetMachineMode(machineModeString->String());
709 AliInfo("No Machine Mode found within DAQ_time_start and DAQ_time_end, leaving it empty");
713 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
714 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
715 if (machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
716 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(iMachineMode+1);
717 if (machineMode1->GetTimeStamp()>=timeStart && machineMode1->GetTimeStamp()<=timeEnd){
718 timeMachineMode = machineMode1->GetTimeStamp();
719 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));
721 TObjString* machineModeString = machineMode->GetStringArray(0);
722 AliInfo(Form("Machine mode = %s",(machineModeString->String()).Data()));
723 grpobj->SetMachineMode(machineModeString->String());
724 flagMachineMode = kTRUE;
728 if (!flagMachineMode){
729 AliError("Found values for MachineMode, but none within DAQ_time_start and DAQ_time_end, setting MachineMode to UNKNOWN");
730 grpobj->SetMachineMode("UNKONWN");
734 delete machineModeArray;
737 AliError("Machine mode array not found in LHC Data file!!!");
740 // BeamType1 and BeamType2 - both put in the same string
741 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
743 Int_t nBeam = beamArray->GetEntries();
745 AliInfo("No Beam Type found, leaving it empty");
749 AliDCSArray* beam = (AliDCSArray*)beamArray->At(0);
750 if (beam->GetTimeStamp()>=timeStart && beam->GetTimeStamp()<=timeEnd){
751 TObjString* beamString = beam->GetStringArray(0);
752 TString beamType = beamString->String();
753 AliInfo(Form("Beam Type = %s",beamType.Data()));
754 if (beamType.CompareTo("PROTON",TString::kIgnoreCase)){
755 grpobj->SetBeamType("p-p");
757 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase)){
758 grpobj->SetBeamType("Pb-Pb");
761 AliError("Beam Type not known, leaving it empty");
765 AliInfo("No Beam Type found within DAQ_time_start and DAQ_time_end, leaving it empty");
769 for (Int_t iBeam=0; iBeam<nBeam; iBeam++){
770 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
771 if (beam->GetTimeStamp()>=timeStart && beam->GetTimeStamp()<=timeEnd){
772 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(iBeam+1);
773 if (beam1->GetTimeStamp()>=timeStart && beam1->GetTimeStamp()<=timeEnd){
774 timeBeam = beam1->GetTimeStamp();
775 AliWarning(Form("The Beam Type changed at timestamp %f! Setting it to the first value found and keeping track of the time of the change to set MaxTimeLHCValidity afterwards",timeBeam));
777 TObjString* beamString = beam->GetStringArray(0);
778 TString beamType = beamString->String();
779 AliInfo(Form("Beam Type = %s",beamType.Data()));
780 if (beamType.CompareTo("PROTON",TString::kIgnoreCase)){
781 grpobj->SetBeamType("p-p");
783 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase)){
784 grpobj->SetBeamType("Pb-Pb");
787 AliError("Beam Type not known, leaving it empty");
794 AliError("Found values for Beam Type, but none within DAQ_time_start and DAQ_time_end, leaving it empty");
801 AliError("BeamType array not found in LHC data file!!!");
804 // Setting minTimeLHCValidity
805 if (timeBeamMode!=0 || timeMachineMode!=0 || timeBeam !=0){
806 Double_t minTimeLHCValidity;
807 if (timeBeamMode == 0 && timeMachineMode == 0 && timeBeam != 0){ // timeBeam only != 0
808 minTimeLHCValidity = timeBeam;
810 else if (timeBeamMode == 0 && timeMachineMode != 0 && timeBeam == 0){ // timeMachineMode only != 0
811 minTimeLHCValidity = timeMachineMode;
813 else if (timeBeamMode != 0 && timeMachineMode == 0 && timeBeam == 0){ // timeBeamMode only != 0
814 minTimeLHCValidity = timeBeamMode;
816 else if (timeBeamMode == 0 && timeMachineMode != 0 && timeBeam != 0){ // timeBeam and timeMachineMode only != 0
817 minTimeLHCValidity= TMath::Min(timeBeam,timeMachineMode);
819 else if (timeBeamMode != 0 && timeMachineMode == 0 && timeBeam != 0){ // timeBeam and timeBeamMode only != 0
820 minTimeLHCValidity= TMath::Min(timeBeam,timeBeamMode);
822 else if (timeBeamMode != 0 && timeMachineMode != 0 && timeBeam == 0){ // timeMachineMode and timeBeamMode only != 0
823 minTimeLHCValidity= TMath::Min(timeMachineMode,timeBeamMode);
826 Double_t arrayTimes[3] = {timeBeamMode,timeMachineMode,timeBeam};
827 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
829 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
830 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
833 // Processing data to go to AliLHCData object
834 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
835 // storing AliLHCData in OCDB
837 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
839 md.SetResponsible("Ruben Shahoyan");
840 md.SetComment("LHC data from the GRP preprocessor.");
841 Bool_t result = kTRUE;
842 result = Store("GRP", "LHCData", dt, &md);
844 if (result) return 0;
850 AliError("No LHCData file found in DCS FXS");
856 //_______________________________________________________________
858 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
861 //Getting the SPD Mean Vertex
864 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
865 Bool_t storeResult = kTRUE;
866 if (list !=0x0 && list->GetEntries()!=0)
868 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
870 for (Int_t jj=0;jj<list->GetEntries();jj++){
871 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
872 AliInfo(Form("found source %s", str->String().Data()));
873 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
874 if (fileNameRun.Length()>0){
875 AliInfo(Form("Got the file %s", fileNameRun.Data()));
876 TFile daqFile(fileNameRun.Data(),"READ");
877 if (daqFile.IsOpen()) {
878 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
881 // storing in the OCDB
883 md.SetResponsible("Cvetan Cheshkov");
884 md.SetComment("SPD Mean Vertex");
885 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
888 AliWarning("No SPD Mean Vertex object found in file");
892 AliError("Can't open file");
893 storeResult = kFALSE;
897 AliWarning("No file found for current source for SPD Mean Vertex");
902 AliWarning("No list found for SPD Mean Vertex");
905 if (list) delete list;
911 //_______________________________________________________________
913 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
915 //Getting the DAQ lb information
917 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
918 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
919 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
920 TString beamType = (TString)GetRunParameter("beamType");
921 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
922 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
923 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
924 TString runType = (TString)GetRunType();
926 UInt_t nparameter = 0;
928 grpObj->SetTimeStart(timeStart);
929 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
933 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
937 grpObj->SetTimeEnd(timeEnd);
938 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
942 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
945 if (beamEnergy != 0){
946 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
949 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
953 if (beamType.Length() != 0){
954 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()));
957 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
960 if (numberOfDetectors != 0){
961 grpObj->SetNumberOfDetectors(numberOfDetectors);
962 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
966 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
969 if (detectorMask != 0){
970 grpObj->SetDetectorMask(detectorMask);
971 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
975 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
978 if (lhcPeriod.Length() != 0) {
979 grpObj->SetLHCPeriod(lhcPeriod);
980 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
984 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
986 if (runType.Length() != 0) {
987 grpObj->SetRunType(runType);
988 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
992 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
998 //_______________________________________________________________
1000 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1002 //======DAQ FXS======//
1004 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1005 TList* list = GetFileSources(kDAQ);
1007 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1011 if (list->GetEntries() == 0) {
1012 Log("no raw data tags in this run: nothing to merge!");
1013 delete list; list=0;
1017 TChain *fRawTagChain = new TChain("T");
1019 TIterator* iter = list->MakeIterator();
1021 while ((obj = iter->Next())) {
1022 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1024 Log(Form("Found source %s", objStr->String().Data()));
1025 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1027 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1028 delete fRawTagChain; fRawTagChain=0;
1031 Log(Form("Number of ids: %d",list2->GetEntries()));
1032 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1033 TObjString *idStr = (TObjString *)list2->At(i);
1034 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1035 if (fileName.Length() > 0) {
1036 Log(Form("Adding file in the chain: %s",fileName.Data()));
1037 fRawTagChain->Add(fileName.Data());
1040 Log(Form("Could not retrieve file with id %s from source %s: "
1041 "connection problems with DAQ FXS!",
1042 idStr->String().Data(), objStr->String().Data()));
1043 delete list; list=0;
1044 delete list2; list2=0;
1045 delete fRawTagChain; fRawTagChain=0;
1053 TString fRawDataFileName = "GRP_Merged.tag.root";
1054 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1056 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1057 Log("Error merging raw data files!!!");
1061 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1062 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1065 Log("Problem storing raw data tags in local file!!!");
1067 Log("Raw data tags merged successfully!!");
1072 delete fRawTagChain; fRawTagChain=0;
1074 if (result == kFALSE) {
1082 //_______________________________________________________________
1083 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1086 // processing the info
1087 // stored in the DCS FXS
1088 // coming from the trigger
1090 // Get the CTP counters information
1092 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1093 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1094 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1096 Log(Form("No dummy CTP scalers entry found, going into error..."));
1100 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1102 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1106 AliCDBMetaData metaData;
1107 metaData.SetResponsible("Roman Lietava");
1108 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1109 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1110 Log("Unable to store the dummy CTP scalers object to OCDB!");
1117 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1118 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1119 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1120 if (countersfile.IsNull()) {
1121 Log("No CTP counters files has been found: empty source!");
1125 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1126 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1128 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1132 AliCDBMetaData metaData;
1133 metaData.SetBeamPeriod(0);
1134 metaData.SetResponsible("Roman Lietava");
1135 metaData.SetComment("CTP scalers");
1136 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1137 Log("Unable to store the CTP scalers object to OCDB!");
1148 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1155 //_______________________________________________________________
1157 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1161 // processing DCS DPs
1164 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1165 Int_t nL3Entries = 0;
1166 Int_t nDipoleEntries = 0;
1167 Int_t nEnvEntries = 0;
1168 Int_t nHallProbesEntries = 0;
1169 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1170 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1171 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1172 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1173 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1174 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1175 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1180 //_______________________________________________________________
1182 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1189 Int_t nL3Entries = 0;
1191 TObjArray *array = 0x0;
1193 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1195 AliInfo(Form("==========L3Current==========="));
1196 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1197 indexDP = kL3Current;
1198 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1200 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1203 if (array->GetEntries() == 0){
1204 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1207 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1208 if (floatDCS != NULL){
1209 grpObj->SetL3Current(floatDCS);
1221 ffailedDPs->RemoveAt(indexDP);
1225 if (array) array = 0x0;
1227 AliInfo(Form("==========L3Polarity==========="));
1228 indexDP = kL3Polarity;
1229 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1231 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1234 if (array->GetEntries() == 0){
1235 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1238 Bool_t change = kFALSE;
1239 Char_t charDCS = ProcessBool(array,change);
1240 if (change == kFALSE){
1241 grpObj->SetL3Polarity(charDCS);
1242 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1243 ffailedDPs->RemoveAt(indexDP);
1247 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1248 ffailedDPs->RemoveAt(indexDP);
1252 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]));
1260 //_______________________________________________________________
1262 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1268 Int_t nDipoleEntries = 0;
1269 TObjArray *array = 0x0;
1271 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1273 AliInfo(Form("==========DipoleCurrent==========="));
1274 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1275 indexDP = kDipoleCurrent;
1276 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1278 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1281 if (array->GetEntries() == 0){
1282 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1285 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1286 if (floatDCS != NULL){
1287 grpObj->SetDipoleCurrent(floatDCS);
1299 ffailedDPs->RemoveAt(indexDP);
1303 if (array) array = 0x0;
1305 AliInfo(Form("==========DipolePolarity==========="));
1306 indexDP = kDipolePolarity;
1307 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1309 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1312 if (array->GetEntries() == 0){
1313 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1316 Bool_t change = kFALSE;
1317 Char_t charDCS = ProcessBool(array,change);
1319 grpObj->SetDipolePolarity(charDCS);
1320 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1321 ffailedDPs->RemoveAt(indexDP);
1325 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1326 ffailedDPs->RemoveAt(indexDP);
1330 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]));
1335 return nDipoleEntries;
1338 //_______________________________________________________________
1340 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1344 // evironment conditions (temperature, pressure) info
1346 Int_t nEnvEntries = 0;
1347 TObjArray *array = 0x0;
1350 AliInfo(Form("==========CavernTemperature==========="));
1351 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1352 indexDP = kCavernTemperature;
1353 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1355 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1358 if (array->GetEntries() == 0){
1359 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1362 Float_t *floatDCS = ProcessFloatAll(array);
1363 if (floatDCS != NULL){
1364 grpObj->SetCavernTemperature(floatDCS);
1375 ffailedDPs->RemoveAt(indexDP);
1380 if (array) array = 0x0;
1382 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1383 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1384 //dcsSensorArray->Print();
1385 if( fPressure->NumFits()<kNumSensors ) {
1386 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1388 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1390 AliInfo(Form("==========CavernAtmosPressure==========="));
1391 indexDP = kCavernAtmosPressure;
1392 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1393 TGraph* graph = sensorCavernP2->GetGraph();
1394 AliDebug(3,Form("index = %d",indexDP));
1395 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1396 AliDebug(2,Form("graph = %p",graph));
1397 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1398 if(sensorCavernP2->GetFit() || graph) {
1399 if (sensorCavernP2->GetFit()){
1400 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1403 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1405 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1406 ffailedDPs->RemoveAt(indexDP);
1409 //if (sensorP2) delete sensorP2;
1411 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] ));
1414 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1415 indexDP = kSurfaceAtmosPressure;
1416 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1417 graph = sensorP2->GetGraph();
1418 AliDebug(3,Form("index = %d",indexDP));
1419 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1420 AliDebug(2,Form("graph = %p",graph));
1421 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1422 if(sensorP2->GetFit() || graph) {
1423 if (sensorP2->GetFit()){
1424 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1427 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1429 grpObj->SetSurfaceAtmosPressure(sensorP2);
1430 ffailedDPs->RemoveAt(indexDP);
1433 //if (sensorP2) delete sensorP2;
1435 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] ));
1438 AliInfo(Form("==========CavernAtmosPressure2==========="));
1439 indexDP = kCavernAtmosPressure2;
1440 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1441 graph = sensorCavernP22->GetGraph();
1442 AliDebug(3,Form("index = %d",indexDP));
1443 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1444 AliDebug(2,Form("graph = %p",graph));
1445 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1446 if(sensorCavernP22->GetFit() || graph) {
1447 if (sensorCavernP22->GetFit()){
1448 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1451 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1453 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1454 ffailedDPs->RemoveAt(indexDP);
1457 //if (sensorP2) delete sensorP2;
1459 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] ));
1465 //_______________________________________________________________
1467 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1473 Int_t nHPEntries = 0;
1474 TObjArray *array = 0x0;
1476 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1478 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1479 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()));
1481 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1482 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1483 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1484 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1486 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1489 if (array->GetEntries() == 0){
1490 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1493 Float_t *floatDCS = ProcessFloatAll(array);
1494 if (floatDCS != NULL){
1495 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]));
1496 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1497 for (Int_t kk = 0 ; kk< 5; kk++){
1498 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1510 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1516 Log(Form("Hall Probes = %d ", nHPEntries));
1520 //_________________________________________________________________________
1522 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1526 // returning Spline Fit
1529 Int_t entriesarray = array->GetEntries();
1530 Float_t* value = new Float_t[entriesarray];
1531 Float_t* time = new Float_t[entriesarray];
1532 AliDCSValue* v = 0x0;
1533 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1534 v = (AliDCSValue*)array->At(iarray);
1535 value[iarray] = v->GetFloat();
1536 time[iarray] = v->GetTimeStamp();
1537 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1539 TGraph* gr = new TGraph(entriesarray,value,time);
1541 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1544 AliSplineFit *fit = new AliSplineFit();
1545 fit->SetMinPoints(10);
1546 fit->InitKnots(gr,10,10,0.0);
1550 AliWarning(Form("%s: no fit performed",stringID.Data()));
1556 //_________________________________________________________________________
1558 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1565 TString aDCSString="";
1567 AliDCSValue *v = 0x0;
1568 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1569 v = (AliDCSValue *)array->At(iCount);
1570 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1571 AliError(Form("DCS values for the parameter outside the queried interval"));
1575 if (aDCSString != v->GetChar())
1576 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1578 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1583 //__________________________________________________________________________________________________________________
1585 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1588 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1590 // parameters[0] = mean
1591 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1592 // parameters[2] = median
1593 // parameters[3] = standard deviation wrt mean
1594 // parameters[4] = standard deviation wrt median
1597 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1598 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1599 if (timeStartString.IsNull() || timeStartString.IsNull()){
1600 if (timeStartString.IsNull()){
1601 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1603 else if (timeStartString.IsNull()){
1604 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1606 fdaqStartEndTimeOk = kFALSE;
1610 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1611 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1612 Float_t* parameters = new Float_t[5];
1614 Int_t iCountsRun = 0;
1615 Int_t nCounts = array->GetEntries();
1616 Float_t valueBeforeSOR = 0;
1617 Float_t valueAfterEOR = 0;
1618 Int_t timestampBeforeSOR = -1;
1619 Int_t timestampAfterEOR = -1;
1620 Int_t ientrySOR = -1;
1621 Int_t ientryEOR = -1;
1622 Float_t* arrayValues = 0x0;
1623 Double_t* arrayWeights = 0x0;
1624 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1625 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1627 for(Int_t i = 0; i < nCounts; i++) {
1628 AliDCSValue *v = (AliDCSValue *)array->At(i);
1629 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1630 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1631 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1632 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1635 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1636 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1638 // look for the last value before SOR and the first value before EOR
1639 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1640 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1641 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1642 valueBeforeSOR = v->GetFloat();
1644 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1645 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1646 valueAfterEOR = v->GetFloat();
1647 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1649 // check if there are DPs between DAQ_time_start and DAQ_time_end
1650 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1651 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1652 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1653 AliDebug(2,Form("entry between SOR and EOR"));
1658 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1662 if (timestampBeforeSOR == -1){
1663 AliWarning("No value found before SOR");
1665 if (timestampAfterEOR == -1){
1666 AliWarning("No value found after EOR");
1669 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1670 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1671 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1672 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1673 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1674 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1676 Int_t nentriesUsed = 0;
1677 if (iCountsRun > 1){
1678 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1679 AliDebug(2,"Calculating (weighted) Mean and Median");
1680 arrayValues = new Float_t[iCountsRun];
1681 arrayWeights = new Double_t[iCountsRun];
1682 nentriesUsed = iCountsRun;
1683 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1684 AliDCSValue *v = (AliDCSValue *)array->At(i);
1685 Int_t timestamp2 = 0;
1687 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1688 timestamp2 = (Int_t)v1->GetTimeStamp();
1691 timestamp2 = timeEnd+1;
1693 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1694 arrayValues[i-ientrySOR] = v->GetFloat();
1696 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1697 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1699 else if (iCountsRun == 1){
1700 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1702 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1703 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.");
1704 arrayValues = new Float_t[2];
1705 arrayWeights = new Double_t[2];
1706 arrayValues[0] = valueBeforeSOR;
1707 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1708 arrayValues[1] = v->GetFloat();
1709 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1710 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1711 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1712 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1713 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1714 truncMeanFlag = kFALSE;
1717 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");
1718 parameters[0] = AliGRPObject::GetInvalidFloat();
1719 parameters[1] = AliGRPObject::GetInvalidFloat();
1720 parameters[2] = AliGRPObject::GetInvalidFloat();
1721 parameters[3] = AliGRPObject::GetInvalidFloat();
1722 parameters[4] = AliGRPObject::GetInvalidFloat();
1726 else { // iCountsRun == 0, using only the point immediately before SOR
1727 if (timestampBeforeSOR == -1){
1728 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");
1729 parameters[0] = AliGRPObject::GetInvalidFloat();
1730 parameters[1] = AliGRPObject::GetInvalidFloat();
1731 parameters[2] = AliGRPObject::GetInvalidFloat();
1732 parameters[3] = AliGRPObject::GetInvalidFloat();
1733 parameters[4] = AliGRPObject::GetInvalidFloat();
1737 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1738 AliDebug(2,Form("value = %f",valueBeforeSOR));
1739 parameters[0] = valueBeforeSOR;
1740 parameters[2] = valueBeforeSOR;
1741 truncMeanFlag = kFALSE;
1748 Float_t sumweights = 0;
1749 Int_t entriesTruncMean = 0;
1750 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1751 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1753 // calculating SD wrt Mean and Median
1754 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1756 for (Int_t i =0; i< nentriesUsed; i++){
1757 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1758 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1759 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1760 sumweights += arrayWeights[i];
1762 // setting SD wrt Mean
1763 if (sumweights != 0 ){
1764 parameters[3] = TMath::Sqrt(temp1/sumweights);
1767 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1768 parameters[3] = AliGRPObject::GetInvalidFloat();
1770 // setting SD wrt Median
1771 if (nentriesUsed != 0){
1772 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1775 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1776 parameters[4] = AliGRPObject::GetInvalidFloat();
1780 parameters[3] = AliGRPObject::GetInvalidFloat();
1781 parameters[4] = AliGRPObject::GetInvalidFloat();
1784 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1786 AliDebug(2,"Calculating Truncated Mean");
1787 for (Int_t i =0; i< nentriesUsed; i++){
1788 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1789 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1790 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1791 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1792 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1796 AliDebug(2,"Discarding entry");
1799 // setting truncated mean
1800 if (entriesTruncMean >1){
1801 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1802 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1805 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1806 parameters[1] = AliGRPObject::GetInvalidFloat();
1810 parameters[1] = AliGRPObject::GetInvalidFloat();
1813 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1814 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1815 AliInfo(Form("median = %f ",parameters[2]));
1816 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1817 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1822 //__________________________________________________________________________________________________________________
1824 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1827 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1828 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1829 // the flag is set according to the L3/Dipole current value
1830 // current threshold for L3 = 350 A (value provided by DCS)
1831 // current threshold for Dipole = 450 A (value provided by DCS)
1833 // parameters[0] = mean
1834 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1835 // parameters[2] = median
1836 // parameters[3] = standard deviation wrt mean
1837 // parameters[4] = standard deviation wrt median
1840 AliInfo(Form("indexDP = %d",indexDP));
1842 Int_t nCounts = array->GetEntries();
1843 for(Int_t i = 0; i < nCounts; i++) {
1844 AliDCSValue *v = (AliDCSValue *)array->At(i);
1845 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1846 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1847 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1848 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1851 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1852 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1853 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1854 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1857 AliError(Form("DCS values for the parameter outside the queried interval"));
1861 return ProcessFloatAll(array);
1865 //_______________________________________________________________
1867 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1870 // processing Boolean values
1873 Bool_t aDCSBool = kTRUE;
1875 AliDCSValue *v = 0x0;
1877 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1878 v = (AliDCSValue *)array->At(iCount);
1879 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1880 AliError(Form("DCS values for the parameter outside the queried interval"));
1884 if (aDCSBool != v->GetBool()) {
1885 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1889 aDCSBool = v->GetBool(); // always keeping last value
1890 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1893 Char_t caDCSBool = (Char_t) aDCSBool;
1898 //_______________________________________________________________
1900 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1903 // processing Int values, returning mean
1904 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1905 // are outside the queried time interval or their value is out of range
1908 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1909 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1910 if (timeStartString.IsNull() || timeStartString.IsNull()){
1911 if (timeStartString.IsNull()){
1912 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1914 else if (timeStartString.IsNull()){
1915 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1920 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1921 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1922 Float_t aDCSArrayMean = 0.0;
1924 Float_t valueBeforeSOR = 0;
1925 Float_t valueAfterEOR = 0;
1926 Int_t timestampBeforeSOR = -1;
1927 Int_t timestampAfterEOR = -1;
1928 Int_t ientrySOR = -1;
1929 Int_t ientryEOR = -1;
1930 Float_t* arrayValues = 0x0;
1931 Double_t* arrayWeights = 0x0;
1932 Int_t iCountsRun = 0;
1933 Int_t nCounts = array->GetEntries();
1935 for(Int_t i = 0; i < nCounts; i++) {
1936 AliDCSValue* v = (AliDCSValue *)array->At(i);
1937 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1938 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1939 return AliGRPObject::GetInvalidFloat();
1941 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1942 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1944 // look for the last value before SOR and the first value before EOR
1945 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1946 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1947 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1948 valueBeforeSOR = (Float_t) v->GetInt();
1950 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1951 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1952 valueAfterEOR = (Float_t) v->GetInt();
1953 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1955 // check if there are DPs between DAQ_time_start and DAQ_time_end
1956 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1957 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1958 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1959 AliDebug(2,Form("entry between SOR and EOR"));
1964 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1968 if (timestampBeforeSOR == -1){
1969 AliWarning("No value found before SOR!");
1971 if (timestampAfterEOR == -1){
1972 AliWarning("No value found after EOR!");
1975 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1976 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1977 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1978 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1979 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1980 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1982 Int_t nentriesUsed = 0;
1983 if (iCountsRun > 1){
1984 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1985 AliDebug(2,"Calculating (weighted) Mean");
1986 arrayValues = new Float_t[iCountsRun];
1987 arrayWeights = new Double_t[iCountsRun];
1988 nentriesUsed = iCountsRun;
1989 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1990 AliDCSValue *v = (AliDCSValue *)array->At(i);
1991 Int_t timestamp2 = 0;
1993 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1994 timestamp2 = (Int_t)v1->GetTimeStamp();
1997 timestamp2 = timeEnd+1;
1999 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2000 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2002 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2004 else if (iCountsRun == 1){
2005 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2007 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2008 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2009 arrayValues = new Float_t[2];
2010 arrayWeights = new Double_t[2];
2011 arrayValues[0] = valueBeforeSOR;
2012 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2013 arrayValues[1] = (Float_t)v->GetInt();
2014 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2015 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2016 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2017 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2020 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2021 return AliGRPObject::GetInvalidFloat();
2024 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2025 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2026 if (timestampBeforeSOR == -1){
2027 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2029 if (timestampAfterEOR == -1){
2030 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2032 return AliGRPObject::GetInvalidFloat();
2035 AliWarning("Using last entry before SOR and first entry after EOR.");
2037 arrayValues = new Float_t[2];
2038 arrayWeights = new Double_t[2];
2039 arrayValues[0] = valueBeforeSOR;
2040 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2041 arrayValues[1] = valueAfterEOR;
2042 arrayWeights[1] = 1.;
2043 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2044 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2045 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2049 AliInfo(Form("mean = %f ", aDCSArrayMean));
2050 return aDCSArrayMean;
2053 //_______________________________________________________________
2055 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2058 // processing Int values, returning mean
2059 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2060 // are outside the queried time interval or their value is out of range
2063 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2064 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2065 if (timeStartString.IsNull() || timeStartString.IsNull()){
2066 if (timeStartString.IsNull()){
2067 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2069 else if (timeStartString.IsNull()){
2070 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2075 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2076 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2077 Float_t aDCSArrayMean = 0.0;
2079 Float_t valueBeforeSOR = 0;
2080 Float_t valueAfterEOR = 0;
2081 Int_t timestampBeforeSOR = -1;
2082 Int_t timestampAfterEOR = -1;
2083 Int_t ientrySOR = -1;
2084 Int_t ientryEOR = -1;
2085 Float_t* arrayValues = 0x0;
2086 Double_t* arrayWeights = 0x0;
2087 Int_t iCountsRun = 0;
2088 Int_t nCounts = array->GetEntries();
2090 for(Int_t i = 0; i < nCounts; i++) {
2091 AliDCSValue* v = (AliDCSValue *)array->At(i);
2092 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2093 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2094 return AliGRPObject::GetInvalidFloat();
2096 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2097 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2099 // look for the last value before SOR and the first value before EOR
2100 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2101 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2102 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2103 valueBeforeSOR = (Float_t)v->GetUInt();
2105 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2106 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2107 valueAfterEOR = (Float_t)v->GetUInt();
2108 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2110 // check if there are DPs between DAQ_time_start and DAQ_time_end
2111 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2112 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2113 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2114 AliDebug(2,Form("entry between SOR and EOR"));
2119 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2123 if (timestampBeforeSOR == -1){
2124 AliWarning("No value found before SOR!");
2126 if (timestampAfterEOR == -1){
2127 AliWarning("No value found after EOR!");
2130 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2131 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2132 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2133 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2134 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2135 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2137 Int_t nentriesUsed = 0;
2138 if (iCountsRun > 1){
2139 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2140 AliDebug(2,"Calculating (weighted) Mean");
2141 arrayValues = new Float_t[iCountsRun];
2142 arrayWeights = new Double_t[iCountsRun];
2143 nentriesUsed = iCountsRun;
2144 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2145 AliDCSValue *v = (AliDCSValue *)array->At(i);
2146 Int_t timestamp2 = 0;
2148 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2149 timestamp2 = (Int_t)v1->GetTimeStamp();
2152 timestamp2 = timeEnd+1;
2154 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2155 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2157 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2159 else if (iCountsRun == 1){
2160 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2162 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2163 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2164 arrayValues = new Float_t[2];
2165 arrayWeights = new Double_t[2];
2166 arrayValues[0] = valueBeforeSOR;
2167 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2168 arrayValues[1] = (Float_t)v->GetUInt();
2169 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2170 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2171 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2172 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2175 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2176 return AliGRPObject::GetInvalidFloat();
2179 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2180 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2181 if (timestampBeforeSOR == -1){
2182 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2184 if (timestampAfterEOR == -1){
2185 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2187 return AliGRPObject::GetInvalidFloat();
2190 AliWarning("Using last entry before SOR and first entry after EOR.");
2192 arrayValues = new Float_t[2];
2193 arrayWeights = new Double_t[2];
2194 arrayValues[0] = valueBeforeSOR;
2195 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2196 arrayValues[1] = valueAfterEOR;
2197 arrayWeights[1] = 1.;
2198 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2199 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2200 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2204 AliInfo(Form("mean = %f ",aDCSArrayMean));
2205 return aDCSArrayMean;
2210 //_______________________________________________________________
2212 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2214 // extract DCS pressure maps. Perform fits to save space
2216 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2218 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2219 fPressure->MakeSplineFit(map);
2220 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2221 if (fitFraction > kFitFraction ) {
2222 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2224 AliInfo("Too few pressure maps fitted!!!");
2227 AliInfo("no atmospheric pressure map extracted!!!");
2236 //_______________________________________________________________
2237 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)
2240 // Retrieves logbook and trigger information from the online logbook
2241 // This information is needed for prompt reconstruction
2245 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2249 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2250 // 0 on success and no run was found
2251 // negative on error
2253 // This function is NOT called during the preprocessor run in the Shuttle!
2261 AliCDBManager* cdb = AliCDBManager::Instance();
2262 cdb->SetDefaultStorage(cdbRoot);
2265 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2269 Printf("ERROR: Could not connect to DAQ LB");
2275 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2276 TSQLResult* result = server->Query(sqlQuery);
2279 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2283 if (result->GetRowCount() == 0)
2285 Printf("ERROR: Run %d not found", run);
2290 TSQLRow* row = result->Next();
2293 Printf("ERROR: Could not receive data from run %d", run);
2298 TString timeStartString(row->GetField(0));
2299 TString runType(row->GetField(1));
2300 TString detectorMaskString(row->GetField(2));
2301 TString l3CurrentString(row->GetField(3));
2302 TString dipoleCurrentString(row->GetField(4));
2303 time_t timeStart = (time_t)(timeStartString.Atoi());
2304 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2305 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2306 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2307 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2308 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2310 AliGRPObject * grpObj = new AliGRPObject();
2311 grpObj->SetTimeStart(timeStart);
2312 grpObj->SetRunType((TString)(row->GetField(1)));
2313 grpObj->SetDetectorMask(detectorMask);
2314 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2315 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2316 grpObj->SetL3Polarity(l3Polarity);
2317 grpObj->SetDipolePolarity(dipolePolarity);
2318 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2326 Printf("Storing GRP/GRP/Data object with the following content");
2329 AliCDBMetaData metadata;
2330 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2331 metadata.SetComment("GRP Output parameters received during online running");
2333 AliCDBId id("GRP/GRP/Data", run, run);
2334 Bool_t success = cdb->Put(grpObj, id, &metadata);
2340 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2344 // Receive trigger information
2345 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config 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_trigger_config", run);
2360 row = result->Next();
2363 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2368 TString triggerConfig(row->GetField(0));
2376 Printf("Found trigger configuration: %s", triggerConfig.Data());
2378 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2381 Printf("ERROR: Could not create CTP configuration object");
2385 metadata.SetComment("CTP run configuration received during online running");
2387 AliCDBId id2("GRP/CTP/Config", run, run);
2388 success = cdb->Put(runcfg, id2, &metadata);
2395 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2400 // Receive list of GDCs for this run
2401 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2402 result = server->Query(sqlQuery);
2405 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2409 if (result->GetRowCount() == 0)
2411 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2417 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2418 row = result->Next();
2421 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2425 gdc += row->GetField(0);
2435 Printf("Found GDC: %s", gdc.Data());
2437 // get last run with same run type that was already processed by the SHUTTLE
2439 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());
2440 result = server->Query(sqlQuery);
2443 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2447 if (result->GetRowCount() == 0)
2449 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2454 row = result->Next();
2457 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2462 TString lastRunStr(row->GetField(0));
2463 Int_t lastRun = lastRunStr.Atoi();
2465 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2479 //-----------------------------------------------------------------
2480 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* array){
2483 // Calculating mean over TObjArray from LHC Data
2486 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2487 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2488 if (timeStartString.IsNull() || timeStartString.IsNull()){
2489 if (timeStartString.IsNull()){
2490 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2492 else if (timeStartString.IsNull()){
2493 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2498 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2499 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2500 timeStart = 1260646960;
2501 timeEnd = 1260652740;
2502 Double_t* parameters = new Double_t[5];
2503 parameters[0] = -1.;
2504 parameters[1] = -1.;
2505 parameters[2] = -1.;
2506 parameters[3] = -1.;
2507 parameters[4] = -1.;
2509 Int_t iCountsRun = 0;
2510 Int_t nCounts = array->GetEntries();
2511 printf("ncounts = %d\n",nCounts);
2512 Double_t valueBeforeSOR = 0;
2513 Double_t valueAfterEOR = 0;
2514 Double_t timestampBeforeSOR = -1.;
2515 Double_t timestampAfterEOR = -1.;
2516 Int_t ientrySOR = -1;
2517 Int_t ientryEOR = -1;
2518 Double_t* arrayValues = 0x0;
2519 Double_t* arrayWeights = 0x0;
2520 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2521 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2523 for(Int_t i = 0; i < nCounts; i++) {
2524 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2525 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2526 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2528 // look for the last value before SOR and the first value before EOR
2529 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2530 timestampBeforeSOR = dcs->GetTimeStamp();
2531 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2532 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2534 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2535 timestampAfterEOR = dcs->GetTimeStamp();
2536 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2537 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2539 // check if there are DPs between DAQ_time_start and DAQ_time_end
2540 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2541 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2542 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2543 AliDebug(2,Form("entry between SOR and EOR\n"));
2548 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2552 if (timestampBeforeSOR == -1.){
2553 printf("No value found before SOR\n");
2555 if (timestampAfterEOR == -1.){
2556 printf("No value found after EOR\n");
2559 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2560 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2561 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2562 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2563 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2564 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2566 Int_t nentriesUsed = 0;
2567 if (iCountsRun > 1){
2568 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2569 printf("Calculating (weighted) Mean and Median\n" );
2570 arrayValues = new Double_t[iCountsRun];
2571 arrayWeights = new Double_t[iCountsRun];
2572 nentriesUsed = iCountsRun;
2573 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2574 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2575 Double_t timestamp2 = 0;
2577 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2578 timestamp2 = dcs1->GetTimeStamp();
2581 timestamp2 = (Double_t)timeEnd+1;
2583 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2584 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2585 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2587 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2588 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2590 else if (iCountsRun == 1){
2591 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2593 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2594 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");
2595 arrayValues = new Double_t[2];
2596 arrayWeights = new Double_t[2];
2597 arrayValues[0] = valueBeforeSOR;
2598 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2599 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2600 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2601 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2602 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2603 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2604 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2605 truncMeanFlag = kFALSE;
2608 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");
2614 return parameters[0];
2617 else { // iCountsRun == 0, using only the point immediately before SOR
2618 if (timestampBeforeSOR == -1.){
2619 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");
2625 return parameters[0];
2628 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2629 printf("value = %f\n",valueBeforeSOR);
2630 parameters[0] = valueBeforeSOR;
2631 parameters[2] = valueBeforeSOR;
2632 truncMeanFlag = kFALSE;
2639 Double_t sumweights = 0;
2640 Int_t entriesTruncMean = 0;
2641 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2642 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2644 // calculating SD wrt Mean and Median
2645 printf("Calculating SD wrt Mean and SD wrt Median\n");
2647 for (Int_t i =0; i< nentriesUsed; i++){
2648 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2649 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2650 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2651 sumweights += arrayWeights[i];
2653 // setting SD wrt Mean
2654 if (sumweights != 0 ){
2655 parameters[3] = TMath::Sqrt(temp1/sumweights);
2658 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2661 // setting SD wrt Median
2662 if (nentriesUsed != 0){
2663 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2666 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2675 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2677 printf("Calculating Truncated Mean\n");
2678 for (Int_t i =0; i< nentriesUsed; i++){
2679 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2680 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2681 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2682 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2683 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2687 printf("Discarding entry\n");
2690 // setting truncated mean
2691 if (entriesTruncMean >1){
2692 printf("%d entries used for truncated mean\n",entriesTruncMean);
2693 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2696 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2704 printf("(weighted) mean = %f \n",parameters[0]);
2705 printf("(weighted) truncated mean = %f \n",parameters[1]);
2706 printf("median = %f \n",parameters[2]);
2707 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2708 printf("standard deviation with median = %f \n",parameters[4]);
2710 return (parameters[0]);
2712 //------------------------------------------------------------------------------------------------------
2713 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* array, Double_t timeStart, Double_t timeEnd){
2716 // Method to processo LHC Energy information
2717 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2720 Int_t nCounts = array->GetEntries();
2721 Float_t energy = -1;
2722 Bool_t inRange = kFALSE;
2723 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2725 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2728 for(Int_t i = 0; i < nCounts; i++) {
2729 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2730 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2731 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2732 AliInfo(Form("Energy value found = %d, converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),energy));
2737 if (inRange == kFALSE){
2738 AliInfo("No Energy value found between DAQ_time_start and DAQ_time_end - energy will remain invalid!");