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>
34 #include "AliGRPPreprocessor.h"
35 #include "AliGRPObject.h"
36 #include "AliDCSSensor.h"
37 #include "AliSplineFit.h"
38 #include "AliDCSSensorArray.h"
39 #include "AliRawEventHeaderVersions.h"
41 #include "AliTriggerConfiguration.h"
42 #include "AliTriggerRunScalers.h"
44 #include "AliCDBMetaData.h"
48 class AliShuttleInterface;
50 // needed for ReceivePromptRecoParameters
52 #include <TSQLServer.h>
53 #include <TSQLResult.h>
55 #include <AliCDBManager.h>
56 #include <AliCDBMetaData.h>
58 #include <AliTriggerConfiguration.h>
59 #include <AliCTPTimeParams.h>
61 const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
63 ClassImp(AliGRPPreprocessor)
65 //_______________________________________________________________
67 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook for PHYSICS runs, when beamType from DAQ logbook == NULL
68 const Int_t AliGRPPreprocessor::fgknDAQLbParReduced = 7; // num parameters in the logbook for the other cases
69 const Int_t AliGRPPreprocessor::fgknDCSDP = 51; // number of dcs dps
70 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
71 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
72 "LHCState", // missing in DCS
75 "LHCLuminosity", // missing in DCS
76 "BeamIntensity", // missing in DCS
82 "L3_BSF17_Temperature",
86 "L3_BSF4_Temperature",
90 "L3_BKF17_Temperature",
94 "L3_BKF4_Temperature",
98 "L3_BSF13_Temperature",
102 "L3_BSF8_Temperature",
106 "L3_BKF13_Temperature",
110 "L3_BKF8_Temperature",
114 "Dipole_Inside_Temperature",
118 "Dipole_Outside_Temperature",
120 "CavernAtmosPressure",
121 "SurfaceAtmosPressure",
122 "CavernAtmosPressure2",
125 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
129 "L3_BSF17_Temperature",
133 "L3_BSF4_Temperature",
137 "L3_BKF17_Temperature",
141 "L3_BKF4_Temperature",
145 "L3_BSF13_Temperature",
149 "L3_BSF8_Temperature",
153 "L3_BKF13_Temperature",
157 "L3_BKF8_Temperature",
161 "Dipole_Inside_Temperature",
165 "Dipole_Outside_Temperature",
168 const Short_t kSensors = 48; // start index position of sensor in DCS DPs
169 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
172 const char* AliGRPPreprocessor::fgkLHCState[20] = {
178 "U", "UNSTABLE BEAMS",
185 const char* kppError[] = {
187 "(DAQ logbook ERROR)",
189 "(Trigger Scalers not found in DCS FXS - ERROR)",
190 "(DCS data points ERROR)",
191 "(Trigger Configuration ERROR)",
192 "(DAQ logbook ERROR determining partition of the run)",
196 //_______________________________________________________________
198 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
199 AliPreprocessor("GRP",shuttle), fPressure(0), fmaxFloat(0), fminFloat(0),fmaxDouble(0), fminDouble(0), fmaxInt(0), fminInt(0), fmaxUInt(0), fminUInt(0)
201 // constructor - shuttle must be instantiated!
203 AddRunType("COSMIC");
205 AddRunType("PHYSICS");
206 AddRunType("CALIBRATION_BC");
207 AddRunType("CALIBRATION_CENTRAL");
208 AddRunType("CALIBRATION_EMD");
209 AddRunType("CALIBRATION_MB");
210 AddRunType("CALIBRATION_SEMICENTRAL");
211 AddRunType("CALIBRATION");
212 AddRunType("PEDESTAL");
213 AddRunType("STANDALONE");
216 AddRunType("PULSER");
217 AddRunType("STANDALONE_PULSER");
220 fminFloat = -FLT_MAX;
221 fmaxDouble = DBL_MAX;
222 fminDouble = -DBL_MAX;
228 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
229 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
230 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
231 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
232 AliInfo(Form("Max allowed integer = %d",fmaxInt));
233 AliInfo(Form("Min allowed integer = %d",fminInt));
234 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
235 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
239 //_______________________________________________________________
241 AliGRPPreprocessor::~AliGRPPreprocessor()
248 //_______________________________________________________________
250 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
252 // Initialize preprocessor
254 AliPreprocessor::Initialize(run, startTime, endTime);
256 AliInfo("Initialization of the GRP preprocessor.");
257 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
258 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
259 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
260 for(Int_t j = 0; j < kNumSensors; j++) {
261 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
262 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
264 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
266 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
269 //_______________________________________________________________
271 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
273 // process data retrieved by the Shuttle
275 // retrieving "partition" and "detector" fields from DAQ logbook to
276 // determine the partition in which the run was taken
277 // the partition is used to decide how to react in case of errors for CTP
279 TString partition = (TString)GetRunParameter("partition");
280 TString detector = (TString)GetRunParameter("detector");
282 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
284 //=================//
286 //=================//
289 Int_t iDaqLB = ProcessDaqLB(grpobj);
290 TString runType = (TString)GetRunType();
291 TString beamType = (TString)GetRunParameter("beamType");
292 //if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
293 if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && !beamType.IsNull()) || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType.IsNull()) || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
294 Log(Form("DAQ Logbook, successful!"));
296 Log(Form("DAQ Logbook, could not get all expected entries!!!"));
300 //=================//
302 //=================//
303 UInt_t iDaqFxs = ProcessDaqFxs();
305 Log(Form("DAQ FXS, successful!"));
307 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
311 //=================//
313 //=================//
314 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
316 Log(Form("DCS FXS, successful!"));
317 } else if (iDcsFxs ==1) {
318 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
321 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
325 //=================//
326 // DCS data points //
327 //=================//
328 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
329 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
330 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-4));
331 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, LH3_BSF4_H3 are not working yet...
332 Log(Form("Problem with the DCS data points!!! Only %d/%d entries found",entries,fgknDCSDP-4));
334 } else Log(Form("DCS data points, successful!"));
336 //=======================//
337 // Trigger Configuration //
338 //=======================//
340 const char * triggerConf = GetTriggerConfiguration();
342 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
343 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
344 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
346 Log(Form("No dummy CTP configuration entry found, going into error..."));
350 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
352 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
356 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
357 runcfg->SetTitle(titleCTPcfg);
358 AliCDBMetaData metaData;
359 metaData.SetResponsible("Roman Lietava");
360 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
361 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
362 Log("Unable to store the dummy CTP run configuration object to OCDB!");
369 else if (!partition.IsNull() && detector.IsNull()){ // global partition
370 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
371 if (triggerConf!= NULL) {
372 Log("Found trigger configuration in DAQ logbook");
373 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
375 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
379 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
380 runcfg->SetTitle(titleCTPcfg);
381 AliCDBMetaData metaData;
382 metaData.SetBeamPeriod(0);
383 metaData.SetResponsible("Roman Lietava");
384 metaData.SetComment("CTP run configuration from DAQ logbook");
385 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
386 Log("Unable to store the CTP run configuration object to OCDB!");
393 Log("Trigger configuration NULL in DAQ logbook");
399 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
403 //===========================//
404 // Trigger Timing Parameters //
405 //===========================//
408 const char * triggerCTPtiming = GetCTPTimeParams();
410 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
411 Log("STANDALONE partition for current run, using CTP timing params dummy value");
412 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
414 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
418 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
420 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
424 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
425 runCTPtiming->SetTitle(titleCTPtiming);
426 AliCDBMetaData metadata;
427 metadata.SetResponsible("Roman Lietava");
428 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
429 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
430 Log("Unable to store the dummy CTP timing params object to OCDB!");
437 else if (!partition.IsNull() && detector.IsNull()){ // global partition
438 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
439 if (triggerCTPtiming!= NULL) {
440 Log("Found trigger timing params in DAQ logbook");
441 AliDebug(2,Form("%s",triggerCTPtiming));
442 AliCTPTimeParams *runCTPtiming = runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
444 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
448 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
449 runCTPtiming->SetTitle(titleCTPtiming);
450 AliCDBMetaData metadata;
451 metadata.SetBeamPeriod(0);
452 metadata.SetResponsible("Roman Lietava");
453 metadata.SetComment("CTP timing params from DAQ logbook");
454 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
455 Log("Unable to store the CTP timing params object to OCDB!");
462 Log("Trigger timing params NULL in DAQ logbook");
468 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
471 // storing AliGRPObject in OCDB
474 md.SetResponsible("Chiara Zampolli");
475 md.SetComment("Output parameters from the GRP preprocessor.");
477 Bool_t result = kTRUE;
478 result = Store("GRP", "Data", grpobj, &md);
481 if (result && !error ) {
482 Log("GRP Preprocessor Success");
485 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s",
486 kppError[(error&1)?1:0],
487 kppError[(error&2)?2:0],
488 kppError[(error&4)?3:0],
489 kppError[(error&8)?4:0],
490 kppError[(error&16)?5:0],
491 kppError[(error&32)?6:0],
492 kppError[(error&64)?7:0]
498 //_______________________________________________________________
500 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
502 //Getting the DAQ lb information
504 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
505 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
506 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
507 TString beamType = (TString)GetRunParameter("beamType");
508 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
509 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
510 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
511 TString runType = (TString)GetRunType();
513 UInt_t nparameter = 0;
515 grpObj->SetTimeStart(timeStart);
516 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
520 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
524 grpObj->SetTimeEnd(timeEnd);
525 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
529 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
532 if (beamEnergy != 0){
533 grpObj->SetBeamEnergy(beamEnergy);
534 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
535 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
536 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
537 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
541 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
542 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
543 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()));
546 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()));
551 if (beamType.Length() != 0){
552 grpObj->SetBeamType(beamType);
553 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
557 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
561 if (numberOfDetectors != 0){
562 grpObj->SetNumberOfDetectors(numberOfDetectors);
563 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
567 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
570 if (detectorMask != 0){
571 grpObj->SetDetectorMask(detectorMask);
572 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
576 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
579 if (lhcPeriod.Length() != 0) {
580 grpObj->SetLHCPeriod(lhcPeriod);
581 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
585 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
587 if (runType.Length() != 0) {
588 grpObj->SetRunType(runType);
589 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
593 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
599 //_______________________________________________________________
601 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
603 //======DAQ FXS======//
605 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
606 TList* list = GetFileSources(kDAQ);
608 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
612 if (list->GetEntries() == 0) {
613 Log("no raw data tags in this run: nothing to merge!");
618 TChain *fRawTagChain = new TChain("T");
620 TIterator* iter = list->MakeIterator();
622 while ((obj = iter->Next())) {
623 TObjString* objStr = dynamic_cast<TObjString*> (obj);
625 Log(Form("Found source %s", objStr->String().Data()));
626 TList* list2 = GetFileIDs(kDAQ, objStr->String());
628 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
629 delete fRawTagChain; fRawTagChain=0;
632 Log(Form("Number of ids: %d",list2->GetEntries()));
633 for(Int_t i = 0; i < list2->GetEntries(); i++) {
634 TObjString *idStr = (TObjString *)list2->At(i);
635 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
636 if (fileName.Length() > 0) {
637 Log(Form("Adding file in the chain: %s",fileName.Data()));
638 fRawTagChain->Add(fileName.Data());
641 Log(Form("Could not retrieve file with id %s from source %s: "
642 "connection problems with DAQ FXS!",
643 idStr->String().Data(), objStr->String().Data()));
645 delete list2; list2=0;
646 delete fRawTagChain; fRawTagChain=0;
654 TString fRawDataFileName = "GRP_Merged.tag.root";
655 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
657 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
658 Log("Error merging raw data files!!!");
662 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
663 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
666 Log("Problem storing raw data tags in local file!!!");
668 Log("Raw data tags merged successfully!!");
673 delete fRawTagChain; fRawTagChain=0;
675 if (result == kFALSE) {
683 //_______________________________________________________________
684 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
687 // processing the info
688 // stored in the DCS FXS
689 // coming from the trigger
691 // Get the CTP counters information
693 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
694 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
695 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
697 Log(Form("No dummy CTP scalers entry found, going into error..."));
701 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
703 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
707 AliCDBMetaData metaData;
708 metaData.SetResponsible("Roman Lietava");
709 metaData.SetComment("CTP scalers from dummy entry in OCDB");
710 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
711 Log("Unable to store the dummy CTP scalers object to OCDB!");
718 else if (!partition.IsNull() && detector.IsNull()){ // global partition
719 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
720 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
721 if (countersfile.IsNull()) {
722 Log("No CTP counters files has been found: empty source!");
726 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
727 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
729 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
733 AliCDBMetaData metaData;
734 metaData.SetBeamPeriod(0);
735 metaData.SetResponsible("Roman Lietava");
736 metaData.SetComment("CTP scalers");
737 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
738 Log("Unable to store the CTP scalers object to OCDB!");
747 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
754 //_______________________________________________________________
756 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
760 // processing DCS DPs
763 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
764 Int_t nLHCEntries = 0;
765 Int_t nL3Entries = 0;
766 Int_t nDipoleEntries = 0;
767 Int_t nEnvEntries = 0;
768 Int_t nHallProbesEntries = 0;
769 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
770 nL3Entries = ProcessL3DPs(valueMap, grpObj);
771 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
772 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
773 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
774 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
775 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
780 //_______________________________________________________________
782 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
789 Int_t nL3Entries = 0;
790 TObjArray *array = 0x0;
792 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
794 AliInfo(Form("==========L3Current==========="));
795 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
796 indexDP = kL3Current;
797 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
799 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
802 if (array->GetEntries() == 0){
803 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
806 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
807 if (floatDCS != NULL){
808 grpObj->SetL3Current(floatDCS);
818 if (!outOfRange) nL3Entries++;
821 if (array) array = 0x0;
823 AliInfo(Form("==========L3Polarity==========="));
824 indexDP = kL3Polarity;
825 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
827 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
830 if (array->GetEntries() == 0){
831 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
834 Bool_t change = kFALSE;
835 Char_t charDCS = ProcessBool(array,change);
836 if (change == kFALSE){
837 grpObj->SetL3Polarity(charDCS);
838 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
842 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
846 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]));
854 //_______________________________________________________________
856 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
862 Int_t nDipoleEntries = 0;
863 TObjArray *array = 0x0;
865 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
867 AliInfo(Form("==========DipoleCurrent==========="));
868 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
869 indexDP = kDipoleCurrent;
870 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
872 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
875 if (array->GetEntries() == 0){
876 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
879 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
880 if (floatDCS != NULL){
881 grpObj->SetDipoleCurrent(floatDCS);
891 if (!outOfRange) nDipoleEntries++;
894 if (array) array = 0x0;
896 AliInfo(Form("==========DipolePolarity==========="));
897 indexDP = kDipolePolarity;
898 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
900 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
903 if (array->GetEntries() == 0){
904 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
907 Bool_t change = kFALSE;
908 Char_t charDCS = ProcessBool(array,change);
910 grpObj->SetDipolePolarity(charDCS);
911 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
915 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
919 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]));
924 return nDipoleEntries;
927 //_______________________________________________________________
929 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
933 // evironment conditions (temperature, pressure) info
935 Int_t nEnvEntries = 0;
936 TObjArray *array = 0x0;
939 AliInfo(Form("==========CavernTemperature==========="));
940 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
941 indexDP = kCavernTemperature;
942 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
944 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
947 if (array->GetEntries() == 0){
948 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
951 Float_t *floatDCS = ProcessFloatAll(array);
952 if (floatDCS != NULL){
953 grpObj->SetCavernTemperature(floatDCS);
963 if (!outOfRange) nEnvEntries++;
966 if (array) array = 0x0;
968 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
969 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
970 //dcsSensorArray->Print();
971 if( fPressure->NumFits()<kNumSensors ) {
972 Log(Form("Problem with the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
975 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
976 AliInfo(Form("==========CavernAtmosPressure==========="));
977 indexDP = kCavernAtmosPressure;
978 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
979 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
980 if( sensorCavernP2->GetFit() ) {
981 Log(Form("Fit for Sensor %s found",fgkDCSDataPoints[indexDP]));
982 grpObj->SetCavernAtmosPressure(sensorCavernP2);
985 //if (sensorP2) delete sensorP2;
987 Log(Form("ERROR Sensor Fit for %s not found ", fgkDCSDataPoints[indexDP] ));
989 AliInfo(Form("==========SurfaceAtmosPressure==========="));
990 indexDP = kSurfaceAtmosPressure;
991 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
992 AliDebug(2,Form("sensorP2 = %p", sensorP2));
993 if( sensorP2->GetFit() ) {
994 Log(Form("Fit for Sendor %s found",fgkDCSDataPoints[indexDP]));
995 grpObj->SetSurfaceAtmosPressure(sensorP2);
998 //if (sensorP2) delete sensorP2;
1000 Log(Form("ERROR Sensor Fit for %s not found ", fgkDCSDataPoints[indexDP] ));
1002 AliInfo(Form("==========CavernAtmosPressure2==========="));
1003 indexDP = kCavernAtmosPressure2;
1004 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1005 AliDebug(2,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1006 if( sensorCavernP22->GetFit() ) {
1007 Log(Form("Fit for Sensor %s found",fgkDCSDataPoints[indexDP]));
1008 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1011 //if (sensorP2) delete sensorP2;
1013 Log(Form("ERROR Sensor Fit for %s not found ", fgkDCSDataPoints[indexDP] ));
1020 //_______________________________________________________________
1022 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1028 Int_t nHPEntries = 0;
1029 TObjArray *array = 0x0;
1031 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1033 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1034 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()));
1036 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1037 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1038 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1039 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1041 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1044 if (array->GetEntries() == 0){
1045 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1048 Float_t *floatDCS = ProcessFloatAll(array);
1049 if (floatDCS != NULL){
1050 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]));
1051 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1052 for (Int_t kk = 0 ; kk< 5; kk++){
1053 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1064 if (!outOfRange) nHPEntries++;
1068 Log(Form("Hall Probes = %d ", nHPEntries));
1072 //_______________________________________________________________
1074 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
1078 // processing of LHC related DCS DPs, i.e.:
1084 Int_t nLHCEntries = 0;
1085 TObjArray *array = 0x0;
1088 AliInfo(Form("==========LHCState==========="));
1089 indexDP = kLHCState;
1090 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1092 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1095 if (array->GetEntries() == 0){
1096 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1099 TString stringDCS = ProcessChar(array);
1100 if (stringDCS.Length()!=0) {
1101 Bool_t found = kFALSE;
1102 for( Int_t i=0; i<20; i+=2 ) {
1103 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
1104 stringDCS = fgkLHCState[i+1];
1110 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
1111 grpObj->SetLHCState(stringDCS);
1114 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
1115 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1119 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
1120 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1126 if (array) array = 0x0;
1128 AliInfo(Form("==========LHCLuminosity==========="));
1129 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1130 indexDP = kLHCLuminosity;
1131 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1133 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1136 if (array->GetEntries() == 0){
1137 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1140 Float_t *floatDCS = ProcessFloatAll(array);
1141 if (floatDCS != NULL){
1142 grpObj->SetLHCLuminosity(floatDCS);
1143 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1144 grpObj->SetLHCLuminositySplineFit(splfit);
1155 if (!outOfRange) nLHCEntries++;
1158 if (array) array = 0x0;
1160 AliInfo(Form("==========BeamIntensity==========="));
1161 if (outOfRange) outOfRange = kFALSE; // resetting outOfRange if needed
1162 indexDP = kBeamIntensity;
1163 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1165 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1168 if (array->GetEntries() == 0){
1169 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1172 Float_t *floatDCS = ProcessFloatAll(array);
1173 if (floatDCS != NULL){
1174 grpObj->SetBeamIntensity(floatDCS);
1175 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1176 grpObj->SetBeamIntensitySplineFit(splfit1);
1187 if (!outOfRange) nLHCEntries++;
1192 //_________________________________________________________________________
1194 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1198 // returning Spline Fit
1201 Int_t entriesarray = array->GetEntries();
1202 Float_t* value = new Float_t[entriesarray];
1203 Float_t* time = new Float_t[entriesarray];
1204 AliDCSValue* v = 0x0;
1205 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1206 v = (AliDCSValue*)array->At(iarray);
1207 value[iarray] = v->GetFloat();
1208 time[iarray] = v->GetTimeStamp();
1209 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1211 TGraph* gr = new TGraph(entriesarray,value,time);
1213 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1216 AliSplineFit *fit = new AliSplineFit();
1217 fit->SetMinPoints(10);
1218 fit->InitKnots(gr,10,10,0.0);
1222 AliWarning(Form("%s: no fit performed",stringID.Data()));
1228 //_________________________________________________________________________
1230 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1237 TString aDCSString="";
1239 AliDCSValue *v = 0x0;
1240 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1241 v = (AliDCSValue *)array->At(iCount);
1242 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1243 AliError(Form("DCS values for the parameter outside the queried interval"));
1247 if (aDCSString != v->GetChar())
1248 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1250 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1255 //__________________________________________________________________________________________________________________
1257 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1260 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1262 // parameters[0] = mean
1263 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1264 // parameters[2] = median
1265 // parameters[3] = standard deviation wrt mean
1266 // parameters[4] = standard deviation wrt median
1269 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1270 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1271 if (timeStartString.IsNull() || timeStartString.IsNull()){
1272 if (timeStartString.IsNull()){
1273 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1275 else if (timeStartString.IsNull()){
1276 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1281 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1282 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1283 Float_t* parameters = new Float_t[5];
1285 Int_t iCountsRun = 0;
1286 Int_t nCounts = array->GetEntries();
1287 Float_t valueBeforeSOR = 0;
1288 Float_t valueAfterEOR = 0;
1289 Int_t timestampBeforeSOR = -1;
1290 Int_t timestampAfterEOR = -1;
1291 Int_t ientrySOR = -1;
1292 Int_t ientryEOR = -1;
1293 Float_t* arrayValues = 0x0;
1294 Double_t* arrayWeights = 0x0;
1295 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1296 for(Int_t i = 0; i < nCounts; i++) {
1297 AliDCSValue *v = (AliDCSValue *)array->At(i);
1298 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1299 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1300 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1301 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1304 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1305 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1307 // look for the last value before SOR and the first value before EOR
1308 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1309 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1310 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1311 valueBeforeSOR = v->GetFloat();
1313 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1314 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1315 valueAfterEOR = v->GetFloat();
1316 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1318 // check if there are DPs between DAQ_time_start and DAQ_time_end
1319 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1320 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1321 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1322 AliDebug(2,Form("entry between SOR and EOR"));
1327 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1331 if (timestampBeforeSOR == -1){
1332 AliWarning("No value found before SOR!");
1334 if (timestampAfterEOR == -1){
1335 AliWarning("No value found after EOR!");
1338 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1339 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1340 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1341 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1342 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1343 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1345 Int_t nentriesUsed = 0;
1346 if (iCountsRun > 1){
1347 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1348 AliDebug(2,"Calculating (weighted) Mean and Median");
1349 arrayValues = new Float_t[iCountsRun];
1350 arrayWeights = new Double_t[iCountsRun];
1351 nentriesUsed = iCountsRun;
1352 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1353 AliDCSValue *v = (AliDCSValue *)array->At(i);
1354 Int_t timestamp2 = 0;
1356 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1357 timestamp2 = (Int_t)v1->GetTimeStamp();
1360 timestamp2 = timeEnd+1;
1362 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1363 arrayValues[i-ientrySOR] = v->GetFloat();
1365 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1366 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1368 else if (iCountsRun == 1){
1369 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1371 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1372 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.");
1373 arrayValues = new Float_t[2];
1374 arrayWeights = new Double_t[2];
1375 arrayValues[0] = valueBeforeSOR;
1376 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1377 arrayValues[1] = v->GetFloat();
1378 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1379 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1380 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1381 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1382 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1383 truncMeanFlag = kFALSE;
1386 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");
1387 parameters[0] = AliGRPObject::GetInvalidFloat();
1388 parameters[1] = AliGRPObject::GetInvalidFloat();
1389 parameters[2] = AliGRPObject::GetInvalidFloat();
1390 parameters[3] = AliGRPObject::GetInvalidFloat();
1391 parameters[4] = AliGRPObject::GetInvalidFloat();
1395 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1396 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1397 if (timestampBeforeSOR == -1){
1398 AliError("Cannot calculate mean, truncated mean, median, SD wrt mean, SD wrt median for current DP - no points during the run collected, and point before SOR missing");
1400 if (timestampAfterEOR == -1){
1401 AliError("Cannot calculate mean, truncated mean, median, SD wrt mean, SD wrt median for current DP - no points during the run collected, and point after EOR missing");
1403 parameters[0] = AliGRPObject::GetInvalidFloat();
1404 parameters[1] = AliGRPObject::GetInvalidFloat();
1405 parameters[2] = AliGRPObject::GetInvalidFloat();
1406 parameters[3] = AliGRPObject::GetInvalidFloat();
1407 parameters[4] = AliGRPObject::GetInvalidFloat();
1411 AliWarning("Using last entry before SOR and first entry after EOR. Truncated mean won't be calculated.");
1413 arrayValues = new Float_t[2];
1414 arrayWeights = new Double_t[2];
1415 arrayValues[0] = valueBeforeSOR;
1416 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1417 arrayValues[1] = valueAfterEOR;
1418 arrayWeights[1] = 1.;
1419 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1420 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1421 parameters[0] = TMath::Mean(1,arrayValues,arrayWeights);
1422 parameters[2] = TMath::Median(1,arrayValues,arrayWeights);
1423 truncMeanFlag = kFALSE;
1429 Float_t sumweights = 0;
1430 Int_t entriesTruncMean = 0;
1431 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1432 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1434 // calculating SD wrt Mean and Median
1435 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1436 for (Int_t i =0; i< nentriesUsed; i++){
1437 AliInfo(Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1438 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1439 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1440 sumweights += arrayWeights[i];
1442 // setting SD wrt Mean
1443 if (sumweights != 0 ){
1444 parameters[3] = TMath::Sqrt(temp1/sumweights);
1447 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1448 parameters[3] = AliGRPObject::GetInvalidFloat();
1450 // setting SD wrt Median
1451 if (nentriesUsed != 0){
1452 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1455 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1456 parameters[4] = AliGRPObject::GetInvalidFloat();
1459 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1461 AliDebug(2,"Calculating Truncated Mean");
1462 for (Int_t i =0; i< nentriesUsed; i++){
1463 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1464 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1466 arrayValuesTruncMean[i]=arrayValues[i];
1467 arrayWeightsTruncMean[i]=arrayWeights[i];
1470 // setting truncated mean
1471 if (entriesTruncMean >1){
1472 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1473 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1476 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1477 parameters[1] = AliGRPObject::GetInvalidFloat();
1481 parameters[1] = AliGRPObject::GetInvalidFloat();
1484 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1485 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1486 AliInfo(Form("median = %f ",parameters[2]));
1487 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1488 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1493 //__________________________________________________________________________________________________________________
1495 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1498 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1499 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1500 // the flag is set according to the L3/Dipole current value
1501 // current threshold for L3 = 350 A (value provided by DCS)
1502 // current threshold for Dipole = 450 A (value provided by DCS)
1504 // parameters[0] = mean
1505 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1506 // parameters[2] = median
1507 // parameters[3] = standard deviation wrt mean
1508 // parameters[4] = standard deviation wrt median
1511 AliInfo(Form("indexDP = %d",indexDP));
1513 Int_t nCounts = array->GetEntries();
1514 for(Int_t i = 0; i < nCounts; i++) {
1515 AliDCSValue *v = (AliDCSValue *)array->At(i);
1516 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1517 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1518 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1519 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1522 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1523 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1524 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1525 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1528 AliError(Form("DCS values for the parameter outside the queried interval"));
1532 return ProcessFloatAll(array);
1536 //_______________________________________________________________
1538 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1541 // processing Boolean values
1544 Bool_t aDCSBool = kTRUE;
1546 AliDCSValue *v = 0x0;
1548 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1549 v = (AliDCSValue *)array->At(iCount);
1550 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1551 AliError(Form("DCS values for the parameter outside the queried interval"));
1555 if (aDCSBool != v->GetBool()) {
1556 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1560 aDCSBool = v->GetBool(); // always keeping last value
1561 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1564 Char_t caDCSBool = (Char_t) aDCSBool;
1569 //_______________________________________________________________
1571 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1574 // processing Int values, returning mean
1575 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1576 // are outside the queried time interval or their value is out of range
1579 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1580 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1581 if (timeStartString.IsNull() || timeStartString.IsNull()){
1582 if (timeStartString.IsNull()){
1583 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1585 else if (timeStartString.IsNull()){
1586 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1591 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1592 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1593 Float_t aDCSArrayMean = 0.0;
1595 AliDCSValue* v = 0x0;
1596 Float_t valueBeforeSOR = 0;
1597 Float_t valueAfterEOR = 0;
1598 Int_t timestampBeforeSOR = -1;
1599 Int_t timestampAfterEOR = -1;
1600 Int_t ientrySOR = -1;
1601 Int_t ientryEOR = -1;
1602 Float_t* arrayValues = 0x0;
1603 Double_t* arrayWeights = 0x0;
1604 Int_t iCountsRun = 0;
1605 Int_t nCounts = array->GetEntries();
1607 for(Int_t i = 0; i < nCounts; i++) {
1608 v = (AliDCSValue *)array->At(i);
1609 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1610 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1611 return AliGRPObject::GetInvalidFloat();
1613 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1614 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1616 // look for the last value before SOR and the first value before EOR
1617 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1618 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1619 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1620 valueBeforeSOR = (Float_t) v->GetInt();
1622 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1623 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1624 valueAfterEOR = (Float_t) v->GetInt();
1625 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1627 // check if there are DPs between DAQ_time_start and DAQ_time_end
1628 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1629 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1630 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1631 AliDebug(2,Form("entry between SOR and EOR"));
1636 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1640 if (timestampBeforeSOR == -1){
1641 AliWarning("No value found before SOR!");
1643 if (timestampAfterEOR == -1){
1644 AliWarning("No value found after EOR!");
1647 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1648 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1649 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1650 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1651 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1652 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1654 Int_t nentriesUsed = 0;
1655 if (iCountsRun > 1){
1656 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1657 AliDebug(2,"Calculating (weighted) Mean");
1658 arrayValues = new Float_t[iCountsRun];
1659 arrayWeights = new Double_t[iCountsRun];
1660 nentriesUsed = iCountsRun;
1661 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1662 AliDCSValue *v = (AliDCSValue *)array->At(i);
1663 Int_t timestamp2 = 0;
1665 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1666 timestamp2 = (Int_t)v1->GetTimeStamp();
1669 timestamp2 = timeEnd+1;
1671 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1672 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1674 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1676 else if (iCountsRun == 1){
1677 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1679 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1680 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1681 arrayValues = new Float_t[2];
1682 arrayWeights = new Double_t[2];
1683 arrayValues[0] = valueBeforeSOR;
1684 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1685 arrayValues[1] = (Float_t)v->GetInt();
1686 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1687 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1688 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1689 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1692 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1693 return AliGRPObject::GetInvalidFloat();
1696 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1697 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1698 if (timestampBeforeSOR == -1){
1699 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1701 if (timestampAfterEOR == -1){
1702 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1704 return AliGRPObject::GetInvalidFloat();
1707 AliWarning("Using last entry before SOR and first entry after EOR.");
1709 arrayValues = new Float_t[2];
1710 arrayWeights = new Double_t[2];
1711 arrayValues[0] = valueBeforeSOR;
1712 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1713 arrayValues[1] = valueAfterEOR;
1714 arrayWeights[1] = 1.;
1715 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1716 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1717 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1721 AliInfo(Form("mean = %f ", aDCSArrayMean));
1722 return aDCSArrayMean;
1725 //_______________________________________________________________
1727 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1730 // processing Int values, returning mean
1731 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1732 // are outside the queried time interval or their value is out of range
1735 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1736 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1737 if (timeStartString.IsNull() || timeStartString.IsNull()){
1738 if (timeStartString.IsNull()){
1739 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1741 else if (timeStartString.IsNull()){
1742 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1747 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1748 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1749 Float_t aDCSArrayMean = 0.0;
1751 AliDCSValue* v = 0x0;
1752 Float_t valueBeforeSOR = 0;
1753 Float_t valueAfterEOR = 0;
1754 Int_t timestampBeforeSOR = -1;
1755 Int_t timestampAfterEOR = -1;
1756 Int_t ientrySOR = -1;
1757 Int_t ientryEOR = -1;
1758 Float_t* arrayValues = 0x0;
1759 Double_t* arrayWeights = 0x0;
1760 Int_t iCountsRun = 0;
1761 Int_t nCounts = array->GetEntries();
1763 for(Int_t i = 0; i < nCounts; i++) {
1764 v = (AliDCSValue *)array->At(i);
1765 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
1766 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
1767 return AliGRPObject::GetInvalidFloat();
1769 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1770 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
1772 // look for the last value before SOR and the first value before EOR
1773 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1774 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1775 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1776 valueBeforeSOR = (Float_t)v->GetUInt();
1778 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1779 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1780 valueAfterEOR = (Float_t)v->GetUInt();
1781 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1783 // check if there are DPs between DAQ_time_start and DAQ_time_end
1784 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1785 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1786 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1787 AliDebug(2,Form("entry between SOR and EOR"));
1792 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1796 if (timestampBeforeSOR == -1){
1797 AliWarning("No value found before SOR!");
1799 if (timestampAfterEOR == -1){
1800 AliWarning("No value found after EOR!");
1803 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1804 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1805 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1806 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1807 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1808 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1810 Int_t nentriesUsed = 0;
1811 if (iCountsRun > 1){
1812 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1813 AliDebug(2,"Calculating (weighted) Mean");
1814 arrayValues = new Float_t[iCountsRun];
1815 arrayWeights = new Double_t[iCountsRun];
1816 nentriesUsed = iCountsRun;
1817 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1818 AliDCSValue *v = (AliDCSValue *)array->At(i);
1819 Int_t timestamp2 = 0;
1821 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1822 timestamp2 = (Int_t)v1->GetTimeStamp();
1825 timestamp2 = timeEnd+1;
1827 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1828 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
1830 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1832 else if (iCountsRun == 1){
1833 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1835 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1836 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1837 arrayValues = new Float_t[2];
1838 arrayWeights = new Double_t[2];
1839 arrayValues[0] = valueBeforeSOR;
1840 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1841 arrayValues[1] = (Float_t)v->GetUInt();
1842 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1843 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1844 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1845 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1848 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1849 return AliGRPObject::GetInvalidFloat();
1852 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1853 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1854 if (timestampBeforeSOR == -1){
1855 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1857 if (timestampAfterEOR == -1){
1858 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1860 return AliGRPObject::GetInvalidFloat();
1863 AliWarning("Using last entry before SOR and first entry after EOR.");
1865 arrayValues = new Float_t[2];
1866 arrayWeights = new Double_t[2];
1867 arrayValues[0] = valueBeforeSOR;
1868 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1869 arrayValues[1] = valueAfterEOR;
1870 arrayWeights[1] = 1.;
1871 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1872 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1873 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1877 AliInfo(Form("mean = %f ",aDCSArrayMean));
1878 return aDCSArrayMean;
1883 //_______________________________________________________________
1885 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1887 // extract DCS pressure maps. Perform fits to save space
1889 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1891 fPressure->MakeSplineFit(map);
1892 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1893 if (fitFraction > kFitFraction ) {
1894 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
1896 AliInfo("Too few pressure maps fitted!!!");
1899 AliInfo("no atmospheric pressure map extracted!!!");
1908 //_______________________________________________________________
1909 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)
1912 // Retrieves logbook and trigger information from the online logbook
1913 // This information is needed for prompt reconstruction
1917 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1921 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1922 // 0 on success and no run was found
1923 // negative on error
1925 // This function is NOT called during the preprocessor run in the Shuttle!
1933 AliCDBManager* cdb = AliCDBManager::Instance();
1934 cdb->SetDefaultStorage(cdbRoot);
1937 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1941 Printf("ERROR: Could not connect to DAQ LB");
1947 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1948 TSQLResult* result = server->Query(sqlQuery);
1951 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1955 if (result->GetRowCount() == 0)
1957 Printf("ERROR: Run %d not found", run);
1962 TSQLRow* row = result->Next();
1965 Printf("ERROR: Could not receive data from run %d", run);
1970 TString timeStartString(row->GetField(0));
1971 TString runType(row->GetField(1));
1972 TString detectorMaskString(row->GetField(2));
1973 TString l3CurrentString(row->GetField(3));
1974 TString dipoleCurrentString(row->GetField(4));
1975 time_t timeStart = (time_t)(timeStartString.Atoi());
1976 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1977 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1978 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1979 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
1980 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
1982 AliGRPObject * grpObj = new AliGRPObject();
1983 grpObj->SetTimeStart(timeStart);
1984 grpObj->SetRunType((TString)(row->GetField(1)));
1985 grpObj->SetDetectorMask(detectorMask);
1986 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1987 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1988 grpObj->SetL3Polarity(l3Polarity);
1989 grpObj->SetDipolePolarity(dipolePolarity);
1997 Printf("Storing GRP/GRP/Data object with the following content");
2000 AliCDBMetaData metadata;
2001 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2002 metadata.SetComment("GRP Output parameters received during online running");
2004 AliCDBId id("GRP/GRP/Data", run, run);
2005 Bool_t success = cdb->Put(grpObj, id, &metadata);
2011 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2015 // Receive trigger information
2016 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2017 result = server->Query(sqlQuery);
2020 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2024 if (result->GetRowCount() == 0)
2026 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2031 row = result->Next();
2034 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2039 TString triggerConfig(row->GetField(0));
2047 Printf("Found trigger configuration: %s", triggerConfig.Data());
2049 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2052 Printf("ERROR: Could not create CTP configuration object");
2056 metadata.SetComment("CTP run configuration received during online running");
2058 AliCDBId id2("GRP/CTP/Config", run, run);
2059 success = cdb->Put(runcfg, id2, &metadata);
2066 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2071 // Receive list of GDCs for this run
2072 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2073 result = server->Query(sqlQuery);
2076 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2080 if (result->GetRowCount() == 0)
2082 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2088 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2089 row = result->Next();
2092 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2096 gdc += row->GetField(0);
2106 Printf("Found GDC: %s", gdc.Data());
2108 // get last run with same run type that was already processed by the SHUTTLE
2110 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());
2111 result = server->Query(sqlQuery);
2114 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2118 if (result->GetRowCount() == 0)
2120 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2125 row = result->Next();
2128 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2133 TString lastRunStr(row->GetField(0));
2134 Int_t lastRun = lastRunStr.Atoi();
2136 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);