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>
67 #include <AliLHCClockPhase.h>
69 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
71 ClassImp(AliGRPPreprocessor)
73 //_______________________________________________________________
75 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 6; // num parameters in the logbook used to fill the GRP object
76 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
77 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
78 const Int_t AliGRPPreprocessor::fgknLHCDP = 6; // number of dcs dps from LHC data
79 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
80 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
81 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
89 "L3_BSF17_Temperature",
93 "L3_BSF4_Temperature",
97 "L3_BKF17_Temperature",
101 "L3_BKF4_Temperature",
105 "L3_BSF13_Temperature",
109 "L3_BSF8_Temperature",
113 "L3_BKF13_Temperature",
117 "L3_BKF8_Temperature",
121 "Dipole_Inside_Temperature",
125 "Dipole_Outside_Temperature",
127 "CavernAtmosPressure",
128 "SurfaceAtmosPressure",
129 "CavernAtmosPressure2"
132 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
136 "L3_BSF17_Temperature",
140 "L3_BSF4_Temperature",
144 "L3_BKF17_Temperature",
148 "L3_BKF4_Temperature",
152 "L3_BSF13_Temperature",
156 "L3_BSF8_Temperature",
160 "L3_BKF13_Temperature",
164 "L3_BKF8_Temperature",
168 "Dipole_Inside_Temperature",
172 "Dipole_Outside_Temperature"
175 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
176 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
179 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
183 "LHC_Beams_Particle_Type",
184 "BPTX_Phase_Shift_B1",
185 "BPTX_Phase_Shift_B2"
188 const char* kppError[] = {
190 "(DAQ logbook ERROR)",
192 "(Trigger Scalers not found in DCS FXS - ERROR)",
193 "(DCS data points ERROR)",
194 "(Trigger Configuration ERROR)",
195 "(DAQ logbook ERROR determining partition of the run)",
196 "(CTP timing ERROR)",
197 "(SPD Mean Vertex ERROR)",
198 "(DCS FXS Error for LHC Data)",
200 "(LHC Clock Phase Error (from LHC Data))"
203 //_______________________________________________________________
205 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
206 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))
208 // constructor - shuttle must be instantiated!
210 AddRunType("COSMIC");
212 AddRunType("PHYSICS");
213 AddRunType("CALIBRATION_BC");
214 AddRunType("CALIBRATION_CENTRAL");
215 AddRunType("CALIBRATION_EMD");
216 AddRunType("CALIBRATION_MB");
217 AddRunType("CALIBRATION_SEMICENTRAL");
218 AddRunType("CALIBRATION");
219 AddRunType("PEDESTAL");
220 AddRunType("STANDALONE");
223 AddRunType("PULSER");
224 AddRunType("STANDALONE_PULSER");
225 AddRunType("STANDALONE_BC");
228 fminFloat = -FLT_MAX;
229 fmaxDouble = DBL_MAX;
230 fminDouble = -DBL_MAX;
236 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
237 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
238 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
239 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
240 AliInfo(Form("Max allowed integer = %d",fmaxInt));
241 AliInfo(Form("Min allowed integer = %d",fminInt));
242 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
243 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
245 ffailedDPs->SetOwner(kTRUE);
248 //_______________________________________________________________
250 AliGRPPreprocessor::~AliGRPPreprocessor()
259 //_______________________________________________________________
261 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
263 // Initialize preprocessor
265 AliPreprocessor::Initialize(run, startTime, endTime);
267 AliInfo("Initialization of the GRP preprocessor.");
268 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
269 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
270 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
271 for(Int_t j = 0; j < kNumSensors; j++) {
272 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
273 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
275 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
277 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
279 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
280 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
281 ffailedDPs->AddAt(dp,iDP);
286 //_______________________________________________________________
288 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
290 // process data retrieved by the Shuttle
292 // retrieving "partition" and "detector" fields from DAQ logbook to
293 // determine the partition in which the run was taken
294 // the partition is used to decide how to react in case of errors for CTP
296 TString partition = (TString)GetRunParameter("partition");
297 TString detector = (TString)GetRunParameter("detector");
299 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
300 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
302 //=================//
304 //=================//
306 Log("*************** Processing DAQ logbook");
310 Int_t iDaqLB = ProcessDaqLB(grpobj);
311 TString runType = (TString)GetRunType();
312 TString beamType = (TString)GetRunParameter("beamType");
313 if(iDaqLB == fgknDAQLbPar) {
314 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
316 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
320 //=================//
322 //=================//
324 Log("*************** Processing DAQ FXS");
326 UInt_t iDaqFxs = ProcessDaqFxs();
328 Log(Form("DAQ FXS, successful!"));
330 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
334 //=================//
336 //=================//
338 Log("*************** Processing DCS FXS");
340 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
342 Log(Form("DCS FXS, successful!"));
343 } else if (iDcsFxs ==1) {
344 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
347 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
351 //=================//
352 // DCS data points //
353 //=================//
355 Log("*************** Processing DCS DPs");
357 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
358 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
359 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
360 if (fdaqStartEndTimeOk){
361 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
362 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
363 Log(Form("The DPs giving problems were:"));
364 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
365 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
367 TString name = dpString->String();
368 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
369 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
372 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()));
378 else Log(Form("DCS data points, successful!"));
380 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"));
382 //=======================//
383 // Trigger Configuration //
384 //=======================//
386 Log("*************** Processing Trigger Configuration");
388 const char * triggerConf = GetTriggerConfiguration();
390 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
391 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
392 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
394 Log(Form("No dummy CTP configuration entry found, going into error..."));
398 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
400 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
404 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
405 runcfg->SetTitle(titleCTPcfg);
406 AliCDBMetaData metaData;
407 metaData.SetResponsible("Roman Lietava");
408 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
409 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
410 Log("Unable to store the dummy CTP run configuration object to OCDB!");
417 else if (!partition.IsNull() && detector.IsNull()){ // global partition
418 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
419 if (triggerConf!= NULL) {
420 Log("Found trigger configuration in DAQ logbook");
421 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
423 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
427 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
428 runcfg->SetTitle(titleCTPcfg);
429 AliCDBMetaData metaData;
430 metaData.SetBeamPeriod(0);
431 metaData.SetResponsible("Roman Lietava");
432 metaData.SetComment("CTP run configuration from DAQ logbook");
433 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
434 Log("Unable to store the CTP run configuration object to OCDB!");
441 Log("Trigger configuration NULL in DAQ logbook");
447 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
451 //===========================//
452 // Trigger Timing Parameters //
453 //===========================//
455 Log("*************** Processing Trigger Time Params");
457 const char * triggerCTPtiming = GetCTPTimeParams();
459 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
460 Log("STANDALONE partition for current run, using CTP timing params dummy value");
461 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
463 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
467 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
469 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
473 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
474 runCTPtiming->SetTitle(titleCTPtiming);
475 AliCDBMetaData metadata;
476 metadata.SetResponsible("Roman Lietava");
477 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
478 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
479 Log("Unable to store the dummy CTP timing params object to OCDB!");
486 else if (!partition.IsNull() && detector.IsNull()){ // global partition
487 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
488 if (triggerCTPtiming!= NULL) {
489 Log("Found trigger timing params in DAQ logbook");
490 AliDebug(2,Form("%s",triggerCTPtiming));
491 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
493 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
497 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
498 runCTPtiming->SetTitle(titleCTPtiming);
499 AliCDBMetaData metadata;
500 metadata.SetBeamPeriod(0);
501 metadata.SetResponsible("Roman Lietava");
502 metadata.SetComment("CTP timing params from DAQ logbook");
503 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
504 Log("Unable to store the CTP timing params object to OCDB!");
511 Log("Trigger timing params NULL in DAQ logbook");
517 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
522 //=================//
524 //=================//
526 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
527 Log("*************** Processing LHC Data");
529 UInt_t iLHCData = ProcessLHCData(grpobj);
531 if( iLHCData == 0 ) {
532 Log(Form("LHC Data from DCS FXS, successful!"));
533 } else if (iLHCData == 1) {
534 Log(Form("LHC Data, problems with DCS FXS!"));
536 } else if (iLHCData == 2) {
537 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
539 } else if (iLHCData ==3){
540 Log(Form("Problems in storing LHC Phase - going into Error"));
542 } else if (iLHCData ==4){
543 Log(Form("Problems with LHC Phase - going into Error"));
546 Log(Form("LHC Data problems"));
552 //==================//
553 // SPD Mean Vertex //
554 //==================//
556 Log("*************** Processing SPD Mean Vertex");
558 if (runType == "PHYSICS"){
559 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
560 if( iSPDMeanVertex == 1 ) {
561 Log(Form("SPD Mean Vertex, successful!"));
563 Log(Form("SPD Mean Vertex failed!!!"));
568 Log("SPD Mean Vertex not processed since runType != PHYSICS");
571 // storing AliGRPObject in OCDB
574 md.SetResponsible("Chiara Zampolli");
575 md.SetComment("Output parameters from the GRP preprocessor.");
577 Bool_t result = kTRUE;
578 result = Store("GRP", "Data", grpobj, &md);
581 if (result && !error ) {
582 Log("GRP Preprocessor Success");
585 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s",
586 kppError[(error&1)?1:0],
587 kppError[(error&2)?2:0],
588 kppError[(error&4)?3:0],
589 kppError[(error&8)?4:0],
590 kppError[(error&16)?5:0],
591 kppError[(error&32)?6:0],
592 kppError[(error&64)?7:0],
593 kppError[(error&128)?8:0],
594 kppError[(error&256)?9:0],
595 kppError[(error&512)?10:0],
596 kppError[(error&1024)?11:0]
604 //_______________________________________________________________
606 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
609 //Getting the LHC Data from DCS FXS
612 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
613 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
614 if (timeStartString.IsNull() || timeEndString.IsNull()){
615 if (timeStartString.IsNull()){
616 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
618 else if (timeEndString.IsNull()){
619 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
624 Double_t timeStart = timeStartString.Atof();
625 Double_t timeEnd = timeEndString.Atof();
627 TString fileName = GetFile(kDCS, "LHCData","");
628 if (fileName.Length()>0){
629 AliInfo("Got The LHC Data file");
630 AliLHCReader lhcReader;
632 // Processing data to be put in AliGRPObject
635 Log("*************Energy ");
636 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
638 Float_t energy = ProcessEnergy(energyArray,timeStart);
640 grpobj->SetBeamEnergy(energy);
641 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
646 AliError("Energy not found in LHC Data file!!!");
649 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
650 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
651 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
652 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
653 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
654 Double_t timeBeamStart = -1; // min validity for Beam Type
655 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
656 Int_t indexMachineMode = -1; // index of measurement used to set Beam Mode
657 Int_t indexBeam = -1; // index of measurement used to set Beam Mode
658 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
659 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
660 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
661 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
662 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
663 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
666 Log("*************BeamMode (LHCState) ");
667 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
668 Int_t nBeamMode = -1;
670 nBeamMode = beamModeArray->GetEntries();
672 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
675 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
676 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
678 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
679 timeBeamModeStart = beamMode->GetTimeStamp();
680 indexBeamMode = iBeamMode;
681 foundBeamModeStart = kTRUE;
689 if (!foundBeamModeStart){
690 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
693 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
694 TObjString* beamModeString = beamMode->GetStringArray(0);
695 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
696 grpobj->SetLHCState(beamModeString->String());
697 if (indexBeamMode < nBeamMode-1){
698 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
700 if (beamMode1->GetTimeStamp()<=timeStart){
701 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
703 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
704 timeBeamModeEnd = beamMode1->GetTimeStamp();
705 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
706 TString bmString0 = beamModeString->String();
707 TString bmString1 = beamModeString1->String();
708 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
709 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(), timeBeamModeEnd, bmString0.Data()));
710 flagBeamMode = kTRUE;
715 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
720 delete beamModeArray;
723 AliError("Beam mode array not found in LHC Data file!!!");
727 Log("*************MachineMode ");
728 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
729 Int_t nMachineMode = -1;
730 if (machineModeArray){
731 nMachineMode = machineModeArray->GetEntries();
732 if (nMachineMode==0){
733 AliInfo("No Machine Mode found, leaving it empty");
736 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
737 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
739 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
740 timeMachineModeStart = machineMode->GetTimeStamp();
741 indexMachineMode = iMachineMode;
742 foundMachineModeStart = kTRUE;
749 if (!foundMachineModeStart){
750 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
753 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
754 TObjString* machineModeString = machineMode->GetStringArray(0);
755 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
756 grpobj->SetMachineMode(machineModeString->String());
757 if (indexMachineMode < nMachineMode-1){
758 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
760 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
761 timeMachineModeEnd = machineMode1->GetTimeStamp();
762 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
763 TString mmString0 = machineModeString->String();
764 TString mmString1 = machineModeString1->String();
765 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
766 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(),timeMachineModeEnd,mmString0.Data()));
767 flagMachineMode = kTRUE;
772 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
777 delete machineModeArray;
780 AliError("Machine mode array not found in LHC Data file!!!");
783 // BeamType1 and BeamType2 - both put in the same string
784 Log("*************BeamType ");
785 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
787 Int_t nBeam = beamArray->GetEntries();
789 AliInfo("No Beam Type found, leaving it empty");
792 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
793 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
795 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
796 timeBeamStart = beam->GetTimeStamp();
798 foundBeamStart = kTRUE;
805 if (!foundBeamStart){
806 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
809 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
810 TObjString* beamString = beam->GetStringArray(0);
811 TString beamType = beamString->String();
812 AliInfo(Form("Beam Type = %s",beamType.Data()));
813 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
814 AliInfo("Setting beam type to p-p");
815 grpobj->SetBeamType("p-p");
817 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
818 AliInfo("Setting beam type to Pb-Pb");
819 grpobj->SetBeamType("Pb-Pb");
822 AliError("Beam Type not known, leaving it empty");
824 if (indexBeam < nBeam-1){
825 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
827 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
828 timeBeamEnd = beam1->GetTimeStamp();
829 TObjString* beamString1 = beam1->GetStringArray(0);
830 TString beamType1 = beamString1->String();
831 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
832 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(),timeBeamEnd,beamType.Data()));
838 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
846 AliError("Beam Type array not found in LHC Data file!!!");
849 // Setting minTimeLHCValidity
850 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
851 Double_t minTimeLHCValidity;
852 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true
853 minTimeLHCValidity = timeBeamEnd;
855 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
856 minTimeLHCValidity = timeMachineModeEnd;
858 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
859 minTimeLHCValidity = timeBeamModeEnd;
861 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
862 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
864 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
865 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
867 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
868 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
871 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
872 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
874 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
875 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
878 // Processing data to go to AliLHCData object
879 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
880 // storing AliLHCData in OCDB
882 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
884 md.SetResponsible("Ruben Shahoyan");
885 md.SetComment("LHC data from the GRP preprocessor.");
886 Bool_t result = kTRUE;
887 result = Store("GRP", "LHCData", dt, &md);
890 Log(Form("Problems in storing LHC Data - but not going into Error"));
894 // processing LHC Phase
896 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
897 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
898 if (beam1phase == 0x0 || beam2phase == 0x0){
899 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
902 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeStart,timeEnd);
904 AliInfo(Form("LHC Phase found"));
905 AliCDBMetaData mdPhase;
906 mdPhase.SetResponsible("Cvetan Cheshkov");
907 mdPhase.SetComment("LHC Clock Phase");
908 Bool_t result = kTRUE;
909 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
911 if (!result) return 3;
917 AliError("No LHCData file found in DCS FXS");
924 //_______________________________________________________________
926 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
929 //Getting the SPD Mean Vertex
932 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
933 Bool_t storeResult = kTRUE;
934 if (list !=0x0 && list->GetEntries()!=0)
936 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
938 for (Int_t jj=0;jj<list->GetEntries();jj++){
939 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
940 AliInfo(Form("found source %s", str->String().Data()));
941 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
942 if (fileNameRun.Length()>0){
943 AliInfo(Form("Got the file %s", fileNameRun.Data()));
944 TFile daqFile(fileNameRun.Data(),"READ");
945 if (daqFile.IsOpen()) {
946 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
949 // storing in the OCDB
951 md.SetResponsible("Cvetan Cheshkov");
952 md.SetComment("SPD Mean Vertex");
953 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
956 AliWarning("No SPD Mean Vertex object found in file");
960 AliError("Can't open file");
961 storeResult = kFALSE;
965 AliWarning("No file found for current source for SPD Mean Vertex");
970 AliWarning("No list found for SPD Mean Vertex");
973 if (list) delete list;
979 //_______________________________________________________________
981 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
983 //Getting the DAQ lb information
985 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
986 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
987 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
988 TString beamType = (TString)GetRunParameter("beamType");
989 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
990 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
991 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
992 TString runType = (TString)GetRunType();
994 UInt_t nparameter = 0;
996 grpObj->SetTimeStart(timeStart);
997 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
1001 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1005 grpObj->SetTimeEnd(timeEnd);
1006 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
1010 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1013 if (beamEnergy != 0){
1014 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1017 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1021 if (beamType.Length() != 0){
1022 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()));
1025 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1028 if (numberOfDetectors != 0){
1029 grpObj->SetNumberOfDetectors(numberOfDetectors);
1030 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1034 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1037 if (detectorMask != 0){
1038 grpObj->SetDetectorMask(detectorMask);
1039 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1043 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1046 if (lhcPeriod.Length() != 0) {
1047 grpObj->SetLHCPeriod(lhcPeriod);
1048 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1052 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1054 if (runType.Length() != 0) {
1055 grpObj->SetRunType(runType);
1056 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1060 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1066 //_______________________________________________________________
1068 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1070 //======DAQ FXS======//
1072 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1073 TList* list = GetFileSources(kDAQ);
1075 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1079 if (list->GetEntries() == 0) {
1080 Log("no raw data tags in this run: nothing to merge!");
1081 delete list; list=0;
1085 TChain *fRawTagChain = new TChain("T");
1087 TIterator* iter = list->MakeIterator();
1089 while ((obj = iter->Next())) {
1090 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1092 Log(Form("Found source %s", objStr->String().Data()));
1093 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1095 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1096 delete fRawTagChain; fRawTagChain=0;
1099 Log(Form("Number of ids: %d",list2->GetEntries()));
1100 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1101 TObjString *idStr = (TObjString *)list2->At(i);
1102 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1103 if (fileName.Length() > 0) {
1104 Log(Form("Adding file in the chain: %s",fileName.Data()));
1105 fRawTagChain->Add(fileName.Data());
1108 Log(Form("Could not retrieve file with id %s from source %s: "
1109 "connection problems with DAQ FXS!",
1110 idStr->String().Data(), objStr->String().Data()));
1111 delete list; list=0;
1112 delete list2; list2=0;
1113 delete fRawTagChain; fRawTagChain=0;
1121 TString fRawDataFileName = "GRP_Merged.tag.root";
1122 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1124 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1125 Log("Error merging raw data files!!!");
1129 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1130 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1133 Log("Problem storing raw data tags in local file!!!");
1135 Log("Raw data tags merged successfully!!");
1140 delete fRawTagChain; fRawTagChain=0;
1142 if (result == kFALSE) {
1150 //_______________________________________________________________
1151 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1154 // processing the info
1155 // stored in the DCS FXS
1156 // coming from the trigger
1158 // Get the CTP counters information
1160 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1161 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1162 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1164 Log(Form("No dummy CTP scalers entry found, going into error..."));
1168 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1170 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1174 AliCDBMetaData metaData;
1175 metaData.SetResponsible("Roman Lietava");
1176 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1177 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1178 Log("Unable to store the dummy CTP scalers object to OCDB!");
1185 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1186 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1187 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1188 if (countersfile.IsNull()) {
1189 Log("No CTP counters files has been found: empty source!");
1193 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1194 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1196 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1200 AliCDBMetaData metaData;
1201 metaData.SetBeamPeriod(0);
1202 metaData.SetResponsible("Roman Lietava");
1203 metaData.SetComment("CTP scalers");
1204 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1205 Log("Unable to store the CTP scalers object to OCDB!");
1216 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1223 //_______________________________________________________________
1225 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1229 // processing DCS DPs
1232 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1233 Int_t nL3Entries = 0;
1234 Int_t nDipoleEntries = 0;
1235 Int_t nEnvEntries = 0;
1236 Int_t nHallProbesEntries = 0;
1237 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1238 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1239 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1240 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1241 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1242 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1243 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1248 //_______________________________________________________________
1250 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1257 Int_t nL3Entries = 0;
1259 TObjArray *array = 0x0;
1261 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1263 AliInfo(Form("==========L3Current==========="));
1264 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1265 indexDP = kL3Current;
1266 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1268 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1271 if (array->GetEntries() == 0){
1272 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1275 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1276 if (floatDCS != NULL){
1277 grpObj->SetL3Current(floatDCS);
1289 ffailedDPs->RemoveAt(indexDP);
1293 if (array) array = 0x0;
1295 AliInfo(Form("==========L3Polarity==========="));
1296 indexDP = kL3Polarity;
1297 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1299 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1302 if (array->GetEntries() == 0){
1303 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1306 Bool_t change = kFALSE;
1307 Char_t charDCS = ProcessBool(array,change);
1308 if (change == kFALSE){
1309 grpObj->SetL3Polarity(charDCS);
1310 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1311 ffailedDPs->RemoveAt(indexDP);
1315 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1316 ffailedDPs->RemoveAt(indexDP);
1320 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]));
1328 //_______________________________________________________________
1330 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1336 Int_t nDipoleEntries = 0;
1337 TObjArray *array = 0x0;
1339 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1341 AliInfo(Form("==========DipoleCurrent==========="));
1342 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1343 indexDP = kDipoleCurrent;
1344 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1346 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1349 if (array->GetEntries() == 0){
1350 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1353 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1354 if (floatDCS != NULL){
1355 grpObj->SetDipoleCurrent(floatDCS);
1367 ffailedDPs->RemoveAt(indexDP);
1371 if (array) array = 0x0;
1373 AliInfo(Form("==========DipolePolarity==========="));
1374 indexDP = kDipolePolarity;
1375 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1377 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1380 if (array->GetEntries() == 0){
1381 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1384 Bool_t change = kFALSE;
1385 Char_t charDCS = ProcessBool(array,change);
1387 grpObj->SetDipolePolarity(charDCS);
1388 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1389 ffailedDPs->RemoveAt(indexDP);
1393 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1394 ffailedDPs->RemoveAt(indexDP);
1398 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]));
1403 return nDipoleEntries;
1406 //_______________________________________________________________
1408 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1412 // evironment conditions (temperature, pressure) info
1414 Int_t nEnvEntries = 0;
1415 TObjArray *array = 0x0;
1418 AliInfo(Form("==========CavernTemperature==========="));
1419 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1420 indexDP = kCavernTemperature;
1421 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1423 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1426 if (array->GetEntries() == 0){
1427 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1430 Float_t *floatDCS = ProcessFloatAll(array);
1431 if (floatDCS != NULL){
1432 grpObj->SetCavernTemperature(floatDCS);
1443 ffailedDPs->RemoveAt(indexDP);
1448 if (array) array = 0x0;
1450 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1451 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1452 //dcsSensorArray->Print();
1453 if( fPressure->NumFits()<kNumSensors ) {
1454 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1456 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1458 AliInfo(Form("==========CavernAtmosPressure==========="));
1459 indexDP = kCavernAtmosPressure;
1460 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1461 TGraph* graph = sensorCavernP2->GetGraph();
1462 AliDebug(3,Form("index = %d",indexDP));
1463 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1464 AliDebug(2,Form("graph = %p",graph));
1465 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1466 if(sensorCavernP2->GetFit() || graph) {
1467 if (sensorCavernP2->GetFit()){
1468 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1471 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1473 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1474 ffailedDPs->RemoveAt(indexDP);
1477 //if (sensorP2) delete sensorP2;
1479 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] ));
1482 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1483 indexDP = kSurfaceAtmosPressure;
1484 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1485 graph = sensorP2->GetGraph();
1486 AliDebug(3,Form("index = %d",indexDP));
1487 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1488 AliDebug(2,Form("graph = %p",graph));
1489 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1490 if(sensorP2->GetFit() || graph) {
1491 if (sensorP2->GetFit()){
1492 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1495 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1497 grpObj->SetSurfaceAtmosPressure(sensorP2);
1498 ffailedDPs->RemoveAt(indexDP);
1501 //if (sensorP2) delete sensorP2;
1503 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] ));
1506 AliInfo(Form("==========CavernAtmosPressure2==========="));
1507 indexDP = kCavernAtmosPressure2;
1508 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1509 graph = sensorCavernP22->GetGraph();
1510 AliDebug(3,Form("index = %d",indexDP));
1511 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1512 AliDebug(2,Form("graph = %p",graph));
1513 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1514 if(sensorCavernP22->GetFit() || graph) {
1515 if (sensorCavernP22->GetFit()){
1516 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1519 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1521 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1522 ffailedDPs->RemoveAt(indexDP);
1525 //if (sensorP2) delete sensorP2;
1527 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] ));
1533 //_______________________________________________________________
1535 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1541 Int_t nHPEntries = 0;
1542 TObjArray *array = 0x0;
1544 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1546 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1547 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()));
1549 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1550 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1551 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1552 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1554 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1557 if (array->GetEntries() == 0){
1558 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1561 Float_t *floatDCS = ProcessFloatAll(array);
1562 if (floatDCS != NULL){
1563 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]));
1564 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1565 for (Int_t kk = 0 ; kk< 5; kk++){
1566 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1578 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1584 Log(Form("Hall Probes = %d ", nHPEntries));
1588 //_________________________________________________________________________
1590 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1594 // returning Spline Fit
1597 Int_t entriesarray = array->GetEntries();
1598 Float_t* value = new Float_t[entriesarray];
1599 Float_t* time = new Float_t[entriesarray];
1600 AliDCSValue* v = 0x0;
1601 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1602 v = (AliDCSValue*)array->At(iarray);
1603 value[iarray] = v->GetFloat();
1604 time[iarray] = v->GetTimeStamp();
1605 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1607 TGraph* gr = new TGraph(entriesarray,value,time);
1609 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1612 AliSplineFit *fit = new AliSplineFit();
1613 fit->SetMinPoints(10);
1614 fit->InitKnots(gr,10,10,0.0);
1618 AliWarning(Form("%s: no fit performed",stringID.Data()));
1624 //_________________________________________________________________________
1626 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1633 TString aDCSString="";
1635 AliDCSValue *v = 0x0;
1636 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1637 v = (AliDCSValue *)array->At(iCount);
1638 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1639 AliError(Form("DCS values for the parameter outside the queried interval"));
1643 if (aDCSString != v->GetChar())
1644 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1646 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1651 //__________________________________________________________________________________________________________________
1653 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1656 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1658 // parameters[0] = mean
1659 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1660 // parameters[2] = median
1661 // parameters[3] = standard deviation wrt mean
1662 // parameters[4] = standard deviation wrt median
1665 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1666 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1667 if (timeStartString.IsNull() || timeStartString.IsNull()){
1668 if (timeStartString.IsNull()){
1669 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1671 else if (timeStartString.IsNull()){
1672 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1674 fdaqStartEndTimeOk = kFALSE;
1678 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1679 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1680 Float_t* parameters = new Float_t[5];
1682 Int_t iCountsRun = 0;
1683 Int_t nCounts = array->GetEntries();
1684 Float_t valueBeforeSOR = 0;
1685 Float_t valueAfterEOR = 0;
1686 Int_t timestampBeforeSOR = -1;
1687 Int_t timestampAfterEOR = -1;
1688 Int_t ientrySOR = -1;
1689 Int_t ientryEOR = -1;
1690 Float_t* arrayValues = 0x0;
1691 Double_t* arrayWeights = 0x0;
1692 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1693 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1695 for(Int_t i = 0; i < nCounts; i++) {
1696 AliDCSValue *v = (AliDCSValue *)array->At(i);
1697 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1698 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1699 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1700 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1703 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1704 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1706 // look for the last value before SOR and the first value before EOR
1707 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1708 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1709 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1710 valueBeforeSOR = v->GetFloat();
1712 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1713 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1714 valueAfterEOR = v->GetFloat();
1715 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1717 // check if there are DPs between DAQ_time_start and DAQ_time_end
1718 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1719 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1720 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1721 AliDebug(2,Form("entry between SOR and EOR"));
1726 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1730 if (timestampBeforeSOR == -1){
1731 AliWarning("No value found before SOR");
1733 if (timestampAfterEOR == -1){
1734 AliWarning("No value found after EOR");
1737 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1738 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1739 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1740 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1741 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1742 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1744 Int_t nentriesUsed = 0;
1745 if (iCountsRun > 1){
1746 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1747 AliDebug(2,"Calculating (weighted) Mean and Median");
1748 arrayValues = new Float_t[iCountsRun];
1749 arrayWeights = new Double_t[iCountsRun];
1750 nentriesUsed = iCountsRun;
1751 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1752 AliDCSValue *v = (AliDCSValue *)array->At(i);
1753 Int_t timestamp2 = 0;
1755 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1756 timestamp2 = (Int_t)v1->GetTimeStamp();
1759 timestamp2 = timeEnd+1;
1761 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1762 arrayValues[i-ientrySOR] = v->GetFloat();
1764 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1765 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1767 else if (iCountsRun == 1){
1768 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1770 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1771 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.");
1772 arrayValues = new Float_t[2];
1773 arrayWeights = new Double_t[2];
1774 arrayValues[0] = valueBeforeSOR;
1775 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1776 arrayValues[1] = v->GetFloat();
1777 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1778 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1779 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1780 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1781 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1782 truncMeanFlag = kFALSE;
1785 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");
1786 parameters[0] = AliGRPObject::GetInvalidFloat();
1787 parameters[1] = AliGRPObject::GetInvalidFloat();
1788 parameters[2] = AliGRPObject::GetInvalidFloat();
1789 parameters[3] = AliGRPObject::GetInvalidFloat();
1790 parameters[4] = AliGRPObject::GetInvalidFloat();
1794 else { // iCountsRun == 0, using only the point immediately before SOR
1795 if (timestampBeforeSOR == -1){
1796 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");
1797 parameters[0] = AliGRPObject::GetInvalidFloat();
1798 parameters[1] = AliGRPObject::GetInvalidFloat();
1799 parameters[2] = AliGRPObject::GetInvalidFloat();
1800 parameters[3] = AliGRPObject::GetInvalidFloat();
1801 parameters[4] = AliGRPObject::GetInvalidFloat();
1805 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1806 AliDebug(2,Form("value = %f",valueBeforeSOR));
1807 parameters[0] = valueBeforeSOR;
1808 parameters[2] = valueBeforeSOR;
1809 truncMeanFlag = kFALSE;
1816 Float_t sumweights = 0;
1817 Int_t entriesTruncMean = 0;
1818 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1819 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1821 // calculating SD wrt Mean and Median
1822 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1824 for (Int_t i =0; i< nentriesUsed; i++){
1825 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1826 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1827 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1828 sumweights += arrayWeights[i];
1830 // setting SD wrt Mean
1831 if (sumweights != 0 ){
1832 parameters[3] = TMath::Sqrt(temp1/sumweights);
1835 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1836 parameters[3] = AliGRPObject::GetInvalidFloat();
1838 // setting SD wrt Median
1839 if (nentriesUsed != 0){
1840 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1843 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1844 parameters[4] = AliGRPObject::GetInvalidFloat();
1848 parameters[3] = AliGRPObject::GetInvalidFloat();
1849 parameters[4] = AliGRPObject::GetInvalidFloat();
1852 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1854 AliDebug(2,"Calculating Truncated Mean");
1855 for (Int_t i =0; i< nentriesUsed; i++){
1856 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1857 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1858 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1859 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1860 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1864 AliDebug(2,"Discarding entry");
1867 // setting truncated mean
1868 if (entriesTruncMean >1){
1869 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1870 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1873 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1874 parameters[1] = AliGRPObject::GetInvalidFloat();
1878 parameters[1] = AliGRPObject::GetInvalidFloat();
1881 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1882 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1883 AliInfo(Form("median = %f ",parameters[2]));
1884 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1885 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1890 //__________________________________________________________________________________________________________________
1892 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1895 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1896 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1897 // the flag is set according to the L3/Dipole current value
1898 // current threshold for L3 = 350 A (value provided by DCS)
1899 // current threshold for Dipole = 450 A (value provided by DCS)
1901 // parameters[0] = mean
1902 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1903 // parameters[2] = median
1904 // parameters[3] = standard deviation wrt mean
1905 // parameters[4] = standard deviation wrt median
1908 AliInfo(Form("indexDP = %d",indexDP));
1910 Int_t nCounts = array->GetEntries();
1911 for(Int_t i = 0; i < nCounts; i++) {
1912 AliDCSValue *v = (AliDCSValue *)array->At(i);
1913 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1914 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1915 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1916 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1919 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1920 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1921 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1922 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1925 AliError(Form("DCS values for the parameter outside the queried interval"));
1929 return ProcessFloatAll(array);
1933 //_______________________________________________________________
1935 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1938 // processing Boolean values
1941 Bool_t aDCSBool = kTRUE;
1943 AliDCSValue *v = 0x0;
1945 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1946 v = (AliDCSValue *)array->At(iCount);
1947 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1948 AliError(Form("DCS values for the parameter outside the queried interval"));
1952 if (aDCSBool != v->GetBool()) {
1953 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1957 aDCSBool = v->GetBool(); // always keeping last value
1958 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1961 Char_t caDCSBool = (Char_t) aDCSBool;
1966 //_______________________________________________________________
1968 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1971 // processing Int values, returning mean
1972 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1973 // are outside the queried time interval or their value is out of range
1976 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1977 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1978 if (timeStartString.IsNull() || timeStartString.IsNull()){
1979 if (timeStartString.IsNull()){
1980 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1982 else if (timeStartString.IsNull()){
1983 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1988 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1989 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1990 Float_t aDCSArrayMean = 0.0;
1992 Float_t valueBeforeSOR = 0;
1993 Float_t valueAfterEOR = 0;
1994 Int_t timestampBeforeSOR = -1;
1995 Int_t timestampAfterEOR = -1;
1996 Int_t ientrySOR = -1;
1997 Int_t ientryEOR = -1;
1998 Float_t* arrayValues = 0x0;
1999 Double_t* arrayWeights = 0x0;
2000 Int_t iCountsRun = 0;
2001 Int_t nCounts = array->GetEntries();
2003 for(Int_t i = 0; i < nCounts; i++) {
2004 AliDCSValue* v = (AliDCSValue *)array->At(i);
2005 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
2006 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
2007 return AliGRPObject::GetInvalidFloat();
2009 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2010 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
2012 // look for the last value before SOR and the first value before EOR
2013 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2014 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2015 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2016 valueBeforeSOR = (Float_t) v->GetInt();
2018 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2019 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2020 valueAfterEOR = (Float_t) v->GetInt();
2021 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2023 // check if there are DPs between DAQ_time_start and DAQ_time_end
2024 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2025 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2026 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2027 AliDebug(2,Form("entry between SOR and EOR"));
2032 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2036 if (timestampBeforeSOR == -1){
2037 AliWarning("No value found before SOR!");
2039 if (timestampAfterEOR == -1){
2040 AliWarning("No value found after EOR!");
2043 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2044 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2045 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2046 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2047 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2048 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2050 Int_t nentriesUsed = 0;
2051 if (iCountsRun > 1){
2052 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2053 AliDebug(2,"Calculating (weighted) Mean");
2054 arrayValues = new Float_t[iCountsRun];
2055 arrayWeights = new Double_t[iCountsRun];
2056 nentriesUsed = iCountsRun;
2057 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2058 AliDCSValue *v = (AliDCSValue *)array->At(i);
2059 Int_t timestamp2 = 0;
2061 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2062 timestamp2 = (Int_t)v1->GetTimeStamp();
2065 timestamp2 = timeEnd+1;
2067 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2068 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2070 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2072 else if (iCountsRun == 1){
2073 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2075 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2076 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2077 arrayValues = new Float_t[2];
2078 arrayWeights = new Double_t[2];
2079 arrayValues[0] = valueBeforeSOR;
2080 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2081 arrayValues[1] = (Float_t)v->GetInt();
2082 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2083 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2084 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2085 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2088 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2089 return AliGRPObject::GetInvalidFloat();
2092 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2093 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2094 if (timestampBeforeSOR == -1){
2095 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2097 if (timestampAfterEOR == -1){
2098 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2100 return AliGRPObject::GetInvalidFloat();
2103 AliWarning("Using last entry before SOR and first entry after EOR.");
2105 arrayValues = new Float_t[2];
2106 arrayWeights = new Double_t[2];
2107 arrayValues[0] = valueBeforeSOR;
2108 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2109 arrayValues[1] = valueAfterEOR;
2110 arrayWeights[1] = 1.;
2111 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2112 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2113 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2117 AliInfo(Form("mean = %f ", aDCSArrayMean));
2118 return aDCSArrayMean;
2121 //_______________________________________________________________
2123 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2126 // processing Int values, returning mean
2127 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2128 // are outside the queried time interval or their value is out of range
2131 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2132 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2133 if (timeStartString.IsNull() || timeStartString.IsNull()){
2134 if (timeStartString.IsNull()){
2135 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2137 else if (timeStartString.IsNull()){
2138 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2143 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2144 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2145 Float_t aDCSArrayMean = 0.0;
2147 Float_t valueBeforeSOR = 0;
2148 Float_t valueAfterEOR = 0;
2149 Int_t timestampBeforeSOR = -1;
2150 Int_t timestampAfterEOR = -1;
2151 Int_t ientrySOR = -1;
2152 Int_t ientryEOR = -1;
2153 Float_t* arrayValues = 0x0;
2154 Double_t* arrayWeights = 0x0;
2155 Int_t iCountsRun = 0;
2156 Int_t nCounts = array->GetEntries();
2158 for(Int_t i = 0; i < nCounts; i++) {
2159 AliDCSValue* v = (AliDCSValue *)array->At(i);
2160 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2161 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2162 return AliGRPObject::GetInvalidFloat();
2164 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2165 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2167 // look for the last value before SOR and the first value before EOR
2168 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2169 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2170 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2171 valueBeforeSOR = (Float_t)v->GetUInt();
2173 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2174 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2175 valueAfterEOR = (Float_t)v->GetUInt();
2176 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2178 // check if there are DPs between DAQ_time_start and DAQ_time_end
2179 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2180 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2181 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2182 AliDebug(2,Form("entry between SOR and EOR"));
2187 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2191 if (timestampBeforeSOR == -1){
2192 AliWarning("No value found before SOR!");
2194 if (timestampAfterEOR == -1){
2195 AliWarning("No value found after EOR!");
2198 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2199 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2200 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2201 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2202 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2203 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2205 Int_t nentriesUsed = 0;
2206 if (iCountsRun > 1){
2207 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2208 AliDebug(2,"Calculating (weighted) Mean");
2209 arrayValues = new Float_t[iCountsRun];
2210 arrayWeights = new Double_t[iCountsRun];
2211 nentriesUsed = iCountsRun;
2212 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2213 AliDCSValue *v = (AliDCSValue *)array->At(i);
2214 Int_t timestamp2 = 0;
2216 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2217 timestamp2 = (Int_t)v1->GetTimeStamp();
2220 timestamp2 = timeEnd+1;
2222 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2223 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2225 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2227 else if (iCountsRun == 1){
2228 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2230 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2231 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2232 arrayValues = new Float_t[2];
2233 arrayWeights = new Double_t[2];
2234 arrayValues[0] = valueBeforeSOR;
2235 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2236 arrayValues[1] = (Float_t)v->GetUInt();
2237 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2238 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2239 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2240 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2243 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2244 return AliGRPObject::GetInvalidFloat();
2247 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2248 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2249 if (timestampBeforeSOR == -1){
2250 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2252 if (timestampAfterEOR == -1){
2253 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2255 return AliGRPObject::GetInvalidFloat();
2258 AliWarning("Using last entry before SOR and first entry after EOR.");
2260 arrayValues = new Float_t[2];
2261 arrayWeights = new Double_t[2];
2262 arrayValues[0] = valueBeforeSOR;
2263 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2264 arrayValues[1] = valueAfterEOR;
2265 arrayWeights[1] = 1.;
2266 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2267 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2268 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2272 AliInfo(Form("mean = %f ",aDCSArrayMean));
2273 return aDCSArrayMean;
2278 //_______________________________________________________________
2280 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2282 // extract DCS pressure maps. Perform fits to save space
2284 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2286 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2287 fPressure->MakeSplineFit(map);
2288 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2289 if (fitFraction > kFitFraction ) {
2290 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2292 AliInfo("Too few pressure maps fitted!!!");
2295 AliInfo("no atmospheric pressure map extracted!!!");
2304 //_______________________________________________________________
2305 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)
2308 // Retrieves logbook and trigger information from the online logbook
2309 // This information is needed for prompt reconstruction
2313 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2317 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2318 // 0 on success and no run was found
2319 // negative on error
2321 // This function is NOT called during the preprocessor run in the Shuttle!
2329 AliCDBManager* cdb = AliCDBManager::Instance();
2330 cdb->SetDefaultStorage(cdbRoot);
2333 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2337 Printf("ERROR: Could not connect to DAQ LB");
2343 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2344 TSQLResult* result = server->Query(sqlQuery);
2347 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2351 if (result->GetRowCount() == 0)
2353 Printf("ERROR: Run %d not found", run);
2358 TSQLRow* row = result->Next();
2361 Printf("ERROR: Could not receive data from run %d", run);
2366 TString timeStartString(row->GetField(0));
2367 TString runType(row->GetField(1));
2368 TString detectorMaskString(row->GetField(2));
2369 TString l3CurrentString(row->GetField(3));
2370 TString dipoleCurrentString(row->GetField(4));
2371 time_t timeStart = (time_t)(timeStartString.Atoi());
2372 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2373 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2374 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2375 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2376 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2378 AliGRPObject * grpObj = new AliGRPObject();
2379 grpObj->SetTimeStart(timeStart);
2380 grpObj->SetRunType((TString)(row->GetField(1)));
2381 grpObj->SetDetectorMask(detectorMask);
2382 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2383 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2384 grpObj->SetL3Polarity(l3Polarity);
2385 grpObj->SetDipolePolarity(dipolePolarity);
2386 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2394 Printf("Storing GRP/GRP/Data object with the following content");
2397 AliCDBMetaData metadata;
2398 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2399 metadata.SetComment("GRP Output parameters received during online running");
2401 AliCDBId id("GRP/GRP/Data", run, run);
2402 Bool_t success = cdb->Put(grpObj, id, &metadata);
2408 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2412 // Receive trigger information
2413 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2414 result = server->Query(sqlQuery);
2417 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2421 if (result->GetRowCount() == 0)
2423 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2428 row = result->Next();
2431 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2436 TString triggerConfig(row->GetField(0));
2444 Printf("Found trigger configuration: %s", triggerConfig.Data());
2446 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2449 Printf("ERROR: Could not create CTP configuration object");
2453 metadata.SetComment("CTP run configuration received during online running");
2455 AliCDBId id2("GRP/CTP/Config", run, run);
2456 success = cdb->Put(runcfg, id2, &metadata);
2463 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2468 // Receive list of GDCs for this run
2469 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2470 result = server->Query(sqlQuery);
2473 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2477 if (result->GetRowCount() == 0)
2479 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2485 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2486 row = result->Next();
2489 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2493 gdc += row->GetField(0);
2503 Printf("Found GDC: %s", gdc.Data());
2505 // get last run with same run type that was already processed by the SHUTTLE
2507 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());
2508 result = server->Query(sqlQuery);
2511 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2515 if (result->GetRowCount() == 0)
2517 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2522 row = result->Next();
2525 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2530 TString lastRunStr(row->GetField(0));
2531 Int_t lastRun = lastRunStr.Atoi();
2533 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2547 //-----------------------------------------------------------------
2548 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* const array){
2551 // Calculating mean over TObjArray from LHC Data
2554 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2555 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2556 if (timeStartString.IsNull() || timeStartString.IsNull()){
2557 if (timeStartString.IsNull()){
2558 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2560 else if (timeStartString.IsNull()){
2561 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2566 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2567 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2568 timeStart = 1260646960;
2569 timeEnd = 1260652740;
2570 Double_t* parameters = new Double_t[5];
2571 parameters[0] = -1.;
2572 parameters[1] = -1.;
2573 parameters[2] = -1.;
2574 parameters[3] = -1.;
2575 parameters[4] = -1.;
2577 Int_t iCountsRun = 0;
2578 Int_t nCounts = array->GetEntries();
2579 printf("ncounts = %d\n",nCounts);
2580 Double_t valueBeforeSOR = 0;
2581 Double_t valueAfterEOR = 0;
2582 Double_t timestampBeforeSOR = -1.;
2583 Double_t timestampAfterEOR = -1.;
2584 Int_t ientrySOR = -1;
2585 Int_t ientryEOR = -1;
2586 Double_t* arrayValues = 0x0;
2587 Double_t* arrayWeights = 0x0;
2588 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2589 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2591 for(Int_t i = 0; i < nCounts; i++) {
2592 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2593 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2594 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2596 // look for the last value before SOR and the first value before EOR
2597 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2598 timestampBeforeSOR = dcs->GetTimeStamp();
2599 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2600 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2602 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2603 timestampAfterEOR = dcs->GetTimeStamp();
2604 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2605 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2607 // check if there are DPs between DAQ_time_start and DAQ_time_end
2608 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2609 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2610 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2611 AliDebug(2,Form("entry between SOR and EOR\n"));
2616 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2620 if (timestampBeforeSOR == -1.){
2621 printf("No value found before SOR\n");
2623 if (timestampAfterEOR == -1.){
2624 printf("No value found after EOR\n");
2627 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2628 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2629 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2630 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2631 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2632 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2634 Int_t nentriesUsed = 0;
2635 if (iCountsRun > 1){
2636 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2637 printf("Calculating (weighted) Mean and Median\n" );
2638 arrayValues = new Double_t[iCountsRun];
2639 arrayWeights = new Double_t[iCountsRun];
2640 nentriesUsed = iCountsRun;
2641 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2642 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2643 Double_t timestamp2 = 0;
2645 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2646 timestamp2 = dcs1->GetTimeStamp();
2649 timestamp2 = (Double_t)timeEnd+1;
2651 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2652 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2653 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2655 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2656 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2658 else if (iCountsRun == 1){
2659 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2661 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2662 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");
2663 arrayValues = new Double_t[2];
2664 arrayWeights = new Double_t[2];
2665 arrayValues[0] = valueBeforeSOR;
2666 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2667 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2668 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2669 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2670 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2671 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2672 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2673 truncMeanFlag = kFALSE;
2676 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");
2682 return parameters[0];
2685 else { // iCountsRun == 0, using only the point immediately before SOR
2686 if (timestampBeforeSOR == -1.){
2687 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");
2693 return parameters[0];
2696 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2697 printf("value = %f\n",valueBeforeSOR);
2698 parameters[0] = valueBeforeSOR;
2699 parameters[2] = valueBeforeSOR;
2700 truncMeanFlag = kFALSE;
2707 Double_t sumweights = 0;
2708 Int_t entriesTruncMean = 0;
2709 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2710 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2712 // calculating SD wrt Mean and Median
2713 printf("Calculating SD wrt Mean and SD wrt Median\n");
2715 for (Int_t i =0; i< nentriesUsed; i++){
2716 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2717 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2718 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2719 sumweights += arrayWeights[i];
2721 // setting SD wrt Mean
2722 if (sumweights != 0 ){
2723 parameters[3] = TMath::Sqrt(temp1/sumweights);
2726 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2729 // setting SD wrt Median
2730 if (nentriesUsed != 0){
2731 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2734 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2743 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2745 printf("Calculating Truncated Mean\n");
2746 for (Int_t i =0; i< nentriesUsed; i++){
2747 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2748 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2749 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2750 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2751 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2755 printf("Discarding entry\n");
2758 // setting truncated mean
2759 if (entriesTruncMean >1){
2760 printf("%d entries used for truncated mean\n",entriesTruncMean);
2761 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2764 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2772 printf("(weighted) mean = %f \n",parameters[0]);
2773 printf("(weighted) truncated mean = %f \n",parameters[1]);
2774 printf("median = %f \n",parameters[2]);
2775 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2776 printf("standard deviation with median = %f \n",parameters[4]);
2778 return (parameters[0]);
2780 //------------------------------------------------------------------------------------------------------
2781 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
2784 // Method to processo LHC Energy information
2785 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2788 Int_t nCounts = array->GetEntries();
2789 Float_t energy = -1;
2790 Double_t timeEnergy = -1;
2791 Int_t indexEnergy = -1;
2792 Bool_t foundEnergy = kFALSE;
2794 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2796 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2799 for (Int_t i = 0; i < nCounts; i++){
2800 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2802 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
2803 timeEnergy = dcs->GetTimeStamp();
2805 foundEnergy = kTRUE;
2813 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
2816 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
2817 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2818 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
2824 //------------------------------------------------------------------------------------------------------
2825 AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeStart, Double_t timeEnd)
2828 // Method to process LHC-Clock Phase data
2829 // Only the values between DAQ_time_start and DAQ_time_end are kept
2831 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
2833 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
2835 Int_t nCounts = beam1phase->GetEntries();
2836 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
2838 AliWarning("No beam1 LHC clock phase values found!");
2843 for (Int_t i = 0; i < nCounts; i++){
2844 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
2846 if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
2847 foundBeam1Phase = kTRUE;
2848 AliInfo(Form("Beam1 Clock Phase = %f at timestamp = %f",
2849 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2850 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2854 if (!foundBeam1Phase){
2855 AliError("No beam1 LHC clock phase values found within the run!");
2861 nCounts = beam2phase->GetEntries();
2862 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
2864 AliWarning("No beam2 LHC clock phase values found!");
2869 for (Int_t i = 0; i < nCounts; i++){
2870 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
2872 if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
2873 foundBeam2Phase = kTRUE;
2874 AliInfo(Form("Beam2 Clock Phase = %f at timestamp = %f",
2875 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2876 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2880 if (!foundBeam2Phase){
2881 AliError("No beam2 LHC clock phase values found within the run!");