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"
76 ClassImp(AliGRPPreprocessor)
79 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
81 //_______________________________________________________________
83 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 6; // num parameters in the logbook used to fill the GRP object
84 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
85 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
86 const Int_t AliGRPPreprocessor::fgknLHCDP = 9; // number of dcs dps from LHC data
87 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
88 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
89 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
97 "L3_BSF17_Temperature",
101 "L3_BSF4_Temperature",
105 "L3_BKF17_Temperature",
109 "L3_BKF4_Temperature",
113 "L3_BSF13_Temperature",
117 "L3_BSF8_Temperature",
121 "L3_BKF13_Temperature",
125 "L3_BKF8_Temperature",
129 "Dipole_Inside_Temperature",
133 "Dipole_Outside_Temperature",
135 "CavernAtmosPressure",
136 "SurfaceAtmosPressure",
137 "CavernAtmosPressure2"
140 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
144 "L3_BSF17_Temperature",
148 "L3_BSF4_Temperature",
152 "L3_BKF17_Temperature",
156 "L3_BKF4_Temperature",
160 "L3_BSF13_Temperature",
164 "L3_BSF8_Temperature",
168 "L3_BKF13_Temperature",
172 "L3_BKF8_Temperature",
176 "Dipole_Inside_Temperature",
180 "Dipole_Outside_Temperature"
183 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
184 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
187 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
191 "LHC_Beams_Particle_Type",
192 "BPTX_Phase_Shift_B1",
193 "BPTX_Phase_Shift_B2",
194 "LHC_Particle_Type_B1",
195 "LHC_Particle_Type_B2",
196 "LHC_Data_Quality_Flag"
199 const char* kppError[] = {
201 "(DAQ logbook ERROR)",
203 "(Trigger Scalers not found in FXS - ERROR)",
204 "(DCS data points ERROR)",
205 "(Trigger Configuration ERROR)",
206 "(DAQ logbook ERROR determining partition of the run)",
207 "(CTP timing ERROR)",
208 "(SPD Mean Vertex ERROR)",
209 "(FXS Error for LHC Data)",
211 "(LHC Clock Phase Error (from LHC Data))",
212 "(LTU Configuration Error)",
214 "(Trigger Aliases wrong or not found in DCS FXS - ERROR)"
217 //_______________________________________________________________
219 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
220 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))
222 // constructor - shuttle must be instantiated!
224 AddRunType("COSMIC");
226 AddRunType("PHYSICS");
227 AddRunType("CALIBRATION_BC");
228 AddRunType("CALIBRATION_CENTRAL");
229 AddRunType("CALIBRATION_EMD");
230 AddRunType("CALIBRATION_MB");
231 AddRunType("CALIBRATION_SEMICENTRAL");
232 AddRunType("CALIBRATION");
233 AddRunType("PEDESTAL");
234 AddRunType("STANDALONE");
237 AddRunType("PULSER");
238 AddRunType("STANDALONE_PULSER");
239 AddRunType("STANDALONE_BC");
242 fminFloat = -FLT_MAX;
243 fmaxDouble = DBL_MAX;
244 fminDouble = -DBL_MAX;
250 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
251 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
252 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
253 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
254 AliInfo(Form("Max allowed integer = %d",fmaxInt));
255 AliInfo(Form("Min allowed integer = %d",fminInt));
256 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
257 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
259 ffailedDPs->SetOwner(kTRUE);
262 //_______________________________________________________________
264 AliGRPPreprocessor::~AliGRPPreprocessor()
273 //_______________________________________________________________
275 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
277 // Initialize preprocessor
279 AliPreprocessor::Initialize(run, startTime, endTime);
281 AliInfo("Initialization of the GRP preprocessor.");
282 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
283 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
284 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
285 for(Int_t j = 0; j < kNumSensors; j++) {
286 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
287 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
289 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
291 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
293 ffailedDPs->Clear(); // cleaning ffailedDPs for current run
294 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
295 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
296 ffailedDPs->AddAt(dp,iDP);
301 //_______________________________________________________________
303 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
305 // process data retrieved by the Shuttle
307 // retrieving "partition" and "detector" fields from DAQ logbook to
308 // determine the partition in which the run was taken
309 // the partition is used to decide how to react in case of errors for CTP
311 TString partition = (TString)GetRunParameter("partition");
312 TString detector = (TString)GetRunParameter("detector");
314 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
315 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
317 //=================//
319 //=================//
321 Log("*************** Processing DAQ logbook");
325 Int_t iDaqLB = ProcessDaqLB(grpobj);
326 TString runType = (TString)GetRunType();
327 TString beamType = (TString)GetRunParameter("beamType");
328 if(iDaqLB == fgknDAQLbPar) {
329 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
331 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
335 //=================//
337 //=================//
339 Log("*************** Processing DAQ FXS");
341 UInt_t iDaqFxs = ProcessDaqFxs();
343 Log(Form("DAQ FXS, successful!"));
345 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
349 //=================//
351 //=================//
353 Log("*************** Processing DCS FXS");
355 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
357 Log(Form("DCS FXS, successful!"));
358 } else if (iDcsFxs ==1) {
359 Log(Form("Could not store CTP scalers!!!"));
361 } else if (iDcsFxs == 2) {
362 Log(Form("Could not store CTP aliases!!!"));
365 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
369 //=================//
370 // DCS data points //
371 //=================//
373 Log("*************** Processing DCS DPs");
375 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
376 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
377 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
378 if (fdaqStartEndTimeOk){
379 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
380 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
381 Log(Form("The DPs giving problems were:"));
382 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
383 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
385 TString name = dpString->String();
386 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
387 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
390 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()));
396 else Log(Form("DCS data points, successful!"));
398 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"));
400 //=======================//
401 // Trigger Configuration //
402 //=======================//
404 Log("*************** Processing Trigger Configuration");
406 const char * triggerConf = GetTriggerConfiguration();
408 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
409 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
410 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
412 Log(Form("No dummy CTP configuration entry found, going into error..."));
416 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
418 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
422 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
423 runcfg->SetTitle(titleCTPcfg);
424 AliCDBMetaData metaData;
425 metaData.SetResponsible("Roman Lietava");
426 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
427 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
428 Log("Unable to store the dummy CTP run configuration object to OCDB!");
435 else if (!partition.IsNull() && detector.IsNull()){ // global partition
436 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
437 if (triggerConf!= NULL) {
438 Log("Found trigger configuration in DAQ logbook");
439 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
441 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
445 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
446 runcfg->SetTitle(titleCTPcfg);
447 AliCDBMetaData metaData;
448 metaData.SetBeamPeriod(0);
449 metaData.SetResponsible("Roman Lietava");
450 metaData.SetComment("CTP run configuration from DAQ logbook");
451 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
452 Log("Unable to store the CTP run configuration object to OCDB!");
459 Log("Trigger configuration NULL in DAQ logbook");
465 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
469 //===========================//
470 // Trigger Timing Parameters //
471 //===========================//
473 Log("*************** Processing Trigger Time Params");
475 const char * triggerCTPtiming = GetCTPTimeParams();
477 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
478 Log("STANDALONE partition for current run, using CTP timing params dummy value");
479 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
481 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
485 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
487 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
491 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
492 runCTPtiming->SetTitle(titleCTPtiming);
493 AliCDBMetaData metadata;
494 metadata.SetResponsible("Roman Lietava");
495 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
496 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
497 Log("Unable to store the dummy CTP timing params object to OCDB!");
504 else if (!partition.IsNull() && detector.IsNull()){ // global partition
505 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
506 if (triggerCTPtiming!= NULL) {
507 Log("Found trigger timing params in DAQ logbook");
508 AliDebug(2,Form("%s",triggerCTPtiming));
509 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
511 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
515 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
516 runCTPtiming->SetTitle(titleCTPtiming);
517 AliCDBMetaData metadata;
518 metadata.SetBeamPeriod(0);
519 metadata.SetResponsible("Roman Lietava");
520 metadata.SetComment("CTP timing params from DAQ logbook");
521 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
522 Log("Unable to store the CTP timing params object to OCDB!");
529 Log("Trigger timing params NULL in DAQ logbook");
535 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
539 //===========================//
540 // LTU Configuration //
541 //===========================//
543 Log("*************** Processing LTU Configuration");
545 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
546 Log("STANDALONE partition for current run, using LTU configuration dummy value");
547 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
549 Log(Form("No dummy LTU Config entry found, going into error..."));
553 TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
555 Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
559 AliCDBMetaData metadata;
560 metadata.SetResponsible("Roman Lietava");
561 metadata.SetComment("LTU Config from dummy entry in OCDB");
562 if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
563 Log("Unable to store the dummy LTU Config object to OCDB!");
570 else if (!partition.IsNull() && detector.IsNull()){ // global partition
572 Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
573 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
574 Printf ("detectormask = %d",detectorMask);
575 TObjArray * ltuarray = new TObjArray();
576 ltuarray->SetOwner(1);
577 Bool_t isLTUok = kTRUE;
578 for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
579 if ((detectorMask >> i) & 0x1) {
580 TString det = AliDAQ::OfflineModuleName(i);
581 TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
582 if (detCTPName == "CTP") {
583 detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors
584 Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
587 Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
588 TString* ltu = GetLTUConfig(detCTPName.Data());
590 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()));
596 Float_t ltuFineDelay1 = ltu[0].Atof();
597 Float_t ltuFineDelay2 = ltu[1].Atof();
598 Float_t ltuBCDelayAdd = ltu[2].Atof();
599 const char* name = AliDAQ::DetectorName(i);
600 AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
601 ltuarray->AddAtAndExpand(ltuConfig,i);
606 AliCDBMetaData metadata;
607 metadata.SetBeamPeriod(0);
608 metadata.SetResponsible("Roman Lietava");
609 metadata.SetComment("LTU Configuration for current run");
610 if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
611 Log("Unable to store the LTU Config object to OCDB!");
619 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
624 //=================//
626 //=================//
628 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
629 Log("*************** Processing LHC Data");
631 UInt_t iLHCData = ProcessLHCData(grpobj);
633 if( iLHCData == 0 ) {
634 Log(Form("LHC Data from FXS, successful!"));
635 } else if (iLHCData == 1) {
636 Log(Form("LHC Data, problems with FXS!"));
638 } else if (iLHCData == 2) {
639 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
641 } else if (iLHCData ==3){
642 Log(Form("Problems in storing LHC Phase - going into Error"));
644 } else if (iLHCData ==4){
645 Log(Form("Problems with LHC Phase - going into Error"));
648 Log(Form("LHC Data problems"));
654 //==================//
655 // SPD Mean Vertex //
656 //==================//
658 Log("*************** Processing SPD Mean Vertex");
660 if (runType == "PHYSICS"){
661 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
662 if( iSPDMeanVertex == 1 ) {
663 Log(Form("SPD Mean Vertex, successful!"));
665 Log(Form("SPD Mean Vertex failed!!!"));
670 Log("SPD Mean Vertex not processed since runType != PHYSICS");
673 //=================//
675 //=================//
677 Log("*************** Processing DQM FXS");
679 UInt_t iDqmFxs = ProcessDqmFxs();
681 Log(Form("DQM FXS, successful!"));
683 Log(Form("DQM FXS failed!!!"));
687 // storing AliGRPObject in OCDB
690 md.SetResponsible("Chiara Zampolli");
691 md.SetComment("Output parameters from the GRP preprocessor.");
693 Bool_t result = kTRUE;
694 result = Store("GRP", "Data", grpobj, &md);
697 if (result && !error ) {
698 Log("GRP Preprocessor Success");
701 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s%s%s",
702 kppError[(error&1)?1:0],
703 kppError[(error&2)?2:0],
704 kppError[(error&4)?3:0],
705 kppError[(error&8)?4:0],
706 kppError[(error&16)?5:0],
707 kppError[(error&32)?6:0],
708 kppError[(error&64)?7:0],
709 kppError[(error&128)?8:0],
710 kppError[(error&256)?9:0],
711 kppError[(error&512)?10:0],
712 kppError[(error&1024)?11:0],
713 kppError[(error&2048)?12:0],
714 kppError[(error&4096)?13:0],
715 kppError[(error&8192)?14:0]
723 //_______________________________________________________________
725 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
728 //Getting the LHC Data from DCS FXS
731 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
732 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
733 if (timeStartString.IsNull() || timeEndString.IsNull()){
734 if (timeStartString.IsNull()){
735 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
737 else if (timeEndString.IsNull()){
738 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
743 Double_t timeStart = timeStartString.Atof();
744 Double_t timeEnd = timeEndString.Atof();
746 TString fileName = GetFile(kDCS, "LHCData","");
747 if (fileName.Length()>0){
748 AliInfo("Got The LHC Data file");
749 AliLHCReader lhcReader;
751 // Processing data to be put in AliGRPObject
754 Log("*************Energy ");
755 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
757 Float_t energy = ProcessEnergy(energyArray,timeStart);
759 grpobj->SetBeamEnergy(energy);
760 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
765 AliError("Energy not found in LHC Data file!!!");
768 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
769 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
770 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
771 Double_t timeBeamTypeEnd[2] = {timeEnd, timeEnd}; // max validity for Beam Type1,2
772 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
773 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
774 Double_t timeBeamStart = -1; // min validity for Beam Type
775 Double_t timeBeamTypeStart[2] = {-1,-1}; // min validity for Beam Type1,2
776 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
777 Int_t indexMachineMode = -1; // index of measurement used to set Machine Mode
778 Int_t indexBeam = -1; // index of measurement used to set Beam Type
779 Int_t indexBeamType[2] = {-1, -1}; // index of measurement used to set Beam Type1,2
780 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
781 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Machine Mode is found before (or at) SOR
782 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Type is found before (or at) SOR
783 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
784 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
785 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
786 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
787 Bool_t flagBeamType[2] = {kFALSE, kFALSE}; //flag set true if a changed occurred in BeamType1,2
789 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...)
790 // arrayTimes elements order correspond to the one used in the array of the strings fgkLHCDataPoints, i.e.:
791 // arrayTimes[0] --> MachineMode
792 // arrayTimes[1] --> BeamMode
793 // arrayTimes[2] --> BeamType (when written together)
794 // arrayTimes[3] --> BeamType1 (when written separate)
795 // arrayTimes[4] --> BeamType2 (when written separate)
798 Log("*************BeamMode (LHCState) ");
799 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
800 Int_t nBeamMode = -1;
802 nBeamMode = beamModeArray->GetEntries();
804 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
807 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
808 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
810 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
811 timeBeamModeStart = beamMode->GetTimeStamp();
812 indexBeamMode = iBeamMode;
813 foundBeamModeStart = kTRUE;
821 if (!foundBeamModeStart){
822 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
825 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
826 TObjString* beamModeString = beamMode->GetStringArray(0);
827 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
828 grpobj->SetLHCState(beamModeString->String());
829 if (indexBeamMode < nBeamMode-1){
830 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
832 if (beamMode1->GetTimeStamp()<=timeStart){
833 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
835 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
836 timeBeamModeEnd = beamMode1->GetTimeStamp();
837 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
838 TString bmString0 = beamModeString->String();
839 TString bmString1 = beamModeString1->String();
840 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
841 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()));
842 flagBeamMode = kTRUE;
843 arrayTimes[1]=timeBeamModeEnd;
849 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
854 delete beamModeArray;
857 AliError("Beam mode array not found in LHC Data file!!!");
861 Log("*************MachineMode ");
862 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
863 Int_t nMachineMode = -1;
864 if (machineModeArray){
865 nMachineMode = machineModeArray->GetEntries();
866 if (nMachineMode==0){
867 AliInfo("No Machine Mode found, leaving it empty");
870 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
871 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
873 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
874 timeMachineModeStart = machineMode->GetTimeStamp();
875 indexMachineMode = iMachineMode;
876 foundMachineModeStart = kTRUE;
883 if (!foundMachineModeStart){
884 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
887 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
888 TObjString* machineModeString = machineMode->GetStringArray(0);
889 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
890 grpobj->SetMachineMode(machineModeString->String());
891 if (indexMachineMode < nMachineMode-1){
892 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
894 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
895 timeMachineModeEnd = machineMode1->GetTimeStamp();
896 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
897 TString mmString0 = machineModeString->String();
898 TString mmString1 = machineModeString1->String();
899 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
900 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()));
901 flagMachineMode = kTRUE;
902 arrayTimes[0]=timeMachineModeEnd;
907 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
912 delete machineModeArray;
915 AliError("Machine mode array not found in LHC Data file!!!");
918 // BeamType1 and BeamType2 - both put in the same string
919 Log("*************BeamType ");
920 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
922 Int_t nBeam = beamArray->GetEntries();
924 AliInfo("No Beam Type found, leaving it empty");
927 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
928 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
930 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
931 timeBeamStart = beam->GetTimeStamp();
933 foundBeamStart = kTRUE;
940 if (!foundBeamStart){
941 AliInfo("No value for the Beam Type found before start of run, the (common) Beam Type will remain empty");
944 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
945 TObjString* beamString = beam->GetStringArray(0);
946 TString beamType = beamString->String();
947 AliInfo(Form("Beam Type = %s",beamType.Data()));
948 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
949 AliInfo("Setting beam type to p-p");
950 grpobj->SetBeamType("p-p");
952 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
953 AliInfo("Setting beam type to A-A");
954 grpobj->SetBeamType("A-A");
957 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
958 AliInfo("Setting beam type to Pb-Pb");
959 grpobj->SetBeamType("Pb-Pb");
962 AliError("Beam Type not known, leaving it empty");
965 if (indexBeam < nBeam-1){
966 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
968 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
969 timeBeamEnd = beam1->GetTimeStamp();
970 TObjString* beamString1 = beam1->GetStringArray(0);
971 TString beamType1 = beamString1->String();
972 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
973 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()));
975 arrayTimes[2] = timeBeamEnd;
980 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
988 AliError("Beam Type array not found in LHC Data file!!!");
991 // BeamType1 and BeamType2 - in separete string
992 Log("*************BeamType, 1 and 2 ");
993 Int_t indexBeamTypeString = 6; // index of the string with the alias of BeanType1 in the array fgkLHCDataPoints
994 TString combinedBeamType = "-"; // combined beam type, built from beam type 1 and beam type 2
995 TString combinedBeamTypeFromLHC = "-"; // combined beam type, built from beam type 1 and beam type 2 AS SENT FROM LHC
996 for (Int_t ibeamType = 0; ibeamType<2; ibeamType++){
997 beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[indexBeamTypeString+ibeamType]);
999 Int_t nBeam = beamArray->GetEntries();
1001 AliInfo(Form("No Beam Type %s found, leaving it empty",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1004 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
1005 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
1007 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
1008 timeBeamTypeStart[ibeamType] = beam->GetTimeStamp();
1009 indexBeamType[ibeamType] = iBeam;
1010 foundBeamTypeStart[ibeamType] = kTRUE;
1017 if (!foundBeamTypeStart[ibeamType]){
1018 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));
1021 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
1022 TObjString* beamString = beam->GetStringArray(0);
1023 TString beamType = beamString->String();
1024 AliInfo(Form("Beam Type (for %s) = %s", fgkLHCDataPoints[indexBeamTypeString+ibeamType], beamType.Data()));
1025 TString singleBeam = ParseBeamTypeString(beamType,ibeamType);
1026 AliInfo(Form("Single Beam Type for beam %d set to %s", ibeamType, singleBeam.Data()));
1027 grpobj->SetSingleBeamType(ibeamType, singleBeam);
1028 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
1029 AliInfo(Form("Setting beam %d for combined beam type to p", ibeamType));
1030 if (ibeamType == 0) combinedBeamType.Prepend("p");
1031 else combinedBeamType.Append("p");
1033 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
1034 AliInfo(Form("Setting beam %d for combined beam type to A",ibeamType));
1035 if (ibeamType == 0) combinedBeamType.Prepend("A");
1036 else combinedBeamType.Append("A");
1038 if (ibeamType == 0) combinedBeamTypeFromLHC.Prepend(beamType);
1039 else combinedBeamTypeFromLHC.Append(beamType);
1041 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
1042 AliInfo("Setting beam type to Pb-Pb");
1043 grpobj->SetSingleBeamType(ibeamType, "Pb-Pb");
1046 AliError("Beam Type not known, leaving it empty");
1049 if (indexBeamType[ibeamType] < nBeam-1){
1050 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
1052 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
1053 timeBeamTypeEnd[ibeamType] = beam1->GetTimeStamp();
1054 TObjString* beamString1 = beam1->GetStringArray(0);
1055 TString beamType1 = beamString1->String();
1056 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
1057 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()));
1058 flagBeamType[ibeamType] = kTRUE;
1059 arrayTimes[3+ibeamType] = timeBeamTypeEnd[ibeamType];
1064 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]));
1072 AliError(Form("Beam Type %s array not found in LHC Data file!!!",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1075 AliInfo(Form("Setting combined beam type to %s",combinedBeamType.Data()));
1076 grpobj->SetBeamType(combinedBeamType);
1077 AliInfo(Form("Setting combined beam type form LHC to %s",combinedBeamTypeFromLHC.Data()));
1078 grpobj->SetBeamTypeFromLHC(combinedBeamTypeFromLHC);
1080 // Setting minTimeLHCValidity
1081 if (flagBeamMode == kTRUE || flagMachineMode == kTRUE || flagBeam == kTRUE || flagBeamType[0] == kTRUE || flagBeamType[1] == kTRUE){
1082 Double_t minTimeLHCValidity= TMath::MinElement(5,arrayTimes);
1083 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1084 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1087 // Old way to determine the Maximum Time during which the LHC info is valid
1088 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
1089 Double_t minTimeLHCValidity;
1090 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true --> it is the only one that changed
1091 minTimeLHCValidity = timeBeamEnd;
1093 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
1094 minTimeLHCValidity = timeMachineModeEnd;
1096 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
1097 minTimeLHCValidity = timeBeamModeEnd;
1099 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
1100 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
1102 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
1103 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
1105 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
1106 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
1109 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
1110 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
1112 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1113 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1117 // Data Quality Flag --> storing start and end values of periods within the run during which the value was found to be FALSE
1118 Log("*************Data Quality Flag ");
1119 TObjArray* dataQualityArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[8]);
1120 Int_t nDataQuality = -1;
1121 Double_t timeDataQualityStart = -1; // min validity for Data Quality Flag
1122 Int_t indexDataQuality = -1; // index of first measurement used to set Data Quality Flag
1123 Bool_t foundDataQualityStart = kFALSE; // flag to be set in case an entry for the Data Quality Flag is found before (or at) SOR
1125 if (dataQualityArray){
1126 nDataQuality = dataQualityArray->GetEntries();
1127 if (nDataQuality==0){
1128 AliInfo("No Data Quality Flag found, leaving it empty");
1131 for (Int_t iDataQuality = 0; iDataQuality<nDataQuality; iDataQuality++){
1132 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1134 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
1135 timeDataQualityStart = dataQuality->GetTimeStamp();
1136 indexDataQuality = iDataQuality;
1137 foundDataQualityStart = kTRUE;
1140 // we suppose here that if the first measurement is not before SOR, then none will be (they MUST be in chronological order!!!)
1145 if (!foundDataQualityStart){
1146 // 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..
1147 AliInfo("No value for the Data Quality Flag found before start of run, the Data Quality Flag will remain empty");
1150 // counting how many FALSE values there are
1151 Bool_t foundEndOfFalse = kFALSE;
1153 for (Int_t iDataQuality = indexDataQuality; iDataQuality < nDataQuality; iDataQuality ++){
1154 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1155 AliDebug(4,Form("dataQuality->GetTimeStamp() = %f, timeDataQualityStart = %f, timeEnd = %f", dataQuality->GetTimeStamp(), timeDataQualityStart, timeEnd ));
1156 if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
1157 Bool_t dataQualityFlag = dataQuality->GetBool(0);
1158 AliDebug(3,Form("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp()));
1159 if (dataQualityFlag != kTRUE){
1160 if (iDataQuality == indexDataQuality) { // the first Data Quality value should be TRUE, but ignoring the problem now...
1161 AliError("The first value for the Data Quality MUST be TRUE! Ignoring for now...");
1168 AliInfo(Form("Found %d FALSE values for the Data Quality Flag",nFalse));
1169 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
1171 Int_t iDataQuality = indexDataQuality;
1174 // filling the info about the periods when the flag was set to FALSE
1175 // starting, like for the other DPS, from the measurement closest to SOR (the index of which is iDataQuality)
1176 while (iDataQuality < nDataQuality){
1177 AliDebug(3,Form("iDataQuality = %d",iDataQuality));
1178 AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
1179 if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
1180 Bool_t dataQualityFlag = dataQuality->GetBool(0);
1181 AliDebug(3,Form("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp()));
1182 if (dataQualityFlag == kTRUE){
1183 // found TRUE value, continuing
1189 // the check was already done before
1190 if (iDataQuality == indexDataQuality) { // the first Data Quality value should be TRUE, but ignoring the problem now...
1191 AliError("The first value for the Data Quality MUST be TRUE! Ignoring for now...");
1194 falses[iFalse*2] = dataQuality->GetTimeStamp();
1195 foundEndOfFalse = kFALSE;
1196 Int_t iDataQualityNext = iDataQuality+1;
1197 while (iDataQualityNext < nDataQuality){
1198 AliDCSArray* dataQualityNext = (AliDCSArray*)dataQualityArray->At(iDataQualityNext);
1199 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
1200 Bool_t dataQualityFlagNext = dataQualityNext->GetBool(0);
1201 AliDebug(3,Form("DataQualityNext = %d (set at %f)",(Int_t)dataQualityFlagNext,dataQualityNext->GetTimeStamp()));
1202 if (dataQualityFlagNext == kTRUE){
1203 // found TRUE value, first FALSE period completed
1204 foundEndOfFalse = kTRUE;
1205 falses[iFalse*2+1] = dataQualityNext->GetTimeStamp();
1212 if (!foundEndOfFalse) {
1213 AliInfo("Please, note that the last FALSE value lasted until the end of the run");
1214 falses[iFalse*2+1] = timeEnd;
1218 iDataQuality = iDataQualityNext+1;
1222 grpobj->SetNFalseDataQualityFlag(iFalse);
1223 grpobj->SetFalseDataQualityFlagPeriods(falses);
1227 delete dataQualityArray;
1230 AliError("Data Quality Flag array not found in LHC Data file!!!");
1233 // Processing data to go to AliLHCData object
1234 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
1235 // storing AliLHCData in OCDB
1237 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
1239 md.SetResponsible("Ruben Shahoyan");
1240 md.SetComment("LHC data from the GRP preprocessor.");
1241 Bool_t result = kTRUE;
1242 result = Store("GRP", "LHCData", dt, &md);
1245 Log(Form("Problems in storing LHC Data - but not going into Error"));
1249 // processing LHC Phase
1251 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
1252 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
1253 if (beam1phase == 0x0 || beam2phase == 0x0){
1254 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
1257 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
1261 AliInfo(Form("LHC Phase found"));
1262 AliCDBMetaData mdPhase;
1263 mdPhase.SetResponsible("Cvetan Cheshkov");
1264 mdPhase.SetComment("LHC Clock Phase");
1265 Bool_t result = kTRUE;
1266 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
1268 if (!result) return 3;
1274 AliError("No LHCData file found in FXS");
1281 //_______________________________________________________________
1283 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
1286 //Getting the SPD Mean Vertex
1289 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
1290 Bool_t storeResult = kTRUE;
1291 if (list !=0x0 && list->GetEntries()!=0)
1293 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
1295 for (Int_t jj=0;jj<list->GetEntries();jj++){
1296 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1298 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1301 AliInfo(Form("found source %s", str->String().Data()));
1302 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
1303 if (fileNameRun.Length()>0){
1304 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1305 TFile daqFile(fileNameRun.Data(),"READ");
1306 if (daqFile.IsOpen()) {
1307 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
1310 // storing in the OCDB
1312 md.SetResponsible("Cvetan Cheshkov");
1313 md.SetComment("SPD Mean Vertex");
1314 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
1317 AliWarning("No SPD Mean Vertex object found in file");
1321 AliError("Can't open file");
1322 storeResult = kFALSE;
1326 AliWarning("No file found for current source for SPD Mean Vertex");
1331 AliWarning("No list found for SPD Mean Vertex");
1334 if (list) delete list;
1338 //_______________________________________________________________
1340 UInt_t AliGRPPreprocessor::ProcessDqmFxs()
1343 // Processing DQM fxs information
1346 // TriggerClassesAndHistosToClone
1347 TList* list = GetFileSources(kDQM, "TriggerClassesAndHistosToClone");
1348 Bool_t storeResult = kTRUE;
1349 Bool_t storeResultQAThr = kTRUE;
1350 if (list !=0x0 && list->GetEntries()!=0){
1351 AliInfo("The following sources produced files with the id TriggerClassesAndHistosToClone for GRP");
1353 for (Int_t jj=0;jj<list->GetEntries();jj++){
1354 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1356 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1359 AliInfo(Form("found source %s", str->String().Data()));
1360 TString fileNameRun = GetFile(kDQM, "TriggerClassesAndHistosToClone", str->GetName());
1361 if (fileNameRun.Length()>0){
1362 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1363 TFile dqmFile(fileNameRun.Data(),"READ");
1364 if (dqmFile.IsOpen()) {
1368 AliError("Can't open file");
1369 storeResult = kFALSE;
1373 AliWarning("No file found for current source for DQM TriggerClassesAndHistosToClone");
1378 AliWarning("No list found for DQM TriggerClassesAndHistosToClone");
1381 if (list) delete list;
1384 TObjArray* qaThrArray = new TObjArray();
1385 for (Int_t idet = 0; idet < AliDAQ::kNDetectors; idet++){
1386 TString detName = AliDAQ::OnlineName(idet);
1387 if (detName == "TRI" || detName == "HLT" || detName == "TST") continue; // skipping TRI, HLT, TST since they do not produce QAThresholds
1388 AliDebug(2, Form("Processing QAThreshold for detector %s",detName.Data()));
1389 TList* listQAThr = GetForeignFileSources(detName.Data(), kDQM, "QAThresholds");
1390 if (listQAThr !=0x0){
1391 if (listQAThr->GetEntries() > 1){
1392 AliError(Form("More than one sources found for QAThresholds from detector %s, skipping",detName.Data()));
1395 else if (listQAThr->GetEntries()==1){
1396 AliInfo(Form("The following source produced files with the id QAThresholds for GRP, coming from detector %s:",detName.Data()));
1398 TObjString * str = dynamic_cast<TObjString*> (listQAThr->At(0));
1400 AliError(Form("Expecting a TObjString in the list for detector %s, but something else was found.",detName.Data()));
1404 AliInfo(Form("found source %s", str->String().Data()));
1405 TString fileNameRun = GetForeignFile(detName.Data(), kDQM, "QAThresholds", str->GetName());
1406 if (fileNameRun.Length()>0){
1407 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1408 TFile dqmFile(fileNameRun.Data(),"READ");
1409 if (dqmFile.IsOpen()) {
1410 AliQAThresholds* qaThr = dynamic_cast<AliQAThresholds*>(dqmFile.Get(detName.Data()));
1412 Int_t qaThrId = qaThr->GetDetectorId();
1413 if (qaThrId != idet){
1414 AliError(Form("Expecting QA threshold for detector %s, but found that for detector %s, skipping",detName.Data(), AliDAQ::OnlineName(qaThrId)));
1419 qaThrArray->AddAtAndExpand(qaThr, qaThrId);
1424 AliError(Form("No QAThresholds object found in the file for detector %s, skipping",detName.Data()));
1430 AliError(Form("Can't open QAThreshold file for detector %s, skipping",detName.Data()));
1436 AliWarning(Form("No file found for DQM QAThreshold for detector %s, skipping",detName.Data()));
1442 AliError(Form("No sources found for QAThresholds from detector %s, skipping",detName.Data()));
1448 AliWarning(Form("No list found for DQM QAThreshold for detector %s, skipping",detName.Data()));
1452 if (qaThrArray->GetEntries() > 0){
1454 md.SetResponsible("Barthélémy von Haller");
1455 md.SetComment("QA Threshold TObjArray");
1456 storeResultQAThr = Store("Calib", "QAThresholds", qaThrArray, &md, 0, kTRUE);
1459 Printf("No valid QAThresholds entries found, storing nothing in the OCDB");
1462 // return storeResult;
1463 return kTRUE; // temporary!!
1467 //_______________________________________________________________
1469 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
1471 //Getting the DAQ lb information
1473 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
1474 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
1475 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
1476 TString beamType = (TString)GetRunParameter("beamType");
1477 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
1478 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
1479 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
1480 TString runType = (TString)GetRunType();
1482 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!!!");
1484 UInt_t nparameter = 0;
1485 if (timeStart != 0){
1486 grpObj->SetTimeStart(timeStart);
1487 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
1491 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1495 grpObj->SetTimeEnd(timeEnd);
1496 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
1500 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1503 if (beamEnergy != 0){
1504 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1507 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1511 if (beamType.Length() != 0){
1512 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()));
1515 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1518 if (numberOfDetectors != 0){
1519 grpObj->SetNumberOfDetectors(numberOfDetectors);
1520 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1524 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1527 if (detectorMask != 0){
1528 grpObj->SetDetectorMask(detectorMask);
1529 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1533 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1536 if (lhcPeriod.Length() != 0) {
1537 grpObj->SetLHCPeriod(lhcPeriod);
1538 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1542 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1544 if (runType.Length() != 0) {
1545 grpObj->SetRunType(runType);
1546 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1550 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1555 //_______________________________________________________________
1557 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1559 //======DAQ FXS======//
1561 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1562 AliRawEventHeaderV3_11::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_11 - temporary fix
1563 AliRawEventHeaderV3_12::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_12 - temporary fix
1564 AliRawEventHeaderV3_13::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_13 - temporary fix
1565 Log("Processing DAQ FXS");
1566 TList* list = GetFileSources(kDAQ);
1568 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1572 if (list->GetEntries() == 0) {
1573 Log("no raw data tags in this run: nothing to merge!");
1574 delete list; list=0;
1578 TChain *fRawTagChain = new TChain("T");
1580 TIterator* iter = list->MakeIterator();
1582 while ((obj = iter->Next())) {
1583 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1585 Log(Form("Found source %s", objStr->String().Data()));
1586 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1588 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1589 delete fRawTagChain; fRawTagChain=0;
1592 Log(Form("Number of ids: %d",list2->GetEntries()));
1593 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1594 TObjString *idStr = (TObjString *)list2->At(i);
1595 if (idStr->String().CompareTo("QAThreshold") == 0 || idStr->String().CompareTo("TriggerClassesAndHistosToClone") == 0) {
1596 Log(Form("Skipping file with Id %s",idStr->String().Data()));
1599 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1600 if (fileName.Length() > 0) {
1601 Log(Form("Adding file in the chain: %s",fileName.Data()));
1602 fRawTagChain->Add(fileName.Data());
1605 Log(Form("Could not retrieve file with id %s from source %s: "
1606 "connection problems with DAQ FXS!",
1607 idStr->String().Data(), objStr->String().Data()));
1608 delete list; list=0;
1609 delete list2; list2=0;
1610 delete fRawTagChain; fRawTagChain=0;
1619 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!");
1624 delete fRawTagChain;
1629 TString fRawDataFileName = "GRP_Merged.tag.root";
1630 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1632 if (fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1633 Log(Form("Error merging %d raw data files!!!",nFiles));
1638 delete fRawTagChain;
1643 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1644 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1647 Log("Problem storing raw data tags in local file!!!");
1649 Log("Raw data tags merged successfully!!");
1656 delete fRawTagChain; fRawTagChain=0;
1658 if (result == kFALSE) {
1666 //_______________________________________________________________
1667 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1670 // processing the info
1671 // stored in the DCS FXS
1672 // coming from the trigger
1674 // Get the CTP counters information
1676 // Get the CTP aliases information
1678 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1679 Log("STANDALONE partition for current run, using Trigger Scalers and Trigger Aliases dummy values");
1681 AliCDBEntry *cdbEntryScalers = GetFromOCDB("CTP","DummyScalers");
1682 if (!cdbEntryScalers) {
1683 Log(Form("No dummy CTP scalers entry found, going into error..."));
1687 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntryScalers->GetObject();
1689 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1693 AliCDBMetaData metaData;
1694 metaData.SetResponsible("Roman Lietava");
1695 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1696 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1697 Log("Unable to store the dummy CTP scalers object to OCDB!");
1704 AliCDBEntry *cdbEntryAliases = GetFromOCDB("CTP","DummyAliases");
1705 if (!cdbEntryAliases) {
1706 Log(Form("No dummy CTP aliases entry found, going into error..."));
1710 THashList *aliases = dynamic_cast<THashList*>(cdbEntryAliases->GetObject());
1712 Log(Form("CTP dummy aliases not found in OCDB entry, going into error..."));
1716 AliCDBMetaData metaData;
1717 metaData.SetResponsible("Evgeny Kryshen");
1718 metaData.SetComment("CTP mapping of trigger classes to trigger aliases");
1719 if (!Store("CTP","Aliases", aliases, &metaData, 0, 0)) {
1720 Log("Unable to store the dummy CTP aliases object to OCDB!");
1728 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1729 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1730 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1731 if (countersfile.IsNull()) {
1732 Log("No CTP counters files has been found: empty source!");
1736 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1737 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1739 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1743 AliCDBMetaData metaData;
1744 metaData.SetBeamPeriod(0);
1745 metaData.SetResponsible("Roman Lietava");
1746 metaData.SetComment("CTP scalers");
1747 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1748 Log("Unable to store the CTP scalers object to OCDB!");
1758 TString aliasesFile = GetFile(kDCS, "CTP_aliases","");
1759 if (aliasesFile.IsNull()) {
1760 Log("No CTP aliases files has been found: empty source!");
1764 Log(Form("File with Id CTP_aliases found in DCS FXS! Copied to %s",aliasesFile.Data()));
1765 // We build the THashList of TNamed("triggerclass","comma_separated_list_of_corresponding_aliases")
1766 THashList* trClasses2Aliases = ProcessAliases(aliasesFile);
1767 if (!trClasses2Aliases) {
1768 Log("Bad CTP aliases file! The corresponding CDB entry will not be filled!");
1772 AliCDBMetaData metaData;
1773 metaData.SetBeamPeriod(0);
1774 metaData.SetResponsible("Evgeny Kryshen");
1775 metaData.SetComment("CTP mapping of trigger classes to trigger aliases");
1776 if (!Store("CTP","Aliases", trClasses2Aliases, &metaData, 0, 0)) {
1777 Log("Unable to store the CTP aliases object to OCDB!");
1778 delete trClasses2Aliases;
1782 delete trClasses2Aliases;
1788 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1796 //_______________________________________________________________
1797 THashList* AliGRPPreprocessor::ProcessAliases(const char* aliasesFile)
1801 // build the THashList of triggerclasses-to-triggeraliases from text file
1802 // each line of the file is supposed to be a string composed by
1803 // triggerclass+spaces+commaseparatedlistofcorrespondingaliases\n
1804 // it will add a TNamed("triggerclass","commaseparatedlistofcorrespondingaliases")
1808 if (gSystem->AccessPathName(aliasesFile)) {
1809 Printf("file (%s) not found", aliasesFile);
1813 ifstream *file = new ifstream(aliasesFile);
1815 Printf("Error opening file (%s) !",aliasesFile);
1821 THashList *hList = new THashList(10);
1822 hList->SetName("List of trigger classes to trigger aliases strings");
1825 while (strLine.ReadLine(*file)) {
1827 // safety for null lines, tabs instead of whitespaces, trailing carriage return, leading or trailing spaces/tabs
1828 if (strLine.IsNull()) continue;
1829 strLine.ReplaceAll('\t',' ');
1830 strLine.Remove(TString::kLeading,' ');
1831 strLine.Remove(TString::kTrailing,'\r');
1832 strLine.Remove(TString::kTrailing,' ');
1834 TObjArray* arr = strLine.Tokenize(' ');
1835 if(arr->GetEntries() != 2){
1836 Printf("The line:\n%s\nunexpectedly contains %d tokens, instead of two.",strLine.Data(),arr->GetEntries());
1839 TObjString *osTC = (TObjString*) arr->At(0);
1840 TObjString *osTAlist = (TObjString*) arr->At(1);
1841 TNamed *ctoa = new TNamed(osTC->GetName(),osTAlist->GetName());
1852 //_______________________________________________________________
1853 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1857 // processing DCS DPs
1860 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1861 Int_t nL3Entries = 0;
1862 Int_t nDipoleEntries = 0;
1863 Int_t nEnvEntries = 0;
1864 Int_t nHallProbesEntries = 0;
1865 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1866 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1867 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1868 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1869 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1870 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1871 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1876 //_______________________________________________________________
1878 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1885 Int_t nL3Entries = 0;
1887 TObjArray *array = 0x0;
1889 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1891 AliInfo(Form("==========L3Current==========="));
1892 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1893 indexDP = kL3Current;
1894 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1896 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1899 if (array->GetEntries() == 0){
1900 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1903 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1904 if (floatDCS != NULL){
1905 grpObj->SetL3Current(floatDCS);
1917 ffailedDPs->RemoveAt(indexDP);
1921 if (array) array = 0x0;
1923 AliInfo(Form("==========L3Polarity==========="));
1924 indexDP = kL3Polarity;
1925 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1927 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1930 if (array->GetEntries() == 0){
1931 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1934 Bool_t change = kFALSE;
1935 Char_t charDCS = ProcessBool(array,change);
1936 if (change == kFALSE){
1937 grpObj->SetL3Polarity(charDCS);
1938 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1939 ffailedDPs->RemoveAt(indexDP);
1943 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1944 ffailedDPs->RemoveAt(indexDP);
1948 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]));
1956 //_______________________________________________________________
1958 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1964 Int_t nDipoleEntries = 0;
1965 TObjArray *array = 0x0;
1967 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1969 AliInfo(Form("==========DipoleCurrent==========="));
1970 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1971 indexDP = kDipoleCurrent;
1972 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1974 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1977 if (array->GetEntries() == 0){
1978 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1981 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1982 if (floatDCS != NULL){
1983 grpObj->SetDipoleCurrent(floatDCS);
1995 ffailedDPs->RemoveAt(indexDP);
1999 if (array) array = 0x0;
2001 AliInfo(Form("==========DipolePolarity==========="));
2002 indexDP = kDipolePolarity;
2003 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
2005 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
2008 if (array->GetEntries() == 0){
2009 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
2012 Bool_t change = kFALSE;
2013 Char_t charDCS = ProcessBool(array,change);
2015 grpObj->SetDipolePolarity(charDCS);
2016 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
2017 ffailedDPs->RemoveAt(indexDP);
2021 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
2022 ffailedDPs->RemoveAt(indexDP);
2026 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]));
2031 return nDipoleEntries;
2034 //_______________________________________________________________
2036 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
2040 // evironment conditions (temperature, pressure) info
2042 Int_t nEnvEntries = 0;
2043 TObjArray *array = 0x0;
2046 AliInfo(Form("==========CavernTemperature==========="));
2047 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
2048 indexDP = kCavernTemperature;
2049 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
2051 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
2054 if (array->GetEntries() == 0){
2055 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
2058 Float_t *floatDCS = ProcessFloatAll(array);
2059 if (floatDCS != NULL){
2060 grpObj->SetCavernTemperature(floatDCS);
2071 ffailedDPs->RemoveAt(indexDP);
2076 if (array) array = 0x0;
2078 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
2079 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
2080 //dcsSensorArray->Print();
2081 if( fPressure->NumFits()<kNumSensors ) {
2082 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
2084 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
2086 AliInfo(Form("==========CavernAtmosPressure==========="));
2087 indexDP = kCavernAtmosPressure;
2088 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
2089 TGraph* graph = sensorCavernP2->GetGraph();
2090 AliDebug(3,Form("index = %d",indexDP));
2091 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
2092 AliDebug(2,Form("graph = %p",graph));
2093 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
2094 if(sensorCavernP2->GetFit() || graph) {
2095 if (sensorCavernP2->GetFit()){
2096 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
2099 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
2101 grpObj->SetCavernAtmosPressure(sensorCavernP2);
2102 ffailedDPs->RemoveAt(indexDP);
2105 //if (sensorP2) delete sensorP2;
2107 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] ));
2110 AliInfo(Form("==========SurfaceAtmosPressure==========="));
2111 indexDP = kSurfaceAtmosPressure;
2112 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
2113 graph = sensorP2->GetGraph();
2114 AliDebug(3,Form("index = %d",indexDP));
2115 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
2116 AliDebug(2,Form("graph = %p",graph));
2117 AliDebug(3,Form("sensorP2 = %p", sensorP2));
2118 if(sensorP2->GetFit() || graph) {
2119 if (sensorP2->GetFit()){
2120 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
2123 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
2125 grpObj->SetSurfaceAtmosPressure(sensorP2);
2126 ffailedDPs->RemoveAt(indexDP);
2129 //if (sensorP2) delete sensorP2;
2131 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] ));
2134 AliInfo(Form("==========CavernAtmosPressure2==========="));
2135 indexDP = kCavernAtmosPressure2;
2136 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
2137 graph = sensorCavernP22->GetGraph();
2138 AliDebug(3,Form("index = %d",indexDP));
2139 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
2140 AliDebug(2,Form("graph = %p",graph));
2141 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
2142 if(sensorCavernP22->GetFit() || graph) {
2143 if (sensorCavernP22->GetFit()){
2144 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
2147 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
2149 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
2150 ffailedDPs->RemoveAt(indexDP);
2153 //if (sensorP2) delete sensorP2;
2155 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] ));
2161 //_______________________________________________________________
2163 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
2169 Int_t nHPEntries = 0;
2170 TObjArray *array = 0x0;
2172 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
2174 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
2175 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()));
2177 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
2178 outOfRange = kFALSE; // resetting outOfRange flag at each HP
2179 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
2180 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
2182 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
2185 if (array->GetEntries() == 0){
2186 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
2189 Float_t *floatDCS = ProcessFloatAll(array);
2190 if (floatDCS != NULL){
2191 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]));
2192 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
2193 for (Int_t kk = 0 ; kk< 5; kk++){
2194 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
2206 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
2212 Log(Form("Hall Probes = %d ", nHPEntries));
2216 //_________________________________________________________________________
2218 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
2222 // returning Spline Fit
2225 Int_t entriesarray = array->GetEntries();
2226 Float_t* value = new Float_t[entriesarray];
2227 Float_t* time = new Float_t[entriesarray];
2228 AliDCSValue* v = 0x0;
2229 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
2230 v = (AliDCSValue*)array->At(iarray);
2231 value[iarray] = v->GetFloat();
2232 time[iarray] = v->GetTimeStamp();
2233 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
2235 TGraph* gr = new TGraph(entriesarray,value,time);
2237 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
2240 AliSplineFit *fit = new AliSplineFit();
2241 fit->SetMinPoints(10);
2242 fit->InitKnots(gr,10,10,0.0);
2248 //_________________________________________________________________________
2250 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
2257 TString aDCSString="";
2259 AliDCSValue *v = 0x0;
2260 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2261 v = (AliDCSValue *)array->At(iCount);
2262 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
2263 AliError(Form("DCS values for the parameter outside the queried interval"));
2267 if (aDCSString != v->GetChar())
2268 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
2270 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
2275 //__________________________________________________________________________________________________________________
2277 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
2280 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2282 // parameters[0] = mean
2283 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2284 // parameters[2] = median
2285 // parameters[3] = standard deviation wrt mean
2286 // parameters[4] = standard deviation wrt median
2289 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2290 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2291 if (timeStartString.IsNull() || timeStartString.IsNull()){
2292 if (timeStartString.IsNull()){
2293 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2295 else if (timeStartString.IsNull()){
2296 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2298 fdaqStartEndTimeOk = kFALSE;
2302 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2303 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2304 Float_t* parameters = new Float_t[5];
2306 Int_t iCountsRun = 0;
2307 Int_t nCounts = array->GetEntries();
2308 Float_t valueBeforeSOR = 0;
2309 Float_t valueAfterEOR = 0;
2310 Int_t timestampBeforeSOR = -1;
2311 Int_t timestampAfterEOR = -1;
2312 Int_t ientrySOR = -1;
2313 Int_t ientryEOR = -1;
2314 Float_t* arrayValues = 0x0;
2315 Double_t* arrayWeights = 0x0;
2316 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
2317 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
2319 for(Int_t i = 0; i < nCounts; i++) {
2320 AliDCSValue *v = (AliDCSValue *)array->At(i);
2321 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2322 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2323 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2324 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
2325 delete [] parameters;
2328 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2329 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
2331 // look for the last value before SOR and the first value before EOR
2332 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2333 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2334 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2335 valueBeforeSOR = v->GetFloat();
2337 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2338 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2339 valueAfterEOR = v->GetFloat();
2340 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2342 // check if there are DPs between DAQ_time_start and DAQ_time_end
2343 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2344 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2345 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2346 AliDebug(2,Form("entry between SOR and EOR"));
2351 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2355 if (timestampBeforeSOR == -1){
2356 AliWarning("No value found before SOR");
2358 if (timestampAfterEOR == -1){
2359 AliWarning("No value found after EOR");
2362 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
2363 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2364 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2365 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2366 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2367 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2369 Int_t nentriesUsed = 0;
2370 if (iCountsRun > 1){
2371 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2372 AliDebug(2,"Calculating (weighted) Mean and Median");
2373 arrayValues = new Float_t[iCountsRun];
2374 arrayWeights = new Double_t[iCountsRun];
2375 nentriesUsed = iCountsRun;
2376 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2377 AliDCSValue *v = (AliDCSValue *)array->At(i);
2378 Int_t timestamp2 = 0;
2380 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2381 timestamp2 = (Int_t)v1->GetTimeStamp();
2384 timestamp2 = timeEnd+1;
2386 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2387 arrayValues[i-ientrySOR] = v->GetFloat();
2389 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2390 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
2392 else if (iCountsRun == 1){
2393 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2395 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2396 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.");
2397 arrayValues = new Float_t[2];
2398 arrayWeights = new Double_t[2];
2399 arrayValues[0] = valueBeforeSOR;
2400 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2401 arrayValues[1] = v->GetFloat();
2402 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2403 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2404 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2405 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
2406 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
2407 truncMeanFlag = kFALSE;
2410 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");
2411 parameters[0] = AliGRPObject::GetInvalidFloat();
2412 parameters[1] = AliGRPObject::GetInvalidFloat();
2413 parameters[2] = AliGRPObject::GetInvalidFloat();
2414 parameters[3] = AliGRPObject::GetInvalidFloat();
2415 parameters[4] = AliGRPObject::GetInvalidFloat();
2419 else { // iCountsRun == 0, using only the point immediately before SOR
2420 if (timestampBeforeSOR == -1){
2421 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");
2422 parameters[0] = AliGRPObject::GetInvalidFloat();
2423 parameters[1] = AliGRPObject::GetInvalidFloat();
2424 parameters[2] = AliGRPObject::GetInvalidFloat();
2425 parameters[3] = AliGRPObject::GetInvalidFloat();
2426 parameters[4] = AliGRPObject::GetInvalidFloat();
2430 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
2431 AliDebug(2,Form("value = %f",valueBeforeSOR));
2432 parameters[0] = valueBeforeSOR;
2433 parameters[2] = valueBeforeSOR;
2434 truncMeanFlag = kFALSE;
2441 Float_t sumweights = 0;
2442 Int_t entriesTruncMean = 0;
2443 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
2444 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2446 // calculating SD wrt Mean and Median
2447 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
2449 for (Int_t i =0; i< nentriesUsed; i++){
2450 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2451 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2452 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2453 sumweights += arrayWeights[i];
2455 // setting SD wrt Mean
2456 if (sumweights != 0 ){
2457 parameters[3] = TMath::Sqrt(temp1/sumweights);
2460 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
2461 parameters[3] = AliGRPObject::GetInvalidFloat();
2463 // setting SD wrt Median
2464 if (nentriesUsed != 0){
2465 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2468 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
2469 parameters[4] = AliGRPObject::GetInvalidFloat();
2473 parameters[3] = AliGRPObject::GetInvalidFloat();
2474 parameters[4] = AliGRPObject::GetInvalidFloat();
2477 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2479 AliDebug(2,"Calculating Truncated Mean");
2480 for (Int_t i =0; i< nentriesUsed; i++){
2481 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2482 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2483 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2484 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2485 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
2489 AliDebug(2,"Discarding entry");
2492 // setting truncated mean
2493 if (entriesTruncMean >1){
2494 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
2495 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2498 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
2499 parameters[1] = AliGRPObject::GetInvalidFloat();
2503 parameters[1] = AliGRPObject::GetInvalidFloat();
2507 delete [] arrayValues;
2510 delete [] arrayWeights;
2512 delete [] arrayValuesTruncMean;
2513 delete [] arrayWeightsTruncMean;
2515 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
2516 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
2517 AliInfo(Form("median = %f ",parameters[2]));
2518 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
2519 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
2524 //__________________________________________________________________________________________________________________
2526 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
2529 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2530 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
2531 // the flag is set according to the L3/Dipole current value
2532 // current threshold for L3 = 350 A (value provided by DCS)
2533 // current threshold for Dipole = 450 A (value provided by DCS)
2535 // parameters[0] = mean
2536 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2537 // parameters[2] = median
2538 // parameters[3] = standard deviation wrt mean
2539 // parameters[4] = standard deviation wrt median
2542 AliInfo(Form("indexDP = %d",indexDP));
2544 Int_t nCounts = array->GetEntries();
2545 for(Int_t i = 0; i < nCounts; i++) {
2546 AliDCSValue *v = (AliDCSValue *)array->At(i);
2547 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2548 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2549 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2550 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
2553 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2554 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
2555 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2556 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
2559 AliError(Form("DCS values for the parameter outside the queried interval"));
2563 return ProcessFloatAll(array);
2567 //_______________________________________________________________
2569 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
2572 // processing Boolean values
2575 Bool_t aDCSBool = kTRUE;
2577 AliDCSValue *v = 0x0;
2579 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2580 v = (AliDCSValue *)array->At(iCount);
2581 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
2582 AliError(Form("DCS values for the parameter outside the queried interval"));
2586 if (aDCSBool != v->GetBool()) {
2587 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2591 aDCSBool = v->GetBool(); // always keeping last value
2592 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
2595 Char_t caDCSBool = (Char_t) aDCSBool;
2600 //_______________________________________________________________
2602 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
2605 // processing Int values, returning mean
2606 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2607 // are outside the queried time interval or their value is out of range
2610 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2611 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2612 if (timeStartString.IsNull() || timeStartString.IsNull()){
2613 if (timeStartString.IsNull()){
2614 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2616 else if (timeStartString.IsNull()){
2617 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2622 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2623 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2624 Float_t aDCSArrayMean = 0.0;
2626 Float_t valueBeforeSOR = 0;
2627 Float_t valueAfterEOR = 0;
2628 Int_t timestampBeforeSOR = -1;
2629 Int_t timestampAfterEOR = -1;
2630 Int_t ientrySOR = -1;
2631 Int_t ientryEOR = -1;
2632 Float_t* arrayValues = 0x0;
2633 Double_t* arrayWeights = 0x0;
2634 Int_t iCountsRun = 0;
2635 Int_t nCounts = array->GetEntries();
2637 for(Int_t i = 0; i < nCounts; i++) {
2638 AliDCSValue* v = (AliDCSValue *)array->At(i);
2639 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
2640 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
2641 return AliGRPObject::GetInvalidFloat();
2643 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2644 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
2646 // look for the last value before SOR and the first value before EOR
2647 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2648 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2649 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2650 valueBeforeSOR = (Float_t) v->GetInt();
2652 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2653 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2654 valueAfterEOR = (Float_t) v->GetInt();
2655 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2657 // check if there are DPs between DAQ_time_start and DAQ_time_end
2658 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2659 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2660 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2661 AliDebug(2,Form("entry between SOR and EOR"));
2666 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2670 if (timestampBeforeSOR == -1){
2671 AliWarning("No value found before SOR!");
2673 if (timestampAfterEOR == -1){
2674 AliWarning("No value found after EOR!");
2677 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2678 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2679 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2680 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2681 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2682 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2684 Int_t nentriesUsed = 0;
2685 if (iCountsRun > 1){
2686 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2687 AliDebug(2,"Calculating (weighted) Mean");
2688 arrayValues = new Float_t[iCountsRun];
2689 arrayWeights = new Double_t[iCountsRun];
2690 nentriesUsed = iCountsRun;
2691 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2692 AliDCSValue *v = (AliDCSValue *)array->At(i);
2693 Int_t timestamp2 = 0;
2695 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2696 timestamp2 = (Int_t)v1->GetTimeStamp();
2699 timestamp2 = timeEnd+1;
2701 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2702 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2704 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2705 delete [] arrayValues;
2706 delete [] arrayWeights;
2708 else if (iCountsRun == 1){
2709 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2711 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2712 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2713 arrayValues = new Float_t[2];
2714 arrayWeights = new Double_t[2];
2715 arrayValues[0] = valueBeforeSOR;
2716 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2717 arrayValues[1] = (Float_t)v->GetInt();
2718 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2719 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2720 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2721 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2722 delete [] arrayValues;
2723 delete [] arrayWeights;
2726 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2727 return AliGRPObject::GetInvalidFloat();
2730 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2731 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2732 if (timestampBeforeSOR == -1){
2733 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2735 if (timestampAfterEOR == -1){
2736 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2738 return AliGRPObject::GetInvalidFloat();
2741 AliWarning("Using last entry before SOR and first entry after EOR.");
2743 arrayValues = new Float_t[2];
2744 arrayWeights = new Double_t[2];
2745 arrayValues[0] = valueBeforeSOR;
2746 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2747 arrayValues[1] = valueAfterEOR;
2748 arrayWeights[1] = 1.;
2749 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2750 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2751 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2752 delete [] arrayValues;
2753 delete [] arrayWeights;
2757 AliInfo(Form("mean = %f ", aDCSArrayMean));
2758 return aDCSArrayMean;
2761 //_______________________________________________________________
2763 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2766 // processing Int values, returning mean
2767 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2768 // are outside the queried time interval or their value is out of range
2771 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2772 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2773 if (timeStartString.IsNull() || timeStartString.IsNull()){
2774 if (timeStartString.IsNull()){
2775 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2777 else if (timeStartString.IsNull()){
2778 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2783 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2784 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2785 Float_t aDCSArrayMean = 0.0;
2787 Float_t valueBeforeSOR = 0;
2788 Float_t valueAfterEOR = 0;
2789 Int_t timestampBeforeSOR = -1;
2790 Int_t timestampAfterEOR = -1;
2791 Int_t ientrySOR = -1;
2792 Int_t ientryEOR = -1;
2793 Float_t* arrayValues = 0x0;
2794 Double_t* arrayWeights = 0x0;
2795 Int_t iCountsRun = 0;
2796 Int_t nCounts = array->GetEntries();
2798 for(Int_t i = 0; i < nCounts; i++) {
2799 AliDCSValue* v = (AliDCSValue *)array->At(i);
2800 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2801 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2802 return AliGRPObject::GetInvalidFloat();
2804 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2805 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2807 // look for the last value before SOR and the first value before EOR
2808 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2809 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2810 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2811 valueBeforeSOR = (Float_t)v->GetUInt();
2813 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2814 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2815 valueAfterEOR = (Float_t)v->GetUInt();
2816 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2818 // check if there are DPs between DAQ_time_start and DAQ_time_end
2819 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2820 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2821 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2822 AliDebug(2,Form("entry between SOR and EOR"));
2827 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2831 if (timestampBeforeSOR == -1){
2832 AliWarning("No value found before SOR!");
2834 if (timestampAfterEOR == -1){
2835 AliWarning("No value found after EOR!");
2838 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2839 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2840 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2841 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2842 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2843 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2845 Int_t nentriesUsed = 0;
2846 if (iCountsRun > 1){
2847 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2848 AliDebug(2,"Calculating (weighted) Mean");
2849 arrayValues = new Float_t[iCountsRun];
2850 arrayWeights = new Double_t[iCountsRun];
2851 nentriesUsed = iCountsRun;
2852 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2853 AliDCSValue *v = (AliDCSValue *)array->At(i);
2854 Int_t timestamp2 = 0;
2856 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2857 timestamp2 = (Int_t)v1->GetTimeStamp();
2860 timestamp2 = timeEnd+1;
2862 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2863 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2865 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2866 delete [] arrayValues;
2867 delete [] arrayWeights;
2869 else if (iCountsRun == 1){
2870 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2872 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2873 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2874 arrayValues = new Float_t[2];
2875 arrayWeights = new Double_t[2];
2876 arrayValues[0] = valueBeforeSOR;
2877 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2878 arrayValues[1] = (Float_t)v->GetUInt();
2879 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2880 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2881 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2882 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2883 delete [] arrayValues;
2884 delete [] arrayWeights;
2887 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2888 return AliGRPObject::GetInvalidFloat();
2891 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2892 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2893 if (timestampBeforeSOR == -1){
2894 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2896 if (timestampAfterEOR == -1){
2897 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2899 return AliGRPObject::GetInvalidFloat();
2902 AliWarning("Using last entry before SOR and first entry after EOR.");
2904 arrayValues = new Float_t[2];
2905 arrayWeights = new Double_t[2];
2906 arrayValues[0] = valueBeforeSOR;
2907 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2908 arrayValues[1] = valueAfterEOR;
2909 arrayWeights[1] = 1.;
2910 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2911 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2912 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2913 delete [] arrayValues;
2914 delete [] arrayWeights;
2918 AliInfo(Form("mean = %f ",aDCSArrayMean));
2919 return aDCSArrayMean;
2924 //_______________________________________________________________
2926 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2928 // extract DCS pressure maps. Perform fits to save space
2930 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2932 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2933 fPressure->MakeSplineFit(map);
2934 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2935 if (fitFraction > kFitFraction ) {
2936 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2938 AliInfo("Too few pressure maps fitted!!!");
2941 AliInfo("no atmospheric pressure map extracted!!!");
2950 //_______________________________________________________________
2951 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)
2954 // Retrieves logbook and trigger information from the online logbook
2955 // This information is needed for prompt reconstruction
2959 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2963 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2964 // 0 on success and no run was found
2965 // negative on error
2967 // This function is NOT called during the preprocessor run in the Shuttle!
2975 AliCDBManager* cdb = AliCDBManager::Instance();
2976 cdb->SetDefaultStorage(cdbRoot);
2979 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2983 Printf("ERROR: Could not connect to DAQ LB");
2989 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
2990 TSQLResult* result = server->Query(sqlQuery);
2993 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2997 if (result->GetRowCount() == 0)
2999 Printf("ERROR: Run %d not found", run);
3004 TSQLRow* row = result->Next();
3007 Printf("ERROR: Could not receive data from run %d", run);
3012 TString timeStartString(row->GetField(0));
3013 TString runType(row->GetField(1));
3014 TString detectorMaskString(row->GetField(2));
3015 TString l3CurrentString(row->GetField(3));
3016 TString dipoleCurrentString(row->GetField(4));
3017 TString beamTypeString(row->GetField(5));
3018 time_t timeStart = (time_t)(timeStartString.Atoi());
3019 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
3020 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
3021 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
3022 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
3023 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
3024 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
3025 beamTypeString="A-A";
3028 AliGRPObject * grpObj = new AliGRPObject();
3029 grpObj->SetTimeStart(timeStart);
3030 grpObj->SetRunType((TString)(row->GetField(1)));
3031 grpObj->SetDetectorMask(detectorMask);
3032 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
3033 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
3034 grpObj->SetL3Polarity(l3Polarity);
3035 grpObj->SetDipolePolarity(dipolePolarity);
3036 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
3037 grpObj->SetBeamType(beamTypeString);
3045 Printf("Storing GRP/GRP/Data object with the following content");
3048 AliCDBMetaData metadata;
3049 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
3050 metadata.SetComment("GRP Output parameters received during online running");
3052 AliCDBId id("GRP/GRP/Data", run, run);
3053 Bool_t success = cdb->Put(grpObj, id, &metadata);
3059 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
3063 // Receive trigger information
3064 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
3065 result = server->Query(sqlQuery);
3068 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3072 if (result->GetRowCount() == 0)
3074 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
3079 row = result->Next();
3082 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
3087 TString triggerConfig(row->GetField(0));
3095 Printf("Found trigger configuration: %s", triggerConfig.Data());
3097 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
3100 Printf("ERROR: Could not create CTP configuration object");
3104 metadata.SetComment("CTP run configuration received during online running");
3106 AliCDBId id2("GRP/CTP/Config", run, run);
3107 success = cdb->Put(runcfg, id2, &metadata);
3114 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
3119 // Receive list of GDCs for this run
3120 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
3121 result = server->Query(sqlQuery);
3124 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3128 if (result->GetRowCount() == 0)
3130 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
3136 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
3137 row = result->Next();
3140 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
3144 gdc += row->GetField(0);
3154 Printf("Found GDC: %s", gdc.Data());
3156 // get last run with same run type that was already processed by the SHUTTLE
3158 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());
3159 result = server->Query(sqlQuery);
3162 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
3166 if (result->GetRowCount() == 0)
3168 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
3173 row = result->Next();
3176 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
3181 TString lastRunStr(row->GetField(0));
3182 Int_t lastRun = lastRunStr.Atoi();
3184 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
3198 //------------------------------------------------------------------------------------------------------
3199 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
3202 // Method to processo LHC Energy information
3203 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
3206 Int_t nCounts = array->GetEntries();
3207 Float_t energy = -1;
3208 Double_t timeEnergy = -1;
3209 Int_t indexEnergy = -1;
3210 Bool_t foundEnergy = kFALSE;
3212 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
3214 AliWarning("No Energy values found! Beam Energy remaining invalid!");
3217 for (Int_t i = 0; i < nCounts; i++){
3218 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
3220 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
3221 timeEnergy = dcs->GetTimeStamp();
3223 foundEnergy = kTRUE;
3231 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
3234 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
3235 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
3236 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
3242 //------------------------------------------------------------------------------------------------------
3243 AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
3246 // Method to process LHC-Clock Phase data
3247 // Only the values between DAQ_time_start and DAQ_time_end are kept
3249 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
3251 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
3252 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
3254 TString timeCreatedStr = GetRunParameter("time_created");
3255 Double_t timeCreated = timeCreatedStr.Atof();
3257 Int_t nCounts = beam1phase->GetEntries();
3258 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
3260 AliWarning("No beam1 LHC clock phase values found!");
3265 Double_t prevPhase = 0;
3266 for (Int_t i = 0; i < nCounts; i++){
3267 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
3269 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
3270 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
3271 if ((i == 0) || (i == (nCounts-1)) ||
3273 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3274 prevPhase = dcs->GetDouble(0);
3275 foundBeam1Phase = kTRUE;
3276 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
3277 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3278 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3283 if (!foundBeam1Phase){
3284 AliError("No beam1 LHC clock phase values found within the run!");
3290 nCounts = beam2phase->GetEntries();
3291 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
3293 AliWarning("No beam2 LHC clock phase values found!");
3298 Double_t prevPhase = 0;
3299 for (Int_t i = 0; i < nCounts; i++){
3300 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
3302 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
3303 if ((i == 0) || (i == (nCounts-1)) ||
3305 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
3306 prevPhase = dcs->GetDouble(0);
3307 foundBeam2Phase = kTRUE;
3308 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
3309 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
3310 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
3315 if (!foundBeam2Phase){
3316 AliError("No beam2 LHC clock phase values found within the run!");
3324 //------------------------------------------------------------------------------------------------------
3325 TString AliGRPPreprocessor::ParseBeamTypeString(TString beamType, Int_t iBeamType)
3327 // Method to return the convention for the separate beam type
3328 // in the form A*1000+Z
3329 // e.g.: Pb82 --> 208000 + 82 = 208082
3330 // p --> 1000 + 1 = 1001
3334 TString separateString("");
3335 Log(Form("Setting Beam Type for beam %d to A*1000+Z",iBeamType));
3336 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
3337 Log(Form("Beam type %d is PROTON --> The single beam type will be set to 1001 (A = 1, Z = 1)",iBeamType));
3338 separateString = "1001";
3339 return separateString;
3342 TPRegexp regexpA("\\D+");
3343 TPRegexp regexpZ("\\d+");
3344 TObjArray* arrayA = regexpA.MatchS(beamType);
3345 TObjArray* arrayZ = regexpZ.MatchS(beamType);
3346 if (arrayA->GetEntries() != 1 || arrayZ->GetEntries() != 1){
3347 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()));
3351 TString strA = ((TObjString*)(arrayA->At(0)))->String();
3352 TString strZ = ((TObjString*)(arrayZ->At(0)))->String();
3353 if (strA.CompareTo("LEAD",TString::kIgnoreCase) == 0 || strA.CompareTo("PB",TString::kIgnoreCase) == 0){
3354 Log(Form("Beam %d is %s --> A = 208",iBeamType, strA.Data()));
3358 Log(Form("This beam was not foreseen so far, leaving A=0"));
3361 Log(Form("Beam %d has Z = %d",iBeamType, z));
3362 separateString = Form("%d",a*1000+z);
3363 return separateString;
3367 return separateString;