1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Class AliGRPPreprocessor
20 // Global Run Parameters (GRP) preprocessor
21 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 // Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN
23 // Modified: Chiara.Zampolli@cern.ch CERN
24 //-------------------------------------------------------------------------
29 #include <TObjString.h>
30 #include <TObjArray.h>
37 #include "AliGRPPreprocessor.h"
38 #include "AliGRPObject.h"
39 #include "AliDCSSensor.h"
40 #include "AliSplineFit.h"
41 #include "AliDCSSensorArray.h"
42 #include "AliRawEventHeaderVersions.h"
44 #include "AliTriggerConfiguration.h"
45 #include "AliTriggerRunScalers.h"
46 #include "AliTriggerInput.h"
48 #include "AliCDBMetaData.h"
49 #include "AliESDVertex.h"
50 #include "AliLHCReader.h"
51 #include "AliLHCData.h"
52 #include "AliDCSArray.h"
54 #include "AliLTUConfig.h"
58 class AliShuttleInterface;
60 // needed for ReceivePromptRecoParameters
62 #include <TSQLServer.h>
63 #include <TSQLResult.h>
65 #include <AliCDBManager.h>
66 #include <AliCDBMetaData.h>
68 #include "AliCTPTimeParams.h"
69 #include "AliLHCClockPhase.h"
71 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
73 ClassImp(AliGRPPreprocessor)
75 //_______________________________________________________________
77 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 6; // num parameters in the logbook used to fill the GRP object
78 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
79 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
80 const Int_t AliGRPPreprocessor::fgknLHCDP = 8; // number of dcs dps from LHC data
81 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
82 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
83 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
91 "L3_BSF17_Temperature",
95 "L3_BSF4_Temperature",
99 "L3_BKF17_Temperature",
103 "L3_BKF4_Temperature",
107 "L3_BSF13_Temperature",
111 "L3_BSF8_Temperature",
115 "L3_BKF13_Temperature",
119 "L3_BKF8_Temperature",
123 "Dipole_Inside_Temperature",
127 "Dipole_Outside_Temperature",
129 "CavernAtmosPressure",
130 "SurfaceAtmosPressure",
131 "CavernAtmosPressure2"
134 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
138 "L3_BSF17_Temperature",
142 "L3_BSF4_Temperature",
146 "L3_BKF17_Temperature",
150 "L3_BKF4_Temperature",
154 "L3_BSF13_Temperature",
158 "L3_BSF8_Temperature",
162 "L3_BKF13_Temperature",
166 "L3_BKF8_Temperature",
170 "Dipole_Inside_Temperature",
174 "Dipole_Outside_Temperature"
177 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
178 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
181 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
185 "LHC_Beams_Particle_Type",
186 "BPTX_Phase_Shift_B1",
187 "BPTX_Phase_Shift_B2",
188 "LHC_Particle_Type_B1",
189 "LHC_Particle_Type_B2"
192 const char* kppError[] = {
194 "(DAQ logbook ERROR)",
196 "(Trigger Scalers not found in DCS FXS - ERROR)",
197 "(DCS data points ERROR)",
198 "(Trigger Configuration ERROR)",
199 "(DAQ logbook ERROR determining partition of the run)",
200 "(CTP timing ERROR)",
201 "(SPD Mean Vertex ERROR)",
202 "(DCS FXS Error for LHC Data)",
204 "(LHC Clock Phase Error (from LHC Data))",
205 "(LTU Configuration Error)"
208 //_______________________________________________________________
210 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
211 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))
213 // constructor - shuttle must be instantiated!
215 AddRunType("COSMIC");
217 AddRunType("PHYSICS");
218 AddRunType("CALIBRATION_BC");
219 AddRunType("CALIBRATION_CENTRAL");
220 AddRunType("CALIBRATION_EMD");
221 AddRunType("CALIBRATION_MB");
222 AddRunType("CALIBRATION_SEMICENTRAL");
223 AddRunType("CALIBRATION");
224 AddRunType("PEDESTAL");
225 AddRunType("STANDALONE");
228 AddRunType("PULSER");
229 AddRunType("STANDALONE_PULSER");
230 AddRunType("STANDALONE_BC");
233 fminFloat = -FLT_MAX;
234 fmaxDouble = DBL_MAX;
235 fminDouble = -DBL_MAX;
241 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
242 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
243 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
244 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
245 AliInfo(Form("Max allowed integer = %d",fmaxInt));
246 AliInfo(Form("Min allowed integer = %d",fminInt));
247 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
248 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
250 ffailedDPs->SetOwner(kTRUE);
253 //_______________________________________________________________
255 AliGRPPreprocessor::~AliGRPPreprocessor()
264 //_______________________________________________________________
266 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
268 // Initialize preprocessor
270 AliPreprocessor::Initialize(run, startTime, endTime);
272 AliInfo("Initialization of the GRP preprocessor.");
273 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
274 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
275 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
276 for(Int_t j = 0; j < kNumSensors; j++) {
277 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
278 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
280 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
282 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
284 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
285 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
286 ffailedDPs->AddAt(dp,iDP);
291 //_______________________________________________________________
293 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
295 // process data retrieved by the Shuttle
297 // retrieving "partition" and "detector" fields from DAQ logbook to
298 // determine the partition in which the run was taken
299 // the partition is used to decide how to react in case of errors for CTP
301 TString partition = (TString)GetRunParameter("partition");
302 TString detector = (TString)GetRunParameter("detector");
304 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
305 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
307 //=================//
309 //=================//
311 Log("*************** Processing DAQ logbook");
315 Int_t iDaqLB = ProcessDaqLB(grpobj);
316 TString runType = (TString)GetRunType();
317 TString beamType = (TString)GetRunParameter("beamType");
318 if(iDaqLB == fgknDAQLbPar) {
319 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
321 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
325 //=================//
327 //=================//
329 Log("*************** Processing DAQ FXS");
331 UInt_t iDaqFxs = ProcessDaqFxs();
333 Log(Form("DAQ FXS, successful!"));
335 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
339 //=================//
341 //=================//
343 Log("*************** Processing DCS FXS");
345 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
347 Log(Form("DCS FXS, successful!"));
348 } else if (iDcsFxs ==1) {
349 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
352 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
356 //=================//
357 // DCS data points //
358 //=================//
360 Log("*************** Processing DCS DPs");
362 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
363 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
364 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
365 if (fdaqStartEndTimeOk){
366 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
367 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
368 Log(Form("The DPs giving problems were:"));
369 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
370 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
372 TString name = dpString->String();
373 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
374 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
377 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()));
383 else Log(Form("DCS data points, successful!"));
385 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"));
387 //=======================//
388 // Trigger Configuration //
389 //=======================//
391 Log("*************** Processing Trigger Configuration");
393 const char * triggerConf = GetTriggerConfiguration();
395 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
396 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
397 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
399 Log(Form("No dummy CTP configuration entry found, going into error..."));
403 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
405 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
409 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
410 runcfg->SetTitle(titleCTPcfg);
411 AliCDBMetaData metaData;
412 metaData.SetResponsible("Roman Lietava");
413 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
414 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
415 Log("Unable to store the dummy CTP run configuration object to OCDB!");
422 else if (!partition.IsNull() && detector.IsNull()){ // global partition
423 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
424 if (triggerConf!= NULL) {
425 Log("Found trigger configuration in DAQ logbook");
426 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
428 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
432 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
433 runcfg->SetTitle(titleCTPcfg);
434 AliCDBMetaData metaData;
435 metaData.SetBeamPeriod(0);
436 metaData.SetResponsible("Roman Lietava");
437 metaData.SetComment("CTP run configuration from DAQ logbook");
438 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
439 Log("Unable to store the CTP run configuration object to OCDB!");
446 Log("Trigger configuration NULL in DAQ logbook");
452 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
456 //===========================//
457 // Trigger Timing Parameters //
458 //===========================//
460 Log("*************** Processing Trigger Time Params");
462 const char * triggerCTPtiming = GetCTPTimeParams();
464 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
465 Log("STANDALONE partition for current run, using CTP timing params dummy value");
466 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
468 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
472 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
474 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
478 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
479 runCTPtiming->SetTitle(titleCTPtiming);
480 AliCDBMetaData metadata;
481 metadata.SetResponsible("Roman Lietava");
482 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
483 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
484 Log("Unable to store the dummy CTP timing params object to OCDB!");
491 else if (!partition.IsNull() && detector.IsNull()){ // global partition
492 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
493 if (triggerCTPtiming!= NULL) {
494 Log("Found trigger timing params in DAQ logbook");
495 AliDebug(2,Form("%s",triggerCTPtiming));
496 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
498 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
502 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
503 runCTPtiming->SetTitle(titleCTPtiming);
504 AliCDBMetaData metadata;
505 metadata.SetBeamPeriod(0);
506 metadata.SetResponsible("Roman Lietava");
507 metadata.SetComment("CTP timing params from DAQ logbook");
508 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
509 Log("Unable to store the CTP timing params object to OCDB!");
516 Log("Trigger timing params NULL in DAQ logbook");
522 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
526 //===========================//
527 // LTU Configuration //
528 //===========================//
530 Log("*************** Processing LTU Configuration");
532 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
533 Log("STANDALONE partition for current run, using LTU configuration dummy value");
534 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
536 Log(Form("No dummy LTU Config entry found, going into error..."));
540 TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
542 Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
546 AliCDBMetaData metadata;
547 metadata.SetResponsible("Roman Lietava");
548 metadata.SetComment("LTU Config from dummy entry in OCDB");
549 if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
550 Log("Unable to store the dummy LTU Config object to OCDB!");
557 else if (!partition.IsNull() && detector.IsNull()){ // global partition
559 Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
560 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
561 Printf ("detectormask = %d",detectorMask);
562 TObjArray * ltuarray = new TObjArray();
563 ltuarray->SetOwner(1);
564 Bool_t isLTUok = kTRUE;
565 for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
566 if ((detectorMask >> i) & 0x1) {
567 TString det = AliDAQ::OfflineModuleName(i);
568 TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
569 if (detCTPName == "CTP") {
570 detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors
571 Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
574 Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
575 TString* ltu = GetLTUConfig(detCTPName.Data());
577 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()));
583 Float_t ltuFineDelay1 = ltu[0].Atof();
584 Float_t ltuFineDelay2 = ltu[1].Atof();
585 Float_t ltuBCDelayAdd = ltu[2].Atof();
586 const char* name = AliDAQ::DetectorName(i);
587 AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
588 ltuarray->AddAtAndExpand(ltuConfig,i);
593 AliCDBMetaData metadata;
594 metadata.SetBeamPeriod(0);
595 metadata.SetResponsible("Roman Lietava");
596 metadata.SetComment("LTU Configuration for current run");
597 if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
598 Log("Unable to store the LTU Config object to OCDB!");
606 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
611 //=================//
613 //=================//
615 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
616 Log("*************** Processing LHC Data");
618 UInt_t iLHCData = ProcessLHCData(grpobj);
620 if( iLHCData == 0 ) {
621 Log(Form("LHC Data from DCS FXS, successful!"));
622 } else if (iLHCData == 1) {
623 Log(Form("LHC Data, problems with DCS FXS!"));
625 } else if (iLHCData == 2) {
626 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
628 } else if (iLHCData ==3){
629 Log(Form("Problems in storing LHC Phase - going into Error"));
631 } else if (iLHCData ==4){
632 Log(Form("Problems with LHC Phase - going into Error"));
635 Log(Form("LHC Data problems"));
641 //==================//
642 // SPD Mean Vertex //
643 //==================//
645 Log("*************** Processing SPD Mean Vertex");
647 if (runType == "PHYSICS"){
648 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
649 if( iSPDMeanVertex == 1 ) {
650 Log(Form("SPD Mean Vertex, successful!"));
652 Log(Form("SPD Mean Vertex failed!!!"));
657 Log("SPD Mean Vertex not processed since runType != PHYSICS");
660 // storing AliGRPObject in OCDB
663 md.SetResponsible("Chiara Zampolli");
664 md.SetComment("Output parameters from the GRP preprocessor.");
666 Bool_t result = kTRUE;
667 result = Store("GRP", "Data", grpobj, &md);
670 if (result && !error ) {
671 Log("GRP Preprocessor Success");
674 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s",
675 kppError[(error&1)?1:0],
676 kppError[(error&2)?2:0],
677 kppError[(error&4)?3:0],
678 kppError[(error&8)?4:0],
679 kppError[(error&16)?5:0],
680 kppError[(error&32)?6:0],
681 kppError[(error&64)?7:0],
682 kppError[(error&128)?8:0],
683 kppError[(error&256)?9:0],
684 kppError[(error&512)?10:0],
685 kppError[(error&1024)?11:0],
686 kppError[(error&2048)?12:0]
694 //_______________________________________________________________
696 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
699 //Getting the LHC Data from DCS FXS
702 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
703 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
704 if (timeStartString.IsNull() || timeEndString.IsNull()){
705 if (timeStartString.IsNull()){
706 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
708 else if (timeEndString.IsNull()){
709 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
714 Double_t timeStart = timeStartString.Atof();
715 Double_t timeEnd = timeEndString.Atof();
717 TString fileName = GetFile(kDCS, "LHCData","");
718 if (fileName.Length()>0){
719 AliInfo("Got The LHC Data file");
720 AliLHCReader lhcReader;
722 // Processing data to be put in AliGRPObject
725 Log("*************Energy ");
726 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
728 Float_t energy = ProcessEnergy(energyArray,timeStart);
730 grpobj->SetBeamEnergy(energy);
731 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
736 AliError("Energy not found in LHC Data file!!!");
739 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
740 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
741 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
742 Double_t timeBeamTypeEnd[2] = {timeEnd, timeEnd}; // max validity for Beam Type1,2
743 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
744 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
745 Double_t timeBeamStart = -1; // min validity for Beam Type
746 Double_t timeBeamTypeStart[2] = {-1,-1}; // min validity for Beam Type1,2
747 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
748 Int_t indexMachineMode = -1; // index of measurement used to set Machine Mode
749 Int_t indexBeam = -1; // index of measurement used to set Beam Type
750 Int_t indexBeamType[2] = {-1, -1}; // index of measurement used to set Beam Type1,2
751 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
752 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Machine Mode is found before (or at) SOR
753 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Type is found before (or at) SOR
754 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
755 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
756 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
757 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
758 Bool_t flagBeamType[2] = {kFALSE, kFALSE}; //flag set true if a changed occurred in BeamType1,2
760 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...)
761 // arrayTimes elements order correspond to the one used in the array of the strings fgkLHCDataPoints, i.e.:
762 // arrayTimes[0] --> MachineMode
763 // arrayTimes[1] --> BeamMode
764 // arrayTimes[2] --> BeamType (when written together)
765 // arrayTimes[3] --> BeamType1 (when written separate)
766 // arrayTimes[4] --> BeamType2 (when written separate)
769 Log("*************BeamMode (LHCState) ");
770 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
771 Int_t nBeamMode = -1;
773 nBeamMode = beamModeArray->GetEntries();
775 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
778 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
779 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
781 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
782 timeBeamModeStart = beamMode->GetTimeStamp();
783 indexBeamMode = iBeamMode;
784 foundBeamModeStart = kTRUE;
792 if (!foundBeamModeStart){
793 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
796 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
797 TObjString* beamModeString = beamMode->GetStringArray(0);
798 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
799 grpobj->SetLHCState(beamModeString->String());
800 if (indexBeamMode < nBeamMode-1){
801 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
803 if (beamMode1->GetTimeStamp()<=timeStart){
804 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
806 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
807 timeBeamModeEnd = beamMode1->GetTimeStamp();
808 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
809 TString bmString0 = beamModeString->String();
810 TString bmString1 = beamModeString1->String();
811 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
812 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()));
813 flagBeamMode = kTRUE;
814 arrayTimes[1]=timeBeamModeEnd;
820 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
825 delete beamModeArray;
828 AliError("Beam mode array not found in LHC Data file!!!");
832 Log("*************MachineMode ");
833 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
834 Int_t nMachineMode = -1;
835 if (machineModeArray){
836 nMachineMode = machineModeArray->GetEntries();
837 if (nMachineMode==0){
838 AliInfo("No Machine Mode found, leaving it empty");
841 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
842 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
844 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
845 timeMachineModeStart = machineMode->GetTimeStamp();
846 indexMachineMode = iMachineMode;
847 foundMachineModeStart = kTRUE;
854 if (!foundMachineModeStart){
855 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
858 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
859 TObjString* machineModeString = machineMode->GetStringArray(0);
860 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
861 grpobj->SetMachineMode(machineModeString->String());
862 if (indexMachineMode < nMachineMode-1){
863 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
865 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
866 timeMachineModeEnd = machineMode1->GetTimeStamp();
867 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
868 TString mmString0 = machineModeString->String();
869 TString mmString1 = machineModeString1->String();
870 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
871 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()));
872 flagMachineMode = kTRUE;
873 arrayTimes[0]=timeMachineModeEnd;
878 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
883 delete machineModeArray;
886 AliError("Machine mode array not found in LHC Data file!!!");
889 // BeamType1 and BeamType2 - both put in the same string
890 Log("*************BeamType ");
891 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
893 Int_t nBeam = beamArray->GetEntries();
895 AliInfo("No Beam Type found, leaving it empty");
898 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
899 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
901 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
902 timeBeamStart = beam->GetTimeStamp();
904 foundBeamStart = kTRUE;
911 if (!foundBeamStart){
912 AliInfo("No value for the Beam Type found before start of run, the (common) Beam Type will remain empty");
915 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
916 TObjString* beamString = beam->GetStringArray(0);
917 TString beamType = beamString->String();
918 AliInfo(Form("Beam Type = %s",beamType.Data()));
919 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
920 AliInfo("Setting beam type to p-p");
921 grpobj->SetBeamType("p-p");
923 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
924 AliInfo("Setting beam type to A-A");
925 grpobj->SetBeamType("A-A");
928 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
929 AliInfo("Setting beam type to Pb-Pb");
930 grpobj->SetBeamType("Pb-Pb");
933 AliError("Beam Type not known, leaving it empty");
936 if (indexBeam < nBeam-1){
937 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
939 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
940 timeBeamEnd = beam1->GetTimeStamp();
941 TObjString* beamString1 = beam1->GetStringArray(0);
942 TString beamType1 = beamString1->String();
943 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
944 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()));
946 arrayTimes[2] = timeBeamEnd;
951 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
959 AliError("Beam Type array not found in LHC Data file!!!");
962 // BeamType1 and BeamType2 - in separete string
963 Log("*************BeamType, 1 and 2 ");
964 Int_t indexBeamTypeString = 6; // index of the string with the alias of BeanType1 in the array fgkLHCDataPoints
965 TString combinedBeamType = "-"; // combined beam tyope, built from beam type 1 and beam type 2
966 for (Int_t ibeamType = 0; ibeamType<2; ibeamType++){
967 beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[indexBeamTypeString+ibeamType]);
969 Int_t nBeam = beamArray->GetEntries();
971 AliInfo(Form("No Beam Type %s found, leaving it empty",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
974 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
975 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
977 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
978 timeBeamTypeStart[ibeamType] = beam->GetTimeStamp();
979 indexBeamType[ibeamType] = iBeam;
980 foundBeamTypeStart[ibeamType] = kTRUE;
987 if (!foundBeamTypeStart[ibeamType]){
988 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));
991 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
992 TObjString* beamString = beam->GetStringArray(0);
993 TString beamType = beamString->String();
994 AliInfo(Form("Beam Type (for %s) = %s", fgkLHCDataPoints[indexBeamTypeString+ibeamType], beamType.Data()));
995 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
996 AliInfo(Form("Setting beam type %s to p", fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
997 grpobj->SetSingleBeamType(ibeamType,"p");
998 if (ibeamType == 0) combinedBeamType.Prepend("p");
999 else combinedBeamType.Append("p");
1001 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
1002 AliInfo("Setting beam type to A");
1003 grpobj->SetSingleBeamType(ibeamType,"A");
1004 if (ibeamType == 0) combinedBeamType.Prepend("A");
1005 else combinedBeamType.Append("A");
1008 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
1009 AliInfo("Setting beam type to Pb-Pb");
1010 grpobj->SetSingleBeamType(ibeamType, "Pb-Pb");
1013 AliError("Beam Type not known, leaving it empty");
1016 if (indexBeamType[ibeamType] < nBeam-1){
1017 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
1019 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
1020 timeBeamTypeEnd[ibeamType] = beam1->GetTimeStamp();
1021 TObjString* beamString1 = beam1->GetStringArray(0);
1022 TString beamType1 = beamString1->String();
1023 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
1024 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()));
1025 flagBeamType[ibeamType] = kTRUE;
1026 arrayTimes[3+ibeamType] = timeBeamTypeEnd[ibeamType];
1031 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]));
1039 AliError(Form("Beam Type %s array not found in LHC Data file!!!",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1042 AliInfo(Form("Setting combined beam type to %s",combinedBeamType.Data()));
1043 grpobj->SetBeamType(combinedBeamType);
1045 // Setting minTimeLHCValidity
1046 if (flagBeamMode == kTRUE || flagMachineMode == kTRUE || flagBeam == kTRUE || flagBeamType[0] == kTRUE || flagBeamType[1] == kTRUE){
1047 Double_t minTimeLHCValidity= TMath::MinElement(5,arrayTimes);
1048 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1049 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1052 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
1053 Double_t minTimeLHCValidity;
1054 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true --> it is the only one that changed
1055 minTimeLHCValidity = timeBeamEnd;
1057 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
1058 minTimeLHCValidity = timeMachineModeEnd;
1060 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
1061 minTimeLHCValidity = timeBeamModeEnd;
1063 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
1064 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
1066 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
1067 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
1069 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
1070 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
1073 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
1074 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
1076 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1077 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1081 // Processing data to go to AliLHCData object
1082 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
1083 // storing AliLHCData in OCDB
1085 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
1087 md.SetResponsible("Ruben Shahoyan");
1088 md.SetComment("LHC data from the GRP preprocessor.");
1089 Bool_t result = kTRUE;
1090 result = Store("GRP", "LHCData", dt, &md);
1093 Log(Form("Problems in storing LHC Data - but not going into Error"));
1097 // processing LHC Phase
1099 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
1100 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
1101 if (beam1phase == 0x0 || beam2phase == 0x0){
1102 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
1105 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
1107 AliInfo(Form("LHC Phase found"));
1108 AliCDBMetaData mdPhase;
1109 mdPhase.SetResponsible("Cvetan Cheshkov");
1110 mdPhase.SetComment("LHC Clock Phase");
1111 Bool_t result = kTRUE;
1112 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
1114 if (!result) return 3;
1120 AliError("No LHCData file found in DCS FXS");
1127 //_______________________________________________________________
1129 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
1132 //Getting the SPD Mean Vertex
1135 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
1136 Bool_t storeResult = kTRUE;
1137 if (list !=0x0 && list->GetEntries()!=0)
1139 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
1141 for (Int_t jj=0;jj<list->GetEntries();jj++){
1142 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1144 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1147 AliInfo(Form("found source %s", str->String().Data()));
1148 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
1149 if (fileNameRun.Length()>0){
1150 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1151 TFile daqFile(fileNameRun.Data(),"READ");
1152 if (daqFile.IsOpen()) {
1153 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
1156 // storing in the OCDB
1158 md.SetResponsible("Cvetan Cheshkov");
1159 md.SetComment("SPD Mean Vertex");
1160 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
1163 AliWarning("No SPD Mean Vertex object found in file");
1167 AliError("Can't open file");
1168 storeResult = kFALSE;
1172 AliWarning("No file found for current source for SPD Mean Vertex");
1177 AliWarning("No list found for SPD Mean Vertex");
1180 if (list) delete list;
1186 //_______________________________________________________________
1188 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
1190 //Getting the DAQ lb information
1192 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
1193 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
1194 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
1195 TString beamType = (TString)GetRunParameter("beamType");
1196 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
1197 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
1198 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
1199 TString runType = (TString)GetRunType();
1201 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!!!");
1203 UInt_t nparameter = 0;
1204 if (timeStart != 0){
1205 grpObj->SetTimeStart(timeStart);
1206 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
1210 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1214 grpObj->SetTimeEnd(timeEnd);
1215 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
1219 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1222 if (beamEnergy != 0){
1223 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1226 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1230 if (beamType.Length() != 0){
1231 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()));
1234 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1237 if (numberOfDetectors != 0){
1238 grpObj->SetNumberOfDetectors(numberOfDetectors);
1239 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1243 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1246 if (detectorMask != 0){
1247 grpObj->SetDetectorMask(detectorMask);
1248 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1252 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1255 if (lhcPeriod.Length() != 0) {
1256 grpObj->SetLHCPeriod(lhcPeriod);
1257 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1261 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1263 if (runType.Length() != 0) {
1264 grpObj->SetRunType(runType);
1265 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1269 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1275 //_______________________________________________________________
1277 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1279 //======DAQ FXS======//
1281 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1282 AliRawEventHeaderV3_11::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_11 - temporary fix
1283 TList* list = GetFileSources(kDAQ);
1285 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1289 if (list->GetEntries() == 0) {
1290 Log("no raw data tags in this run: nothing to merge!");
1291 delete list; list=0;
1295 TChain *fRawTagChain = new TChain("T");
1297 TIterator* iter = list->MakeIterator();
1299 while ((obj = iter->Next())) {
1300 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1302 Log(Form("Found source %s", objStr->String().Data()));
1303 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1305 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1306 delete fRawTagChain; fRawTagChain=0;
1309 Log(Form("Number of ids: %d",list2->GetEntries()));
1310 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1311 TObjString *idStr = (TObjString *)list2->At(i);
1312 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1313 if (fileName.Length() > 0) {
1314 Log(Form("Adding file in the chain: %s",fileName.Data()));
1315 fRawTagChain->Add(fileName.Data());
1318 Log(Form("Could not retrieve file with id %s from source %s: "
1319 "connection problems with DAQ FXS!",
1320 idStr->String().Data(), objStr->String().Data()));
1321 delete list; list=0;
1322 delete list2; list2=0;
1323 delete fRawTagChain; fRawTagChain=0;
1331 TString fRawDataFileName = "GRP_Merged.tag.root";
1332 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1334 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1335 Log("Error merging raw data files!!!");
1339 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1340 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1343 Log("Problem storing raw data tags in local file!!!");
1345 Log("Raw data tags merged successfully!!");
1350 delete fRawTagChain; fRawTagChain=0;
1352 if (result == kFALSE) {
1360 //_______________________________________________________________
1361 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1364 // processing the info
1365 // stored in the DCS FXS
1366 // coming from the trigger
1368 // Get the CTP counters information
1370 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1371 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1372 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1374 Log(Form("No dummy CTP scalers entry found, going into error..."));
1378 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1380 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1384 AliCDBMetaData metaData;
1385 metaData.SetResponsible("Roman Lietava");
1386 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1387 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1388 Log("Unable to store the dummy CTP scalers object to OCDB!");
1395 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1396 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1397 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1398 if (countersfile.IsNull()) {
1399 Log("No CTP counters files has been found: empty source!");
1403 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1404 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1406 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1410 AliCDBMetaData metaData;
1411 metaData.SetBeamPeriod(0);
1412 metaData.SetResponsible("Roman Lietava");
1413 metaData.SetComment("CTP scalers");
1414 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1415 Log("Unable to store the CTP scalers object to OCDB!");
1426 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1433 //_______________________________________________________________
1435 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1439 // processing DCS DPs
1442 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1443 Int_t nL3Entries = 0;
1444 Int_t nDipoleEntries = 0;
1445 Int_t nEnvEntries = 0;
1446 Int_t nHallProbesEntries = 0;
1447 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1448 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1449 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1450 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1451 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1452 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1453 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1458 //_______________________________________________________________
1460 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1467 Int_t nL3Entries = 0;
1469 TObjArray *array = 0x0;
1471 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1473 AliInfo(Form("==========L3Current==========="));
1474 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1475 indexDP = kL3Current;
1476 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1478 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1481 if (array->GetEntries() == 0){
1482 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1485 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1486 if (floatDCS != NULL){
1487 grpObj->SetL3Current(floatDCS);
1499 ffailedDPs->RemoveAt(indexDP);
1503 if (array) array = 0x0;
1505 AliInfo(Form("==========L3Polarity==========="));
1506 indexDP = kL3Polarity;
1507 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1509 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1512 if (array->GetEntries() == 0){
1513 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1516 Bool_t change = kFALSE;
1517 Char_t charDCS = ProcessBool(array,change);
1518 if (change == kFALSE){
1519 grpObj->SetL3Polarity(charDCS);
1520 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1521 ffailedDPs->RemoveAt(indexDP);
1525 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1526 ffailedDPs->RemoveAt(indexDP);
1530 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]));
1538 //_______________________________________________________________
1540 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1546 Int_t nDipoleEntries = 0;
1547 TObjArray *array = 0x0;
1549 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1551 AliInfo(Form("==========DipoleCurrent==========="));
1552 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1553 indexDP = kDipoleCurrent;
1554 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1556 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1559 if (array->GetEntries() == 0){
1560 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1563 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1564 if (floatDCS != NULL){
1565 grpObj->SetDipoleCurrent(floatDCS);
1577 ffailedDPs->RemoveAt(indexDP);
1581 if (array) array = 0x0;
1583 AliInfo(Form("==========DipolePolarity==========="));
1584 indexDP = kDipolePolarity;
1585 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1587 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1590 if (array->GetEntries() == 0){
1591 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1594 Bool_t change = kFALSE;
1595 Char_t charDCS = ProcessBool(array,change);
1597 grpObj->SetDipolePolarity(charDCS);
1598 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1599 ffailedDPs->RemoveAt(indexDP);
1603 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1604 ffailedDPs->RemoveAt(indexDP);
1608 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]));
1613 return nDipoleEntries;
1616 //_______________________________________________________________
1618 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1622 // evironment conditions (temperature, pressure) info
1624 Int_t nEnvEntries = 0;
1625 TObjArray *array = 0x0;
1628 AliInfo(Form("==========CavernTemperature==========="));
1629 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1630 indexDP = kCavernTemperature;
1631 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1633 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1636 if (array->GetEntries() == 0){
1637 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1640 Float_t *floatDCS = ProcessFloatAll(array);
1641 if (floatDCS != NULL){
1642 grpObj->SetCavernTemperature(floatDCS);
1653 ffailedDPs->RemoveAt(indexDP);
1658 if (array) array = 0x0;
1660 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1661 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1662 //dcsSensorArray->Print();
1663 if( fPressure->NumFits()<kNumSensors ) {
1664 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1666 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1668 AliInfo(Form("==========CavernAtmosPressure==========="));
1669 indexDP = kCavernAtmosPressure;
1670 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1671 TGraph* graph = sensorCavernP2->GetGraph();
1672 AliDebug(3,Form("index = %d",indexDP));
1673 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1674 AliDebug(2,Form("graph = %p",graph));
1675 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1676 if(sensorCavernP2->GetFit() || graph) {
1677 if (sensorCavernP2->GetFit()){
1678 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1681 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1683 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1684 ffailedDPs->RemoveAt(indexDP);
1687 //if (sensorP2) delete sensorP2;
1689 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] ));
1692 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1693 indexDP = kSurfaceAtmosPressure;
1694 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1695 graph = sensorP2->GetGraph();
1696 AliDebug(3,Form("index = %d",indexDP));
1697 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1698 AliDebug(2,Form("graph = %p",graph));
1699 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1700 if(sensorP2->GetFit() || graph) {
1701 if (sensorP2->GetFit()){
1702 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1705 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1707 grpObj->SetSurfaceAtmosPressure(sensorP2);
1708 ffailedDPs->RemoveAt(indexDP);
1711 //if (sensorP2) delete sensorP2;
1713 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] ));
1716 AliInfo(Form("==========CavernAtmosPressure2==========="));
1717 indexDP = kCavernAtmosPressure2;
1718 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1719 graph = sensorCavernP22->GetGraph();
1720 AliDebug(3,Form("index = %d",indexDP));
1721 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1722 AliDebug(2,Form("graph = %p",graph));
1723 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1724 if(sensorCavernP22->GetFit() || graph) {
1725 if (sensorCavernP22->GetFit()){
1726 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1729 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1731 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1732 ffailedDPs->RemoveAt(indexDP);
1735 //if (sensorP2) delete sensorP2;
1737 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] ));
1743 //_______________________________________________________________
1745 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1751 Int_t nHPEntries = 0;
1752 TObjArray *array = 0x0;
1754 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1756 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1757 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()));
1759 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1760 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1761 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1762 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1764 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1767 if (array->GetEntries() == 0){
1768 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1771 Float_t *floatDCS = ProcessFloatAll(array);
1772 if (floatDCS != NULL){
1773 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]));
1774 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1775 for (Int_t kk = 0 ; kk< 5; kk++){
1776 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1788 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1794 Log(Form("Hall Probes = %d ", nHPEntries));
1798 //_________________________________________________________________________
1800 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1804 // returning Spline Fit
1807 Int_t entriesarray = array->GetEntries();
1808 Float_t* value = new Float_t[entriesarray];
1809 Float_t* time = new Float_t[entriesarray];
1810 AliDCSValue* v = 0x0;
1811 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1812 v = (AliDCSValue*)array->At(iarray);
1813 value[iarray] = v->GetFloat();
1814 time[iarray] = v->GetTimeStamp();
1815 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1817 TGraph* gr = new TGraph(entriesarray,value,time);
1819 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1822 AliSplineFit *fit = new AliSplineFit();
1823 fit->SetMinPoints(10);
1824 fit->InitKnots(gr,10,10,0.0);
1830 //_________________________________________________________________________
1832 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1839 TString aDCSString="";
1841 AliDCSValue *v = 0x0;
1842 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1843 v = (AliDCSValue *)array->At(iCount);
1844 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1845 AliError(Form("DCS values for the parameter outside the queried interval"));
1849 if (aDCSString != v->GetChar())
1850 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1852 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1857 //__________________________________________________________________________________________________________________
1859 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1862 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1864 // parameters[0] = mean
1865 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1866 // parameters[2] = median
1867 // parameters[3] = standard deviation wrt mean
1868 // parameters[4] = standard deviation wrt median
1871 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1872 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1873 if (timeStartString.IsNull() || timeStartString.IsNull()){
1874 if (timeStartString.IsNull()){
1875 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1877 else if (timeStartString.IsNull()){
1878 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1880 fdaqStartEndTimeOk = kFALSE;
1884 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1885 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1886 Float_t* parameters = new Float_t[5];
1888 Int_t iCountsRun = 0;
1889 Int_t nCounts = array->GetEntries();
1890 Float_t valueBeforeSOR = 0;
1891 Float_t valueAfterEOR = 0;
1892 Int_t timestampBeforeSOR = -1;
1893 Int_t timestampAfterEOR = -1;
1894 Int_t ientrySOR = -1;
1895 Int_t ientryEOR = -1;
1896 Float_t* arrayValues = 0x0;
1897 Double_t* arrayWeights = 0x0;
1898 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1899 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1901 for(Int_t i = 0; i < nCounts; i++) {
1902 AliDCSValue *v = (AliDCSValue *)array->At(i);
1903 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1904 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1905 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1906 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1907 delete [] parameters;
1910 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1911 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1913 // look for the last value before SOR and the first value before EOR
1914 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1915 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1916 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1917 valueBeforeSOR = v->GetFloat();
1919 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1920 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1921 valueAfterEOR = v->GetFloat();
1922 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1924 // check if there are DPs between DAQ_time_start and DAQ_time_end
1925 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1926 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1927 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1928 AliDebug(2,Form("entry between SOR and EOR"));
1933 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1937 if (timestampBeforeSOR == -1){
1938 AliWarning("No value found before SOR");
1940 if (timestampAfterEOR == -1){
1941 AliWarning("No value found after EOR");
1944 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1945 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1946 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1947 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1948 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1949 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1951 Int_t nentriesUsed = 0;
1952 if (iCountsRun > 1){
1953 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1954 AliDebug(2,"Calculating (weighted) Mean and Median");
1955 arrayValues = new Float_t[iCountsRun];
1956 arrayWeights = new Double_t[iCountsRun];
1957 nentriesUsed = iCountsRun;
1958 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1959 AliDCSValue *v = (AliDCSValue *)array->At(i);
1960 Int_t timestamp2 = 0;
1962 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1963 timestamp2 = (Int_t)v1->GetTimeStamp();
1966 timestamp2 = timeEnd+1;
1968 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1969 arrayValues[i-ientrySOR] = v->GetFloat();
1971 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1972 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1974 else if (iCountsRun == 1){
1975 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1977 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1978 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.");
1979 arrayValues = new Float_t[2];
1980 arrayWeights = new Double_t[2];
1981 arrayValues[0] = valueBeforeSOR;
1982 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1983 arrayValues[1] = v->GetFloat();
1984 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1985 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1986 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1987 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1988 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1989 truncMeanFlag = kFALSE;
1992 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");
1993 parameters[0] = AliGRPObject::GetInvalidFloat();
1994 parameters[1] = AliGRPObject::GetInvalidFloat();
1995 parameters[2] = AliGRPObject::GetInvalidFloat();
1996 parameters[3] = AliGRPObject::GetInvalidFloat();
1997 parameters[4] = AliGRPObject::GetInvalidFloat();
2001 else { // iCountsRun == 0, using only the point immediately before SOR
2002 if (timestampBeforeSOR == -1){
2003 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");
2004 parameters[0] = AliGRPObject::GetInvalidFloat();
2005 parameters[1] = AliGRPObject::GetInvalidFloat();
2006 parameters[2] = AliGRPObject::GetInvalidFloat();
2007 parameters[3] = AliGRPObject::GetInvalidFloat();
2008 parameters[4] = AliGRPObject::GetInvalidFloat();
2012 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
2013 AliDebug(2,Form("value = %f",valueBeforeSOR));
2014 parameters[0] = valueBeforeSOR;
2015 parameters[2] = valueBeforeSOR;
2016 truncMeanFlag = kFALSE;
2023 Float_t sumweights = 0;
2024 Int_t entriesTruncMean = 0;
2025 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
2026 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2028 // calculating SD wrt Mean and Median
2029 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
2031 for (Int_t i =0; i< nentriesUsed; i++){
2032 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2033 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2034 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2035 sumweights += arrayWeights[i];
2037 // setting SD wrt Mean
2038 if (sumweights != 0 ){
2039 parameters[3] = TMath::Sqrt(temp1/sumweights);
2042 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
2043 parameters[3] = AliGRPObject::GetInvalidFloat();
2045 // setting SD wrt Median
2046 if (nentriesUsed != 0){
2047 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2050 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
2051 parameters[4] = AliGRPObject::GetInvalidFloat();
2055 parameters[3] = AliGRPObject::GetInvalidFloat();
2056 parameters[4] = AliGRPObject::GetInvalidFloat();
2059 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2061 AliDebug(2,"Calculating Truncated Mean");
2062 for (Int_t i =0; i< nentriesUsed; i++){
2063 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2064 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2065 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2066 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2067 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
2071 AliDebug(2,"Discarding entry");
2074 // setting truncated mean
2075 if (entriesTruncMean >1){
2076 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
2077 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2080 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
2081 parameters[1] = AliGRPObject::GetInvalidFloat();
2085 parameters[1] = AliGRPObject::GetInvalidFloat();
2089 delete [] arrayValues;
2092 delete [] arrayWeights;
2094 delete [] arrayValuesTruncMean;
2095 delete [] arrayWeightsTruncMean;
2097 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
2098 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
2099 AliInfo(Form("median = %f ",parameters[2]));
2100 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
2101 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
2106 //__________________________________________________________________________________________________________________
2108 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
2111 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2112 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
2113 // the flag is set according to the L3/Dipole current value
2114 // current threshold for L3 = 350 A (value provided by DCS)
2115 // current threshold for Dipole = 450 A (value provided by DCS)
2117 // parameters[0] = mean
2118 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2119 // parameters[2] = median
2120 // parameters[3] = standard deviation wrt mean
2121 // parameters[4] = standard deviation wrt median
2124 AliInfo(Form("indexDP = %d",indexDP));
2126 Int_t nCounts = array->GetEntries();
2127 for(Int_t i = 0; i < nCounts; i++) {
2128 AliDCSValue *v = (AliDCSValue *)array->At(i);
2129 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2130 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2131 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2132 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
2135 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2136 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
2137 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2138 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
2141 AliError(Form("DCS values for the parameter outside the queried interval"));
2145 return ProcessFloatAll(array);
2149 //_______________________________________________________________
2151 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
2154 // processing Boolean values
2157 Bool_t aDCSBool = kTRUE;
2159 AliDCSValue *v = 0x0;
2161 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2162 v = (AliDCSValue *)array->At(iCount);
2163 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
2164 AliError(Form("DCS values for the parameter outside the queried interval"));
2168 if (aDCSBool != v->GetBool()) {
2169 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2173 aDCSBool = v->GetBool(); // always keeping last value
2174 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
2177 Char_t caDCSBool = (Char_t) aDCSBool;
2182 //_______________________________________________________________
2184 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
2187 // processing Int values, returning mean
2188 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2189 // are outside the queried time interval or their value is out of range
2192 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2193 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2194 if (timeStartString.IsNull() || timeStartString.IsNull()){
2195 if (timeStartString.IsNull()){
2196 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2198 else if (timeStartString.IsNull()){
2199 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2204 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2205 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2206 Float_t aDCSArrayMean = 0.0;
2208 Float_t valueBeforeSOR = 0;
2209 Float_t valueAfterEOR = 0;
2210 Int_t timestampBeforeSOR = -1;
2211 Int_t timestampAfterEOR = -1;
2212 Int_t ientrySOR = -1;
2213 Int_t ientryEOR = -1;
2214 Float_t* arrayValues = 0x0;
2215 Double_t* arrayWeights = 0x0;
2216 Int_t iCountsRun = 0;
2217 Int_t nCounts = array->GetEntries();
2219 for(Int_t i = 0; i < nCounts; i++) {
2220 AliDCSValue* v = (AliDCSValue *)array->At(i);
2221 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
2222 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
2223 return AliGRPObject::GetInvalidFloat();
2225 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2226 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
2228 // look for the last value before SOR and the first value before EOR
2229 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2230 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2231 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2232 valueBeforeSOR = (Float_t) v->GetInt();
2234 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2235 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2236 valueAfterEOR = (Float_t) v->GetInt();
2237 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2239 // check if there are DPs between DAQ_time_start and DAQ_time_end
2240 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2241 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2242 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2243 AliDebug(2,Form("entry between SOR and EOR"));
2248 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2252 if (timestampBeforeSOR == -1){
2253 AliWarning("No value found before SOR!");
2255 if (timestampAfterEOR == -1){
2256 AliWarning("No value found after EOR!");
2259 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2260 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2261 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2262 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2263 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2264 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2266 Int_t nentriesUsed = 0;
2267 if (iCountsRun > 1){
2268 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2269 AliDebug(2,"Calculating (weighted) Mean");
2270 arrayValues = new Float_t[iCountsRun];
2271 arrayWeights = new Double_t[iCountsRun];
2272 nentriesUsed = iCountsRun;
2273 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2274 AliDCSValue *v = (AliDCSValue *)array->At(i);
2275 Int_t timestamp2 = 0;
2277 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2278 timestamp2 = (Int_t)v1->GetTimeStamp();
2281 timestamp2 = timeEnd+1;
2283 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2284 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2286 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2287 delete [] arrayValues;
2288 delete [] arrayWeights;
2290 else if (iCountsRun == 1){
2291 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2293 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2294 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2295 arrayValues = new Float_t[2];
2296 arrayWeights = new Double_t[2];
2297 arrayValues[0] = valueBeforeSOR;
2298 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2299 arrayValues[1] = (Float_t)v->GetInt();
2300 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2301 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2302 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2303 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2304 delete [] arrayValues;
2305 delete [] arrayWeights;
2308 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2309 return AliGRPObject::GetInvalidFloat();
2312 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2313 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2314 if (timestampBeforeSOR == -1){
2315 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2317 if (timestampAfterEOR == -1){
2318 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2320 return AliGRPObject::GetInvalidFloat();
2323 AliWarning("Using last entry before SOR and first entry after EOR.");
2325 arrayValues = new Float_t[2];
2326 arrayWeights = new Double_t[2];
2327 arrayValues[0] = valueBeforeSOR;
2328 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2329 arrayValues[1] = valueAfterEOR;
2330 arrayWeights[1] = 1.;
2331 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2332 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2333 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2334 delete [] arrayValues;
2335 delete [] arrayWeights;
2339 AliInfo(Form("mean = %f ", aDCSArrayMean));
2340 return aDCSArrayMean;
2343 //_______________________________________________________________
2345 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2348 // processing Int values, returning mean
2349 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2350 // are outside the queried time interval or their value is out of range
2353 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2354 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2355 if (timeStartString.IsNull() || timeStartString.IsNull()){
2356 if (timeStartString.IsNull()){
2357 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2359 else if (timeStartString.IsNull()){
2360 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2365 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2366 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2367 Float_t aDCSArrayMean = 0.0;
2369 Float_t valueBeforeSOR = 0;
2370 Float_t valueAfterEOR = 0;
2371 Int_t timestampBeforeSOR = -1;
2372 Int_t timestampAfterEOR = -1;
2373 Int_t ientrySOR = -1;
2374 Int_t ientryEOR = -1;
2375 Float_t* arrayValues = 0x0;
2376 Double_t* arrayWeights = 0x0;
2377 Int_t iCountsRun = 0;
2378 Int_t nCounts = array->GetEntries();
2380 for(Int_t i = 0; i < nCounts; i++) {
2381 AliDCSValue* v = (AliDCSValue *)array->At(i);
2382 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2383 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2384 return AliGRPObject::GetInvalidFloat();
2386 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2387 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2389 // look for the last value before SOR and the first value before EOR
2390 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2391 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2392 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2393 valueBeforeSOR = (Float_t)v->GetUInt();
2395 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2396 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2397 valueAfterEOR = (Float_t)v->GetUInt();
2398 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2400 // check if there are DPs between DAQ_time_start and DAQ_time_end
2401 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2402 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2403 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2404 AliDebug(2,Form("entry between SOR and EOR"));
2409 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2413 if (timestampBeforeSOR == -1){
2414 AliWarning("No value found before SOR!");
2416 if (timestampAfterEOR == -1){
2417 AliWarning("No value found after EOR!");
2420 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2421 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2422 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2423 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2424 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2425 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2427 Int_t nentriesUsed = 0;
2428 if (iCountsRun > 1){
2429 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2430 AliDebug(2,"Calculating (weighted) Mean");
2431 arrayValues = new Float_t[iCountsRun];
2432 arrayWeights = new Double_t[iCountsRun];
2433 nentriesUsed = iCountsRun;
2434 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2435 AliDCSValue *v = (AliDCSValue *)array->At(i);
2436 Int_t timestamp2 = 0;
2438 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2439 timestamp2 = (Int_t)v1->GetTimeStamp();
2442 timestamp2 = timeEnd+1;
2444 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2445 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2447 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2448 delete [] arrayValues;
2449 delete [] arrayWeights;
2451 else if (iCountsRun == 1){
2452 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2454 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2455 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2456 arrayValues = new Float_t[2];
2457 arrayWeights = new Double_t[2];
2458 arrayValues[0] = valueBeforeSOR;
2459 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2460 arrayValues[1] = (Float_t)v->GetUInt();
2461 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2462 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2463 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2464 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2465 delete [] arrayValues;
2466 delete [] arrayWeights;
2469 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2470 return AliGRPObject::GetInvalidFloat();
2473 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2474 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2475 if (timestampBeforeSOR == -1){
2476 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2478 if (timestampAfterEOR == -1){
2479 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2481 return AliGRPObject::GetInvalidFloat();
2484 AliWarning("Using last entry before SOR and first entry after EOR.");
2486 arrayValues = new Float_t[2];
2487 arrayWeights = new Double_t[2];
2488 arrayValues[0] = valueBeforeSOR;
2489 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2490 arrayValues[1] = valueAfterEOR;
2491 arrayWeights[1] = 1.;
2492 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2493 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2494 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2495 delete [] arrayValues;
2496 delete [] arrayWeights;
2500 AliInfo(Form("mean = %f ",aDCSArrayMean));
2501 return aDCSArrayMean;
2506 //_______________________________________________________________
2508 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2510 // extract DCS pressure maps. Perform fits to save space
2512 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2514 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2515 fPressure->MakeSplineFit(map);
2516 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2517 if (fitFraction > kFitFraction ) {
2518 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2520 AliInfo("Too few pressure maps fitted!!!");
2523 AliInfo("no atmospheric pressure map extracted!!!");
2532 //_______________________________________________________________
2533 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)
2536 // Retrieves logbook and trigger information from the online logbook
2537 // This information is needed for prompt reconstruction
2541 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2545 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2546 // 0 on success and no run was found
2547 // negative on error
2549 // This function is NOT called during the preprocessor run in the Shuttle!
2557 AliCDBManager* cdb = AliCDBManager::Instance();
2558 cdb->SetDefaultStorage(cdbRoot);
2561 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2565 Printf("ERROR: Could not connect to DAQ LB");
2571 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
2572 TSQLResult* result = server->Query(sqlQuery);
2575 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2579 if (result->GetRowCount() == 0)
2581 Printf("ERROR: Run %d not found", run);
2586 TSQLRow* row = result->Next();
2589 Printf("ERROR: Could not receive data from run %d", run);
2594 TString timeStartString(row->GetField(0));
2595 TString runType(row->GetField(1));
2596 TString detectorMaskString(row->GetField(2));
2597 TString l3CurrentString(row->GetField(3));
2598 TString dipoleCurrentString(row->GetField(4));
2599 TString beamTypeString(row->GetField(5));
2600 time_t timeStart = (time_t)(timeStartString.Atoi());
2601 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2602 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2603 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2604 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2605 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2606 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
2607 beamTypeString="A-A";
2610 AliGRPObject * grpObj = new AliGRPObject();
2611 grpObj->SetTimeStart(timeStart);
2612 grpObj->SetRunType((TString)(row->GetField(1)));
2613 grpObj->SetDetectorMask(detectorMask);
2614 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2615 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2616 grpObj->SetL3Polarity(l3Polarity);
2617 grpObj->SetDipolePolarity(dipolePolarity);
2618 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2619 grpObj->SetBeamType(beamTypeString);
2627 Printf("Storing GRP/GRP/Data object with the following content");
2630 AliCDBMetaData metadata;
2631 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2632 metadata.SetComment("GRP Output parameters received during online running");
2634 AliCDBId id("GRP/GRP/Data", run, run);
2635 Bool_t success = cdb->Put(grpObj, id, &metadata);
2641 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2645 // Receive trigger information
2646 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2647 result = server->Query(sqlQuery);
2650 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2654 if (result->GetRowCount() == 0)
2656 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2661 row = result->Next();
2664 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2669 TString triggerConfig(row->GetField(0));
2677 Printf("Found trigger configuration: %s", triggerConfig.Data());
2679 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2682 Printf("ERROR: Could not create CTP configuration object");
2686 metadata.SetComment("CTP run configuration received during online running");
2688 AliCDBId id2("GRP/CTP/Config", run, run);
2689 success = cdb->Put(runcfg, id2, &metadata);
2696 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2701 // Receive list of GDCs for this run
2702 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2703 result = server->Query(sqlQuery);
2706 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2710 if (result->GetRowCount() == 0)
2712 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2718 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2719 row = result->Next();
2722 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2726 gdc += row->GetField(0);
2736 Printf("Found GDC: %s", gdc.Data());
2738 // get last run with same run type that was already processed by the SHUTTLE
2740 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());
2741 result = server->Query(sqlQuery);
2744 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2748 if (result->GetRowCount() == 0)
2750 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2755 row = result->Next();
2758 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2763 TString lastRunStr(row->GetField(0));
2764 Int_t lastRun = lastRunStr.Atoi();
2766 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2780 //------------------------------------------------------------------------------------------------------
2781 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
2784 // Method to processo LHC Energy information
2785 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2788 Int_t nCounts = array->GetEntries();
2789 Float_t energy = -1;
2790 Double_t timeEnergy = -1;
2791 Int_t indexEnergy = -1;
2792 Bool_t foundEnergy = kFALSE;
2794 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2796 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2799 for (Int_t i = 0; i < nCounts; i++){
2800 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2802 if (dcs->GetTimeStamp()<=timeStart && dcs->GetTimeStamp()>=timeEnergy){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
2803 timeEnergy = dcs->GetTimeStamp();
2805 foundEnergy = kTRUE;
2813 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
2816 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
2817 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2818 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
2824 //------------------------------------------------------------------------------------------------------
2825 AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
2828 // Method to process LHC-Clock Phase data
2829 // Only the values between DAQ_time_start and DAQ_time_end are kept
2831 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
2833 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
2834 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
2836 TString timeCreatedStr = GetRunParameter("time_created");
2837 Double_t timeCreated = timeCreatedStr.Atof();
2839 Int_t nCounts = beam1phase->GetEntries();
2840 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
2842 AliWarning("No beam1 LHC clock phase values found!");
2847 Double_t prevPhase = 0;
2848 for (Int_t i = 0; i < nCounts; i++){
2849 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
2851 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
2852 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2853 if ((i == 0) || (i == (nCounts-1)) ||
2855 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2856 prevPhase = dcs->GetDouble(0);
2857 foundBeam1Phase = kTRUE;
2858 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
2859 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2860 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2865 if (!foundBeam1Phase){
2866 AliError("No beam1 LHC clock phase values found within the run!");
2872 nCounts = beam2phase->GetEntries();
2873 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
2875 AliWarning("No beam2 LHC clock phase values found!");
2880 Double_t prevPhase = 0;
2881 for (Int_t i = 0; i < nCounts; i++){
2882 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
2884 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2885 if ((i == 0) || (i == (nCounts-1)) ||
2887 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2888 prevPhase = dcs->GetDouble(0);
2889 foundBeam2Phase = kTRUE;
2890 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
2891 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2892 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2897 if (!foundBeam2Phase){
2898 AliError("No beam2 LHC clock phase values found within the run!");