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);
630 grpobj->SetBeamEnergy(energy);
631 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
636 AliError("Energy not found in LHC Data file!!!");
639 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
640 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
641 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
642 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
643 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
644 Double_t timeBeamStart = -1; // min validity for Beam Type
645 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
646 Int_t indexMachineMode = -1; // index of measurement used to set Beam Mode
647 Int_t indexBeam = -1; // index of measurement used to set Beam Mode
648 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
649 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
650 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
651 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
652 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
653 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
656 Log("*************BeamMode (LHCState) ");
657 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
658 Int_t nBeamMode = -1;
660 nBeamMode = beamModeArray->GetEntries();
662 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
665 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
666 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
668 if (beamMode->GetTimeStamp()<=timeStart && beamMode->GetTimeStamp()>=timeBeamModeStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
669 timeBeamModeStart = beamMode->GetTimeStamp();
670 indexBeamMode = iBeamMode;
671 foundBeamModeStart = kTRUE;
679 if (!foundBeamModeStart){
680 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
683 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
684 TObjString* beamModeString = beamMode->GetStringArray(0);
685 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
686 grpobj->SetLHCState(beamModeString->String());
687 if (indexBeamMode < nBeamMode-1){
688 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
690 if (beamMode1->GetTimeStamp()<=timeStart){
691 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
693 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
694 timeBeamModeEnd = beamMode1->GetTimeStamp();
695 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
696 TString bmString0 = beamModeString->String();
697 TString bmString1 = beamModeString1->String();
698 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
699 AliWarning(Form("The beam mode changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",bmString0.Data(), bmString1.Data(), bmString0.Data(), timeBeamModeEnd));
700 flagBeamMode = kTRUE;
705 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
710 delete beamModeArray;
713 AliError("Beam mode array not found in LHC Data file!!!");
717 Log("*************MachineMode ");
718 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
719 Int_t nMachineMode = -1;
720 if (machineModeArray){
721 nMachineMode = machineModeArray->GetEntries();
722 if (nMachineMode==0){
723 AliInfo("No Machine Mode found, leaving it empty");
726 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
727 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
729 if (machineMode->GetTimeStamp()<=timeStart && machineMode->GetTimeStamp()>=timeMachineModeStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
730 timeMachineModeStart = machineMode->GetTimeStamp();
731 indexMachineMode = iMachineMode;
732 foundMachineModeStart = kTRUE;
739 if (!foundMachineModeStart){
740 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
743 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
744 TObjString* machineModeString = machineMode->GetStringArray(0);
745 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
746 grpobj->SetMachineMode(machineModeString->String());
747 if (indexMachineMode < nMachineMode-1){
748 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
750 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
751 timeMachineModeEnd = machineMode1->GetTimeStamp();
752 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
753 TString mmString0 = machineModeString->String();
754 TString mmString1 = machineModeString1->String();
755 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
756 AliWarning(Form("The machine mode changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",mmString0.Data(),mmString1.Data(),mmString0.Data(),timeMachineModeEnd));
757 flagMachineMode = kTRUE;
762 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
767 delete machineModeArray;
770 AliError("Machine mode array not found in LHC Data file!!!");
773 // BeamType1 and BeamType2 - both put in the same string
774 Log("*************BeamType ");
775 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
777 Int_t nBeam = beamArray->GetEntries();
779 AliInfo("No Beam Type found, leaving it empty");
782 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
783 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
785 if (beam->GetTimeStamp()<=timeStart && beam->GetTimeStamp()>=timeBeamStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
786 timeBeamStart = beam->GetTimeStamp();
788 foundBeamStart = kTRUE;
795 if (!foundBeamStart){
796 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
799 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
800 TObjString* beamString = beam->GetStringArray(0);
801 TString beamType = beamString->String();
802 AliInfo(Form("Beam Type = %s",beamType.Data()));
803 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
804 AliInfo("Setting beam type to p-p");
805 grpobj->SetBeamType("p-p");
807 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
808 AliInfo("Setting beam type to Pb-Pb");
809 grpobj->SetBeamType("Pb-Pb");
812 AliError("Beam Type not known, leaving it empty");
814 if (indexBeam < nBeam-1){
815 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
817 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
818 timeBeamEnd = beam1->GetTimeStamp();
819 TObjString* beamString1 = beam1->GetStringArray(0);
820 TString beamType1 = beamString1->String();
821 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
822 AliWarning(Form("The Beam Type changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",beamType.Data(),(beamString1->String()).Data(),beamType.Data(),timeBeamEnd));
828 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
836 AliError("Beam Type array not found in LHC Data file!!!");
839 // Setting minTimeLHCValidity
840 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
841 Double_t minTimeLHCValidity;
842 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true
843 minTimeLHCValidity = timeBeamEnd;
845 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
846 minTimeLHCValidity = timeMachineModeEnd;
848 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
849 minTimeLHCValidity = timeBeamModeEnd;
851 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
852 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
854 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
855 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
857 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
858 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
861 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
862 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
864 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
865 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
868 // Processing data to go to AliLHCData object
869 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
870 // storing AliLHCData in OCDB
872 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
874 md.SetResponsible("Ruben Shahoyan");
875 md.SetComment("LHC data from the GRP preprocessor.");
876 Bool_t result = kTRUE;
877 result = Store("GRP", "LHCData", dt, &md);
879 if (result) return 0;
885 AliError("No LHCData file found in DCS FXS");
892 //_______________________________________________________________
894 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
897 //Getting the SPD Mean Vertex
900 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
901 Bool_t storeResult = kTRUE;
902 if (list !=0x0 && list->GetEntries()!=0)
904 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
906 for (Int_t jj=0;jj<list->GetEntries();jj++){
907 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
908 AliInfo(Form("found source %s", str->String().Data()));
909 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
910 if (fileNameRun.Length()>0){
911 AliInfo(Form("Got the file %s", fileNameRun.Data()));
912 TFile daqFile(fileNameRun.Data(),"READ");
913 if (daqFile.IsOpen()) {
914 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
917 // storing in the OCDB
919 md.SetResponsible("Cvetan Cheshkov");
920 md.SetComment("SPD Mean Vertex");
921 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
924 AliWarning("No SPD Mean Vertex object found in file");
928 AliError("Can't open file");
929 storeResult = kFALSE;
933 AliWarning("No file found for current source for SPD Mean Vertex");
938 AliWarning("No list found for SPD Mean Vertex");
941 if (list) delete list;
947 //_______________________________________________________________
949 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
951 //Getting the DAQ lb information
953 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
954 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
955 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
956 TString beamType = (TString)GetRunParameter("beamType");
957 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
958 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
959 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
960 TString runType = (TString)GetRunType();
962 UInt_t nparameter = 0;
964 grpObj->SetTimeStart(timeStart);
965 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
969 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
973 grpObj->SetTimeEnd(timeEnd);
974 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
978 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
981 if (beamEnergy != 0){
982 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
985 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
989 if (beamType.Length() != 0){
990 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()));
993 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
996 if (numberOfDetectors != 0){
997 grpObj->SetNumberOfDetectors(numberOfDetectors);
998 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1002 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1005 if (detectorMask != 0){
1006 grpObj->SetDetectorMask(detectorMask);
1007 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1011 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1014 if (lhcPeriod.Length() != 0) {
1015 grpObj->SetLHCPeriod(lhcPeriod);
1016 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1020 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1022 if (runType.Length() != 0) {
1023 grpObj->SetRunType(runType);
1024 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1028 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1034 //_______________________________________________________________
1036 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1038 //======DAQ FXS======//
1040 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1041 TList* list = GetFileSources(kDAQ);
1043 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1047 if (list->GetEntries() == 0) {
1048 Log("no raw data tags in this run: nothing to merge!");
1049 delete list; list=0;
1053 TChain *fRawTagChain = new TChain("T");
1055 TIterator* iter = list->MakeIterator();
1057 while ((obj = iter->Next())) {
1058 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1060 Log(Form("Found source %s", objStr->String().Data()));
1061 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1063 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1064 delete fRawTagChain; fRawTagChain=0;
1067 Log(Form("Number of ids: %d",list2->GetEntries()));
1068 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1069 TObjString *idStr = (TObjString *)list2->At(i);
1070 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1071 if (fileName.Length() > 0) {
1072 Log(Form("Adding file in the chain: %s",fileName.Data()));
1073 fRawTagChain->Add(fileName.Data());
1076 Log(Form("Could not retrieve file with id %s from source %s: "
1077 "connection problems with DAQ FXS!",
1078 idStr->String().Data(), objStr->String().Data()));
1079 delete list; list=0;
1080 delete list2; list2=0;
1081 delete fRawTagChain; fRawTagChain=0;
1089 TString fRawDataFileName = "GRP_Merged.tag.root";
1090 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1092 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1093 Log("Error merging raw data files!!!");
1097 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1098 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1101 Log("Problem storing raw data tags in local file!!!");
1103 Log("Raw data tags merged successfully!!");
1108 delete fRawTagChain; fRawTagChain=0;
1110 if (result == kFALSE) {
1118 //_______________________________________________________________
1119 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1122 // processing the info
1123 // stored in the DCS FXS
1124 // coming from the trigger
1126 // Get the CTP counters information
1128 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1129 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1130 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1132 Log(Form("No dummy CTP scalers entry found, going into error..."));
1136 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1138 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1142 AliCDBMetaData metaData;
1143 metaData.SetResponsible("Roman Lietava");
1144 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1145 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1146 Log("Unable to store the dummy CTP scalers object to OCDB!");
1153 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1154 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1155 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1156 if (countersfile.IsNull()) {
1157 Log("No CTP counters files has been found: empty source!");
1161 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1162 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1164 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1168 AliCDBMetaData metaData;
1169 metaData.SetBeamPeriod(0);
1170 metaData.SetResponsible("Roman Lietava");
1171 metaData.SetComment("CTP scalers");
1172 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1173 Log("Unable to store the CTP scalers object to OCDB!");
1184 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1191 //_______________________________________________________________
1193 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1197 // processing DCS DPs
1200 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1201 Int_t nL3Entries = 0;
1202 Int_t nDipoleEntries = 0;
1203 Int_t nEnvEntries = 0;
1204 Int_t nHallProbesEntries = 0;
1205 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1206 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1207 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1208 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1209 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1210 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1211 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1216 //_______________________________________________________________
1218 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1225 Int_t nL3Entries = 0;
1227 TObjArray *array = 0x0;
1229 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1231 AliInfo(Form("==========L3Current==========="));
1232 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1233 indexDP = kL3Current;
1234 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1236 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1239 if (array->GetEntries() == 0){
1240 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1243 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1244 if (floatDCS != NULL){
1245 grpObj->SetL3Current(floatDCS);
1257 ffailedDPs->RemoveAt(indexDP);
1261 if (array) array = 0x0;
1263 AliInfo(Form("==========L3Polarity==========="));
1264 indexDP = kL3Polarity;
1265 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1267 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1270 if (array->GetEntries() == 0){
1271 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1274 Bool_t change = kFALSE;
1275 Char_t charDCS = ProcessBool(array,change);
1276 if (change == kFALSE){
1277 grpObj->SetL3Polarity(charDCS);
1278 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1279 ffailedDPs->RemoveAt(indexDP);
1283 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1284 ffailedDPs->RemoveAt(indexDP);
1288 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]));
1296 //_______________________________________________________________
1298 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1304 Int_t nDipoleEntries = 0;
1305 TObjArray *array = 0x0;
1307 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1309 AliInfo(Form("==========DipoleCurrent==========="));
1310 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1311 indexDP = kDipoleCurrent;
1312 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1314 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1317 if (array->GetEntries() == 0){
1318 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1321 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1322 if (floatDCS != NULL){
1323 grpObj->SetDipoleCurrent(floatDCS);
1335 ffailedDPs->RemoveAt(indexDP);
1339 if (array) array = 0x0;
1341 AliInfo(Form("==========DipolePolarity==========="));
1342 indexDP = kDipolePolarity;
1343 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1345 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1348 if (array->GetEntries() == 0){
1349 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1352 Bool_t change = kFALSE;
1353 Char_t charDCS = ProcessBool(array,change);
1355 grpObj->SetDipolePolarity(charDCS);
1356 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1357 ffailedDPs->RemoveAt(indexDP);
1361 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1362 ffailedDPs->RemoveAt(indexDP);
1366 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]));
1371 return nDipoleEntries;
1374 //_______________________________________________________________
1376 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1380 // evironment conditions (temperature, pressure) info
1382 Int_t nEnvEntries = 0;
1383 TObjArray *array = 0x0;
1386 AliInfo(Form("==========CavernTemperature==========="));
1387 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1388 indexDP = kCavernTemperature;
1389 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1391 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1394 if (array->GetEntries() == 0){
1395 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1398 Float_t *floatDCS = ProcessFloatAll(array);
1399 if (floatDCS != NULL){
1400 grpObj->SetCavernTemperature(floatDCS);
1411 ffailedDPs->RemoveAt(indexDP);
1416 if (array) array = 0x0;
1418 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1419 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1420 //dcsSensorArray->Print();
1421 if( fPressure->NumFits()<kNumSensors ) {
1422 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1424 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1426 AliInfo(Form("==========CavernAtmosPressure==========="));
1427 indexDP = kCavernAtmosPressure;
1428 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1429 TGraph* graph = sensorCavernP2->GetGraph();
1430 AliDebug(3,Form("index = %d",indexDP));
1431 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1432 AliDebug(2,Form("graph = %p",graph));
1433 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1434 if(sensorCavernP2->GetFit() || graph) {
1435 if (sensorCavernP2->GetFit()){
1436 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1439 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1441 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1442 ffailedDPs->RemoveAt(indexDP);
1445 //if (sensorP2) delete sensorP2;
1447 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] ));
1450 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1451 indexDP = kSurfaceAtmosPressure;
1452 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1453 graph = sensorP2->GetGraph();
1454 AliDebug(3,Form("index = %d",indexDP));
1455 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1456 AliDebug(2,Form("graph = %p",graph));
1457 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1458 if(sensorP2->GetFit() || graph) {
1459 if (sensorP2->GetFit()){
1460 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1463 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1465 grpObj->SetSurfaceAtmosPressure(sensorP2);
1466 ffailedDPs->RemoveAt(indexDP);
1469 //if (sensorP2) delete sensorP2;
1471 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] ));
1474 AliInfo(Form("==========CavernAtmosPressure2==========="));
1475 indexDP = kCavernAtmosPressure2;
1476 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1477 graph = sensorCavernP22->GetGraph();
1478 AliDebug(3,Form("index = %d",indexDP));
1479 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1480 AliDebug(2,Form("graph = %p",graph));
1481 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1482 if(sensorCavernP22->GetFit() || graph) {
1483 if (sensorCavernP22->GetFit()){
1484 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1487 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1489 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1490 ffailedDPs->RemoveAt(indexDP);
1493 //if (sensorP2) delete sensorP2;
1495 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] ));
1501 //_______________________________________________________________
1503 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1509 Int_t nHPEntries = 0;
1510 TObjArray *array = 0x0;
1512 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1514 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1515 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()));
1517 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1518 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1519 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1520 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1522 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1525 if (array->GetEntries() == 0){
1526 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1529 Float_t *floatDCS = ProcessFloatAll(array);
1530 if (floatDCS != NULL){
1531 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]));
1532 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1533 for (Int_t kk = 0 ; kk< 5; kk++){
1534 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1546 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1552 Log(Form("Hall Probes = %d ", nHPEntries));
1556 //_________________________________________________________________________
1558 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1562 // returning Spline Fit
1565 Int_t entriesarray = array->GetEntries();
1566 Float_t* value = new Float_t[entriesarray];
1567 Float_t* time = new Float_t[entriesarray];
1568 AliDCSValue* v = 0x0;
1569 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1570 v = (AliDCSValue*)array->At(iarray);
1571 value[iarray] = v->GetFloat();
1572 time[iarray] = v->GetTimeStamp();
1573 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1575 TGraph* gr = new TGraph(entriesarray,value,time);
1577 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1580 AliSplineFit *fit = new AliSplineFit();
1581 fit->SetMinPoints(10);
1582 fit->InitKnots(gr,10,10,0.0);
1586 AliWarning(Form("%s: no fit performed",stringID.Data()));
1592 //_________________________________________________________________________
1594 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1601 TString aDCSString="";
1603 AliDCSValue *v = 0x0;
1604 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1605 v = (AliDCSValue *)array->At(iCount);
1606 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1607 AliError(Form("DCS values for the parameter outside the queried interval"));
1611 if (aDCSString != v->GetChar())
1612 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1614 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1619 //__________________________________________________________________________________________________________________
1621 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1624 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1626 // parameters[0] = mean
1627 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1628 // parameters[2] = median
1629 // parameters[3] = standard deviation wrt mean
1630 // parameters[4] = standard deviation wrt median
1633 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1634 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1635 if (timeStartString.IsNull() || timeStartString.IsNull()){
1636 if (timeStartString.IsNull()){
1637 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1639 else if (timeStartString.IsNull()){
1640 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1642 fdaqStartEndTimeOk = kFALSE;
1646 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1647 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1648 Float_t* parameters = new Float_t[5];
1650 Int_t iCountsRun = 0;
1651 Int_t nCounts = array->GetEntries();
1652 Float_t valueBeforeSOR = 0;
1653 Float_t valueAfterEOR = 0;
1654 Int_t timestampBeforeSOR = -1;
1655 Int_t timestampAfterEOR = -1;
1656 Int_t ientrySOR = -1;
1657 Int_t ientryEOR = -1;
1658 Float_t* arrayValues = 0x0;
1659 Double_t* arrayWeights = 0x0;
1660 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1661 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1663 for(Int_t i = 0; i < nCounts; i++) {
1664 AliDCSValue *v = (AliDCSValue *)array->At(i);
1665 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1666 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1667 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1668 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1671 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1672 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1674 // look for the last value before SOR and the first value before EOR
1675 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1676 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1677 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1678 valueBeforeSOR = v->GetFloat();
1680 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1681 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1682 valueAfterEOR = v->GetFloat();
1683 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1685 // check if there are DPs between DAQ_time_start and DAQ_time_end
1686 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1687 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1688 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1689 AliDebug(2,Form("entry between SOR and EOR"));
1694 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1698 if (timestampBeforeSOR == -1){
1699 AliWarning("No value found before SOR");
1701 if (timestampAfterEOR == -1){
1702 AliWarning("No value found after EOR");
1705 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1706 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1707 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1708 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1709 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1710 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1712 Int_t nentriesUsed = 0;
1713 if (iCountsRun > 1){
1714 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1715 AliDebug(2,"Calculating (weighted) Mean and Median");
1716 arrayValues = new Float_t[iCountsRun];
1717 arrayWeights = new Double_t[iCountsRun];
1718 nentriesUsed = iCountsRun;
1719 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1720 AliDCSValue *v = (AliDCSValue *)array->At(i);
1721 Int_t timestamp2 = 0;
1723 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1724 timestamp2 = (Int_t)v1->GetTimeStamp();
1727 timestamp2 = timeEnd+1;
1729 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1730 arrayValues[i-ientrySOR] = v->GetFloat();
1732 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1733 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1735 else if (iCountsRun == 1){
1736 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1738 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1739 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.");
1740 arrayValues = new Float_t[2];
1741 arrayWeights = new Double_t[2];
1742 arrayValues[0] = valueBeforeSOR;
1743 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1744 arrayValues[1] = v->GetFloat();
1745 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1746 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1747 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1748 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1749 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1750 truncMeanFlag = kFALSE;
1753 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");
1754 parameters[0] = AliGRPObject::GetInvalidFloat();
1755 parameters[1] = AliGRPObject::GetInvalidFloat();
1756 parameters[2] = AliGRPObject::GetInvalidFloat();
1757 parameters[3] = AliGRPObject::GetInvalidFloat();
1758 parameters[4] = AliGRPObject::GetInvalidFloat();
1762 else { // iCountsRun == 0, using only the point immediately before SOR
1763 if (timestampBeforeSOR == -1){
1764 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");
1765 parameters[0] = AliGRPObject::GetInvalidFloat();
1766 parameters[1] = AliGRPObject::GetInvalidFloat();
1767 parameters[2] = AliGRPObject::GetInvalidFloat();
1768 parameters[3] = AliGRPObject::GetInvalidFloat();
1769 parameters[4] = AliGRPObject::GetInvalidFloat();
1773 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1774 AliDebug(2,Form("value = %f",valueBeforeSOR));
1775 parameters[0] = valueBeforeSOR;
1776 parameters[2] = valueBeforeSOR;
1777 truncMeanFlag = kFALSE;
1784 Float_t sumweights = 0;
1785 Int_t entriesTruncMean = 0;
1786 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1787 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1789 // calculating SD wrt Mean and Median
1790 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1792 for (Int_t i =0; i< nentriesUsed; i++){
1793 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1794 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1795 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1796 sumweights += arrayWeights[i];
1798 // setting SD wrt Mean
1799 if (sumweights != 0 ){
1800 parameters[3] = TMath::Sqrt(temp1/sumweights);
1803 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1804 parameters[3] = AliGRPObject::GetInvalidFloat();
1806 // setting SD wrt Median
1807 if (nentriesUsed != 0){
1808 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1811 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1812 parameters[4] = AliGRPObject::GetInvalidFloat();
1816 parameters[3] = AliGRPObject::GetInvalidFloat();
1817 parameters[4] = AliGRPObject::GetInvalidFloat();
1820 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1822 AliDebug(2,"Calculating Truncated Mean");
1823 for (Int_t i =0; i< nentriesUsed; i++){
1824 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1825 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1826 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1827 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1828 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1832 AliDebug(2,"Discarding entry");
1835 // setting truncated mean
1836 if (entriesTruncMean >1){
1837 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1838 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1841 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1842 parameters[1] = AliGRPObject::GetInvalidFloat();
1846 parameters[1] = AliGRPObject::GetInvalidFloat();
1849 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1850 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1851 AliInfo(Form("median = %f ",parameters[2]));
1852 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1853 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1858 //__________________________________________________________________________________________________________________
1860 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1863 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1864 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1865 // the flag is set according to the L3/Dipole current value
1866 // current threshold for L3 = 350 A (value provided by DCS)
1867 // current threshold for Dipole = 450 A (value provided by DCS)
1869 // parameters[0] = mean
1870 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1871 // parameters[2] = median
1872 // parameters[3] = standard deviation wrt mean
1873 // parameters[4] = standard deviation wrt median
1876 AliInfo(Form("indexDP = %d",indexDP));
1878 Int_t nCounts = array->GetEntries();
1879 for(Int_t i = 0; i < nCounts; i++) {
1880 AliDCSValue *v = (AliDCSValue *)array->At(i);
1881 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1882 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1883 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1884 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1887 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1888 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1889 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1890 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1893 AliError(Form("DCS values for the parameter outside the queried interval"));
1897 return ProcessFloatAll(array);
1901 //_______________________________________________________________
1903 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1906 // processing Boolean values
1909 Bool_t aDCSBool = kTRUE;
1911 AliDCSValue *v = 0x0;
1913 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1914 v = (AliDCSValue *)array->At(iCount);
1915 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1916 AliError(Form("DCS values for the parameter outside the queried interval"));
1920 if (aDCSBool != v->GetBool()) {
1921 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1925 aDCSBool = v->GetBool(); // always keeping last value
1926 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1929 Char_t caDCSBool = (Char_t) aDCSBool;
1934 //_______________________________________________________________
1936 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1939 // processing Int values, returning mean
1940 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1941 // are outside the queried time interval or their value is out of range
1944 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1945 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1946 if (timeStartString.IsNull() || timeStartString.IsNull()){
1947 if (timeStartString.IsNull()){
1948 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1950 else if (timeStartString.IsNull()){
1951 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1956 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1957 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1958 Float_t aDCSArrayMean = 0.0;
1960 Float_t valueBeforeSOR = 0;
1961 Float_t valueAfterEOR = 0;
1962 Int_t timestampBeforeSOR = -1;
1963 Int_t timestampAfterEOR = -1;
1964 Int_t ientrySOR = -1;
1965 Int_t ientryEOR = -1;
1966 Float_t* arrayValues = 0x0;
1967 Double_t* arrayWeights = 0x0;
1968 Int_t iCountsRun = 0;
1969 Int_t nCounts = array->GetEntries();
1971 for(Int_t i = 0; i < nCounts; i++) {
1972 AliDCSValue* v = (AliDCSValue *)array->At(i);
1973 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1974 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1975 return AliGRPObject::GetInvalidFloat();
1977 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1978 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1980 // look for the last value before SOR and the first value before EOR
1981 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1982 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1983 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1984 valueBeforeSOR = (Float_t) v->GetInt();
1986 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1987 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1988 valueAfterEOR = (Float_t) v->GetInt();
1989 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1991 // check if there are DPs between DAQ_time_start and DAQ_time_end
1992 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1993 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1994 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1995 AliDebug(2,Form("entry between SOR and EOR"));
2000 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2004 if (timestampBeforeSOR == -1){
2005 AliWarning("No value found before SOR!");
2007 if (timestampAfterEOR == -1){
2008 AliWarning("No value found after EOR!");
2011 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2012 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2013 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2014 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2015 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2016 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2018 Int_t nentriesUsed = 0;
2019 if (iCountsRun > 1){
2020 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2021 AliDebug(2,"Calculating (weighted) Mean");
2022 arrayValues = new Float_t[iCountsRun];
2023 arrayWeights = new Double_t[iCountsRun];
2024 nentriesUsed = iCountsRun;
2025 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2026 AliDCSValue *v = (AliDCSValue *)array->At(i);
2027 Int_t timestamp2 = 0;
2029 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2030 timestamp2 = (Int_t)v1->GetTimeStamp();
2033 timestamp2 = timeEnd+1;
2035 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2036 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2038 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2040 else if (iCountsRun == 1){
2041 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2043 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2044 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2045 arrayValues = new Float_t[2];
2046 arrayWeights = new Double_t[2];
2047 arrayValues[0] = valueBeforeSOR;
2048 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2049 arrayValues[1] = (Float_t)v->GetInt();
2050 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2051 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2052 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2053 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2056 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2057 return AliGRPObject::GetInvalidFloat();
2060 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2061 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2062 if (timestampBeforeSOR == -1){
2063 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2065 if (timestampAfterEOR == -1){
2066 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2068 return AliGRPObject::GetInvalidFloat();
2071 AliWarning("Using last entry before SOR and first entry after EOR.");
2073 arrayValues = new Float_t[2];
2074 arrayWeights = new Double_t[2];
2075 arrayValues[0] = valueBeforeSOR;
2076 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2077 arrayValues[1] = valueAfterEOR;
2078 arrayWeights[1] = 1.;
2079 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2080 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2081 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2085 AliInfo(Form("mean = %f ", aDCSArrayMean));
2086 return aDCSArrayMean;
2089 //_______________________________________________________________
2091 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2094 // processing Int values, returning mean
2095 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2096 // are outside the queried time interval or their value is out of range
2099 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2100 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2101 if (timeStartString.IsNull() || timeStartString.IsNull()){
2102 if (timeStartString.IsNull()){
2103 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2105 else if (timeStartString.IsNull()){
2106 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2111 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2112 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2113 Float_t aDCSArrayMean = 0.0;
2115 Float_t valueBeforeSOR = 0;
2116 Float_t valueAfterEOR = 0;
2117 Int_t timestampBeforeSOR = -1;
2118 Int_t timestampAfterEOR = -1;
2119 Int_t ientrySOR = -1;
2120 Int_t ientryEOR = -1;
2121 Float_t* arrayValues = 0x0;
2122 Double_t* arrayWeights = 0x0;
2123 Int_t iCountsRun = 0;
2124 Int_t nCounts = array->GetEntries();
2126 for(Int_t i = 0; i < nCounts; i++) {
2127 AliDCSValue* v = (AliDCSValue *)array->At(i);
2128 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2129 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2130 return AliGRPObject::GetInvalidFloat();
2132 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2133 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2135 // look for the last value before SOR and the first value before EOR
2136 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2137 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2138 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2139 valueBeforeSOR = (Float_t)v->GetUInt();
2141 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2142 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2143 valueAfterEOR = (Float_t)v->GetUInt();
2144 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2146 // check if there are DPs between DAQ_time_start and DAQ_time_end
2147 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2148 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2149 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2150 AliDebug(2,Form("entry between SOR and EOR"));
2155 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2159 if (timestampBeforeSOR == -1){
2160 AliWarning("No value found before SOR!");
2162 if (timestampAfterEOR == -1){
2163 AliWarning("No value found after EOR!");
2166 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2167 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2168 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2169 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2170 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2171 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2173 Int_t nentriesUsed = 0;
2174 if (iCountsRun > 1){
2175 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2176 AliDebug(2,"Calculating (weighted) Mean");
2177 arrayValues = new Float_t[iCountsRun];
2178 arrayWeights = new Double_t[iCountsRun];
2179 nentriesUsed = iCountsRun;
2180 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2181 AliDCSValue *v = (AliDCSValue *)array->At(i);
2182 Int_t timestamp2 = 0;
2184 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2185 timestamp2 = (Int_t)v1->GetTimeStamp();
2188 timestamp2 = timeEnd+1;
2190 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2191 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2193 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2195 else if (iCountsRun == 1){
2196 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2198 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2199 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2200 arrayValues = new Float_t[2];
2201 arrayWeights = new Double_t[2];
2202 arrayValues[0] = valueBeforeSOR;
2203 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2204 arrayValues[1] = (Float_t)v->GetUInt();
2205 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2206 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2207 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2208 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2211 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2212 return AliGRPObject::GetInvalidFloat();
2215 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2216 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2217 if (timestampBeforeSOR == -1){
2218 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2220 if (timestampAfterEOR == -1){
2221 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2223 return AliGRPObject::GetInvalidFloat();
2226 AliWarning("Using last entry before SOR and first entry after EOR.");
2228 arrayValues = new Float_t[2];
2229 arrayWeights = new Double_t[2];
2230 arrayValues[0] = valueBeforeSOR;
2231 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2232 arrayValues[1] = valueAfterEOR;
2233 arrayWeights[1] = 1.;
2234 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2235 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2236 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2240 AliInfo(Form("mean = %f ",aDCSArrayMean));
2241 return aDCSArrayMean;
2246 //_______________________________________________________________
2248 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2250 // extract DCS pressure maps. Perform fits to save space
2252 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2254 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2255 fPressure->MakeSplineFit(map);
2256 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2257 if (fitFraction > kFitFraction ) {
2258 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2260 AliInfo("Too few pressure maps fitted!!!");
2263 AliInfo("no atmospheric pressure map extracted!!!");
2272 //_______________________________________________________________
2273 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)
2276 // Retrieves logbook and trigger information from the online logbook
2277 // This information is needed for prompt reconstruction
2281 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2285 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2286 // 0 on success and no run was found
2287 // negative on error
2289 // This function is NOT called during the preprocessor run in the Shuttle!
2297 AliCDBManager* cdb = AliCDBManager::Instance();
2298 cdb->SetDefaultStorage(cdbRoot);
2301 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2305 Printf("ERROR: Could not connect to DAQ LB");
2311 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2312 TSQLResult* result = server->Query(sqlQuery);
2315 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2319 if (result->GetRowCount() == 0)
2321 Printf("ERROR: Run %d not found", run);
2326 TSQLRow* row = result->Next();
2329 Printf("ERROR: Could not receive data from run %d", run);
2334 TString timeStartString(row->GetField(0));
2335 TString runType(row->GetField(1));
2336 TString detectorMaskString(row->GetField(2));
2337 TString l3CurrentString(row->GetField(3));
2338 TString dipoleCurrentString(row->GetField(4));
2339 time_t timeStart = (time_t)(timeStartString.Atoi());
2340 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2341 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2342 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2343 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2344 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2346 AliGRPObject * grpObj = new AliGRPObject();
2347 grpObj->SetTimeStart(timeStart);
2348 grpObj->SetRunType((TString)(row->GetField(1)));
2349 grpObj->SetDetectorMask(detectorMask);
2350 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2351 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2352 grpObj->SetL3Polarity(l3Polarity);
2353 grpObj->SetDipolePolarity(dipolePolarity);
2354 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2362 Printf("Storing GRP/GRP/Data object with the following content");
2365 AliCDBMetaData metadata;
2366 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2367 metadata.SetComment("GRP Output parameters received during online running");
2369 AliCDBId id("GRP/GRP/Data", run, run);
2370 Bool_t success = cdb->Put(grpObj, id, &metadata);
2376 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2380 // Receive trigger information
2381 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2382 result = server->Query(sqlQuery);
2385 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2389 if (result->GetRowCount() == 0)
2391 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2396 row = result->Next();
2399 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2404 TString triggerConfig(row->GetField(0));
2412 Printf("Found trigger configuration: %s", triggerConfig.Data());
2414 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2417 Printf("ERROR: Could not create CTP configuration object");
2421 metadata.SetComment("CTP run configuration received during online running");
2423 AliCDBId id2("GRP/CTP/Config", run, run);
2424 success = cdb->Put(runcfg, id2, &metadata);
2431 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2436 // Receive list of GDCs for this run
2437 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2438 result = server->Query(sqlQuery);
2441 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2445 if (result->GetRowCount() == 0)
2447 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2453 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2454 row = result->Next();
2457 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2461 gdc += row->GetField(0);
2471 Printf("Found GDC: %s", gdc.Data());
2473 // get last run with same run type that was already processed by the SHUTTLE
2475 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());
2476 result = server->Query(sqlQuery);
2479 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2483 if (result->GetRowCount() == 0)
2485 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2490 row = result->Next();
2493 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2498 TString lastRunStr(row->GetField(0));
2499 Int_t lastRun = lastRunStr.Atoi();
2501 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2515 //-----------------------------------------------------------------
2516 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* const array){
2519 // Calculating mean over TObjArray from LHC Data
2522 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2523 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2524 if (timeStartString.IsNull() || timeStartString.IsNull()){
2525 if (timeStartString.IsNull()){
2526 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2528 else if (timeStartString.IsNull()){
2529 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2534 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2535 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2536 timeStart = 1260646960;
2537 timeEnd = 1260652740;
2538 Double_t* parameters = new Double_t[5];
2539 parameters[0] = -1.;
2540 parameters[1] = -1.;
2541 parameters[2] = -1.;
2542 parameters[3] = -1.;
2543 parameters[4] = -1.;
2545 Int_t iCountsRun = 0;
2546 Int_t nCounts = array->GetEntries();
2547 printf("ncounts = %d\n",nCounts);
2548 Double_t valueBeforeSOR = 0;
2549 Double_t valueAfterEOR = 0;
2550 Double_t timestampBeforeSOR = -1.;
2551 Double_t timestampAfterEOR = -1.;
2552 Int_t ientrySOR = -1;
2553 Int_t ientryEOR = -1;
2554 Double_t* arrayValues = 0x0;
2555 Double_t* arrayWeights = 0x0;
2556 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2557 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2559 for(Int_t i = 0; i < nCounts; i++) {
2560 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2561 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2562 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2564 // look for the last value before SOR and the first value before EOR
2565 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2566 timestampBeforeSOR = dcs->GetTimeStamp();
2567 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2568 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2570 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2571 timestampAfterEOR = dcs->GetTimeStamp();
2572 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2573 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2575 // check if there are DPs between DAQ_time_start and DAQ_time_end
2576 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2577 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2578 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2579 AliDebug(2,Form("entry between SOR and EOR\n"));
2584 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2588 if (timestampBeforeSOR == -1.){
2589 printf("No value found before SOR\n");
2591 if (timestampAfterEOR == -1.){
2592 printf("No value found after EOR\n");
2595 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2596 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2597 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2598 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2599 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2600 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2602 Int_t nentriesUsed = 0;
2603 if (iCountsRun > 1){
2604 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2605 printf("Calculating (weighted) Mean and Median\n" );
2606 arrayValues = new Double_t[iCountsRun];
2607 arrayWeights = new Double_t[iCountsRun];
2608 nentriesUsed = iCountsRun;
2609 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2610 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2611 Double_t timestamp2 = 0;
2613 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2614 timestamp2 = dcs1->GetTimeStamp();
2617 timestamp2 = (Double_t)timeEnd+1;
2619 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2620 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2621 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2623 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2624 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2626 else if (iCountsRun == 1){
2627 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2629 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2630 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");
2631 arrayValues = new Double_t[2];
2632 arrayWeights = new Double_t[2];
2633 arrayValues[0] = valueBeforeSOR;
2634 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2635 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2636 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2637 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2638 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2639 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2640 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2641 truncMeanFlag = kFALSE;
2644 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");
2650 return parameters[0];
2653 else { // iCountsRun == 0, using only the point immediately before SOR
2654 if (timestampBeforeSOR == -1.){
2655 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");
2661 return parameters[0];
2664 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2665 printf("value = %f\n",valueBeforeSOR);
2666 parameters[0] = valueBeforeSOR;
2667 parameters[2] = valueBeforeSOR;
2668 truncMeanFlag = kFALSE;
2675 Double_t sumweights = 0;
2676 Int_t entriesTruncMean = 0;
2677 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2678 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2680 // calculating SD wrt Mean and Median
2681 printf("Calculating SD wrt Mean and SD wrt Median\n");
2683 for (Int_t i =0; i< nentriesUsed; i++){
2684 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2685 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2686 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2687 sumweights += arrayWeights[i];
2689 // setting SD wrt Mean
2690 if (sumweights != 0 ){
2691 parameters[3] = TMath::Sqrt(temp1/sumweights);
2694 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2697 // setting SD wrt Median
2698 if (nentriesUsed != 0){
2699 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2702 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2711 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2713 printf("Calculating Truncated Mean\n");
2714 for (Int_t i =0; i< nentriesUsed; i++){
2715 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2716 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2717 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2718 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2719 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2723 printf("Discarding entry\n");
2726 // setting truncated mean
2727 if (entriesTruncMean >1){
2728 printf("%d entries used for truncated mean\n",entriesTruncMean);
2729 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2732 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2740 printf("(weighted) mean = %f \n",parameters[0]);
2741 printf("(weighted) truncated mean = %f \n",parameters[1]);
2742 printf("median = %f \n",parameters[2]);
2743 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2744 printf("standard deviation with median = %f \n",parameters[4]);
2746 return (parameters[0]);
2748 //------------------------------------------------------------------------------------------------------
2749 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
2752 // Method to processo LHC Energy information
2753 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2756 Int_t nCounts = array->GetEntries();
2757 Float_t energy = -1;
2758 Double_t timeEnergy = -1;
2759 Int_t indexEnergy = -1;
2760 Bool_t foundEnergy = kFALSE;
2762 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2764 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2767 for (Int_t i = 0; i < nCounts; i++){
2768 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2770 if (dcs->GetTimeStamp()<=timeStart && dcs->GetTimeStamp()>=timeEnergy){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
2771 timeEnergy = dcs->GetTimeStamp();
2773 foundEnergy = kTRUE;
2781 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
2784 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
2785 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2786 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));