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>
36 #include "AliGRPPreprocessor.h"
37 #include "AliGRPObject.h"
38 #include "AliDCSSensor.h"
39 #include "AliSplineFit.h"
40 #include "AliDCSSensorArray.h"
41 #include "AliRawEventHeaderVersions.h"
43 #include "AliTriggerConfiguration.h"
44 #include "AliTriggerRunScalers.h"
46 #include "AliCDBMetaData.h"
50 class AliShuttleInterface;
52 // needed for ReceivePromptRecoParameters
54 #include <TSQLServer.h>
55 #include <TSQLResult.h>
57 #include <AliCDBManager.h>
58 #include <AliCDBMetaData.h>
60 #include <AliTriggerConfiguration.h>
61 #include <AliCTPTimeParams.h>
63 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
65 ClassImp(AliGRPPreprocessor)
67 //_______________________________________________________________
69 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook for PHYSICS runs, when beamType from DAQ logbook == NULL
70 const Int_t AliGRPPreprocessor::fgknDAQLbParReduced = 7; // num parameters in the logbook for the other cases
71 const Int_t AliGRPPreprocessor::fgknDCSDP = 51; // number of dcs dps
72 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
73 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
74 "LHCState", // missing in DCS
77 "LHCLuminosity", // missing in DCS
78 "BeamIntensity", // missing in DCS
84 "L3_BSF17_Temperature",
88 "L3_BSF4_Temperature",
92 "L3_BKF17_Temperature",
96 "L3_BKF4_Temperature",
100 "L3_BSF13_Temperature",
104 "L3_BSF8_Temperature",
108 "L3_BKF13_Temperature",
112 "L3_BKF8_Temperature",
116 "Dipole_Inside_Temperature",
120 "Dipole_Outside_Temperature",
122 "CavernAtmosPressure",
123 "SurfaceAtmosPressure",
124 "CavernAtmosPressure2"
127 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
131 "L3_BSF17_Temperature",
135 "L3_BSF4_Temperature",
139 "L3_BKF17_Temperature",
143 "L3_BKF4_Temperature",
147 "L3_BSF13_Temperature",
151 "L3_BSF8_Temperature",
155 "L3_BKF13_Temperature",
159 "L3_BKF8_Temperature",
163 "Dipole_Inside_Temperature",
167 "Dipole_Outside_Temperature"
170 const Short_t kSensors = 48; // start index position of sensor in DCS DPs
171 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
174 const char* AliGRPPreprocessor::fgkLHCState[20] = {
180 "U", "UNSTABLE BEAMS",
187 const char* kppError[] = {
189 "(DAQ logbook ERROR)",
191 "(Trigger Scalers not found in DCS FXS - ERROR)",
192 "(DCS data points ERROR)",
193 "(Trigger Configuration ERROR)",
194 "(DAQ logbook ERROR determining partition of the run)",
198 //_______________________________________________________________
200 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
201 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))
203 // constructor - shuttle must be instantiated!
205 AddRunType("COSMIC");
207 AddRunType("PHYSICS");
208 AddRunType("CALIBRATION_BC");
209 AddRunType("CALIBRATION_CENTRAL");
210 AddRunType("CALIBRATION_EMD");
211 AddRunType("CALIBRATION_MB");
212 AddRunType("CALIBRATION_SEMICENTRAL");
213 AddRunType("CALIBRATION");
214 AddRunType("PEDESTAL");
215 AddRunType("STANDALONE");
218 AddRunType("PULSER");
219 AddRunType("STANDALONE_PULSER");
220 AddRunType("STANDALONE_BC");
223 fminFloat = -FLT_MAX;
224 fmaxDouble = DBL_MAX;
225 fminDouble = -DBL_MAX;
231 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
232 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
233 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
234 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
235 AliInfo(Form("Max allowed integer = %d",fmaxInt));
236 AliInfo(Form("Min allowed integer = %d",fminInt));
237 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
238 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
240 ffailedDPs->SetOwner(kTRUE);
243 //_______________________________________________________________
245 AliGRPPreprocessor::~AliGRPPreprocessor()
254 //_______________________________________________________________
256 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
258 // Initialize preprocessor
260 AliPreprocessor::Initialize(run, startTime, endTime);
262 AliInfo("Initialization of the GRP preprocessor.");
263 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
264 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
265 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
266 for(Int_t j = 0; j < kNumSensors; j++) {
267 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
268 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
270 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
272 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
274 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
275 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
276 ffailedDPs->AddAt(dp,iDP);
281 //_______________________________________________________________
283 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
285 // process data retrieved by the Shuttle
287 // retrieving "partition" and "detector" fields from DAQ logbook to
288 // determine the partition in which the run was taken
289 // the partition is used to decide how to react in case of errors for CTP
291 TString partition = (TString)GetRunParameter("partition");
292 TString detector = (TString)GetRunParameter("detector");
294 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
295 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
296 //=================//
298 //=================//
301 Int_t iDaqLB = ProcessDaqLB(grpobj);
302 TString runType = (TString)GetRunType();
303 TString beamType = (TString)GetRunParameter("beamType");
304 //if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
305 if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && !beamType.IsNull()) || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType.IsNull()) || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
306 Log(Form("DAQ Logbook, successful!"));
308 Log(Form("DAQ Logbook, could not get all expected entries!!!"));
312 //=================//
314 //=================//
315 UInt_t iDaqFxs = ProcessDaqFxs();
317 Log(Form("DAQ FXS, successful!"));
319 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
323 //=================//
325 //=================//
326 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
328 Log(Form("DCS FXS, successful!"));
329 } else if (iDcsFxs ==1) {
330 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
333 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
337 //=================//
338 // DCS data points //
339 //=================//
340 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
341 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
342 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-4));
343 if (fdaqStartEndTimeOk){
344 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, L3_BSF4_H3 are not working yet...
345 Log(Form("Problem with the DCS data points!!! Only %d/%d entries found",entries,fgknDCSDP-4));
346 Log(Form("The DPs giving problems were:"));
347 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
348 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
350 TString name = dpString->String();
351 if (name != "LHCState" && name != "LHCLuminosity" && name != "BeamIntensity" && name != "L3_BSF4_H3"){
352 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
355 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()));
361 else Log(Form("DCS data points, successful!"));
363 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"));
365 //=======================//
366 // Trigger Configuration //
367 //=======================//
369 const char * triggerConf = GetTriggerConfiguration();
371 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
372 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
373 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
375 Log(Form("No dummy CTP configuration entry found, going into error..."));
379 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
381 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
385 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
386 runcfg->SetTitle(titleCTPcfg);
387 AliCDBMetaData metaData;
388 metaData.SetResponsible("Roman Lietava");
389 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
390 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
391 Log("Unable to store the dummy CTP run configuration object to OCDB!");
398 else if (!partition.IsNull() && detector.IsNull()){ // global partition
399 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
400 if (triggerConf!= NULL) {
401 Log("Found trigger configuration in DAQ logbook");
402 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
404 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
408 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
409 runcfg->SetTitle(titleCTPcfg);
410 AliCDBMetaData metaData;
411 metaData.SetBeamPeriod(0);
412 metaData.SetResponsible("Roman Lietava");
413 metaData.SetComment("CTP run configuration from DAQ logbook");
414 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
415 Log("Unable to store the CTP run configuration object to OCDB!");
422 Log("Trigger configuration NULL in DAQ logbook");
428 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
432 //===========================//
433 // Trigger Timing Parameters //
434 //===========================//
437 const char * triggerCTPtiming = GetCTPTimeParams();
439 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
440 Log("STANDALONE partition for current run, using CTP timing params dummy value");
441 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
443 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
447 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
449 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
453 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
454 runCTPtiming->SetTitle(titleCTPtiming);
455 AliCDBMetaData metadata;
456 metadata.SetResponsible("Roman Lietava");
457 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
458 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
459 Log("Unable to store the dummy CTP timing params object to OCDB!");
466 else if (!partition.IsNull() && detector.IsNull()){ // global partition
467 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
468 if (triggerCTPtiming!= NULL) {
469 Log("Found trigger timing params in DAQ logbook");
470 AliDebug(2,Form("%s",triggerCTPtiming));
471 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
473 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
477 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
478 runCTPtiming->SetTitle(titleCTPtiming);
479 AliCDBMetaData metadata;
480 metadata.SetBeamPeriod(0);
481 metadata.SetResponsible("Roman Lietava");
482 metadata.SetComment("CTP timing params from DAQ logbook");
483 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
484 Log("Unable to store the CTP timing params object to OCDB!");
491 Log("Trigger timing params NULL in DAQ logbook");
497 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
500 // storing AliGRPObject in OCDB
503 md.SetResponsible("Chiara Zampolli");
504 md.SetComment("Output parameters from the GRP preprocessor.");
506 Bool_t result = kTRUE;
507 result = Store("GRP", "Data", grpobj, &md);
510 if (result && !error ) {
511 Log("GRP Preprocessor Success");
514 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s",
515 kppError[(error&1)?1:0],
516 kppError[(error&2)?2:0],
517 kppError[(error&4)?3:0],
518 kppError[(error&8)?4:0],
519 kppError[(error&16)?5:0],
520 kppError[(error&32)?6:0],
521 kppError[(error&64)?7:0]
527 //_______________________________________________________________
529 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
531 //Getting the DAQ lb information
533 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
534 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
535 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
536 TString beamType = (TString)GetRunParameter("beamType");
537 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
538 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
539 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
540 TString runType = (TString)GetRunType();
542 UInt_t nparameter = 0;
544 grpObj->SetTimeStart(timeStart);
545 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
549 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
553 grpObj->SetTimeEnd(timeEnd);
554 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
558 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
561 if (beamEnergy != 0){
562 grpObj->SetBeamEnergy(beamEnergy);
563 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
564 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
565 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
566 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
570 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
571 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
572 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, and producing an error (beamType = %s, runType = %s)",beamType.Data(), runType.Data()));
575 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, but not producing any error (beamType = NULL, runType = %s)", runType.Data()));
580 if (beamType.Length() != 0){
581 grpObj->SetBeamType(beamType);
582 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
586 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
590 if (numberOfDetectors != 0){
591 grpObj->SetNumberOfDetectors(numberOfDetectors);
592 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
596 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
599 if (detectorMask != 0){
600 grpObj->SetDetectorMask(detectorMask);
601 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
605 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
608 if (lhcPeriod.Length() != 0) {
609 grpObj->SetLHCPeriod(lhcPeriod);
610 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
614 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
616 if (runType.Length() != 0) {
617 grpObj->SetRunType(runType);
618 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
622 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
628 //_______________________________________________________________
630 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
632 //======DAQ FXS======//
634 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
635 TList* list = GetFileSources(kDAQ);
637 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
641 if (list->GetEntries() == 0) {
642 Log("no raw data tags in this run: nothing to merge!");
647 TChain *fRawTagChain = new TChain("T");
649 TIterator* iter = list->MakeIterator();
651 while ((obj = iter->Next())) {
652 TObjString* objStr = dynamic_cast<TObjString*> (obj);
654 Log(Form("Found source %s", objStr->String().Data()));
655 TList* list2 = GetFileIDs(kDAQ, objStr->String());
657 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
658 delete fRawTagChain; fRawTagChain=0;
661 Log(Form("Number of ids: %d",list2->GetEntries()));
662 for(Int_t i = 0; i < list2->GetEntries(); i++) {
663 TObjString *idStr = (TObjString *)list2->At(i);
664 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
665 if (fileName.Length() > 0) {
666 Log(Form("Adding file in the chain: %s",fileName.Data()));
667 fRawTagChain->Add(fileName.Data());
670 Log(Form("Could not retrieve file with id %s from source %s: "
671 "connection problems with DAQ FXS!",
672 idStr->String().Data(), objStr->String().Data()));
674 delete list2; list2=0;
675 delete fRawTagChain; fRawTagChain=0;
683 TString fRawDataFileName = "GRP_Merged.tag.root";
684 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
686 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
687 Log("Error merging raw data files!!!");
691 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
692 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
695 Log("Problem storing raw data tags in local file!!!");
697 Log("Raw data tags merged successfully!!");
702 delete fRawTagChain; fRawTagChain=0;
704 if (result == kFALSE) {
712 //_______________________________________________________________
713 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
716 // processing the info
717 // stored in the DCS FXS
718 // coming from the trigger
720 // Get the CTP counters information
722 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
723 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
724 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
726 Log(Form("No dummy CTP scalers entry found, going into error..."));
730 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
732 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
736 AliCDBMetaData metaData;
737 metaData.SetResponsible("Roman Lietava");
738 metaData.SetComment("CTP scalers from dummy entry in OCDB");
739 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
740 Log("Unable to store the dummy CTP scalers object to OCDB!");
747 else if (!partition.IsNull() && detector.IsNull()){ // global partition
748 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
749 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
750 if (countersfile.IsNull()) {
751 Log("No CTP counters files has been found: empty source!");
755 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
756 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
758 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
762 AliCDBMetaData metaData;
763 metaData.SetBeamPeriod(0);
764 metaData.SetResponsible("Roman Lietava");
765 metaData.SetComment("CTP scalers");
766 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
767 Log("Unable to store the CTP scalers object to OCDB!");
776 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
783 //_______________________________________________________________
785 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
789 // processing DCS DPs
792 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
793 Int_t nLHCEntries = 0;
794 Int_t nL3Entries = 0;
795 Int_t nDipoleEntries = 0;
796 Int_t nEnvEntries = 0;
797 Int_t nHallProbesEntries = 0;
798 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
799 nL3Entries = ProcessL3DPs(valueMap, grpObj);
800 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
801 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
802 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
803 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
804 Log(Form("nLHCEntries = %d, L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nLHCEntries, nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
805 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
810 //_______________________________________________________________
812 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
819 Int_t nL3Entries = 0;
821 TObjArray *array = 0x0;
823 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
825 AliInfo(Form("==========L3Current==========="));
826 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
827 indexDP = kL3Current;
828 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
830 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
833 if (array->GetEntries() == 0){
834 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
837 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
838 if (floatDCS != NULL){
839 grpObj->SetL3Current(floatDCS);
851 ffailedDPs->RemoveAt(indexDP);
855 if (array) array = 0x0;
857 AliInfo(Form("==========L3Polarity==========="));
858 indexDP = kL3Polarity;
859 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
861 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
864 if (array->GetEntries() == 0){
865 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
868 Bool_t change = kFALSE;
869 Char_t charDCS = ProcessBool(array,change);
870 if (change == kFALSE){
871 grpObj->SetL3Polarity(charDCS);
872 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
873 ffailedDPs->RemoveAt(indexDP);
877 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
878 ffailedDPs->RemoveAt(indexDP);
882 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]));
890 //_______________________________________________________________
892 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
898 Int_t nDipoleEntries = 0;
899 TObjArray *array = 0x0;
901 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
903 AliInfo(Form("==========DipoleCurrent==========="));
904 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
905 indexDP = kDipoleCurrent;
906 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
908 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
911 if (array->GetEntries() == 0){
912 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
915 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
916 if (floatDCS != NULL){
917 grpObj->SetDipoleCurrent(floatDCS);
929 ffailedDPs->RemoveAt(indexDP);
933 if (array) array = 0x0;
935 AliInfo(Form("==========DipolePolarity==========="));
936 indexDP = kDipolePolarity;
937 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
939 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
942 if (array->GetEntries() == 0){
943 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
946 Bool_t change = kFALSE;
947 Char_t charDCS = ProcessBool(array,change);
949 grpObj->SetDipolePolarity(charDCS);
950 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
951 ffailedDPs->RemoveAt(indexDP);
955 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
956 ffailedDPs->RemoveAt(indexDP);
960 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]));
965 return nDipoleEntries;
968 //_______________________________________________________________
970 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
974 // evironment conditions (temperature, pressure) info
976 Int_t nEnvEntries = 0;
977 TObjArray *array = 0x0;
980 AliInfo(Form("==========CavernTemperature==========="));
981 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
982 indexDP = kCavernTemperature;
983 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
985 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
988 if (array->GetEntries() == 0){
989 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
992 Float_t *floatDCS = ProcessFloatAll(array);
993 if (floatDCS != NULL){
994 grpObj->SetCavernTemperature(floatDCS);
1005 ffailedDPs->RemoveAt(indexDP);
1010 if (array) array = 0x0;
1012 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1013 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1014 //dcsSensorArray->Print();
1015 if( fPressure->NumFits()<kNumSensors ) {
1016 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1018 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1020 AliInfo(Form("==========CavernAtmosPressure==========="));
1021 indexDP = kCavernAtmosPressure;
1022 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1023 TGraph* graph = sensorCavernP2->GetGraph();
1024 AliDebug(3,Form("index = %d",indexDP));
1025 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1026 AliDebug(2,Form("graph = %p",graph));
1027 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1028 if(sensorCavernP2->GetFit() || graph) {
1029 if (sensorCavernP2->GetFit()){
1030 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1033 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1035 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1036 ffailedDPs->RemoveAt(indexDP);
1039 //if (sensorP2) delete sensorP2;
1041 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] ));
1044 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1045 indexDP = kSurfaceAtmosPressure;
1046 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1047 graph = sensorP2->GetGraph();
1048 AliDebug(3,Form("index = %d",indexDP));
1049 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1050 AliDebug(2,Form("graph = %p",graph));
1051 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1052 if(sensorP2->GetFit() || graph) {
1053 if (sensorP2->GetFit()){
1054 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1057 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1059 grpObj->SetSurfaceAtmosPressure(sensorP2);
1060 ffailedDPs->RemoveAt(indexDP);
1063 //if (sensorP2) delete sensorP2;
1065 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] ));
1068 AliInfo(Form("==========CavernAtmosPressure2==========="));
1069 indexDP = kCavernAtmosPressure2;
1070 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1071 graph = sensorCavernP22->GetGraph();
1072 AliDebug(3,Form("index = %d",indexDP));
1073 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1074 AliDebug(2,Form("graph = %p",graph));
1075 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1076 if(sensorCavernP22->GetFit() || graph) {
1077 if (sensorCavernP22->GetFit()){
1078 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1081 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1083 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1084 ffailedDPs->RemoveAt(indexDP);
1087 //if (sensorP2) delete sensorP2;
1089 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] ));
1095 //_______________________________________________________________
1097 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1103 Int_t nHPEntries = 0;
1104 TObjArray *array = 0x0;
1106 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1108 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1109 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()));
1111 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1112 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1113 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1114 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1116 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1119 if (array->GetEntries() == 0){
1120 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1123 Float_t *floatDCS = ProcessFloatAll(array);
1124 if (floatDCS != NULL){
1125 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]));
1126 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1127 for (Int_t kk = 0 ; kk< 5; kk++){
1128 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1140 ffailedDPs->RemoveAt(indexDP + 7); // 7 = shift in the complete list of DPs to get to the Hall Probes
1146 Log(Form("Hall Probes = %d ", nHPEntries));
1150 //_______________________________________________________________
1152 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
1156 // processing of LHC related DCS DPs, i.e.:
1162 Int_t nLHCEntries = 0;
1163 TObjArray *array = 0x0;
1166 AliInfo(Form("==========LHCState==========="));
1167 indexDP = kLHCState;
1168 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1170 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1173 if (array->GetEntries() == 0){
1174 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1177 TString stringDCS = ProcessChar(array);
1178 if (stringDCS.Length()!=0) {
1179 Bool_t found = kFALSE;
1180 for( Int_t i=0; i<20; i+=2 ) {
1181 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
1182 stringDCS = fgkLHCState[i+1];
1188 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
1189 grpObj->SetLHCState(stringDCS);
1192 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
1193 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1197 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
1198 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1201 ffailedDPs->RemoveAt(indexDP);
1205 if (array) array = 0x0;
1207 AliInfo(Form("==========LHCLuminosity==========="));
1208 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1209 indexDP = kLHCLuminosity;
1210 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1212 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1215 if (array->GetEntries() == 0){
1216 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1219 Float_t *floatDCS = ProcessFloatAll(array);
1220 if (floatDCS != NULL){
1221 grpObj->SetLHCLuminosity(floatDCS);
1222 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1223 grpObj->SetLHCLuminositySplineFit(splfit);
1235 ffailedDPs->RemoveAt(indexDP);
1240 if (array) array = 0x0;
1242 AliInfo(Form("==========BeamIntensity==========="));
1243 if (outOfRange) outOfRange = kFALSE; // resetting outOfRange if needed
1244 indexDP = kBeamIntensity;
1245 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1247 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1250 if (array->GetEntries() == 0){
1251 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1254 Float_t *floatDCS = ProcessFloatAll(array);
1255 if (floatDCS != NULL){
1256 grpObj->SetBeamIntensity(floatDCS);
1257 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1258 grpObj->SetBeamIntensitySplineFit(splfit1);
1271 ffailedDPs->RemoveAt(indexDP);
1277 //_________________________________________________________________________
1279 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1283 // returning Spline Fit
1286 Int_t entriesarray = array->GetEntries();
1287 Float_t* value = new Float_t[entriesarray];
1288 Float_t* time = new Float_t[entriesarray];
1289 AliDCSValue* v = 0x0;
1290 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1291 v = (AliDCSValue*)array->At(iarray);
1292 value[iarray] = v->GetFloat();
1293 time[iarray] = v->GetTimeStamp();
1294 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1296 TGraph* gr = new TGraph(entriesarray,value,time);
1298 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1301 AliSplineFit *fit = new AliSplineFit();
1302 fit->SetMinPoints(10);
1303 fit->InitKnots(gr,10,10,0.0);
1307 AliWarning(Form("%s: no fit performed",stringID.Data()));
1313 //_________________________________________________________________________
1315 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1322 TString aDCSString="";
1324 AliDCSValue *v = 0x0;
1325 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1326 v = (AliDCSValue *)array->At(iCount);
1327 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1328 AliError(Form("DCS values for the parameter outside the queried interval"));
1332 if (aDCSString != v->GetChar())
1333 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1335 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1340 //__________________________________________________________________________________________________________________
1342 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1345 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1347 // parameters[0] = mean
1348 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1349 // parameters[2] = median
1350 // parameters[3] = standard deviation wrt mean
1351 // parameters[4] = standard deviation wrt median
1354 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1355 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1356 if (timeStartString.IsNull() || timeStartString.IsNull()){
1357 if (timeStartString.IsNull()){
1358 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1360 else if (timeStartString.IsNull()){
1361 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1363 fdaqStartEndTimeOk = kFALSE;
1367 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1368 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1369 Float_t* parameters = new Float_t[5];
1371 Int_t iCountsRun = 0;
1372 Int_t nCounts = array->GetEntries();
1373 Float_t valueBeforeSOR = 0;
1374 Float_t valueAfterEOR = 0;
1375 Int_t timestampBeforeSOR = -1;
1376 Int_t timestampAfterEOR = -1;
1377 Int_t ientrySOR = -1;
1378 Int_t ientryEOR = -1;
1379 Float_t* arrayValues = 0x0;
1380 Double_t* arrayWeights = 0x0;
1381 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1382 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1384 for(Int_t i = 0; i < nCounts; i++) {
1385 AliDCSValue *v = (AliDCSValue *)array->At(i);
1386 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1387 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1388 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1389 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1392 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1393 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1395 // look for the last value before SOR and the first value before EOR
1396 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1397 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1398 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1399 valueBeforeSOR = v->GetFloat();
1401 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1402 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1403 valueAfterEOR = v->GetFloat();
1404 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1406 // check if there are DPs between DAQ_time_start and DAQ_time_end
1407 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1408 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1409 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1410 AliDebug(2,Form("entry between SOR and EOR"));
1415 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1419 if (timestampBeforeSOR == -1){
1420 AliWarning("No value found before SOR");
1422 if (timestampAfterEOR == -1){
1423 AliWarning("No value found after EOR");
1426 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1427 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1428 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1429 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1430 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1431 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1433 Int_t nentriesUsed = 0;
1434 if (iCountsRun > 1){
1435 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1436 AliDebug(2,"Calculating (weighted) Mean and Median");
1437 arrayValues = new Float_t[iCountsRun];
1438 arrayWeights = new Double_t[iCountsRun];
1439 nentriesUsed = iCountsRun;
1440 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1441 AliDCSValue *v = (AliDCSValue *)array->At(i);
1442 Int_t timestamp2 = 0;
1444 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1445 timestamp2 = (Int_t)v1->GetTimeStamp();
1448 timestamp2 = timeEnd+1;
1450 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1451 arrayValues[i-ientrySOR] = v->GetFloat();
1453 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1454 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1456 else if (iCountsRun == 1){
1457 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1459 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1460 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.");
1461 arrayValues = new Float_t[2];
1462 arrayWeights = new Double_t[2];
1463 arrayValues[0] = valueBeforeSOR;
1464 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1465 arrayValues[1] = v->GetFloat();
1466 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1467 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1468 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1469 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1470 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1471 truncMeanFlag = kFALSE;
1474 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");
1475 parameters[0] = AliGRPObject::GetInvalidFloat();
1476 parameters[1] = AliGRPObject::GetInvalidFloat();
1477 parameters[2] = AliGRPObject::GetInvalidFloat();
1478 parameters[3] = AliGRPObject::GetInvalidFloat();
1479 parameters[4] = AliGRPObject::GetInvalidFloat();
1483 else { // iCountsRun == 0, using only the point immediately before SOR
1484 if (timestampBeforeSOR == -1){
1485 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");
1486 parameters[0] = AliGRPObject::GetInvalidFloat();
1487 parameters[1] = AliGRPObject::GetInvalidFloat();
1488 parameters[2] = AliGRPObject::GetInvalidFloat();
1489 parameters[3] = AliGRPObject::GetInvalidFloat();
1490 parameters[4] = AliGRPObject::GetInvalidFloat();
1494 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1495 AliDebug(2,Form("value = %f",valueBeforeSOR));
1496 parameters[0] = valueBeforeSOR;
1497 parameters[2] = valueBeforeSOR;
1498 truncMeanFlag = kFALSE;
1505 Float_t sumweights = 0;
1506 Int_t entriesTruncMean = 0;
1507 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1508 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1510 // calculating SD wrt Mean and Median
1511 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1513 for (Int_t i =0; i< nentriesUsed; i++){
1514 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1515 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1516 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1517 sumweights += arrayWeights[i];
1519 // setting SD wrt Mean
1520 if (sumweights != 0 ){
1521 parameters[3] = TMath::Sqrt(temp1/sumweights);
1524 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1525 parameters[3] = AliGRPObject::GetInvalidFloat();
1527 // setting SD wrt Median
1528 if (nentriesUsed != 0){
1529 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1532 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1533 parameters[4] = AliGRPObject::GetInvalidFloat();
1537 parameters[3] = AliGRPObject::GetInvalidFloat();
1538 parameters[4] = AliGRPObject::GetInvalidFloat();
1541 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1543 AliDebug(2,"Calculating Truncated Mean");
1544 for (Int_t i =0; i< nentriesUsed; i++){
1545 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1546 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1547 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1548 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1549 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1553 AliDebug(2,"Discarding entry");
1556 // setting truncated mean
1557 if (entriesTruncMean >1){
1558 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1559 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1562 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1563 parameters[1] = AliGRPObject::GetInvalidFloat();
1567 parameters[1] = AliGRPObject::GetInvalidFloat();
1570 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1571 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1572 AliInfo(Form("median = %f ",parameters[2]));
1573 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1574 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1579 //__________________________________________________________________________________________________________________
1581 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1584 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1585 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1586 // the flag is set according to the L3/Dipole current value
1587 // current threshold for L3 = 350 A (value provided by DCS)
1588 // current threshold for Dipole = 450 A (value provided by DCS)
1590 // parameters[0] = mean
1591 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1592 // parameters[2] = median
1593 // parameters[3] = standard deviation wrt mean
1594 // parameters[4] = standard deviation wrt median
1597 AliInfo(Form("indexDP = %d",indexDP));
1599 Int_t nCounts = array->GetEntries();
1600 for(Int_t i = 0; i < nCounts; i++) {
1601 AliDCSValue *v = (AliDCSValue *)array->At(i);
1602 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1603 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1604 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1605 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1608 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1609 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1610 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1611 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1614 AliError(Form("DCS values for the parameter outside the queried interval"));
1618 return ProcessFloatAll(array);
1622 //_______________________________________________________________
1624 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1627 // processing Boolean values
1630 Bool_t aDCSBool = kTRUE;
1632 AliDCSValue *v = 0x0;
1634 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1635 v = (AliDCSValue *)array->At(iCount);
1636 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1637 AliError(Form("DCS values for the parameter outside the queried interval"));
1641 if (aDCSBool != v->GetBool()) {
1642 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1646 aDCSBool = v->GetBool(); // always keeping last value
1647 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1650 Char_t caDCSBool = (Char_t) aDCSBool;
1655 //_______________________________________________________________
1657 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1660 // processing Int values, returning mean
1661 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1662 // are outside the queried time interval or their value is out of range
1665 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1666 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1667 if (timeStartString.IsNull() || timeStartString.IsNull()){
1668 if (timeStartString.IsNull()){
1669 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1671 else if (timeStartString.IsNull()){
1672 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1677 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1678 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1679 Float_t aDCSArrayMean = 0.0;
1681 Float_t valueBeforeSOR = 0;
1682 Float_t valueAfterEOR = 0;
1683 Int_t timestampBeforeSOR = -1;
1684 Int_t timestampAfterEOR = -1;
1685 Int_t ientrySOR = -1;
1686 Int_t ientryEOR = -1;
1687 Float_t* arrayValues = 0x0;
1688 Double_t* arrayWeights = 0x0;
1689 Int_t iCountsRun = 0;
1690 Int_t nCounts = array->GetEntries();
1692 for(Int_t i = 0; i < nCounts; i++) {
1693 AliDCSValue* v = (AliDCSValue *)array->At(i);
1694 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1695 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1696 return AliGRPObject::GetInvalidFloat();
1698 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1699 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1701 // look for the last value before SOR and the first value before EOR
1702 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1703 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1704 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1705 valueBeforeSOR = (Float_t) v->GetInt();
1707 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1708 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1709 valueAfterEOR = (Float_t) v->GetInt();
1710 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1712 // check if there are DPs between DAQ_time_start and DAQ_time_end
1713 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1714 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1715 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1716 AliDebug(2,Form("entry between SOR and EOR"));
1721 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1725 if (timestampBeforeSOR == -1){
1726 AliWarning("No value found before SOR!");
1728 if (timestampAfterEOR == -1){
1729 AliWarning("No value found after EOR!");
1732 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1733 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1734 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1735 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1736 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1737 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1739 Int_t nentriesUsed = 0;
1740 if (iCountsRun > 1){
1741 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1742 AliDebug(2,"Calculating (weighted) Mean");
1743 arrayValues = new Float_t[iCountsRun];
1744 arrayWeights = new Double_t[iCountsRun];
1745 nentriesUsed = iCountsRun;
1746 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1747 AliDCSValue *v = (AliDCSValue *)array->At(i);
1748 Int_t timestamp2 = 0;
1750 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1751 timestamp2 = (Int_t)v1->GetTimeStamp();
1754 timestamp2 = timeEnd+1;
1756 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1757 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1759 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1761 else if (iCountsRun == 1){
1762 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1764 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1765 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1766 arrayValues = new Float_t[2];
1767 arrayWeights = new Double_t[2];
1768 arrayValues[0] = valueBeforeSOR;
1769 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1770 arrayValues[1] = (Float_t)v->GetInt();
1771 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1772 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1773 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1774 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1777 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1778 return AliGRPObject::GetInvalidFloat();
1781 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1782 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1783 if (timestampBeforeSOR == -1){
1784 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1786 if (timestampAfterEOR == -1){
1787 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1789 return AliGRPObject::GetInvalidFloat();
1792 AliWarning("Using last entry before SOR and first entry after EOR.");
1794 arrayValues = new Float_t[2];
1795 arrayWeights = new Double_t[2];
1796 arrayValues[0] = valueBeforeSOR;
1797 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1798 arrayValues[1] = valueAfterEOR;
1799 arrayWeights[1] = 1.;
1800 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1801 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1802 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1806 AliInfo(Form("mean = %f ", aDCSArrayMean));
1807 return aDCSArrayMean;
1810 //_______________________________________________________________
1812 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1815 // processing Int values, returning mean
1816 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1817 // are outside the queried time interval or their value is out of range
1820 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1821 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1822 if (timeStartString.IsNull() || timeStartString.IsNull()){
1823 if (timeStartString.IsNull()){
1824 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1826 else if (timeStartString.IsNull()){
1827 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1832 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1833 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1834 Float_t aDCSArrayMean = 0.0;
1836 Float_t valueBeforeSOR = 0;
1837 Float_t valueAfterEOR = 0;
1838 Int_t timestampBeforeSOR = -1;
1839 Int_t timestampAfterEOR = -1;
1840 Int_t ientrySOR = -1;
1841 Int_t ientryEOR = -1;
1842 Float_t* arrayValues = 0x0;
1843 Double_t* arrayWeights = 0x0;
1844 Int_t iCountsRun = 0;
1845 Int_t nCounts = array->GetEntries();
1847 for(Int_t i = 0; i < nCounts; i++) {
1848 AliDCSValue* v = (AliDCSValue *)array->At(i);
1849 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
1850 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
1851 return AliGRPObject::GetInvalidFloat();
1853 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1854 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
1856 // look for the last value before SOR and the first value before EOR
1857 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1858 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1859 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1860 valueBeforeSOR = (Float_t)v->GetUInt();
1862 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1863 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1864 valueAfterEOR = (Float_t)v->GetUInt();
1865 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1867 // check if there are DPs between DAQ_time_start and DAQ_time_end
1868 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1869 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1870 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1871 AliDebug(2,Form("entry between SOR and EOR"));
1876 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1880 if (timestampBeforeSOR == -1){
1881 AliWarning("No value found before SOR!");
1883 if (timestampAfterEOR == -1){
1884 AliWarning("No value found after EOR!");
1887 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1888 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1889 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1890 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1891 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1892 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1894 Int_t nentriesUsed = 0;
1895 if (iCountsRun > 1){
1896 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1897 AliDebug(2,"Calculating (weighted) Mean");
1898 arrayValues = new Float_t[iCountsRun];
1899 arrayWeights = new Double_t[iCountsRun];
1900 nentriesUsed = iCountsRun;
1901 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1902 AliDCSValue *v = (AliDCSValue *)array->At(i);
1903 Int_t timestamp2 = 0;
1905 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1906 timestamp2 = (Int_t)v1->GetTimeStamp();
1909 timestamp2 = timeEnd+1;
1911 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1912 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
1914 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1916 else if (iCountsRun == 1){
1917 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1919 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1920 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1921 arrayValues = new Float_t[2];
1922 arrayWeights = new Double_t[2];
1923 arrayValues[0] = valueBeforeSOR;
1924 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1925 arrayValues[1] = (Float_t)v->GetUInt();
1926 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1927 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1928 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1929 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1932 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1933 return AliGRPObject::GetInvalidFloat();
1936 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1937 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1938 if (timestampBeforeSOR == -1){
1939 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1941 if (timestampAfterEOR == -1){
1942 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1944 return AliGRPObject::GetInvalidFloat();
1947 AliWarning("Using last entry before SOR and first entry after EOR.");
1949 arrayValues = new Float_t[2];
1950 arrayWeights = new Double_t[2];
1951 arrayValues[0] = valueBeforeSOR;
1952 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1953 arrayValues[1] = valueAfterEOR;
1954 arrayWeights[1] = 1.;
1955 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1956 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1957 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1961 AliInfo(Form("mean = %f ",aDCSArrayMean));
1962 return aDCSArrayMean;
1967 //_______________________________________________________________
1969 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1971 // extract DCS pressure maps. Perform fits to save space
1973 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1975 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
1976 fPressure->MakeSplineFit(map);
1977 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1978 if (fitFraction > kFitFraction ) {
1979 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
1981 AliInfo("Too few pressure maps fitted!!!");
1984 AliInfo("no atmospheric pressure map extracted!!!");
1993 //_______________________________________________________________
1994 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)
1997 // Retrieves logbook and trigger information from the online logbook
1998 // This information is needed for prompt reconstruction
2002 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2006 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2007 // 0 on success and no run was found
2008 // negative on error
2010 // This function is NOT called during the preprocessor run in the Shuttle!
2018 AliCDBManager* cdb = AliCDBManager::Instance();
2019 cdb->SetDefaultStorage(cdbRoot);
2022 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2026 Printf("ERROR: Could not connect to DAQ LB");
2032 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2033 TSQLResult* result = server->Query(sqlQuery);
2036 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2040 if (result->GetRowCount() == 0)
2042 Printf("ERROR: Run %d not found", run);
2047 TSQLRow* row = result->Next();
2050 Printf("ERROR: Could not receive data from run %d", run);
2055 TString timeStartString(row->GetField(0));
2056 TString runType(row->GetField(1));
2057 TString detectorMaskString(row->GetField(2));
2058 TString l3CurrentString(row->GetField(3));
2059 TString dipoleCurrentString(row->GetField(4));
2060 time_t timeStart = (time_t)(timeStartString.Atoi());
2061 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2062 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2063 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2064 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2065 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2067 AliGRPObject * grpObj = new AliGRPObject();
2068 grpObj->SetTimeStart(timeStart);
2069 grpObj->SetRunType((TString)(row->GetField(1)));
2070 grpObj->SetDetectorMask(detectorMask);
2071 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2072 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2073 grpObj->SetL3Polarity(l3Polarity);
2074 grpObj->SetDipolePolarity(dipolePolarity);
2075 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2083 Printf("Storing GRP/GRP/Data object with the following content");
2086 AliCDBMetaData metadata;
2087 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2088 metadata.SetComment("GRP Output parameters received during online running");
2090 AliCDBId id("GRP/GRP/Data", run, run);
2091 Bool_t success = cdb->Put(grpObj, id, &metadata);
2097 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2101 // Receive trigger information
2102 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2103 result = server->Query(sqlQuery);
2106 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2110 if (result->GetRowCount() == 0)
2112 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2117 row = result->Next();
2120 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2125 TString triggerConfig(row->GetField(0));
2133 Printf("Found trigger configuration: %s", triggerConfig.Data());
2135 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2138 Printf("ERROR: Could not create CTP configuration object");
2142 metadata.SetComment("CTP run configuration received during online running");
2144 AliCDBId id2("GRP/CTP/Config", run, run);
2145 success = cdb->Put(runcfg, id2, &metadata);
2152 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2157 // Receive list of GDCs for this run
2158 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2159 result = server->Query(sqlQuery);
2162 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2166 if (result->GetRowCount() == 0)
2168 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2174 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2175 row = result->Next();
2178 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2182 gdc += row->GetField(0);
2192 Printf("Found GDC: %s", gdc.Data());
2194 // get last run with same run type that was already processed by the SHUTTLE
2196 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());
2197 result = server->Query(sqlQuery);
2200 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2204 if (result->GetRowCount() == 0)
2206 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2211 row = result->Next();
2214 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2219 TString lastRunStr(row->GetField(0));
2220 Int_t lastRun = lastRunStr.Atoi();
2222 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);