1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Class AliGRPPreprocessor
20 // Global Run Parameters (GRP) preprocessor
21 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 // Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN
23 // Modified: Chiara.Zampolli@cern.ch CERN
24 //-------------------------------------------------------------------------
29 #include <TObjString.h>
30 #include <TObjArray.h>
37 #include "AliGRPPreprocessor.h"
38 #include "AliGRPObject.h"
39 #include "AliDCSSensor.h"
40 #include "AliSplineFit.h"
41 #include "AliDCSSensorArray.h"
42 #include "AliRawEventHeaderVersions.h"
44 #include "AliTriggerConfiguration.h"
45 #include "AliTriggerRunScalers.h"
46 #include "AliTriggerInput.h"
48 #include "AliCDBMetaData.h"
49 #include "AliESDVertex.h"
50 #include "AliLHCReader.h"
51 #include "AliLHCData.h"
52 #include "AliDCSArray.h"
54 #include "AliLTUConfig.h"
58 class AliShuttleInterface;
60 // needed for ReceivePromptRecoParameters
62 #include <TSQLServer.h>
63 #include <TSQLResult.h>
65 #include <AliCDBManager.h>
66 #include <AliCDBMetaData.h>
68 #include <AliTriggerConfiguration.h>
69 #include <AliCTPTimeParams.h>
70 #include <AliLHCClockPhase.h>
72 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
74 ClassImp(AliGRPPreprocessor)
76 //_______________________________________________________________
78 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 6; // num parameters in the logbook used to fill the GRP object
79 const Int_t AliGRPPreprocessor::fgknDCSDP = 48; // number of dcs dps
80 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
81 const Int_t AliGRPPreprocessor::fgknLHCDP = 8; // number of dcs dps from LHC data
82 const Int_t AliGRPPreprocessor::fgkDCSDPHallTopShift = 4; // shift from the top to get tp the Hall Probes names in the list of DCS DPs
83 const Int_t AliGRPPreprocessor::fgkDCSDPNonWorking = 5; // number of non working DCS DPs
84 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
92 "L3_BSF17_Temperature",
96 "L3_BSF4_Temperature",
100 "L3_BKF17_Temperature",
104 "L3_BKF4_Temperature",
108 "L3_BSF13_Temperature",
112 "L3_BSF8_Temperature",
116 "L3_BKF13_Temperature",
120 "L3_BKF8_Temperature",
124 "Dipole_Inside_Temperature",
128 "Dipole_Outside_Temperature",
130 "CavernAtmosPressure",
131 "SurfaceAtmosPressure",
132 "CavernAtmosPressure2"
135 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
139 "L3_BSF17_Temperature",
143 "L3_BSF4_Temperature",
147 "L3_BKF17_Temperature",
151 "L3_BKF4_Temperature",
155 "L3_BSF13_Temperature",
159 "L3_BSF8_Temperature",
163 "L3_BKF13_Temperature",
167 "L3_BKF8_Temperature",
171 "Dipole_Inside_Temperature",
175 "Dipole_Outside_Temperature"
178 const Short_t kSensors = 45; // start index position of sensor in DCS DPs
179 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
182 const char* AliGRPPreprocessor::fgkLHCDataPoints[AliGRPPreprocessor::fgknLHCDP] = {
186 "LHC_Beams_Particle_Type",
187 "BPTX_Phase_Shift_B1",
188 "BPTX_Phase_Shift_B2",
189 "LHC_Particle_Type_B1",
190 "LHC_Particle_Type_B2"
193 const char* kppError[] = {
195 "(DAQ logbook ERROR)",
197 "(Trigger Scalers not found in DCS FXS - ERROR)",
198 "(DCS data points ERROR)",
199 "(Trigger Configuration ERROR)",
200 "(DAQ logbook ERROR determining partition of the run)",
201 "(CTP timing ERROR)",
202 "(SPD Mean Vertex ERROR)",
203 "(DCS FXS Error for LHC Data)",
205 "(LHC Clock Phase Error (from LHC Data))",
206 "(LTU Configuration Error)"
209 //_______________________________________________________________
211 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
212 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))
214 // constructor - shuttle must be instantiated!
216 AddRunType("COSMIC");
218 AddRunType("PHYSICS");
219 AddRunType("CALIBRATION_BC");
220 AddRunType("CALIBRATION_CENTRAL");
221 AddRunType("CALIBRATION_EMD");
222 AddRunType("CALIBRATION_MB");
223 AddRunType("CALIBRATION_SEMICENTRAL");
224 AddRunType("CALIBRATION");
225 AddRunType("PEDESTAL");
226 AddRunType("STANDALONE");
229 AddRunType("PULSER");
230 AddRunType("STANDALONE_PULSER");
231 AddRunType("STANDALONE_BC");
234 fminFloat = -FLT_MAX;
235 fmaxDouble = DBL_MAX;
236 fminDouble = -DBL_MAX;
242 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
243 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
244 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
245 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
246 AliInfo(Form("Max allowed integer = %d",fmaxInt));
247 AliInfo(Form("Min allowed integer = %d",fminInt));
248 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
249 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
251 ffailedDPs->SetOwner(kTRUE);
254 //_______________________________________________________________
256 AliGRPPreprocessor::~AliGRPPreprocessor()
265 //_______________________________________________________________
267 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
269 // Initialize preprocessor
271 AliPreprocessor::Initialize(run, startTime, endTime);
273 AliInfo("Initialization of the GRP preprocessor.");
274 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
275 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
276 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
277 for(Int_t j = 0; j < kNumSensors; j++) {
278 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
279 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
281 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
283 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
285 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
286 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
287 ffailedDPs->AddAt(dp,iDP);
292 //_______________________________________________________________
294 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
296 // process data retrieved by the Shuttle
298 // retrieving "partition" and "detector" fields from DAQ logbook to
299 // determine the partition in which the run was taken
300 // the partition is used to decide how to react in case of errors for CTP
302 TString partition = (TString)GetRunParameter("partition");
303 TString detector = (TString)GetRunParameter("detector");
305 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
306 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
308 //=================//
310 //=================//
312 Log("*************** Processing DAQ logbook");
316 Int_t iDaqLB = ProcessDaqLB(grpobj);
317 TString runType = (TString)GetRunType();
318 TString beamType = (TString)GetRunParameter("beamType");
319 if(iDaqLB == fgknDAQLbPar) {
320 Log(Form("DAQ Logbook, successful! Retrieved %d/%d entries",iDaqLB,fgknDAQLbPar));
322 Log(Form("DAQ Logbook, could not get all expected entries!!! Retrieved only %d/%d entries",iDaqLB,fgknDAQLbPar));
326 //=================//
328 //=================//
330 Log("*************** Processing DAQ FXS");
332 UInt_t iDaqFxs = ProcessDaqFxs();
334 Log(Form("DAQ FXS, successful!"));
336 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
340 //=================//
342 //=================//
344 Log("*************** Processing DCS FXS");
346 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
348 Log(Form("DCS FXS, successful!"));
349 } else if (iDcsFxs ==1) {
350 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
353 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
357 //=================//
358 // DCS data points //
359 //=================//
361 Log("*************** Processing DCS DPs");
363 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
364 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
365 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-fgkDCSDPNonWorking));
366 if (fdaqStartEndTimeOk){
367 if( entries < fgknDCSDP - fgkDCSDPNonWorking ) { // L3_BSF4_H3, L3_BSF17_H1, L3_BSF17_H2, L3_BSF17_H3, L3_BSF17_Temperature are not working yet...
368 Log(Form("Possible problem with the DCS data points!!! Only %d/%d entries found - Please read further for more details",entries,fgknDCSDP-fgkDCSDPNonWorking));
369 Log(Form("The DPs giving problems were:"));
370 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
371 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
373 TString name = dpString->String();
374 if (name != "L3_BSF4_H3" && name != "L3_BSF17_H1" && name != "L3_BSF17_H2" && name != "L3_BSF17_H3" && name != "L3_BSF17_Temperature" ){
375 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
378 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()));
384 else Log(Form("DCS data points, successful!"));
386 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"));
388 //=======================//
389 // Trigger Configuration //
390 //=======================//
392 Log("*************** Processing Trigger Configuration");
394 const char * triggerConf = GetTriggerConfiguration();
396 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
397 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
398 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
400 Log(Form("No dummy CTP configuration entry found, going into error..."));
404 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
406 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
410 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
411 runcfg->SetTitle(titleCTPcfg);
412 AliCDBMetaData metaData;
413 metaData.SetResponsible("Roman Lietava");
414 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
415 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
416 Log("Unable to store the dummy CTP run configuration object to OCDB!");
423 else if (!partition.IsNull() && detector.IsNull()){ // global partition
424 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
425 if (triggerConf!= NULL) {
426 Log("Found trigger configuration in DAQ logbook");
427 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
429 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
433 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
434 runcfg->SetTitle(titleCTPcfg);
435 AliCDBMetaData metaData;
436 metaData.SetBeamPeriod(0);
437 metaData.SetResponsible("Roman Lietava");
438 metaData.SetComment("CTP run configuration from DAQ logbook");
439 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
440 Log("Unable to store the CTP run configuration object to OCDB!");
447 Log("Trigger configuration NULL in DAQ logbook");
453 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
457 //===========================//
458 // Trigger Timing Parameters //
459 //===========================//
461 Log("*************** Processing Trigger Time Params");
463 const char * triggerCTPtiming = GetCTPTimeParams();
465 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
466 Log("STANDALONE partition for current run, using CTP timing params dummy value");
467 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
469 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
473 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
475 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
479 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
480 runCTPtiming->SetTitle(titleCTPtiming);
481 AliCDBMetaData metadata;
482 metadata.SetResponsible("Roman Lietava");
483 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
484 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
485 Log("Unable to store the dummy CTP timing params object to OCDB!");
492 else if (!partition.IsNull() && detector.IsNull()){ // global partition
493 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
494 if (triggerCTPtiming!= NULL) {
495 Log("Found trigger timing params in DAQ logbook");
496 AliDebug(2,Form("%s",triggerCTPtiming));
497 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
499 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
503 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
504 runCTPtiming->SetTitle(titleCTPtiming);
505 AliCDBMetaData metadata;
506 metadata.SetBeamPeriod(0);
507 metadata.SetResponsible("Roman Lietava");
508 metadata.SetComment("CTP timing params from DAQ logbook");
509 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
510 Log("Unable to store the CTP timing params object to OCDB!");
517 Log("Trigger timing params NULL in DAQ logbook");
523 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
527 //===========================//
528 // LTU Configuration //
529 //===========================//
531 Log("*************** Processing LTU Configuration");
533 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
534 Log("STANDALONE partition for current run, using LTU configuration dummy value");
535 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
537 Log(Form("No dummy LTU Config entry found, going into error..."));
541 TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
543 Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
547 AliCDBMetaData metadata;
548 metadata.SetResponsible("Roman Lietava");
549 metadata.SetComment("LTU Config from dummy entry in OCDB");
550 if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
551 Log("Unable to store the dummy LTU Config object to OCDB!");
558 else if (!partition.IsNull() && detector.IsNull()){ // global partition
560 Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
561 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
562 Printf ("detectormask = %d",detectorMask);
563 TObjArray * ltuarray = new TObjArray();
564 ltuarray->SetOwner(1);
565 Bool_t isLTUok = kTRUE;
566 for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
567 if ((detectorMask >> i) & 0x1) {
568 TString det = AliDAQ::OfflineModuleName(i);
569 TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
570 if (detCTPName == "CTP") {
571 detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors
572 Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
575 Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
576 TString* ltu = GetLTUConfig(detCTPName.Data());
578 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()));
584 Float_t ltuFineDelay1 = ltu[0].Atof();
585 Float_t ltuFineDelay2 = ltu[1].Atof();
586 Float_t ltuBCDelayAdd = ltu[2].Atof();
587 const char* name = AliDAQ::DetectorName(i);
588 AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
589 ltuarray->AddAtAndExpand(ltuConfig,i);
594 AliCDBMetaData metadata;
595 metadata.SetBeamPeriod(0);
596 metadata.SetResponsible("Roman Lietava");
597 metadata.SetComment("LTU Configuration for current run");
598 if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
599 Log("Unable to store the LTU Config object to OCDB!");
607 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
612 //=================//
614 //=================//
616 if (runType == "PHYSICS"){ // processing the LHC file only in PHYSICS runs
617 Log("*************** Processing LHC Data");
619 UInt_t iLHCData = ProcessLHCData(grpobj);
621 if( iLHCData == 0 ) {
622 Log(Form("LHC Data from DCS FXS, successful!"));
623 } else if (iLHCData == 1) {
624 Log(Form("LHC Data, problems with DCS FXS!"));
626 } else if (iLHCData == 2) {
627 Log(Form("LHC Data, problems with DAQ_time_start/DAQ_time_end!"));
629 } else if (iLHCData ==3){
630 Log(Form("Problems in storing LHC Phase - going into Error"));
632 } else if (iLHCData ==4){
633 Log(Form("Problems with LHC Phase - going into Error"));
636 Log(Form("LHC Data problems"));
642 //==================//
643 // SPD Mean Vertex //
644 //==================//
646 Log("*************** Processing SPD Mean Vertex");
648 if (runType == "PHYSICS"){
649 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
650 if( iSPDMeanVertex == 1 ) {
651 Log(Form("SPD Mean Vertex, successful!"));
653 Log(Form("SPD Mean Vertex failed!!!"));
658 Log("SPD Mean Vertex not processed since runType != PHYSICS");
661 // storing AliGRPObject in OCDB
664 md.SetResponsible("Chiara Zampolli");
665 md.SetComment("Output parameters from the GRP preprocessor.");
667 Bool_t result = kTRUE;
668 result = Store("GRP", "Data", grpobj, &md);
671 if (result && !error ) {
672 Log("GRP Preprocessor Success");
675 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s",
676 kppError[(error&1)?1:0],
677 kppError[(error&2)?2:0],
678 kppError[(error&4)?3:0],
679 kppError[(error&8)?4:0],
680 kppError[(error&16)?5:0],
681 kppError[(error&32)?6:0],
682 kppError[(error&64)?7:0],
683 kppError[(error&128)?8:0],
684 kppError[(error&256)?9:0],
685 kppError[(error&512)?10:0],
686 kppError[(error&1024)?11:0],
687 kppError[(error&2048)?12:0]
695 //_______________________________________________________________
697 UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
700 //Getting the LHC Data from DCS FXS
703 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
704 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
705 if (timeStartString.IsNull() || timeEndString.IsNull()){
706 if (timeStartString.IsNull()){
707 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
709 else if (timeEndString.IsNull()){
710 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
715 Double_t timeStart = timeStartString.Atof();
716 Double_t timeEnd = timeEndString.Atof();
718 TString fileName = GetFile(kDCS, "LHCData","");
719 if (fileName.Length()>0){
720 AliInfo("Got The LHC Data file");
721 AliLHCReader lhcReader;
723 // Processing data to be put in AliGRPObject
726 Log("*************Energy ");
727 TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
729 Float_t energy = ProcessEnergy(energyArray,timeStart);
731 grpobj->SetBeamEnergy(energy);
732 grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
737 AliError("Energy not found in LHC Data file!!!");
740 Double_t timeBeamModeEnd = timeEnd; // max validity for Beam Mode
741 Double_t timeMachineModeEnd = timeEnd; // max validity for Machine Mode
742 Double_t timeBeamEnd = timeEnd; // max validity for Beam Type
743 Double_t timeBeamTypeEnd[2] = {timeEnd, timeEnd}; // max validity for Beam Type1,2
744 Double_t timeBeamModeStart = -1; // min validity for Beam Mode
745 Double_t timeMachineModeStart = -1; // min validity for Machine Mode
746 Double_t timeBeamStart = -1; // min validity for Beam Type
747 Double_t timeBeamTypeStart[2] = {-1,-1}; // min validity for Beam Type1,2
748 Int_t indexBeamMode = -1; // index of measurement used to set Beam Mode
749 Int_t indexMachineMode = -1; // index of measurement used to set Machine Mode
750 Int_t indexBeam = -1; // index of measurement used to set Beam Type
751 Int_t indexBeamType[2] = {-1, -1}; // index of measurement used to set Beam Type1,2
752 Bool_t foundBeamModeStart = kFALSE; // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
753 Bool_t foundMachineModeStart = kFALSE; // flag to be set in case an entry for the Machine Mode is found before (or at) SOR
754 Bool_t foundBeamStart = kFALSE; // flag to be set in case an entry for the Beam Type is found before (or at) SOR
755 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
756 Bool_t flagBeamMode = kFALSE; //flag set true if a changed occurred in BeamMode
757 Bool_t flagMachineMode = kFALSE; //flag set true if a changed occurred in MachineMode
758 Bool_t flagBeam = kFALSE; //flag set true if a changed occurred in BeamType
759 Bool_t flagBeamType[2] = {kFALSE, kFALSE}; //flag set true if a changed occurred in BeamType1,2
761 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...)
762 // arrayTimes elements order correspond to the one used in the array of the strings fgkLHCDataPoints, i.e.:
763 // arrayTimes[0] --> MachineMode
764 // arrayTimes[1] --> BeamMode
765 // arrayTimes[2] --> BeamType (when written together)
766 // arrayTimes[3] --> BeamType1 (when written separate)
767 // arrayTimes[4] --> BeamType2 (when written separate)
770 Log("*************BeamMode (LHCState) ");
771 TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
772 Int_t nBeamMode = -1;
774 nBeamMode = beamModeArray->GetEntries();
776 AliInfo("Found zero entries for the Beam Mode, leaving it empty");
779 for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
780 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
782 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
783 timeBeamModeStart = beamMode->GetTimeStamp();
784 indexBeamMode = iBeamMode;
785 foundBeamModeStart = kTRUE;
793 if (!foundBeamModeStart){
794 AliInfo("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
797 AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
798 TObjString* beamModeString = beamMode->GetStringArray(0);
799 AliInfo(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
800 grpobj->SetLHCState(beamModeString->String());
801 if (indexBeamMode < nBeamMode-1){
802 AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
804 if (beamMode1->GetTimeStamp()<=timeStart){
805 AliError("you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
807 else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
808 timeBeamModeEnd = beamMode1->GetTimeStamp();
809 TObjString* beamModeString1 = beamMode1->GetStringArray(0);
810 TString bmString0 = beamModeString->String();
811 TString bmString1 = beamModeString1->String();
812 if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
813 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()));
814 flagBeamMode = kTRUE;
815 arrayTimes[1]=timeBeamModeEnd;
821 AliInfo("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
826 delete beamModeArray;
829 AliError("Beam mode array not found in LHC Data file!!!");
833 Log("*************MachineMode ");
834 TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
835 Int_t nMachineMode = -1;
836 if (machineModeArray){
837 nMachineMode = machineModeArray->GetEntries();
838 if (nMachineMode==0){
839 AliInfo("No Machine Mode found, leaving it empty");
842 for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
843 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
845 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
846 timeMachineModeStart = machineMode->GetTimeStamp();
847 indexMachineMode = iMachineMode;
848 foundMachineModeStart = kTRUE;
855 if (!foundMachineModeStart){
856 AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
859 AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
860 TObjString* machineModeString = machineMode->GetStringArray(0);
861 AliInfo(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
862 grpobj->SetMachineMode(machineModeString->String());
863 if (indexMachineMode < nMachineMode-1){
864 AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
866 if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
867 timeMachineModeEnd = machineMode1->GetTimeStamp();
868 TObjString* machineModeString1 = machineMode1->GetStringArray(0);
869 TString mmString0 = machineModeString->String();
870 TString mmString1 = machineModeString1->String();
871 if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
872 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()));
873 flagMachineMode = kTRUE;
874 arrayTimes[0]=timeMachineModeEnd;
879 AliInfo("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
884 delete machineModeArray;
887 AliError("Machine mode array not found in LHC Data file!!!");
890 // BeamType1 and BeamType2 - both put in the same string
891 Log("*************BeamType ");
892 TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
894 Int_t nBeam = beamArray->GetEntries();
896 AliInfo("No Beam Type found, leaving it empty");
899 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
900 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
902 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
903 timeBeamStart = beam->GetTimeStamp();
905 foundBeamStart = kTRUE;
912 if (!foundBeamStart){
913 AliInfo("No value for the Beam Type found before start of run, the (common) Beam Type will remain empty");
916 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
917 TObjString* beamString = beam->GetStringArray(0);
918 TString beamType = beamString->String();
919 AliInfo(Form("Beam Type = %s",beamType.Data()));
920 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
921 AliInfo("Setting beam type to p-p");
922 grpobj->SetBeamType("p-p");
924 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
925 AliInfo("Setting beam type to A-A");
926 grpobj->SetBeamType("A-A");
929 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
930 AliInfo("Setting beam type to Pb-Pb");
931 grpobj->SetBeamType("Pb-Pb");
934 AliError("Beam Type not known, leaving it empty");
937 if (indexBeam < nBeam-1){
938 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
940 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
941 timeBeamEnd = beam1->GetTimeStamp();
942 TObjString* beamString1 = beam1->GetStringArray(0);
943 TString beamType1 = beamString1->String();
944 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
945 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()));
947 arrayTimes[2] = timeBeamEnd;
952 AliInfo("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
960 AliError("Beam Type array not found in LHC Data file!!!");
963 // BeamType1 and BeamType2 - in separete string
964 Log("*************BeamType, 1 and 2 ");
965 Int_t indexBeamTypeString = 6; // index of the string with the alias of BeanType1 in the array fgkLHCDataPoints
966 TString combinedBeamType = "-"; // combined beam tyope, built from beam type 1 and beam type 2
967 for (Int_t ibeamType = 0; ibeamType<2; ibeamType++){
968 beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[indexBeamTypeString+ibeamType]);
970 Int_t nBeam = beamArray->GetEntries();
972 AliInfo(Form("No Beam Type %s found, leaving it empty",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
975 for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
976 AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
978 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
979 timeBeamTypeStart[ibeamType] = beam->GetTimeStamp();
980 indexBeamType[ibeamType] = iBeam;
981 foundBeamTypeStart[ibeamType] = kTRUE;
988 if (!foundBeamTypeStart[ibeamType]){
989 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));
992 AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
993 TObjString* beamString = beam->GetStringArray(0);
994 TString beamType = beamString->String();
995 AliInfo(Form("Beam Type (for %s) = %s", fgkLHCDataPoints[indexBeamTypeString+ibeamType], beamType.Data()));
996 if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
997 AliInfo(Form("Setting beam type %s to p", fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
998 grpobj->SetSingleBeamType(ibeamType,"p");
999 if (ibeamType == 0) combinedBeamType.Prepend("p");
1000 else combinedBeamType.Append("p");
1002 else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
1003 AliInfo("Setting beam type to A");
1004 grpobj->SetSingleBeamType(ibeamType,"A");
1005 if (ibeamType == 0) combinedBeamType.Prepend("A");
1006 else combinedBeamType.Append("A");
1009 else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
1010 AliInfo("Setting beam type to Pb-Pb");
1011 grpobj->SetSingleBeamType(ibeamType, "Pb-Pb");
1014 AliError("Beam Type not known, leaving it empty");
1017 if (indexBeamType[ibeamType] < nBeam-1){
1018 AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
1020 if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
1021 timeBeamTypeEnd[ibeamType] = beam1->GetTimeStamp();
1022 TObjString* beamString1 = beam1->GetStringArray(0);
1023 TString beamType1 = beamString1->String();
1024 if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
1025 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()));
1026 flagBeamType[ibeamType] = kTRUE;
1027 arrayTimes[3+ibeamType] = timeBeamTypeEnd[ibeamType];
1032 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]));
1040 AliError(Form("Beam Type %s array not found in LHC Data file!!!",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
1043 AliInfo(Form("Setting combined beam type to %s",combinedBeamType.Data()));
1044 grpobj->SetBeamType(combinedBeamType);
1046 // Setting minTimeLHCValidity
1047 if (flagBeamMode == kTRUE || flagMachineMode == kTRUE || flagBeam == kTRUE || flagBeamType[0] == kTRUE || flagBeamType[1] == kTRUE){
1048 Double_t minTimeLHCValidity= TMath::MinElement(5,arrayTimes);
1049 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1050 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1053 if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
1054 Double_t minTimeLHCValidity;
1055 if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true --> it is the only one that changed
1056 minTimeLHCValidity = timeBeamEnd;
1058 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
1059 minTimeLHCValidity = timeMachineModeEnd;
1061 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
1062 minTimeLHCValidity = timeBeamModeEnd;
1064 else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
1065 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
1067 else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
1068 minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
1070 else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
1071 minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
1074 Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam
1075 minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
1077 AliWarning(Form("Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
1078 grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
1082 // Processing data to go to AliLHCData object
1083 AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
1084 // storing AliLHCData in OCDB
1086 AliInfo(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
1088 md.SetResponsible("Ruben Shahoyan");
1089 md.SetComment("LHC data from the GRP preprocessor.");
1090 Bool_t result = kTRUE;
1091 result = Store("GRP", "LHCData", dt, &md);
1094 Log(Form("Problems in storing LHC Data - but not going into Error"));
1098 // processing LHC Phase
1100 TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
1101 TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
1102 if (beam1phase == 0x0 || beam2phase == 0x0){
1103 Log(Form("Problems in retrieving LHC Clock data from LHC file"));
1106 AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
1108 AliInfo(Form("LHC Phase found"));
1109 AliCDBMetaData mdPhase;
1110 mdPhase.SetResponsible("Cvetan Cheshkov");
1111 mdPhase.SetComment("LHC Clock Phase");
1112 Bool_t result = kTRUE;
1113 result = Store("Calib", "LHCClockPhase", phaseObj, &mdPhase);
1115 if (!result) return 3;
1121 AliError("No LHCData file found in DCS FXS");
1128 //_______________________________________________________________
1130 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
1133 //Getting the SPD Mean Vertex
1136 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
1137 Bool_t storeResult = kTRUE;
1138 if (list !=0x0 && list->GetEntries()!=0)
1140 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
1142 for (Int_t jj=0;jj<list->GetEntries();jj++){
1143 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
1145 AliError(Form("Expecting a TObjString in the list for the %d-th source, but something else was found.",jj));
1148 AliInfo(Form("found source %s", str->String().Data()));
1149 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
1150 if (fileNameRun.Length()>0){
1151 AliInfo(Form("Got the file %s", fileNameRun.Data()));
1152 TFile daqFile(fileNameRun.Data(),"READ");
1153 if (daqFile.IsOpen()) {
1154 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
1157 // storing in the OCDB
1159 md.SetResponsible("Cvetan Cheshkov");
1160 md.SetComment("SPD Mean Vertex");
1161 storeResult = Store("Calib", "MeanVertexSPD", meanVtx, &md, 0, kTRUE);
1164 AliWarning("No SPD Mean Vertex object found in file");
1168 AliError("Can't open file");
1169 storeResult = kFALSE;
1173 AliWarning("No file found for current source for SPD Mean Vertex");
1178 AliWarning("No list found for SPD Mean Vertex");
1181 if (list) delete list;
1187 //_______________________________________________________________
1189 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
1191 //Getting the DAQ lb information
1193 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
1194 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
1195 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
1196 TString beamType = (TString)GetRunParameter("beamType");
1197 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
1198 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
1199 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
1200 TString runType = (TString)GetRunType();
1202 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!!!");
1204 UInt_t nparameter = 0;
1205 if (timeStart != 0){
1206 grpObj->SetTimeStart(timeStart);
1207 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
1211 Log(Form("Start time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1215 grpObj->SetTimeEnd(timeEnd);
1216 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
1220 Log(Form("End time not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1223 if (beamEnergy != 0){
1224 Log(Form("Beam Energy for run %d: %f (NOT USING IT TO FILL THE GRP OBJECT, taking it from the LHC file)",fRun, beamEnergy));
1227 Log(Form("Beam Energy not put in logbook, but not using it anyway for the GRP object (taking it from the LHC file)"));
1231 if (beamType.Length() != 0){
1232 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()));
1235 Log(Form("Beam Type not put in logbook, but not using it anyway for the GRP entry (taking it from the LHC file)"));
1238 if (numberOfDetectors != 0){
1239 grpObj->SetNumberOfDetectors(numberOfDetectors);
1240 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
1244 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1247 if (detectorMask != 0){
1248 grpObj->SetDetectorMask(detectorMask);
1249 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
1253 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1256 if (lhcPeriod.Length() != 0) {
1257 grpObj->SetLHCPeriod(lhcPeriod);
1258 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
1262 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1264 if (runType.Length() != 0) {
1265 grpObj->SetRunType(runType);
1266 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
1270 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry, and causing an error!"));
1276 //_______________________________________________________________
1278 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
1280 //======DAQ FXS======//
1282 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
1283 AliRawEventHeaderV3_11::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_11 - temporary fix
1284 TList* list = GetFileSources(kDAQ);
1286 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
1290 if (list->GetEntries() == 0) {
1291 Log("no raw data tags in this run: nothing to merge!");
1292 delete list; list=0;
1296 TChain *fRawTagChain = new TChain("T");
1298 TIterator* iter = list->MakeIterator();
1300 while ((obj = iter->Next())) {
1301 TObjString* objStr = dynamic_cast<TObjString*> (obj);
1303 Log(Form("Found source %s", objStr->String().Data()));
1304 TList* list2 = GetFileIDs(kDAQ, objStr->String());
1306 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
1307 delete fRawTagChain; fRawTagChain=0;
1310 Log(Form("Number of ids: %d",list2->GetEntries()));
1311 for(Int_t i = 0; i < list2->GetEntries(); i++) {
1312 TObjString *idStr = (TObjString *)list2->At(i);
1313 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
1314 if (fileName.Length() > 0) {
1315 Log(Form("Adding file in the chain: %s",fileName.Data()));
1316 fRawTagChain->Add(fileName.Data());
1319 Log(Form("Could not retrieve file with id %s from source %s: "
1320 "connection problems with DAQ FXS!",
1321 idStr->String().Data(), objStr->String().Data()));
1322 delete list; list=0;
1323 delete list2; list2=0;
1324 delete fRawTagChain; fRawTagChain=0;
1332 TString fRawDataFileName = "GRP_Merged.tag.root";
1333 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
1335 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
1336 Log("Error merging raw data files!!!");
1340 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
1341 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
1344 Log("Problem storing raw data tags in local file!!!");
1346 Log("Raw data tags merged successfully!!");
1351 delete fRawTagChain; fRawTagChain=0;
1353 if (result == kFALSE) {
1361 //_______________________________________________________________
1362 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
1365 // processing the info
1366 // stored in the DCS FXS
1367 // coming from the trigger
1369 // Get the CTP counters information
1371 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
1372 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
1373 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
1375 Log(Form("No dummy CTP scalers entry found, going into error..."));
1379 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
1381 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
1385 AliCDBMetaData metaData;
1386 metaData.SetResponsible("Roman Lietava");
1387 metaData.SetComment("CTP scalers from dummy entry in OCDB");
1388 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1389 Log("Unable to store the dummy CTP scalers object to OCDB!");
1396 else if (!partition.IsNull() && detector.IsNull()){ // global partition
1397 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
1398 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
1399 if (countersfile.IsNull()) {
1400 Log("No CTP counters files has been found: empty source!");
1404 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
1405 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
1407 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
1411 AliCDBMetaData metaData;
1412 metaData.SetBeamPeriod(0);
1413 metaData.SetResponsible("Roman Lietava");
1414 metaData.SetComment("CTP scalers");
1415 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
1416 Log("Unable to store the CTP scalers object to OCDB!");
1427 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
1434 //_______________________________________________________________
1436 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
1440 // processing DCS DPs
1443 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
1444 Int_t nL3Entries = 0;
1445 Int_t nDipoleEntries = 0;
1446 Int_t nEnvEntries = 0;
1447 Int_t nHallProbesEntries = 0;
1448 nL3Entries = ProcessL3DPs(valueMap, grpObj);
1449 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
1450 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
1451 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
1452 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
1453 Log(Form("L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
1454 entries = nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
1459 //_______________________________________________________________
1461 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
1468 Int_t nL3Entries = 0;
1470 TObjArray *array = 0x0;
1472 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1474 AliInfo(Form("==========L3Current==========="));
1475 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1476 indexDP = kL3Current;
1477 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1479 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1482 if (array->GetEntries() == 0){
1483 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1486 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1487 if (floatDCS != NULL){
1488 grpObj->SetL3Current(floatDCS);
1500 ffailedDPs->RemoveAt(indexDP);
1504 if (array) array = 0x0;
1506 AliInfo(Form("==========L3Polarity==========="));
1507 indexDP = kL3Polarity;
1508 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1510 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1513 if (array->GetEntries() == 0){
1514 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
1517 Bool_t change = kFALSE;
1518 Char_t charDCS = ProcessBool(array,change);
1519 if (change == kFALSE){
1520 grpObj->SetL3Polarity(charDCS);
1521 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
1522 ffailedDPs->RemoveAt(indexDP);
1526 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1527 ffailedDPs->RemoveAt(indexDP);
1531 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]));
1539 //_______________________________________________________________
1541 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
1547 Int_t nDipoleEntries = 0;
1548 TObjArray *array = 0x0;
1550 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
1552 AliInfo(Form("==========DipoleCurrent==========="));
1553 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1554 indexDP = kDipoleCurrent;
1555 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1557 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1560 if (array->GetEntries() == 0){
1561 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1564 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
1565 if (floatDCS != NULL){
1566 grpObj->SetDipoleCurrent(floatDCS);
1578 ffailedDPs->RemoveAt(indexDP);
1582 if (array) array = 0x0;
1584 AliInfo(Form("==========DipolePolarity==========="));
1585 indexDP = kDipolePolarity;
1586 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1588 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1591 if (array->GetEntries() == 0){
1592 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1595 Bool_t change = kFALSE;
1596 Char_t charDCS = ProcessBool(array,change);
1598 grpObj->SetDipolePolarity(charDCS);
1599 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1600 ffailedDPs->RemoveAt(indexDP);
1604 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1605 ffailedDPs->RemoveAt(indexDP);
1609 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]));
1614 return nDipoleEntries;
1617 //_______________________________________________________________
1619 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1623 // evironment conditions (temperature, pressure) info
1625 Int_t nEnvEntries = 0;
1626 TObjArray *array = 0x0;
1629 AliInfo(Form("==========CavernTemperature==========="));
1630 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1631 indexDP = kCavernTemperature;
1632 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1634 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1637 if (array->GetEntries() == 0){
1638 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1641 Float_t *floatDCS = ProcessFloatAll(array);
1642 if (floatDCS != NULL){
1643 grpObj->SetCavernTemperature(floatDCS);
1654 ffailedDPs->RemoveAt(indexDP);
1659 if (array) array = 0x0;
1661 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1662 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1663 //dcsSensorArray->Print();
1664 if( fPressure->NumFits()<kNumSensors ) {
1665 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1667 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1669 AliInfo(Form("==========CavernAtmosPressure==========="));
1670 indexDP = kCavernAtmosPressure;
1671 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1672 TGraph* graph = sensorCavernP2->GetGraph();
1673 AliDebug(3,Form("index = %d",indexDP));
1674 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1675 AliDebug(2,Form("graph = %p",graph));
1676 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1677 if(sensorCavernP2->GetFit() || graph) {
1678 if (sensorCavernP2->GetFit()){
1679 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1682 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1684 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1685 ffailedDPs->RemoveAt(indexDP);
1688 //if (sensorP2) delete sensorP2;
1690 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] ));
1693 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1694 indexDP = kSurfaceAtmosPressure;
1695 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1696 graph = sensorP2->GetGraph();
1697 AliDebug(3,Form("index = %d",indexDP));
1698 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1699 AliDebug(2,Form("graph = %p",graph));
1700 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1701 if(sensorP2->GetFit() || graph) {
1702 if (sensorP2->GetFit()){
1703 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1706 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1708 grpObj->SetSurfaceAtmosPressure(sensorP2);
1709 ffailedDPs->RemoveAt(indexDP);
1712 //if (sensorP2) delete sensorP2;
1714 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] ));
1717 AliInfo(Form("==========CavernAtmosPressure2==========="));
1718 indexDP = kCavernAtmosPressure2;
1719 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1720 graph = sensorCavernP22->GetGraph();
1721 AliDebug(3,Form("index = %d",indexDP));
1722 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1723 AliDebug(2,Form("graph = %p",graph));
1724 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1725 if(sensorCavernP22->GetFit() || graph) {
1726 if (sensorCavernP22->GetFit()){
1727 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1730 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1732 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1733 ffailedDPs->RemoveAt(indexDP);
1736 //if (sensorP2) delete sensorP2;
1738 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] ));
1744 //_______________________________________________________________
1746 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1752 Int_t nHPEntries = 0;
1753 TObjArray *array = 0x0;
1755 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1757 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1758 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()));
1760 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1761 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1762 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1763 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1765 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1768 if (array->GetEntries() == 0){
1769 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1772 Float_t *floatDCS = ProcessFloatAll(array);
1773 if (floatDCS != NULL){
1774 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]));
1775 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1776 for (Int_t kk = 0 ; kk< 5; kk++){
1777 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1789 ffailedDPs->RemoveAt(indexDP + fgkDCSDPHallTopShift); // 7 = shift in the complete list of DPs to get to the Hall Probes
1795 Log(Form("Hall Probes = %d ", nHPEntries));
1799 //_________________________________________________________________________
1801 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1805 // returning Spline Fit
1808 Int_t entriesarray = array->GetEntries();
1809 Float_t* value = new Float_t[entriesarray];
1810 Float_t* time = new Float_t[entriesarray];
1811 AliDCSValue* v = 0x0;
1812 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1813 v = (AliDCSValue*)array->At(iarray);
1814 value[iarray] = v->GetFloat();
1815 time[iarray] = v->GetTimeStamp();
1816 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1818 TGraph* gr = new TGraph(entriesarray,value,time);
1820 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1823 AliSplineFit *fit = new AliSplineFit();
1824 fit->SetMinPoints(10);
1825 fit->InitKnots(gr,10,10,0.0);
1831 //_________________________________________________________________________
1833 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1840 TString aDCSString="";
1842 AliDCSValue *v = 0x0;
1843 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1844 v = (AliDCSValue *)array->At(iCount);
1845 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1846 AliError(Form("DCS values for the parameter outside the queried interval"));
1850 if (aDCSString != v->GetChar())
1851 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1853 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1858 //__________________________________________________________________________________________________________________
1860 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1863 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1865 // parameters[0] = mean
1866 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1867 // parameters[2] = median
1868 // parameters[3] = standard deviation wrt mean
1869 // parameters[4] = standard deviation wrt median
1872 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1873 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1874 if (timeStartString.IsNull() || timeStartString.IsNull()){
1875 if (timeStartString.IsNull()){
1876 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1878 else if (timeStartString.IsNull()){
1879 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1881 fdaqStartEndTimeOk = kFALSE;
1885 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1886 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1887 Float_t* parameters = new Float_t[5];
1889 Int_t iCountsRun = 0;
1890 Int_t nCounts = array->GetEntries();
1891 Float_t valueBeforeSOR = 0;
1892 Float_t valueAfterEOR = 0;
1893 Int_t timestampBeforeSOR = -1;
1894 Int_t timestampAfterEOR = -1;
1895 Int_t ientrySOR = -1;
1896 Int_t ientryEOR = -1;
1897 Float_t* arrayValues = 0x0;
1898 Double_t* arrayWeights = 0x0;
1899 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1900 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1902 for(Int_t i = 0; i < nCounts; i++) {
1903 AliDCSValue *v = (AliDCSValue *)array->At(i);
1904 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1905 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1906 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1907 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1908 delete [] parameters;
1911 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1912 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1914 // look for the last value before SOR and the first value before EOR
1915 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1916 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1917 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1918 valueBeforeSOR = v->GetFloat();
1920 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1921 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1922 valueAfterEOR = v->GetFloat();
1923 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1925 // check if there are DPs between DAQ_time_start and DAQ_time_end
1926 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1927 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1928 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1929 AliDebug(2,Form("entry between SOR and EOR"));
1934 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1938 if (timestampBeforeSOR == -1){
1939 AliWarning("No value found before SOR");
1941 if (timestampAfterEOR == -1){
1942 AliWarning("No value found after EOR");
1945 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1946 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1947 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1948 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1949 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1950 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1952 Int_t nentriesUsed = 0;
1953 if (iCountsRun > 1){
1954 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1955 AliDebug(2,"Calculating (weighted) Mean and Median");
1956 arrayValues = new Float_t[iCountsRun];
1957 arrayWeights = new Double_t[iCountsRun];
1958 nentriesUsed = iCountsRun;
1959 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1960 AliDCSValue *v = (AliDCSValue *)array->At(i);
1961 Int_t timestamp2 = 0;
1963 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1964 timestamp2 = (Int_t)v1->GetTimeStamp();
1967 timestamp2 = timeEnd+1;
1969 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1970 arrayValues[i-ientrySOR] = v->GetFloat();
1972 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1973 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1975 else if (iCountsRun == 1){
1976 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1978 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1979 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.");
1980 arrayValues = new Float_t[2];
1981 arrayWeights = new Double_t[2];
1982 arrayValues[0] = valueBeforeSOR;
1983 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1984 arrayValues[1] = v->GetFloat();
1985 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1986 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1987 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1988 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1989 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1990 truncMeanFlag = kFALSE;
1993 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");
1994 parameters[0] = AliGRPObject::GetInvalidFloat();
1995 parameters[1] = AliGRPObject::GetInvalidFloat();
1996 parameters[2] = AliGRPObject::GetInvalidFloat();
1997 parameters[3] = AliGRPObject::GetInvalidFloat();
1998 parameters[4] = AliGRPObject::GetInvalidFloat();
2002 else { // iCountsRun == 0, using only the point immediately before SOR
2003 if (timestampBeforeSOR == -1){
2004 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");
2005 parameters[0] = AliGRPObject::GetInvalidFloat();
2006 parameters[1] = AliGRPObject::GetInvalidFloat();
2007 parameters[2] = AliGRPObject::GetInvalidFloat();
2008 parameters[3] = AliGRPObject::GetInvalidFloat();
2009 parameters[4] = AliGRPObject::GetInvalidFloat();
2013 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
2014 AliDebug(2,Form("value = %f",valueBeforeSOR));
2015 parameters[0] = valueBeforeSOR;
2016 parameters[2] = valueBeforeSOR;
2017 truncMeanFlag = kFALSE;
2024 Float_t sumweights = 0;
2025 Int_t entriesTruncMean = 0;
2026 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
2027 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
2029 // calculating SD wrt Mean and Median
2030 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
2032 for (Int_t i =0; i< nentriesUsed; i++){
2033 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2034 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
2035 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
2036 sumweights += arrayWeights[i];
2038 // setting SD wrt Mean
2039 if (sumweights != 0 ){
2040 parameters[3] = TMath::Sqrt(temp1/sumweights);
2043 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
2044 parameters[3] = AliGRPObject::GetInvalidFloat();
2046 // setting SD wrt Median
2047 if (nentriesUsed != 0){
2048 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
2051 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
2052 parameters[4] = AliGRPObject::GetInvalidFloat();
2056 parameters[3] = AliGRPObject::GetInvalidFloat();
2057 parameters[4] = AliGRPObject::GetInvalidFloat();
2060 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
2062 AliDebug(2,"Calculating Truncated Mean");
2063 for (Int_t i =0; i< nentriesUsed; i++){
2064 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
2065 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
2066 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
2067 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
2068 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
2072 AliDebug(2,"Discarding entry");
2075 // setting truncated mean
2076 if (entriesTruncMean >1){
2077 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
2078 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
2081 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
2082 parameters[1] = AliGRPObject::GetInvalidFloat();
2086 parameters[1] = AliGRPObject::GetInvalidFloat();
2090 delete [] arrayValues;
2093 delete [] arrayWeights;
2095 delete [] arrayValuesTruncMean;
2096 delete [] arrayWeightsTruncMean;
2098 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
2099 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
2100 AliInfo(Form("median = %f ",parameters[2]));
2101 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
2102 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
2107 //__________________________________________________________________________________________________________________
2109 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
2112 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
2113 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
2114 // the flag is set according to the L3/Dipole current value
2115 // current threshold for L3 = 350 A (value provided by DCS)
2116 // current threshold for Dipole = 450 A (value provided by DCS)
2118 // parameters[0] = mean
2119 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
2120 // parameters[2] = median
2121 // parameters[3] = standard deviation wrt mean
2122 // parameters[4] = standard deviation wrt median
2125 AliInfo(Form("indexDP = %d",indexDP));
2127 Int_t nCounts = array->GetEntries();
2128 for(Int_t i = 0; i < nCounts; i++) {
2129 AliDCSValue *v = (AliDCSValue *)array->At(i);
2130 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
2131 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
2132 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
2133 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
2136 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2137 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
2138 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
2139 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
2142 AliError(Form("DCS values for the parameter outside the queried interval"));
2146 return ProcessFloatAll(array);
2150 //_______________________________________________________________
2152 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
2155 // processing Boolean values
2158 Bool_t aDCSBool = kTRUE;
2160 AliDCSValue *v = 0x0;
2162 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
2163 v = (AliDCSValue *)array->At(iCount);
2164 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
2165 AliError(Form("DCS values for the parameter outside the queried interval"));
2169 if (aDCSBool != v->GetBool()) {
2170 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
2174 aDCSBool = v->GetBool(); // always keeping last value
2175 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
2178 Char_t caDCSBool = (Char_t) aDCSBool;
2183 //_______________________________________________________________
2185 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
2188 // processing Int values, returning mean
2189 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2190 // are outside the queried time interval or their value is out of range
2193 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2194 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2195 if (timeStartString.IsNull() || timeStartString.IsNull()){
2196 if (timeStartString.IsNull()){
2197 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2199 else if (timeStartString.IsNull()){
2200 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2205 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2206 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2207 Float_t aDCSArrayMean = 0.0;
2209 Float_t valueBeforeSOR = 0;
2210 Float_t valueAfterEOR = 0;
2211 Int_t timestampBeforeSOR = -1;
2212 Int_t timestampAfterEOR = -1;
2213 Int_t ientrySOR = -1;
2214 Int_t ientryEOR = -1;
2215 Float_t* arrayValues = 0x0;
2216 Double_t* arrayWeights = 0x0;
2217 Int_t iCountsRun = 0;
2218 Int_t nCounts = array->GetEntries();
2220 for(Int_t i = 0; i < nCounts; i++) {
2221 AliDCSValue* v = (AliDCSValue *)array->At(i);
2222 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
2223 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
2224 return AliGRPObject::GetInvalidFloat();
2226 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2227 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
2229 // look for the last value before SOR and the first value before EOR
2230 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2231 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2232 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2233 valueBeforeSOR = (Float_t) v->GetInt();
2235 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2236 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2237 valueAfterEOR = (Float_t) v->GetInt();
2238 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2240 // check if there are DPs between DAQ_time_start and DAQ_time_end
2241 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2242 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2243 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2244 AliDebug(2,Form("entry between SOR and EOR"));
2249 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2253 if (timestampBeforeSOR == -1){
2254 AliWarning("No value found before SOR!");
2256 if (timestampAfterEOR == -1){
2257 AliWarning("No value found after EOR!");
2260 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2261 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2262 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2263 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2264 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2265 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2267 Int_t nentriesUsed = 0;
2268 if (iCountsRun > 1){
2269 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2270 AliDebug(2,"Calculating (weighted) Mean");
2271 arrayValues = new Float_t[iCountsRun];
2272 arrayWeights = new Double_t[iCountsRun];
2273 nentriesUsed = iCountsRun;
2274 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2275 AliDCSValue *v = (AliDCSValue *)array->At(i);
2276 Int_t timestamp2 = 0;
2278 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2279 timestamp2 = (Int_t)v1->GetTimeStamp();
2282 timestamp2 = timeEnd+1;
2284 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2285 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
2287 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2288 delete [] arrayValues;
2289 delete [] arrayWeights;
2291 else if (iCountsRun == 1){
2292 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2294 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2295 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2296 arrayValues = new Float_t[2];
2297 arrayWeights = new Double_t[2];
2298 arrayValues[0] = valueBeforeSOR;
2299 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2300 arrayValues[1] = (Float_t)v->GetInt();
2301 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2302 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2303 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2304 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2305 delete [] arrayValues;
2306 delete [] arrayWeights;
2309 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2310 return AliGRPObject::GetInvalidFloat();
2313 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2314 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2315 if (timestampBeforeSOR == -1){
2316 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2318 if (timestampAfterEOR == -1){
2319 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2321 return AliGRPObject::GetInvalidFloat();
2324 AliWarning("Using last entry before SOR and first entry after EOR.");
2326 arrayValues = new Float_t[2];
2327 arrayWeights = new Double_t[2];
2328 arrayValues[0] = valueBeforeSOR;
2329 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2330 arrayValues[1] = valueAfterEOR;
2331 arrayWeights[1] = 1.;
2332 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2333 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2334 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2335 delete [] arrayValues;
2336 delete [] arrayWeights;
2340 AliInfo(Form("mean = %f ", aDCSArrayMean));
2341 return aDCSArrayMean;
2344 //_______________________________________________________________
2346 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
2349 // processing Int values, returning mean
2350 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
2351 // are outside the queried time interval or their value is out of range
2354 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
2355 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
2356 if (timeStartString.IsNull() || timeStartString.IsNull()){
2357 if (timeStartString.IsNull()){
2358 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
2360 else if (timeStartString.IsNull()){
2361 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
2366 Int_t timeStart = (Int_t)(timeStartString.Atoi());
2367 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
2368 Float_t aDCSArrayMean = 0.0;
2370 Float_t valueBeforeSOR = 0;
2371 Float_t valueAfterEOR = 0;
2372 Int_t timestampBeforeSOR = -1;
2373 Int_t timestampAfterEOR = -1;
2374 Int_t ientrySOR = -1;
2375 Int_t ientryEOR = -1;
2376 Float_t* arrayValues = 0x0;
2377 Double_t* arrayWeights = 0x0;
2378 Int_t iCountsRun = 0;
2379 Int_t nCounts = array->GetEntries();
2381 for(Int_t i = 0; i < nCounts; i++) {
2382 AliDCSValue* v = (AliDCSValue *)array->At(i);
2383 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
2384 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
2385 return AliGRPObject::GetInvalidFloat();
2387 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
2388 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
2390 // look for the last value before SOR and the first value before EOR
2391 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
2392 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
2393 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
2394 valueBeforeSOR = (Float_t)v->GetUInt();
2396 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
2397 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
2398 valueAfterEOR = (Float_t)v->GetUInt();
2399 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
2401 // check if there are DPs between DAQ_time_start and DAQ_time_end
2402 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
2403 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
2404 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
2405 AliDebug(2,Form("entry between SOR and EOR"));
2410 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
2414 if (timestampBeforeSOR == -1){
2415 AliWarning("No value found before SOR!");
2417 if (timestampAfterEOR == -1){
2418 AliWarning("No value found after EOR!");
2421 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
2422 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
2423 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
2424 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
2425 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
2426 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
2428 Int_t nentriesUsed = 0;
2429 if (iCountsRun > 1){
2430 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
2431 AliDebug(2,"Calculating (weighted) Mean");
2432 arrayValues = new Float_t[iCountsRun];
2433 arrayWeights = new Double_t[iCountsRun];
2434 nentriesUsed = iCountsRun;
2435 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
2436 AliDCSValue *v = (AliDCSValue *)array->At(i);
2437 Int_t timestamp2 = 0;
2439 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
2440 timestamp2 = (Int_t)v1->GetTimeStamp();
2443 timestamp2 = timeEnd+1;
2445 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
2446 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
2448 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
2449 delete [] arrayValues;
2450 delete [] arrayWeights;
2452 else if (iCountsRun == 1){
2453 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
2455 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
2456 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
2457 arrayValues = new Float_t[2];
2458 arrayWeights = new Double_t[2];
2459 arrayValues[0] = valueBeforeSOR;
2460 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
2461 arrayValues[1] = (Float_t)v->GetUInt();
2462 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
2463 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2464 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2465 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
2466 delete [] arrayValues;
2467 delete [] arrayWeights;
2470 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2471 return AliGRPObject::GetInvalidFloat();
2474 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2475 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2476 if (timestampBeforeSOR == -1){
2477 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2479 if (timestampAfterEOR == -1){
2480 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2482 return AliGRPObject::GetInvalidFloat();
2485 AliWarning("Using last entry before SOR and first entry after EOR.");
2487 arrayValues = new Float_t[2];
2488 arrayWeights = new Double_t[2];
2489 arrayValues[0] = valueBeforeSOR;
2490 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2491 arrayValues[1] = valueAfterEOR;
2492 arrayWeights[1] = 1.;
2493 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2494 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2495 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2496 delete [] arrayValues;
2497 delete [] arrayWeights;
2501 AliInfo(Form("mean = %f ",aDCSArrayMean));
2502 return aDCSArrayMean;
2507 //_______________________________________________________________
2509 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2511 // extract DCS pressure maps. Perform fits to save space
2513 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2515 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2516 fPressure->MakeSplineFit(map);
2517 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2518 if (fitFraction > kFitFraction ) {
2519 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2521 AliInfo("Too few pressure maps fitted!!!");
2524 AliInfo("no atmospheric pressure map extracted!!!");
2533 //_______________________________________________________________
2534 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)
2537 // Retrieves logbook and trigger information from the online logbook
2538 // This information is needed for prompt reconstruction
2542 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2546 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2547 // 0 on success and no run was found
2548 // negative on error
2550 // This function is NOT called during the preprocessor run in the Shuttle!
2558 AliCDBManager* cdb = AliCDBManager::Instance();
2559 cdb->SetDefaultStorage(cdbRoot);
2562 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2566 Printf("ERROR: Could not connect to DAQ LB");
2572 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
2573 TSQLResult* result = server->Query(sqlQuery);
2576 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2580 if (result->GetRowCount() == 0)
2582 Printf("ERROR: Run %d not found", run);
2587 TSQLRow* row = result->Next();
2590 Printf("ERROR: Could not receive data from run %d", run);
2595 TString timeStartString(row->GetField(0));
2596 TString runType(row->GetField(1));
2597 TString detectorMaskString(row->GetField(2));
2598 TString l3CurrentString(row->GetField(3));
2599 TString dipoleCurrentString(row->GetField(4));
2600 TString beamTypeString(row->GetField(5));
2601 time_t timeStart = (time_t)(timeStartString.Atoi());
2602 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2603 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2604 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2605 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2606 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2607 if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
2608 beamTypeString="A-A";
2611 AliGRPObject * grpObj = new AliGRPObject();
2612 grpObj->SetTimeStart(timeStart);
2613 grpObj->SetRunType((TString)(row->GetField(1)));
2614 grpObj->SetDetectorMask(detectorMask);
2615 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2616 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2617 grpObj->SetL3Polarity(l3Polarity);
2618 grpObj->SetDipolePolarity(dipolePolarity);
2619 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2620 grpObj->SetBeamType(beamTypeString);
2628 Printf("Storing GRP/GRP/Data object with the following content");
2631 AliCDBMetaData metadata;
2632 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2633 metadata.SetComment("GRP Output parameters received during online running");
2635 AliCDBId id("GRP/GRP/Data", run, run);
2636 Bool_t success = cdb->Put(grpObj, id, &metadata);
2642 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2646 // Receive trigger information
2647 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2648 result = server->Query(sqlQuery);
2651 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2655 if (result->GetRowCount() == 0)
2657 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2662 row = result->Next();
2665 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2670 TString triggerConfig(row->GetField(0));
2678 Printf("Found trigger configuration: %s", triggerConfig.Data());
2680 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2683 Printf("ERROR: Could not create CTP configuration object");
2687 metadata.SetComment("CTP run configuration received during online running");
2689 AliCDBId id2("GRP/CTP/Config", run, run);
2690 success = cdb->Put(runcfg, id2, &metadata);
2697 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2702 // Receive list of GDCs for this run
2703 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2704 result = server->Query(sqlQuery);
2707 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2711 if (result->GetRowCount() == 0)
2713 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2719 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2720 row = result->Next();
2723 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2727 gdc += row->GetField(0);
2737 Printf("Found GDC: %s", gdc.Data());
2739 // get last run with same run type that was already processed by the SHUTTLE
2741 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());
2742 result = server->Query(sqlQuery);
2745 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2749 if (result->GetRowCount() == 0)
2751 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2756 row = result->Next();
2759 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2764 TString lastRunStr(row->GetField(0));
2765 Int_t lastRun = lastRunStr.Atoi();
2767 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
2781 //------------------------------------------------------------------------------------------------------
2782 Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeStart){
2785 // Method to processo LHC Energy information
2786 // Only the first value is returned, provided that it is withing DAQ_time_start and DAQ_time_end
2789 Int_t nCounts = array->GetEntries();
2790 Float_t energy = -1;
2791 Double_t timeEnergy = -1;
2792 Int_t indexEnergy = -1;
2793 Bool_t foundEnergy = kFALSE;
2795 AliDebug(2,Form("Energy measurements = %d\n",nCounts));
2797 AliWarning("No Energy values found! Beam Energy remaining invalid!");
2800 for (Int_t i = 0; i < nCounts; i++){
2801 AliDCSArray *dcs = (AliDCSArray*)array->At(i);
2803 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
2804 timeEnergy = dcs->GetTimeStamp();
2806 foundEnergy = kTRUE;
2814 AliInfo("No value for the Energy found before start of run, the Energy will remain invalid");
2817 AliDCSArray* dcs = (AliDCSArray*)array->At(indexEnergy);
2818 energy = (Float_t)(TMath::Nint(((Double_t)(dcs->GetInt(0)))*120/1000)); // sqrt(s)/2 energy in GeV
2819 AliInfo(Form("Energy value found = %d (at %f), converting --> sqrt(s)/2 = %f (GeV)", dcs->GetInt(0),dcs->GetTimeStamp(),energy));
2825 //------------------------------------------------------------------------------------------------------
2826 AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
2829 // Method to process LHC-Clock Phase data
2830 // Only the values between DAQ_time_start and DAQ_time_end are kept
2832 AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
2834 Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
2835 const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one
2837 TString timeCreatedStr = GetRunParameter("time_created");
2838 Double_t timeCreated = timeCreatedStr.Atof();
2840 Int_t nCounts = beam1phase->GetEntries();
2841 AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
2843 AliWarning("No beam1 LHC clock phase values found!");
2848 Double_t prevPhase = 0;
2849 for (Int_t i = 0; i < nCounts; i++){
2850 AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
2852 //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
2853 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2854 if ((i == 0) || (i == (nCounts-1)) ||
2856 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2857 prevPhase = dcs->GetDouble(0);
2858 foundBeam1Phase = kTRUE;
2859 AliInfo(Form("B1 Clk Phase = %f at TS = %f",
2860 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2861 phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2866 if (!foundBeam1Phase){
2867 AliError("No beam1 LHC clock phase values found within the run!");
2873 nCounts = beam2phase->GetEntries();
2874 AliDebug(2,Form("Beam2 phase measurements = %d\n",nCounts));
2876 AliWarning("No beam2 LHC clock phase values found!");
2881 Double_t prevPhase = 0;
2882 for (Int_t i = 0; i < nCounts; i++){
2883 AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
2885 if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
2886 if ((i == 0) || (i == (nCounts-1)) ||
2888 (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
2889 prevPhase = dcs->GetDouble(0);
2890 foundBeam2Phase = kTRUE;
2891 AliInfo(Form("B2 Clk Phase = %f at TS = %f",
2892 (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));
2893 phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
2898 if (!foundBeam2Phase){
2899 AliError("No beam2 LHC clock phase values found within the run!");