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 = -1.; // 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),fdaqStartEndTimeOk(kTRUE)
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 (fdaqStartEndTimeOk){
332 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, LH3_BSF4_H3 are not working yet...
333 Log(Form("Problem with the DCS data points!!! Only %d/%d entries found",entries,fgknDCSDP-4));
336 else Log(Form("DCS data points, successful!"));
338 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"));
340 //=======================//
341 // Trigger Configuration //
342 //=======================//
344 const char * triggerConf = GetTriggerConfiguration();
346 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
347 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
348 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
350 Log(Form("No dummy CTP configuration entry found, going into error..."));
354 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
356 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
360 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
361 runcfg->SetTitle(titleCTPcfg);
362 AliCDBMetaData metaData;
363 metaData.SetResponsible("Roman Lietava");
364 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
365 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
366 Log("Unable to store the dummy CTP run configuration object to OCDB!");
373 else if (!partition.IsNull() && detector.IsNull()){ // global partition
374 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
375 if (triggerConf!= NULL) {
376 Log("Found trigger configuration in DAQ logbook");
377 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
379 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
383 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
384 runcfg->SetTitle(titleCTPcfg);
385 AliCDBMetaData metaData;
386 metaData.SetBeamPeriod(0);
387 metaData.SetResponsible("Roman Lietava");
388 metaData.SetComment("CTP run configuration from DAQ logbook");
389 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
390 Log("Unable to store the CTP run configuration object to OCDB!");
397 Log("Trigger configuration NULL in DAQ logbook");
403 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
407 //===========================//
408 // Trigger Timing Parameters //
409 //===========================//
412 const char * triggerCTPtiming = GetCTPTimeParams();
414 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
415 Log("STANDALONE partition for current run, using CTP timing params dummy value");
416 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
418 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
422 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
424 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
428 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
429 runCTPtiming->SetTitle(titleCTPtiming);
430 AliCDBMetaData metadata;
431 metadata.SetResponsible("Roman Lietava");
432 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
433 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
434 Log("Unable to store the dummy CTP timing params object to OCDB!");
441 else if (!partition.IsNull() && detector.IsNull()){ // global partition
442 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
443 if (triggerCTPtiming!= NULL) {
444 Log("Found trigger timing params in DAQ logbook");
445 AliDebug(2,Form("%s",triggerCTPtiming));
446 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
448 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
452 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
453 runCTPtiming->SetTitle(titleCTPtiming);
454 AliCDBMetaData metadata;
455 metadata.SetBeamPeriod(0);
456 metadata.SetResponsible("Roman Lietava");
457 metadata.SetComment("CTP timing params from DAQ logbook");
458 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
459 Log("Unable to store the CTP timing params object to OCDB!");
466 Log("Trigger timing params NULL in DAQ logbook");
472 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
475 // storing AliGRPObject in OCDB
478 md.SetResponsible("Chiara Zampolli");
479 md.SetComment("Output parameters from the GRP preprocessor.");
481 Bool_t result = kTRUE;
482 result = Store("GRP", "Data", grpobj, &md);
485 if (result && !error ) {
486 Log("GRP Preprocessor Success");
489 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s",
490 kppError[(error&1)?1:0],
491 kppError[(error&2)?2:0],
492 kppError[(error&4)?3:0],
493 kppError[(error&8)?4:0],
494 kppError[(error&16)?5:0],
495 kppError[(error&32)?6:0],
496 kppError[(error&64)?7:0]
502 //_______________________________________________________________
504 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
506 //Getting the DAQ lb information
508 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
509 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
510 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
511 TString beamType = (TString)GetRunParameter("beamType");
512 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
513 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
514 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
515 TString runType = (TString)GetRunType();
517 UInt_t nparameter = 0;
519 grpObj->SetTimeStart(timeStart);
520 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
524 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
528 grpObj->SetTimeEnd(timeEnd);
529 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
533 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
536 if (beamEnergy != 0){
537 grpObj->SetBeamEnergy(beamEnergy);
538 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
539 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
540 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
541 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
545 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
546 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
547 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()));
550 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()));
555 if (beamType.Length() != 0){
556 grpObj->SetBeamType(beamType);
557 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
561 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
565 if (numberOfDetectors != 0){
566 grpObj->SetNumberOfDetectors(numberOfDetectors);
567 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
571 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
574 if (detectorMask != 0){
575 grpObj->SetDetectorMask(detectorMask);
576 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
580 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
583 if (lhcPeriod.Length() != 0) {
584 grpObj->SetLHCPeriod(lhcPeriod);
585 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
589 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
591 if (runType.Length() != 0) {
592 grpObj->SetRunType(runType);
593 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
597 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
603 //_______________________________________________________________
605 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
607 //======DAQ FXS======//
609 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
610 TList* list = GetFileSources(kDAQ);
612 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
616 if (list->GetEntries() == 0) {
617 Log("no raw data tags in this run: nothing to merge!");
622 TChain *fRawTagChain = new TChain("T");
624 TIterator* iter = list->MakeIterator();
626 while ((obj = iter->Next())) {
627 TObjString* objStr = dynamic_cast<TObjString*> (obj);
629 Log(Form("Found source %s", objStr->String().Data()));
630 TList* list2 = GetFileIDs(kDAQ, objStr->String());
632 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
633 delete fRawTagChain; fRawTagChain=0;
636 Log(Form("Number of ids: %d",list2->GetEntries()));
637 for(Int_t i = 0; i < list2->GetEntries(); i++) {
638 TObjString *idStr = (TObjString *)list2->At(i);
639 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
640 if (fileName.Length() > 0) {
641 Log(Form("Adding file in the chain: %s",fileName.Data()));
642 fRawTagChain->Add(fileName.Data());
645 Log(Form("Could not retrieve file with id %s from source %s: "
646 "connection problems with DAQ FXS!",
647 idStr->String().Data(), objStr->String().Data()));
649 delete list2; list2=0;
650 delete fRawTagChain; fRawTagChain=0;
658 TString fRawDataFileName = "GRP_Merged.tag.root";
659 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
661 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
662 Log("Error merging raw data files!!!");
666 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
667 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
670 Log("Problem storing raw data tags in local file!!!");
672 Log("Raw data tags merged successfully!!");
677 delete fRawTagChain; fRawTagChain=0;
679 if (result == kFALSE) {
687 //_______________________________________________________________
688 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
691 // processing the info
692 // stored in the DCS FXS
693 // coming from the trigger
695 // Get the CTP counters information
697 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
698 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
699 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
701 Log(Form("No dummy CTP scalers entry found, going into error..."));
705 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
707 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
711 AliCDBMetaData metaData;
712 metaData.SetResponsible("Roman Lietava");
713 metaData.SetComment("CTP scalers from dummy entry in OCDB");
714 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
715 Log("Unable to store the dummy CTP scalers object to OCDB!");
722 else if (!partition.IsNull() && detector.IsNull()){ // global partition
723 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
724 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
725 if (countersfile.IsNull()) {
726 Log("No CTP counters files has been found: empty source!");
730 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
731 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
733 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
737 AliCDBMetaData metaData;
738 metaData.SetBeamPeriod(0);
739 metaData.SetResponsible("Roman Lietava");
740 metaData.SetComment("CTP scalers");
741 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
742 Log("Unable to store the CTP scalers object to OCDB!");
751 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
758 //_______________________________________________________________
760 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
764 // processing DCS DPs
767 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
768 Int_t nLHCEntries = 0;
769 Int_t nL3Entries = 0;
770 Int_t nDipoleEntries = 0;
771 Int_t nEnvEntries = 0;
772 Int_t nHallProbesEntries = 0;
773 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
774 nL3Entries = ProcessL3DPs(valueMap, grpObj);
775 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
776 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
777 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
778 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
779 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
784 //_______________________________________________________________
786 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
793 Int_t nL3Entries = 0;
794 TObjArray *array = 0x0;
796 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
798 AliInfo(Form("==========L3Current==========="));
799 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
800 indexDP = kL3Current;
801 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
803 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
806 if (array->GetEntries() == 0){
807 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
810 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
811 if (floatDCS != NULL){
812 grpObj->SetL3Current(floatDCS);
822 if (!outOfRange) nL3Entries++;
825 if (array) array = 0x0;
827 AliInfo(Form("==========L3Polarity==========="));
828 indexDP = kL3Polarity;
829 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
831 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
834 if (array->GetEntries() == 0){
835 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
838 Bool_t change = kFALSE;
839 Char_t charDCS = ProcessBool(array,change);
840 if (change == kFALSE){
841 grpObj->SetL3Polarity(charDCS);
842 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
846 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
850 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]));
858 //_______________________________________________________________
860 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
866 Int_t nDipoleEntries = 0;
867 TObjArray *array = 0x0;
869 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
871 AliInfo(Form("==========DipoleCurrent==========="));
872 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
873 indexDP = kDipoleCurrent;
874 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
876 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
879 if (array->GetEntries() == 0){
880 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
883 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
884 if (floatDCS != NULL){
885 grpObj->SetDipoleCurrent(floatDCS);
895 if (!outOfRange) nDipoleEntries++;
898 if (array) array = 0x0;
900 AliInfo(Form("==========DipolePolarity==========="));
901 indexDP = kDipolePolarity;
902 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
904 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
907 if (array->GetEntries() == 0){
908 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
911 Bool_t change = kFALSE;
912 Char_t charDCS = ProcessBool(array,change);
914 grpObj->SetDipolePolarity(charDCS);
915 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
919 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
923 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]));
928 return nDipoleEntries;
931 //_______________________________________________________________
933 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
937 // evironment conditions (temperature, pressure) info
939 Int_t nEnvEntries = 0;
940 TObjArray *array = 0x0;
943 AliInfo(Form("==========CavernTemperature==========="));
944 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
945 indexDP = kCavernTemperature;
946 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
948 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
951 if (array->GetEntries() == 0){
952 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
955 Float_t *floatDCS = ProcessFloatAll(array);
956 if (floatDCS != NULL){
957 grpObj->SetCavernTemperature(floatDCS);
967 if (!outOfRange) nEnvEntries++;
970 if (array) array = 0x0;
972 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
973 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
974 //dcsSensorArray->Print();
975 if( fPressure->NumFits()<kNumSensors ) {
976 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
978 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
980 AliInfo(Form("==========CavernAtmosPressure==========="));
981 indexDP = kCavernAtmosPressure;
982 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
983 TGraph* graph = sensorCavernP2->GetGraph();
984 AliDebug(2,Form("graph = %p",graph));
985 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
986 if(sensorCavernP2->GetFit() || graph) {
987 if (sensorCavernP2->GetFit()){
988 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
991 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
993 grpObj->SetCavernAtmosPressure(sensorCavernP2);
996 //if (sensorP2) delete sensorP2;
998 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] ));
1001 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1002 indexDP = kSurfaceAtmosPressure;
1003 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1004 graph = sensorP2->GetGraph();
1005 AliDebug(2,Form("graph = %p",graph));
1006 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1007 if(sensorP2->GetFit() || graph) {
1008 if (sensorP2->GetFit()){
1009 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1012 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1014 grpObj->SetSurfaceAtmosPressure(sensorP2);
1017 //if (sensorP2) delete sensorP2;
1019 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] ));
1022 AliInfo(Form("==========CavernAtmosPressure2==========="));
1023 indexDP = kCavernAtmosPressure2;
1024 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1025 graph = sensorP2->GetGraph();
1026 AliDebug(2,Form("graph = %p",graph));
1027 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1028 if(sensorCavernP22->GetFit() || graph) {
1029 if (sensorCavernP22->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->SetCavernAtmosPressure2(sensorCavernP22);
1038 //if (sensorP2) delete sensorP2;
1040 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] ));
1046 //_______________________________________________________________
1048 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1054 Int_t nHPEntries = 0;
1055 TObjArray *array = 0x0;
1057 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1059 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1060 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()));
1062 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1063 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1064 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1065 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1067 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1070 if (array->GetEntries() == 0){
1071 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1074 Float_t *floatDCS = ProcessFloatAll(array);
1075 if (floatDCS != NULL){
1076 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]));
1077 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1078 for (Int_t kk = 0 ; kk< 5; kk++){
1079 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1090 if (!outOfRange) nHPEntries++;
1094 Log(Form("Hall Probes = %d ", nHPEntries));
1098 //_______________________________________________________________
1100 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
1104 // processing of LHC related DCS DPs, i.e.:
1110 Int_t nLHCEntries = 0;
1111 TObjArray *array = 0x0;
1114 AliInfo(Form("==========LHCState==========="));
1115 indexDP = kLHCState;
1116 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1118 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1121 if (array->GetEntries() == 0){
1122 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1125 TString stringDCS = ProcessChar(array);
1126 if (stringDCS.Length()!=0) {
1127 Bool_t found = kFALSE;
1128 for( Int_t i=0; i<20; i+=2 ) {
1129 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
1130 stringDCS = fgkLHCState[i+1];
1136 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
1137 grpObj->SetLHCState(stringDCS);
1140 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
1141 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1145 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
1146 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1152 if (array) array = 0x0;
1154 AliInfo(Form("==========LHCLuminosity==========="));
1155 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1156 indexDP = kLHCLuminosity;
1157 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1159 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1162 if (array->GetEntries() == 0){
1163 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1166 Float_t *floatDCS = ProcessFloatAll(array);
1167 if (floatDCS != NULL){
1168 grpObj->SetLHCLuminosity(floatDCS);
1169 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1170 grpObj->SetLHCLuminositySplineFit(splfit);
1181 if (!outOfRange) nLHCEntries++;
1184 if (array) array = 0x0;
1186 AliInfo(Form("==========BeamIntensity==========="));
1187 if (outOfRange) outOfRange = kFALSE; // resetting outOfRange if needed
1188 indexDP = kBeamIntensity;
1189 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1191 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1194 if (array->GetEntries() == 0){
1195 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1198 Float_t *floatDCS = ProcessFloatAll(array);
1199 if (floatDCS != NULL){
1200 grpObj->SetBeamIntensity(floatDCS);
1201 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1202 grpObj->SetBeamIntensitySplineFit(splfit1);
1213 if (!outOfRange) nLHCEntries++;
1218 //_________________________________________________________________________
1220 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1224 // returning Spline Fit
1227 Int_t entriesarray = array->GetEntries();
1228 Float_t* value = new Float_t[entriesarray];
1229 Float_t* time = new Float_t[entriesarray];
1230 AliDCSValue* v = 0x0;
1231 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1232 v = (AliDCSValue*)array->At(iarray);
1233 value[iarray] = v->GetFloat();
1234 time[iarray] = v->GetTimeStamp();
1235 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1237 TGraph* gr = new TGraph(entriesarray,value,time);
1239 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1242 AliSplineFit *fit = new AliSplineFit();
1243 fit->SetMinPoints(10);
1244 fit->InitKnots(gr,10,10,0.0);
1248 AliWarning(Form("%s: no fit performed",stringID.Data()));
1254 //_________________________________________________________________________
1256 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1263 TString aDCSString="";
1265 AliDCSValue *v = 0x0;
1266 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1267 v = (AliDCSValue *)array->At(iCount);
1268 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1269 AliError(Form("DCS values for the parameter outside the queried interval"));
1273 if (aDCSString != v->GetChar())
1274 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1276 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1281 //__________________________________________________________________________________________________________________
1283 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1286 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1288 // parameters[0] = mean
1289 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1290 // parameters[2] = median
1291 // parameters[3] = standard deviation wrt mean
1292 // parameters[4] = standard deviation wrt median
1295 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1296 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1297 if (timeStartString.IsNull() || timeStartString.IsNull()){
1298 if (timeStartString.IsNull()){
1299 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1301 else if (timeStartString.IsNull()){
1302 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1304 fdaqStartEndTimeOk = kFALSE;
1308 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1309 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1310 Float_t* parameters = new Float_t[5];
1312 Int_t iCountsRun = 0;
1313 Int_t nCounts = array->GetEntries();
1314 Float_t valueBeforeSOR = 0;
1315 Float_t valueAfterEOR = 0;
1316 Int_t timestampBeforeSOR = -1;
1317 Int_t timestampAfterEOR = -1;
1318 Int_t ientrySOR = -1;
1319 Int_t ientryEOR = -1;
1320 Float_t* arrayValues = 0x0;
1321 Double_t* arrayWeights = 0x0;
1322 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1323 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1325 for(Int_t i = 0; i < nCounts; i++) {
1326 AliDCSValue *v = (AliDCSValue *)array->At(i);
1327 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1328 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1329 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1330 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1333 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1334 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1336 // look for the last value before SOR and the first value before EOR
1337 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1338 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1339 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1340 valueBeforeSOR = v->GetFloat();
1342 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1343 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1344 valueAfterEOR = v->GetFloat();
1345 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1347 // check if there are DPs between DAQ_time_start and DAQ_time_end
1348 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1349 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1350 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1351 AliDebug(2,Form("entry between SOR and EOR"));
1356 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1360 if (timestampBeforeSOR == -1){
1361 AliWarning("No value found before SOR");
1363 if (timestampAfterEOR == -1){
1364 AliWarning("No value found after EOR");
1367 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1368 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1369 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1370 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1371 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1372 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1374 Int_t nentriesUsed = 0;
1375 if (iCountsRun > 1){
1376 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1377 AliDebug(2,"Calculating (weighted) Mean and Median");
1378 arrayValues = new Float_t[iCountsRun];
1379 arrayWeights = new Double_t[iCountsRun];
1380 nentriesUsed = iCountsRun;
1381 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1382 AliDCSValue *v = (AliDCSValue *)array->At(i);
1383 Int_t timestamp2 = 0;
1385 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1386 timestamp2 = (Int_t)v1->GetTimeStamp();
1389 timestamp2 = timeEnd+1;
1391 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1392 arrayValues[i-ientrySOR] = v->GetFloat();
1394 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1395 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1397 else if (iCountsRun == 1){
1398 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1400 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1401 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.");
1402 arrayValues = new Float_t[2];
1403 arrayWeights = new Double_t[2];
1404 arrayValues[0] = valueBeforeSOR;
1405 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1406 arrayValues[1] = v->GetFloat();
1407 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1408 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1409 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1410 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1411 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1412 truncMeanFlag = kFALSE;
1415 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");
1416 parameters[0] = AliGRPObject::GetInvalidFloat();
1417 parameters[1] = AliGRPObject::GetInvalidFloat();
1418 parameters[2] = AliGRPObject::GetInvalidFloat();
1419 parameters[3] = AliGRPObject::GetInvalidFloat();
1420 parameters[4] = AliGRPObject::GetInvalidFloat();
1424 else { // iCountsRun == 0, using only the point immediately before SOR
1425 if (timestampBeforeSOR == -1){
1426 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");
1427 parameters[0] = AliGRPObject::GetInvalidFloat();
1428 parameters[1] = AliGRPObject::GetInvalidFloat();
1429 parameters[2] = AliGRPObject::GetInvalidFloat();
1430 parameters[3] = AliGRPObject::GetInvalidFloat();
1431 parameters[4] = AliGRPObject::GetInvalidFloat();
1435 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1436 AliDebug(2,Form("value = %f",valueBeforeSOR));
1437 parameters[0] = valueBeforeSOR;
1438 parameters[2] = valueBeforeSOR;
1439 truncMeanFlag = kFALSE;
1446 Float_t sumweights = 0;
1447 Int_t entriesTruncMean = 0;
1448 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1449 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1451 // calculating SD wrt Mean and Median
1452 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1454 for (Int_t i =0; i< nentriesUsed; i++){
1455 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1456 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1457 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1458 sumweights += arrayWeights[i];
1460 // setting SD wrt Mean
1461 if (sumweights != 0 ){
1462 parameters[3] = TMath::Sqrt(temp1/sumweights);
1465 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1466 parameters[3] = AliGRPObject::GetInvalidFloat();
1468 // setting SD wrt Median
1469 if (nentriesUsed != 0){
1470 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1473 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1474 parameters[4] = AliGRPObject::GetInvalidFloat();
1478 parameters[3] = AliGRPObject::GetInvalidFloat();
1479 parameters[4] = AliGRPObject::GetInvalidFloat();
1482 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1484 AliDebug(2,"Calculating Truncated Mean");
1485 for (Int_t i =0; i< nentriesUsed; i++){
1486 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1487 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1488 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1489 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1490 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1494 AliDebug(2,"Discarding entry");
1497 // setting truncated mean
1498 if (entriesTruncMean >1){
1499 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1500 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1503 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1504 parameters[1] = AliGRPObject::GetInvalidFloat();
1508 parameters[1] = AliGRPObject::GetInvalidFloat();
1511 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1512 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1513 AliInfo(Form("median = %f ",parameters[2]));
1514 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1515 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1520 //__________________________________________________________________________________________________________________
1522 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1525 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1526 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1527 // the flag is set according to the L3/Dipole current value
1528 // current threshold for L3 = 350 A (value provided by DCS)
1529 // current threshold for Dipole = 450 A (value provided by DCS)
1531 // parameters[0] = mean
1532 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1533 // parameters[2] = median
1534 // parameters[3] = standard deviation wrt mean
1535 // parameters[4] = standard deviation wrt median
1538 AliInfo(Form("indexDP = %d",indexDP));
1540 Int_t nCounts = array->GetEntries();
1541 for(Int_t i = 0; i < nCounts; i++) {
1542 AliDCSValue *v = (AliDCSValue *)array->At(i);
1543 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1544 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1545 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1546 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1549 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1550 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1551 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1552 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1555 AliError(Form("DCS values for the parameter outside the queried interval"));
1559 return ProcessFloatAll(array);
1563 //_______________________________________________________________
1565 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1568 // processing Boolean values
1571 Bool_t aDCSBool = kTRUE;
1573 AliDCSValue *v = 0x0;
1575 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1576 v = (AliDCSValue *)array->At(iCount);
1577 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1578 AliError(Form("DCS values for the parameter outside the queried interval"));
1582 if (aDCSBool != v->GetBool()) {
1583 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1587 aDCSBool = v->GetBool(); // always keeping last value
1588 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1591 Char_t caDCSBool = (Char_t) aDCSBool;
1596 //_______________________________________________________________
1598 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1601 // processing Int values, returning mean
1602 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1603 // are outside the queried time interval or their value is out of range
1606 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1607 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1608 if (timeStartString.IsNull() || timeStartString.IsNull()){
1609 if (timeStartString.IsNull()){
1610 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1612 else if (timeStartString.IsNull()){
1613 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1618 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1619 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1620 Float_t aDCSArrayMean = 0.0;
1622 Float_t valueBeforeSOR = 0;
1623 Float_t valueAfterEOR = 0;
1624 Int_t timestampBeforeSOR = -1;
1625 Int_t timestampAfterEOR = -1;
1626 Int_t ientrySOR = -1;
1627 Int_t ientryEOR = -1;
1628 Float_t* arrayValues = 0x0;
1629 Double_t* arrayWeights = 0x0;
1630 Int_t iCountsRun = 0;
1631 Int_t nCounts = array->GetEntries();
1633 for(Int_t i = 0; i < nCounts; i++) {
1634 AliDCSValue* v = (AliDCSValue *)array->At(i);
1635 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1636 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1637 return AliGRPObject::GetInvalidFloat();
1639 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1640 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1642 // look for the last value before SOR and the first value before EOR
1643 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1644 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1645 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1646 valueBeforeSOR = (Float_t) v->GetInt();
1648 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1649 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1650 valueAfterEOR = (Float_t) v->GetInt();
1651 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1653 // check if there are DPs between DAQ_time_start and DAQ_time_end
1654 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1655 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1656 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1657 AliDebug(2,Form("entry between SOR and EOR"));
1662 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1666 if (timestampBeforeSOR == -1){
1667 AliWarning("No value found before SOR!");
1669 if (timestampAfterEOR == -1){
1670 AliWarning("No value found after EOR!");
1673 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1674 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1675 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1676 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1677 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1678 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1680 Int_t nentriesUsed = 0;
1681 if (iCountsRun > 1){
1682 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1683 AliDebug(2,"Calculating (weighted) Mean");
1684 arrayValues = new Float_t[iCountsRun];
1685 arrayWeights = new Double_t[iCountsRun];
1686 nentriesUsed = iCountsRun;
1687 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1688 AliDCSValue *v = (AliDCSValue *)array->At(i);
1689 Int_t timestamp2 = 0;
1691 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1692 timestamp2 = (Int_t)v1->GetTimeStamp();
1695 timestamp2 = timeEnd+1;
1697 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1698 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1700 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1702 else if (iCountsRun == 1){
1703 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1705 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1706 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1707 arrayValues = new Float_t[2];
1708 arrayWeights = new Double_t[2];
1709 arrayValues[0] = valueBeforeSOR;
1710 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1711 arrayValues[1] = (Float_t)v->GetInt();
1712 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1713 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1714 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1715 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1718 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1719 return AliGRPObject::GetInvalidFloat();
1722 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1723 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1724 if (timestampBeforeSOR == -1){
1725 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1727 if (timestampAfterEOR == -1){
1728 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1730 return AliGRPObject::GetInvalidFloat();
1733 AliWarning("Using last entry before SOR and first entry after EOR.");
1735 arrayValues = new Float_t[2];
1736 arrayWeights = new Double_t[2];
1737 arrayValues[0] = valueBeforeSOR;
1738 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1739 arrayValues[1] = valueAfterEOR;
1740 arrayWeights[1] = 1.;
1741 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1742 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1743 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1747 AliInfo(Form("mean = %f ", aDCSArrayMean));
1748 return aDCSArrayMean;
1751 //_______________________________________________________________
1753 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1756 // processing Int values, returning mean
1757 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1758 // are outside the queried time interval or their value is out of range
1761 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1762 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1763 if (timeStartString.IsNull() || timeStartString.IsNull()){
1764 if (timeStartString.IsNull()){
1765 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1767 else if (timeStartString.IsNull()){
1768 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1773 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1774 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1775 Float_t aDCSArrayMean = 0.0;
1777 Float_t valueBeforeSOR = 0;
1778 Float_t valueAfterEOR = 0;
1779 Int_t timestampBeforeSOR = -1;
1780 Int_t timestampAfterEOR = -1;
1781 Int_t ientrySOR = -1;
1782 Int_t ientryEOR = -1;
1783 Float_t* arrayValues = 0x0;
1784 Double_t* arrayWeights = 0x0;
1785 Int_t iCountsRun = 0;
1786 Int_t nCounts = array->GetEntries();
1788 for(Int_t i = 0; i < nCounts; i++) {
1789 AliDCSValue* v = (AliDCSValue *)array->At(i);
1790 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
1791 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
1792 return AliGRPObject::GetInvalidFloat();
1794 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1795 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
1797 // look for the last value before SOR and the first value before EOR
1798 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1799 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1800 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1801 valueBeforeSOR = (Float_t)v->GetUInt();
1803 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1804 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1805 valueAfterEOR = (Float_t)v->GetUInt();
1806 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1808 // check if there are DPs between DAQ_time_start and DAQ_time_end
1809 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1810 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1811 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1812 AliDebug(2,Form("entry between SOR and EOR"));
1817 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1821 if (timestampBeforeSOR == -1){
1822 AliWarning("No value found before SOR!");
1824 if (timestampAfterEOR == -1){
1825 AliWarning("No value found after EOR!");
1828 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1829 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1830 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1831 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1832 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1833 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1835 Int_t nentriesUsed = 0;
1836 if (iCountsRun > 1){
1837 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1838 AliDebug(2,"Calculating (weighted) Mean");
1839 arrayValues = new Float_t[iCountsRun];
1840 arrayWeights = new Double_t[iCountsRun];
1841 nentriesUsed = iCountsRun;
1842 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1843 AliDCSValue *v = (AliDCSValue *)array->At(i);
1844 Int_t timestamp2 = 0;
1846 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1847 timestamp2 = (Int_t)v1->GetTimeStamp();
1850 timestamp2 = timeEnd+1;
1852 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1853 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
1855 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1857 else if (iCountsRun == 1){
1858 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1860 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1861 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1862 arrayValues = new Float_t[2];
1863 arrayWeights = new Double_t[2];
1864 arrayValues[0] = valueBeforeSOR;
1865 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1866 arrayValues[1] = (Float_t)v->GetUInt();
1867 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1868 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1869 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1870 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1873 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1874 return AliGRPObject::GetInvalidFloat();
1877 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1878 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1879 if (timestampBeforeSOR == -1){
1880 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1882 if (timestampAfterEOR == -1){
1883 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1885 return AliGRPObject::GetInvalidFloat();
1888 AliWarning("Using last entry before SOR and first entry after EOR.");
1890 arrayValues = new Float_t[2];
1891 arrayWeights = new Double_t[2];
1892 arrayValues[0] = valueBeforeSOR;
1893 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1894 arrayValues[1] = valueAfterEOR;
1895 arrayWeights[1] = 1.;
1896 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1897 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1898 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1902 AliInfo(Form("mean = %f ",aDCSArrayMean));
1903 return aDCSArrayMean;
1908 //_______________________________________________________________
1910 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1912 // extract DCS pressure maps. Perform fits to save space
1914 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1916 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
1917 fPressure->MakeSplineFit(map);
1918 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1919 if (fitFraction > kFitFraction ) {
1920 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
1922 AliInfo("Too few pressure maps fitted!!!");
1925 AliInfo("no atmospheric pressure map extracted!!!");
1934 //_______________________________________________________________
1935 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)
1938 // Retrieves logbook and trigger information from the online logbook
1939 // This information is needed for prompt reconstruction
1943 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1947 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1948 // 0 on success and no run was found
1949 // negative on error
1951 // This function is NOT called during the preprocessor run in the Shuttle!
1959 AliCDBManager* cdb = AliCDBManager::Instance();
1960 cdb->SetDefaultStorage(cdbRoot);
1963 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1967 Printf("ERROR: Could not connect to DAQ LB");
1973 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1974 TSQLResult* result = server->Query(sqlQuery);
1977 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1981 if (result->GetRowCount() == 0)
1983 Printf("ERROR: Run %d not found", run);
1988 TSQLRow* row = result->Next();
1991 Printf("ERROR: Could not receive data from run %d", run);
1996 TString timeStartString(row->GetField(0));
1997 TString runType(row->GetField(1));
1998 TString detectorMaskString(row->GetField(2));
1999 TString l3CurrentString(row->GetField(3));
2000 TString dipoleCurrentString(row->GetField(4));
2001 time_t timeStart = (time_t)(timeStartString.Atoi());
2002 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2003 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2004 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2005 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2006 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2008 AliGRPObject * grpObj = new AliGRPObject();
2009 grpObj->SetTimeStart(timeStart);
2010 grpObj->SetRunType((TString)(row->GetField(1)));
2011 grpObj->SetDetectorMask(detectorMask);
2012 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2013 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2014 grpObj->SetL3Polarity(l3Polarity);
2015 grpObj->SetDipolePolarity(dipolePolarity);
2023 Printf("Storing GRP/GRP/Data object with the following content");
2026 AliCDBMetaData metadata;
2027 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2028 metadata.SetComment("GRP Output parameters received during online running");
2030 AliCDBId id("GRP/GRP/Data", run, run);
2031 Bool_t success = cdb->Put(grpObj, id, &metadata);
2037 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2041 // Receive trigger information
2042 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2043 result = server->Query(sqlQuery);
2046 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2050 if (result->GetRowCount() == 0)
2052 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2057 row = result->Next();
2060 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2065 TString triggerConfig(row->GetField(0));
2073 Printf("Found trigger configuration: %s", triggerConfig.Data());
2075 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2078 Printf("ERROR: Could not create CTP configuration object");
2082 metadata.SetComment("CTP run configuration received during online running");
2084 AliCDBId id2("GRP/CTP/Config", run, run);
2085 success = cdb->Put(runcfg, id2, &metadata);
2092 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2097 // Receive list of GDCs for this run
2098 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2099 result = server->Query(sqlQuery);
2102 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2106 if (result->GetRowCount() == 0)
2108 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2114 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2115 row = result->Next();
2118 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2122 gdc += row->GetField(0);
2132 Printf("Found GDC: %s", gdc.Data());
2134 // get last run with same run type that was already processed by the SHUTTLE
2136 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());
2137 result = server->Query(sqlQuery);
2140 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2144 if (result->GetRowCount() == 0)
2146 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2151 row = result->Next();
2154 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2159 TString lastRunStr(row->GetField(0));
2160 Int_t lastRun = lastRunStr.Atoi();
2162 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);