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>
32 #include "AliGRPPreprocessor.h"
33 #include "AliGRPObject.h"
34 #include "AliDCSSensor.h"
35 #include "AliSplineFit.h"
36 #include "AliDCSSensorArray.h"
38 #include "AliTriggerConfiguration.h"
39 #include "AliTriggerRunScalers.h"
41 #include "AliCDBMetaData.h"
45 class AliShuttleInterface;
47 // needed for ReceivePromptRecoParameters
49 #include <TSQLServer.h>
50 #include <TSQLResult.h>
52 #include <AliCDBManager.h>
53 #include <AliCDBMetaData.h>
55 #include <AliTriggerConfiguration.h>
57 const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
59 ClassImp(AliGRPPreprocessor)
61 //_______________________________________________________________
63 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook for PHYSICS runs, when beamType from DAQ logbook != Cosmics
64 const Int_t AliGRPPreprocessor::fgknDAQLbParReduced = 7; // num parameters in the logbook for the other cases
65 const Int_t AliGRPPreprocessor::fgknDCSDP = 50; // number of dcs dps
66 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
67 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
68 "LHCState", // missing in DCS
71 "LHCLuminosity", // missing in DCS
72 "BeamIntensity", // missing in DCS
78 "L3_BSF17_Temperature",
82 "L3_BSF4_Temperature",
86 "L3_BKF17_Temperature",
90 "L3_BKF4_Temperature",
94 "L3_BSF13_Temperature",
98 "L3_BSF8_Temperature",
102 "L3_BKF13_Temperature",
106 "L3_BKF8_Temperature",
110 "Dipole_Inside_Temperature",
114 "Dipole_Outside_Temperature",
116 "CavernAtmosPressure",
117 "SurfaceAtmosPressure"
120 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
124 "L3_BSF17_Temperature",
128 "L3_BSF4_Temperature",
132 "L3_BKF17_Temperature",
136 "L3_BKF4_Temperature",
140 "L3_BSF13_Temperature",
144 "L3_BSF8_Temperature",
148 "L3_BKF13_Temperature",
152 "L3_BKF8_Temperature",
156 "Dipole_Inside_Temperature",
160 "Dipole_Outside_Temperature",
163 const Short_t kSensors = 48; // start index position of sensor in DCS DPs
164 const Short_t kNumSensors = 2; // Number of sensors in DCS DPs
166 const char* AliGRPPreprocessor::fgkLHCState[20] = {
172 "U", "UNSTABLE BEAMS",
179 const char* kppError[] = {
181 "(DAQ logbook ERROR)",
184 "(DCS data points ERROR)",
185 "(Trigger Configuration ERROR)",
186 "(DAQ logbook ERROR determining partition of the run)"
189 //_______________________________________________________________
191 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
192 AliPreprocessor("GRP",shuttle), fPressure(0)
194 // constructor - shuttle must be instantiated!
196 AddRunType("COSMIC");
198 AddRunType("PHYSICS");
199 AddRunType("CALIBRATION_BC");
200 AddRunType("CALIBRATION_CENTRAL");
201 AddRunType("CALIBRATION_EMD");
202 AddRunType("CALIBRATION_MB");
203 AddRunType("CALIBRATION_SEMICENTRAL");
204 AddRunType("CALIBRATION");
205 AddRunType("PEDESTAL");
206 AddRunType("STANDALONE");
209 AddRunType("PULSER");
210 AddRunType("STANDALONE_PULSER");
213 //_______________________________________________________________
215 AliGRPPreprocessor::~AliGRPPreprocessor()
222 //_______________________________________________________________
224 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
226 // Initialize preprocessor
228 AliPreprocessor::Initialize(run, startTime, endTime);
230 AliInfo("Initialization of the GRP preprocessor.");
231 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
232 for(Int_t j = 0; j < kNumSensors; j++) {
233 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
234 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
236 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
238 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
241 //_______________________________________________________________
243 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
245 // process data retrieved by the Shuttle
247 // retrieving "partition" and "detector" fields from DAQ logbook to
248 // determine the partition in which the run was taken
249 // the partition is used to decide how to react in case of errors for CTP
251 TString partition = (TString)GetRunParameter("partition");
252 TString detector = (TString)GetRunParameter("detector");
254 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
256 //=================//
258 //=================//
261 Int_t iDaqLB = ProcessDaqLB(grpobj);
262 TString runType = (TString)GetRunType();
263 TString beamType = (TString)GetRunParameter("beamType");
264 if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
265 Log(Form("DAQ Logbook, successful!"));
267 Log(Form("DAQ Logbook, could not get all expected entries!!!"));
271 //=================//
273 //=================//
274 UInt_t iDaqFxs = ProcessDaqFxs();
276 Log(Form("DAQ FXS, successful!"));
278 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
282 //=================//
284 //=================//
285 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
287 Log(Form("DCS FXS, successful!"));
288 } else if (iDcsFxs ==1) {
289 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
292 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
296 //=================//
297 // DCS data points //
298 //=================//
299 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
300 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
301 Log(Form("entries found = %d",entries));
302 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, LH3_BSF4_H3 are not working yet...
303 Log(Form("Problem with the DCS data points!!!"));
305 } else Log(Form("DCS data points, successful!"));
307 //=======================//
308 // Trigger Configuration //
309 //=======================//
311 const char * triggerConf = GetTriggerConfiguration();
313 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
314 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
315 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
317 Log(Form("No dummy CTP configuration entry found, going into error..."));
321 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
323 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
327 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
328 runcfg->SetTitle(titleCTPcfg);
329 AliCDBMetaData metaData;
330 metaData.SetResponsible("Roman Lietava");
331 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
332 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
333 Log("Unable to store the dummy CTP run configuration object to OCDB!");
340 else if (!partition.IsNull() && detector.IsNull()){ // global partition
341 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
342 if (triggerConf!= NULL) {
343 Log("Found trigger configuration in DAQ logbook");
344 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
346 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
350 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
351 runcfg->SetTitle(titleCTPcfg);
352 AliCDBMetaData metaData;
353 metaData.SetBeamPeriod(0);
354 metaData.SetResponsible("Roman Lietava");
355 metaData.SetComment("CTP run configuration from DAQ logbook");
356 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
357 Log("Unable to store the CTP run configuration object to OCDB!");
364 Log("Trigger configuration NULL in DAQ logbook");
370 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
374 // storing AliGRPObject in OCDB
377 md.SetResponsible("Ernesto Lopez Torres");
378 md.SetComment("Output parameters from the GRP preprocessor.");
380 Bool_t result = kTRUE;
381 result = Store("GRP", "Data", grpobj, &md);
384 if (result && !error ) {
385 Log("GRP Preprocessor Success");
388 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s",
389 kppError[(error&1)?1:0],
390 kppError[(error&2)?2:0],
391 kppError[(error&4)?3:0],
392 kppError[(error&8)?4:0],
393 kppError[(error&16)?5:0],
394 kppError[(error&32)?6:0]
400 //_______________________________________________________________
402 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
404 //Getting the DAQ lb information
406 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
407 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
408 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
409 TString beamType = (TString)GetRunParameter("beamType");
410 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
411 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
412 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
413 TString runType = (TString)GetRunType();
415 UInt_t nparameter = 0;
417 grpObj->SetTimeStart(timeStart);
418 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
422 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
426 grpObj->SetTimeEnd(timeEnd);
427 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
431 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
434 if (beamEnergy != 0){
435 grpObj->SetBeamEnergy(beamEnergy);
436 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
437 if ((runType == "PHYSICS" && beamType!="Cosmics")){
438 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != Cosmics
442 if ((runType == "PHYSICS" && beamType!="Cosmics")){
443 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()));
446 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, but not producing any error (beamType = %s, runType = %s)",beamType.Data(), runType.Data()));
451 if (beamType.Length() != 0){
452 grpObj->SetBeamType(beamType);
453 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
457 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
460 if (numberOfDetectors != 0){
461 grpObj->SetNumberOfDetectors(numberOfDetectors);
462 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
466 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
469 if (detectorMask != 0){
470 grpObj->SetDetectorMask(detectorMask);
471 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
475 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
478 if (lhcPeriod.Length() != 0) {
479 grpObj->SetLHCPeriod(lhcPeriod);
480 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
484 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
486 if (runType.Length() != 0) {
487 grpObj->SetRunType(runType);
488 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
492 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
498 //_______________________________________________________________
500 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
502 //======DAQ FXS======//
504 TList* list = GetFileSources(kDAQ);
506 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
510 if (list->GetEntries() == 0) {
511 Log("no raw data tags in this run: nothing to merge!");
516 TChain *fRawTagChain = new TChain("T");
518 TIterator* iter = list->MakeIterator();
520 while ((obj = iter->Next())) {
521 TObjString* objStr = dynamic_cast<TObjString*> (obj);
523 Log(Form("Found source %s", objStr->String().Data()));
524 TList* list2 = GetFileIDs(kDAQ, objStr->String());
526 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
527 delete fRawTagChain; fRawTagChain=0;
530 Log(Form("Number of ids: %d",list2->GetEntries()));
531 for(Int_t i = 0; i < list2->GetEntries(); i++) {
532 TObjString *idStr = (TObjString *)list2->At(i);
533 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
534 if (fileName.Length() > 0) {
535 Log(Form("Adding file in the chain: %s",fileName.Data()));
536 fRawTagChain->Add(fileName.Data());
539 Log(Form("Could not retrieve file with id %s from source %s: "
540 "connection problems with DAQ FXS!",
541 idStr->String().Data(), objStr->String().Data()));
543 delete list2; list2=0;
544 delete fRawTagChain; fRawTagChain=0;
552 TString fRawDataFileName = "GRP_Merged.tag.root";
553 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
555 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
556 Log("Error merging raw data files!!!");
560 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
561 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
564 Log("Problem storing raw data tags in local file!!!");
566 Log("Raw data tags merged successfully!!");
571 delete fRawTagChain; fRawTagChain=0;
573 if (result == kFALSE) {
581 //_______________________________________________________________
582 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
585 // processing the info
586 // stored in the DCS FXS
587 // coming from the trigger
589 // Get the CTP counters information
591 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
592 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
593 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
595 Log(Form("No dummy CTP scalers entry found, going into error..."));
599 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
601 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
605 AliCDBMetaData metaData;
606 metaData.SetResponsible("Roman Lietava");
607 metaData.SetComment("CTP scalers from dummy entry in OCDB");
608 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
609 Log("Unable to store the dummy CTP scalers object to OCDB!");
616 else if (!partition.IsNull() && detector.IsNull()){ // global partition
617 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
618 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
619 if (countersfile.IsNull()) {
620 Log("No CTP counters files has been found: empty source!");
624 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
625 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
627 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
631 AliCDBMetaData metaData;
632 metaData.SetBeamPeriod(0);
633 metaData.SetResponsible("Roman Lietava");
634 metaData.SetComment("CTP scalers");
635 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
636 Log("Unable to store the CTP scalers object to OCDB!");
645 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
652 //_______________________________________________________________
654 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
658 // processing DCS DPs
661 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
662 Int_t nLHCEntries = 0;
663 Int_t nL3Entries = 0;
664 Int_t nDipoleEntries = 0;
665 Int_t nEnvEntries = 0;
666 Int_t nHallProbesEntries = 0;
667 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
668 nL3Entries = ProcessL3DPs(valueMap, grpObj);
669 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
670 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
671 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
673 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
678 //_______________________________________________________________
680 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
687 Int_t nL3Entries = 0;
688 TObjArray *array = 0x0;
691 AliInfo(Form("==========L3Polarity==========="));
692 indexDP = kL3Polarity;
693 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
695 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
698 if (array->GetEntries() == 0){
699 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
702 Char_t charDCS = ProcessBool(array);
703 grpObj->SetL3Polarity(charDCS);
704 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
709 if (array) array = 0x0;
711 AliInfo(Form("==========L3Current==========="));
712 indexDP = kL3Current;
713 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
715 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
718 if (array->GetEntries() == 0){
719 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
722 Float_t *floatDCS = ProcessFloatAll(array);
723 grpObj->SetL3Current(floatDCS);
732 //_______________________________________________________________
734 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
740 Int_t nDipoleEntries = 0;
741 TObjArray *array = 0x0;
744 AliInfo(Form("==========DipolePolarity==========="));
745 indexDP = kDipolePolarity;
746 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
748 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
751 if (array->GetEntries() == 0){
752 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
755 Char_t charDCS = ProcessBool(array);
756 grpObj->SetDipolePolarity(charDCS);
757 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
762 if (array) array = 0x0;
764 AliInfo(Form("==========DipoleCurrent==========="));
765 indexDP = kDipoleCurrent;
766 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
768 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
771 if (array->GetEntries() == 0){
772 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
775 Float_t *floatDCS = ProcessFloatAll(array);
776 grpObj->SetDipoleCurrent(floatDCS);
782 return nDipoleEntries;
785 //_______________________________________________________________
787 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
791 // evironment conditions (temperature, pressure) info
793 Int_t nEnvEntries = 0;
794 TObjArray *array = 0x0;
797 AliInfo(Form("==========CavernTemperature==========="));
798 indexDP = kCavernTemperature;
799 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
801 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
804 if (array->GetEntries() == 0){
805 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
808 Float_t *floatDCS = ProcessFloatAll(array);
809 grpObj->SetCavernTemperature(floatDCS);
815 if (array) array = 0x0;
817 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
818 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
819 dcsSensorArray->Print();
820 if( fPressure->NumFits()==0 ) {
821 Log("Problem with the pressure sensor values!!!");
824 AliInfo(Form("==========CavernAtmosPressure==========="));
825 indexDP = kCavernAtmosPressure;
826 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
827 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
828 if( sensorCavernP2->GetFit() ) {
829 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
830 grpObj->SetCavernAtmosPressure(sensorCavernP2);
833 //if (sensorP2) delete sensorP2;
835 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
837 AliInfo(Form("==========SurfaceAtmosPressure==========="));
838 indexDP = kSurfaceAtmosPressure;
839 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
840 AliDebug(2,Form("sensorP2 = %p", sensorP2));
841 if( sensorP2->GetFit() ) {
842 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
843 grpObj->SetSurfaceAtmosPressure(sensorP2);
846 //if (sensorP2) delete sensorP2;
848 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
855 //_______________________________________________________________
857 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
863 Int_t nHPEntries = 0;
864 TObjArray *array = 0x0;
867 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
868 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()));
870 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
871 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
872 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
874 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
877 if (array->GetEntries() == 0){
878 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
881 Float_t *floatDCS = ProcessFloatAll(array);
882 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]));
883 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
884 for (Int_t kk = 0 ; kk< 5; kk++){
885 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
893 Log(Form("Hall Probes = %d ", nHPEntries));
897 //_______________________________________________________________
899 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
903 // processing of LHC related DCS DPs, i.e.:
909 Int_t nLHCEntries = 0;
910 TObjArray *array = 0x0;
913 AliInfo(Form("==========LHCState==========="));
915 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
917 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
920 if (array->GetEntries() == 0){
921 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
924 TString stringDCS = ProcessChar(array);
925 if (stringDCS.Length()!=0) {
926 Bool_t found = kFALSE;
927 for( Int_t i=0; i<20; i+=2 ) {
928 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
929 stringDCS = fgkLHCState[i+1];
935 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
936 grpObj->SetLHCState(stringDCS);
939 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
940 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
944 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
945 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
951 if (array) array = 0x0;
953 AliInfo(Form("==========LHCLuminosity==========="));
954 indexDP = kLHCLuminosity;
955 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
957 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
960 if (array->GetEntries() == 0){
961 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
964 Float_t *floatDCS = ProcessFloatAll(array);
965 grpObj->SetLHCLuminosity(floatDCS);
967 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
968 grpObj->SetLHCLuminositySplineFit(splfit);
974 if (array) array = 0x0;
976 AliInfo(Form("==========BeamIntensity==========="));
977 indexDP = kBeamIntensity;
978 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
980 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
983 if (array->GetEntries() == 0){
984 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
987 Float_t *floatDCS = ProcessFloatAll(array);
988 grpObj->SetBeamIntensity(floatDCS);
990 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
991 grpObj->SetBeamIntensitySplineFit(splfit1);
999 //_________________________________________________________________________
1001 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1005 // returning Spline Fit
1008 Int_t entriesarray = array->GetEntries();
1009 Float_t* value = new Float_t[entriesarray];
1010 Float_t* time = new Float_t[entriesarray];
1011 AliDCSValue* v = 0x0;
1012 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1013 v = (AliDCSValue*)array->At(iarray);
1014 value[iarray] = v->GetFloat();
1015 time[iarray] = v->GetTimeStamp();
1016 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1018 TGraph* gr = new TGraph(entriesarray,value,time);
1020 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1023 AliSplineFit *fit = new AliSplineFit();
1024 fit->SetMinPoints(10);
1025 fit->InitKnots(gr,10,10,0.0);
1029 AliWarning(Form("%s: no fit performed",stringID.Data()));
1035 //_________________________________________________________________________
1037 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1044 TString aDCSString="";
1046 AliDCSValue *v = 0x0;
1047 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1048 v = (AliDCSValue *)array->At(iCount);
1049 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1050 AliError(Form("DCS values for the parameter outside the queried interval"));
1054 if (aDCSString != v->GetChar())
1055 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1057 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1062 //__________________________________________________________________________________________________________________
1064 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1067 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1069 // parameters[0] = mean
1070 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1071 // parameters[2] = median
1072 // parameters[3] = standard deviation wrt mean
1073 // parameters[4] = standard deviation wrt median
1076 Float_t* parameters = new Float_t[5];
1077 Double_t aDCSArrayMean = 0; // Mean
1078 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1079 Double_t aDCSArrayMedian = 0; // Median
1080 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1081 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1082 Float_t aDCSArraySum = 0.0;
1087 Int_t nCounts = array->GetEntries();
1088 Float_t *tempArray = new Float_t[nCounts];
1089 for(Int_t i = 0; i < nCounts; i++) {
1090 AliDCSValue *v = (AliDCSValue *)array->At(i);
1091 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1092 aDCSArraySum += v->GetFloat();
1093 tempArray[i] = v->GetFloat();
1094 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1099 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
1101 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1102 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1103 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1104 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
1105 // computing standard deviation wrt median
1106 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1107 for (Int_t i = 0; i < iCounts; i++){
1108 AliDCSValue *v = (AliDCSValue *)array->At(i);
1109 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1110 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
1111 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
1112 temp1+=v->GetFloat();
1114 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
1116 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1118 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
1120 AliDebug(3,Form("temp after the ratio = %f", temp));
1122 aDCSArraySDMedian = TMath::Sqrt(temp);
1125 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1126 aDCSArraySDMedian = 0;
1129 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
1130 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1134 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1135 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1136 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1138 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
1140 aDCSArrayTruncMean = temp1/iCounts1;
1143 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1148 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1149 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1150 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1151 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1152 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
1154 parameters[0] = aDCSArrayMean;
1155 parameters[1] = aDCSArrayTruncMean;
1156 parameters[2] = aDCSArrayMedian;
1157 parameters[3] = aDCSArraySDMean;
1158 parameters[4] = aDCSArraySDMedian;
1160 AliDebug(2,Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4]));
1161 //AliInfo(Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4]));
1167 //_______________________________________________________________
1169 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
1172 // processing Boolean values
1175 Bool_t aDCSBool = kTRUE;
1177 AliDCSValue *v = 0x0;
1179 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1180 v = (AliDCSValue *)array->At(iCount);
1181 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1182 AliError(Form("DCS values for the parameter outside the queried interval"));
1186 if (aDCSBool != v->GetBool())
1187 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1189 aDCSBool = v->GetBool(); // always keeping last value
1190 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1193 Char_t caDCSBool = (Char_t) aDCSBool;
1198 //_______________________________________________________________
1200 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1203 // processing Int values, returning mean
1206 Float_t aDCSArraySum = 0.0;
1207 Float_t aDCSArrayMean = 0.0;
1209 AliDCSValue* v = 0x0;
1211 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1212 v = (AliDCSValue *)array->At(iCount);
1213 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1214 aDCSArraySum += v->GetInt();
1219 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1220 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1222 return aDCSArrayMean;
1225 //_______________________________________________________________
1227 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1230 // processing Int values, returning mean
1233 Float_t aDCSArraySum = 0.0;
1234 Float_t aDCSArrayMean = 0.0;
1236 AliDCSValue* v = 0x0;
1238 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1239 v = (AliDCSValue *)array->At(iCount);
1240 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1241 aDCSArraySum += v->GetUInt();
1246 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1247 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1249 return aDCSArrayMean;
1254 //_______________________________________________________________
1256 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1258 // extract DCS pressure maps. Perform fits to save space
1260 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1262 fPressure->MakeSplineFit(map);
1263 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1264 if (fitFraction > kFitFraction ) {
1265 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1267 AliInfo("Too few pressure maps fitted!!!");
1270 AliInfo("no atmospheric pressure map extracted!!!");
1279 //_______________________________________________________________
1280 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)
1283 // Retrieves logbook and trigger information from the online logbook
1284 // This information is needed for prompt reconstruction
1288 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1292 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1293 // 0 on success and no run was found
1294 // negative on error
1296 // This function is NOT called during the preprocessor run in the Shuttle!
1304 AliCDBManager* cdb = AliCDBManager::Instance();
1305 cdb->SetDefaultStorage(cdbRoot);
1308 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1312 Printf("ERROR: Could not connect to DAQ LB");
1318 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1319 TSQLResult* result = server->Query(sqlQuery);
1322 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1326 if (result->GetRowCount() == 0)
1328 Printf("ERROR: Run %d not found", run);
1333 TSQLRow* row = result->Next();
1336 Printf("ERROR: Could not receive data from run %d", run);
1341 TString timeStartString(row->GetField(0));
1342 TString runType(row->GetField(1));
1343 TString detectorMaskString(row->GetField(2));
1344 TString l3CurrentString(row->GetField(3));
1345 TString dipoleCurrentString(row->GetField(4));
1346 time_t timeStart = (time_t)(timeStartString.Atoi());
1347 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1348 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1349 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1351 AliGRPObject * grpObj = new AliGRPObject();
1352 grpObj->SetTimeStart(timeStart);
1353 grpObj->SetRunType((TString)(row->GetField(1)));
1354 grpObj->SetDetectorMask(detectorMask);
1355 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1356 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1364 Printf("Storing GRP/GRP/Data object with the following content");
1367 AliCDBMetaData metadata;
1368 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
1369 metadata.SetComment("GRP Output parameters received during online running");
1371 AliCDBId id("GRP/GRP/Data", run, run);
1372 Bool_t success = cdb->Put(grpObj, id, &metadata);
1378 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1382 // Receive trigger information
1383 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1384 result = server->Query(sqlQuery);
1387 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1391 if (result->GetRowCount() == 0)
1393 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1398 row = result->Next();
1401 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1406 TString triggerConfig(row->GetField(0));
1414 Printf("Found trigger configuration: %s", triggerConfig.Data());
1416 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1419 Printf("ERROR: Could not create CTP configuration object");
1423 metadata.SetComment("CTP run configuration received during online running");
1425 AliCDBId id2("GRP/CTP/Config", run, run);
1426 success = cdb->Put(runcfg, id2, &metadata);
1433 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1437 // get last run with same run type that was already processed by the SHUTTLE
1439 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());
1440 result = server->Query(sqlQuery);
1443 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1447 if (result->GetRowCount() == 0)
1449 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1454 row = result->Next();
1457 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1462 TString lastRunStr(row->GetField(0));
1463 Int_t lastRun = lastRunStr.Atoi();
1465 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);