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"
46 #include "AliTriggerInput.h"
48 #include "AliCDBMetaData.h"
49 #include "AliESDVertex.h"
50 #include "AliLHCReader.h"
51 #include "AliLHCData.h"
52 #include "AliDCSArray.h"
54 #include "AliLTUConfig.h"
58 class AliShuttleInterface;
60 // needed for ReceivePromptRecoParameters
62 #include <TSQLServer.h>
63 #include <TSQLResult.h>
65 #include <AliCDBManager.h>
66 #include <AliCDBMetaData.h>
68 #include <AliTriggerConfiguration.h>
69 #include <AliCTPTimeParams.h>
70 #include <AliLHCClockPhase.h>
72 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
74 ClassImp(AliGRPPreprocessor)
76 //_______________________________________________________________
78 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 6; // num parameters in the logbook used to fill the GRP object
79 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
80 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
81 const Int_t AliGRPPreprocessor::fgknLHCDP = 6; // number of dcs dps from LHC data
82 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
83 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
84 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
92 "L3_BSF17_Temperature",
96 "L3_BSF4_Temperature",
100 "L3_BKF17_Temperature",
104 "L3_BKF4_Temperature",
108 "L3_BSF13_Temperature",
112 "L3_BSF8_Temperature",
116 "L3_BKF13_Temperature",
120 "L3_BKF8_Temperature",
124 "Dipole_Inside_Temperature",
128 "Dipole_Outside_Temperature",
130 "CavernAtmosPressure",
131 "SurfaceAtmosPressure",
132 "CavernAtmosPressure2"
135 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
139 "L3_BSF17_Temperature",
143 "L3_BSF4_Temperature",
147 "L3_BKF17_Temperature",
151 "L3_BKF4_Temperature",
155 "L3_BSF13_Temperature",
159 "L3_BSF8_Temperature",
163 "L3_BKF13_Temperature",
167 "L3_BKF8_Temperature",
171 "Dipole_Inside_Temperature",
175 "Dipole_Outside_Temperature"
178 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
179 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
182 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
186 "LHC_Beams_Particle_Type",
187 "BPTX_Phase_Shift_B1",
188 "BPTX_Phase_Shift_B2"
191 const char* kppError[] = {
193 "(DAQ logbook ERROR)",
195 "(Trigger Scalers not found in DCS FXS - ERROR)",
196 "(DCS data points ERROR)",
197 "(Trigger Configuration ERROR)",
198 "(DAQ logbook ERROR determining partition of the run)",
199 "(CTP timing ERROR)",
200 "(SPD Mean Vertex ERROR)",
201 "(DCS FXS Error for LHC Data)",
203 "(LHC Clock Phase Error (from LHC Data))",
204 "(LTU Configuration Error)"
207 //_______________________________________________________________
209 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
210 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))
212 // constructor - shuttle must be instantiated!
214 AddRunType("COSMIC");
216 AddRunType("PHYSICS");
217 AddRunType("CALIBRATION_BC");
218 AddRunType("CALIBRATION_CENTRAL");
219 AddRunType("CALIBRATION_EMD");
220 AddRunType("CALIBRATION_MB");
221 AddRunType("CALIBRATION_SEMICENTRAL");
222 AddRunType("CALIBRATION");
223 AddRunType("PEDESTAL");
224 AddRunType("STANDALONE");
227 AddRunType("PULSER");
228 AddRunType("STANDALONE_PULSER");
229 AddRunType("STANDALONE_BC");
232 fminFloat = -FLT_MAX;
233 fmaxDouble = DBL_MAX;
234 fminDouble = -DBL_MAX;
240 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
241 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
242 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
243 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
244 AliInfo(Form("Max allowed integer = %d",fmaxInt));
245 AliInfo(Form("Min allowed integer = %d",fminInt));
246 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
247 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
249 ffailedDPs->SetOwner(kTRUE);
252 //_______________________________________________________________
254 AliGRPPreprocessor::~AliGRPPreprocessor()
263 //_______________________________________________________________
265 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
267 // Initialize preprocessor
269 AliPreprocessor::Initialize(run, startTime, endTime);
271 AliInfo("Initialization of the GRP preprocessor.");
272 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
273 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
274 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
275 for(Int_t j = 0; j < kNumSensors; j++) {
276 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
277 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
279 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
281 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
283 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
284 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
285 ffailedDPs->AddAt(dp,iDP);
290 //_______________________________________________________________
292 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
294 // process data retrieved by the Shuttle
296 // retrieving "partition" and "detector" fields from DAQ logbook to
297 // determine the partition in which the run was taken
298 // the partition is used to decide how to react in case of errors for CTP
300 TString partition = (TString)GetRunParameter("partition");
301 TString detector = (TString)GetRunParameter("detector");
303 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
304 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
306 //=================//
308 //=================//
310 Log("*************** Processing DAQ logbook");
314 Int_t iDaqLB = ProcessDaqLB(grpobj);
315 TString runType = (TString)GetRunType();
316 TString beamType = (TString)GetRunParameter("beamType");
317 if(iDaqLB == fgknDAQLbPar) {
318 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
320 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
324 //=================//
326 //=================//
328 Log("*************** Processing DAQ FXS");
330 UInt_t iDaqFxs = ProcessDaqFxs();
332 Log(Form("DAQ FXS, successful!"));
334 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
338 //=================//
340 //=================//
342 Log("*************** Processing DCS FXS");
344 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
346 Log(Form("DCS FXS, successful!"));
347 } else if (iDcsFxs ==1) {
348 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
351 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
355 //=================//
356 // DCS data points //
357 //=================//
359 Log("*************** Processing DCS DPs");
361 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
362 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
363 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
364 if (fdaqStartEndTimeOk){
365 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
366 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
367 Log(Form("The DPs giving problems were:"));
368 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
369 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
371 TString name = dpString->String();
372 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
373 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
376 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()));
382 else Log(Form("DCS data points, successful!"));
384 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"));
386 //=======================//
387 // Trigger Configuration //
388 //=======================//
390 Log("*************** Processing Trigger Configuration");
392 const char * triggerConf = GetTriggerConfiguration();
394 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
395 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
396 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
398 Log(Form("No dummy CTP configuration entry found, going into error..."));
402 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
404 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
408 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
409 runcfg->SetTitle(titleCTPcfg);
410 AliCDBMetaData metaData;
411 metaData.SetResponsible("Roman Lietava");
412 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
413 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
414 Log("Unable to store the dummy CTP run configuration object to OCDB!");
421 else if (!partition.IsNull() && detector.IsNull()){ // global partition
422 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
423 if (triggerConf!= NULL) {
424 Log("Found trigger configuration in DAQ logbook");
425 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
427 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
431 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
432 runcfg->SetTitle(titleCTPcfg);
433 AliCDBMetaData metaData;
434 metaData.SetBeamPeriod(0);
435 metaData.SetResponsible("Roman Lietava");
436 metaData.SetComment("CTP run configuration from DAQ logbook");
437 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
438 Log("Unable to store the CTP run configuration object to OCDB!");
445 Log("Trigger configuration NULL in DAQ logbook");
451 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
455 //===========================//
456 // Trigger Timing Parameters //
457 //===========================//
459 Log("*************** Processing Trigger Time Params");
461 const char * triggerCTPtiming = GetCTPTimeParams();
463 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
464 Log("STANDALONE partition for current run, using CTP timing params dummy value");
465 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
467 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
471 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
473 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
477 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
478 runCTPtiming->SetTitle(titleCTPtiming);
479 AliCDBMetaData metadata;
480 metadata.SetResponsible("Roman Lietava");
481 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
482 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
483 Log("Unable to store the dummy CTP timing params object to OCDB!");
490 else if (!partition.IsNull() && detector.IsNull()){ // global partition
491 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
492 if (triggerCTPtiming!= NULL) {
493 Log("Found trigger timing params in DAQ logbook");
494 AliDebug(2,Form("%s",triggerCTPtiming));
495 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
497 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
501 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
502 runCTPtiming->SetTitle(titleCTPtiming);
503 AliCDBMetaData metadata;
504 metadata.SetBeamPeriod(0);
505 metadata.SetResponsible("Roman Lietava");
506 metadata.SetComment("CTP timing params from DAQ logbook");
507 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
508 Log("Unable to store the CTP timing params object to OCDB!");
515 Log("Trigger timing params NULL in DAQ logbook");
521 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
525 //===========================//
526 // LTU Configuration //
527 //===========================//
529 Log("*************** Processing LTU Configuration");
531 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
532 Log("STANDALONE partition for current run, using LTU configuration dummy value");
533 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
535 Log(Form("No dummy LTU Config entry found, going into error..."));
539 TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
541 Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
545 AliCDBMetaData metadata;
546 metadata.SetResponsible("Roman Lietava");
547 metadata.SetComment("LTU Config from dummy entry in OCDB");
548 if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
549 Log("Unable to store the dummy LTU Config object to OCDB!");
556 else if (!partition.IsNull() && detector.IsNull()){ // global partition
558 Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
559 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
560 Printf ("detectormask = %d",detectorMask);
561 TObjArray * ltuarray = new TObjArray();
562 ltuarray->SetOwner(1);
563 Bool_t isLTUok = kTRUE;
564 for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
565 if ((detectorMask >> i) & 0x1) {
566 TString det = AliDAQ::OfflineModuleName(i);
567 TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
568 if (detCTPName == "CTP") {
569 detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors
570 Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
573 Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
574 TString* ltu = GetLTUConfig(detCTPName.Data());
576 Log(Form("No LTU Configuration from DAQ logbook for detector %s (BUT it was expected)! The corresponding CDB entry will not be filled!",detCTPName.Data()));
582 Float_t ltuFineDelay1 = ltu[0].Atof();
583 Float_t ltuFineDelay2 = ltu[1].Atof();
584 Float_t ltuBCDelayAdd = ltu[2].Atof();
585 const char* name = AliDAQ::DetectorName(i);
586 AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
587 ltuarray->AddAtAndExpand(ltuConfig,i);
592 AliCDBMetaData metadata;
593 metadata.SetBeamPeriod(0);
594 metadata.SetResponsible("Roman Lietava");
595 metadata.SetComment("LTU Configuration for current run");
596 if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
597 Log("Unable to store the LTU Config object to OCDB!");
601 if (ltuarray) delete ltuarray;
605 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
610 //=================//
612 //=================//
614 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
615 Log("*************** Processing LHC Data");
617 UInt_t iLHCData = ProcessLHCData(grpobj);
619 if( iLHCData == 0 ) {
620 Log(Form("LHC Data from DCS FXS, successful!"));
621 } else if (iLHCData == 1) {
622 Log(Form("LHC Data, problems with DCS FXS!"));
624 } else if (iLHCData == 2) {
625 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
627 } else if (iLHCData ==3){
628 Log(Form("Problems in storing LHC Phase - going into Error"));
630 } else if (iLHCData ==4){
631 Log(Form("Problems with LHC Phase - going into Error"));
634 Log(Form("LHC Data problems"));
640 //==================//
641 // SPD Mean Vertex //
642 //==================//
644 Log("*************** Processing SPD Mean Vertex");
646 if (runType == "PHYSICS"){
647 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
648 if( iSPDMeanVertex == 1 ) {
649 Log(Form("SPD Mean Vertex, successful!"));
651 Log(Form("SPD Mean Vertex failed!!!"));
656 Log("SPD Mean Vertex not processed since runType != PHYSICS");
659 // storing AliGRPObject in OCDB
662 md.SetResponsible("Chiara Zampolli");
663 md.SetComment("Output parameters from the GRP preprocessor.");
665 Bool_t result = kTRUE;
666 result = Store("GRP", "Data", grpobj, &md);
669 if (result && !error ) {
670 Log("GRP Preprocessor Success");
673 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s",
674 kppError[(error&1)?1:0],
675 kppError[(error&2)?2:0],
676 kppError[(error&4)?3:0],
677 kppError[(error&8)?4:0],
678 kppError[(error&16)?5:0],
679 kppError[(error&32)?6:0],
680 kppError[(error&64)?7:0],
681 kppError[(error&128)?8:0],
682 kppError[(error&256)?9:0],
683 kppError[(error&512)?10:0],
684 kppError[(error&1024)?11:0],
685 kppError[(error&2048)?12:0]
693 //_______________________________________________________________
695 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
698 //Getting the LHC Data from DCS FXS
701 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
702 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
703 if (timeStartString.IsNull() || timeEndString.IsNull()){
704 if (timeStartString.IsNull()){
705 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
707 else if (timeEndString.IsNull()){
708 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
713 Double_t timeStart = timeStartString.Atof();
714 Double_t timeEnd = timeEndString.Atof();
716 TString fileName = GetFile(kDCS, "LHCData","");
717 if (fileName.Length()>0){
718 AliInfo("Got The LHC Data file");
719 AliLHCReader lhcReader;
721 // Processing data to be put in AliGRPObject
724 Log("*************Energy ");
725 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
727 Float_t energy = ProcessEnergy(energyArray,timeStart);
729 grpobj->SetBeamEnergy(energy);
730 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
735 AliError("Energy not found in LHC Data file!!!");
738 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
739 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
740 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
741 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
742 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
743 Double_t timeBeamStart = -1; // min validity for Beam Type
744 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
745 Int_t indexMachineMode = -1; // index of measurement used to set Beam Mode
746 Int_t indexBeam = -1; // index of measurement used to set Beam Mode
747 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
748 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
749 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
750 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
751 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
752 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
755 Log("*************BeamMode (LHCState) ");
756 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
757 Int_t nBeamMode = -1;
759 nBeamMode = beamModeArray->GetEntries();
761 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
764 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
765 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
767 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
768 timeBeamModeStart = beamMode->GetTimeStamp();
769 indexBeamMode = iBeamMode;
770 foundBeamModeStart = kTRUE;
778 if (!foundBeamModeStart){
779 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
782 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
783 TObjString* beamModeString = beamMode->GetStringArray(0);
784 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
785 grpobj->SetLHCState(beamModeString->String());
786 if (indexBeamMode < nBeamMode-1){
787 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
789 if (beamMode1->GetTimeStamp()<=timeStart){
790 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
792 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
793 timeBeamModeEnd = beamMode1->GetTimeStamp();
794 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
795 TString bmString0 = beamModeString->String();
796 TString bmString1 = beamModeString1->String();
797 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
798 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()));
799 flagBeamMode = kTRUE;
804 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
809 delete beamModeArray;
812 AliError("Beam mode array not found in LHC Data file!!!");
816 Log("*************MachineMode ");
817 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
818 Int_t nMachineMode = -1;
819 if (machineModeArray){
820 nMachineMode = machineModeArray->GetEntries();
821 if (nMachineMode==0){
822 AliInfo("No Machine Mode found, leaving it empty");
825 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
826 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
828 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
829 timeMachineModeStart = machineMode->GetTimeStamp();
830 indexMachineMode = iMachineMode;
831 foundMachineModeStart = kTRUE;
838 if (!foundMachineModeStart){
839 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
842 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
843 TObjString* machineModeString = machineMode->GetStringArray(0);
844 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
845 grpobj->SetMachineMode(machineModeString->String());
846 if (indexMachineMode < nMachineMode-1){
847 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
849 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
850 timeMachineModeEnd = machineMode1->GetTimeStamp();
851 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
852 TString mmString0 = machineModeString->String();
853 TString mmString1 = machineModeString1->String();
854 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
855 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()));
856 flagMachineMode = kTRUE;
861 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
866 delete machineModeArray;
869 AliError("Machine mode array not found in LHC Data file!!!");
872 // BeamType1 and BeamType2 - both put in the same string
873 Log("*************BeamType ");
874 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
876 Int_t nBeam = beamArray->GetEntries();
878 AliInfo("No Beam Type found, leaving it empty");
881 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
882 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
884 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
885 timeBeamStart = beam->GetTimeStamp();
887 foundBeamStart = kTRUE;
894 if (!foundBeamStart){
895 AliInfo("No value for the Beam Type found before start of run, the Machine Mode will remain empty");
898 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
899 TObjString* beamString = beam->GetStringArray(0);
900 TString beamType = beamString->String();
901 AliInfo(Form("Beam Type = %s",beamType.Data()));
902 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
903 AliInfo("Setting beam type to p-p");
904 grpobj->SetBeamType("p-p");
906 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
907 AliInfo("Setting beam type to A-A");
908 grpobj->SetBeamType("A-A");
911 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
912 AliInfo("Setting beam type to Pb-Pb");
913 grpobj->SetBeamType("Pb-Pb");
916 AliError("Beam Type not known, leaving it empty");
919 if (indexBeam < nBeam-1){
920 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
922 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
923 timeBeamEnd = beam1->GetTimeStamp();
924 TObjString* beamString1 = beam1->GetStringArray(0);
925 TString beamType1 = beamString1->String();
926 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
927 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()));
933 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
941 AliError("Beam Type array not found in LHC Data file!!!");
944 // Setting minTimeLHCValidity
945 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
946 Double_t minTimeLHCValidity;
947 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true
948 minTimeLHCValidity = timeBeamEnd;
950 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
951 minTimeLHCValidity = timeMachineModeEnd;
953 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
954 minTimeLHCValidity = timeBeamModeEnd;
956 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
957 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
959 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
960 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
962 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
963 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
966 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
967 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
969 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
970 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
973 // Processing data to go to AliLHCData object
974 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
975 // storing AliLHCData in OCDB
977 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
979 md.SetResponsible("Ruben Shahoyan");
980 md.SetComment("LHC data from the GRP preprocessor.");
981 Bool_t result = kTRUE;
982 result = Store("GRP", "LHCData", dt, &md);
985 Log(Form("Problems in storing LHC Data - but not going into Error"));
989 // processing LHC Phase
991 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
992 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
993 if (beam1phase == 0x0 || beam2phase == 0x0){
994 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
997 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
999 AliInfo(Form("LHC Phase found"));
1000 AliCDBMetaData mdPhase;
1001 mdPhase.SetResponsible("Cvetan Cheshkov");
1002 mdPhase.SetComment("LHC Clock Phase");
1003 Bool_t result = kTRUE;
1004 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
1006 if (!result) return 3;
1012 AliError("No LHCData file found in DCS FXS");
1019 //_______________________________________________________________
1021 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
1024 //Getting the SPD Mean Vertex
1027 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
1028 Bool_t storeResult = kTRUE;
1029 if (list !=0x0 && list->GetEntries()!=0)
1031 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
1033 for (Int_t jj=0;jj<list->GetEntries();jj++){
1034 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1035 AliInfo(Form("found source %s", str->String().Data()));
1036 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
1037 if (fileNameRun.Length()>0){
1038 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1039 TFile daqFile(fileNameRun.Data(),"READ");
1040 if (daqFile.IsOpen()) {
1041 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
1044 // storing in the OCDB
1046 md.SetResponsible("Cvetan Cheshkov");
1047 md.SetComment("SPD Mean Vertex");
1048 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
1051 AliWarning("No SPD Mean Vertex object found in file");
1055 AliError("Can't open file");
1056 storeResult = kFALSE;
1060 AliWarning("No file found for current source for SPD Mean Vertex");
1065 AliWarning("No list found for SPD Mean Vertex");
1068 if (list) delete list;
1074 //_______________________________________________________________
1076 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
1078 //Getting the DAQ lb information
1080 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
1081 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
1082 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
1083 TString beamType = (TString)GetRunParameter("beamType");
1084 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
1085 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
1086 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
1087 TString runType = (TString)GetRunType();
1089 UInt_t nparameter = 0;
1090 if (timeStart != 0){
1091 grpObj->SetTimeStart(timeStart);
1092 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
1096 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1100 grpObj->SetTimeEnd(timeEnd);
1101 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
1105 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1108 if (beamEnergy != 0){
1109 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1112 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1116 if (beamType.Length() != 0){
1117 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()));
1120 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1123 if (numberOfDetectors != 0){
1124 grpObj->SetNumberOfDetectors(numberOfDetectors);
1125 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1129 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1132 if (detectorMask != 0){
1133 grpObj->SetDetectorMask(detectorMask);
1134 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1138 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1141 if (lhcPeriod.Length() != 0) {
1142 grpObj->SetLHCPeriod(lhcPeriod);
1143 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1147 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1149 if (runType.Length() != 0) {
1150 grpObj->SetRunType(runType);
1151 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1155 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1161 //_______________________________________________________________
1163 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1165 //======DAQ FXS======//
1167 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1168 AliRawEventHeaderV3_11::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_11 - temporary fix
1169 TList* list = GetFileSources(kDAQ);
1171 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1175 if (list->GetEntries() == 0) {
1176 Log("no raw data tags in this run: nothing to merge!");
1177 delete list; list=0;
1181 TChain *fRawTagChain = new TChain("T");
1183 TIterator* iter = list->MakeIterator();
1185 while ((obj = iter->Next())) {
1186 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1188 Log(Form("Found source %s", objStr->String().Data()));
1189 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1191 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1192 delete fRawTagChain; fRawTagChain=0;
1195 Log(Form("Number of ids: %d",list2->GetEntries()));
1196 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1197 TObjString *idStr = (TObjString *)list2->At(i);
1198 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1199 if (fileName.Length() > 0) {
1200 Log(Form("Adding file in the chain: %s",fileName.Data()));
1201 fRawTagChain->Add(fileName.Data());
1204 Log(Form("Could not retrieve file with id %s from source %s: "
1205 "connection problems with DAQ FXS!",
1206 idStr->String().Data(), objStr->String().Data()));
1207 delete list; list=0;
1208 delete list2; list2=0;
1209 delete fRawTagChain; fRawTagChain=0;
1217 TString fRawDataFileName = "GRP_Merged.tag.root";
1218 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1220 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1221 Log("Error merging raw data files!!!");
1225 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1226 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1229 Log("Problem storing raw data tags in local file!!!");
1231 Log("Raw data tags merged successfully!!");
1236 delete fRawTagChain; fRawTagChain=0;
1238 if (result == kFALSE) {
1246 //_______________________________________________________________
1247 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1250 // processing the info
1251 // stored in the DCS FXS
1252 // coming from the trigger
1254 // Get the CTP counters information
1256 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1257 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1258 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1260 Log(Form("No dummy CTP scalers entry found, going into error..."));
1264 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1266 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1270 AliCDBMetaData metaData;
1271 metaData.SetResponsible("Roman Lietava");
1272 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1273 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1274 Log("Unable to store the dummy CTP scalers object to OCDB!");
1281 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1282 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1283 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1284 if (countersfile.IsNull()) {
1285 Log("No CTP counters files has been found: empty source!");
1289 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1290 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1292 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1296 AliCDBMetaData metaData;
1297 metaData.SetBeamPeriod(0);
1298 metaData.SetResponsible("Roman Lietava");
1299 metaData.SetComment("CTP scalers");
1300 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1301 Log("Unable to store the CTP scalers object to OCDB!");
1312 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1319 //_______________________________________________________________
1321 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1325 // processing DCS DPs
1328 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1329 Int_t nL3Entries = 0;
1330 Int_t nDipoleEntries = 0;
1331 Int_t nEnvEntries = 0;
1332 Int_t nHallProbesEntries = 0;
1333 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1334 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1335 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1336 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1337 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1338 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1339 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1344 //_______________________________________________________________
1346 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1353 Int_t nL3Entries = 0;
1355 TObjArray *array = 0x0;
1357 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1359 AliInfo(Form("==========L3Current==========="));
1360 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1361 indexDP = kL3Current;
1362 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1364 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1367 if (array->GetEntries() == 0){
1368 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1371 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1372 if (floatDCS != NULL){
1373 grpObj->SetL3Current(floatDCS);
1385 ffailedDPs->RemoveAt(indexDP);
1389 if (array) array = 0x0;
1391 AliInfo(Form("==========L3Polarity==========="));
1392 indexDP = kL3Polarity;
1393 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1395 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1398 if (array->GetEntries() == 0){
1399 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1402 Bool_t change = kFALSE;
1403 Char_t charDCS = ProcessBool(array,change);
1404 if (change == kFALSE){
1405 grpObj->SetL3Polarity(charDCS);
1406 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1407 ffailedDPs->RemoveAt(indexDP);
1411 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1412 ffailedDPs->RemoveAt(indexDP);
1416 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]));
1424 //_______________________________________________________________
1426 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1432 Int_t nDipoleEntries = 0;
1433 TObjArray *array = 0x0;
1435 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1437 AliInfo(Form("==========DipoleCurrent==========="));
1438 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1439 indexDP = kDipoleCurrent;
1440 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1442 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1445 if (array->GetEntries() == 0){
1446 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1449 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1450 if (floatDCS != NULL){
1451 grpObj->SetDipoleCurrent(floatDCS);
1463 ffailedDPs->RemoveAt(indexDP);
1467 if (array) array = 0x0;
1469 AliInfo(Form("==========DipolePolarity==========="));
1470 indexDP = kDipolePolarity;
1471 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1473 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1476 if (array->GetEntries() == 0){
1477 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1480 Bool_t change = kFALSE;
1481 Char_t charDCS = ProcessBool(array,change);
1483 grpObj->SetDipolePolarity(charDCS);
1484 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1485 ffailedDPs->RemoveAt(indexDP);
1489 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1490 ffailedDPs->RemoveAt(indexDP);
1494 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]));
1499 return nDipoleEntries;
1502 //_______________________________________________________________
1504 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1508 // evironment conditions (temperature, pressure) info
1510 Int_t nEnvEntries = 0;
1511 TObjArray *array = 0x0;
1514 AliInfo(Form("==========CavernTemperature==========="));
1515 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1516 indexDP = kCavernTemperature;
1517 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1519 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1522 if (array->GetEntries() == 0){
1523 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1526 Float_t *floatDCS = ProcessFloatAll(array);
1527 if (floatDCS != NULL){
1528 grpObj->SetCavernTemperature(floatDCS);
1539 ffailedDPs->RemoveAt(indexDP);
1544 if (array) array = 0x0;
1546 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1547 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1548 //dcsSensorArray->Print();
1549 if( fPressure->NumFits()<kNumSensors ) {
1550 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1552 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1554 AliInfo(Form("==========CavernAtmosPressure==========="));
1555 indexDP = kCavernAtmosPressure;
1556 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1557 TGraph* graph = sensorCavernP2->GetGraph();
1558 AliDebug(3,Form("index = %d",indexDP));
1559 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1560 AliDebug(2,Form("graph = %p",graph));
1561 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1562 if(sensorCavernP2->GetFit() || graph) {
1563 if (sensorCavernP2->GetFit()){
1564 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1567 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1569 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1570 ffailedDPs->RemoveAt(indexDP);
1573 //if (sensorP2) delete sensorP2;
1575 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] ));
1578 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1579 indexDP = kSurfaceAtmosPressure;
1580 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1581 graph = sensorP2->GetGraph();
1582 AliDebug(3,Form("index = %d",indexDP));
1583 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1584 AliDebug(2,Form("graph = %p",graph));
1585 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1586 if(sensorP2->GetFit() || graph) {
1587 if (sensorP2->GetFit()){
1588 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1591 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1593 grpObj->SetSurfaceAtmosPressure(sensorP2);
1594 ffailedDPs->RemoveAt(indexDP);
1597 //if (sensorP2) delete sensorP2;
1599 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] ));
1602 AliInfo(Form("==========CavernAtmosPressure2==========="));
1603 indexDP = kCavernAtmosPressure2;
1604 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1605 graph = sensorCavernP22->GetGraph();
1606 AliDebug(3,Form("index = %d",indexDP));
1607 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1608 AliDebug(2,Form("graph = %p",graph));
1609 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1610 if(sensorCavernP22->GetFit() || graph) {
1611 if (sensorCavernP22->GetFit()){
1612 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1615 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1617 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1618 ffailedDPs->RemoveAt(indexDP);
1621 //if (sensorP2) delete sensorP2;
1623 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] ));
1629 //_______________________________________________________________
1631 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1637 Int_t nHPEntries = 0;
1638 TObjArray *array = 0x0;
1640 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1642 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1643 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()));
1645 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1646 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1647 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1648 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1650 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1653 if (array->GetEntries() == 0){
1654 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1657 Float_t *floatDCS = ProcessFloatAll(array);
1658 if (floatDCS != NULL){
1659 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]));
1660 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1661 for (Int_t kk = 0 ; kk< 5; kk++){
1662 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1674 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1680 Log(Form("Hall Probes = %d ", nHPEntries));
1684 //_________________________________________________________________________
1686 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1690 // returning Spline Fit
1693 Int_t entriesarray = array->GetEntries();
1694 Float_t* value = new Float_t[entriesarray];
1695 Float_t* time = new Float_t[entriesarray];
1696 AliDCSValue* v = 0x0;
1697 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1698 v = (AliDCSValue*)array->At(iarray);
1699 value[iarray] = v->GetFloat();
1700 time[iarray] = v->GetTimeStamp();
1701 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1703 TGraph* gr = new TGraph(entriesarray,value,time);
1705 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1708 AliSplineFit *fit = new AliSplineFit();
1709 fit->SetMinPoints(10);
1710 fit->InitKnots(gr,10,10,0.0);
1714 AliWarning(Form("%s: no fit performed",stringID.Data()));
1720 //_________________________________________________________________________
1722 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1729 TString aDCSString="";
1731 AliDCSValue *v = 0x0;
1732 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1733 v = (AliDCSValue *)array->At(iCount);
1734 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1735 AliError(Form("DCS values for the parameter outside the queried interval"));
1739 if (aDCSString != v->GetChar())
1740 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1742 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1747 //__________________________________________________________________________________________________________________
1749 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1752 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1754 // parameters[0] = mean
1755 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1756 // parameters[2] = median
1757 // parameters[3] = standard deviation wrt mean
1758 // parameters[4] = standard deviation wrt median
1761 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1762 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1763 if (timeStartString.IsNull() || timeStartString.IsNull()){
1764 if (timeStartString.IsNull()){
1765 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1767 else if (timeStartString.IsNull()){
1768 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1770 fdaqStartEndTimeOk = kFALSE;
1774 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1775 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1776 Float_t* parameters = new Float_t[5];
1778 Int_t iCountsRun = 0;
1779 Int_t nCounts = array->GetEntries();
1780 Float_t valueBeforeSOR = 0;
1781 Float_t valueAfterEOR = 0;
1782 Int_t timestampBeforeSOR = -1;
1783 Int_t timestampAfterEOR = -1;
1784 Int_t ientrySOR = -1;
1785 Int_t ientryEOR = -1;
1786 Float_t* arrayValues = 0x0;
1787 Double_t* arrayWeights = 0x0;
1788 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1789 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1791 for(Int_t i = 0; i < nCounts; i++) {
1792 AliDCSValue *v = (AliDCSValue *)array->At(i);
1793 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1794 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1795 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1796 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1799 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1800 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1802 // look for the last value before SOR and the first value before EOR
1803 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1804 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1805 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1806 valueBeforeSOR = v->GetFloat();
1808 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1809 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1810 valueAfterEOR = v->GetFloat();
1811 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1813 // check if there are DPs between DAQ_time_start and DAQ_time_end
1814 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1815 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1816 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1817 AliDebug(2,Form("entry between SOR and EOR"));
1822 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1826 if (timestampBeforeSOR == -1){
1827 AliWarning("No value found before SOR");
1829 if (timestampAfterEOR == -1){
1830 AliWarning("No value found after EOR");
1833 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1834 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1835 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1836 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1837 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1838 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1840 Int_t nentriesUsed = 0;
1841 if (iCountsRun > 1){
1842 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1843 AliDebug(2,"Calculating (weighted) Mean and Median");
1844 arrayValues = new Float_t[iCountsRun];
1845 arrayWeights = new Double_t[iCountsRun];
1846 nentriesUsed = iCountsRun;
1847 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1848 AliDCSValue *v = (AliDCSValue *)array->At(i);
1849 Int_t timestamp2 = 0;
1851 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1852 timestamp2 = (Int_t)v1->GetTimeStamp();
1855 timestamp2 = timeEnd+1;
1857 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1858 arrayValues[i-ientrySOR] = v->GetFloat();
1860 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1861 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1863 else if (iCountsRun == 1){
1864 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1866 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1867 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.");
1868 arrayValues = new Float_t[2];
1869 arrayWeights = new Double_t[2];
1870 arrayValues[0] = valueBeforeSOR;
1871 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1872 arrayValues[1] = v->GetFloat();
1873 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1874 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1875 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1876 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1877 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1878 truncMeanFlag = kFALSE;
1881 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");
1882 parameters[0] = AliGRPObject::GetInvalidFloat();
1883 parameters[1] = AliGRPObject::GetInvalidFloat();
1884 parameters[2] = AliGRPObject::GetInvalidFloat();
1885 parameters[3] = AliGRPObject::GetInvalidFloat();
1886 parameters[4] = AliGRPObject::GetInvalidFloat();
1890 else { // iCountsRun == 0, using only the point immediately before SOR
1891 if (timestampBeforeSOR == -1){
1892 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");
1893 parameters[0] = AliGRPObject::GetInvalidFloat();
1894 parameters[1] = AliGRPObject::GetInvalidFloat();
1895 parameters[2] = AliGRPObject::GetInvalidFloat();
1896 parameters[3] = AliGRPObject::GetInvalidFloat();
1897 parameters[4] = AliGRPObject::GetInvalidFloat();
1901 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1902 AliDebug(2,Form("value = %f",valueBeforeSOR));
1903 parameters[0] = valueBeforeSOR;
1904 parameters[2] = valueBeforeSOR;
1905 truncMeanFlag = kFALSE;
1912 Float_t sumweights = 0;
1913 Int_t entriesTruncMean = 0;
1914 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1915 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1917 // calculating SD wrt Mean and Median
1918 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1920 for (Int_t i =0; i< nentriesUsed; i++){
1921 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1922 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1923 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1924 sumweights += arrayWeights[i];
1926 // setting SD wrt Mean
1927 if (sumweights != 0 ){
1928 parameters[3] = TMath::Sqrt(temp1/sumweights);
1931 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1932 parameters[3] = AliGRPObject::GetInvalidFloat();
1934 // setting SD wrt Median
1935 if (nentriesUsed != 0){
1936 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1939 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1940 parameters[4] = AliGRPObject::GetInvalidFloat();
1944 parameters[3] = AliGRPObject::GetInvalidFloat();
1945 parameters[4] = AliGRPObject::GetInvalidFloat();
1948 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1950 AliDebug(2,"Calculating Truncated Mean");
1951 for (Int_t i =0; i< nentriesUsed; i++){
1952 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1953 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1954 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1955 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1956 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1960 AliDebug(2,"Discarding entry");
1963 // setting truncated mean
1964 if (entriesTruncMean >1){
1965 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1966 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1969 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1970 parameters[1] = AliGRPObject::GetInvalidFloat();
1974 parameters[1] = AliGRPObject::GetInvalidFloat();
1977 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1978 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1979 AliInfo(Form("median = %f ",parameters[2]));
1980 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1981 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1986 //__________________________________________________________________________________________________________________
1988 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1991 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1992 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1993 // the flag is set according to the L3/Dipole current value
1994 // current threshold for L3 = 350 A (value provided by DCS)
1995 // current threshold for Dipole = 450 A (value provided by DCS)
1997 // parameters[0] = mean
1998 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1999 // parameters[2] = median
2000 // parameters[3] = standard deviation wrt mean
2001 // parameters[4] = standard deviation wrt median
2004 AliInfo(Form("indexDP = %d",indexDP));
2006 Int_t nCounts = array->GetEntries();
2007 for(Int_t i = 0; i < nCounts; i++) {
2008 AliDCSValue *v = (AliDCSValue *)array->At(i);
2009 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2010 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2011 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2012 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
2015 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2016 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
2017 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2018 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
2021 AliError(Form("DCS values for the parameter outside the queried interval"));
2025 return ProcessFloatAll(array);
2029 //_______________________________________________________________
2031 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
2034 // processing Boolean values
2037 Bool_t aDCSBool = kTRUE;
2039 AliDCSValue *v = 0x0;
2041 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2042 v = (AliDCSValue *)array->At(iCount);
2043 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
2044 AliError(Form("DCS values for the parameter outside the queried interval"));
2048 if (aDCSBool != v->GetBool()) {
2049 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2053 aDCSBool = v->GetBool(); // always keeping last value
2054 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
2057 Char_t caDCSBool = (Char_t) aDCSBool;
2062 //_______________________________________________________________
2064 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
2067 // processing Int values, returning mean
2068 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2069 // are outside the queried time interval or their value is out of range
2072 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2073 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2074 if (timeStartString.IsNull() || timeStartString.IsNull()){
2075 if (timeStartString.IsNull()){
2076 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2078 else if (timeStartString.IsNull()){
2079 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2084 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2085 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2086 Float_t aDCSArrayMean = 0.0;
2088 Float_t valueBeforeSOR = 0;
2089 Float_t valueAfterEOR = 0;
2090 Int_t timestampBeforeSOR = -1;
2091 Int_t timestampAfterEOR = -1;
2092 Int_t ientrySOR = -1;
2093 Int_t ientryEOR = -1;
2094 Float_t* arrayValues = 0x0;
2095 Double_t* arrayWeights = 0x0;
2096 Int_t iCountsRun = 0;
2097 Int_t nCounts = array->GetEntries();
2099 for(Int_t i = 0; i < nCounts; i++) {
2100 AliDCSValue* v = (AliDCSValue *)array->At(i);
2101 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
2102 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
2103 return AliGRPObject::GetInvalidFloat();
2105 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2106 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
2108 // look for the last value before SOR and the first value before EOR
2109 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2110 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2111 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2112 valueBeforeSOR = (Float_t) v->GetInt();
2114 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2115 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2116 valueAfterEOR = (Float_t) v->GetInt();
2117 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2119 // check if there are DPs between DAQ_time_start and DAQ_time_end
2120 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2121 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2122 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2123 AliDebug(2,Form("entry between SOR and EOR"));
2128 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2132 if (timestampBeforeSOR == -1){
2133 AliWarning("No value found before SOR!");
2135 if (timestampAfterEOR == -1){
2136 AliWarning("No value found after EOR!");
2139 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2140 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2141 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2142 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2143 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2144 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2146 Int_t nentriesUsed = 0;
2147 if (iCountsRun > 1){
2148 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2149 AliDebug(2,"Calculating (weighted) Mean");
2150 arrayValues = new Float_t[iCountsRun];
2151 arrayWeights = new Double_t[iCountsRun];
2152 nentriesUsed = iCountsRun;
2153 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2154 AliDCSValue *v = (AliDCSValue *)array->At(i);
2155 Int_t timestamp2 = 0;
2157 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2158 timestamp2 = (Int_t)v1->GetTimeStamp();
2161 timestamp2 = timeEnd+1;
2163 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2164 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2166 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2168 else if (iCountsRun == 1){
2169 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2171 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2172 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2173 arrayValues = new Float_t[2];
2174 arrayWeights = new Double_t[2];
2175 arrayValues[0] = valueBeforeSOR;
2176 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2177 arrayValues[1] = (Float_t)v->GetInt();
2178 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2179 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2180 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2181 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2184 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2185 return AliGRPObject::GetInvalidFloat();
2188 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2189 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2190 if (timestampBeforeSOR == -1){
2191 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2193 if (timestampAfterEOR == -1){
2194 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2196 return AliGRPObject::GetInvalidFloat();
2199 AliWarning("Using last entry before SOR and first entry after EOR.");
2201 arrayValues = new Float_t[2];
2202 arrayWeights = new Double_t[2];
2203 arrayValues[0] = valueBeforeSOR;
2204 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2205 arrayValues[1] = valueAfterEOR;
2206 arrayWeights[1] = 1.;
2207 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2208 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2209 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2213 AliInfo(Form("mean = %f ", aDCSArrayMean));
2214 return aDCSArrayMean;
2217 //_______________________________________________________________
2219 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2222 // processing Int values, returning mean
2223 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2224 // are outside the queried time interval or their value is out of range
2227 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2228 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2229 if (timeStartString.IsNull() || timeStartString.IsNull()){
2230 if (timeStartString.IsNull()){
2231 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2233 else if (timeStartString.IsNull()){
2234 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2239 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2240 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2241 Float_t aDCSArrayMean = 0.0;
2243 Float_t valueBeforeSOR = 0;
2244 Float_t valueAfterEOR = 0;
2245 Int_t timestampBeforeSOR = -1;
2246 Int_t timestampAfterEOR = -1;
2247 Int_t ientrySOR = -1;
2248 Int_t ientryEOR = -1;
2249 Float_t* arrayValues = 0x0;
2250 Double_t* arrayWeights = 0x0;
2251 Int_t iCountsRun = 0;
2252 Int_t nCounts = array->GetEntries();
2254 for(Int_t i = 0; i < nCounts; i++) {
2255 AliDCSValue* v = (AliDCSValue *)array->At(i);
2256 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2257 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2258 return AliGRPObject::GetInvalidFloat();
2260 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2261 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2263 // look for the last value before SOR and the first value before EOR
2264 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2265 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2266 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2267 valueBeforeSOR = (Float_t)v->GetUInt();
2269 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2270 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2271 valueAfterEOR = (Float_t)v->GetUInt();
2272 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2274 // check if there are DPs between DAQ_time_start and DAQ_time_end
2275 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2276 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2277 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2278 AliDebug(2,Form("entry between SOR and EOR"));
2283 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2287 if (timestampBeforeSOR == -1){
2288 AliWarning("No value found before SOR!");
2290 if (timestampAfterEOR == -1){
2291 AliWarning("No value found after EOR!");
2294 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2295 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2296 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2297 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2298 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2299 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2301 Int_t nentriesUsed = 0;
2302 if (iCountsRun > 1){
2303 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2304 AliDebug(2,"Calculating (weighted) Mean");
2305 arrayValues = new Float_t[iCountsRun];
2306 arrayWeights = new Double_t[iCountsRun];
2307 nentriesUsed = iCountsRun;
2308 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2309 AliDCSValue *v = (AliDCSValue *)array->At(i);
2310 Int_t timestamp2 = 0;
2312 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2313 timestamp2 = (Int_t)v1->GetTimeStamp();
2316 timestamp2 = timeEnd+1;
2318 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2319 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2321 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2323 else if (iCountsRun == 1){
2324 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2326 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2327 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2328 arrayValues = new Float_t[2];
2329 arrayWeights = new Double_t[2];
2330 arrayValues[0] = valueBeforeSOR;
2331 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2332 arrayValues[1] = (Float_t)v->GetUInt();
2333 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2334 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2335 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2336 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2339 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2340 return AliGRPObject::GetInvalidFloat();
2343 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2344 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2345 if (timestampBeforeSOR == -1){
2346 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2348 if (timestampAfterEOR == -1){
2349 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2351 return AliGRPObject::GetInvalidFloat();
2354 AliWarning("Using last entry before SOR and first entry after EOR.");
2356 arrayValues = new Float_t[2];
2357 arrayWeights = new Double_t[2];
2358 arrayValues[0] = valueBeforeSOR;
2359 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2360 arrayValues[1] = valueAfterEOR;
2361 arrayWeights[1] = 1.;
2362 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2363 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2364 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2368 AliInfo(Form("mean = %f ",aDCSArrayMean));
2369 return aDCSArrayMean;
2374 //_______________________________________________________________
2376 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2378 // extract DCS pressure maps. Perform fits to save space
2380 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2382 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2383 fPressure->MakeSplineFit(map);
2384 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2385 if (fitFraction > kFitFraction ) {
2386 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2388 AliInfo("Too few pressure maps fitted!!!");
2391 AliInfo("no atmospheric pressure map extracted!!!");
2400 //_______________________________________________________________
2401 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)
2404 // Retrieves logbook and trigger information from the online logbook
2405 // This information is needed for prompt reconstruction
2409 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2413 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2414 // 0 on success and no run was found
2415 // negative on error
2417 // This function is NOT called during the preprocessor run in the Shuttle!
2425 AliCDBManager* cdb = AliCDBManager::Instance();
2426 cdb->SetDefaultStorage(cdbRoot);
2429 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2433 Printf("ERROR: Could not connect to DAQ LB");
2439 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
2440 TSQLResult* result = server->Query(sqlQuery);
2443 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2447 if (result->GetRowCount() == 0)
2449 Printf("ERROR: Run %d not found", run);
2454 TSQLRow* row = result->Next();
2457 Printf("ERROR: Could not receive data from run %d", run);
2462 TString timeStartString(row->GetField(0));
2463 TString runType(row->GetField(1));
2464 TString detectorMaskString(row->GetField(2));
2465 TString l3CurrentString(row->GetField(3));
2466 TString dipoleCurrentString(row->GetField(4));
2467 TString beamTypeString(row->GetField(5));
2468 time_t timeStart = (time_t)(timeStartString.Atoi());
2469 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2470 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2471 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2472 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2473 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2474 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
2475 beamTypeString="A-A";
2478 AliGRPObject * grpObj = new AliGRPObject();
2479 grpObj->SetTimeStart(timeStart);
2480 grpObj->SetRunType((TString)(row->GetField(1)));
2481 grpObj->SetDetectorMask(detectorMask);
2482 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2483 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2484 grpObj->SetL3Polarity(l3Polarity);
2485 grpObj->SetDipolePolarity(dipolePolarity);
2486 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2487 grpObj->SetBeamType(beamTypeString);
2495 Printf("Storing GRP/GRP/Data object with the following content");
2498 AliCDBMetaData metadata;
2499 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2500 metadata.SetComment("GRP Output parameters received during online running");
2502 AliCDBId id("GRP/GRP/Data", run, run);
2503 Bool_t success = cdb->Put(grpObj, id, &metadata);
2509 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2513 // Receive trigger information
2514 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2515 result = server->Query(sqlQuery);
2518 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2522 if (result->GetRowCount() == 0)
2524 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2529 row = result->Next();
2532 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2537 TString triggerConfig(row->GetField(0));
2545 Printf("Found trigger configuration: %s", triggerConfig.Data());
2547 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2550 Printf("ERROR: Could not create CTP configuration object");
2554 metadata.SetComment("CTP run configuration received during online running");
2556 AliCDBId id2("GRP/CTP/Config", run, run);
2557 success = cdb->Put(runcfg, id2, &metadata);
2564 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2569 // Receive list of GDCs for this run
2570 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2571 result = server->Query(sqlQuery);
2574 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2578 if (result->GetRowCount() == 0)
2580 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2586 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2587 row = result->Next();
2590 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2594 gdc += row->GetField(0);
2604 Printf("Found GDC: %s", gdc.Data());
2606 // get last run with same run type that was already processed by the SHUTTLE
2608 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());
2609 result = server->Query(sqlQuery);
2612 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2616 if (result->GetRowCount() == 0)
2618 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2623 row = result->Next();
2626 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2631 TString lastRunStr(row->GetField(0));
2632 Int_t lastRun = lastRunStr.Atoi();
2634 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2648 //-----------------------------------------------------------------
2649 Double_t AliGRPPreprocessor::CalculateMean(TObjArray* const array){
2652 // Calculating mean over TObjArray from LHC Data
2655 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2656 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2657 if (timeStartString.IsNull() || timeStartString.IsNull()){
2658 if (timeStartString.IsNull()){
2659 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2661 else if (timeStartString.IsNull()){
2662 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2667 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2668 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2669 timeStart = 1260646960;
2670 timeEnd = 1260652740;
2671 Double_t* parameters = new Double_t[5];
2672 parameters[0] = -1.;
2673 parameters[1] = -1.;
2674 parameters[2] = -1.;
2675 parameters[3] = -1.;
2676 parameters[4] = -1.;
2678 Int_t iCountsRun = 0;
2679 Int_t nCounts = array->GetEntries();
2680 printf("ncounts = %d\n",nCounts);
2681 Double_t valueBeforeSOR = 0;
2682 Double_t valueAfterEOR = 0;
2683 Double_t timestampBeforeSOR = -1.;
2684 Double_t timestampAfterEOR = -1.;
2685 Int_t ientrySOR = -1;
2686 Int_t ientryEOR = -1;
2687 Double_t* arrayValues = 0x0;
2688 Double_t* arrayWeights = 0x0;
2689 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2690 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2692 for(Int_t i = 0; i < nCounts; i++) {
2693 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2694 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2695 AliDebug(2,Form("%d-th entry = %f at timestamp %f\n",i,(Double_t)(dcs->GetInt(0)),dcs->GetTimeStamp()));
2697 // look for the last value before SOR and the first value before EOR
2698 if ((dcs->GetTimeStamp() >= timeStart) && (dcs->GetTimeStamp() < timeStart)) {
2699 timestampBeforeSOR = dcs->GetTimeStamp();
2700 AliDebug(2,Form("timestamp of last value before SOR = %f, with DAQ_time_start = %d\n",timestampBeforeSOR,timeStart));
2701 valueBeforeSOR = (Double_t)(dcs->GetInt(0));
2703 else if ((dcs->GetTimeStamp() <= timeEnd) && (dcs->GetTimeStamp() > timeEnd) && timestampAfterEOR == -1){
2704 timestampAfterEOR = dcs->GetTimeStamp();
2705 valueAfterEOR = (Double_t)(dcs->GetInt(0));
2706 AliDebug(2,Form("timestamp of first value after EOR = %f, with DAQ_time_end = %d\n",timestampAfterEOR,timeEnd));
2708 // check if there are DPs between DAQ_time_start and DAQ_time_end
2709 if((dcs->GetTimeStamp() >= timeStart) &&(dcs->GetTimeStamp() <= timeEnd)) {
2710 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2711 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2712 AliDebug(2,Form("entry between SOR and EOR\n"));
2717 printf("DCS values for the parameter outside the queried interval: timestamp = %f\n",dcs->GetTimeStamp());
2721 if (timestampBeforeSOR == -1.){
2722 printf("No value found before SOR\n");
2724 if (timestampAfterEOR == -1.){
2725 printf("No value found after EOR\n");
2728 printf("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries\n",iCounts,nCounts);
2729 printf("Last value before DAQ_time_start (SOR) = %f at timestamp = %f\n",valueBeforeSOR,timestampBeforeSOR);
2730 printf("First value after DAQ_time_end (EOR) = %f at timestamp = %f\n",valueAfterEOR,timestampAfterEOR);
2731 printf("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n",iCountsRun);
2732 printf("Index of first entry after DAQ_time_start (SOR) = %d\n ",ientrySOR);
2733 printf("Index of first entry before DAQ_time_end (EOR) = %d\n ",ientryEOR);
2735 Int_t nentriesUsed = 0;
2736 if (iCountsRun > 1){
2737 printf("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)\n");
2738 printf("Calculating (weighted) Mean and Median\n" );
2739 arrayValues = new Double_t[iCountsRun];
2740 arrayWeights = new Double_t[iCountsRun];
2741 nentriesUsed = iCountsRun;
2742 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2743 AliDCSArray *dcs = (AliDCSArray *)array->At(i);
2744 Double_t timestamp2 = 0;
2746 AliDCSArray *dcs1 = (AliDCSArray *)array->At(i+1);
2747 timestamp2 = dcs1->GetTimeStamp();
2750 timestamp2 = (Double_t)timeEnd+1;
2752 arrayWeights[i-ientrySOR] = (Double_t)((Double_t)timestamp2 - dcs->GetTimeStamp());
2753 arrayValues[i-ientrySOR] = (Double_t)(dcs->GetInt(0));
2754 printf("Entry %d: value = %f, weight = %f\n",i-ientrySOR,arrayValues[i-ientrySOR],arrayWeights[i-ientrySOR]);
2756 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2757 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2759 else if (iCountsRun == 1){
2760 AliDCSArray* dcs = (AliDCSArray *)array->At(ientrySOR);
2762 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)dcs->GetTimeStamp()){
2763 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");
2764 arrayValues = new Double_t[2];
2765 arrayWeights = new Double_t[2];
2766 arrayValues[0] = valueBeforeSOR;
2767 arrayWeights[0] = (Double_t)(dcs->GetTimeStamp()-(Double_t)timestampBeforeSOR);
2768 arrayValues[1] = (Double_t)(dcs->GetInt(0));
2769 arrayWeights[1] = (Double_t)((Double_t)timeEnd+1-dcs->GetTimeStamp());
2770 printf("value0 = %f, with weight = %f\n",arrayValues[0],arrayWeights[0]);
2771 printf("value1 = %f, with weight = %f\n",arrayValues[1],arrayWeights[1]);
2772 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2773 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2774 truncMeanFlag = kFALSE;
2777 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");
2783 return parameters[0];
2786 else { // iCountsRun == 0, using only the point immediately before SOR
2787 if (timestampBeforeSOR == -1.){
2788 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");
2794 return parameters[0];
2797 printf("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.\n");
2798 printf("value = %f\n",valueBeforeSOR);
2799 parameters[0] = valueBeforeSOR;
2800 parameters[2] = valueBeforeSOR;
2801 truncMeanFlag = kFALSE;
2808 Double_t sumweights = 0;
2809 Int_t entriesTruncMean = 0;
2810 Double_t* arrayValuesTruncMean = new Double_t[nentriesUsed];
2811 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2813 // calculating SD wrt Mean and Median
2814 printf("Calculating SD wrt Mean and SD wrt Median\n");
2816 for (Int_t i =0; i< nentriesUsed; i++){
2817 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2818 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2819 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2820 sumweights += arrayWeights[i];
2822 // setting SD wrt Mean
2823 if (sumweights != 0 ){
2824 parameters[3] = TMath::Sqrt(temp1/sumweights);
2827 printf("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid\n");
2830 // setting SD wrt Median
2831 if (nentriesUsed != 0){
2832 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2835 printf("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid\n");
2844 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2846 printf("Calculating Truncated Mean\n");
2847 for (Int_t i =0; i< nentriesUsed; i++){
2848 //printf("Entry %d: value = %f, weight = %f\n",i,arrayValues[i],arrayWeights[i]);
2849 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2850 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2851 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2852 printf("For Truncated Mean: Entry %d: value = %f, weight = %f\n",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]);
2856 printf("Discarding entry\n");
2859 // setting truncated mean
2860 if (entriesTruncMean >1){
2861 printf("%d entries used for truncated mean\n",entriesTruncMean);
2862 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2865 printf("Too few entries (%d) to calculate truncated mean\n",entriesTruncMean);
2873 printf("(weighted) mean = %f \n",parameters[0]);
2874 printf("(weighted) truncated mean = %f \n",parameters[1]);
2875 printf("median = %f \n",parameters[2]);
2876 printf("(weighted) standard deviation with (weighted) mean = %f \n",parameters[3]);
2877 printf("standard deviation with median = %f \n",parameters[4]);
2879 return (parameters[0]);
2881 //------------------------------------------------------------------------------------------------------
2882 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
2885 // Method to processo LHC Energy information
2886 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2889 Int_t nCounts = array->GetEntries();
2890 Float_t energy = -1;
2891 Double_t timeEnergy = -1;
2892 Int_t indexEnergy = -1;
2893 Bool_t foundEnergy = kFALSE;
2895 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2897 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2900 for (Int_t i = 0; i < nCounts; i++){
2901 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2903 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
2904 timeEnergy = dcs->GetTimeStamp();
2906 foundEnergy = kTRUE;
2914 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
2917 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
2918 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2919 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
2925 //------------------------------------------------------------------------------------------------------
2926 AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
2929 // Method to process LHC-Clock Phase data
2930 // Only the values between DAQ_time_start and DAQ_time_end are kept
2932 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
2934 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
2935 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
2937 TString timeCreatedStr = GetRunParameter("time_created");
2938 Double_t timeCreated = timeCreatedStr.Atof();
2940 Int_t nCounts = beam1phase->GetEntries();
2941 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
2943 AliWarning("No beam1 LHC clock phase values found!");
2948 Double_t prevPhase = 0;
2949 for (Int_t i = 0; i < nCounts; i++){
2950 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
2952 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
2953 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2954 if ((i == 0) || (i == (nCounts-1)) ||
2956 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2957 prevPhase = dcs->GetDouble(0);
2958 foundBeam1Phase = kTRUE;
2959 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
2960 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2961 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2966 if (!foundBeam1Phase){
2967 AliError("No beam1 LHC clock phase values found within the run!");
2973 nCounts = beam2phase->GetEntries();
2974 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
2976 AliWarning("No beam2 LHC clock phase values found!");
2981 Double_t prevPhase = 0;
2982 for (Int_t i = 0; i < nCounts; i++){
2983 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
2985 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2986 if ((i == 0) || (i == (nCounts-1)) ||
2988 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2989 prevPhase = dcs->GetDouble(0);
2990 foundBeam2Phase = kTRUE;
2991 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
2992 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2993 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2998 if (!foundBeam2Phase){
2999 AliError("No beam2 LHC clock phase values found within the run!");