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
835 TMap* lhcMap = (TMap*)lhcReader.ReadLHCDP(fileName.Data());
837 Log(Form("LHCData map entries = %d",lhcMap->GetEntries()));
839 AliLHCData* dt = new AliLHCData(lhcMap,timeStart,timeEnd);
841 // storing AliLHCData in OCDB
844 md.SetResponsible("Ruben Shahoyan");
845 md.SetComment("LHC data from the GRP preprocessor.");
847 Bool_t result = kTRUE;
848 result = Store("GRP", "LHCData", dt, &md);
850 if (result) return 0;
857 AliError("Cannot read correctly LHCData file");
863 AliError("No LHCData file found in DCS FXS");
869 //_______________________________________________________________
871 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
874 //Getting the SPD Mean Vertex
877 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
878 Bool_t storeResult = kTRUE;
879 if (list !=0x0 && list->GetEntries()!=0)
881 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
883 for (Int_t jj=0;jj<list->GetEntries();jj++){
884 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
885 AliInfo(Form("found source %s", str->String().Data()));
886 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
887 if (fileNameRun.Length()>0){
888 AliInfo(Form("Got the file %s", fileNameRun.Data()));
889 TFile daqFile(fileNameRun.Data(),"READ");
890 if (daqFile.IsOpen()) {
891 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
894 // storing in the OCDB
896 md.SetResponsible("Cvetan Cheshkov");
897 md.SetComment("SPD Mean Vertex");
898 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
901 AliWarning("No SPD Mean Vertex object found in file");
905 AliError("Can't open file");
906 storeResult = kFALSE;
910 AliWarning("No file found for current source for SPD Mean Vertex");
915 AliWarning("No list found for SPD Mean Vertex");
918 if (list) delete list;
924 //_______________________________________________________________
926 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
928 //Getting the DAQ lb information
930 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
931 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
932 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
933 TString beamType = (TString)GetRunParameter("beamType");
934 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
935 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
936 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
937 TString runType = (TString)GetRunType();
939 UInt_t nparameter = 0;
941 grpObj->SetTimeStart(timeStart);
942 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
946 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
950 grpObj->SetTimeEnd(timeEnd);
951 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
955 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
958 if (beamEnergy != 0){
959 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
962 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
966 if (beamType.Length() != 0){
967 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()));
970 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
973 if (numberOfDetectors != 0){
974 grpObj->SetNumberOfDetectors(numberOfDetectors);
975 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
979 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
982 if (detectorMask != 0){
983 grpObj->SetDetectorMask(detectorMask);
984 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
988 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
991 if (lhcPeriod.Length() != 0) {
992 grpObj->SetLHCPeriod(lhcPeriod);
993 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
997 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
999 if (runType.Length() != 0) {
1000 grpObj->SetRunType(runType);
1001 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1005 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1011 //_______________________________________________________________
1013 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1015 //======DAQ FXS======//
1017 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1018 TList* list = GetFileSources(kDAQ);
1020 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1024 if (list->GetEntries() == 0) {
1025 Log("no raw data tags in this run: nothing to merge!");
1026 delete list; list=0;
1030 TChain *fRawTagChain = new TChain("T");
1032 TIterator* iter = list->MakeIterator();
1034 while ((obj = iter->Next())) {
1035 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1037 Log(Form("Found source %s", objStr->String().Data()));
1038 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1040 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1041 delete fRawTagChain; fRawTagChain=0;
1044 Log(Form("Number of ids: %d",list2->GetEntries()));
1045 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1046 TObjString *idStr = (TObjString *)list2->At(i);
1047 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1048 if (fileName.Length() > 0) {
1049 Log(Form("Adding file in the chain: %s",fileName.Data()));
1050 fRawTagChain->Add(fileName.Data());
1053 Log(Form("Could not retrieve file with id %s from source %s: "
1054 "connection problems with DAQ FXS!",
1055 idStr->String().Data(), objStr->String().Data()));
1056 delete list; list=0;
1057 delete list2; list2=0;
1058 delete fRawTagChain; fRawTagChain=0;
1066 TString fRawDataFileName = "GRP_Merged.tag.root";
1067 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1069 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1070 Log("Error merging raw data files!!!");
1074 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1075 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1078 Log("Problem storing raw data tags in local file!!!");
1080 Log("Raw data tags merged successfully!!");
1085 delete fRawTagChain; fRawTagChain=0;
1087 if (result == kFALSE) {
1095 //_______________________________________________________________
1096 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1099 // processing the info
1100 // stored in the DCS FXS
1101 // coming from the trigger
1103 // Get the CTP counters information
1105 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1106 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1107 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1109 Log(Form("No dummy CTP scalers entry found, going into error..."));
1113 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1115 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1119 AliCDBMetaData metaData;
1120 metaData.SetResponsible("Roman Lietava");
1121 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1122 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1123 Log("Unable to store the dummy CTP scalers object to OCDB!");
1130 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1131 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1132 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1133 if (countersfile.IsNull()) {
1134 Log("No CTP counters files has been found: empty source!");
1138 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1139 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1141 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1145 AliCDBMetaData metaData;
1146 metaData.SetBeamPeriod(0);
1147 metaData.SetResponsible("Roman Lietava");
1148 metaData.SetComment("CTP scalers");
1149 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1150 Log("Unable to store the CTP scalers object to OCDB!");
1161 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1168 //_______________________________________________________________
1170 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1174 // processing DCS DPs
1177 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1178 Int_t nL3Entries = 0;
1179 Int_t nDipoleEntries = 0;
1180 Int_t nEnvEntries = 0;
1181 Int_t nHallProbesEntries = 0;
1182 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1183 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1184 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1185 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1186 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1187 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1188 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1193 //_______________________________________________________________
1195 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1202 Int_t nL3Entries = 0;
1204 TObjArray *array = 0x0;
1206 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1208 AliInfo(Form("==========L3Current==========="));
1209 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1210 indexDP = kL3Current;
1211 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1213 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1216 if (array->GetEntries() == 0){
1217 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1220 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1221 if (floatDCS != NULL){
1222 grpObj->SetL3Current(floatDCS);
1234 ffailedDPs->RemoveAt(indexDP);
1238 if (array) array = 0x0;
1240 AliInfo(Form("==========L3Polarity==========="));
1241 indexDP = kL3Polarity;
1242 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1244 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1247 if (array->GetEntries() == 0){
1248 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1251 Bool_t change = kFALSE;
1252 Char_t charDCS = ProcessBool(array,change);
1253 if (change == kFALSE){
1254 grpObj->SetL3Polarity(charDCS);
1255 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1256 ffailedDPs->RemoveAt(indexDP);
1260 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1261 ffailedDPs->RemoveAt(indexDP);
1265 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]));
1273 //_______________________________________________________________
1275 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1281 Int_t nDipoleEntries = 0;
1282 TObjArray *array = 0x0;
1284 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1286 AliInfo(Form("==========DipoleCurrent==========="));
1287 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1288 indexDP = kDipoleCurrent;
1289 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1291 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1294 if (array->GetEntries() == 0){
1295 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1298 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1299 if (floatDCS != NULL){
1300 grpObj->SetDipoleCurrent(floatDCS);
1312 ffailedDPs->RemoveAt(indexDP);
1316 if (array) array = 0x0;
1318 AliInfo(Form("==========DipolePolarity==========="));
1319 indexDP = kDipolePolarity;
1320 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1322 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1325 if (array->GetEntries() == 0){
1326 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1329 Bool_t change = kFALSE;
1330 Char_t charDCS = ProcessBool(array,change);
1332 grpObj->SetDipolePolarity(charDCS);
1333 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1334 ffailedDPs->RemoveAt(indexDP);
1338 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1339 ffailedDPs->RemoveAt(indexDP);
1343 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]));
1348 return nDipoleEntries;
1351 //_______________________________________________________________
1353 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1357 // evironment conditions (temperature, pressure) info
1359 Int_t nEnvEntries = 0;
1360 TObjArray *array = 0x0;
1363 AliInfo(Form("==========CavernTemperature==========="));
1364 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1365 indexDP = kCavernTemperature;
1366 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1368 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1371 if (array->GetEntries() == 0){
1372 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1375 Float_t *floatDCS = ProcessFloatAll(array);
1376 if (floatDCS != NULL){
1377 grpObj->SetCavernTemperature(floatDCS);
1388 ffailedDPs->RemoveAt(indexDP);
1393 if (array) array = 0x0;
1395 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1396 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1397 //dcsSensorArray->Print();
1398 if( fPressure->NumFits()<kNumSensors ) {
1399 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1401 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1403 AliInfo(Form("==========CavernAtmosPressure==========="));
1404 indexDP = kCavernAtmosPressure;
1405 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1406 TGraph* graph = sensorCavernP2->GetGraph();
1407 AliDebug(3,Form("index = %d",indexDP));
1408 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1409 AliDebug(2,Form("graph = %p",graph));
1410 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1411 if(sensorCavernP2->GetFit() || graph) {
1412 if (sensorCavernP2->GetFit()){
1413 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1416 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1418 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1419 ffailedDPs->RemoveAt(indexDP);
1422 //if (sensorP2) delete sensorP2;
1424 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] ));
1427 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1428 indexDP = kSurfaceAtmosPressure;
1429 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1430 graph = sensorP2->GetGraph();
1431 AliDebug(3,Form("index = %d",indexDP));
1432 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1433 AliDebug(2,Form("graph = %p",graph));
1434 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1435 if(sensorP2->GetFit() || graph) {
1436 if (sensorP2->GetFit()){
1437 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1440 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1442 grpObj->SetSurfaceAtmosPressure(sensorP2);
1443 ffailedDPs->RemoveAt(indexDP);
1446 //if (sensorP2) delete sensorP2;
1448 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] ));
1451 AliInfo(Form("==========CavernAtmosPressure2==========="));
1452 indexDP = kCavernAtmosPressure2;
1453 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1454 graph = sensorCavernP22->GetGraph();
1455 AliDebug(3,Form("index = %d",indexDP));
1456 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1457 AliDebug(2,Form("graph = %p",graph));
1458 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1459 if(sensorCavernP22->GetFit() || graph) {
1460 if (sensorCavernP22->GetFit()){
1461 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1464 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1466 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1467 ffailedDPs->RemoveAt(indexDP);
1470 //if (sensorP2) delete sensorP2;
1472 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] ));
1478 //_______________________________________________________________
1480 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1486 Int_t nHPEntries = 0;
1487 TObjArray *array = 0x0;
1489 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1491 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1492 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()));
1494 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1495 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1496 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1497 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1499 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1502 if (array->GetEntries() == 0){
1503 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1506 Float_t *floatDCS = ProcessFloatAll(array);
1507 if (floatDCS != NULL){
1508 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]));
1509 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1510 for (Int_t kk = 0 ; kk< 5; kk++){
1511 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1523 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1529 Log(Form("Hall Probes = %d ", nHPEntries));
1533 //_________________________________________________________________________
1535 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1539 // returning Spline Fit
1542 Int_t entriesarray = array->GetEntries();
1543 Float_t* value = new Float_t[entriesarray];
1544 Float_t* time = new Float_t[entriesarray];
1545 AliDCSValue* v = 0x0;
1546 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1547 v = (AliDCSValue*)array->At(iarray);
1548 value[iarray] = v->GetFloat();
1549 time[iarray] = v->GetTimeStamp();
1550 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1552 TGraph* gr = new TGraph(entriesarray,value,time);
1554 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1557 AliSplineFit *fit = new AliSplineFit();
1558 fit->SetMinPoints(10);
1559 fit->InitKnots(gr,10,10,0.0);
1563 AliWarning(Form("%s: no fit performed",stringID.Data()));
1569 //_________________________________________________________________________
1571 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1578 TString aDCSString="";
1580 AliDCSValue *v = 0x0;
1581 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1582 v = (AliDCSValue *)array->At(iCount);
1583 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1584 AliError(Form("DCS values for the parameter outside the queried interval"));
1588 if (aDCSString != v->GetChar())
1589 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1591 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1596 //__________________________________________________________________________________________________________________
1598 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1601 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1603 // parameters[0] = mean
1604 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1605 // parameters[2] = median
1606 // parameters[3] = standard deviation wrt mean
1607 // parameters[4] = standard deviation wrt median
1610 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1611 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1612 if (timeStartString.IsNull() || timeStartString.IsNull()){
1613 if (timeStartString.IsNull()){
1614 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1616 else if (timeStartString.IsNull()){
1617 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1619 fdaqStartEndTimeOk = kFALSE;
1623 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1624 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1625 Float_t* parameters = new Float_t[5];
1627 Int_t iCountsRun = 0;
1628 Int_t nCounts = array->GetEntries();
1629 Float_t valueBeforeSOR = 0;
1630 Float_t valueAfterEOR = 0;
1631 Int_t timestampBeforeSOR = -1;
1632 Int_t timestampAfterEOR = -1;
1633 Int_t ientrySOR = -1;
1634 Int_t ientryEOR = -1;
1635 Float_t* arrayValues = 0x0;
1636 Double_t* arrayWeights = 0x0;
1637 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1638 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1640 for(Int_t i = 0; i < nCounts; i++) {
1641 AliDCSValue *v = (AliDCSValue *)array->At(i);
1642 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1643 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1644 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1645 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1648 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1649 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1651 // look for the last value before SOR and the first value before EOR
1652 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1653 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1654 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1655 valueBeforeSOR = v->GetFloat();
1657 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1658 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1659 valueAfterEOR = v->GetFloat();
1660 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1662 // check if there are DPs between DAQ_time_start and DAQ_time_end
1663 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1664 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1665 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1666 AliDebug(2,Form("entry between SOR and EOR"));
1671 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1675 if (timestampBeforeSOR == -1){
1676 AliWarning("No value found before SOR");
1678 if (timestampAfterEOR == -1){
1679 AliWarning("No value found after EOR");
1682 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1683 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1684 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1685 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1686 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1687 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1689 Int_t nentriesUsed = 0;
1690 if (iCountsRun > 1){
1691 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1692 AliDebug(2,"Calculating (weighted) Mean and Median");
1693 arrayValues = new Float_t[iCountsRun];
1694 arrayWeights = new Double_t[iCountsRun];
1695 nentriesUsed = iCountsRun;
1696 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1697 AliDCSValue *v = (AliDCSValue *)array->At(i);
1698 Int_t timestamp2 = 0;
1700 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1701 timestamp2 = (Int_t)v1->GetTimeStamp();
1704 timestamp2 = timeEnd+1;
1706 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1707 arrayValues[i-ientrySOR] = v->GetFloat();
1709 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1710 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1712 else if (iCountsRun == 1){
1713 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1715 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1716 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.");
1717 arrayValues = new Float_t[2];
1718 arrayWeights = new Double_t[2];
1719 arrayValues[0] = valueBeforeSOR;
1720 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1721 arrayValues[1] = v->GetFloat();
1722 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1723 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1724 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1725 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1726 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1727 truncMeanFlag = kFALSE;
1730 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");
1731 parameters[0] = AliGRPObject::GetInvalidFloat();
1732 parameters[1] = AliGRPObject::GetInvalidFloat();
1733 parameters[2] = AliGRPObject::GetInvalidFloat();
1734 parameters[3] = AliGRPObject::GetInvalidFloat();
1735 parameters[4] = AliGRPObject::GetInvalidFloat();
1739 else { // iCountsRun == 0, using only the point immediately before SOR
1740 if (timestampBeforeSOR == -1){
1741 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");
1742 parameters[0] = AliGRPObject::GetInvalidFloat();
1743 parameters[1] = AliGRPObject::GetInvalidFloat();
1744 parameters[2] = AliGRPObject::GetInvalidFloat();
1745 parameters[3] = AliGRPObject::GetInvalidFloat();
1746 parameters[4] = AliGRPObject::GetInvalidFloat();
1750 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1751 AliDebug(2,Form("value = %f",valueBeforeSOR));
1752 parameters[0] = valueBeforeSOR;
1753 parameters[2] = valueBeforeSOR;
1754 truncMeanFlag = kFALSE;
1761 Float_t sumweights = 0;
1762 Int_t entriesTruncMean = 0;
1763 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1764 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1766 // calculating SD wrt Mean and Median
1767 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1769 for (Int_t i =0; i< nentriesUsed; i++){
1770 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1771 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1772 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1773 sumweights += arrayWeights[i];
1775 // setting SD wrt Mean
1776 if (sumweights != 0 ){
1777 parameters[3] = TMath::Sqrt(temp1/sumweights);
1780 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1781 parameters[3] = AliGRPObject::GetInvalidFloat();
1783 // setting SD wrt Median
1784 if (nentriesUsed != 0){
1785 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1788 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1789 parameters[4] = AliGRPObject::GetInvalidFloat();
1793 parameters[3] = AliGRPObject::GetInvalidFloat();
1794 parameters[4] = AliGRPObject::GetInvalidFloat();
1797 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1799 AliDebug(2,"Calculating Truncated Mean");
1800 for (Int_t i =0; i< nentriesUsed; i++){
1801 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1802 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1803 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1804 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1805 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1809 AliDebug(2,"Discarding entry");
1812 // setting truncated mean
1813 if (entriesTruncMean >1){
1814 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1815 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1818 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1819 parameters[1] = AliGRPObject::GetInvalidFloat();
1823 parameters[1] = AliGRPObject::GetInvalidFloat();
1826 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1827 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1828 AliInfo(Form("median = %f ",parameters[2]));
1829 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1830 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1835 //__________________________________________________________________________________________________________________
1837 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1840 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1841 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1842 // the flag is set according to the L3/Dipole current value
1843 // current threshold for L3 = 350 A (value provided by DCS)
1844 // current threshold for Dipole = 450 A (value provided by DCS)
1846 // parameters[0] = mean
1847 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1848 // parameters[2] = median
1849 // parameters[3] = standard deviation wrt mean
1850 // parameters[4] = standard deviation wrt median
1853 AliInfo(Form("indexDP = %d",indexDP));
1855 Int_t nCounts = array->GetEntries();
1856 for(Int_t i = 0; i < nCounts; i++) {
1857 AliDCSValue *v = (AliDCSValue *)array->At(i);
1858 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1859 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1860 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1861 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1864 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1865 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1866 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1867 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1870 AliError(Form("DCS values for the parameter outside the queried interval"));
1874 return ProcessFloatAll(array);
1878 //_______________________________________________________________
1880 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1883 // processing Boolean values
1886 Bool_t aDCSBool = kTRUE;
1888 AliDCSValue *v = 0x0;
1890 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1891 v = (AliDCSValue *)array->At(iCount);
1892 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1893 AliError(Form("DCS values for the parameter outside the queried interval"));
1897 if (aDCSBool != v->GetBool()) {
1898 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1902 aDCSBool = v->GetBool(); // always keeping last value
1903 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1906 Char_t caDCSBool = (Char_t) aDCSBool;
1911 //_______________________________________________________________
1913 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1916 // processing Int values, returning mean
1917 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1918 // are outside the queried time interval or their value is out of range
1921 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1922 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1923 if (timeStartString.IsNull() || timeStartString.IsNull()){
1924 if (timeStartString.IsNull()){
1925 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1927 else if (timeStartString.IsNull()){
1928 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1933 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1934 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1935 Float_t aDCSArrayMean = 0.0;
1937 Float_t valueBeforeSOR = 0;
1938 Float_t valueAfterEOR = 0;
1939 Int_t timestampBeforeSOR = -1;
1940 Int_t timestampAfterEOR = -1;
1941 Int_t ientrySOR = -1;
1942 Int_t ientryEOR = -1;
1943 Float_t* arrayValues = 0x0;
1944 Double_t* arrayWeights = 0x0;
1945 Int_t iCountsRun = 0;
1946 Int_t nCounts = array->GetEntries();
1948 for(Int_t i = 0; i < nCounts; i++) {
1949 AliDCSValue* v = (AliDCSValue *)array->At(i);
1950 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1951 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1952 return AliGRPObject::GetInvalidFloat();
1954 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1955 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1957 // look for the last value before SOR and the first value before EOR
1958 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1959 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1960 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1961 valueBeforeSOR = (Float_t) v->GetInt();
1963 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1964 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1965 valueAfterEOR = (Float_t) v->GetInt();
1966 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1968 // check if there are DPs between DAQ_time_start and DAQ_time_end
1969 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1970 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1971 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1972 AliDebug(2,Form("entry between SOR and EOR"));
1977 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1981 if (timestampBeforeSOR == -1){
1982 AliWarning("No value found before SOR!");
1984 if (timestampAfterEOR == -1){
1985 AliWarning("No value found after EOR!");
1988 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1989 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1990 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1991 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1992 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1993 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1995 Int_t nentriesUsed = 0;
1996 if (iCountsRun > 1){
1997 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1998 AliDebug(2,"Calculating (weighted) Mean");
1999 arrayValues = new Float_t[iCountsRun];
2000 arrayWeights = new Double_t[iCountsRun];
2001 nentriesUsed = iCountsRun;
2002 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2003 AliDCSValue *v = (AliDCSValue *)array->At(i);
2004 Int_t timestamp2 = 0;
2006 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2007 timestamp2 = (Int_t)v1->GetTimeStamp();
2010 timestamp2 = timeEnd+1;
2012 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2013 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2015 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2017 else if (iCountsRun == 1){
2018 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2020 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2021 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2022 arrayValues = new Float_t[2];
2023 arrayWeights = new Double_t[2];
2024 arrayValues[0] = valueBeforeSOR;
2025 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2026 arrayValues[1] = (Float_t)v->GetInt();
2027 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2028 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2029 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2030 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2033 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2034 return AliGRPObject::GetInvalidFloat();
2037 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2038 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2039 if (timestampBeforeSOR == -1){
2040 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2042 if (timestampAfterEOR == -1){
2043 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2045 return AliGRPObject::GetInvalidFloat();
2048 AliWarning("Using last entry before SOR and first entry after EOR.");
2050 arrayValues = new Float_t[2];
2051 arrayWeights = new Double_t[2];
2052 arrayValues[0] = valueBeforeSOR;
2053 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2054 arrayValues[1] = valueAfterEOR;
2055 arrayWeights[1] = 1.;
2056 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2057 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2058 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2062 AliInfo(Form("mean = %f ", aDCSArrayMean));
2063 return aDCSArrayMean;
2066 //_______________________________________________________________
2068 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2071 // processing Int values, returning mean
2072 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2073 // are outside the queried time interval or their value is out of range
2076 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2077 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2078 if (timeStartString.IsNull() || timeStartString.IsNull()){
2079 if (timeStartString.IsNull()){
2080 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2082 else if (timeStartString.IsNull()){
2083 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2088 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2089 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2090 Float_t aDCSArrayMean = 0.0;
2092 Float_t valueBeforeSOR = 0;
2093 Float_t valueAfterEOR = 0;
2094 Int_t timestampBeforeSOR = -1;
2095 Int_t timestampAfterEOR = -1;
2096 Int_t ientrySOR = -1;
2097 Int_t ientryEOR = -1;
2098 Float_t* arrayValues = 0x0;
2099 Double_t* arrayWeights = 0x0;
2100 Int_t iCountsRun = 0;
2101 Int_t nCounts = array->GetEntries();
2103 for(Int_t i = 0; i < nCounts; i++) {
2104 AliDCSValue* v = (AliDCSValue *)array->At(i);
2105 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2106 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2107 return AliGRPObject::GetInvalidFloat();
2109 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2110 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2112 // look for the last value before SOR and the first value before EOR
2113 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2114 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2115 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2116 valueBeforeSOR = (Float_t)v->GetUInt();
2118 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2119 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2120 valueAfterEOR = (Float_t)v->GetUInt();
2121 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2123 // check if there are DPs between DAQ_time_start and DAQ_time_end
2124 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2125 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2126 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2127 AliDebug(2,Form("entry between SOR and EOR"));
2132 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2136 if (timestampBeforeSOR == -1){
2137 AliWarning("No value found before SOR!");
2139 if (timestampAfterEOR == -1){
2140 AliWarning("No value found after EOR!");
2143 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2144 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2145 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2146 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2147 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2148 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2150 Int_t nentriesUsed = 0;
2151 if (iCountsRun > 1){
2152 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2153 AliDebug(2,"Calculating (weighted) Mean");
2154 arrayValues = new Float_t[iCountsRun];
2155 arrayWeights = new Double_t[iCountsRun];
2156 nentriesUsed = iCountsRun;
2157 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2158 AliDCSValue *v = (AliDCSValue *)array->At(i);
2159 Int_t timestamp2 = 0;
2161 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2162 timestamp2 = (Int_t)v1->GetTimeStamp();
2165 timestamp2 = timeEnd+1;
2167 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2168 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2170 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2172 else if (iCountsRun == 1){
2173 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2175 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2176 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2177 arrayValues = new Float_t[2];
2178 arrayWeights = new Double_t[2];
2179 arrayValues[0] = valueBeforeSOR;
2180 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2181 arrayValues[1] = (Float_t)v->GetUInt();
2182 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2183 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2184 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2185 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2188 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2189 return AliGRPObject::GetInvalidFloat();
2192 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2193 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2194 if (timestampBeforeSOR == -1){
2195 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2197 if (timestampAfterEOR == -1){
2198 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2200 return AliGRPObject::GetInvalidFloat();
2203 AliWarning("Using last entry before SOR and first entry after EOR.");
2205 arrayValues = new Float_t[2];
2206 arrayWeights = new Double_t[2];
2207 arrayValues[0] = valueBeforeSOR;
2208 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2209 arrayValues[1] = valueAfterEOR;
2210 arrayWeights[1] = 1.;
2211 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2212 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2213 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2217 AliInfo(Form("mean = %f ",aDCSArrayMean));
2218 return aDCSArrayMean;
2223 //_______________________________________________________________
2225 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2227 // extract DCS pressure maps. Perform fits to save space
2229 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2231 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2232 fPressure->MakeSplineFit(map);
2233 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2234 if (fitFraction > kFitFraction ) {
2235 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2237 AliInfo("Too few pressure maps fitted!!!");
2240 AliInfo("no atmospheric pressure map extracted!!!");
2249 //_______________________________________________________________
2250 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)
2253 // Retrieves logbook and trigger information from the online logbook
2254 // This information is needed for prompt reconstruction
2258 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2262 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2263 // 0 on success and no run was found
2264 // negative on error
2266 // This function is NOT called during the preprocessor run in the Shuttle!
2274 AliCDBManager* cdb = AliCDBManager::Instance();
2275 cdb->SetDefaultStorage(cdbRoot);
2278 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2282 Printf("ERROR: Could not connect to DAQ LB");
2288 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2289 TSQLResult* result = server->Query(sqlQuery);
2292 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2296 if (result->GetRowCount() == 0)
2298 Printf("ERROR: Run %d not found", run);
2303 TSQLRow* row = result->Next();
2306 Printf("ERROR: Could not receive data from run %d", run);
2311 TString timeStartString(row->GetField(0));
2312 TString runType(row->GetField(1));
2313 TString detectorMaskString(row->GetField(2));
2314 TString l3CurrentString(row->GetField(3));
2315 TString dipoleCurrentString(row->GetField(4));
2316 time_t timeStart = (time_t)(timeStartString.Atoi());
2317 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2318 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2319 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2320 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2321 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2323 AliGRPObject * grpObj = new AliGRPObject();
2324 grpObj->SetTimeStart(timeStart);
2325 grpObj->SetRunType((TString)(row->GetField(1)));
2326 grpObj->SetDetectorMask(detectorMask);
2327 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2328 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2329 grpObj->SetL3Polarity(l3Polarity);
2330 grpObj->SetDipolePolarity(dipolePolarity);
2331 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2339 Printf("Storing GRP/GRP/Data object with the following content");
2342 AliCDBMetaData metadata;
2343 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2344 metadata.SetComment("GRP Output parameters received during online running");
2346 AliCDBId id("GRP/GRP/Data", run, run);
2347 Bool_t success = cdb->Put(grpObj, id, &metadata);
2353 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2357 // Receive trigger information
2358 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2359 result = server->Query(sqlQuery);
2362 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2366 if (result->GetRowCount() == 0)
2368 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2373 row = result->Next();
2376 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2381 TString triggerConfig(row->GetField(0));
2389 Printf("Found trigger configuration: %s", triggerConfig.Data());
2391 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2394 Printf("ERROR: Could not create CTP configuration object");
2398 metadata.SetComment("CTP run configuration received during online running");
2400 AliCDBId id2("GRP/CTP/Config", run, run);
2401 success = cdb->Put(runcfg, id2, &metadata);
2408 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2413 // Receive list of GDCs for this run
2414 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2415 result = server->Query(sqlQuery);
2418 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2422 if (result->GetRowCount() == 0)
2424 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2430 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2431 row = result->Next();
2434 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2438 gdc += row->GetField(0);
2448 Printf("Found GDC: %s", gdc.Data());
2450 // get last run with same run type that was already processed by the SHUTTLE
2452 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());
2453 result = server->Query(sqlQuery);
2456 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2460 if (result->GetRowCount() == 0)
2462 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2467 row = result->Next();
2470 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2475 TString lastRunStr(row->GetField(0));
2476 Int_t lastRun = lastRunStr.Atoi();
2478 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2492 //-----------------------------------------------------------------
2493 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* array){
2496 // Calculating mean over TObjArray from LHC Data
2499 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2500 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2501 if (timeStartString.IsNull() || timeStartString.IsNull()){
2502 if (timeStartString.IsNull()){
2503 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2505 else if (timeStartString.IsNull()){
2506 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2511 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2512 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2513 timeStart = 1260646960;
2514 timeEnd = 1260652740;
2515 Double_t* parameters = new Double_t[5];
2516 parameters[0] = -1.;
2517 parameters[1] = -1.;
2518 parameters[2] = -1.;
2519 parameters[3] = -1.;
2520 parameters[4] = -1.;
2522 Int_t iCountsRun = 0;
2523 Int_t nCounts = array->GetEntries();
2524 printf("ncounts = %d\n",nCounts);
2525 Double_t valueBeforeSOR = 0;
2526 Double_t valueAfterEOR = 0;
2527 Double_t timestampBeforeSOR = -1.;
2528 Double_t timestampAfterEOR = -1.;
2529 Int_t ientrySOR = -1;
2530 Int_t ientryEOR = -1;
2531 Double_t* arrayValues = 0x0;
2532 Double_t* arrayWeights = 0x0;
2533 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2534 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2536 for(Int_t i = 0; i < nCounts; i++) {
2537 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2538 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2539 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2541 // look for the last value before SOR and the first value before EOR
2542 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2543 timestampBeforeSOR = dcs->GetTimeStamp();
2544 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2545 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2547 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2548 timestampAfterEOR = dcs->GetTimeStamp();
2549 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2550 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2552 // check if there are DPs between DAQ_time_start and DAQ_time_end
2553 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2554 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2555 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2556 AliDebug(2,Form("entry between SOR and EOR\n"));
2561 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2565 if (timestampBeforeSOR == -1.){
2566 printf("No value found before SOR\n");
2568 if (timestampAfterEOR == -1.){
2569 printf("No value found after EOR\n");
2572 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2573 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2574 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2575 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2576 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2577 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2579 Int_t nentriesUsed = 0;
2580 if (iCountsRun > 1){
2581 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2582 printf("Calculating (weighted) Mean and Median\n" );
2583 arrayValues = new Double_t[iCountsRun];
2584 arrayWeights = new Double_t[iCountsRun];
2585 nentriesUsed = iCountsRun;
2586 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2587 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2588 Double_t timestamp2 = 0;
2590 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2591 timestamp2 = dcs1->GetTimeStamp();
2594 timestamp2 = (Double_t)timeEnd+1;
2596 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2597 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2598 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2600 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2601 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2603 else if (iCountsRun == 1){
2604 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2606 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2607 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");
2608 arrayValues = new Double_t[2];
2609 arrayWeights = new Double_t[2];
2610 arrayValues[0] = valueBeforeSOR;
2611 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2612 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2613 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2614 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2615 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2616 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2617 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2618 truncMeanFlag = kFALSE;
2621 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");
2627 return parameters[0];
2630 else { // iCountsRun == 0, using only the point immediately before SOR
2631 if (timestampBeforeSOR == -1.){
2632 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");
2638 return parameters[0];
2641 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2642 printf("value = %f\n",valueBeforeSOR);
2643 parameters[0] = valueBeforeSOR;
2644 parameters[2] = valueBeforeSOR;
2645 truncMeanFlag = kFALSE;
2652 Double_t sumweights = 0;
2653 Int_t entriesTruncMean = 0;
2654 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2655 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2657 // calculating SD wrt Mean and Median
2658 printf("Calculating SD wrt Mean and SD wrt Median\n");
2660 for (Int_t i =0; i< nentriesUsed; i++){
2661 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2662 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2663 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2664 sumweights += arrayWeights[i];
2666 // setting SD wrt Mean
2667 if (sumweights != 0 ){
2668 parameters[3] = TMath::Sqrt(temp1/sumweights);
2671 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2674 // setting SD wrt Median
2675 if (nentriesUsed != 0){
2676 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2679 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2688 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2690 printf("Calculating Truncated Mean\n");
2691 for (Int_t i =0; i< nentriesUsed; i++){
2692 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2693 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2694 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2695 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2696 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2700 printf("Discarding entry\n");
2703 // setting truncated mean
2704 if (entriesTruncMean >1){
2705 printf("%d entries used for truncated mean\n",entriesTruncMean);
2706 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2709 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2717 printf("(weighted) mean = %f \n",parameters[0]);
2718 printf("(weighted) truncated mean = %f \n",parameters[1]);
2719 printf("median = %f \n",parameters[2]);
2720 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2721 printf("standard deviation with median = %f \n",parameters[4]);
2723 return (parameters[0]);
2725 //------------------------------------------------------------------------------------------------------
2726 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* array, Double_t timeStart, Double_t timeEnd){
2729 // Method to processo LHC Energy information
2730 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2733 Int_t nCounts = array->GetEntries();
2734 Float_t energy = -1;
2735 Bool_t inRange = kFALSE;
2736 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2738 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2741 for(Int_t i = 0; i < nCounts; i++) {
2742 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2743 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2744 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2745 AliInfo(Form("Energy value found = %d, converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),energy));
2750 if (inRange == kFALSE){
2751 AliInfo("No Energy value found between DAQ_time_start and DAQ_time_end - energy will remain invalid!");