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 //-------------------------------------------------------------------------
28 #include <TObjString.h>
31 #include "AliGRPPreprocessor.h"
32 #include "AliGRPObject.h"
33 #include "AliDCSSensor.h"
34 #include "AliSplineFit.h"
35 #include "AliDCSSensorArray.h"
37 #include "AliTriggerConfiguration.h"
38 #include "AliTriggerRunScalers.h"
40 #include "AliCDBMetaData.h"
44 class AliShuttleInterface;
46 // needed for ReceivePromptRecoParameters
48 #include <TSQLServer.h>
49 #include <TSQLResult.h>
51 #include <AliCDBManager.h>
52 #include <AliCDBMetaData.h>
54 #include <AliTriggerConfiguration.h>
56 const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
58 ClassImp(AliGRPPreprocessor)
60 //_______________________________________________________________
62 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook
63 const Int_t AliGRPPreprocessor::fgknDCSDP = 50; // number of dcs dps
64 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
65 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
66 "LHCState", // missing in DCS
69 "LHCLuminosity", // missing in DCS
70 "BeamIntensity", // missing in DCS
76 "L3_BSF17_Temperature",
80 "L3_BSF4_Temperature",
84 "L3_BKF17_Temperature",
88 "L3_BKF4_Temperature",
92 "L3_BSF13_Temperature",
96 "L3_BSF8_Temperature",
100 "L3_BKF13_Temperature",
104 "L3_BKF8_Temperature",
108 "Dipole_Inside_Temperature",
112 "Dipole_Outside_Temperature",
114 "CavernAtmosPressure",
115 "SurfaceAtmosPressure"
118 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
122 "L3_BSF17_Temperature",
126 "L3_BSF4_Temperature",
130 "L3_BKF17_Temperature",
134 "L3_BKF4_Temperature",
138 "L3_BSF13_Temperature",
142 "L3_BSF8_Temperature",
146 "L3_BKF13_Temperature",
150 "L3_BKF8_Temperature",
154 "Dipole_Inside_Temperature",
158 "Dipole_Outside_Temperature",
161 const Short_t kSensors = 48; // start index position of sensor in DCS DPs
162 const Short_t kNumSensors = 2; // Number of sensors in DCS DPs
164 const char* AliGRPPreprocessor::fgkLHCState[20] = {
170 "U", "UNSTABLE BEAMS",
177 const char* kppError[] = {
179 "(DAQ logbook ERROR)",
182 "(DCS data points ERROR)",
183 "(Trigger Configuration ERROR)"
186 //_______________________________________________________________
188 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
189 AliPreprocessor("GRP",shuttle), fPressure(0)
191 // constructor - shuttle must be instantiated!
193 AddRunType("COSMIC");
195 AddRunType("PHYSICS");
196 AddRunType("CALIBRATION_BC");
197 AddRunType("CALIBRATION_CENTRAL");
198 AddRunType("CALIBRATION_EMD");
199 AddRunType("CALIBRATION_MB");
200 AddRunType("CALIBRATION_SEMICENTRAL");
201 AddRunType("CALIBRATION");
202 AddRunType("PEDESTAL");
205 //_______________________________________________________________
207 AliGRPPreprocessor::~AliGRPPreprocessor()
214 //_______________________________________________________________
216 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
218 // Initialize preprocessor
220 AliPreprocessor::Initialize(run, startTime, endTime);
222 AliInfo("Initialization of the GRP preprocessor.");
223 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
224 for(Int_t j = 0; j < kNumSensors; j++) {
225 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
226 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
228 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
230 // fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
231 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
234 //_______________________________________________________________
236 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
238 // process data retrieved by the Shuttle
240 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
242 //=================//
244 //=================//
247 grpobj = ProcessDaqLB();
249 //=================//
251 //=================//
252 UInt_t iDaqFxs = ProcessDaqFxs();
254 Log(Form("DAQ FXS, successful!"));
256 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
260 //=================//
262 //=================//
263 UInt_t iDcsFxs = ProcessDcsFxs();
265 Log(Form("DCS FXS, successful!"));
267 Log(Form("DCS FXS, Could not store CTP run configuration and scalers!!!"));
271 //=================//
272 // DCS data points //
273 //=================//
274 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
275 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
276 Log(Form("entries found = %d",entries));
277 if( entries < fgknDCSDP-7 ) { // FIXME (!= ) LHState and pressure map are not working yet... and removing the 4 values for the missing HP
278 Log(Form("Problem with the DCS data points!!!"));
280 } else Log(Form("DCS data points, successful!"));
282 //=======================//
283 // Trigger Configuration //
284 //=======================//
285 // either from DAQ logbook.....
286 const char * triggerConf = GetTriggerConfiguration();
287 if (triggerConf!= NULL) {
288 Log("Found trigger configuration in DAQ logbook");
289 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
291 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
295 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
296 runcfg->SetTitle(titleCTPcfg);
297 AliCDBMetaData metaData;
298 metaData.SetBeamPeriod(0);
299 metaData.SetResponsible("Roman Lietava");
300 metaData.SetComment("CTP run configuration from DAQ logbook");
301 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
302 Log("Unable to store the CTP run configuration object to OCDB!");
307 /* the DCS should not been used any more to access this stuff!!!
308 // ...or from DCS FXS
310 Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS...");
311 TString runcfgfile = GetFile(kDCS, "CTP_runconfig", "");
312 if (runcfgfile.IsNull()) {
313 Log("No CTP runconfig files has been found in DCS FXS!");
317 Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data()));
318 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
320 Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!");
324 TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun);
325 runcfg->SetTitle(titleCTPcfg);
326 AliCDBMetaData metaData;
327 metaData.SetBeamPeriod(0);
328 metaData.SetResponsible("Roman Lietava");
329 metaData.SetComment("CTP run configuration from DCS FXS");
330 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
331 Log("Unable to store the CTP run configuration object to OCDB!");
339 md.SetResponsible("Ernesto Lopez Torres");
340 md.SetComment("Output parameters from the GRP preprocessor.");
342 Bool_t result = kTRUE;
343 Log("Before storing");
344 result = Store("GRP", "Data", grpobj, &md);
347 if (result && !error ) {
348 Log("GRP Preprocessor Success");
351 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s",
352 kppError[(error&1)?1:0],
353 kppError[(error&2)?2:0],
354 kppError[(error&4)?3:0],
355 kppError[(error&8)?4:0],
356 kppError[(error&16)?5:0]
362 //_______________________________________________________________
364 AliGRPObject* AliGRPPreprocessor::ProcessDaqLB()
366 //Getting the DAQ lb information
368 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
369 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
370 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
371 TString beamType = (TString)GetRunParameter("beamType");
372 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
373 UInt_t detectorMask= (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
374 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
375 TString runType = (TString)GetRunType();
377 AliGRPObject* grpObj = new AliGRPObject();
380 grpObj->SetTimeStart(timeStart);
381 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
384 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
388 grpObj->SetTimeEnd(timeEnd);
389 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
392 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
395 if (beamEnergy != 0){
396 grpObj->SetBeamEnergy(beamEnergy);
397 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
400 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry!"));
403 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
405 if (beamType.Length() != 0){
406 grpObj->SetBeamType(beamType);
407 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
410 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
413 if (numberOfDetectors != 0){
414 grpObj->SetNumberOfDetectors(numberOfDetectors);
415 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
418 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
421 if (detectorMask != 0){
422 grpObj->SetDetectorMask(detectorMask);
423 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
426 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
429 if (lhcPeriod.Length() != 0) {
430 grpObj->SetLHCPeriod(lhcPeriod);
431 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
433 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
435 if (runType.Length() != 0) {
436 grpObj->SetRunType(runType);
437 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
439 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
445 //_______________________________________________________________
447 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
449 //======DAQ FXS======//
451 TList* list = GetFileSources(kDAQ);
453 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
457 if (list->GetEntries() == 0) {
458 Log("no raw data tags in this run: nothing to merge!");
463 TChain *fRawTagChain = new TChain("T");
465 TIterator* iter = list->MakeIterator();
467 while ((obj = iter->Next())) {
468 TObjString* objStr = dynamic_cast<TObjString*> (obj);
470 Log(Form("Found source %s", objStr->String().Data()));
471 TList* list2 = GetFileIDs(kDAQ, objStr->String());
473 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
474 delete fRawTagChain; fRawTagChain=0;
477 Log(Form("Number of ids: %d",list2->GetEntries()));
478 for(Int_t i = 0; i < list2->GetEntries(); i++) {
479 TObjString *idStr = (TObjString *)list2->At(i);
480 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
481 if (fileName.Length() > 0) {
482 Log(Form("Adding file in the chain: %s",fileName.Data()));
483 fRawTagChain->Add(fileName.Data());
486 Log(Form("Could not retrieve file with id %s from source %s: "
487 "connection problems with DAQ FXS!",
488 idStr->String().Data(), objStr->String().Data()));
490 delete list2; list2=0;
491 delete fRawTagChain; fRawTagChain=0;
499 TString fRawDataFileName = "GRP_Merged.tag.root";
500 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
502 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
503 Log("Error merging raw data files!!!");
507 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
508 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
511 Log("Problem storing raw data tags in local file!!!");
513 Log("Raw data tags merged successfully!!");
518 delete fRawTagChain; fRawTagChain=0;
520 if (result == kFALSE) {
528 //_______________________________________________________________
529 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
532 // processing the info
533 // stored in the DCS FXS
534 // coming from the trigger
537 // Get the CTP counters information
538 TList* list = GetFileSources(kDCS,"CTP_xcounters");
540 Log("No CTP counters file: connection problems with DAQ FXS logbook!");
544 if (list->GetEntries() == 0) {
545 Log("No CTP counters file to be processed!");
551 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
552 TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
553 if (countersfile.IsNull()) {
554 Log("No CTP counters files has been found: empty source!");
557 Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
558 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
560 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
564 AliCDBMetaData metaData;
565 metaData.SetBeamPeriod(0);
566 metaData.SetResponsible("Roman Lietava");
567 metaData.SetComment("CTP scalers");
568 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
569 Log("Unable to store the CTP scalers object to OCDB!");
580 //_______________________________________________________________
582 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
586 // processing DCS DPs
589 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
590 Int_t nLHCEntries = 0;
591 Int_t nL3Entries = 0;
592 Int_t nDipoleEntries = 0;
593 Int_t nEnvEntries = 0;
594 Int_t nHallProbesEntries = 0;
595 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
596 nL3Entries = ProcessL3DPs(valueMap, grpObj);
597 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
598 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
599 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
601 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
606 //_______________________________________________________________
608 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
615 Int_t nL3Entries = 0;
616 TObjArray *array = 0x0;
619 AliInfo(Form("==========L3Polarity==========="));
620 indexDP = kL3Polarity;
621 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
623 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
626 if (array->GetEntries() == 0){
627 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
630 Char_t charDCS = ProcessBool(array);
631 grpObj->SetL3Polarity(charDCS);
632 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
637 if (array) array = 0x0;
639 AliInfo(Form("==========L3Current==========="));
640 indexDP = kL3Current;
641 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
643 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
646 if (array->GetEntries() == 0){
647 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
650 Float_t *floatDCS = ProcessFloatAll(array);
651 grpObj->SetL3Current(floatDCS);
660 //_______________________________________________________________
662 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
668 Int_t nDipoleEntries = 0;
669 TObjArray *array = 0x0;
672 AliInfo(Form("==========DipolePolarity==========="));
673 indexDP = kDipolePolarity;
674 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
676 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
679 if (array->GetEntries() == 0){
680 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
683 Char_t charDCS = ProcessBool(array);
684 grpObj->SetDipolePolarity(charDCS);
685 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
690 if (array) array = 0x0;
692 AliInfo(Form("==========DipoleCurrent==========="));
693 indexDP = kDipoleCurrent;
694 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
696 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
699 if (array->GetEntries() == 0){
700 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
703 Float_t *floatDCS = ProcessFloatAll(array);
704 grpObj->SetDipoleCurrent(floatDCS);
710 return nDipoleEntries;
713 //_______________________________________________________________
715 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
719 // evironment conditions (temperature, pressure) info
721 Int_t nEnvEntries = 0;
722 TObjArray *array = 0x0;
725 AliInfo(Form("==========CavernTemperature==========="));
726 indexDP = kCavernTemperature;
727 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
729 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
732 if (array->GetEntries() == 0){
733 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
736 Float_t *floatDCS = ProcessFloatAll(array);
737 grpObj->SetCavernTemperature(floatDCS);
743 if (array) array = 0x0;
745 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
746 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
747 dcsSensorArray->Print();
748 if( fPressure->NumFits()==0 ) {
749 Log("Problem with the pressure sensor values!!!");
752 AliInfo(Form("==========CavernAtmosPressure==========="));
753 indexDP = kCavernAtmosPressure;
754 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
755 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
756 if( sensorCavernP2->GetFit() ) {
757 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
758 grpObj->SetCavernAtmosPressure(sensorCavernP2);
761 //if (sensorP2) delete sensorP2;
763 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
765 AliInfo(Form("==========SurfaceAtmosPressure==========="));
766 indexDP = kSurfaceAtmosPressure;
767 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
768 AliDebug(2,Form("sensorP2 = %p", sensorP2));
769 if( sensorP2->GetFit() ) {
770 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
771 grpObj->SetSurfaceAtmosPressure(sensorP2);
774 //if (sensorP2) delete sensorP2;
776 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
781 /* indexDP = kCavernAtmosPressure;
782 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
784 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
787 Float_t *floatDCS = ProcessFloatAll(array);
788 grpObj->SetCavernAtmosPressure(floatDCS);
794 if (array) array = 0x0;
796 AliInfo(Form("==========SurfaceAtmosPressure==========="));
797 indexDP = kSurfaceAtmosPressure;
798 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
799 dcsSensorArray->Print();
800 AliInfo(Form("fPressure = %p",fPressure));
801 AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
802 if( fPressure->NumFits()==0 ) {
803 Log("Problem with the pressure sensor values!!!");
806 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
807 AliDebug(2,Form("sensorP2 = %p", sensorP2));
808 if( sensorP2->GetFit() ) {
809 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
810 grpObj->SetSurfaceAtmosPressure(sensorP2);
813 //if (sensorP2) delete sensorP2;
815 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
823 //_______________________________________________________________
825 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
831 Int_t nHPEntries = 0;
832 TObjArray *array = 0x0;
835 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
836 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()));
838 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
839 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
840 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
842 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
845 if (array->GetEntries() == 0){
846 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
849 Float_t *floatDCS = ProcessFloatAll(array);
850 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]));
851 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
852 for (Int_t kk = 0 ; kk< 5; kk++){
853 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
861 Log(Form("Hall Probes = %d ", nHPEntries));
865 //_______________________________________________________________
867 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
871 // processing of LHC related DCS DPs, i.e.:
877 Int_t nLHCEntries = 0;
878 TObjArray *array = 0x0;
881 AliInfo(Form("==========LHCState==========="));
883 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
885 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
888 if (array->GetEntries() == 0){
889 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
892 TString stringDCS = ProcessChar(array);
893 if (stringDCS.Length()!=0) {
894 Bool_t found = kFALSE;
895 for( Int_t i=0; i<20; i+=2 ) {
896 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
897 stringDCS = fgkLHCState[i+1];
903 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
904 grpObj->SetLHCState(stringDCS);
907 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
908 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
912 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
913 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
919 if (array) array = 0x0;
921 AliInfo(Form("==========LHCLuminosity==========="));
922 indexDP = kLHCLuminosity;
923 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
925 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
928 if (array->GetEntries() == 0){
929 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
932 Float_t *floatDCS = ProcessFloatAll(array);
933 grpObj->SetLHCLuminosity(floatDCS);
935 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
936 grpObj->SetLHCLuminositySplineFit(splfit);
942 if (array) array = 0x0;
944 AliInfo(Form("==========BeamIntensity==========="));
945 indexDP = kBeamIntensity;
946 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
948 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
951 if (array->GetEntries() == 0){
952 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
955 Float_t *floatDCS = ProcessFloatAll(array);
956 grpObj->SetBeamIntensity(floatDCS);
958 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
959 grpObj->SetBeamIntensitySplineFit(splfit1);
967 //_________________________________________________________________________
969 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
973 // returning Spline Fit
976 Int_t entriesarray = array->GetEntries();
977 Float_t* value = new Float_t[entriesarray];
978 Float_t* time = new Float_t[entriesarray];
979 AliDCSValue* v = 0x0;
980 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
981 v = (AliDCSValue*)array->At(iarray);
982 value[iarray] = v->GetFloat();
983 time[iarray] = v->GetTimeStamp();
984 AliInfo(Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
986 TGraph* gr = new TGraph(entriesarray,value,time);
988 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
991 AliSplineFit *fit = new AliSplineFit();
992 fit->SetMinPoints(10);
993 fit->InitKnots(gr,10,10,0.0);
997 AliWarning(Form("%s: no fit performed",stringID.Data()));
1003 //_________________________________________________________________________
1005 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1012 TString aDCSString="";
1014 AliDCSValue *v = 0x0;
1015 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1016 v = (AliDCSValue *)array->At(iCount);
1017 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1018 AliError(Form("DCS values for the parameter outside the queried interval"));
1022 if (aDCSString != v->GetChar())
1023 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1025 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1030 //__________________________________________________________________________________________________________________
1032 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1035 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1037 // parameters[0] = mean
1038 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1039 // parameters[2] = median
1040 // parameters[3] = standard deviation wrt mean
1041 // parameters[4] = standard deviation wrt median
1044 Float_t* parameters = new Float_t[5];
1045 Double_t aDCSArrayMean = 0; // Mean
1046 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1047 Double_t aDCSArrayMedian = 0; // Median
1048 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1049 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1050 Float_t aDCSArraySum = 0.0;
1055 Int_t nCounts = array->GetEntries();
1056 Float_t *tempArray = new Float_t[nCounts];
1057 for(Int_t i = 0; i < nCounts; i++) {
1058 AliDCSValue *v = (AliDCSValue *)array->At(i);
1059 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1060 aDCSArraySum += v->GetFloat();
1061 tempArray[i] = v->GetFloat();
1062 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1067 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
1069 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1070 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1071 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1072 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
1073 // computing standard deviation wrt median
1074 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1075 for (Int_t i = 0; i < iCounts; i++){
1076 AliDCSValue *v = (AliDCSValue *)array->At(i);
1077 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1078 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
1079 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
1080 temp1+=v->GetFloat();
1082 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
1084 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1086 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
1088 AliDebug(3,Form("temp after the ratio = %f", temp));
1090 aDCSArraySDMedian = TMath::Sqrt(temp);
1093 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1094 aDCSArraySDMedian = 0;
1097 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
1098 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1102 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1103 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1104 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1106 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
1108 aDCSArrayTruncMean = temp1/iCounts1;
1111 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1116 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1117 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1118 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1119 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1120 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
1122 parameters[0] = aDCSArrayMean;
1123 parameters[1] = aDCSArrayTruncMean;
1124 parameters[2] = aDCSArrayMedian;
1125 parameters[3] = aDCSArraySDMean;
1126 parameters[4] = aDCSArraySDMedian;
1128 // 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]));
1129 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]));
1135 //_______________________________________________________________
1137 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
1140 // processing Boolean values
1143 Bool_t aDCSBool = kTRUE;
1145 AliDCSValue *v = 0x0;
1147 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1148 v = (AliDCSValue *)array->At(iCount);
1149 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1150 AliError(Form("DCS values for the parameter outside the queried interval"));
1154 if (aDCSBool != v->GetBool())
1155 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1157 aDCSBool = v->GetBool(); // always keeping last value
1158 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1161 Char_t caDCSBool = (Char_t) aDCSBool;
1166 //_______________________________________________________________
1168 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1171 // processing Int values, returning mean
1174 Float_t aDCSArraySum = 0.0;
1175 Float_t aDCSArrayMean = 0.0;
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 aDCSArraySum += v->GetInt();
1187 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1188 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1190 return aDCSArrayMean;
1193 //_______________________________________________________________
1195 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1198 // processing Int values, returning mean
1201 Float_t aDCSArraySum = 0.0;
1202 Float_t aDCSArrayMean = 0.0;
1204 AliDCSValue* v = 0x0;
1206 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1207 v = (AliDCSValue *)array->At(iCount);
1208 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1209 aDCSArraySum += v->GetUInt();
1214 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1215 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1217 return aDCSArrayMean;
1222 //_______________________________________________________________
1224 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1226 // extract DCS pressure maps. Perform fits to save space
1228 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1230 fPressure->MakeSplineFit(map);
1231 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1232 if (fitFraction > kFitFraction ) {
1233 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1235 AliInfo("Too few pressure maps fitted!!!");
1238 AliInfo("no atmospheric pressure map extracted!!!");
1247 //_______________________________________________________________
1248 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)
1251 // Retrieves logbook and trigger information from the online logbook
1252 // This information is needed for prompt reconstruction
1256 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1260 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1261 // 0 on success and no run was found
1262 // negative on error
1264 // This function is NOT called during the preprocessor run in the Shuttle!
1272 AliCDBManager* cdb = AliCDBManager::Instance();
1273 cdb->SetDefaultStorage(cdbRoot);
1276 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1280 Printf("ERROR: Could not connect to DAQ LB");
1286 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1287 TSQLResult* result = server->Query(sqlQuery);
1290 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1294 if (result->GetRowCount() == 0)
1296 Printf("ERROR: Run %d not found", run);
1301 TSQLRow* row = result->Next();
1304 Printf("ERROR: Could not receive data from run %d", run);
1309 TString timeStartString(row->GetField(0));
1310 TString runType(row->GetField(1));
1311 TString detectorMaskString(row->GetField(2));
1312 TString l3CurrentString(row->GetField(3));
1313 TString dipoleCurrentString(row->GetField(4));
1314 time_t timeStart = (time_t)(timeStartString.Atoi());
1315 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1316 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1317 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1319 AliGRPObject * grpObj = new AliGRPObject();
1320 grpObj->SetTimeStart(timeStart);
1321 grpObj->SetRunType((TString)(row->GetField(1)));
1322 grpObj->SetDetectorMask(detectorMask);
1323 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1324 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1332 Printf("Storing GRP/GRP/Data object with the following content");
1335 AliCDBMetaData metadata;
1336 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
1337 metadata.SetComment("GRP Output parameters received during online running");
1339 AliCDBId id("GRP/GRP/Data", run, run);
1340 Bool_t success = cdb->Put(grpObj, id, &metadata);
1346 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1350 // Receive trigger information
1351 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1352 result = server->Query(sqlQuery);
1355 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1359 if (result->GetRowCount() == 0)
1361 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1366 row = result->Next();
1369 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1374 TString triggerConfig(row->GetField(0));
1382 Printf("Found trigger configuration: %s", triggerConfig.Data());
1384 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1387 Printf("ERROR: Could not create CTP configuration object");
1391 metadata.SetComment("CTP run configuration received during online running");
1393 AliCDBId id2("GRP/CTP/Config", run, run);
1394 success = cdb->Put(runcfg, id2, &metadata);
1401 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1405 // get last run with same run type that was already processed by the SHUTTLE
1407 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());
1408 result = server->Query(sqlQuery);
1411 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1415 if (result->GetRowCount() == 0)
1417 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1422 row = result->Next();
1425 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1430 TString lastRunStr(row->GetField(0));
1431 Int_t lastRun = lastRunStr.Atoi();
1433 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);