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");
203 //_______________________________________________________________
205 AliGRPPreprocessor::~AliGRPPreprocessor()
212 //_______________________________________________________________
214 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
216 // Initialize preprocessor
218 AliPreprocessor::Initialize(run, startTime, endTime);
220 AliInfo("Initialization of the GRP preprocessor.");
221 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
222 for(Int_t j = 0; j < kNumSensors; j++) {
223 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
224 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
226 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
228 // fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
229 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
232 //_______________________________________________________________
234 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
236 // process data retrieved by the Shuttle
238 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
240 //=================//
242 //=================//
245 grpobj = ProcessDaqLB();
247 //=================//
249 //=================//
250 UInt_t iDaqFxs = ProcessDaqFxs();
252 Log(Form("DAQ FXS, successful!"));
254 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
258 //=================//
260 //=================//
261 UInt_t iDcsFxs = ProcessDcsFxs();
263 Log(Form("DCS FXS, successful!"));
265 Log(Form("DCS FXS, Could not store CTP run configuration and scalers!!!"));
269 //=================//
270 // DCS data points //
271 //=================//
272 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
273 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
274 Log(Form("entries found = %d",entries));
275 if( entries < fgknDCSDP-7 ) { // FIXME (!= ) LHState and pressure map are not working yet... and removing the 4 values for the missing HP
276 Log(Form("Problem with the DCS data points!!!"));
278 } else Log(Form("DCS data points, successful!"));
280 //=======================//
281 // Trigger Configuration //
282 //=======================//
283 // either from DAQ logbook.....
284 const char * triggerConf = GetTriggerConfiguration();
285 if (triggerConf!= NULL) {
286 Log("Found trigger configuration in DAQ logbook");
287 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
289 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
293 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
294 runcfg->SetTitle(titleCTPcfg);
295 AliCDBMetaData metaData;
296 metaData.SetBeamPeriod(0);
297 metaData.SetResponsible("Roman Lietava");
298 metaData.SetComment("CTP run configuration from DAQ logbook");
299 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
300 Log("Unable to store the CTP run configuration object to OCDB!");
305 /* the DCS should not been used any more to access this stuff!!!
306 // ...or from DCS FXS
308 Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS...");
309 TString runcfgfile = GetFile(kDCS, "CTP_runconfig", "");
310 if (runcfgfile.IsNull()) {
311 Log("No CTP runconfig files has been found in DCS FXS!");
315 Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data()));
316 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
318 Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!");
322 TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun);
323 runcfg->SetTitle(titleCTPcfg);
324 AliCDBMetaData metaData;
325 metaData.SetBeamPeriod(0);
326 metaData.SetResponsible("Roman Lietava");
327 metaData.SetComment("CTP run configuration from DCS FXS");
328 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
329 Log("Unable to store the CTP run configuration object to OCDB!");
337 md.SetResponsible("Ernesto Lopez Torres");
338 md.SetComment("Output parameters from the GRP preprocessor.");
340 Bool_t result = kTRUE;
341 Log("Before storing");
342 result = Store("GRP", "Data", grpobj, &md);
345 if (result && !error ) {
346 Log("GRP Preprocessor Success");
349 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s",
350 kppError[(error&1)?1:0],
351 kppError[(error&2)?2:0],
352 kppError[(error&4)?3:0],
353 kppError[(error&8)?4:0],
354 kppError[(error&16)?5:0]
360 //_______________________________________________________________
362 AliGRPObject* AliGRPPreprocessor::ProcessDaqLB()
364 //Getting the DAQ lb information
366 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
367 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
368 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
369 TString beamType = (TString)GetRunParameter("beamType");
370 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
371 UInt_t detectorMask= (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
372 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
373 TString runType = (TString)GetRunType();
375 AliGRPObject* grpObj = new AliGRPObject();
378 grpObj->SetTimeStart(timeStart);
379 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
382 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
386 grpObj->SetTimeEnd(timeEnd);
387 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
390 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
393 if (beamEnergy != 0){
394 grpObj->SetBeamEnergy(beamEnergy);
395 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
398 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry!"));
401 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
403 if (beamType.Length() != 0){
404 grpObj->SetBeamType(beamType);
405 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
408 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
411 if (numberOfDetectors != 0){
412 grpObj->SetNumberOfDetectors(numberOfDetectors);
413 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
416 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
419 if (detectorMask != 0){
420 grpObj->SetDetectorMask(detectorMask);
421 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
424 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
427 if (lhcPeriod.Length() != 0) {
428 grpObj->SetLHCPeriod(lhcPeriod);
429 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
431 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
433 if (runType.Length() != 0) {
434 grpObj->SetRunType(runType);
435 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
437 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
443 //_______________________________________________________________
445 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
447 //======DAQ FXS======//
449 TList* list = GetFileSources(kDAQ);
451 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
455 if (list->GetEntries() == 0) {
456 Log("no raw data tags in this run: nothing to merge!");
461 TChain *fRawTagChain = new TChain("T");
463 TIterator* iter = list->MakeIterator();
465 while ((obj = iter->Next())) {
466 TObjString* objStr = dynamic_cast<TObjString*> (obj);
468 Log(Form("Found source %s", objStr->String().Data()));
469 TList* list2 = GetFileIDs(kDAQ, objStr->String());
471 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
472 delete fRawTagChain; fRawTagChain=0;
475 Log(Form("Number of ids: %d",list2->GetEntries()));
476 for(Int_t i = 0; i < list2->GetEntries(); i++) {
477 TObjString *idStr = (TObjString *)list2->At(i);
478 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
479 if (fileName.Length() > 0) {
480 Log(Form("Adding file in the chain: %s",fileName.Data()));
481 fRawTagChain->Add(fileName.Data());
484 Log(Form("Could not retrieve file with id %s from source %s: "
485 "connection problems with DAQ FXS!",
486 idStr->String().Data(), objStr->String().Data()));
488 delete list2; list2=0;
489 delete fRawTagChain; fRawTagChain=0;
497 TString fRawDataFileName = "GRP_Merged.tag.root";
498 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
500 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
501 Log("Error merging raw data files!!!");
505 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
506 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
509 Log("Problem storing raw data tags in local file!!!");
511 Log("Raw data tags merged successfully!!");
516 delete fRawTagChain; fRawTagChain=0;
518 if (result == kFALSE) {
526 //_______________________________________________________________
527 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
530 // processing the info
531 // stored in the DCS FXS
532 // coming from the trigger
535 // Get the CTP counters information
536 TList* list = GetFileSources(kDCS,"CTP_xcounters");
538 Log("No CTP counters file: connection problems with DAQ FXS logbook!");
542 if (list->GetEntries() == 0) {
543 Log("No CTP counters file to be processed!");
549 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
550 TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
551 if (countersfile.IsNull()) {
552 Log("No CTP counters files has been found: empty source!");
555 Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
556 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
558 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
562 AliCDBMetaData metaData;
563 metaData.SetBeamPeriod(0);
564 metaData.SetResponsible("Roman Lietava");
565 metaData.SetComment("CTP scalers");
566 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
567 Log("Unable to store the CTP scalers object to OCDB!");
578 //_______________________________________________________________
580 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
584 // processing DCS DPs
587 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
588 Int_t nLHCEntries = 0;
589 Int_t nL3Entries = 0;
590 Int_t nDipoleEntries = 0;
591 Int_t nEnvEntries = 0;
592 Int_t nHallProbesEntries = 0;
593 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
594 nL3Entries = ProcessL3DPs(valueMap, grpObj);
595 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
596 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
597 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
599 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
604 //_______________________________________________________________
606 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
613 Int_t nL3Entries = 0;
614 TObjArray *array = 0x0;
617 AliInfo(Form("==========L3Polarity==========="));
618 indexDP = kL3Polarity;
619 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
621 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
624 if (array->GetEntries() == 0){
625 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
628 Char_t charDCS = ProcessBool(array);
629 grpObj->SetL3Polarity(charDCS);
630 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
635 if (array) array = 0x0;
637 AliInfo(Form("==========L3Current==========="));
638 indexDP = kL3Current;
639 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
641 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
644 if (array->GetEntries() == 0){
645 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
648 Float_t *floatDCS = ProcessFloatAll(array);
649 grpObj->SetL3Current(floatDCS);
658 //_______________________________________________________________
660 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
666 Int_t nDipoleEntries = 0;
667 TObjArray *array = 0x0;
670 AliInfo(Form("==========DipolePolarity==========="));
671 indexDP = kDipolePolarity;
672 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
674 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
677 if (array->GetEntries() == 0){
678 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
681 Char_t charDCS = ProcessBool(array);
682 grpObj->SetDipolePolarity(charDCS);
683 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
688 if (array) array = 0x0;
690 AliInfo(Form("==========DipoleCurrent==========="));
691 indexDP = kDipoleCurrent;
692 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
694 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
697 if (array->GetEntries() == 0){
698 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
701 Float_t *floatDCS = ProcessFloatAll(array);
702 grpObj->SetDipoleCurrent(floatDCS);
708 return nDipoleEntries;
711 //_______________________________________________________________
713 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
717 // evironment conditions (temperature, pressure) info
719 Int_t nEnvEntries = 0;
720 TObjArray *array = 0x0;
723 AliInfo(Form("==========CavernTemperature==========="));
724 indexDP = kCavernTemperature;
725 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
727 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
730 if (array->GetEntries() == 0){
731 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
734 Float_t *floatDCS = ProcessFloatAll(array);
735 grpObj->SetCavernTemperature(floatDCS);
741 if (array) array = 0x0;
743 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
744 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
745 dcsSensorArray->Print();
746 if( fPressure->NumFits()==0 ) {
747 Log("Problem with the pressure sensor values!!!");
750 AliInfo(Form("==========CavernAtmosPressure==========="));
751 indexDP = kCavernAtmosPressure;
752 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
753 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
754 if( sensorCavernP2->GetFit() ) {
755 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
756 grpObj->SetCavernAtmosPressure(sensorCavernP2);
759 //if (sensorP2) delete sensorP2;
761 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
763 AliInfo(Form("==========SurfaceAtmosPressure==========="));
764 indexDP = kSurfaceAtmosPressure;
765 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
766 AliDebug(2,Form("sensorP2 = %p", sensorP2));
767 if( sensorP2->GetFit() ) {
768 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
769 grpObj->SetSurfaceAtmosPressure(sensorP2);
772 //if (sensorP2) delete sensorP2;
774 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
779 /* indexDP = kCavernAtmosPressure;
780 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
782 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
785 Float_t *floatDCS = ProcessFloatAll(array);
786 grpObj->SetCavernAtmosPressure(floatDCS);
792 if (array) array = 0x0;
794 AliInfo(Form("==========SurfaceAtmosPressure==========="));
795 indexDP = kSurfaceAtmosPressure;
796 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
797 dcsSensorArray->Print();
798 AliInfo(Form("fPressure = %p",fPressure));
799 AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
800 if( fPressure->NumFits()==0 ) {
801 Log("Problem with the pressure sensor values!!!");
804 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
805 AliDebug(2,Form("sensorP2 = %p", sensorP2));
806 if( sensorP2->GetFit() ) {
807 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
808 grpObj->SetSurfaceAtmosPressure(sensorP2);
811 //if (sensorP2) delete sensorP2;
813 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
821 //_______________________________________________________________
823 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
829 Int_t nHPEntries = 0;
830 TObjArray *array = 0x0;
833 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
834 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()));
836 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
837 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
838 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
840 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
843 if (array->GetEntries() == 0){
844 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
847 Float_t *floatDCS = ProcessFloatAll(array);
848 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]));
849 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
850 for (Int_t kk = 0 ; kk< 5; kk++){
851 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
859 Log(Form("Hall Probes = %d ", nHPEntries));
863 //_______________________________________________________________
865 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
869 // processing of LHC related DCS DPs, i.e.:
875 Int_t nLHCEntries = 0;
876 TObjArray *array = 0x0;
879 AliInfo(Form("==========LHCState==========="));
881 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
883 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
886 if (array->GetEntries() == 0){
887 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
890 TString stringDCS = ProcessChar(array);
891 if (stringDCS.Length()!=0) {
892 Bool_t found = kFALSE;
893 for( Int_t i=0; i<20; i+=2 ) {
894 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
895 stringDCS = fgkLHCState[i+1];
901 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
902 grpObj->SetLHCState(stringDCS);
905 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
906 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
910 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
911 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
917 if (array) array = 0x0;
919 AliInfo(Form("==========LHCLuminosity==========="));
920 indexDP = kLHCLuminosity;
921 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
923 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
926 if (array->GetEntries() == 0){
927 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
930 Float_t *floatDCS = ProcessFloatAll(array);
931 grpObj->SetLHCLuminosity(floatDCS);
933 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
934 grpObj->SetLHCLuminositySplineFit(splfit);
940 if (array) array = 0x0;
942 AliInfo(Form("==========BeamIntensity==========="));
943 indexDP = kBeamIntensity;
944 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
946 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
949 if (array->GetEntries() == 0){
950 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
953 Float_t *floatDCS = ProcessFloatAll(array);
954 grpObj->SetBeamIntensity(floatDCS);
956 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
957 grpObj->SetBeamIntensitySplineFit(splfit1);
965 //_________________________________________________________________________
967 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
971 // returning Spline Fit
974 Int_t entriesarray = array->GetEntries();
975 Float_t* value = new Float_t[entriesarray];
976 Float_t* time = new Float_t[entriesarray];
977 AliDCSValue* v = 0x0;
978 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
979 v = (AliDCSValue*)array->At(iarray);
980 value[iarray] = v->GetFloat();
981 time[iarray] = v->GetTimeStamp();
982 AliInfo(Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
984 TGraph* gr = new TGraph(entriesarray,value,time);
986 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
989 AliSplineFit *fit = new AliSplineFit();
990 fit->SetMinPoints(10);
991 fit->InitKnots(gr,10,10,0.0);
995 AliWarning(Form("%s: no fit performed",stringID.Data()));
1001 //_________________________________________________________________________
1003 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1010 TString aDCSString="";
1012 AliDCSValue *v = 0x0;
1013 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1014 v = (AliDCSValue *)array->At(iCount);
1015 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1016 AliError(Form("DCS values for the parameter outside the queried interval"));
1020 if (aDCSString != v->GetChar())
1021 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1023 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1028 //__________________________________________________________________________________________________________________
1030 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1033 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1035 // parameters[0] = mean
1036 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1037 // parameters[2] = median
1038 // parameters[3] = standard deviation wrt mean
1039 // parameters[4] = standard deviation wrt median
1042 Float_t* parameters = new Float_t[5];
1043 Double_t aDCSArrayMean = 0; // Mean
1044 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1045 Double_t aDCSArrayMedian = 0; // Median
1046 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1047 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1048 Float_t aDCSArraySum = 0.0;
1053 Int_t nCounts = array->GetEntries();
1054 Float_t *tempArray = new Float_t[nCounts];
1055 for(Int_t i = 0; i < nCounts; i++) {
1056 AliDCSValue *v = (AliDCSValue *)array->At(i);
1057 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1058 aDCSArraySum += v->GetFloat();
1059 tempArray[i] = v->GetFloat();
1060 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1065 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
1067 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1068 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1069 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1070 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
1071 // computing standard deviation wrt median
1072 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1073 for (Int_t i = 0; i < iCounts; i++){
1074 AliDCSValue *v = (AliDCSValue *)array->At(i);
1075 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1076 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
1077 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
1078 temp1+=v->GetFloat();
1080 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
1082 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1084 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
1086 AliDebug(3,Form("temp after the ratio = %f", temp));
1088 aDCSArraySDMedian = TMath::Sqrt(temp);
1091 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1092 aDCSArraySDMedian = 0;
1095 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
1096 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1100 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1101 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1102 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1104 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
1106 aDCSArrayTruncMean = temp1/iCounts1;
1109 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1114 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1115 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1116 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1117 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1118 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
1120 parameters[0] = aDCSArrayMean;
1121 parameters[1] = aDCSArrayTruncMean;
1122 parameters[2] = aDCSArrayMedian;
1123 parameters[3] = aDCSArraySDMean;
1124 parameters[4] = aDCSArraySDMedian;
1126 // 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]));
1127 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]));
1133 //_______________________________________________________________
1135 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
1138 // processing Boolean values
1141 Bool_t aDCSBool = kTRUE;
1143 AliDCSValue *v = 0x0;
1145 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1146 v = (AliDCSValue *)array->At(iCount);
1147 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1148 AliError(Form("DCS values for the parameter outside the queried interval"));
1152 if (aDCSBool != v->GetBool())
1153 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1155 aDCSBool = v->GetBool(); // always keeping last value
1156 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1159 Char_t caDCSBool = (Char_t) aDCSBool;
1164 //_______________________________________________________________
1166 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1169 // processing Int values, returning mean
1172 Float_t aDCSArraySum = 0.0;
1173 Float_t aDCSArrayMean = 0.0;
1175 AliDCSValue* v = 0x0;
1177 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1178 v = (AliDCSValue *)array->At(iCount);
1179 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1180 aDCSArraySum += v->GetInt();
1185 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1186 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1188 return aDCSArrayMean;
1191 //_______________________________________________________________
1193 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1196 // processing Int values, returning mean
1199 Float_t aDCSArraySum = 0.0;
1200 Float_t aDCSArrayMean = 0.0;
1202 AliDCSValue* v = 0x0;
1204 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1205 v = (AliDCSValue *)array->At(iCount);
1206 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1207 aDCSArraySum += v->GetUInt();
1212 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1213 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1215 return aDCSArrayMean;
1220 //_______________________________________________________________
1222 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1224 // extract DCS pressure maps. Perform fits to save space
1226 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1228 fPressure->MakeSplineFit(map);
1229 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1230 if (fitFraction > kFitFraction ) {
1231 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1233 AliInfo("Too few pressure maps fitted!!!");
1236 AliInfo("no atmospheric pressure map extracted!!!");
1245 //_______________________________________________________________
1246 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)
1249 // Retrieves logbook and trigger information from the online logbook
1250 // This information is needed for prompt reconstruction
1254 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1258 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1259 // 0 on success and no run was found
1260 // negative on error
1262 // This function is NOT called during the preprocessor run in the Shuttle!
1270 AliCDBManager* cdb = AliCDBManager::Instance();
1271 cdb->SetDefaultStorage(cdbRoot);
1274 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1278 Printf("ERROR: Could not connect to DAQ LB");
1284 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1285 TSQLResult* result = server->Query(sqlQuery);
1288 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1292 if (result->GetRowCount() == 0)
1294 Printf("ERROR: Run %d not found", run);
1299 TSQLRow* row = result->Next();
1302 Printf("ERROR: Could not receive data from run %d", run);
1307 TString timeStartString(row->GetField(0));
1308 TString runType(row->GetField(1));
1309 TString detectorMaskString(row->GetField(2));
1310 TString l3CurrentString(row->GetField(3));
1311 TString dipoleCurrentString(row->GetField(4));
1312 time_t timeStart = (time_t)(timeStartString.Atoi());
1313 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1314 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1315 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1317 AliGRPObject * grpObj = new AliGRPObject();
1318 grpObj->SetTimeStart(timeStart);
1319 grpObj->SetRunType((TString)(row->GetField(1)));
1320 grpObj->SetDetectorMask(detectorMask);
1321 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1322 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1330 Printf("Storing GRP/GRP/Data object with the following content");
1333 AliCDBMetaData metadata;
1334 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
1335 metadata.SetComment("GRP Output parameters received during online running");
1337 AliCDBId id("GRP/GRP/Data", run, run);
1338 Bool_t success = cdb->Put(grpObj, id, &metadata);
1344 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1348 // Receive trigger information
1349 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1350 result = server->Query(sqlQuery);
1353 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1357 if (result->GetRowCount() == 0)
1359 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1364 row = result->Next();
1367 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1372 TString triggerConfig(row->GetField(0));
1380 Printf("Found trigger configuration: %s", triggerConfig.Data());
1382 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1385 Printf("ERROR: Could not create CTP configuration object");
1389 metadata.SetComment("CTP run configuration received during online running");
1391 AliCDBId id2("GRP/CTP/Config", run, run);
1392 success = cdb->Put(runcfg, id2, &metadata);
1399 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1403 // get last run with same run type that was already processed by the SHUTTLE
1405 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());
1406 result = server->Query(sqlQuery);
1409 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1413 if (result->GetRowCount() == 0)
1415 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1420 row = result->Next();
1423 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1428 TString lastRunStr(row->GetField(0));
1429 Int_t lastRun = lastRunStr.Atoi();
1431 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);