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"
48 #include "AliESDVertex.h"
49 #include "AliLHCReader.h"
50 #include "AliLHCData.h"
51 #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 Log("*************Energy ");
626 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
628 Float_t energy = ProcessEnergy(energyArray,timeStart,timeEnd);
630 grpobj->SetBeamEnergy(energy);
631 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
636 AliError("Energy not found in LHC Data file!!!");
639 Double_t timeBeamMode = 0;
640 Double_t timeMachineMode = 0;
641 Double_t timeBeam = 0;
642 Bool_t flagBeamMode = kFALSE; //flag set true if at least one BeamMode measurement is found within DAQ_time_start and DAQ_time_end
643 Bool_t flagMachineMode = kFALSE; //flag set true if at least one MachineMode measurement is found within DAQ_time_start and DAQ_time_end
644 Bool_t flagBeam = kFALSE; //flag set true if at least one Beam Type measurement is found within DAQ_time_start and DAQ_time_end
647 Log("*************BeamMode (LHCState) ");
648 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
649 Int_t nBeamMode = -1;
651 nBeamMode = beamModeArray->GetEntries();
653 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
657 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(0);
659 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
660 TObjString* beamModeString = beamMode->GetStringArray(0);
661 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
662 grpobj->SetLHCState(beamModeString->String());
665 AliInfo("No Beam Mode found within DAQ_time_start and DAQ_time_end, leaving it empty");
669 AliInfo("Invalid pointer for Beam Mode, leaving it empty");
673 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
674 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
676 if (beamMode->GetTimeStamp()>=timeStart && beamMode->GetTimeStamp()<=timeEnd){
677 if (iBeamMode < nBeamMode-1){
678 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(iBeamMode+1);
680 if (beamMode1->GetTimeStamp()>=timeStart && beamMode1->GetTimeStamp()<=timeEnd){
681 timeBeamMode = beamMode1->GetTimeStamp();
682 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));
686 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
689 TObjString* beamModeString = beamMode->GetStringArray(0);
690 AliInfo(Form("LHC State (corresponding to BeamMode) = %s",(beamModeString->String()).Data()));
691 grpobj->SetLHCState(beamModeString->String());
692 flagBeamMode = kTRUE;
697 AliInfo("Invalid pointer for first entry for Beam Mode, no check can be done, leaving Beam Mode empty");
701 AliError("Found values for BeamMode, but none within DAQ_time_start and DAQ_time_end, leaving it empty");
705 delete beamModeArray;
708 AliError("Beam mode array not found in LHC Data file!!!");
712 Log("*************MachineMode ");
713 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
714 Int_t nMachineMode = -1;
715 if (machineModeArray){
716 nMachineMode = machineModeArray->GetEntries();
717 if (nMachineMode==0){
718 AliInfo("No Machine Mode found, leaving it empty");
721 if (nMachineMode ==1) {
722 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(0);
724 if (machineMode && machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
725 TObjString* machineModeString = machineMode->GetStringArray(0);
726 AliInfo(Form("Machine Mode = %s",(machineModeString->String()).Data()));
727 grpobj->SetMachineMode(machineModeString->String());
730 AliInfo("No Machine Mode found within DAQ_time_start and DAQ_time_end, leaving it empty");
734 AliInfo("Invalid pointer for Machine Mode, leaving it empty");
738 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
739 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
741 if (machineMode->GetTimeStamp()>=timeStart && machineMode->GetTimeStamp()<=timeEnd){
742 if (iMachineMode < nMachineMode-1){
743 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(iMachineMode+1);
745 if (machineMode1->GetTimeStamp()>=timeStart && machineMode1->GetTimeStamp()<=timeEnd){
746 timeMachineMode = machineMode1->GetTimeStamp();
747 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));
751 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
754 TObjString* machineModeString = machineMode->GetStringArray(0);
755 AliInfo(Form("Machine mode = %s",(machineModeString->String()).Data()));
756 grpobj->SetMachineMode(machineModeString->String());
757 flagMachineMode = kTRUE;
762 AliInfo("Invalid pointer for first entry for Machine Mode, no check can be done, leaving Machine Mode empty");
765 if (!flagMachineMode){
766 AliError("Found values for MachineMode, but none within DAQ_time_start and DAQ_time_end, leaving it empty");
770 delete machineModeArray;
773 AliError("Machine mode array not found in LHC Data file!!!");
776 // BeamType1 and BeamType2 - both put in the same string
777 Log("*************BeamType ");
778 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
780 Int_t nBeam = beamArray->GetEntries();
782 AliInfo("No Beam Type found, leaving it empty");
786 AliDCSArray* beam = (AliDCSArray*)beamArray->At(0);
788 if (beam->GetTimeStamp()>=timeStart && beam->GetTimeStamp()<=timeEnd){
789 TObjString* beamString = beam->GetStringArray(0);
790 TString beamType = beamString->String();
791 AliInfo(Form("Beam Type = %s",beamType.Data()));
792 if (beamType.CompareTo("PROTON",TString::kIgnoreCase)){
793 grpobj->SetBeamType("p-p");
795 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase)){
796 grpobj->SetBeamType("Pb-Pb");
799 AliError("Beam Type not known, leaving it empty");
803 AliInfo("No Beam Type found within DAQ_time_start and DAQ_time_end, leaving it empty");
807 AliInfo("Invalid pointer for Beam Type, leaving it empty");
811 for (Int_t iBeam=0; iBeam<nBeam; iBeam++){
812 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
814 if (beam->GetTimeStamp()>=timeStart && beam->GetTimeStamp()<=timeEnd){
815 if (iBeam < nBeam-1){
816 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(iBeam+1);
818 if (beam1->GetTimeStamp()>=timeStart && beam1->GetTimeStamp()<=timeEnd){
819 timeBeam = beam1->GetTimeStamp();
820 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));
824 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
827 TObjString* beamString = beam->GetStringArray(0);
828 TString beamType = beamString->String();
829 AliInfo(Form("Beam Type = %s",beamType.Data()));
830 if (beamType.CompareTo("PROTON",TString::kIgnoreCase)){
831 grpobj->SetBeamType("p-p");
833 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase)){
834 grpobj->SetBeamType("Pb-Pb");
837 AliError("Beam Type not known, leaving it empty");
844 AliInfo("Invalid pointer for first entry for Beam Type, no check can be done, leaving Beam Type empty");
848 AliError("Found values for Beam Type, but none within DAQ_time_start and DAQ_time_end, leaving it empty");
855 AliError("BeamType array not found in LHC data file!!!");
858 // Setting minTimeLHCValidity
859 if (timeBeamMode!=0 || timeMachineMode!=0 || timeBeam !=0){
860 Double_t minTimeLHCValidity;
861 if (timeBeamMode == 0 && timeMachineMode == 0 && timeBeam != 0){ // timeBeam only != 0
862 minTimeLHCValidity = timeBeam;
864 else if (timeBeamMode == 0 && timeMachineMode != 0 && timeBeam == 0){ // timeMachineMode only != 0
865 minTimeLHCValidity = timeMachineMode;
867 else if (timeBeamMode != 0 && timeMachineMode == 0 && timeBeam == 0){ // timeBeamMode only != 0
868 minTimeLHCValidity = timeBeamMode;
870 else if (timeBeamMode == 0 && timeMachineMode != 0 && timeBeam != 0){ // timeBeam and timeMachineMode only != 0
871 minTimeLHCValidity= TMath::Min(timeBeam,timeMachineMode);
873 else if (timeBeamMode != 0 && timeMachineMode == 0 && timeBeam != 0){ // timeBeam and timeBeamMode only != 0
874 minTimeLHCValidity= TMath::Min(timeBeam,timeBeamMode);
876 else if (timeBeamMode != 0 && timeMachineMode != 0 && timeBeam == 0){ // timeMachineMode and timeBeamMode only != 0
877 minTimeLHCValidity= TMath::Min(timeMachineMode,timeBeamMode);
880 Double_t arrayTimes[3] = {timeBeamMode,timeMachineMode,timeBeam};
881 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
883 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
884 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
887 // Processing data to go to AliLHCData object
888 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
889 // storing AliLHCData in OCDB
891 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
893 md.SetResponsible("Ruben Shahoyan");
894 md.SetComment("LHC data from the GRP preprocessor.");
895 Bool_t result = kTRUE;
896 result = Store("GRP", "LHCData", dt, &md);
898 if (result) return 0;
904 AliError("No LHCData file found in DCS FXS");
911 //_______________________________________________________________
913 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
916 //Getting the SPD Mean Vertex
919 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
920 Bool_t storeResult = kTRUE;
921 if (list !=0x0 && list->GetEntries()!=0)
923 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
925 for (Int_t jj=0;jj<list->GetEntries();jj++){
926 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
927 AliInfo(Form("found source %s", str->String().Data()));
928 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
929 if (fileNameRun.Length()>0){
930 AliInfo(Form("Got the file %s", fileNameRun.Data()));
931 TFile daqFile(fileNameRun.Data(),"READ");
932 if (daqFile.IsOpen()) {
933 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
936 // storing in the OCDB
938 md.SetResponsible("Cvetan Cheshkov");
939 md.SetComment("SPD Mean Vertex");
940 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
943 AliWarning("No SPD Mean Vertex object found in file");
947 AliError("Can't open file");
948 storeResult = kFALSE;
952 AliWarning("No file found for current source for SPD Mean Vertex");
957 AliWarning("No list found for SPD Mean Vertex");
960 if (list) delete list;
966 //_______________________________________________________________
968 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
970 //Getting the DAQ lb information
972 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
973 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
974 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
975 TString beamType = (TString)GetRunParameter("beamType");
976 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
977 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
978 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
979 TString runType = (TString)GetRunType();
981 UInt_t nparameter = 0;
983 grpObj->SetTimeStart(timeStart);
984 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
988 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
992 grpObj->SetTimeEnd(timeEnd);
993 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
997 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1000 if (beamEnergy != 0){
1001 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1004 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1008 if (beamType.Length() != 0){
1009 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()));
1012 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1015 if (numberOfDetectors != 0){
1016 grpObj->SetNumberOfDetectors(numberOfDetectors);
1017 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1021 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1024 if (detectorMask != 0){
1025 grpObj->SetDetectorMask(detectorMask);
1026 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1030 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1033 if (lhcPeriod.Length() != 0) {
1034 grpObj->SetLHCPeriod(lhcPeriod);
1035 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1039 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1041 if (runType.Length() != 0) {
1042 grpObj->SetRunType(runType);
1043 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1047 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1053 //_______________________________________________________________
1055 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1057 //======DAQ FXS======//
1059 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1060 TList* list = GetFileSources(kDAQ);
1062 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1066 if (list->GetEntries() == 0) {
1067 Log("no raw data tags in this run: nothing to merge!");
1068 delete list; list=0;
1072 TChain *fRawTagChain = new TChain("T");
1074 TIterator* iter = list->MakeIterator();
1076 while ((obj = iter->Next())) {
1077 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1079 Log(Form("Found source %s", objStr->String().Data()));
1080 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1082 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1083 delete fRawTagChain; fRawTagChain=0;
1086 Log(Form("Number of ids: %d",list2->GetEntries()));
1087 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1088 TObjString *idStr = (TObjString *)list2->At(i);
1089 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1090 if (fileName.Length() > 0) {
1091 Log(Form("Adding file in the chain: %s",fileName.Data()));
1092 fRawTagChain->Add(fileName.Data());
1095 Log(Form("Could not retrieve file with id %s from source %s: "
1096 "connection problems with DAQ FXS!",
1097 idStr->String().Data(), objStr->String().Data()));
1098 delete list; list=0;
1099 delete list2; list2=0;
1100 delete fRawTagChain; fRawTagChain=0;
1108 TString fRawDataFileName = "GRP_Merged.tag.root";
1109 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1111 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1112 Log("Error merging raw data files!!!");
1116 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1117 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1120 Log("Problem storing raw data tags in local file!!!");
1122 Log("Raw data tags merged successfully!!");
1127 delete fRawTagChain; fRawTagChain=0;
1129 if (result == kFALSE) {
1137 //_______________________________________________________________
1138 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1141 // processing the info
1142 // stored in the DCS FXS
1143 // coming from the trigger
1145 // Get the CTP counters information
1147 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1148 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1149 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1151 Log(Form("No dummy CTP scalers entry found, going into error..."));
1155 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1157 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1161 AliCDBMetaData metaData;
1162 metaData.SetResponsible("Roman Lietava");
1163 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1164 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1165 Log("Unable to store the dummy CTP scalers object to OCDB!");
1172 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1173 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1174 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1175 if (countersfile.IsNull()) {
1176 Log("No CTP counters files has been found: empty source!");
1180 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1181 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1183 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1187 AliCDBMetaData metaData;
1188 metaData.SetBeamPeriod(0);
1189 metaData.SetResponsible("Roman Lietava");
1190 metaData.SetComment("CTP scalers");
1191 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1192 Log("Unable to store the CTP scalers object to OCDB!");
1203 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1210 //_______________________________________________________________
1212 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1216 // processing DCS DPs
1219 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1220 Int_t nL3Entries = 0;
1221 Int_t nDipoleEntries = 0;
1222 Int_t nEnvEntries = 0;
1223 Int_t nHallProbesEntries = 0;
1224 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1225 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1226 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1227 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1228 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1229 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1230 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1235 //_______________________________________________________________
1237 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1244 Int_t nL3Entries = 0;
1246 TObjArray *array = 0x0;
1248 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1250 AliInfo(Form("==========L3Current==========="));
1251 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1252 indexDP = kL3Current;
1253 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1255 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1258 if (array->GetEntries() == 0){
1259 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1262 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1263 if (floatDCS != NULL){
1264 grpObj->SetL3Current(floatDCS);
1276 ffailedDPs->RemoveAt(indexDP);
1280 if (array) array = 0x0;
1282 AliInfo(Form("==========L3Polarity==========="));
1283 indexDP = kL3Polarity;
1284 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1286 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1289 if (array->GetEntries() == 0){
1290 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1293 Bool_t change = kFALSE;
1294 Char_t charDCS = ProcessBool(array,change);
1295 if (change == kFALSE){
1296 grpObj->SetL3Polarity(charDCS);
1297 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1298 ffailedDPs->RemoveAt(indexDP);
1302 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1303 ffailedDPs->RemoveAt(indexDP);
1307 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]));
1315 //_______________________________________________________________
1317 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1323 Int_t nDipoleEntries = 0;
1324 TObjArray *array = 0x0;
1326 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1328 AliInfo(Form("==========DipoleCurrent==========="));
1329 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1330 indexDP = kDipoleCurrent;
1331 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1333 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1336 if (array->GetEntries() == 0){
1337 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1340 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1341 if (floatDCS != NULL){
1342 grpObj->SetDipoleCurrent(floatDCS);
1354 ffailedDPs->RemoveAt(indexDP);
1358 if (array) array = 0x0;
1360 AliInfo(Form("==========DipolePolarity==========="));
1361 indexDP = kDipolePolarity;
1362 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1364 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1367 if (array->GetEntries() == 0){
1368 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1371 Bool_t change = kFALSE;
1372 Char_t charDCS = ProcessBool(array,change);
1374 grpObj->SetDipolePolarity(charDCS);
1375 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1376 ffailedDPs->RemoveAt(indexDP);
1380 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1381 ffailedDPs->RemoveAt(indexDP);
1385 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]));
1390 return nDipoleEntries;
1393 //_______________________________________________________________
1395 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1399 // evironment conditions (temperature, pressure) info
1401 Int_t nEnvEntries = 0;
1402 TObjArray *array = 0x0;
1405 AliInfo(Form("==========CavernTemperature==========="));
1406 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1407 indexDP = kCavernTemperature;
1408 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1410 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1413 if (array->GetEntries() == 0){
1414 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1417 Float_t *floatDCS = ProcessFloatAll(array);
1418 if (floatDCS != NULL){
1419 grpObj->SetCavernTemperature(floatDCS);
1430 ffailedDPs->RemoveAt(indexDP);
1435 if (array) array = 0x0;
1437 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1438 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1439 //dcsSensorArray->Print();
1440 if( fPressure->NumFits()<kNumSensors ) {
1441 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1443 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1445 AliInfo(Form("==========CavernAtmosPressure==========="));
1446 indexDP = kCavernAtmosPressure;
1447 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1448 TGraph* graph = sensorCavernP2->GetGraph();
1449 AliDebug(3,Form("index = %d",indexDP));
1450 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1451 AliDebug(2,Form("graph = %p",graph));
1452 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1453 if(sensorCavernP2->GetFit() || graph) {
1454 if (sensorCavernP2->GetFit()){
1455 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1458 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1460 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1461 ffailedDPs->RemoveAt(indexDP);
1464 //if (sensorP2) delete sensorP2;
1466 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] ));
1469 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1470 indexDP = kSurfaceAtmosPressure;
1471 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1472 graph = sensorP2->GetGraph();
1473 AliDebug(3,Form("index = %d",indexDP));
1474 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1475 AliDebug(2,Form("graph = %p",graph));
1476 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1477 if(sensorP2->GetFit() || graph) {
1478 if (sensorP2->GetFit()){
1479 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1482 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1484 grpObj->SetSurfaceAtmosPressure(sensorP2);
1485 ffailedDPs->RemoveAt(indexDP);
1488 //if (sensorP2) delete sensorP2;
1490 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] ));
1493 AliInfo(Form("==========CavernAtmosPressure2==========="));
1494 indexDP = kCavernAtmosPressure2;
1495 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1496 graph = sensorCavernP22->GetGraph();
1497 AliDebug(3,Form("index = %d",indexDP));
1498 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1499 AliDebug(2,Form("graph = %p",graph));
1500 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1501 if(sensorCavernP22->GetFit() || graph) {
1502 if (sensorCavernP22->GetFit()){
1503 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1506 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1508 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1509 ffailedDPs->RemoveAt(indexDP);
1512 //if (sensorP2) delete sensorP2;
1514 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] ));
1520 //_______________________________________________________________
1522 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1528 Int_t nHPEntries = 0;
1529 TObjArray *array = 0x0;
1531 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1533 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1534 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()));
1536 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1537 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1538 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1539 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1541 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1544 if (array->GetEntries() == 0){
1545 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1548 Float_t *floatDCS = ProcessFloatAll(array);
1549 if (floatDCS != NULL){
1550 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]));
1551 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1552 for (Int_t kk = 0 ; kk< 5; kk++){
1553 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1565 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1571 Log(Form("Hall Probes = %d ", nHPEntries));
1575 //_________________________________________________________________________
1577 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1581 // returning Spline Fit
1584 Int_t entriesarray = array->GetEntries();
1585 Float_t* value = new Float_t[entriesarray];
1586 Float_t* time = new Float_t[entriesarray];
1587 AliDCSValue* v = 0x0;
1588 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1589 v = (AliDCSValue*)array->At(iarray);
1590 value[iarray] = v->GetFloat();
1591 time[iarray] = v->GetTimeStamp();
1592 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1594 TGraph* gr = new TGraph(entriesarray,value,time);
1596 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1599 AliSplineFit *fit = new AliSplineFit();
1600 fit->SetMinPoints(10);
1601 fit->InitKnots(gr,10,10,0.0);
1605 AliWarning(Form("%s: no fit performed",stringID.Data()));
1611 //_________________________________________________________________________
1613 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1620 TString aDCSString="";
1622 AliDCSValue *v = 0x0;
1623 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1624 v = (AliDCSValue *)array->At(iCount);
1625 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1626 AliError(Form("DCS values for the parameter outside the queried interval"));
1630 if (aDCSString != v->GetChar())
1631 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1633 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1638 //__________________________________________________________________________________________________________________
1640 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1643 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1645 // parameters[0] = mean
1646 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1647 // parameters[2] = median
1648 // parameters[3] = standard deviation wrt mean
1649 // parameters[4] = standard deviation wrt median
1652 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1653 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1654 if (timeStartString.IsNull() || timeStartString.IsNull()){
1655 if (timeStartString.IsNull()){
1656 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1658 else if (timeStartString.IsNull()){
1659 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1661 fdaqStartEndTimeOk = kFALSE;
1665 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1666 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1667 Float_t* parameters = new Float_t[5];
1669 Int_t iCountsRun = 0;
1670 Int_t nCounts = array->GetEntries();
1671 Float_t valueBeforeSOR = 0;
1672 Float_t valueAfterEOR = 0;
1673 Int_t timestampBeforeSOR = -1;
1674 Int_t timestampAfterEOR = -1;
1675 Int_t ientrySOR = -1;
1676 Int_t ientryEOR = -1;
1677 Float_t* arrayValues = 0x0;
1678 Double_t* arrayWeights = 0x0;
1679 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1680 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1682 for(Int_t i = 0; i < nCounts; i++) {
1683 AliDCSValue *v = (AliDCSValue *)array->At(i);
1684 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1685 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1686 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1687 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1690 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1691 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1693 // look for the last value before SOR and the first value before EOR
1694 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1695 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1696 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1697 valueBeforeSOR = v->GetFloat();
1699 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1700 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1701 valueAfterEOR = v->GetFloat();
1702 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1704 // check if there are DPs between DAQ_time_start and DAQ_time_end
1705 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1706 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1707 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1708 AliDebug(2,Form("entry between SOR and EOR"));
1713 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1717 if (timestampBeforeSOR == -1){
1718 AliWarning("No value found before SOR");
1720 if (timestampAfterEOR == -1){
1721 AliWarning("No value found after EOR");
1724 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1725 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1726 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1727 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1728 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1729 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1731 Int_t nentriesUsed = 0;
1732 if (iCountsRun > 1){
1733 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1734 AliDebug(2,"Calculating (weighted) Mean and Median");
1735 arrayValues = new Float_t[iCountsRun];
1736 arrayWeights = new Double_t[iCountsRun];
1737 nentriesUsed = iCountsRun;
1738 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1739 AliDCSValue *v = (AliDCSValue *)array->At(i);
1740 Int_t timestamp2 = 0;
1742 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1743 timestamp2 = (Int_t)v1->GetTimeStamp();
1746 timestamp2 = timeEnd+1;
1748 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1749 arrayValues[i-ientrySOR] = v->GetFloat();
1751 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1752 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1754 else if (iCountsRun == 1){
1755 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1757 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1758 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.");
1759 arrayValues = new Float_t[2];
1760 arrayWeights = new Double_t[2];
1761 arrayValues[0] = valueBeforeSOR;
1762 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1763 arrayValues[1] = v->GetFloat();
1764 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1765 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1766 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1767 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1768 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1769 truncMeanFlag = kFALSE;
1772 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");
1773 parameters[0] = AliGRPObject::GetInvalidFloat();
1774 parameters[1] = AliGRPObject::GetInvalidFloat();
1775 parameters[2] = AliGRPObject::GetInvalidFloat();
1776 parameters[3] = AliGRPObject::GetInvalidFloat();
1777 parameters[4] = AliGRPObject::GetInvalidFloat();
1781 else { // iCountsRun == 0, using only the point immediately before SOR
1782 if (timestampBeforeSOR == -1){
1783 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");
1784 parameters[0] = AliGRPObject::GetInvalidFloat();
1785 parameters[1] = AliGRPObject::GetInvalidFloat();
1786 parameters[2] = AliGRPObject::GetInvalidFloat();
1787 parameters[3] = AliGRPObject::GetInvalidFloat();
1788 parameters[4] = AliGRPObject::GetInvalidFloat();
1792 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1793 AliDebug(2,Form("value = %f",valueBeforeSOR));
1794 parameters[0] = valueBeforeSOR;
1795 parameters[2] = valueBeforeSOR;
1796 truncMeanFlag = kFALSE;
1803 Float_t sumweights = 0;
1804 Int_t entriesTruncMean = 0;
1805 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1806 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1808 // calculating SD wrt Mean and Median
1809 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1811 for (Int_t i =0; i< nentriesUsed; i++){
1812 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1813 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1814 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1815 sumweights += arrayWeights[i];
1817 // setting SD wrt Mean
1818 if (sumweights != 0 ){
1819 parameters[3] = TMath::Sqrt(temp1/sumweights);
1822 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1823 parameters[3] = AliGRPObject::GetInvalidFloat();
1825 // setting SD wrt Median
1826 if (nentriesUsed != 0){
1827 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1830 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1831 parameters[4] = AliGRPObject::GetInvalidFloat();
1835 parameters[3] = AliGRPObject::GetInvalidFloat();
1836 parameters[4] = AliGRPObject::GetInvalidFloat();
1839 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1841 AliDebug(2,"Calculating Truncated Mean");
1842 for (Int_t i =0; i< nentriesUsed; i++){
1843 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1844 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1845 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1846 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1847 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1851 AliDebug(2,"Discarding entry");
1854 // setting truncated mean
1855 if (entriesTruncMean >1){
1856 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1857 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1860 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1861 parameters[1] = AliGRPObject::GetInvalidFloat();
1865 parameters[1] = AliGRPObject::GetInvalidFloat();
1868 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1869 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1870 AliInfo(Form("median = %f ",parameters[2]));
1871 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1872 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1877 //__________________________________________________________________________________________________________________
1879 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1882 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1883 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1884 // the flag is set according to the L3/Dipole current value
1885 // current threshold for L3 = 350 A (value provided by DCS)
1886 // current threshold for Dipole = 450 A (value provided by DCS)
1888 // parameters[0] = mean
1889 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1890 // parameters[2] = median
1891 // parameters[3] = standard deviation wrt mean
1892 // parameters[4] = standard deviation wrt median
1895 AliInfo(Form("indexDP = %d",indexDP));
1897 Int_t nCounts = array->GetEntries();
1898 for(Int_t i = 0; i < nCounts; i++) {
1899 AliDCSValue *v = (AliDCSValue *)array->At(i);
1900 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1901 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1902 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1903 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1906 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1907 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1908 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1909 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1912 AliError(Form("DCS values for the parameter outside the queried interval"));
1916 return ProcessFloatAll(array);
1920 //_______________________________________________________________
1922 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1925 // processing Boolean values
1928 Bool_t aDCSBool = kTRUE;
1930 AliDCSValue *v = 0x0;
1932 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1933 v = (AliDCSValue *)array->At(iCount);
1934 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1935 AliError(Form("DCS values for the parameter outside the queried interval"));
1939 if (aDCSBool != v->GetBool()) {
1940 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1944 aDCSBool = v->GetBool(); // always keeping last value
1945 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1948 Char_t caDCSBool = (Char_t) aDCSBool;
1953 //_______________________________________________________________
1955 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1958 // processing Int values, returning mean
1959 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1960 // are outside the queried time interval or their value is out of range
1963 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1964 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1965 if (timeStartString.IsNull() || timeStartString.IsNull()){
1966 if (timeStartString.IsNull()){
1967 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1969 else if (timeStartString.IsNull()){
1970 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1975 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1976 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1977 Float_t aDCSArrayMean = 0.0;
1979 Float_t valueBeforeSOR = 0;
1980 Float_t valueAfterEOR = 0;
1981 Int_t timestampBeforeSOR = -1;
1982 Int_t timestampAfterEOR = -1;
1983 Int_t ientrySOR = -1;
1984 Int_t ientryEOR = -1;
1985 Float_t* arrayValues = 0x0;
1986 Double_t* arrayWeights = 0x0;
1987 Int_t iCountsRun = 0;
1988 Int_t nCounts = array->GetEntries();
1990 for(Int_t i = 0; i < nCounts; i++) {
1991 AliDCSValue* v = (AliDCSValue *)array->At(i);
1992 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1993 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1994 return AliGRPObject::GetInvalidFloat();
1996 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1997 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1999 // look for the last value before SOR and the first value before EOR
2000 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2001 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2002 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2003 valueBeforeSOR = (Float_t) v->GetInt();
2005 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2006 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2007 valueAfterEOR = (Float_t) v->GetInt();
2008 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2010 // check if there are DPs between DAQ_time_start and DAQ_time_end
2011 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2012 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2013 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2014 AliDebug(2,Form("entry between SOR and EOR"));
2019 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2023 if (timestampBeforeSOR == -1){
2024 AliWarning("No value found before SOR!");
2026 if (timestampAfterEOR == -1){
2027 AliWarning("No value found after EOR!");
2030 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2031 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2032 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2033 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2034 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2035 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2037 Int_t nentriesUsed = 0;
2038 if (iCountsRun > 1){
2039 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2040 AliDebug(2,"Calculating (weighted) Mean");
2041 arrayValues = new Float_t[iCountsRun];
2042 arrayWeights = new Double_t[iCountsRun];
2043 nentriesUsed = iCountsRun;
2044 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2045 AliDCSValue *v = (AliDCSValue *)array->At(i);
2046 Int_t timestamp2 = 0;
2048 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2049 timestamp2 = (Int_t)v1->GetTimeStamp();
2052 timestamp2 = timeEnd+1;
2054 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2055 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2057 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2059 else if (iCountsRun == 1){
2060 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2062 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2063 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2064 arrayValues = new Float_t[2];
2065 arrayWeights = new Double_t[2];
2066 arrayValues[0] = valueBeforeSOR;
2067 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2068 arrayValues[1] = (Float_t)v->GetInt();
2069 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2070 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2071 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2072 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2075 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2076 return AliGRPObject::GetInvalidFloat();
2079 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2080 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2081 if (timestampBeforeSOR == -1){
2082 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2084 if (timestampAfterEOR == -1){
2085 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2087 return AliGRPObject::GetInvalidFloat();
2090 AliWarning("Using last entry before SOR and first entry after EOR.");
2092 arrayValues = new Float_t[2];
2093 arrayWeights = new Double_t[2];
2094 arrayValues[0] = valueBeforeSOR;
2095 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2096 arrayValues[1] = valueAfterEOR;
2097 arrayWeights[1] = 1.;
2098 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2099 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2100 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2104 AliInfo(Form("mean = %f ", aDCSArrayMean));
2105 return aDCSArrayMean;
2108 //_______________________________________________________________
2110 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2113 // processing Int values, returning mean
2114 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2115 // are outside the queried time interval or their value is out of range
2118 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2119 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2120 if (timeStartString.IsNull() || timeStartString.IsNull()){
2121 if (timeStartString.IsNull()){
2122 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2124 else if (timeStartString.IsNull()){
2125 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2130 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2131 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2132 Float_t aDCSArrayMean = 0.0;
2134 Float_t valueBeforeSOR = 0;
2135 Float_t valueAfterEOR = 0;
2136 Int_t timestampBeforeSOR = -1;
2137 Int_t timestampAfterEOR = -1;
2138 Int_t ientrySOR = -1;
2139 Int_t ientryEOR = -1;
2140 Float_t* arrayValues = 0x0;
2141 Double_t* arrayWeights = 0x0;
2142 Int_t iCountsRun = 0;
2143 Int_t nCounts = array->GetEntries();
2145 for(Int_t i = 0; i < nCounts; i++) {
2146 AliDCSValue* v = (AliDCSValue *)array->At(i);
2147 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2148 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2149 return AliGRPObject::GetInvalidFloat();
2151 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2152 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2154 // look for the last value before SOR and the first value before EOR
2155 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2156 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2157 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2158 valueBeforeSOR = (Float_t)v->GetUInt();
2160 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2161 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2162 valueAfterEOR = (Float_t)v->GetUInt();
2163 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2165 // check if there are DPs between DAQ_time_start and DAQ_time_end
2166 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2167 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2168 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2169 AliDebug(2,Form("entry between SOR and EOR"));
2174 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2178 if (timestampBeforeSOR == -1){
2179 AliWarning("No value found before SOR!");
2181 if (timestampAfterEOR == -1){
2182 AliWarning("No value found after EOR!");
2185 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2186 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2187 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2188 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2189 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2190 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2192 Int_t nentriesUsed = 0;
2193 if (iCountsRun > 1){
2194 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2195 AliDebug(2,"Calculating (weighted) Mean");
2196 arrayValues = new Float_t[iCountsRun];
2197 arrayWeights = new Double_t[iCountsRun];
2198 nentriesUsed = iCountsRun;
2199 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2200 AliDCSValue *v = (AliDCSValue *)array->At(i);
2201 Int_t timestamp2 = 0;
2203 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2204 timestamp2 = (Int_t)v1->GetTimeStamp();
2207 timestamp2 = timeEnd+1;
2209 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2210 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2212 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2214 else if (iCountsRun == 1){
2215 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2217 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2218 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2219 arrayValues = new Float_t[2];
2220 arrayWeights = new Double_t[2];
2221 arrayValues[0] = valueBeforeSOR;
2222 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2223 arrayValues[1] = (Float_t)v->GetUInt();
2224 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2225 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2226 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2227 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2230 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2231 return AliGRPObject::GetInvalidFloat();
2234 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2235 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2236 if (timestampBeforeSOR == -1){
2237 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2239 if (timestampAfterEOR == -1){
2240 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2242 return AliGRPObject::GetInvalidFloat();
2245 AliWarning("Using last entry before SOR and first entry after EOR.");
2247 arrayValues = new Float_t[2];
2248 arrayWeights = new Double_t[2];
2249 arrayValues[0] = valueBeforeSOR;
2250 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2251 arrayValues[1] = valueAfterEOR;
2252 arrayWeights[1] = 1.;
2253 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2254 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2255 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2259 AliInfo(Form("mean = %f ",aDCSArrayMean));
2260 return aDCSArrayMean;
2265 //_______________________________________________________________
2267 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2269 // extract DCS pressure maps. Perform fits to save space
2271 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2273 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2274 fPressure->MakeSplineFit(map);
2275 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2276 if (fitFraction > kFitFraction ) {
2277 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2279 AliInfo("Too few pressure maps fitted!!!");
2282 AliInfo("no atmospheric pressure map extracted!!!");
2291 //_______________________________________________________________
2292 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)
2295 // Retrieves logbook and trigger information from the online logbook
2296 // This information is needed for prompt reconstruction
2300 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2304 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2305 // 0 on success and no run was found
2306 // negative on error
2308 // This function is NOT called during the preprocessor run in the Shuttle!
2316 AliCDBManager* cdb = AliCDBManager::Instance();
2317 cdb->SetDefaultStorage(cdbRoot);
2320 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2324 Printf("ERROR: Could not connect to DAQ LB");
2330 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2331 TSQLResult* result = server->Query(sqlQuery);
2334 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2338 if (result->GetRowCount() == 0)
2340 Printf("ERROR: Run %d not found", run);
2345 TSQLRow* row = result->Next();
2348 Printf("ERROR: Could not receive data from run %d", run);
2353 TString timeStartString(row->GetField(0));
2354 TString runType(row->GetField(1));
2355 TString detectorMaskString(row->GetField(2));
2356 TString l3CurrentString(row->GetField(3));
2357 TString dipoleCurrentString(row->GetField(4));
2358 time_t timeStart = (time_t)(timeStartString.Atoi());
2359 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2360 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2361 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2362 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2363 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2365 AliGRPObject * grpObj = new AliGRPObject();
2366 grpObj->SetTimeStart(timeStart);
2367 grpObj->SetRunType((TString)(row->GetField(1)));
2368 grpObj->SetDetectorMask(detectorMask);
2369 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2370 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2371 grpObj->SetL3Polarity(l3Polarity);
2372 grpObj->SetDipolePolarity(dipolePolarity);
2373 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2381 Printf("Storing GRP/GRP/Data object with the following content");
2384 AliCDBMetaData metadata;
2385 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2386 metadata.SetComment("GRP Output parameters received during online running");
2388 AliCDBId id("GRP/GRP/Data", run, run);
2389 Bool_t success = cdb->Put(grpObj, id, &metadata);
2395 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2399 // Receive trigger information
2400 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2401 result = server->Query(sqlQuery);
2404 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2408 if (result->GetRowCount() == 0)
2410 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2415 row = result->Next();
2418 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2423 TString triggerConfig(row->GetField(0));
2431 Printf("Found trigger configuration: %s", triggerConfig.Data());
2433 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2436 Printf("ERROR: Could not create CTP configuration object");
2440 metadata.SetComment("CTP run configuration received during online running");
2442 AliCDBId id2("GRP/CTP/Config", run, run);
2443 success = cdb->Put(runcfg, id2, &metadata);
2450 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2455 // Receive list of GDCs for this run
2456 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2457 result = server->Query(sqlQuery);
2460 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2464 if (result->GetRowCount() == 0)
2466 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2472 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2473 row = result->Next();
2476 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2480 gdc += row->GetField(0);
2490 Printf("Found GDC: %s", gdc.Data());
2492 // get last run with same run type that was already processed by the SHUTTLE
2494 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());
2495 result = server->Query(sqlQuery);
2498 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2502 if (result->GetRowCount() == 0)
2504 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2509 row = result->Next();
2512 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2517 TString lastRunStr(row->GetField(0));
2518 Int_t lastRun = lastRunStr.Atoi();
2520 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2534 //-----------------------------------------------------------------
2535 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* const array){
2538 // Calculating mean over TObjArray from LHC Data
2541 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2542 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2543 if (timeStartString.IsNull() || timeStartString.IsNull()){
2544 if (timeStartString.IsNull()){
2545 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2547 else if (timeStartString.IsNull()){
2548 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2553 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2554 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2555 timeStart = 1260646960;
2556 timeEnd = 1260652740;
2557 Double_t* parameters = new Double_t[5];
2558 parameters[0] = -1.;
2559 parameters[1] = -1.;
2560 parameters[2] = -1.;
2561 parameters[3] = -1.;
2562 parameters[4] = -1.;
2564 Int_t iCountsRun = 0;
2565 Int_t nCounts = array->GetEntries();
2566 printf("ncounts = %d\n",nCounts);
2567 Double_t valueBeforeSOR = 0;
2568 Double_t valueAfterEOR = 0;
2569 Double_t timestampBeforeSOR = -1.;
2570 Double_t timestampAfterEOR = -1.;
2571 Int_t ientrySOR = -1;
2572 Int_t ientryEOR = -1;
2573 Double_t* arrayValues = 0x0;
2574 Double_t* arrayWeights = 0x0;
2575 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2576 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2578 for(Int_t i = 0; i < nCounts; i++) {
2579 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2580 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2581 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2583 // look for the last value before SOR and the first value before EOR
2584 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2585 timestampBeforeSOR = dcs->GetTimeStamp();
2586 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2587 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2589 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2590 timestampAfterEOR = dcs->GetTimeStamp();
2591 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2592 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2594 // check if there are DPs between DAQ_time_start and DAQ_time_end
2595 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2596 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2597 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2598 AliDebug(2,Form("entry between SOR and EOR\n"));
2603 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2607 if (timestampBeforeSOR == -1.){
2608 printf("No value found before SOR\n");
2610 if (timestampAfterEOR == -1.){
2611 printf("No value found after EOR\n");
2614 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2615 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2616 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2617 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2618 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2619 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2621 Int_t nentriesUsed = 0;
2622 if (iCountsRun > 1){
2623 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2624 printf("Calculating (weighted) Mean and Median\n" );
2625 arrayValues = new Double_t[iCountsRun];
2626 arrayWeights = new Double_t[iCountsRun];
2627 nentriesUsed = iCountsRun;
2628 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2629 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2630 Double_t timestamp2 = 0;
2632 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2633 timestamp2 = dcs1->GetTimeStamp();
2636 timestamp2 = (Double_t)timeEnd+1;
2638 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2639 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2640 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2642 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2643 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2645 else if (iCountsRun == 1){
2646 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2648 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2649 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");
2650 arrayValues = new Double_t[2];
2651 arrayWeights = new Double_t[2];
2652 arrayValues[0] = valueBeforeSOR;
2653 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2654 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2655 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2656 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2657 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2658 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2659 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2660 truncMeanFlag = kFALSE;
2663 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");
2669 return parameters[0];
2672 else { // iCountsRun == 0, using only the point immediately before SOR
2673 if (timestampBeforeSOR == -1.){
2674 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");
2680 return parameters[0];
2683 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2684 printf("value = %f\n",valueBeforeSOR);
2685 parameters[0] = valueBeforeSOR;
2686 parameters[2] = valueBeforeSOR;
2687 truncMeanFlag = kFALSE;
2694 Double_t sumweights = 0;
2695 Int_t entriesTruncMean = 0;
2696 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2697 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2699 // calculating SD wrt Mean and Median
2700 printf("Calculating SD wrt Mean and SD wrt Median\n");
2702 for (Int_t i =0; i< nentriesUsed; i++){
2703 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2704 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2705 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2706 sumweights += arrayWeights[i];
2708 // setting SD wrt Mean
2709 if (sumweights != 0 ){
2710 parameters[3] = TMath::Sqrt(temp1/sumweights);
2713 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2716 // setting SD wrt Median
2717 if (nentriesUsed != 0){
2718 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2721 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2730 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2732 printf("Calculating Truncated Mean\n");
2733 for (Int_t i =0; i< nentriesUsed; i++){
2734 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2735 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2736 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2737 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2738 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2742 printf("Discarding entry\n");
2745 // setting truncated mean
2746 if (entriesTruncMean >1){
2747 printf("%d entries used for truncated mean\n",entriesTruncMean);
2748 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2751 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2759 printf("(weighted) mean = %f \n",parameters[0]);
2760 printf("(weighted) truncated mean = %f \n",parameters[1]);
2761 printf("median = %f \n",parameters[2]);
2762 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2763 printf("standard deviation with median = %f \n",parameters[4]);
2765 return (parameters[0]);
2767 //------------------------------------------------------------------------------------------------------
2768 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart, Double_t timeEnd){
2771 // Method to processo LHC Energy information
2772 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2775 Int_t nCounts = array->GetEntries();
2776 Float_t energy = -1;
2777 Bool_t inRange = kFALSE;
2778 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2780 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2783 for(Int_t i = 0; i < nCounts; i++) {
2784 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2785 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2786 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2787 AliInfo(Form("Energy value found = %d, converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),energy));
2792 if (inRange == kFALSE){
2793 AliInfo("No Energy value found between DAQ_time_start and DAQ_time_end - energy will remain invalid!");