1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Class AliGRPPreprocessor
20 // Global Run Parameters (GRP) preprocessor
21 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 // Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN
23 // Modified: Chiara.Zampolli@cern.ch CERN
24 //-------------------------------------------------------------------------
29 #include <TObjString.h>
30 #include <TObjArray.h>
36 #include "AliGRPPreprocessor.h"
37 #include "AliGRPObject.h"
38 #include "AliDCSSensor.h"
39 #include "AliSplineFit.h"
40 #include "AliDCSSensorArray.h"
41 #include "AliRawEventHeaderVersions.h"
43 #include "AliTriggerConfiguration.h"
44 #include "AliTriggerRunScalers.h"
46 #include "AliCDBMetaData.h"
50 class AliShuttleInterface;
52 // needed for ReceivePromptRecoParameters
54 #include <TSQLServer.h>
55 #include <TSQLResult.h>
57 #include <AliCDBManager.h>
58 #include <AliCDBMetaData.h>
60 #include <AliTriggerConfiguration.h>
61 #include <AliCTPTimeParams.h>
63 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
65 ClassImp(AliGRPPreprocessor)
67 //_______________________________________________________________
69 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook for PHYSICS runs, when beamType from DAQ logbook == NULL
70 const Int_t AliGRPPreprocessor::fgknDAQLbParReduced = 7; // num parameters in the logbook for the other cases
71 const Int_t AliGRPPreprocessor::fgknDCSDP = 51; // number of dcs dps
72 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
73 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
74 "LHCState", // missing in DCS
77 "LHCLuminosity", // missing in DCS
78 "BeamIntensity", // missing in DCS
84 "L3_BSF17_Temperature",
88 "L3_BSF4_Temperature",
92 "L3_BKF17_Temperature",
96 "L3_BKF4_Temperature",
100 "L3_BSF13_Temperature",
104 "L3_BSF8_Temperature",
108 "L3_BKF13_Temperature",
112 "L3_BKF8_Temperature",
116 "Dipole_Inside_Temperature",
120 "Dipole_Outside_Temperature",
122 "CavernAtmosPressure",
123 "SurfaceAtmosPressure",
124 "CavernAtmosPressure2"
127 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
131 "L3_BSF17_Temperature",
135 "L3_BSF4_Temperature",
139 "L3_BKF17_Temperature",
143 "L3_BKF4_Temperature",
147 "L3_BSF13_Temperature",
151 "L3_BSF8_Temperature",
155 "L3_BKF13_Temperature",
159 "L3_BKF8_Temperature",
163 "Dipole_Inside_Temperature",
167 "Dipole_Outside_Temperature"
170 const Short_t kSensors = 48; // start index position of sensor in DCS DPs
171 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
174 const char* AliGRPPreprocessor::fgkLHCState[20] = {
180 "U", "UNSTABLE BEAMS",
187 const char* kppError[] = {
189 "(DAQ logbook ERROR)",
191 "(Trigger Scalers not found in DCS FXS - ERROR)",
192 "(DCS data points ERROR)",
193 "(Trigger Configuration ERROR)",
194 "(DAQ logbook ERROR determining partition of the run)",
198 //_______________________________________________________________
200 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
201 AliPreprocessor("GRP",shuttle), fPressure(0), fmaxFloat(0), fminFloat(0),fmaxDouble(0), fminDouble(0), fmaxInt(0), fminInt(0), fmaxUInt(0), fminUInt(0),fdaqStartEndTimeOk(kTRUE),ffailedDPs(new TObjArray(fgknDCSDP))
203 // constructor - shuttle must be instantiated!
205 AddRunType("COSMIC");
207 AddRunType("PHYSICS");
208 AddRunType("CALIBRATION_BC");
209 AddRunType("CALIBRATION_CENTRAL");
210 AddRunType("CALIBRATION_EMD");
211 AddRunType("CALIBRATION_MB");
212 AddRunType("CALIBRATION_SEMICENTRAL");
213 AddRunType("CALIBRATION");
214 AddRunType("PEDESTAL");
215 AddRunType("STANDALONE");
218 AddRunType("PULSER");
219 AddRunType("STANDALONE_PULSER");
222 fminFloat = -FLT_MAX;
223 fmaxDouble = DBL_MAX;
224 fminDouble = -DBL_MAX;
230 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
231 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
232 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
233 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
234 AliInfo(Form("Max allowed integer = %d",fmaxInt));
235 AliInfo(Form("Min allowed integer = %d",fminInt));
236 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
237 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
239 ffailedDPs->SetOwner(kTRUE);
242 //_______________________________________________________________
244 AliGRPPreprocessor::~AliGRPPreprocessor()
253 //_______________________________________________________________
255 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
257 // Initialize preprocessor
259 AliPreprocessor::Initialize(run, startTime, endTime);
261 AliInfo("Initialization of the GRP preprocessor.");
262 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
263 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
264 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
265 for(Int_t j = 0; j < kNumSensors; j++) {
266 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
267 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
269 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
271 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
273 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
274 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
275 ffailedDPs->AddAt(dp,iDP);
280 //_______________________________________________________________
282 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
284 // process data retrieved by the Shuttle
286 // retrieving "partition" and "detector" fields from DAQ logbook to
287 // determine the partition in which the run was taken
288 // the partition is used to decide how to react in case of errors for CTP
290 TString partition = (TString)GetRunParameter("partition");
291 TString detector = (TString)GetRunParameter("detector");
293 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
295 //=================//
297 //=================//
300 Int_t iDaqLB = ProcessDaqLB(grpobj);
301 TString runType = (TString)GetRunType();
302 TString beamType = (TString)GetRunParameter("beamType");
303 //if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
304 if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && !beamType.IsNull()) || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType.IsNull()) || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
305 Log(Form("DAQ Logbook, successful!"));
307 Log(Form("DAQ Logbook, could not get all expected entries!!!"));
311 //=================//
313 //=================//
314 UInt_t iDaqFxs = ProcessDaqFxs();
316 Log(Form("DAQ FXS, successful!"));
318 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
322 //=================//
324 //=================//
325 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
327 Log(Form("DCS FXS, successful!"));
328 } else if (iDcsFxs ==1) {
329 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
332 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
336 //=================//
337 // DCS data points //
338 //=================//
339 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
340 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
341 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-4));
342 if (fdaqStartEndTimeOk){
343 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, L3_BSF4_H3 are not working yet...
344 Log(Form("Problem with the DCS data points!!! Only %d/%d entries found",entries,fgknDCSDP-4));
345 Log(Form("The DPs giving problems were:"));
346 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
347 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
349 TString name = dpString->String();
350 if (name != "LHCState" && name != "LHCLuminosity" && name != "BeamIntensity" && name != "L3_BSF4_H3"){
351 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
354 Log(Form(" %s is not present, but was not generating any error since it is not ready in DCS - check the other DPs in this list!",name.Data()));
360 else Log(Form("DCS data points, successful!"));
362 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"));
364 //=======================//
365 // Trigger Configuration //
366 //=======================//
368 const char * triggerConf = GetTriggerConfiguration();
370 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
371 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
372 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
374 Log(Form("No dummy CTP configuration entry found, going into error..."));
378 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
380 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
384 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
385 runcfg->SetTitle(titleCTPcfg);
386 AliCDBMetaData metaData;
387 metaData.SetResponsible("Roman Lietava");
388 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
389 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
390 Log("Unable to store the dummy CTP run configuration object to OCDB!");
397 else if (!partition.IsNull() && detector.IsNull()){ // global partition
398 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
399 if (triggerConf!= NULL) {
400 Log("Found trigger configuration in DAQ logbook");
401 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
403 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
407 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
408 runcfg->SetTitle(titleCTPcfg);
409 AliCDBMetaData metaData;
410 metaData.SetBeamPeriod(0);
411 metaData.SetResponsible("Roman Lietava");
412 metaData.SetComment("CTP run configuration from DAQ logbook");
413 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
414 Log("Unable to store the CTP run configuration object to OCDB!");
421 Log("Trigger configuration NULL in DAQ logbook");
427 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
431 //===========================//
432 // Trigger Timing Parameters //
433 //===========================//
436 const char * triggerCTPtiming = GetCTPTimeParams();
438 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
439 Log("STANDALONE partition for current run, using CTP timing params dummy value");
440 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
442 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
446 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
448 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
452 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
453 runCTPtiming->SetTitle(titleCTPtiming);
454 AliCDBMetaData metadata;
455 metadata.SetResponsible("Roman Lietava");
456 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
457 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
458 Log("Unable to store the dummy CTP timing params object to OCDB!");
465 else if (!partition.IsNull() && detector.IsNull()){ // global partition
466 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
467 if (triggerCTPtiming!= NULL) {
468 Log("Found trigger timing params in DAQ logbook");
469 AliDebug(2,Form("%s",triggerCTPtiming));
470 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
472 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
476 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
477 runCTPtiming->SetTitle(titleCTPtiming);
478 AliCDBMetaData metadata;
479 metadata.SetBeamPeriod(0);
480 metadata.SetResponsible("Roman Lietava");
481 metadata.SetComment("CTP timing params from DAQ logbook");
482 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
483 Log("Unable to store the CTP timing params object to OCDB!");
490 Log("Trigger timing params NULL in DAQ logbook");
496 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
499 // storing AliGRPObject in OCDB
502 md.SetResponsible("Chiara Zampolli");
503 md.SetComment("Output parameters from the GRP preprocessor.");
505 Bool_t result = kTRUE;
506 result = Store("GRP", "Data", grpobj, &md);
509 if (result && !error ) {
510 Log("GRP Preprocessor Success");
513 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s",
514 kppError[(error&1)?1:0],
515 kppError[(error&2)?2:0],
516 kppError[(error&4)?3:0],
517 kppError[(error&8)?4:0],
518 kppError[(error&16)?5:0],
519 kppError[(error&32)?6:0],
520 kppError[(error&64)?7:0]
526 //_______________________________________________________________
528 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
530 //Getting the DAQ lb information
532 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
533 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
534 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
535 TString beamType = (TString)GetRunParameter("beamType");
536 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
537 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
538 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
539 TString runType = (TString)GetRunType();
541 UInt_t nparameter = 0;
543 grpObj->SetTimeStart(timeStart);
544 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
548 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
552 grpObj->SetTimeEnd(timeEnd);
553 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
557 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
560 if (beamEnergy != 0){
561 grpObj->SetBeamEnergy(beamEnergy);
562 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
563 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
564 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
565 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
569 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
570 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
571 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()));
574 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()));
579 if (beamType.Length() != 0){
580 grpObj->SetBeamType(beamType);
581 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
585 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
589 if (numberOfDetectors != 0){
590 grpObj->SetNumberOfDetectors(numberOfDetectors);
591 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
595 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
598 if (detectorMask != 0){
599 grpObj->SetDetectorMask(detectorMask);
600 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
604 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
607 if (lhcPeriod.Length() != 0) {
608 grpObj->SetLHCPeriod(lhcPeriod);
609 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
613 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
615 if (runType.Length() != 0) {
616 grpObj->SetRunType(runType);
617 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
621 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
627 //_______________________________________________________________
629 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
631 //======DAQ FXS======//
633 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
634 TList* list = GetFileSources(kDAQ);
636 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
640 if (list->GetEntries() == 0) {
641 Log("no raw data tags in this run: nothing to merge!");
646 TChain *fRawTagChain = new TChain("T");
648 TIterator* iter = list->MakeIterator();
650 while ((obj = iter->Next())) {
651 TObjString* objStr = dynamic_cast<TObjString*> (obj);
653 Log(Form("Found source %s", objStr->String().Data()));
654 TList* list2 = GetFileIDs(kDAQ, objStr->String());
656 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
657 delete fRawTagChain; fRawTagChain=0;
660 Log(Form("Number of ids: %d",list2->GetEntries()));
661 for(Int_t i = 0; i < list2->GetEntries(); i++) {
662 TObjString *idStr = (TObjString *)list2->At(i);
663 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
664 if (fileName.Length() > 0) {
665 Log(Form("Adding file in the chain: %s",fileName.Data()));
666 fRawTagChain->Add(fileName.Data());
669 Log(Form("Could not retrieve file with id %s from source %s: "
670 "connection problems with DAQ FXS!",
671 idStr->String().Data(), objStr->String().Data()));
673 delete list2; list2=0;
674 delete fRawTagChain; fRawTagChain=0;
682 TString fRawDataFileName = "GRP_Merged.tag.root";
683 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
685 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
686 Log("Error merging raw data files!!!");
690 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
691 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
694 Log("Problem storing raw data tags in local file!!!");
696 Log("Raw data tags merged successfully!!");
701 delete fRawTagChain; fRawTagChain=0;
703 if (result == kFALSE) {
711 //_______________________________________________________________
712 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
715 // processing the info
716 // stored in the DCS FXS
717 // coming from the trigger
719 // Get the CTP counters information
721 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
722 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
723 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
725 Log(Form("No dummy CTP scalers entry found, going into error..."));
729 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
731 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
735 AliCDBMetaData metaData;
736 metaData.SetResponsible("Roman Lietava");
737 metaData.SetComment("CTP scalers from dummy entry in OCDB");
738 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
739 Log("Unable to store the dummy CTP scalers object to OCDB!");
746 else if (!partition.IsNull() && detector.IsNull()){ // global partition
747 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
748 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
749 if (countersfile.IsNull()) {
750 Log("No CTP counters files has been found: empty source!");
754 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
755 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
757 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
761 AliCDBMetaData metaData;
762 metaData.SetBeamPeriod(0);
763 metaData.SetResponsible("Roman Lietava");
764 metaData.SetComment("CTP scalers");
765 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
766 Log("Unable to store the CTP scalers object to OCDB!");
775 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
782 //_______________________________________________________________
784 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
788 // processing DCS DPs
791 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
792 Int_t nLHCEntries = 0;
793 Int_t nL3Entries = 0;
794 Int_t nDipoleEntries = 0;
795 Int_t nEnvEntries = 0;
796 Int_t nHallProbesEntries = 0;
797 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
798 nL3Entries = ProcessL3DPs(valueMap, grpObj);
799 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
800 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
801 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
802 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
803 Log(Form("nLHCEntries = %d, L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nLHCEntries, nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
804 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
809 //_______________________________________________________________
811 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
818 Int_t nL3Entries = 0;
820 TObjArray *array = 0x0;
822 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
824 AliInfo(Form("==========L3Current==========="));
825 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
826 indexDP = kL3Current;
827 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
829 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
832 if (array->GetEntries() == 0){
833 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
836 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
837 if (floatDCS != NULL){
838 grpObj->SetL3Current(floatDCS);
850 ffailedDPs->RemoveAt(indexDP);
854 if (array) array = 0x0;
856 AliInfo(Form("==========L3Polarity==========="));
857 indexDP = kL3Polarity;
858 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
860 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
863 if (array->GetEntries() == 0){
864 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
867 Bool_t change = kFALSE;
868 Char_t charDCS = ProcessBool(array,change);
869 if (change == kFALSE){
870 grpObj->SetL3Polarity(charDCS);
871 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
872 ffailedDPs->RemoveAt(indexDP);
876 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
877 ffailedDPs->RemoveAt(indexDP);
881 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]));
889 //_______________________________________________________________
891 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
897 Int_t nDipoleEntries = 0;
898 TObjArray *array = 0x0;
900 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
902 AliInfo(Form("==========DipoleCurrent==========="));
903 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
904 indexDP = kDipoleCurrent;
905 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
907 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
910 if (array->GetEntries() == 0){
911 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
914 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
915 if (floatDCS != NULL){
916 grpObj->SetDipoleCurrent(floatDCS);
928 ffailedDPs->RemoveAt(indexDP);
932 if (array) array = 0x0;
934 AliInfo(Form("==========DipolePolarity==========="));
935 indexDP = kDipolePolarity;
936 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
938 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
941 if (array->GetEntries() == 0){
942 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
945 Bool_t change = kFALSE;
946 Char_t charDCS = ProcessBool(array,change);
948 grpObj->SetDipolePolarity(charDCS);
949 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
950 ffailedDPs->RemoveAt(indexDP);
954 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
955 ffailedDPs->RemoveAt(indexDP);
959 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]));
964 return nDipoleEntries;
967 //_______________________________________________________________
969 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
973 // evironment conditions (temperature, pressure) info
975 Int_t nEnvEntries = 0;
976 TObjArray *array = 0x0;
979 AliInfo(Form("==========CavernTemperature==========="));
980 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
981 indexDP = kCavernTemperature;
982 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
984 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
987 if (array->GetEntries() == 0){
988 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
991 Float_t *floatDCS = ProcessFloatAll(array);
992 if (floatDCS != NULL){
993 grpObj->SetCavernTemperature(floatDCS);
1004 ffailedDPs->RemoveAt(indexDP);
1009 if (array) array = 0x0;
1011 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1012 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1013 //dcsSensorArray->Print();
1014 if( fPressure->NumFits()<kNumSensors ) {
1015 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1017 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1019 AliInfo(Form("==========CavernAtmosPressure==========="));
1020 indexDP = kCavernAtmosPressure;
1021 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1022 TGraph* graph = sensorCavernP2->GetGraph();
1023 AliDebug(3,Form("index = %d",indexDP));
1024 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1025 AliDebug(2,Form("graph = %p",graph));
1026 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1027 if(sensorCavernP2->GetFit() || graph) {
1028 if (sensorCavernP2->GetFit()){
1029 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1032 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1034 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1035 ffailedDPs->RemoveAt(indexDP);
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] ));
1043 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1044 indexDP = kSurfaceAtmosPressure;
1045 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1046 graph = sensorP2->GetGraph();
1047 AliDebug(3,Form("index = %d",indexDP));
1048 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1049 AliDebug(2,Form("graph = %p",graph));
1050 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1051 if(sensorP2->GetFit() || graph) {
1052 if (sensorP2->GetFit()){
1053 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1056 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1058 grpObj->SetSurfaceAtmosPressure(sensorP2);
1059 ffailedDPs->RemoveAt(indexDP);
1062 //if (sensorP2) delete sensorP2;
1064 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] ));
1067 AliInfo(Form("==========CavernAtmosPressure2==========="));
1068 indexDP = kCavernAtmosPressure2;
1069 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1070 graph = sensorCavernP22->GetGraph();
1071 AliDebug(3,Form("index = %d",indexDP));
1072 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1073 AliDebug(2,Form("graph = %p",graph));
1074 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1075 if(sensorCavernP22->GetFit() || graph) {
1076 if (sensorCavernP22->GetFit()){
1077 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1080 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1082 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1083 ffailedDPs->RemoveAt(indexDP);
1086 //if (sensorP2) delete sensorP2;
1088 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] ));
1094 //_______________________________________________________________
1096 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1102 Int_t nHPEntries = 0;
1103 TObjArray *array = 0x0;
1105 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1107 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1108 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()));
1110 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1111 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1112 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1113 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1115 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1118 if (array->GetEntries() == 0){
1119 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1122 Float_t *floatDCS = ProcessFloatAll(array);
1123 if (floatDCS != NULL){
1124 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]));
1125 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1126 for (Int_t kk = 0 ; kk< 5; kk++){
1127 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1139 ffailedDPs->RemoveAt(indexDP + 7); // 7 = shift in the complete list of DPs to get to the Hall Probes
1145 Log(Form("Hall Probes = %d ", nHPEntries));
1149 //_______________________________________________________________
1151 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
1155 // processing of LHC related DCS DPs, i.e.:
1161 Int_t nLHCEntries = 0;
1162 TObjArray *array = 0x0;
1165 AliInfo(Form("==========LHCState==========="));
1166 indexDP = kLHCState;
1167 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1169 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1172 if (array->GetEntries() == 0){
1173 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1176 TString stringDCS = ProcessChar(array);
1177 if (stringDCS.Length()!=0) {
1178 Bool_t found = kFALSE;
1179 for( Int_t i=0; i<20; i+=2 ) {
1180 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
1181 stringDCS = fgkLHCState[i+1];
1187 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
1188 grpObj->SetLHCState(stringDCS);
1191 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
1192 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1196 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
1197 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1200 ffailedDPs->RemoveAt(indexDP);
1204 if (array) array = 0x0;
1206 AliInfo(Form("==========LHCLuminosity==========="));
1207 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1208 indexDP = kLHCLuminosity;
1209 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1211 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1214 if (array->GetEntries() == 0){
1215 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1218 Float_t *floatDCS = ProcessFloatAll(array);
1219 if (floatDCS != NULL){
1220 grpObj->SetLHCLuminosity(floatDCS);
1221 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1222 grpObj->SetLHCLuminositySplineFit(splfit);
1234 ffailedDPs->RemoveAt(indexDP);
1239 if (array) array = 0x0;
1241 AliInfo(Form("==========BeamIntensity==========="));
1242 if (outOfRange) outOfRange = kFALSE; // resetting outOfRange if needed
1243 indexDP = kBeamIntensity;
1244 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1246 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1249 if (array->GetEntries() == 0){
1250 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1253 Float_t *floatDCS = ProcessFloatAll(array);
1254 if (floatDCS != NULL){
1255 grpObj->SetBeamIntensity(floatDCS);
1256 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1257 grpObj->SetBeamIntensitySplineFit(splfit1);
1270 ffailedDPs->RemoveAt(indexDP);
1276 //_________________________________________________________________________
1278 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1282 // returning Spline Fit
1285 Int_t entriesarray = array->GetEntries();
1286 Float_t* value = new Float_t[entriesarray];
1287 Float_t* time = new Float_t[entriesarray];
1288 AliDCSValue* v = 0x0;
1289 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1290 v = (AliDCSValue*)array->At(iarray);
1291 value[iarray] = v->GetFloat();
1292 time[iarray] = v->GetTimeStamp();
1293 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1295 TGraph* gr = new TGraph(entriesarray,value,time);
1297 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1300 AliSplineFit *fit = new AliSplineFit();
1301 fit->SetMinPoints(10);
1302 fit->InitKnots(gr,10,10,0.0);
1306 AliWarning(Form("%s: no fit performed",stringID.Data()));
1312 //_________________________________________________________________________
1314 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1321 TString aDCSString="";
1323 AliDCSValue *v = 0x0;
1324 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1325 v = (AliDCSValue *)array->At(iCount);
1326 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1327 AliError(Form("DCS values for the parameter outside the queried interval"));
1331 if (aDCSString != v->GetChar())
1332 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1334 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1339 //__________________________________________________________________________________________________________________
1341 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1344 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1346 // parameters[0] = mean
1347 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1348 // parameters[2] = median
1349 // parameters[3] = standard deviation wrt mean
1350 // parameters[4] = standard deviation wrt median
1353 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1354 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1355 if (timeStartString.IsNull() || timeStartString.IsNull()){
1356 if (timeStartString.IsNull()){
1357 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1359 else if (timeStartString.IsNull()){
1360 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1362 fdaqStartEndTimeOk = kFALSE;
1366 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1367 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1368 Float_t* parameters = new Float_t[5];
1370 Int_t iCountsRun = 0;
1371 Int_t nCounts = array->GetEntries();
1372 Float_t valueBeforeSOR = 0;
1373 Float_t valueAfterEOR = 0;
1374 Int_t timestampBeforeSOR = -1;
1375 Int_t timestampAfterEOR = -1;
1376 Int_t ientrySOR = -1;
1377 Int_t ientryEOR = -1;
1378 Float_t* arrayValues = 0x0;
1379 Double_t* arrayWeights = 0x0;
1380 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1381 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1383 for(Int_t i = 0; i < nCounts; i++) {
1384 AliDCSValue *v = (AliDCSValue *)array->At(i);
1385 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1386 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1387 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1388 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1391 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1392 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1394 // look for the last value before SOR and the first value before EOR
1395 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1396 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1397 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1398 valueBeforeSOR = v->GetFloat();
1400 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1401 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1402 valueAfterEOR = v->GetFloat();
1403 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1405 // check if there are DPs between DAQ_time_start and DAQ_time_end
1406 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1407 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1408 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1409 AliDebug(2,Form("entry between SOR and EOR"));
1414 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1418 if (timestampBeforeSOR == -1){
1419 AliWarning("No value found before SOR");
1421 if (timestampAfterEOR == -1){
1422 AliWarning("No value found after EOR");
1425 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1426 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1427 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1428 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1429 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1430 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1432 Int_t nentriesUsed = 0;
1433 if (iCountsRun > 1){
1434 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1435 AliDebug(2,"Calculating (weighted) Mean and Median");
1436 arrayValues = new Float_t[iCountsRun];
1437 arrayWeights = new Double_t[iCountsRun];
1438 nentriesUsed = iCountsRun;
1439 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1440 AliDCSValue *v = (AliDCSValue *)array->At(i);
1441 Int_t timestamp2 = 0;
1443 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1444 timestamp2 = (Int_t)v1->GetTimeStamp();
1447 timestamp2 = timeEnd+1;
1449 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1450 arrayValues[i-ientrySOR] = v->GetFloat();
1452 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1453 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1455 else if (iCountsRun == 1){
1456 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1458 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1459 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.");
1460 arrayValues = new Float_t[2];
1461 arrayWeights = new Double_t[2];
1462 arrayValues[0] = valueBeforeSOR;
1463 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1464 arrayValues[1] = v->GetFloat();
1465 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1466 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1467 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1468 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1469 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1470 truncMeanFlag = kFALSE;
1473 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");
1474 parameters[0] = AliGRPObject::GetInvalidFloat();
1475 parameters[1] = AliGRPObject::GetInvalidFloat();
1476 parameters[2] = AliGRPObject::GetInvalidFloat();
1477 parameters[3] = AliGRPObject::GetInvalidFloat();
1478 parameters[4] = AliGRPObject::GetInvalidFloat();
1482 else { // iCountsRun == 0, using only the point immediately before SOR
1483 if (timestampBeforeSOR == -1){
1484 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");
1485 parameters[0] = AliGRPObject::GetInvalidFloat();
1486 parameters[1] = AliGRPObject::GetInvalidFloat();
1487 parameters[2] = AliGRPObject::GetInvalidFloat();
1488 parameters[3] = AliGRPObject::GetInvalidFloat();
1489 parameters[4] = AliGRPObject::GetInvalidFloat();
1493 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1494 AliDebug(2,Form("value = %f",valueBeforeSOR));
1495 parameters[0] = valueBeforeSOR;
1496 parameters[2] = valueBeforeSOR;
1497 truncMeanFlag = kFALSE;
1504 Float_t sumweights = 0;
1505 Int_t entriesTruncMean = 0;
1506 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1507 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1509 // calculating SD wrt Mean and Median
1510 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1512 for (Int_t i =0; i< nentriesUsed; i++){
1513 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1514 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1515 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1516 sumweights += arrayWeights[i];
1518 // setting SD wrt Mean
1519 if (sumweights != 0 ){
1520 parameters[3] = TMath::Sqrt(temp1/sumweights);
1523 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1524 parameters[3] = AliGRPObject::GetInvalidFloat();
1526 // setting SD wrt Median
1527 if (nentriesUsed != 0){
1528 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1531 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1532 parameters[4] = AliGRPObject::GetInvalidFloat();
1536 parameters[3] = AliGRPObject::GetInvalidFloat();
1537 parameters[4] = AliGRPObject::GetInvalidFloat();
1540 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1542 AliDebug(2,"Calculating Truncated Mean");
1543 for (Int_t i =0; i< nentriesUsed; i++){
1544 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1545 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1546 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1547 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1548 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1552 AliDebug(2,"Discarding entry");
1555 // setting truncated mean
1556 if (entriesTruncMean >1){
1557 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1558 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1561 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1562 parameters[1] = AliGRPObject::GetInvalidFloat();
1566 parameters[1] = AliGRPObject::GetInvalidFloat();
1569 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1570 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1571 AliInfo(Form("median = %f ",parameters[2]));
1572 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1573 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1578 //__________________________________________________________________________________________________________________
1580 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1583 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1584 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1585 // the flag is set according to the L3/Dipole current value
1586 // current threshold for L3 = 350 A (value provided by DCS)
1587 // current threshold for Dipole = 450 A (value provided by DCS)
1589 // parameters[0] = mean
1590 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1591 // parameters[2] = median
1592 // parameters[3] = standard deviation wrt mean
1593 // parameters[4] = standard deviation wrt median
1596 AliInfo(Form("indexDP = %d",indexDP));
1598 Int_t nCounts = array->GetEntries();
1599 for(Int_t i = 0; i < nCounts; i++) {
1600 AliDCSValue *v = (AliDCSValue *)array->At(i);
1601 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1602 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1603 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1604 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1607 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1608 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1609 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1610 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1613 AliError(Form("DCS values for the parameter outside the queried interval"));
1617 return ProcessFloatAll(array);
1621 //_______________________________________________________________
1623 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1626 // processing Boolean values
1629 Bool_t aDCSBool = kTRUE;
1631 AliDCSValue *v = 0x0;
1633 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1634 v = (AliDCSValue *)array->At(iCount);
1635 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1636 AliError(Form("DCS values for the parameter outside the queried interval"));
1640 if (aDCSBool != v->GetBool()) {
1641 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1645 aDCSBool = v->GetBool(); // always keeping last value
1646 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1649 Char_t caDCSBool = (Char_t) aDCSBool;
1654 //_______________________________________________________________
1656 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1659 // processing Int values, returning mean
1660 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1661 // are outside the queried time interval or their value is out of range
1664 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1665 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1666 if (timeStartString.IsNull() || timeStartString.IsNull()){
1667 if (timeStartString.IsNull()){
1668 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1670 else if (timeStartString.IsNull()){
1671 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1676 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1677 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1678 Float_t aDCSArrayMean = 0.0;
1680 Float_t valueBeforeSOR = 0;
1681 Float_t valueAfterEOR = 0;
1682 Int_t timestampBeforeSOR = -1;
1683 Int_t timestampAfterEOR = -1;
1684 Int_t ientrySOR = -1;
1685 Int_t ientryEOR = -1;
1686 Float_t* arrayValues = 0x0;
1687 Double_t* arrayWeights = 0x0;
1688 Int_t iCountsRun = 0;
1689 Int_t nCounts = array->GetEntries();
1691 for(Int_t i = 0; i < nCounts; i++) {
1692 AliDCSValue* v = (AliDCSValue *)array->At(i);
1693 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1694 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1695 return AliGRPObject::GetInvalidFloat();
1697 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1698 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1700 // look for the last value before SOR and the first value before EOR
1701 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1702 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1703 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1704 valueBeforeSOR = (Float_t) v->GetInt();
1706 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1707 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1708 valueAfterEOR = (Float_t) v->GetInt();
1709 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1711 // check if there are DPs between DAQ_time_start and DAQ_time_end
1712 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1713 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1714 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1715 AliDebug(2,Form("entry between SOR and EOR"));
1720 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1724 if (timestampBeforeSOR == -1){
1725 AliWarning("No value found before SOR!");
1727 if (timestampAfterEOR == -1){
1728 AliWarning("No value found after EOR!");
1731 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1732 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1733 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1734 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1735 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1736 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1738 Int_t nentriesUsed = 0;
1739 if (iCountsRun > 1){
1740 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1741 AliDebug(2,"Calculating (weighted) Mean");
1742 arrayValues = new Float_t[iCountsRun];
1743 arrayWeights = new Double_t[iCountsRun];
1744 nentriesUsed = iCountsRun;
1745 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1746 AliDCSValue *v = (AliDCSValue *)array->At(i);
1747 Int_t timestamp2 = 0;
1749 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1750 timestamp2 = (Int_t)v1->GetTimeStamp();
1753 timestamp2 = timeEnd+1;
1755 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1756 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1758 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1760 else if (iCountsRun == 1){
1761 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1763 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1764 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1765 arrayValues = new Float_t[2];
1766 arrayWeights = new Double_t[2];
1767 arrayValues[0] = valueBeforeSOR;
1768 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1769 arrayValues[1] = (Float_t)v->GetInt();
1770 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1771 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1772 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1773 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1776 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1777 return AliGRPObject::GetInvalidFloat();
1780 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1781 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1782 if (timestampBeforeSOR == -1){
1783 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1785 if (timestampAfterEOR == -1){
1786 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1788 return AliGRPObject::GetInvalidFloat();
1791 AliWarning("Using last entry before SOR and first entry after EOR.");
1793 arrayValues = new Float_t[2];
1794 arrayWeights = new Double_t[2];
1795 arrayValues[0] = valueBeforeSOR;
1796 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1797 arrayValues[1] = valueAfterEOR;
1798 arrayWeights[1] = 1.;
1799 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1800 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1801 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1805 AliInfo(Form("mean = %f ", aDCSArrayMean));
1806 return aDCSArrayMean;
1809 //_______________________________________________________________
1811 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1814 // processing Int values, returning mean
1815 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1816 // are outside the queried time interval or their value is out of range
1819 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1820 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1821 if (timeStartString.IsNull() || timeStartString.IsNull()){
1822 if (timeStartString.IsNull()){
1823 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1825 else if (timeStartString.IsNull()){
1826 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1831 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1832 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1833 Float_t aDCSArrayMean = 0.0;
1835 Float_t valueBeforeSOR = 0;
1836 Float_t valueAfterEOR = 0;
1837 Int_t timestampBeforeSOR = -1;
1838 Int_t timestampAfterEOR = -1;
1839 Int_t ientrySOR = -1;
1840 Int_t ientryEOR = -1;
1841 Float_t* arrayValues = 0x0;
1842 Double_t* arrayWeights = 0x0;
1843 Int_t iCountsRun = 0;
1844 Int_t nCounts = array->GetEntries();
1846 for(Int_t i = 0; i < nCounts; i++) {
1847 AliDCSValue* v = (AliDCSValue *)array->At(i);
1848 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
1849 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
1850 return AliGRPObject::GetInvalidFloat();
1852 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1853 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
1855 // look for the last value before SOR and the first value before EOR
1856 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1857 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1858 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1859 valueBeforeSOR = (Float_t)v->GetUInt();
1861 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1862 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1863 valueAfterEOR = (Float_t)v->GetUInt();
1864 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1866 // check if there are DPs between DAQ_time_start and DAQ_time_end
1867 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1868 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1869 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1870 AliDebug(2,Form("entry between SOR and EOR"));
1875 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1879 if (timestampBeforeSOR == -1){
1880 AliWarning("No value found before SOR!");
1882 if (timestampAfterEOR == -1){
1883 AliWarning("No value found after EOR!");
1886 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1887 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1888 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1889 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1890 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1891 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1893 Int_t nentriesUsed = 0;
1894 if (iCountsRun > 1){
1895 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1896 AliDebug(2,"Calculating (weighted) Mean");
1897 arrayValues = new Float_t[iCountsRun];
1898 arrayWeights = new Double_t[iCountsRun];
1899 nentriesUsed = iCountsRun;
1900 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1901 AliDCSValue *v = (AliDCSValue *)array->At(i);
1902 Int_t timestamp2 = 0;
1904 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1905 timestamp2 = (Int_t)v1->GetTimeStamp();
1908 timestamp2 = timeEnd+1;
1910 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1911 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
1913 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1915 else if (iCountsRun == 1){
1916 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1918 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1919 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1920 arrayValues = new Float_t[2];
1921 arrayWeights = new Double_t[2];
1922 arrayValues[0] = valueBeforeSOR;
1923 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1924 arrayValues[1] = (Float_t)v->GetUInt();
1925 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1926 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1927 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1928 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1931 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1932 return AliGRPObject::GetInvalidFloat();
1935 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1936 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1937 if (timestampBeforeSOR == -1){
1938 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1940 if (timestampAfterEOR == -1){
1941 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1943 return AliGRPObject::GetInvalidFloat();
1946 AliWarning("Using last entry before SOR and first entry after EOR.");
1948 arrayValues = new Float_t[2];
1949 arrayWeights = new Double_t[2];
1950 arrayValues[0] = valueBeforeSOR;
1951 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1952 arrayValues[1] = valueAfterEOR;
1953 arrayWeights[1] = 1.;
1954 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1955 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1956 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1960 AliInfo(Form("mean = %f ",aDCSArrayMean));
1961 return aDCSArrayMean;
1966 //_______________________________________________________________
1968 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1970 // extract DCS pressure maps. Perform fits to save space
1972 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1974 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
1975 fPressure->MakeSplineFit(map);
1976 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1977 if (fitFraction > kFitFraction ) {
1978 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
1980 AliInfo("Too few pressure maps fitted!!!");
1983 AliInfo("no atmospheric pressure map extracted!!!");
1992 //_______________________________________________________________
1993 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)
1996 // Retrieves logbook and trigger information from the online logbook
1997 // This information is needed for prompt reconstruction
2001 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2005 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2006 // 0 on success and no run was found
2007 // negative on error
2009 // This function is NOT called during the preprocessor run in the Shuttle!
2017 AliCDBManager* cdb = AliCDBManager::Instance();
2018 cdb->SetDefaultStorage(cdbRoot);
2021 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2025 Printf("ERROR: Could not connect to DAQ LB");
2031 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2032 TSQLResult* result = server->Query(sqlQuery);
2035 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2039 if (result->GetRowCount() == 0)
2041 Printf("ERROR: Run %d not found", run);
2046 TSQLRow* row = result->Next();
2049 Printf("ERROR: Could not receive data from run %d", run);
2054 TString timeStartString(row->GetField(0));
2055 TString runType(row->GetField(1));
2056 TString detectorMaskString(row->GetField(2));
2057 TString l3CurrentString(row->GetField(3));
2058 TString dipoleCurrentString(row->GetField(4));
2059 time_t timeStart = (time_t)(timeStartString.Atoi());
2060 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2061 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2062 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2063 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2064 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2066 AliGRPObject * grpObj = new AliGRPObject();
2067 grpObj->SetTimeStart(timeStart);
2068 grpObj->SetRunType((TString)(row->GetField(1)));
2069 grpObj->SetDetectorMask(detectorMask);
2070 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2071 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2072 grpObj->SetL3Polarity(l3Polarity);
2073 grpObj->SetDipolePolarity(dipolePolarity);
2081 Printf("Storing GRP/GRP/Data object with the following content");
2084 AliCDBMetaData metadata;
2085 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2086 metadata.SetComment("GRP Output parameters received during online running");
2088 AliCDBId id("GRP/GRP/Data", run, run);
2089 Bool_t success = cdb->Put(grpObj, id, &metadata);
2095 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2099 // Receive trigger information
2100 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2101 result = server->Query(sqlQuery);
2104 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2108 if (result->GetRowCount() == 0)
2110 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2115 row = result->Next();
2118 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2123 TString triggerConfig(row->GetField(0));
2131 Printf("Found trigger configuration: %s", triggerConfig.Data());
2133 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2136 Printf("ERROR: Could not create CTP configuration object");
2140 metadata.SetComment("CTP run configuration received during online running");
2142 AliCDBId id2("GRP/CTP/Config", run, run);
2143 success = cdb->Put(runcfg, id2, &metadata);
2150 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2155 // Receive list of GDCs for this run
2156 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2157 result = server->Query(sqlQuery);
2160 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2164 if (result->GetRowCount() == 0)
2166 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2172 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2173 row = result->Next();
2176 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2180 gdc += row->GetField(0);
2190 Printf("Found GDC: %s", gdc.Data());
2192 // get last run with same run type that was already processed by the SHUTTLE
2194 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());
2195 result = server->Query(sqlQuery);
2198 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2202 if (result->GetRowCount() == 0)
2204 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2209 row = result->Next();
2212 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2217 TString lastRunStr(row->GetField(0));
2218 Int_t lastRun = lastRunStr.Atoi();
2220 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);