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 Beam Type 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 there is no PROTON beam, we suppose it is Pb, and we put A-A
818 AliInfo("Setting beam type to A-A");
819 grpobj->SetBeamType("A-A");
822 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
823 AliInfo("Setting beam type to Pb-Pb");
824 grpobj->SetBeamType("Pb-Pb");
827 AliError("Beam Type not known, leaving it empty");
830 if (indexBeam < nBeam-1){
831 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
833 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
834 timeBeamEnd = beam1->GetTimeStamp();
835 TObjString* beamString1 = beam1->GetStringArray(0);
836 TString beamType1 = beamString1->String();
837 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
838 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()));
844 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
852 AliError("Beam Type array not found in LHC Data file!!!");
855 // Setting minTimeLHCValidity
856 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
857 Double_t minTimeLHCValidity;
858 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true
859 minTimeLHCValidity = timeBeamEnd;
861 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
862 minTimeLHCValidity = timeMachineModeEnd;
864 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
865 minTimeLHCValidity = timeBeamModeEnd;
867 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
868 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
870 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
871 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
873 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
874 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
877 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
878 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
880 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
881 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
884 // Processing data to go to AliLHCData object
885 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
886 // storing AliLHCData in OCDB
888 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
890 md.SetResponsible("Ruben Shahoyan");
891 md.SetComment("LHC data from the GRP preprocessor.");
892 Bool_t result = kTRUE;
893 result = Store("GRP", "LHCData", dt, &md);
896 Log(Form("Problems in storing LHC Data - but not going into Error"));
900 // processing LHC Phase
902 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
903 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
904 if (beam1phase == 0x0 || beam2phase == 0x0){
905 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
908 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
910 AliInfo(Form("LHC Phase found"));
911 AliCDBMetaData mdPhase;
912 mdPhase.SetResponsible("Cvetan Cheshkov");
913 mdPhase.SetComment("LHC Clock Phase");
914 Bool_t result = kTRUE;
915 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
917 if (!result) return 3;
923 AliError("No LHCData file found in DCS FXS");
930 //_______________________________________________________________
932 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
935 //Getting the SPD Mean Vertex
938 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
939 Bool_t storeResult = kTRUE;
940 if (list !=0x0 && list->GetEntries()!=0)
942 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
944 for (Int_t jj=0;jj<list->GetEntries();jj++){
945 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
946 AliInfo(Form("found source %s", str->String().Data()));
947 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
948 if (fileNameRun.Length()>0){
949 AliInfo(Form("Got the file %s", fileNameRun.Data()));
950 TFile daqFile(fileNameRun.Data(),"READ");
951 if (daqFile.IsOpen()) {
952 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
955 // storing in the OCDB
957 md.SetResponsible("Cvetan Cheshkov");
958 md.SetComment("SPD Mean Vertex");
959 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
962 AliWarning("No SPD Mean Vertex object found in file");
966 AliError("Can't open file");
967 storeResult = kFALSE;
971 AliWarning("No file found for current source for SPD Mean Vertex");
976 AliWarning("No list found for SPD Mean Vertex");
979 if (list) delete list;
985 //_______________________________________________________________
987 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
989 //Getting the DAQ lb information
991 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
992 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
993 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
994 TString beamType = (TString)GetRunParameter("beamType");
995 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
996 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
997 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
998 TString runType = (TString)GetRunType();
1000 UInt_t nparameter = 0;
1001 if (timeStart != 0){
1002 grpObj->SetTimeStart(timeStart);
1003 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
1007 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1011 grpObj->SetTimeEnd(timeEnd);
1012 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
1016 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1019 if (beamEnergy != 0){
1020 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1023 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1027 if (beamType.Length() != 0){
1028 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()));
1031 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1034 if (numberOfDetectors != 0){
1035 grpObj->SetNumberOfDetectors(numberOfDetectors);
1036 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1040 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1043 if (detectorMask != 0){
1044 grpObj->SetDetectorMask(detectorMask);
1045 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1049 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1052 if (lhcPeriod.Length() != 0) {
1053 grpObj->SetLHCPeriod(lhcPeriod);
1054 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1058 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1060 if (runType.Length() != 0) {
1061 grpObj->SetRunType(runType);
1062 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1066 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1072 //_______________________________________________________________
1074 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1076 //======DAQ FXS======//
1078 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1079 TList* list = GetFileSources(kDAQ);
1081 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1085 if (list->GetEntries() == 0) {
1086 Log("no raw data tags in this run: nothing to merge!");
1087 delete list; list=0;
1091 TChain *fRawTagChain = new TChain("T");
1093 TIterator* iter = list->MakeIterator();
1095 while ((obj = iter->Next())) {
1096 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1098 Log(Form("Found source %s", objStr->String().Data()));
1099 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1101 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1102 delete fRawTagChain; fRawTagChain=0;
1105 Log(Form("Number of ids: %d",list2->GetEntries()));
1106 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1107 TObjString *idStr = (TObjString *)list2->At(i);
1108 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1109 if (fileName.Length() > 0) {
1110 Log(Form("Adding file in the chain: %s",fileName.Data()));
1111 fRawTagChain->Add(fileName.Data());
1114 Log(Form("Could not retrieve file with id %s from source %s: "
1115 "connection problems with DAQ FXS!",
1116 idStr->String().Data(), objStr->String().Data()));
1117 delete list; list=0;
1118 delete list2; list2=0;
1119 delete fRawTagChain; fRawTagChain=0;
1127 TString fRawDataFileName = "GRP_Merged.tag.root";
1128 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1130 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1131 Log("Error merging raw data files!!!");
1135 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1136 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1139 Log("Problem storing raw data tags in local file!!!");
1141 Log("Raw data tags merged successfully!!");
1146 delete fRawTagChain; fRawTagChain=0;
1148 if (result == kFALSE) {
1156 //_______________________________________________________________
1157 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1160 // processing the info
1161 // stored in the DCS FXS
1162 // coming from the trigger
1164 // Get the CTP counters information
1166 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1167 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1168 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1170 Log(Form("No dummy CTP scalers entry found, going into error..."));
1174 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1176 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1180 AliCDBMetaData metaData;
1181 metaData.SetResponsible("Roman Lietava");
1182 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1183 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1184 Log("Unable to store the dummy CTP scalers object to OCDB!");
1191 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1192 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1193 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1194 if (countersfile.IsNull()) {
1195 Log("No CTP counters files has been found: empty source!");
1199 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1200 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1202 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1206 AliCDBMetaData metaData;
1207 metaData.SetBeamPeriod(0);
1208 metaData.SetResponsible("Roman Lietava");
1209 metaData.SetComment("CTP scalers");
1210 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1211 Log("Unable to store the CTP scalers object to OCDB!");
1222 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1229 //_______________________________________________________________
1231 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1235 // processing DCS DPs
1238 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1239 Int_t nL3Entries = 0;
1240 Int_t nDipoleEntries = 0;
1241 Int_t nEnvEntries = 0;
1242 Int_t nHallProbesEntries = 0;
1243 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1244 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1245 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1246 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1247 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1248 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1249 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1254 //_______________________________________________________________
1256 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1263 Int_t nL3Entries = 0;
1265 TObjArray *array = 0x0;
1267 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1269 AliInfo(Form("==========L3Current==========="));
1270 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1271 indexDP = kL3Current;
1272 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1274 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1277 if (array->GetEntries() == 0){
1278 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1281 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1282 if (floatDCS != NULL){
1283 grpObj->SetL3Current(floatDCS);
1295 ffailedDPs->RemoveAt(indexDP);
1299 if (array) array = 0x0;
1301 AliInfo(Form("==========L3Polarity==========="));
1302 indexDP = kL3Polarity;
1303 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1305 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1308 if (array->GetEntries() == 0){
1309 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1312 Bool_t change = kFALSE;
1313 Char_t charDCS = ProcessBool(array,change);
1314 if (change == kFALSE){
1315 grpObj->SetL3Polarity(charDCS);
1316 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1317 ffailedDPs->RemoveAt(indexDP);
1321 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1322 ffailedDPs->RemoveAt(indexDP);
1326 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]));
1334 //_______________________________________________________________
1336 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1342 Int_t nDipoleEntries = 0;
1343 TObjArray *array = 0x0;
1345 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1347 AliInfo(Form("==========DipoleCurrent==========="));
1348 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1349 indexDP = kDipoleCurrent;
1350 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1352 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1355 if (array->GetEntries() == 0){
1356 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1359 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1360 if (floatDCS != NULL){
1361 grpObj->SetDipoleCurrent(floatDCS);
1373 ffailedDPs->RemoveAt(indexDP);
1377 if (array) array = 0x0;
1379 AliInfo(Form("==========DipolePolarity==========="));
1380 indexDP = kDipolePolarity;
1381 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1383 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1386 if (array->GetEntries() == 0){
1387 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1390 Bool_t change = kFALSE;
1391 Char_t charDCS = ProcessBool(array,change);
1393 grpObj->SetDipolePolarity(charDCS);
1394 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1395 ffailedDPs->RemoveAt(indexDP);
1399 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1400 ffailedDPs->RemoveAt(indexDP);
1404 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]));
1409 return nDipoleEntries;
1412 //_______________________________________________________________
1414 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1418 // evironment conditions (temperature, pressure) info
1420 Int_t nEnvEntries = 0;
1421 TObjArray *array = 0x0;
1424 AliInfo(Form("==========CavernTemperature==========="));
1425 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1426 indexDP = kCavernTemperature;
1427 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1429 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1432 if (array->GetEntries() == 0){
1433 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1436 Float_t *floatDCS = ProcessFloatAll(array);
1437 if (floatDCS != NULL){
1438 grpObj->SetCavernTemperature(floatDCS);
1449 ffailedDPs->RemoveAt(indexDP);
1454 if (array) array = 0x0;
1456 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1457 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1458 //dcsSensorArray->Print();
1459 if( fPressure->NumFits()<kNumSensors ) {
1460 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1462 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1464 AliInfo(Form("==========CavernAtmosPressure==========="));
1465 indexDP = kCavernAtmosPressure;
1466 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1467 TGraph* graph = sensorCavernP2->GetGraph();
1468 AliDebug(3,Form("index = %d",indexDP));
1469 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1470 AliDebug(2,Form("graph = %p",graph));
1471 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1472 if(sensorCavernP2->GetFit() || graph) {
1473 if (sensorCavernP2->GetFit()){
1474 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1477 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1479 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1480 ffailedDPs->RemoveAt(indexDP);
1483 //if (sensorP2) delete sensorP2;
1485 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] ));
1488 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1489 indexDP = kSurfaceAtmosPressure;
1490 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1491 graph = sensorP2->GetGraph();
1492 AliDebug(3,Form("index = %d",indexDP));
1493 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1494 AliDebug(2,Form("graph = %p",graph));
1495 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1496 if(sensorP2->GetFit() || graph) {
1497 if (sensorP2->GetFit()){
1498 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1501 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1503 grpObj->SetSurfaceAtmosPressure(sensorP2);
1504 ffailedDPs->RemoveAt(indexDP);
1507 //if (sensorP2) delete sensorP2;
1509 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] ));
1512 AliInfo(Form("==========CavernAtmosPressure2==========="));
1513 indexDP = kCavernAtmosPressure2;
1514 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1515 graph = sensorCavernP22->GetGraph();
1516 AliDebug(3,Form("index = %d",indexDP));
1517 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1518 AliDebug(2,Form("graph = %p",graph));
1519 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1520 if(sensorCavernP22->GetFit() || graph) {
1521 if (sensorCavernP22->GetFit()){
1522 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1525 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1527 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1528 ffailedDPs->RemoveAt(indexDP);
1531 //if (sensorP2) delete sensorP2;
1533 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] ));
1539 //_______________________________________________________________
1541 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1547 Int_t nHPEntries = 0;
1548 TObjArray *array = 0x0;
1550 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1552 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1553 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()));
1555 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1556 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1557 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1558 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1560 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1563 if (array->GetEntries() == 0){
1564 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1567 Float_t *floatDCS = ProcessFloatAll(array);
1568 if (floatDCS != NULL){
1569 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]));
1570 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1571 for (Int_t kk = 0 ; kk< 5; kk++){
1572 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1584 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1590 Log(Form("Hall Probes = %d ", nHPEntries));
1594 //_________________________________________________________________________
1596 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1600 // returning Spline Fit
1603 Int_t entriesarray = array->GetEntries();
1604 Float_t* value = new Float_t[entriesarray];
1605 Float_t* time = new Float_t[entriesarray];
1606 AliDCSValue* v = 0x0;
1607 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1608 v = (AliDCSValue*)array->At(iarray);
1609 value[iarray] = v->GetFloat();
1610 time[iarray] = v->GetTimeStamp();
1611 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1613 TGraph* gr = new TGraph(entriesarray,value,time);
1615 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1618 AliSplineFit *fit = new AliSplineFit();
1619 fit->SetMinPoints(10);
1620 fit->InitKnots(gr,10,10,0.0);
1624 AliWarning(Form("%s: no fit performed",stringID.Data()));
1630 //_________________________________________________________________________
1632 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1639 TString aDCSString="";
1641 AliDCSValue *v = 0x0;
1642 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1643 v = (AliDCSValue *)array->At(iCount);
1644 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1645 AliError(Form("DCS values for the parameter outside the queried interval"));
1649 if (aDCSString != v->GetChar())
1650 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1652 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1657 //__________________________________________________________________________________________________________________
1659 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1662 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1664 // parameters[0] = mean
1665 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1666 // parameters[2] = median
1667 // parameters[3] = standard deviation wrt mean
1668 // parameters[4] = standard deviation wrt median
1671 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1672 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1673 if (timeStartString.IsNull() || timeStartString.IsNull()){
1674 if (timeStartString.IsNull()){
1675 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1677 else if (timeStartString.IsNull()){
1678 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1680 fdaqStartEndTimeOk = kFALSE;
1684 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1685 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1686 Float_t* parameters = new Float_t[5];
1688 Int_t iCountsRun = 0;
1689 Int_t nCounts = array->GetEntries();
1690 Float_t valueBeforeSOR = 0;
1691 Float_t valueAfterEOR = 0;
1692 Int_t timestampBeforeSOR = -1;
1693 Int_t timestampAfterEOR = -1;
1694 Int_t ientrySOR = -1;
1695 Int_t ientryEOR = -1;
1696 Float_t* arrayValues = 0x0;
1697 Double_t* arrayWeights = 0x0;
1698 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1699 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1701 for(Int_t i = 0; i < nCounts; i++) {
1702 AliDCSValue *v = (AliDCSValue *)array->At(i);
1703 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1704 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1705 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1706 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1709 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1710 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1712 // look for the last value before SOR and the first value before EOR
1713 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1714 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1715 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1716 valueBeforeSOR = v->GetFloat();
1718 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1719 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1720 valueAfterEOR = v->GetFloat();
1721 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1723 // check if there are DPs between DAQ_time_start and DAQ_time_end
1724 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1725 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1726 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1727 AliDebug(2,Form("entry between SOR and EOR"));
1732 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1736 if (timestampBeforeSOR == -1){
1737 AliWarning("No value found before SOR");
1739 if (timestampAfterEOR == -1){
1740 AliWarning("No value found after EOR");
1743 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1744 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1745 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1746 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1747 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1748 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1750 Int_t nentriesUsed = 0;
1751 if (iCountsRun > 1){
1752 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1753 AliDebug(2,"Calculating (weighted) Mean and Median");
1754 arrayValues = new Float_t[iCountsRun];
1755 arrayWeights = new Double_t[iCountsRun];
1756 nentriesUsed = iCountsRun;
1757 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1758 AliDCSValue *v = (AliDCSValue *)array->At(i);
1759 Int_t timestamp2 = 0;
1761 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1762 timestamp2 = (Int_t)v1->GetTimeStamp();
1765 timestamp2 = timeEnd+1;
1767 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1768 arrayValues[i-ientrySOR] = v->GetFloat();
1770 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1771 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1773 else if (iCountsRun == 1){
1774 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1776 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1777 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.");
1778 arrayValues = new Float_t[2];
1779 arrayWeights = new Double_t[2];
1780 arrayValues[0] = valueBeforeSOR;
1781 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1782 arrayValues[1] = v->GetFloat();
1783 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1784 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1785 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1786 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1787 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1788 truncMeanFlag = kFALSE;
1791 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");
1792 parameters[0] = AliGRPObject::GetInvalidFloat();
1793 parameters[1] = AliGRPObject::GetInvalidFloat();
1794 parameters[2] = AliGRPObject::GetInvalidFloat();
1795 parameters[3] = AliGRPObject::GetInvalidFloat();
1796 parameters[4] = AliGRPObject::GetInvalidFloat();
1800 else { // iCountsRun == 0, using only the point immediately before SOR
1801 if (timestampBeforeSOR == -1){
1802 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");
1803 parameters[0] = AliGRPObject::GetInvalidFloat();
1804 parameters[1] = AliGRPObject::GetInvalidFloat();
1805 parameters[2] = AliGRPObject::GetInvalidFloat();
1806 parameters[3] = AliGRPObject::GetInvalidFloat();
1807 parameters[4] = AliGRPObject::GetInvalidFloat();
1811 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1812 AliDebug(2,Form("value = %f",valueBeforeSOR));
1813 parameters[0] = valueBeforeSOR;
1814 parameters[2] = valueBeforeSOR;
1815 truncMeanFlag = kFALSE;
1822 Float_t sumweights = 0;
1823 Int_t entriesTruncMean = 0;
1824 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1825 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1827 // calculating SD wrt Mean and Median
1828 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1830 for (Int_t i =0; i< nentriesUsed; i++){
1831 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1832 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1833 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1834 sumweights += arrayWeights[i];
1836 // setting SD wrt Mean
1837 if (sumweights != 0 ){
1838 parameters[3] = TMath::Sqrt(temp1/sumweights);
1841 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1842 parameters[3] = AliGRPObject::GetInvalidFloat();
1844 // setting SD wrt Median
1845 if (nentriesUsed != 0){
1846 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1849 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1850 parameters[4] = AliGRPObject::GetInvalidFloat();
1854 parameters[3] = AliGRPObject::GetInvalidFloat();
1855 parameters[4] = AliGRPObject::GetInvalidFloat();
1858 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1860 AliDebug(2,"Calculating Truncated Mean");
1861 for (Int_t i =0; i< nentriesUsed; i++){
1862 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1863 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1864 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1865 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1866 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1870 AliDebug(2,"Discarding entry");
1873 // setting truncated mean
1874 if (entriesTruncMean >1){
1875 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1876 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1879 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1880 parameters[1] = AliGRPObject::GetInvalidFloat();
1884 parameters[1] = AliGRPObject::GetInvalidFloat();
1887 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1888 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1889 AliInfo(Form("median = %f ",parameters[2]));
1890 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1891 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1896 //__________________________________________________________________________________________________________________
1898 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1901 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1902 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1903 // the flag is set according to the L3/Dipole current value
1904 // current threshold for L3 = 350 A (value provided by DCS)
1905 // current threshold for Dipole = 450 A (value provided by DCS)
1907 // parameters[0] = mean
1908 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1909 // parameters[2] = median
1910 // parameters[3] = standard deviation wrt mean
1911 // parameters[4] = standard deviation wrt median
1914 AliInfo(Form("indexDP = %d",indexDP));
1916 Int_t nCounts = array->GetEntries();
1917 for(Int_t i = 0; i < nCounts; i++) {
1918 AliDCSValue *v = (AliDCSValue *)array->At(i);
1919 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1920 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1921 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1922 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1925 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1926 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1927 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1928 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1931 AliError(Form("DCS values for the parameter outside the queried interval"));
1935 return ProcessFloatAll(array);
1939 //_______________________________________________________________
1941 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1944 // processing Boolean values
1947 Bool_t aDCSBool = kTRUE;
1949 AliDCSValue *v = 0x0;
1951 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1952 v = (AliDCSValue *)array->At(iCount);
1953 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1954 AliError(Form("DCS values for the parameter outside the queried interval"));
1958 if (aDCSBool != v->GetBool()) {
1959 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1963 aDCSBool = v->GetBool(); // always keeping last value
1964 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1967 Char_t caDCSBool = (Char_t) aDCSBool;
1972 //_______________________________________________________________
1974 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1977 // processing Int values, returning mean
1978 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1979 // are outside the queried time interval or their value is out of range
1982 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1983 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1984 if (timeStartString.IsNull() || timeStartString.IsNull()){
1985 if (timeStartString.IsNull()){
1986 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1988 else if (timeStartString.IsNull()){
1989 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1994 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1995 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1996 Float_t aDCSArrayMean = 0.0;
1998 Float_t valueBeforeSOR = 0;
1999 Float_t valueAfterEOR = 0;
2000 Int_t timestampBeforeSOR = -1;
2001 Int_t timestampAfterEOR = -1;
2002 Int_t ientrySOR = -1;
2003 Int_t ientryEOR = -1;
2004 Float_t* arrayValues = 0x0;
2005 Double_t* arrayWeights = 0x0;
2006 Int_t iCountsRun = 0;
2007 Int_t nCounts = array->GetEntries();
2009 for(Int_t i = 0; i < nCounts; i++) {
2010 AliDCSValue* v = (AliDCSValue *)array->At(i);
2011 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
2012 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
2013 return AliGRPObject::GetInvalidFloat();
2015 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2016 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
2018 // look for the last value before SOR and the first value before EOR
2019 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2020 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2021 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2022 valueBeforeSOR = (Float_t) v->GetInt();
2024 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2025 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2026 valueAfterEOR = (Float_t) v->GetInt();
2027 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2029 // check if there are DPs between DAQ_time_start and DAQ_time_end
2030 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2031 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2032 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2033 AliDebug(2,Form("entry between SOR and EOR"));
2038 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2042 if (timestampBeforeSOR == -1){
2043 AliWarning("No value found before SOR!");
2045 if (timestampAfterEOR == -1){
2046 AliWarning("No value found after EOR!");
2049 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2050 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2051 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2052 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2053 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2054 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2056 Int_t nentriesUsed = 0;
2057 if (iCountsRun > 1){
2058 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2059 AliDebug(2,"Calculating (weighted) Mean");
2060 arrayValues = new Float_t[iCountsRun];
2061 arrayWeights = new Double_t[iCountsRun];
2062 nentriesUsed = iCountsRun;
2063 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2064 AliDCSValue *v = (AliDCSValue *)array->At(i);
2065 Int_t timestamp2 = 0;
2067 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2068 timestamp2 = (Int_t)v1->GetTimeStamp();
2071 timestamp2 = timeEnd+1;
2073 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2074 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2076 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2078 else if (iCountsRun == 1){
2079 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2081 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2082 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2083 arrayValues = new Float_t[2];
2084 arrayWeights = new Double_t[2];
2085 arrayValues[0] = valueBeforeSOR;
2086 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2087 arrayValues[1] = (Float_t)v->GetInt();
2088 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2089 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2090 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2091 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2094 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2095 return AliGRPObject::GetInvalidFloat();
2098 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2099 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2100 if (timestampBeforeSOR == -1){
2101 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2103 if (timestampAfterEOR == -1){
2104 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2106 return AliGRPObject::GetInvalidFloat();
2109 AliWarning("Using last entry before SOR and first entry after EOR.");
2111 arrayValues = new Float_t[2];
2112 arrayWeights = new Double_t[2];
2113 arrayValues[0] = valueBeforeSOR;
2114 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2115 arrayValues[1] = valueAfterEOR;
2116 arrayWeights[1] = 1.;
2117 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2118 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2119 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2123 AliInfo(Form("mean = %f ", aDCSArrayMean));
2124 return aDCSArrayMean;
2127 //_______________________________________________________________
2129 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2132 // processing Int values, returning mean
2133 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2134 // are outside the queried time interval or their value is out of range
2137 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2138 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2139 if (timeStartString.IsNull() || timeStartString.IsNull()){
2140 if (timeStartString.IsNull()){
2141 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2143 else if (timeStartString.IsNull()){
2144 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2149 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2150 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2151 Float_t aDCSArrayMean = 0.0;
2153 Float_t valueBeforeSOR = 0;
2154 Float_t valueAfterEOR = 0;
2155 Int_t timestampBeforeSOR = -1;
2156 Int_t timestampAfterEOR = -1;
2157 Int_t ientrySOR = -1;
2158 Int_t ientryEOR = -1;
2159 Float_t* arrayValues = 0x0;
2160 Double_t* arrayWeights = 0x0;
2161 Int_t iCountsRun = 0;
2162 Int_t nCounts = array->GetEntries();
2164 for(Int_t i = 0; i < nCounts; i++) {
2165 AliDCSValue* v = (AliDCSValue *)array->At(i);
2166 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2167 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2168 return AliGRPObject::GetInvalidFloat();
2170 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2171 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2173 // look for the last value before SOR and the first value before EOR
2174 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2175 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2176 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2177 valueBeforeSOR = (Float_t)v->GetUInt();
2179 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2180 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2181 valueAfterEOR = (Float_t)v->GetUInt();
2182 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2184 // check if there are DPs between DAQ_time_start and DAQ_time_end
2185 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2186 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2187 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2188 AliDebug(2,Form("entry between SOR and EOR"));
2193 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2197 if (timestampBeforeSOR == -1){
2198 AliWarning("No value found before SOR!");
2200 if (timestampAfterEOR == -1){
2201 AliWarning("No value found after EOR!");
2204 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2205 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2206 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2207 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2208 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2209 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2211 Int_t nentriesUsed = 0;
2212 if (iCountsRun > 1){
2213 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2214 AliDebug(2,"Calculating (weighted) Mean");
2215 arrayValues = new Float_t[iCountsRun];
2216 arrayWeights = new Double_t[iCountsRun];
2217 nentriesUsed = iCountsRun;
2218 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2219 AliDCSValue *v = (AliDCSValue *)array->At(i);
2220 Int_t timestamp2 = 0;
2222 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2223 timestamp2 = (Int_t)v1->GetTimeStamp();
2226 timestamp2 = timeEnd+1;
2228 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2229 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2231 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2233 else if (iCountsRun == 1){
2234 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2236 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2237 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2238 arrayValues = new Float_t[2];
2239 arrayWeights = new Double_t[2];
2240 arrayValues[0] = valueBeforeSOR;
2241 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2242 arrayValues[1] = (Float_t)v->GetUInt();
2243 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2244 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2245 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2246 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2249 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2250 return AliGRPObject::GetInvalidFloat();
2253 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2254 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2255 if (timestampBeforeSOR == -1){
2256 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2258 if (timestampAfterEOR == -1){
2259 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2261 return AliGRPObject::GetInvalidFloat();
2264 AliWarning("Using last entry before SOR and first entry after EOR.");
2266 arrayValues = new Float_t[2];
2267 arrayWeights = new Double_t[2];
2268 arrayValues[0] = valueBeforeSOR;
2269 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2270 arrayValues[1] = valueAfterEOR;
2271 arrayWeights[1] = 1.;
2272 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2273 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2274 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2278 AliInfo(Form("mean = %f ",aDCSArrayMean));
2279 return aDCSArrayMean;
2284 //_______________________________________________________________
2286 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2288 // extract DCS pressure maps. Perform fits to save space
2290 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2292 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2293 fPressure->MakeSplineFit(map);
2294 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2295 if (fitFraction > kFitFraction ) {
2296 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2298 AliInfo("Too few pressure maps fitted!!!");
2301 AliInfo("no atmospheric pressure map extracted!!!");
2310 //_______________________________________________________________
2311 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)
2314 // Retrieves logbook and trigger information from the online logbook
2315 // This information is needed for prompt reconstruction
2319 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2323 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2324 // 0 on success and no run was found
2325 // negative on error
2327 // This function is NOT called during the preprocessor run in the Shuttle!
2335 AliCDBManager* cdb = AliCDBManager::Instance();
2336 cdb->SetDefaultStorage(cdbRoot);
2339 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2343 Printf("ERROR: Could not connect to DAQ LB");
2349 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
2350 TSQLResult* result = server->Query(sqlQuery);
2353 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2357 if (result->GetRowCount() == 0)
2359 Printf("ERROR: Run %d not found", run);
2364 TSQLRow* row = result->Next();
2367 Printf("ERROR: Could not receive data from run %d", run);
2372 TString timeStartString(row->GetField(0));
2373 TString runType(row->GetField(1));
2374 TString detectorMaskString(row->GetField(2));
2375 TString l3CurrentString(row->GetField(3));
2376 TString dipoleCurrentString(row->GetField(4));
2377 TString beamTypeString(row->GetField(5));
2378 time_t timeStart = (time_t)(timeStartString.Atoi());
2379 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2380 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2381 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2382 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2383 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2385 AliGRPObject * grpObj = new AliGRPObject();
2386 grpObj->SetTimeStart(timeStart);
2387 grpObj->SetRunType((TString)(row->GetField(1)));
2388 grpObj->SetDetectorMask(detectorMask);
2389 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2390 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2391 grpObj->SetL3Polarity(l3Polarity);
2392 grpObj->SetDipolePolarity(dipolePolarity);
2393 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2394 grpObj->SetBeamType((TString)(row->GetField(5)));
2402 Printf("Storing GRP/GRP/Data object with the following content");
2405 AliCDBMetaData metadata;
2406 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2407 metadata.SetComment("GRP Output parameters received during online running");
2409 AliCDBId id("GRP/GRP/Data", run, run);
2410 Bool_t success = cdb->Put(grpObj, id, &metadata);
2416 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2420 // Receive trigger information
2421 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2422 result = server->Query(sqlQuery);
2425 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2429 if (result->GetRowCount() == 0)
2431 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2436 row = result->Next();
2439 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2444 TString triggerConfig(row->GetField(0));
2452 Printf("Found trigger configuration: %s", triggerConfig.Data());
2454 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2457 Printf("ERROR: Could not create CTP configuration object");
2461 metadata.SetComment("CTP run configuration received during online running");
2463 AliCDBId id2("GRP/CTP/Config", run, run);
2464 success = cdb->Put(runcfg, id2, &metadata);
2471 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2476 // Receive list of GDCs for this run
2477 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2478 result = server->Query(sqlQuery);
2481 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2485 if (result->GetRowCount() == 0)
2487 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2493 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2494 row = result->Next();
2497 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2501 gdc += row->GetField(0);
2511 Printf("Found GDC: %s", gdc.Data());
2513 // get last run with same run type that was already processed by the SHUTTLE
2515 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());
2516 result = server->Query(sqlQuery);
2519 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2523 if (result->GetRowCount() == 0)
2525 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2530 row = result->Next();
2533 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2538 TString lastRunStr(row->GetField(0));
2539 Int_t lastRun = lastRunStr.Atoi();
2541 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2555 //-----------------------------------------------------------------
2556 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* const array){
2559 // Calculating mean over TObjArray from LHC Data
2562 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2563 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2564 if (timeStartString.IsNull() || timeStartString.IsNull()){
2565 if (timeStartString.IsNull()){
2566 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2568 else if (timeStartString.IsNull()){
2569 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2574 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2575 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2576 timeStart = 1260646960;
2577 timeEnd = 1260652740;
2578 Double_t* parameters = new Double_t[5];
2579 parameters[0] = -1.;
2580 parameters[1] = -1.;
2581 parameters[2] = -1.;
2582 parameters[3] = -1.;
2583 parameters[4] = -1.;
2585 Int_t iCountsRun = 0;
2586 Int_t nCounts = array->GetEntries();
2587 printf("ncounts = %d\n",nCounts);
2588 Double_t valueBeforeSOR = 0;
2589 Double_t valueAfterEOR = 0;
2590 Double_t timestampBeforeSOR = -1.;
2591 Double_t timestampAfterEOR = -1.;
2592 Int_t ientrySOR = -1;
2593 Int_t ientryEOR = -1;
2594 Double_t* arrayValues = 0x0;
2595 Double_t* arrayWeights = 0x0;
2596 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2597 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2599 for(Int_t i = 0; i < nCounts; i++) {
2600 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2601 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2602 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2604 // look for the last value before SOR and the first value before EOR
2605 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2606 timestampBeforeSOR = dcs->GetTimeStamp();
2607 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2608 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2610 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2611 timestampAfterEOR = dcs->GetTimeStamp();
2612 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2613 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2615 // check if there are DPs between DAQ_time_start and DAQ_time_end
2616 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2617 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2618 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2619 AliDebug(2,Form("entry between SOR and EOR\n"));
2624 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2628 if (timestampBeforeSOR == -1.){
2629 printf("No value found before SOR\n");
2631 if (timestampAfterEOR == -1.){
2632 printf("No value found after EOR\n");
2635 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2636 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2637 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2638 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2639 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2640 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2642 Int_t nentriesUsed = 0;
2643 if (iCountsRun > 1){
2644 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2645 printf("Calculating (weighted) Mean and Median\n" );
2646 arrayValues = new Double_t[iCountsRun];
2647 arrayWeights = new Double_t[iCountsRun];
2648 nentriesUsed = iCountsRun;
2649 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2650 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2651 Double_t timestamp2 = 0;
2653 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2654 timestamp2 = dcs1->GetTimeStamp();
2657 timestamp2 = (Double_t)timeEnd+1;
2659 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2660 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2661 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2663 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2664 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2666 else if (iCountsRun == 1){
2667 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2669 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2670 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");
2671 arrayValues = new Double_t[2];
2672 arrayWeights = new Double_t[2];
2673 arrayValues[0] = valueBeforeSOR;
2674 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2675 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2676 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2677 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2678 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2679 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2680 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2681 truncMeanFlag = kFALSE;
2684 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");
2690 return parameters[0];
2693 else { // iCountsRun == 0, using only the point immediately before SOR
2694 if (timestampBeforeSOR == -1.){
2695 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");
2701 return parameters[0];
2704 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2705 printf("value = %f\n",valueBeforeSOR);
2706 parameters[0] = valueBeforeSOR;
2707 parameters[2] = valueBeforeSOR;
2708 truncMeanFlag = kFALSE;
2715 Double_t sumweights = 0;
2716 Int_t entriesTruncMean = 0;
2717 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2718 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2720 // calculating SD wrt Mean and Median
2721 printf("Calculating SD wrt Mean and SD wrt Median\n");
2723 for (Int_t i =0; i< nentriesUsed; i++){
2724 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2725 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2726 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2727 sumweights += arrayWeights[i];
2729 // setting SD wrt Mean
2730 if (sumweights != 0 ){
2731 parameters[3] = TMath::Sqrt(temp1/sumweights);
2734 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2737 // setting SD wrt Median
2738 if (nentriesUsed != 0){
2739 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2742 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2751 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2753 printf("Calculating Truncated Mean\n");
2754 for (Int_t i =0; i< nentriesUsed; i++){
2755 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2756 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2757 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2758 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2759 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2763 printf("Discarding entry\n");
2766 // setting truncated mean
2767 if (entriesTruncMean >1){
2768 printf("%d entries used for truncated mean\n",entriesTruncMean);
2769 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2772 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2780 printf("(weighted) mean = %f \n",parameters[0]);
2781 printf("(weighted) truncated mean = %f \n",parameters[1]);
2782 printf("median = %f \n",parameters[2]);
2783 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2784 printf("standard deviation with median = %f \n",parameters[4]);
2786 return (parameters[0]);
2788 //------------------------------------------------------------------------------------------------------
2789 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
2792 // Method to processo LHC Energy information
2793 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2796 Int_t nCounts = array->GetEntries();
2797 Float_t energy = -1;
2798 Double_t timeEnergy = -1;
2799 Int_t indexEnergy = -1;
2800 Bool_t foundEnergy = kFALSE;
2802 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2804 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2807 for (Int_t i = 0; i < nCounts; i++){
2808 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2810 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
2811 timeEnergy = dcs->GetTimeStamp();
2813 foundEnergy = kTRUE;
2821 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
2824 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
2825 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2826 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
2832 //------------------------------------------------------------------------------------------------------
2833 AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
2836 // Method to process LHC-Clock Phase data
2837 // Only the values between DAQ_time_start and DAQ_time_end are kept
2839 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
2841 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
2842 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
2844 TString timeCreatedStr = GetRunParameter("time_created");
2845 Double_t timeCreated = timeCreatedStr.Atof();
2847 Int_t nCounts = beam1phase->GetEntries();
2848 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
2850 AliWarning("No beam1 LHC clock phase values found!");
2855 Double_t prevPhase = 0;
2856 for (Int_t i = 0; i < nCounts; i++){
2857 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
2859 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
2860 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2861 if ((i == 0) || (i == (nCounts-1)) ||
2863 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2864 prevPhase = dcs->GetDouble(0);
2865 foundBeam1Phase = kTRUE;
2866 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
2867 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2868 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2873 if (!foundBeam1Phase){
2874 AliError("No beam1 LHC clock phase values found within the run!");
2880 nCounts = beam2phase->GetEntries();
2881 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
2883 AliWarning("No beam2 LHC clock phase values found!");
2888 Double_t prevPhase = 0;
2889 for (Int_t i = 0; i < nCounts; i++){
2890 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
2892 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2893 if ((i == 0) || (i == (nCounts-1)) ||
2895 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2896 prevPhase = dcs->GetDouble(0);
2897 foundBeam2Phase = kTRUE;
2898 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
2899 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2900 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2905 if (!foundBeam2Phase){
2906 AliError("No beam2 LHC clock phase values found within the run!");