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 <THashList.h>
30 #include <TObjString.h>
31 #include <TObjArray.h>
39 #include "AliGRPPreprocessor.h"
40 #include "AliGRPObject.h"
41 #include "AliDCSSensor.h"
42 #include "AliSplineFit.h"
43 #include "AliDCSSensorArray.h"
44 #include "AliRawEventHeaderVersions.h"
46 #include "AliTriggerConfiguration.h"
47 #include "AliTriggerRunScalers.h"
48 #include "AliTriggerInput.h"
50 #include "AliCDBMetaData.h"
51 #include "AliESDVertex.h"
52 #include "AliLHCReader.h"
53 #include "AliLHCData.h"
54 #include "AliDCSArray.h"
56 #include "AliLTUConfig.h"
57 #include "AliQAThresholds.h"
61 class AliShuttleInterface;
63 // needed for ReceivePromptRecoParameters
65 #include <TSQLServer.h>
66 #include <TSQLResult.h>
68 #include <AliCDBManager.h>
69 #include <AliCDBMetaData.h>
71 #include <AliTriggerConfiguration.h>
72 #include "AliCTPTimeParams.h"
73 #include "AliLHCClockPhase.h"
75 ClassImp(AliGRPPreprocessor)
78 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
80 //_______________________________________________________________
82 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 6; // num parameters in the logbook used to fill the GRP object
83 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
84 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
85 const Int_t AliGRPPreprocessor::fgknLHCDP = 9; // number of dcs dps from LHC data
86 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
87 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
88 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
96 "L3_BSF17_Temperature",
100 "L3_BSF4_Temperature",
104 "L3_BKF17_Temperature",
108 "L3_BKF4_Temperature",
112 "L3_BSF13_Temperature",
116 "L3_BSF8_Temperature",
120 "L3_BKF13_Temperature",
124 "L3_BKF8_Temperature",
128 "Dipole_Inside_Temperature",
132 "Dipole_Outside_Temperature",
134 "CavernAtmosPressure",
135 "SurfaceAtmosPressure",
136 "CavernAtmosPressure2"
139 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
143 "L3_BSF17_Temperature",
147 "L3_BSF4_Temperature",
151 "L3_BKF17_Temperature",
155 "L3_BKF4_Temperature",
159 "L3_BSF13_Temperature",
163 "L3_BSF8_Temperature",
167 "L3_BKF13_Temperature",
171 "L3_BKF8_Temperature",
175 "Dipole_Inside_Temperature",
179 "Dipole_Outside_Temperature"
182 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
183 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
186 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
190 "LHC_Beams_Particle_Type",
191 "BPTX_Phase_Shift_B1",
192 "BPTX_Phase_Shift_B2",
193 "LHC_Particle_Type_B1",
194 "LHC_Particle_Type_B2",
195 "LHC_Data_Quality_Flag"
198 const char* kppError[] = {
200 "(DAQ logbook ERROR)",
202 "(Trigger Scalers not found in FXS - ERROR)",
203 "(DCS data points ERROR)",
204 "(Trigger Configuration ERROR)",
205 "(DAQ logbook ERROR determining partition of the run)",
206 "(CTP timing ERROR)",
207 "(SPD Mean Vertex ERROR)",
208 "(FXS Error for LHC Data)",
210 "(LHC Clock Phase Error (from LHC Data))",
211 "(LTU Configuration Error)",
213 "(Trigger Aliases wrong or not found in DCS FXS - ERROR)"
216 //_______________________________________________________________
218 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
219 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))
221 // constructor - shuttle must be instantiated!
223 AddRunType("COSMIC");
225 AddRunType("PHYSICS");
226 AddRunType("CALIBRATION_BC");
227 AddRunType("CALIBRATION_CENTRAL");
228 AddRunType("CALIBRATION_EMD");
229 AddRunType("CALIBRATION_MB");
230 AddRunType("CALIBRATION_SEMICENTRAL");
231 AddRunType("CALIBRATION");
232 AddRunType("PEDESTAL");
233 AddRunType("STANDALONE");
236 AddRunType("PULSER");
237 AddRunType("STANDALONE_PULSER");
238 AddRunType("STANDALONE_BC");
241 fminFloat = -FLT_MAX;
242 fmaxDouble = DBL_MAX;
243 fminDouble = -DBL_MAX;
249 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
250 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
251 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
252 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
253 AliInfo(Form("Max allowed integer = %d",fmaxInt));
254 AliInfo(Form("Min allowed integer = %d",fminInt));
255 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
256 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
258 ffailedDPs->SetOwner(kTRUE);
261 //_______________________________________________________________
263 AliGRPPreprocessor::~AliGRPPreprocessor()
272 //_______________________________________________________________
274 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
276 // Initialize preprocessor
278 AliPreprocessor::Initialize(run, startTime, endTime);
280 AliInfo("Initialization of the GRP preprocessor.");
281 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
282 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
283 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
284 for(Int_t j = 0; j < kNumSensors; j++) {
285 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
286 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
288 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
290 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
292 ffailedDPs->Clear(); // cleaning ffailedDPs for current run
293 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
294 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
295 ffailedDPs->AddAt(dp,iDP);
300 //_______________________________________________________________
302 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
304 // process data retrieved by the Shuttle
306 // retrieving "partition" and "detector" fields from DAQ logbook to
307 // determine the partition in which the run was taken
308 // the partition is used to decide how to react in case of errors for CTP
310 TString partition = (TString)GetRunParameter("partition");
311 TString detector = (TString)GetRunParameter("detector");
313 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
314 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
316 //=================//
318 //=================//
320 Log("*************** Processing DAQ logbook");
324 Int_t iDaqLB = ProcessDaqLB(grpobj);
325 TString runType = (TString)GetRunType();
326 TString beamType = (TString)GetRunParameter("beamType");
327 if(iDaqLB == fgknDAQLbPar) {
328 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
330 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
334 //=================//
336 //=================//
338 Log("*************** Processing DAQ FXS");
340 UInt_t iDaqFxs = ProcessDaqFxs();
342 Log(Form("DAQ FXS, successful!"));
344 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
348 //=================//
350 //=================//
352 Log("*************** Processing DCS FXS");
354 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
356 Log(Form("DCS FXS, successful!"));
357 } else if (iDcsFxs ==1) {
358 Log(Form("Could not store CTP scalers!!!"));
360 } else if (iDcsFxs == 2) {
361 Log(Form("Could not store CTP aliases!!!"));
364 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
368 //=================//
369 // DCS data points //
370 //=================//
372 Log("*************** Processing DCS DPs");
374 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
375 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
376 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
377 if (fdaqStartEndTimeOk){
378 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
379 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
380 Log(Form("The DPs giving problems were:"));
381 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
382 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
384 TString name = dpString->String();
385 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
386 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
389 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()));
395 else Log(Form("DCS data points, successful!"));
397 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"));
399 //=======================//
400 // Trigger Configuration //
401 //=======================//
403 Log("*************** Processing Trigger Configuration");
405 const char * triggerConf = GetTriggerConfiguration();
407 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
408 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
409 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
411 Log(Form("No dummy CTP configuration entry found, going into error..."));
415 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
417 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
421 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
422 runcfg->SetTitle(titleCTPcfg);
423 AliCDBMetaData metaData;
424 metaData.SetResponsible("Roman Lietava");
425 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
426 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
427 Log("Unable to store the dummy CTP run configuration object to OCDB!");
434 else if (!partition.IsNull() && detector.IsNull()){ // global partition
435 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
436 if (triggerConf!= NULL) {
437 Log("Found trigger configuration in DAQ logbook");
438 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
440 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
444 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
445 runcfg->SetTitle(titleCTPcfg);
446 AliCDBMetaData metaData;
447 metaData.SetBeamPeriod(0);
448 metaData.SetResponsible("Roman Lietava");
449 metaData.SetComment("CTP run configuration from DAQ logbook");
450 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
451 Log("Unable to store the CTP run configuration object to OCDB!");
458 Log("Trigger configuration NULL in DAQ logbook");
464 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
468 //===========================//
469 // Trigger Timing Parameters //
470 //===========================//
472 Log("*************** Processing Trigger Time Params");
474 const char * triggerCTPtiming = GetCTPTimeParams();
476 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
477 Log("STANDALONE partition for current run, using CTP timing params dummy value");
478 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
480 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
484 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
486 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
490 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
491 runCTPtiming->SetTitle(titleCTPtiming);
492 AliCDBMetaData metadata;
493 metadata.SetResponsible("Roman Lietava");
494 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
495 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
496 Log("Unable to store the dummy CTP timing params object to OCDB!");
503 else if (!partition.IsNull() && detector.IsNull()){ // global partition
504 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
505 if (triggerCTPtiming!= NULL) {
506 Log("Found trigger timing params in DAQ logbook");
507 AliDebug(2,Form("%s",triggerCTPtiming));
508 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
510 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
514 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
515 runCTPtiming->SetTitle(titleCTPtiming);
516 AliCDBMetaData metadata;
517 metadata.SetBeamPeriod(0);
518 metadata.SetResponsible("Roman Lietava");
519 metadata.SetComment("CTP timing params from DAQ logbook");
520 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
521 Log("Unable to store the CTP timing params object to OCDB!");
528 Log("Trigger timing params NULL in DAQ logbook");
534 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
538 //===========================//
539 // LTU Configuration //
540 //===========================//
542 Log("*************** Processing LTU Configuration");
544 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
545 Log("STANDALONE partition for current run, using LTU configuration dummy value");
546 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
548 Log(Form("No dummy LTU Config entry found, going into error..."));
552 TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
554 Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
558 AliCDBMetaData metadata;
559 metadata.SetResponsible("Roman Lietava");
560 metadata.SetComment("LTU Config from dummy entry in OCDB");
561 if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
562 Log("Unable to store the dummy LTU Config object to OCDB!");
569 else if (!partition.IsNull() && detector.IsNull()){ // global partition
571 Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
572 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
573 Printf ("detectormask = %d",detectorMask);
574 TObjArray * ltuarray = new TObjArray();
575 ltuarray->SetOwner(1);
576 Bool_t isLTUok = kTRUE;
577 for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
578 if ((detectorMask >> i) & 0x1) {
579 TString det = AliDAQ::OfflineModuleName(i);
580 TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
581 if (detCTPName == "CTP") {
582 detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors
583 Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
586 Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
587 TString* ltu = GetLTUConfig(detCTPName.Data());
589 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()));
595 Float_t ltuFineDelay1 = ltu[0].Atof();
596 Float_t ltuFineDelay2 = ltu[1].Atof();
597 Float_t ltuBCDelayAdd = ltu[2].Atof();
598 const char* name = AliDAQ::DetectorName(i);
599 AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
600 ltuarray->AddAtAndExpand(ltuConfig,i);
605 AliCDBMetaData metadata;
606 metadata.SetBeamPeriod(0);
607 metadata.SetResponsible("Roman Lietava");
608 metadata.SetComment("LTU Configuration for current run");
609 if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
610 Log("Unable to store the LTU Config object to OCDB!");
618 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
623 //=================//
625 //=================//
627 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
628 Log("*************** Processing LHC Data");
630 UInt_t iLHCData = ProcessLHCData(grpobj);
632 if( iLHCData == 0 ) {
633 Log(Form("LHC Data from FXS, successful!"));
634 } else if (iLHCData == 1) {
635 Log(Form("LHC Data, problems with FXS!"));
637 } else if (iLHCData == 2) {
638 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
640 } else if (iLHCData ==3){
641 Log(Form("Problems in storing LHC Phase - going into Error"));
643 } else if (iLHCData ==4){
644 Log(Form("Problems with LHC Phase - going into Error"));
647 Log(Form("LHC Data problems"));
653 //==================//
654 // SPD Mean Vertex //
655 //==================//
657 Log("*************** Processing SPD Mean Vertex");
659 if (runType == "PHYSICS"){
660 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
661 if( iSPDMeanVertex == 1 ) {
662 Log(Form("SPD Mean Vertex, successful!"));
664 Log(Form("SPD Mean Vertex failed!!!"));
669 Log("SPD Mean Vertex not processed since runType != PHYSICS");
672 //=================//
674 //=================//
676 Log("*************** Processing DQM FXS");
678 UInt_t iDqmFxs = ProcessDqmFxs();
680 Log(Form("DQM FXS, successful!"));
682 Log(Form("DQM FXS failed!!!"));
686 // storing AliGRPObject in OCDB
689 md.SetResponsible("Chiara Zampolli");
690 md.SetComment("Output parameters from the GRP preprocessor.");
692 Bool_t result = kTRUE;
693 result = Store("GRP", "Data", grpobj, &md);
696 if (result && !error ) {
697 Log("GRP Preprocessor Success");
700 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
701 kppError[(error&1)?1:0],
702 kppError[(error&2)?2:0],
703 kppError[(error&4)?3:0],
704 kppError[(error&8)?4:0],
705 kppError[(error&16)?5:0],
706 kppError[(error&32)?6:0],
707 kppError[(error&64)?7:0],
708 kppError[(error&128)?8:0],
709 kppError[(error&256)?9:0],
710 kppError[(error&512)?10:0],
711 kppError[(error&1024)?11:0],
712 kppError[(error&2048)?12:0],
713 kppError[(error&4096)?13:0],
714 kppError[(error&8192)?14:0]
722 //_______________________________________________________________
724 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
727 //Getting the LHC Data from DCS FXS
730 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
731 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
732 if (timeStartString.IsNull() || timeEndString.IsNull()){
733 if (timeStartString.IsNull()){
734 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
736 else if (timeEndString.IsNull()){
737 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
742 Double_t timeStart = timeStartString.Atof();
743 Double_t timeEnd = timeEndString.Atof();
745 TString fileName = GetFile(kDCS, "LHCData","");
746 if (fileName.Length()>0){
747 AliInfo("Got The LHC Data file");
748 AliLHCReader lhcReader;
750 // Processing data to be put in AliGRPObject
753 Log("*************Energy ");
754 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
756 Float_t energy = ProcessEnergy(energyArray,timeStart);
758 grpobj->SetBeamEnergy(energy);
759 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
764 AliError("Energy not found in LHC Data file!!!");
767 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
768 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
769 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
770 Double_t timeBeamTypeEnd[2] = {timeEnd, timeEnd}; // max validity for Beam Type1,2
771 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
772 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
773 Double_t timeBeamStart = -1; // min validity for Beam Type
774 Double_t timeBeamTypeStart[2] = {-1,-1}; // min validity for Beam Type1,2
775 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
776 Int_t indexMachineMode = -1; // index of measurement used to set Machine Mode
777 Int_t indexBeam = -1; // index of measurement used to set Beam Type
778 Int_t indexBeamType[2] = {-1, -1}; // index of measurement used to set Beam Type1,2
779 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
780 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Machine Mode is found before (or at) SOR
781 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Type is found before (or at) SOR
782 Bool_t foundBeamTypeStart[2] = {kFALSE, kFALSE}; // flag to be set in case an entry for the Beam Type1,2 is found before (or at) SOR
783 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
784 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
785 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
786 Bool_t flagBeamType[2] = {kFALSE, kFALSE}; //flag set true if a changed occurred in BeamType1,2
788 Double_t arrayTimes[5]={2.E9, 2.E9, 2.E9, 2.E9, 2.E9}; // array to keep track of the times of the possible changes of the LHC DPs; each entry set to Wed May 18 2033, 03:33:20 GMT (ALICE should not be running anymore...)
789 // arrayTimes elements order correspond to the one used in the array of the strings fgkLHCDataPoints, i.e.:
790 // arrayTimes[0] --> MachineMode
791 // arrayTimes[1] --> BeamMode
792 // arrayTimes[2] --> BeamType (when written together)
793 // arrayTimes[3] --> BeamType1 (when written separate)
794 // arrayTimes[4] --> BeamType2 (when written separate)
797 Log("*************BeamMode (LHCState) ");
798 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
799 Int_t nBeamMode = -1;
801 nBeamMode = beamModeArray->GetEntries();
803 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
806 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
807 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
809 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
810 timeBeamModeStart = beamMode->GetTimeStamp();
811 indexBeamMode = iBeamMode;
812 foundBeamModeStart = kTRUE;
820 if (!foundBeamModeStart){
821 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
824 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
825 TObjString* beamModeString = beamMode->GetStringArray(0);
826 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
827 grpobj->SetLHCState(beamModeString->String());
828 if (indexBeamMode < nBeamMode-1){
829 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
831 if (beamMode1->GetTimeStamp()<=timeStart){
832 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
834 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
835 timeBeamModeEnd = beamMode1->GetTimeStamp();
836 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
837 TString bmString0 = beamModeString->String();
838 TString bmString1 = beamModeString1->String();
839 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
840 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()));
841 flagBeamMode = kTRUE;
842 arrayTimes[1]=timeBeamModeEnd;
848 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
853 delete beamModeArray;
856 AliError("Beam mode array not found in LHC Data file!!!");
860 Log("*************MachineMode ");
861 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
862 Int_t nMachineMode = -1;
863 if (machineModeArray){
864 nMachineMode = machineModeArray->GetEntries();
865 if (nMachineMode==0){
866 AliInfo("No Machine Mode found, leaving it empty");
869 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
870 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
872 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
873 timeMachineModeStart = machineMode->GetTimeStamp();
874 indexMachineMode = iMachineMode;
875 foundMachineModeStart = kTRUE;
882 if (!foundMachineModeStart){
883 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
886 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
887 TObjString* machineModeString = machineMode->GetStringArray(0);
888 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
889 grpobj->SetMachineMode(machineModeString->String());
890 if (indexMachineMode < nMachineMode-1){
891 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
893 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
894 timeMachineModeEnd = machineMode1->GetTimeStamp();
895 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
896 TString mmString0 = machineModeString->String();
897 TString mmString1 = machineModeString1->String();
898 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
899 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()));
900 flagMachineMode = kTRUE;
901 arrayTimes[0]=timeMachineModeEnd;
906 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
911 delete machineModeArray;
914 AliError("Machine mode array not found in LHC Data file!!!");
917 // BeamType1 and BeamType2 - both put in the same string
918 Log("*************BeamType ");
919 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
921 Int_t nBeam = beamArray->GetEntries();
923 AliInfo("No Beam Type found, leaving it empty");
926 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
927 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
929 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
930 timeBeamStart = beam->GetTimeStamp();
932 foundBeamStart = kTRUE;
939 if (!foundBeamStart){
940 AliInfo("No value for the Beam Type found before start of run, the (common) Beam Type will remain empty");
943 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
944 TObjString* beamString = beam->GetStringArray(0);
945 TString beamType = beamString->String();
946 AliInfo(Form("Beam Type = %s",beamType.Data()));
947 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
948 AliInfo("Setting beam type to p-p");
949 grpobj->SetBeamType("p-p");
951 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
952 AliInfo("Setting beam type to A-A");
953 grpobj->SetBeamType("A-A");
956 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
957 AliInfo("Setting beam type to Pb-Pb");
958 grpobj->SetBeamType("Pb-Pb");
961 AliError("Beam Type not known, leaving it empty");
964 if (indexBeam < nBeam-1){
965 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
967 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
968 timeBeamEnd = beam1->GetTimeStamp();
969 TObjString* beamString1 = beam1->GetStringArray(0);
970 TString beamType1 = beamString1->String();
971 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
972 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()));
974 arrayTimes[2] = timeBeamEnd;
979 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
987 AliError("Beam Type array not found in LHC Data file!!!");
990 // BeamType1 and BeamType2 - in separete string
991 Log("*************BeamType, 1 and 2 ");
992 Int_t indexBeamTypeString = 6; // index of the string with the alias of BeanType1 in the array fgkLHCDataPoints
993 TString combinedBeamType = "-"; // combined beam type, built from beam type 1 and beam type 2
994 TString combinedBeamTypeFromLHC = "-"; // combined beam type, built from beam type 1 and beam type 2 AS SENT FROM LHC
995 for (Int_t ibeamType = 0; ibeamType<2; ibeamType++){
996 beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[indexBeamTypeString+ibeamType]);
998 Int_t nBeam = beamArray->GetEntries();
1000 AliInfo(Form("No Beam Type %s found, leaving it empty",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1003 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
1004 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
1006 if (beam->GetTimeStamp()<=timeStart && beam->GetTimeStamp()>=timeBeamTypeStart[ibeamType]){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
1007 timeBeamTypeStart[ibeamType] = beam->GetTimeStamp();
1008 indexBeamType[ibeamType] = iBeam;
1009 foundBeamTypeStart[ibeamType] = kTRUE;
1016 if (!foundBeamTypeStart[ibeamType]){
1017 AliInfo(Form("No value for the Beam Type %s found before start of run, the Beam Type %d will remain empty", fgkLHCDataPoints[indexBeamTypeString+ibeamType], ibeamType));
1020 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
1021 TObjString* beamString = beam->GetStringArray(0);
1022 TString beamType = beamString->String();
1023 AliInfo(Form("Beam Type (for %s) = %s", fgkLHCDataPoints[indexBeamTypeString+ibeamType], beamType.Data()));
1024 TString singleBeam = ParseBeamTypeString(beamType,ibeamType);
1025 AliInfo(Form("Single Beam Type for beam %d set to %s", ibeamType, singleBeam.Data()));
1026 grpobj->SetSingleBeamType(ibeamType, singleBeam);
1027 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
1028 AliInfo(Form("Setting beam %d for combined beam type to p", ibeamType));
1029 if (ibeamType == 0) combinedBeamType.Prepend("p");
1030 else combinedBeamType.Append("p");
1032 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
1033 AliInfo(Form("Setting beam %d for combined beam type to A",ibeamType));
1034 if (ibeamType == 0) combinedBeamType.Prepend("A");
1035 else combinedBeamType.Append("A");
1037 if (ibeamType == 0) combinedBeamTypeFromLHC.Prepend(beamType);
1038 else combinedBeamTypeFromLHC.Append(beamType);
1040 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
1041 AliInfo("Setting beam type to Pb-Pb");
1042 grpobj->SetSingleBeamType(ibeamType, "Pb-Pb");
1045 AliError("Beam Type not known, leaving it empty");
1048 if (indexBeamType[ibeamType] < nBeam-1){
1049 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
1051 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
1052 timeBeamTypeEnd[ibeamType] = beam1->GetTimeStamp();
1053 TObjString* beamString1 = beam1->GetStringArray(0);
1054 TString beamType1 = beamString1->String();
1055 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
1056 AliWarning(Form("The Beam Type for %s 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",fgkLHCDataPoints[indexBeamTypeString+ibeamType],beamType.Data(),(beamString1->String()).Data(),timeBeamEnd,beamType.Data()));
1057 flagBeamType[ibeamType] = kTRUE;
1058 arrayTimes[3+ibeamType] = timeBeamTypeEnd[ibeamType];
1063 AliInfo(Form("Invalid pointer for the first entry for Beam Type %s after the first valid one, not considering anything after what has already been found",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1071 AliError(Form("Beam Type %s array not found in LHC Data file!!!",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1074 AliInfo(Form("Setting combined beam type to %s",combinedBeamType.Data()));
1075 grpobj->SetBeamType(combinedBeamType);
1076 AliInfo(Form("Setting combined beam type form LHC to %s",combinedBeamTypeFromLHC.Data()));
1077 grpobj->SetBeamTypeFromLHC(combinedBeamTypeFromLHC);
1079 // Setting minTimeLHCValidity
1080 if (flagBeamMode == kTRUE || flagMachineMode == kTRUE || flagBeam == kTRUE || flagBeamType[0] == kTRUE || flagBeamType[1] == kTRUE){
1081 Double_t minTimeLHCValidity= TMath::MinElement(5,arrayTimes);
1082 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1083 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1086 // Old way to determine the Maximum Time during which the LHC info is valid
1087 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
1088 Double_t minTimeLHCValidity;
1089 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true --> it is the only one that changed
1090 minTimeLHCValidity = timeBeamEnd;
1092 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
1093 minTimeLHCValidity = timeMachineModeEnd;
1095 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
1096 minTimeLHCValidity = timeBeamModeEnd;
1098 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
1099 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
1101 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
1102 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
1104 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
1105 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
1108 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
1109 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
1111 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1112 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1116 // Data Quality Flag --> storing start and end values of periods within the run during which the value was found to be FALSE
1117 Log("*************Data Quality Flag ");
1118 TObjArray* dataQualityArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[8]);
1119 Int_t nDataQuality = -1;
1120 Double_t timeDataQualityStart = -1; // min validity for Data Quality Flag
1121 Int_t indexDataQuality = -1; // index of first measurement used to set Data Quality Flag
1122 Bool_t foundDataQualityStart = kFALSE; // flag to be set in case an entry for the Data Quality Flag is found before (or at) SOR
1124 if (dataQualityArray){
1125 nDataQuality = dataQualityArray->GetEntries();
1126 if (nDataQuality==0){
1127 AliInfo("No Data Quality Flag found, leaving it empty");
1130 for (Int_t iDataQuality = 0; iDataQuality<nDataQuality; iDataQuality++){
1131 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1133 if (dataQuality->GetTimeStamp()<=timeStart && dataQuality->GetTimeStamp()>=timeDataQualityStart){// taking always the very last entry: if two measurements have the same timestamp, the last one is taken
1134 timeDataQualityStart = dataQuality->GetTimeStamp();
1135 indexDataQuality = iDataQuality;
1136 foundDataQualityStart = kTRUE;
1139 // we suppose here that if the first measurement is not before SOR, then none will be (they MUST be in chronological order!!!)
1144 if (!foundDataQualityStart){
1145 // The Data Quality Flag should be found and TRUE at the start of the run. For the time being, if it is not found, don't do anything, but it means there is a problem..
1146 AliInfo("No value for the Data Quality Flag found before start of run, the Data Quality Flag will remain empty");
1149 // counting how many FALSE values there are
1150 Bool_t foundEndOfFalse = kFALSE;
1152 for (Int_t iDataQuality = indexDataQuality; iDataQuality < nDataQuality; iDataQuality ++){
1153 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1154 AliDebug(4,Form("dataQuality->GetTimeStamp() = %f, timeDataQualityStart = %f, timeEnd = %f", dataQuality->GetTimeStamp(), timeDataQualityStart, timeEnd ));
1155 if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
1156 Bool_t dataQualityFlag = dataQuality->GetBool(0);
1157 AliDebug(3,Form("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp()));
1158 if (dataQualityFlag != kTRUE){
1159 if (iDataQuality == indexDataQuality) { // the first Data Quality value should be TRUE, but ignoring the problem now...
1160 AliError("The first value for the Data Quality MUST be TRUE! Ignoring for now...");
1167 AliInfo(Form("Found %d FALSE values for the Data Quality Flag",nFalse));
1168 Double_t falses[nFalse*2]; // dimensioning this to the maximum possible, as if each false value was followed by a true one --> the false periods correspond to the number of falses
1170 Int_t iDataQuality = indexDataQuality;
1173 // filling the info about the periods when the flag was set to FALSE
1174 // starting, like for the other DPS, from the measurement closest to SOR (the index of which is iDataQuality)
1175 while (iDataQuality < nDataQuality){
1176 AliDebug(3,Form("iDataQuality = %d",iDataQuality));
1177 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1178 if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
1179 Bool_t dataQualityFlag = dataQuality->GetBool(0);
1180 AliDebug(3,Form("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp()));
1181 if (dataQualityFlag == kTRUE){
1182 // found TRUE value, continuing
1188 // the check was already done before
1189 if (iDataQuality == indexDataQuality) { // the first Data Quality value should be TRUE, but ignoring the problem now...
1190 AliError("The first value for the Data Quality MUST be TRUE! Ignoring for now...");
1193 falses[iFalse*2] = dataQuality->GetTimeStamp();
1194 foundEndOfFalse = kFALSE;
1195 Int_t iDataQualityNext = iDataQuality+1;
1196 while (iDataQualityNext < nDataQuality){
1197 AliDCSArray* dataQualityNext = (AliDCSArray*)dataQualityArray->At(iDataQualityNext);
1198 if (dataQualityNext->GetTimeStamp()>timeDataQualityStart && dataQualityNext->GetTimeStamp()<=timeEnd && dataQualityNext->GetTimeStamp() > dataQuality->GetTimeStamp()){ // considering only values between the first valid and the end of the run, and subsequent to the current value
1199 Bool_t dataQualityFlagNext = dataQualityNext->GetBool(0);
1200 AliDebug(3,Form("DataQualityNext = %d (set at %f)",(Int_t)dataQualityFlagNext,dataQualityNext->GetTimeStamp()));
1201 if (dataQualityFlagNext == kTRUE){
1202 // found TRUE value, first FALSE period completed
1203 foundEndOfFalse = kTRUE;
1204 falses[iFalse*2+1] = dataQualityNext->GetTimeStamp();
1211 if (!foundEndOfFalse) {
1212 AliInfo("Please, note that the last FALSE value lasted until the end of the run");
1213 falses[iFalse*2+1] = timeEnd;
1217 iDataQuality = iDataQualityNext+1;
1221 grpobj->SetNFalseDataQualityFlag(iFalse);
1222 grpobj->SetFalseDataQualityFlagPeriods(falses);
1226 delete dataQualityArray;
1229 AliError("Data Quality Flag array not found in LHC Data file!!!");
1232 // Processing data to go to AliLHCData object
1233 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
1234 // storing AliLHCData in OCDB
1236 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
1238 md.SetResponsible("Ruben Shahoyan");
1239 md.SetComment("LHC data from the GRP preprocessor.");
1240 Bool_t result = kTRUE;
1241 result = Store("GRP", "LHCData", dt, &md);
1244 Log(Form("Problems in storing LHC Data - but not going into Error"));
1248 // processing LHC Phase
1250 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
1251 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
1252 if (beam1phase == 0x0 || beam2phase == 0x0){
1253 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
1256 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
1260 AliInfo(Form("LHC Phase found"));
1261 AliCDBMetaData mdPhase;
1262 mdPhase.SetResponsible("Cvetan Cheshkov");
1263 mdPhase.SetComment("LHC Clock Phase");
1264 Bool_t result = kTRUE;
1265 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
1267 if (!result) return 3;
1273 AliError("No LHCData file found in FXS");
1280 //_______________________________________________________________
1282 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
1285 //Getting the SPD Mean Vertex
1288 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
1289 Bool_t storeResult = kTRUE;
1290 if (list !=0x0 && list->GetEntries()!=0)
1292 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
1294 for (Int_t jj=0;jj<list->GetEntries();jj++){
1295 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1297 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1300 AliInfo(Form("found source %s", str->String().Data()));
1301 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
1302 if (fileNameRun.Length()>0){
1303 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1304 TFile daqFile(fileNameRun.Data(),"READ");
1305 if (daqFile.IsOpen()) {
1306 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
1309 // storing in the OCDB
1311 md.SetResponsible("Cvetan Cheshkov");
1312 md.SetComment("SPD Mean Vertex");
1313 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
1316 AliWarning("No SPD Mean Vertex object found in file");
1320 AliError("Can't open file");
1321 storeResult = kFALSE;
1325 AliWarning("No file found for current source for SPD Mean Vertex");
1330 AliWarning("No list found for SPD Mean Vertex");
1333 if (list) delete list;
1337 //_______________________________________________________________
1339 UInt_t AliGRPPreprocessor::ProcessDqmFxs()
1342 // Processing DQM fxs information
1345 // TriggerClassesAndHistosToClone
1346 TList* list = GetFileSources(kDQM, "TriggerClassesAndHistosToClone");
1347 Bool_t storeResult = kTRUE;
1348 Bool_t storeResultQAThr = kTRUE;
1349 if (list !=0x0 && list->GetEntries()!=0){
1350 AliInfo("The following sources produced files with the id TriggerClassesAndHistosToClone for GRP");
1352 for (Int_t jj=0;jj<list->GetEntries();jj++){
1353 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1355 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1358 AliInfo(Form("found source %s", str->String().Data()));
1359 TString fileNameRun = GetFile(kDQM, "TriggerClassesAndHistosToClone", str->GetName());
1360 if (fileNameRun.Length()>0){
1361 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1362 TFile dqmFile(fileNameRun.Data(),"READ");
1363 if (dqmFile.IsOpen()) {
1367 AliError("Can't open file");
1368 storeResult = kFALSE;
1372 AliWarning("No file found for current source for DQM TriggerClassesAndHistosToClone");
1377 AliWarning("No list found for DQM TriggerClassesAndHistosToClone");
1380 if (list) delete list;
1383 TObjArray* qaThrArray = new TObjArray();
1384 for (Int_t idet = 0; idet < AliDAQ::kNDetectors; idet++){
1385 TString detName = AliDAQ::OnlineName(idet);
1386 if (detName == "TRI" || detName == "HLT" || detName == "TST") continue; // skipping TRI, HLT, TST since they do not produce QAThresholds
1387 AliDebug(2, Form("Processing QAThreshold for detector %s",detName.Data()));
1388 TList* listQAThr = GetForeignFileSources(detName.Data(), kDQM, "QAThresholds");
1389 if (listQAThr !=0x0){
1390 if (listQAThr->GetEntries() > 1){
1391 AliError(Form("More than one sources found for QAThresholds from detector %s, skipping",detName.Data()));
1394 else if (listQAThr->GetEntries()==1){
1395 AliInfo(Form("The following source produced files with the id QAThresholds for GRP, coming from detector %s:",detName.Data()));
1397 TObjString * str = dynamic_cast<TObjString*> (listQAThr->At(0));
1399 AliError(Form("Expecting a TObjString in the list for detector %s, but something else was found.",detName.Data()));
1403 AliInfo(Form("found source %s", str->String().Data()));
1404 TString fileNameRun = GetForeignFile(detName.Data(), kDQM, "QAThresholds", str->GetName());
1405 if (fileNameRun.Length()>0){
1406 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1407 TFile dqmFile(fileNameRun.Data(),"READ");
1408 if (dqmFile.IsOpen()) {
1409 AliQAThresholds* qaThr = dynamic_cast<AliQAThresholds*>(dqmFile.Get(detName.Data()));
1411 Int_t qaThrId = qaThr->GetDetectorId();
1412 if (qaThrId != idet){
1413 AliError(Form("Expecting QA threshold for detector %s, but found that for detector %s, skipping",detName.Data(), AliDAQ::OnlineName(qaThrId)));
1418 qaThrArray->AddAtAndExpand(qaThr, qaThrId);
1423 AliError(Form("No QAThresholds object found in the file for detector %s, skipping",detName.Data()));
1429 AliError(Form("Can't open QAThreshold file for detector %s, skipping",detName.Data()));
1435 AliWarning(Form("No file found for DQM QAThreshold for detector %s, skipping",detName.Data()));
1441 AliError(Form("No sources found for QAThresholds from detector %s, skipping",detName.Data()));
1447 AliWarning(Form("No list found for DQM QAThreshold for detector %s, skipping",detName.Data()));
1451 if (qaThrArray->GetEntries() > 0){
1453 md.SetResponsible("Barthélémy von Haller");
1454 md.SetComment("QA Threshold TObjArray");
1455 storeResultQAThr = Store("Calib", "QAThresholds", qaThrArray, &md, 0, kTRUE);
1458 Printf("No valid QAThresholds entries found, storing nothing in the OCDB");
1461 // return storeResult;
1462 return kTRUE; // temporary!!
1466 //_______________________________________________________________
1468 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
1470 //Getting the DAQ lb information
1472 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
1473 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
1474 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
1475 TString beamType = (TString)GetRunParameter("beamType");
1476 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
1477 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
1478 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
1479 TString runType = (TString)GetRunType();
1481 if (timeEnd >= 2.E9) AliFatal("ALICE run finshed later than Wed May 18 2033, 03:33:20 GMT, maximum time allowed for LHC data --> fix the GRP preprocessor!!!");
1483 UInt_t nparameter = 0;
1484 if (timeStart != 0){
1485 grpObj->SetTimeStart(timeStart);
1486 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
1490 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1494 grpObj->SetTimeEnd(timeEnd);
1495 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
1499 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1502 if (beamEnergy != 0){
1503 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1506 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1510 if (beamType.Length() != 0){
1511 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()));
1514 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1517 if (numberOfDetectors != 0){
1518 grpObj->SetNumberOfDetectors(numberOfDetectors);
1519 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1523 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1526 if (detectorMask != 0){
1527 grpObj->SetDetectorMask(detectorMask);
1528 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1532 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1535 if (lhcPeriod.Length() != 0) {
1536 grpObj->SetLHCPeriod(lhcPeriod);
1537 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1541 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1543 if (runType.Length() != 0) {
1544 grpObj->SetRunType(runType);
1545 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1549 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1554 //_______________________________________________________________
1556 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1558 //======DAQ FXS======//
1560 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1561 AliRawEventHeaderV3_11::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_11 - temporary fix
1562 AliRawEventHeaderV3_12::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_12 - temporary fix
1563 AliRawEventHeaderV3_13::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_13 - temporary fix
1564 Log("Processing DAQ FXS");
1565 TList* list = GetFileSources(kDAQ);
1567 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1571 if (list->GetEntries() == 0) {
1572 Log("no raw data tags in this run: nothing to merge!");
1573 delete list; list=0;
1577 TChain *fRawTagChain = new TChain("T");
1579 TIterator* iter = list->MakeIterator();
1581 while ((obj = iter->Next())) {
1582 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1584 Log(Form("Found source %s", objStr->String().Data()));
1585 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1587 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1588 delete fRawTagChain; fRawTagChain=0;
1591 Log(Form("Number of ids: %d",list2->GetEntries()));
1592 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1593 TObjString *idStr = (TObjString *)list2->At(i);
1594 if (idStr->String().CompareTo("QAThreshold") == 0 || idStr->String().CompareTo("TriggerClassesAndHistosToClone") == 0) {
1595 Log(Form("Skipping file with Id %s",idStr->String().Data()));
1598 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1599 if (fileName.Length() > 0) {
1600 Log(Form("Adding file in the chain: %s",fileName.Data()));
1601 fRawTagChain->Add(fileName.Data());
1604 Log(Form("Could not retrieve file with id %s from source %s: "
1605 "connection problems with DAQ FXS!",
1606 idStr->String().Data(), objStr->String().Data()));
1607 delete list; list=0;
1608 delete list2; list2=0;
1609 delete fRawTagChain; fRawTagChain=0;
1618 Log("no raw data tags in this run: it could be that one or more files were found in the DAQ FXS, but they were ignored, since not interesting for the raw data tag: nothing to merge!");
1623 delete fRawTagChain;
1628 TString fRawDataFileName = "GRP_Merged.tag.root";
1629 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1631 if (fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1632 Log(Form("Error merging %d raw data files!!!",nFiles));
1637 delete fRawTagChain;
1642 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1643 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1646 Log("Problem storing raw data tags in local file!!!");
1648 Log("Raw data tags merged successfully!!");
1655 delete fRawTagChain; fRawTagChain=0;
1657 if (result == kFALSE) {
1665 //_______________________________________________________________
1666 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1669 // processing the info
1670 // stored in the DCS FXS
1671 // coming from the trigger
1673 // Get the CTP counters information
1675 // Get the CTP aliases information
1677 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1678 Log("STANDALONE partition for current run, using Trigger Scalers and Trigger Aliases dummy values");
1680 AliCDBEntry *cdbEntryScalers = GetFromOCDB("CTP","DummyScalers");
1681 if (!cdbEntryScalers) {
1682 Log(Form("No dummy CTP scalers entry found, going into error..."));
1686 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntryScalers->GetObject();
1688 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1692 AliCDBMetaData metaData;
1693 metaData.SetResponsible("Roman Lietava");
1694 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1695 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1696 Log("Unable to store the dummy CTP scalers object to OCDB!");
1703 AliCDBEntry *cdbEntryAliases = GetFromOCDB("CTP","DummyAliases");
1704 if (!cdbEntryAliases) {
1705 Log(Form("No dummy CTP aliases entry found, going into error..."));
1709 THashList *aliases = dynamic_cast<THashList*>(cdbEntryAliases->GetObject());
1711 Log(Form("CTP dummy aliases not found in OCDB entry, going into error..."));
1715 AliCDBMetaData metaData;
1716 metaData.SetResponsible("Evgeny Kryshen");
1717 metaData.SetComment("CTP mapping of trigger classes to trigger aliases");
1718 if (!Store("CTP","Aliases", aliases, &metaData, 0, 0)) {
1719 Log("Unable to store the dummy CTP aliases object to OCDB!");
1727 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1728 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1729 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1730 if (countersfile.IsNull()) {
1731 Log("No CTP counters files has been found: empty source!");
1735 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1736 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1738 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1742 AliCDBMetaData metaData;
1743 metaData.SetBeamPeriod(0);
1744 metaData.SetResponsible("Roman Lietava");
1745 metaData.SetComment("CTP scalers");
1746 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1747 Log("Unable to store the CTP scalers object to OCDB!");
1757 TString aliasesFile = GetFile(kDCS, "CTP_aliases","");
1758 if (aliasesFile.IsNull()) {
1759 Log("No CTP aliases files has been found: empty source!");
1763 Log(Form("File with Id CTP_aliases found in DCS FXS! Copied to %s",aliasesFile.Data()));
1764 // We build the THashList of TNamed("triggerclass","comma_separated_list_of_corresponding_aliases")
1765 THashList* trClasses2Aliases = ProcessAliases(aliasesFile);
1766 if (!trClasses2Aliases) {
1767 Log("Bad CTP aliases file! The corresponding CDB entry will not be filled!");
1771 AliCDBMetaData metaData;
1772 metaData.SetBeamPeriod(0);
1773 metaData.SetResponsible("Evgeny Kryshen");
1774 metaData.SetComment("CTP mapping of trigger classes to trigger aliases");
1775 if (!Store("CTP","Aliases", trClasses2Aliases, &metaData, 0, 0)) {
1776 Log("Unable to store the CTP aliases object to OCDB!");
1777 delete trClasses2Aliases;
1781 delete trClasses2Aliases;
1787 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1795 //_______________________________________________________________
1796 THashList* AliGRPPreprocessor::ProcessAliases(const char* aliasesFile)
1800 // build the THashList of triggerclasses-to-triggeraliases from text file
1801 // each line of the file is supposed to be a string composed by
1802 // triggerclass+spaces+commaseparatedlistofcorrespondingaliases\n
1803 // it will add a TNamed("triggerclass","commaseparatedlistofcorrespondingaliases")
1807 if (gSystem->AccessPathName(aliasesFile)) {
1808 Printf("file (%s) not found", aliasesFile);
1812 ifstream *file = new ifstream(aliasesFile);
1814 Printf("Error opening file (%s) !",aliasesFile);
1820 THashList *hList = new THashList(10);
1821 hList->SetName("List of trigger classes to trigger aliases strings");
1824 while (strLine.ReadLine(*file)) {
1826 // safety for null lines, tabs instead of whitespaces, trailing carriage return, leading or trailing spaces/tabs
1827 if (strLine.IsNull()) continue;
1828 strLine.ReplaceAll('\t',' ');
1829 strLine.Remove(TString::kLeading,' ');
1830 strLine.Remove(TString::kTrailing,'\r');
1831 strLine.Remove(TString::kTrailing,' ');
1833 TObjArray* arr = strLine.Tokenize(' ');
1834 if(arr->GetEntries() != 2){
1835 Printf("The line:\n%s\nunexpectedly contains %d tokens, instead of two.",strLine.Data(),arr->GetEntries());
1838 TObjString *osTC = (TObjString*) arr->At(0);
1839 TObjString *osTAlist = (TObjString*) arr->At(1);
1840 TNamed *ctoa = new TNamed(osTC->GetName(),osTAlist->GetName());
1850 //_______________________________________________________________
1851 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1855 // processing DCS DPs
1858 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1859 Int_t nL3Entries = 0;
1860 Int_t nDipoleEntries = 0;
1861 Int_t nEnvEntries = 0;
1862 Int_t nHallProbesEntries = 0;
1863 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1864 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1865 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1866 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1867 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1868 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1869 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1874 //_______________________________________________________________
1876 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1883 Int_t nL3Entries = 0;
1885 TObjArray *array = 0x0;
1887 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1889 AliInfo(Form("==========L3Current==========="));
1890 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1891 indexDP = kL3Current;
1892 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1894 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1897 if (array->GetEntries() == 0){
1898 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1901 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1902 if (floatDCS != NULL){
1903 grpObj->SetL3Current(floatDCS);
1915 ffailedDPs->RemoveAt(indexDP);
1919 if (array) array = 0x0;
1921 AliInfo(Form("==========L3Polarity==========="));
1922 indexDP = kL3Polarity;
1923 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1925 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1928 if (array->GetEntries() == 0){
1929 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1932 Bool_t change = kFALSE;
1933 Char_t charDCS = ProcessBool(array,change);
1934 if (change == kFALSE){
1935 grpObj->SetL3Polarity(charDCS);
1936 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1937 ffailedDPs->RemoveAt(indexDP);
1941 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1942 ffailedDPs->RemoveAt(indexDP);
1946 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]));
1954 //_______________________________________________________________
1956 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1962 Int_t nDipoleEntries = 0;
1963 TObjArray *array = 0x0;
1965 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1967 AliInfo(Form("==========DipoleCurrent==========="));
1968 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1969 indexDP = kDipoleCurrent;
1970 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1972 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1975 if (array->GetEntries() == 0){
1976 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1979 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1980 if (floatDCS != NULL){
1981 grpObj->SetDipoleCurrent(floatDCS);
1993 ffailedDPs->RemoveAt(indexDP);
1997 if (array) array = 0x0;
1999 AliInfo(Form("==========DipolePolarity==========="));
2000 indexDP = kDipolePolarity;
2001 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
2003 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
2006 if (array->GetEntries() == 0){
2007 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
2010 Bool_t change = kFALSE;
2011 Char_t charDCS = ProcessBool(array,change);
2013 grpObj->SetDipolePolarity(charDCS);
2014 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
2015 ffailedDPs->RemoveAt(indexDP);
2019 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
2020 ffailedDPs->RemoveAt(indexDP);
2024 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]));
2029 return nDipoleEntries;
2032 //_______________________________________________________________
2034 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
2038 // evironment conditions (temperature, pressure) info
2040 Int_t nEnvEntries = 0;
2041 TObjArray *array = 0x0;
2044 AliInfo(Form("==========CavernTemperature==========="));
2045 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
2046 indexDP = kCavernTemperature;
2047 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
2049 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
2052 if (array->GetEntries() == 0){
2053 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
2056 Float_t *floatDCS = ProcessFloatAll(array);
2057 if (floatDCS != NULL){
2058 grpObj->SetCavernTemperature(floatDCS);
2069 ffailedDPs->RemoveAt(indexDP);
2074 if (array) array = 0x0;
2076 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
2077 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
2078 //dcsSensorArray->Print();
2079 if( fPressure->NumFits()<kNumSensors ) {
2080 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
2082 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
2084 AliInfo(Form("==========CavernAtmosPressure==========="));
2085 indexDP = kCavernAtmosPressure;
2086 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
2087 TGraph* graph = sensorCavernP2->GetGraph();
2088 AliDebug(3,Form("index = %d",indexDP));
2089 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
2090 AliDebug(2,Form("graph = %p",graph));
2091 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
2092 if(sensorCavernP2->GetFit() || graph) {
2093 if (sensorCavernP2->GetFit()){
2094 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
2097 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
2099 grpObj->SetCavernAtmosPressure(sensorCavernP2);
2100 ffailedDPs->RemoveAt(indexDP);
2103 //if (sensorP2) delete sensorP2;
2105 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] ));
2108 AliInfo(Form("==========SurfaceAtmosPressure==========="));
2109 indexDP = kSurfaceAtmosPressure;
2110 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
2111 graph = sensorP2->GetGraph();
2112 AliDebug(3,Form("index = %d",indexDP));
2113 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
2114 AliDebug(2,Form("graph = %p",graph));
2115 AliDebug(3,Form("sensorP2 = %p", sensorP2));
2116 if(sensorP2->GetFit() || graph) {
2117 if (sensorP2->GetFit()){
2118 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
2121 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
2123 grpObj->SetSurfaceAtmosPressure(sensorP2);
2124 ffailedDPs->RemoveAt(indexDP);
2127 //if (sensorP2) delete sensorP2;
2129 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] ));
2132 AliInfo(Form("==========CavernAtmosPressure2==========="));
2133 indexDP = kCavernAtmosPressure2;
2134 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
2135 graph = sensorCavernP22->GetGraph();
2136 AliDebug(3,Form("index = %d",indexDP));
2137 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
2138 AliDebug(2,Form("graph = %p",graph));
2139 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
2140 if(sensorCavernP22->GetFit() || graph) {
2141 if (sensorCavernP22->GetFit()){
2142 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
2145 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
2147 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
2148 ffailedDPs->RemoveAt(indexDP);
2151 //if (sensorP2) delete sensorP2;
2153 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] ));
2159 //_______________________________________________________________
2161 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
2167 Int_t nHPEntries = 0;
2168 TObjArray *array = 0x0;
2170 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
2172 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
2173 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()));
2175 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
2176 outOfRange = kFALSE; // resetting outOfRange flag at each HP
2177 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
2178 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
2180 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
2183 if (array->GetEntries() == 0){
2184 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
2187 Float_t *floatDCS = ProcessFloatAll(array);
2188 if (floatDCS != NULL){
2189 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]));
2190 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
2191 for (Int_t kk = 0 ; kk< 5; kk++){
2192 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
2204 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
2210 Log(Form("Hall Probes = %d ", nHPEntries));
2214 //_________________________________________________________________________
2216 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
2220 // returning Spline Fit
2223 Int_t entriesarray = array->GetEntries();
2224 Float_t* value = new Float_t[entriesarray];
2225 Float_t* time = new Float_t[entriesarray];
2226 AliDCSValue* v = 0x0;
2227 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
2228 v = (AliDCSValue*)array->At(iarray);
2229 value[iarray] = v->GetFloat();
2230 time[iarray] = v->GetTimeStamp();
2231 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
2233 TGraph* gr = new TGraph(entriesarray,value,time);
2235 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
2238 AliSplineFit *fit = new AliSplineFit();
2239 fit->SetMinPoints(10);
2240 fit->InitKnots(gr,10,10,0.0);
2246 //_________________________________________________________________________
2248 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
2255 TString aDCSString="";
2257 AliDCSValue *v = 0x0;
2258 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2259 v = (AliDCSValue *)array->At(iCount);
2260 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
2261 AliError(Form("DCS values for the parameter outside the queried interval"));
2265 if (aDCSString != v->GetChar())
2266 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
2268 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
2273 //__________________________________________________________________________________________________________________
2275 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
2278 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2280 // parameters[0] = mean
2281 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2282 // parameters[2] = median
2283 // parameters[3] = standard deviation wrt mean
2284 // parameters[4] = standard deviation wrt median
2287 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2288 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2289 if (timeStartString.IsNull() || timeStartString.IsNull()){
2290 if (timeStartString.IsNull()){
2291 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2293 else if (timeStartString.IsNull()){
2294 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2296 fdaqStartEndTimeOk = kFALSE;
2300 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2301 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2302 Float_t* parameters = new Float_t[5];
2304 Int_t iCountsRun = 0;
2305 Int_t nCounts = array->GetEntries();
2306 Float_t valueBeforeSOR = 0;
2307 Float_t valueAfterEOR = 0;
2308 Int_t timestampBeforeSOR = -1;
2309 Int_t timestampAfterEOR = -1;
2310 Int_t ientrySOR = -1;
2311 Int_t ientryEOR = -1;
2312 Float_t* arrayValues = 0x0;
2313 Double_t* arrayWeights = 0x0;
2314 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2315 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2317 for(Int_t i = 0; i < nCounts; i++) {
2318 AliDCSValue *v = (AliDCSValue *)array->At(i);
2319 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2320 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2321 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2322 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
2323 delete [] parameters;
2326 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2327 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
2329 // look for the last value before SOR and the first value before EOR
2330 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2331 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2332 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2333 valueBeforeSOR = v->GetFloat();
2335 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2336 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2337 valueAfterEOR = v->GetFloat();
2338 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2340 // check if there are DPs between DAQ_time_start and DAQ_time_end
2341 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2342 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2343 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2344 AliDebug(2,Form("entry between SOR and EOR"));
2349 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2353 if (timestampBeforeSOR == -1){
2354 AliWarning("No value found before SOR");
2356 if (timestampAfterEOR == -1){
2357 AliWarning("No value found after EOR");
2360 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
2361 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2362 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2363 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2364 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2365 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2367 Int_t nentriesUsed = 0;
2368 if (iCountsRun > 1){
2369 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2370 AliDebug(2,"Calculating (weighted) Mean and Median");
2371 arrayValues = new Float_t[iCountsRun];
2372 arrayWeights = new Double_t[iCountsRun];
2373 nentriesUsed = iCountsRun;
2374 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2375 AliDCSValue *v = (AliDCSValue *)array->At(i);
2376 Int_t timestamp2 = 0;
2378 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2379 timestamp2 = (Int_t)v1->GetTimeStamp();
2382 timestamp2 = timeEnd+1;
2384 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2385 arrayValues[i-ientrySOR] = v->GetFloat();
2387 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2388 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2390 else if (iCountsRun == 1){
2391 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2393 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2394 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.");
2395 arrayValues = new Float_t[2];
2396 arrayWeights = new Double_t[2];
2397 arrayValues[0] = valueBeforeSOR;
2398 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2399 arrayValues[1] = v->GetFloat();
2400 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2401 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2402 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2403 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2404 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2405 truncMeanFlag = kFALSE;
2408 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");
2409 parameters[0] = AliGRPObject::GetInvalidFloat();
2410 parameters[1] = AliGRPObject::GetInvalidFloat();
2411 parameters[2] = AliGRPObject::GetInvalidFloat();
2412 parameters[3] = AliGRPObject::GetInvalidFloat();
2413 parameters[4] = AliGRPObject::GetInvalidFloat();
2417 else { // iCountsRun == 0, using only the point immediately before SOR
2418 if (timestampBeforeSOR == -1){
2419 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");
2420 parameters[0] = AliGRPObject::GetInvalidFloat();
2421 parameters[1] = AliGRPObject::GetInvalidFloat();
2422 parameters[2] = AliGRPObject::GetInvalidFloat();
2423 parameters[3] = AliGRPObject::GetInvalidFloat();
2424 parameters[4] = AliGRPObject::GetInvalidFloat();
2428 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
2429 AliDebug(2,Form("value = %f",valueBeforeSOR));
2430 parameters[0] = valueBeforeSOR;
2431 parameters[2] = valueBeforeSOR;
2432 truncMeanFlag = kFALSE;
2439 Float_t sumweights = 0;
2440 Int_t entriesTruncMean = 0;
2441 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
2442 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2444 // calculating SD wrt Mean and Median
2445 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
2447 for (Int_t i =0; i< nentriesUsed; i++){
2448 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2449 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2450 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2451 sumweights += arrayWeights[i];
2453 // setting SD wrt Mean
2454 if (sumweights != 0 ){
2455 parameters[3] = TMath::Sqrt(temp1/sumweights);
2458 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
2459 parameters[3] = AliGRPObject::GetInvalidFloat();
2461 // setting SD wrt Median
2462 if (nentriesUsed != 0){
2463 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2466 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
2467 parameters[4] = AliGRPObject::GetInvalidFloat();
2471 parameters[3] = AliGRPObject::GetInvalidFloat();
2472 parameters[4] = AliGRPObject::GetInvalidFloat();
2475 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2477 AliDebug(2,"Calculating Truncated Mean");
2478 for (Int_t i =0; i< nentriesUsed; i++){
2479 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2480 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2481 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2482 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2483 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
2487 AliDebug(2,"Discarding entry");
2490 // setting truncated mean
2491 if (entriesTruncMean >1){
2492 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
2493 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2496 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
2497 parameters[1] = AliGRPObject::GetInvalidFloat();
2501 parameters[1] = AliGRPObject::GetInvalidFloat();
2505 delete [] arrayValues;
2508 delete [] arrayWeights;
2510 delete [] arrayValuesTruncMean;
2511 delete [] arrayWeightsTruncMean;
2513 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
2514 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
2515 AliInfo(Form("median = %f ",parameters[2]));
2516 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
2517 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
2522 //__________________________________________________________________________________________________________________
2524 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
2527 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2528 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
2529 // the flag is set according to the L3/Dipole current value
2530 // current threshold for L3 = 350 A (value provided by DCS)
2531 // current threshold for Dipole = 450 A (value provided by DCS)
2533 // parameters[0] = mean
2534 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2535 // parameters[2] = median
2536 // parameters[3] = standard deviation wrt mean
2537 // parameters[4] = standard deviation wrt median
2540 AliInfo(Form("indexDP = %d",indexDP));
2542 Int_t nCounts = array->GetEntries();
2543 for(Int_t i = 0; i < nCounts; i++) {
2544 AliDCSValue *v = (AliDCSValue *)array->At(i);
2545 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2546 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2547 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2548 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
2551 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2552 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
2553 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2554 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
2557 AliError(Form("DCS values for the parameter outside the queried interval"));
2561 return ProcessFloatAll(array);
2565 //_______________________________________________________________
2567 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
2570 // processing Boolean values
2573 Bool_t aDCSBool = kTRUE;
2575 AliDCSValue *v = 0x0;
2577 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2578 v = (AliDCSValue *)array->At(iCount);
2579 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
2580 AliError(Form("DCS values for the parameter outside the queried interval"));
2584 if (aDCSBool != v->GetBool()) {
2585 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2589 aDCSBool = v->GetBool(); // always keeping last value
2590 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
2593 Char_t caDCSBool = (Char_t) aDCSBool;
2598 //_______________________________________________________________
2600 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
2603 // processing Int values, returning mean
2604 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2605 // are outside the queried time interval or their value is out of range
2608 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2609 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2610 if (timeStartString.IsNull() || timeStartString.IsNull()){
2611 if (timeStartString.IsNull()){
2612 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2614 else if (timeStartString.IsNull()){
2615 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2620 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2621 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2622 Float_t aDCSArrayMean = 0.0;
2624 Float_t valueBeforeSOR = 0;
2625 Float_t valueAfterEOR = 0;
2626 Int_t timestampBeforeSOR = -1;
2627 Int_t timestampAfterEOR = -1;
2628 Int_t ientrySOR = -1;
2629 Int_t ientryEOR = -1;
2630 Float_t* arrayValues = 0x0;
2631 Double_t* arrayWeights = 0x0;
2632 Int_t iCountsRun = 0;
2633 Int_t nCounts = array->GetEntries();
2635 for(Int_t i = 0; i < nCounts; i++) {
2636 AliDCSValue* v = (AliDCSValue *)array->At(i);
2637 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
2638 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
2639 return AliGRPObject::GetInvalidFloat();
2641 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2642 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
2644 // look for the last value before SOR and the first value before EOR
2645 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2646 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2647 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2648 valueBeforeSOR = (Float_t) v->GetInt();
2650 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2651 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2652 valueAfterEOR = (Float_t) v->GetInt();
2653 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2655 // check if there are DPs between DAQ_time_start and DAQ_time_end
2656 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2657 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2658 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2659 AliDebug(2,Form("entry between SOR and EOR"));
2664 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2668 if (timestampBeforeSOR == -1){
2669 AliWarning("No value found before SOR!");
2671 if (timestampAfterEOR == -1){
2672 AliWarning("No value found after EOR!");
2675 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2676 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2677 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2678 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2679 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2680 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2682 Int_t nentriesUsed = 0;
2683 if (iCountsRun > 1){
2684 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2685 AliDebug(2,"Calculating (weighted) Mean");
2686 arrayValues = new Float_t[iCountsRun];
2687 arrayWeights = new Double_t[iCountsRun];
2688 nentriesUsed = iCountsRun;
2689 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2690 AliDCSValue *v = (AliDCSValue *)array->At(i);
2691 Int_t timestamp2 = 0;
2693 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2694 timestamp2 = (Int_t)v1->GetTimeStamp();
2697 timestamp2 = timeEnd+1;
2699 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2700 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2702 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2703 delete [] arrayValues;
2704 delete [] arrayWeights;
2706 else if (iCountsRun == 1){
2707 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2709 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2710 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2711 arrayValues = new Float_t[2];
2712 arrayWeights = new Double_t[2];
2713 arrayValues[0] = valueBeforeSOR;
2714 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2715 arrayValues[1] = (Float_t)v->GetInt();
2716 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2717 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2718 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2719 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2720 delete [] arrayValues;
2721 delete [] arrayWeights;
2724 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2725 return AliGRPObject::GetInvalidFloat();
2728 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2729 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2730 if (timestampBeforeSOR == -1){
2731 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2733 if (timestampAfterEOR == -1){
2734 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2736 return AliGRPObject::GetInvalidFloat();
2739 AliWarning("Using last entry before SOR and first entry after EOR.");
2741 arrayValues = new Float_t[2];
2742 arrayWeights = new Double_t[2];
2743 arrayValues[0] = valueBeforeSOR;
2744 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2745 arrayValues[1] = valueAfterEOR;
2746 arrayWeights[1] = 1.;
2747 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2748 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2749 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2750 delete [] arrayValues;
2751 delete [] arrayWeights;
2755 AliInfo(Form("mean = %f ", aDCSArrayMean));
2756 return aDCSArrayMean;
2759 //_______________________________________________________________
2761 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2764 // processing Int values, returning mean
2765 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2766 // are outside the queried time interval or their value is out of range
2769 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2770 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2771 if (timeStartString.IsNull() || timeStartString.IsNull()){
2772 if (timeStartString.IsNull()){
2773 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2775 else if (timeStartString.IsNull()){
2776 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2781 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2782 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2783 Float_t aDCSArrayMean = 0.0;
2785 Float_t valueBeforeSOR = 0;
2786 Float_t valueAfterEOR = 0;
2787 Int_t timestampBeforeSOR = -1;
2788 Int_t timestampAfterEOR = -1;
2789 Int_t ientrySOR = -1;
2790 Int_t ientryEOR = -1;
2791 Float_t* arrayValues = 0x0;
2792 Double_t* arrayWeights = 0x0;
2793 Int_t iCountsRun = 0;
2794 Int_t nCounts = array->GetEntries();
2796 for(Int_t i = 0; i < nCounts; i++) {
2797 AliDCSValue* v = (AliDCSValue *)array->At(i);
2798 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2799 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2800 return AliGRPObject::GetInvalidFloat();
2802 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2803 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2805 // look for the last value before SOR and the first value before EOR
2806 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2807 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2808 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2809 valueBeforeSOR = (Float_t)v->GetUInt();
2811 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2812 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2813 valueAfterEOR = (Float_t)v->GetUInt();
2814 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2816 // check if there are DPs between DAQ_time_start and DAQ_time_end
2817 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2818 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2819 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2820 AliDebug(2,Form("entry between SOR and EOR"));
2825 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2829 if (timestampBeforeSOR == -1){
2830 AliWarning("No value found before SOR!");
2832 if (timestampAfterEOR == -1){
2833 AliWarning("No value found after EOR!");
2836 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2837 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2838 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2839 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2840 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2841 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2843 Int_t nentriesUsed = 0;
2844 if (iCountsRun > 1){
2845 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2846 AliDebug(2,"Calculating (weighted) Mean");
2847 arrayValues = new Float_t[iCountsRun];
2848 arrayWeights = new Double_t[iCountsRun];
2849 nentriesUsed = iCountsRun;
2850 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2851 AliDCSValue *v = (AliDCSValue *)array->At(i);
2852 Int_t timestamp2 = 0;
2854 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2855 timestamp2 = (Int_t)v1->GetTimeStamp();
2858 timestamp2 = timeEnd+1;
2860 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2861 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2863 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2864 delete [] arrayValues;
2865 delete [] arrayWeights;
2867 else if (iCountsRun == 1){
2868 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2870 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2871 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2872 arrayValues = new Float_t[2];
2873 arrayWeights = new Double_t[2];
2874 arrayValues[0] = valueBeforeSOR;
2875 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2876 arrayValues[1] = (Float_t)v->GetUInt();
2877 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2878 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2879 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2880 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2881 delete [] arrayValues;
2882 delete [] arrayWeights;
2885 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2886 return AliGRPObject::GetInvalidFloat();
2889 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2890 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2891 if (timestampBeforeSOR == -1){
2892 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2894 if (timestampAfterEOR == -1){
2895 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2897 return AliGRPObject::GetInvalidFloat();
2900 AliWarning("Using last entry before SOR and first entry after EOR.");
2902 arrayValues = new Float_t[2];
2903 arrayWeights = new Double_t[2];
2904 arrayValues[0] = valueBeforeSOR;
2905 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2906 arrayValues[1] = valueAfterEOR;
2907 arrayWeights[1] = 1.;
2908 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2909 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2910 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2911 delete [] arrayValues;
2912 delete [] arrayWeights;
2916 AliInfo(Form("mean = %f ",aDCSArrayMean));
2917 return aDCSArrayMean;
2922 //_______________________________________________________________
2924 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2926 // extract DCS pressure maps. Perform fits to save space
2928 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2930 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2931 fPressure->MakeSplineFit(map);
2932 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2933 if (fitFraction > kFitFraction ) {
2934 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2936 AliInfo("Too few pressure maps fitted!!!");
2939 AliInfo("no atmospheric pressure map extracted!!!");
2948 //_______________________________________________________________
2949 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)
2952 // Retrieves logbook and trigger information from the online logbook
2953 // This information is needed for prompt reconstruction
2957 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2961 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2962 // 0 on success and no run was found
2963 // negative on error
2965 // This function is NOT called during the preprocessor run in the Shuttle!
2973 AliCDBManager* cdb = AliCDBManager::Instance();
2974 cdb->SetDefaultStorage(cdbRoot);
2977 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2981 Printf("ERROR: Could not connect to DAQ LB");
2987 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
2988 TSQLResult* result = server->Query(sqlQuery);
2991 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2995 if (result->GetRowCount() == 0)
2997 Printf("ERROR: Run %d not found", run);
3002 TSQLRow* row = result->Next();
3005 Printf("ERROR: Could not receive data from run %d", run);
3010 TString timeStartString(row->GetField(0));
3011 TString runType(row->GetField(1));
3012 TString detectorMaskString(row->GetField(2));
3013 TString l3CurrentString(row->GetField(3));
3014 TString dipoleCurrentString(row->GetField(4));
3015 TString beamTypeString(row->GetField(5));
3016 time_t timeStart = (time_t)(timeStartString.Atoi());
3017 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
3018 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
3019 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
3020 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
3021 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
3022 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
3023 beamTypeString="A-A";
3026 AliGRPObject * grpObj = new AliGRPObject();
3027 grpObj->SetTimeStart(timeStart);
3028 grpObj->SetRunType((TString)(row->GetField(1)));
3029 grpObj->SetDetectorMask(detectorMask);
3030 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
3031 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
3032 grpObj->SetL3Polarity(l3Polarity);
3033 grpObj->SetDipolePolarity(dipolePolarity);
3034 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
3035 grpObj->SetBeamType(beamTypeString);
3043 Printf("Storing GRP/GRP/Data object with the following content");
3046 AliCDBMetaData metadata;
3047 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
3048 metadata.SetComment("GRP Output parameters received during online running");
3050 AliCDBId id("GRP/GRP/Data", run, run);
3051 Bool_t success = cdb->Put(grpObj, id, &metadata);
3057 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
3061 // Receive trigger information
3062 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
3063 result = server->Query(sqlQuery);
3066 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3070 if (result->GetRowCount() == 0)
3072 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
3077 row = result->Next();
3080 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
3085 TString triggerConfig(row->GetField(0));
3093 Printf("Found trigger configuration: %s", triggerConfig.Data());
3095 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
3098 Printf("ERROR: Could not create CTP configuration object");
3102 metadata.SetComment("CTP run configuration received during online running");
3104 AliCDBId id2("GRP/CTP/Config", run, run);
3105 success = cdb->Put(runcfg, id2, &metadata);
3112 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
3117 // Receive list of GDCs for this run
3118 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
3119 result = server->Query(sqlQuery);
3122 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3126 if (result->GetRowCount() == 0)
3128 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
3134 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
3135 row = result->Next();
3138 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
3142 gdc += row->GetField(0);
3152 Printf("Found GDC: %s", gdc.Data());
3154 // get last run with same run type that was already processed by the SHUTTLE
3156 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());
3157 result = server->Query(sqlQuery);
3160 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3164 if (result->GetRowCount() == 0)
3166 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
3171 row = result->Next();
3174 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
3179 TString lastRunStr(row->GetField(0));
3180 Int_t lastRun = lastRunStr.Atoi();
3182 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
3196 //------------------------------------------------------------------------------------------------------
3197 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
3200 // Method to processo LHC Energy information
3201 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
3204 Int_t nCounts = array->GetEntries();
3205 Float_t energy = -1;
3206 Double_t timeEnergy = -1;
3207 Int_t indexEnergy = -1;
3208 Bool_t foundEnergy = kFALSE;
3210 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
3212 AliWarning("No Energy values found! Beam Energy remaining invalid!");
3215 for (Int_t i = 0; i < nCounts; i++){
3216 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
3218 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
3219 timeEnergy = dcs->GetTimeStamp();
3221 foundEnergy = kTRUE;
3229 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
3232 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
3233 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
3234 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
3240 //------------------------------------------------------------------------------------------------------
3241 AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
3244 // Method to process LHC-Clock Phase data
3245 // Only the values between DAQ_time_start and DAQ_time_end are kept
3247 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
3249 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
3250 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
3252 TString timeCreatedStr = GetRunParameter("time_created");
3253 Double_t timeCreated = timeCreatedStr.Atof();
3255 Int_t nCounts = beam1phase->GetEntries();
3256 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
3258 AliWarning("No beam1 LHC clock phase values found!");
3263 Double_t prevPhase = 0;
3264 for (Int_t i = 0; i < nCounts; i++){
3265 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
3267 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
3268 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
3269 if ((i == 0) || (i == (nCounts-1)) ||
3271 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3272 prevPhase = dcs->GetDouble(0);
3273 foundBeam1Phase = kTRUE;
3274 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
3275 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3276 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3281 if (!foundBeam1Phase){
3282 AliError("No beam1 LHC clock phase values found within the run!");
3288 nCounts = beam2phase->GetEntries();
3289 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
3291 AliWarning("No beam2 LHC clock phase values found!");
3296 Double_t prevPhase = 0;
3297 for (Int_t i = 0; i < nCounts; i++){
3298 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
3300 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
3301 if ((i == 0) || (i == (nCounts-1)) ||
3303 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3304 prevPhase = dcs->GetDouble(0);
3305 foundBeam2Phase = kTRUE;
3306 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
3307 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3308 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3313 if (!foundBeam2Phase){
3314 AliError("No beam2 LHC clock phase values found within the run!");
3322 //------------------------------------------------------------------------------------------------------
3323 TString AliGRPPreprocessor::ParseBeamTypeString(TString beamType, Int_t iBeamType)
3325 // Method to return the convention for the separate beam type
3326 // in the form A*1000+Z
3327 // e.g.: Pb82 --> 208000 + 82 = 208082
3328 // p --> 1000 + 1 = 1001
3332 TString separateString("");
3333 Log(Form("Setting Beam Type for beam %d to A*1000+Z",iBeamType));
3334 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
3335 Log(Form("Beam type %d is PROTON --> The single beam type will be set to 1001 (A = 1, Z = 1)",iBeamType));
3336 separateString = "1001";
3337 return separateString;
3340 TPRegexp regexpA("\\D+");
3341 TPRegexp regexpZ("\\d+");
3342 TObjArray* arrayA = regexpA.MatchS(beamType);
3343 TObjArray* arrayZ = regexpZ.MatchS(beamType);
3344 if (arrayA->GetEntries() != 1 || arrayZ->GetEntries() != 1){
3345 Log(Form("The beamType string for beam %d does not contain the necessary information! Returning the info as published by LHC (i.e. %s)",iBeamType, beamType.Data()));
3349 TString strA = ((TObjString*)(arrayA->At(0)))->String();
3350 TString strZ = ((TObjString*)(arrayZ->At(0)))->String();
3351 if (strA.CompareTo("LEAD",TString::kIgnoreCase) == 0 || strA.CompareTo("PB",TString::kIgnoreCase) == 0){
3352 Log(Form("Beam %d is %s --> A = 208",iBeamType, strA.Data()));
3356 Log(Form("This beam was not foreseen so far, leaving A=0"));
3359 Log(Form("Beam %d has Z = %d",iBeamType, z));
3360 separateString = Form("%d",a*1000+z);
3361 return separateString;
3365 return separateString;