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");
203 AddRunType("STANDALONE");
206 AddRunType("PULSER");
207 AddRunType("STANDALONE_PULSER");
210 //_______________________________________________________________
212 AliGRPPreprocessor::~AliGRPPreprocessor()
219 //_______________________________________________________________
221 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
223 // Initialize preprocessor
225 AliPreprocessor::Initialize(run, startTime, endTime);
227 AliInfo("Initialization of the GRP preprocessor.");
228 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
229 for(Int_t j = 0; j < kNumSensors; j++) {
230 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
231 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
233 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
235 // fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
236 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
239 //_______________________________________________________________
241 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
243 // process data retrieved by the Shuttle
245 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
247 //=================//
249 //=================//
252 grpobj = ProcessDaqLB();
254 //=================//
256 //=================//
257 UInt_t iDaqFxs = ProcessDaqFxs();
259 Log(Form("DAQ FXS, successful!"));
261 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
265 //=================//
267 //=================//
268 UInt_t iDcsFxs = ProcessDcsFxs();
270 Log(Form("DCS FXS, successful!"));
272 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
276 //=================//
277 // DCS data points //
278 //=================//
279 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
280 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
281 Log(Form("entries found = %d",entries));
282 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, LH3_BSF4_H3 are not working yet...
283 Log(Form("Problem with the DCS data points!!!"));
285 } else Log(Form("DCS data points, successful!"));
287 //=======================//
288 // Trigger Configuration //
289 //=======================//
290 // either from DAQ logbook.....
291 const char * triggerConf = GetTriggerConfiguration();
292 if (triggerConf!= NULL) {
293 Log("Found trigger configuration in DAQ logbook");
294 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
296 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
300 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
301 runcfg->SetTitle(titleCTPcfg);
302 AliCDBMetaData metaData;
303 metaData.SetBeamPeriod(0);
304 metaData.SetResponsible("Roman Lietava");
305 metaData.SetComment("CTP run configuration from DAQ logbook");
306 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
307 Log("Unable to store the CTP run configuration object to OCDB!");
313 Log("Trigger configuration NOT FOUND in DAQ logbook");
317 /* the DCS should not been used any more to access this stuff!!!
318 // ...or from DCS FXS
320 Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS...");
321 TString runcfgfile = GetFile(kDCS, "CTP_runconfig", "");
322 if (runcfgfile.IsNull()) {
323 Log("No CTP runconfig files has been found in DCS FXS!");
327 Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data()));
328 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
330 Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!");
334 TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun);
335 runcfg->SetTitle(titleCTPcfg);
336 AliCDBMetaData metaData;
337 metaData.SetBeamPeriod(0);
338 metaData.SetResponsible("Roman Lietava");
339 metaData.SetComment("CTP run configuration from DCS FXS");
340 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
341 Log("Unable to store the CTP run configuration object to OCDB!");
349 md.SetResponsible("Ernesto Lopez Torres");
350 md.SetComment("Output parameters from the GRP preprocessor.");
352 Bool_t result = kTRUE;
353 result = Store("GRP", "Data", grpobj, &md);
356 if (result && !error ) {
357 Log("GRP Preprocessor Success");
360 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s",
361 kppError[(error&1)?1:0],
362 kppError[(error&2)?2:0],
363 kppError[(error&4)?3:0],
364 kppError[(error&8)?4:0],
365 kppError[(error&16)?5:0]
371 //_______________________________________________________________
373 AliGRPObject* AliGRPPreprocessor::ProcessDaqLB()
375 //Getting the DAQ lb information
377 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
378 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
379 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
380 TString beamType = (TString)GetRunParameter("beamType");
381 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
382 UInt_t detectorMask= (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
383 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
384 TString runType = (TString)GetRunType();
386 AliGRPObject* grpObj = new AliGRPObject();
389 grpObj->SetTimeStart(timeStart);
390 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
393 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
397 grpObj->SetTimeEnd(timeEnd);
398 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
401 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
404 if (beamEnergy != 0){
405 grpObj->SetBeamEnergy(beamEnergy);
406 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
409 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry!"));
412 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
414 if (beamType.Length() != 0){
415 grpObj->SetBeamType(beamType);
416 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
419 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
422 if (numberOfDetectors != 0){
423 grpObj->SetNumberOfDetectors(numberOfDetectors);
424 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
427 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
430 if (detectorMask != 0){
431 grpObj->SetDetectorMask(detectorMask);
432 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
435 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
438 if (lhcPeriod.Length() != 0) {
439 grpObj->SetLHCPeriod(lhcPeriod);
440 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
442 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
444 if (runType.Length() != 0) {
445 grpObj->SetRunType(runType);
446 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
448 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
454 //_______________________________________________________________
456 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
458 //======DAQ FXS======//
460 TList* list = GetFileSources(kDAQ);
462 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
466 if (list->GetEntries() == 0) {
467 Log("no raw data tags in this run: nothing to merge!");
472 TChain *fRawTagChain = new TChain("T");
474 TIterator* iter = list->MakeIterator();
476 while ((obj = iter->Next())) {
477 TObjString* objStr = dynamic_cast<TObjString*> (obj);
479 Log(Form("Found source %s", objStr->String().Data()));
480 TList* list2 = GetFileIDs(kDAQ, objStr->String());
482 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
483 delete fRawTagChain; fRawTagChain=0;
486 Log(Form("Number of ids: %d",list2->GetEntries()));
487 for(Int_t i = 0; i < list2->GetEntries(); i++) {
488 TObjString *idStr = (TObjString *)list2->At(i);
489 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
490 if (fileName.Length() > 0) {
491 Log(Form("Adding file in the chain: %s",fileName.Data()));
492 fRawTagChain->Add(fileName.Data());
495 Log(Form("Could not retrieve file with id %s from source %s: "
496 "connection problems with DAQ FXS!",
497 idStr->String().Data(), objStr->String().Data()));
499 delete list2; list2=0;
500 delete fRawTagChain; fRawTagChain=0;
508 TString fRawDataFileName = "GRP_Merged.tag.root";
509 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
511 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
512 Log("Error merging raw data files!!!");
516 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
517 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
520 Log("Problem storing raw data tags in local file!!!");
522 Log("Raw data tags merged successfully!!");
527 delete fRawTagChain; fRawTagChain=0;
529 if (result == kFALSE) {
537 //_______________________________________________________________
538 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
541 // processing the info
542 // stored in the DCS FXS
543 // coming from the trigger
546 // Get the CTP counters information
547 TList* list = GetFileSources(kDCS,"CTP_xcounters");
549 Log("No CTP counters file: connection problems with DCS FXS logbook!");
553 if (list->GetEntries() == 0) {
554 Log("No CTP counters file to be processed!");
560 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
561 TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
562 if (countersfile.IsNull()) {
563 Log("No CTP counters files has been found: empty source!");
566 Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
567 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
569 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
573 AliCDBMetaData metaData;
574 metaData.SetBeamPeriod(0);
575 metaData.SetResponsible("Roman Lietava");
576 metaData.SetComment("CTP scalers");
577 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
578 Log("Unable to store the CTP scalers object to OCDB!");
589 //_______________________________________________________________
591 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
595 // processing DCS DPs
598 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
599 Int_t nLHCEntries = 0;
600 Int_t nL3Entries = 0;
601 Int_t nDipoleEntries = 0;
602 Int_t nEnvEntries = 0;
603 Int_t nHallProbesEntries = 0;
604 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
605 nL3Entries = ProcessL3DPs(valueMap, grpObj);
606 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
607 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
608 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
610 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
615 //_______________________________________________________________
617 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
624 Int_t nL3Entries = 0;
625 TObjArray *array = 0x0;
628 AliInfo(Form("==========L3Polarity==========="));
629 indexDP = kL3Polarity;
630 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
632 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
635 if (array->GetEntries() == 0){
636 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
639 Char_t charDCS = ProcessBool(array);
640 grpObj->SetL3Polarity(charDCS);
641 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
646 if (array) array = 0x0;
648 AliInfo(Form("==========L3Current==========="));
649 indexDP = kL3Current;
650 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
652 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
655 if (array->GetEntries() == 0){
656 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
659 Float_t *floatDCS = ProcessFloatAll(array);
660 grpObj->SetL3Current(floatDCS);
669 //_______________________________________________________________
671 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
677 Int_t nDipoleEntries = 0;
678 TObjArray *array = 0x0;
681 AliInfo(Form("==========DipolePolarity==========="));
682 indexDP = kDipolePolarity;
683 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
685 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
688 if (array->GetEntries() == 0){
689 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
692 Char_t charDCS = ProcessBool(array);
693 grpObj->SetDipolePolarity(charDCS);
694 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
699 if (array) array = 0x0;
701 AliInfo(Form("==========DipoleCurrent==========="));
702 indexDP = kDipoleCurrent;
703 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
705 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
708 if (array->GetEntries() == 0){
709 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
712 Float_t *floatDCS = ProcessFloatAll(array);
713 grpObj->SetDipoleCurrent(floatDCS);
719 return nDipoleEntries;
722 //_______________________________________________________________
724 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
728 // evironment conditions (temperature, pressure) info
730 Int_t nEnvEntries = 0;
731 TObjArray *array = 0x0;
734 AliInfo(Form("==========CavernTemperature==========="));
735 indexDP = kCavernTemperature;
736 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
738 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
741 if (array->GetEntries() == 0){
742 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
745 Float_t *floatDCS = ProcessFloatAll(array);
746 grpObj->SetCavernTemperature(floatDCS);
752 if (array) array = 0x0;
754 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
755 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
756 dcsSensorArray->Print();
757 if( fPressure->NumFits()==0 ) {
758 Log("Problem with the pressure sensor values!!!");
761 AliInfo(Form("==========CavernAtmosPressure==========="));
762 indexDP = kCavernAtmosPressure;
763 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
764 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
765 if( sensorCavernP2->GetFit() ) {
766 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
767 grpObj->SetCavernAtmosPressure(sensorCavernP2);
770 //if (sensorP2) delete sensorP2;
772 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
774 AliInfo(Form("==========SurfaceAtmosPressure==========="));
775 indexDP = kSurfaceAtmosPressure;
776 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
777 AliDebug(2,Form("sensorP2 = %p", sensorP2));
778 if( sensorP2->GetFit() ) {
779 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
780 grpObj->SetSurfaceAtmosPressure(sensorP2);
783 //if (sensorP2) delete sensorP2;
785 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
790 /* indexDP = kCavernAtmosPressure;
791 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
793 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
796 Float_t *floatDCS = ProcessFloatAll(array);
797 grpObj->SetCavernAtmosPressure(floatDCS);
803 if (array) array = 0x0;
805 AliInfo(Form("==========SurfaceAtmosPressure==========="));
806 indexDP = kSurfaceAtmosPressure;
807 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
808 dcsSensorArray->Print();
809 AliInfo(Form("fPressure = %p",fPressure));
810 AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
811 if( fPressure->NumFits()==0 ) {
812 Log("Problem with the pressure sensor values!!!");
815 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
816 AliDebug(2,Form("sensorP2 = %p", sensorP2));
817 if( sensorP2->GetFit() ) {
818 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
819 grpObj->SetSurfaceAtmosPressure(sensorP2);
822 //if (sensorP2) delete sensorP2;
824 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
832 //_______________________________________________________________
834 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
840 Int_t nHPEntries = 0;
841 TObjArray *array = 0x0;
844 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
845 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()));
847 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
848 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
849 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
851 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
854 if (array->GetEntries() == 0){
855 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
858 Float_t *floatDCS = ProcessFloatAll(array);
859 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]));
860 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
861 for (Int_t kk = 0 ; kk< 5; kk++){
862 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
870 Log(Form("Hall Probes = %d ", nHPEntries));
874 //_______________________________________________________________
876 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
880 // processing of LHC related DCS DPs, i.e.:
886 Int_t nLHCEntries = 0;
887 TObjArray *array = 0x0;
890 AliInfo(Form("==========LHCState==========="));
892 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
894 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
897 if (array->GetEntries() == 0){
898 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
901 TString stringDCS = ProcessChar(array);
902 if (stringDCS.Length()!=0) {
903 Bool_t found = kFALSE;
904 for( Int_t i=0; i<20; i+=2 ) {
905 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
906 stringDCS = fgkLHCState[i+1];
912 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
913 grpObj->SetLHCState(stringDCS);
916 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
917 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
921 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
922 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
928 if (array) array = 0x0;
930 AliInfo(Form("==========LHCLuminosity==========="));
931 indexDP = kLHCLuminosity;
932 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
934 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
937 if (array->GetEntries() == 0){
938 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
941 Float_t *floatDCS = ProcessFloatAll(array);
942 grpObj->SetLHCLuminosity(floatDCS);
944 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
945 grpObj->SetLHCLuminositySplineFit(splfit);
951 if (array) array = 0x0;
953 AliInfo(Form("==========BeamIntensity==========="));
954 indexDP = kBeamIntensity;
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->SetBeamIntensity(floatDCS);
967 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
968 grpObj->SetBeamIntensitySplineFit(splfit1);
976 //_________________________________________________________________________
978 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
982 // returning Spline Fit
985 Int_t entriesarray = array->GetEntries();
986 Float_t* value = new Float_t[entriesarray];
987 Float_t* time = new Float_t[entriesarray];
988 AliDCSValue* v = 0x0;
989 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
990 v = (AliDCSValue*)array->At(iarray);
991 value[iarray] = v->GetFloat();
992 time[iarray] = v->GetTimeStamp();
993 AliInfo(Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
995 TGraph* gr = new TGraph(entriesarray,value,time);
997 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1000 AliSplineFit *fit = new AliSplineFit();
1001 fit->SetMinPoints(10);
1002 fit->InitKnots(gr,10,10,0.0);
1006 AliWarning(Form("%s: no fit performed",stringID.Data()));
1012 //_________________________________________________________________________
1014 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1021 TString aDCSString="";
1023 AliDCSValue *v = 0x0;
1024 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1025 v = (AliDCSValue *)array->At(iCount);
1026 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1027 AliError(Form("DCS values for the parameter outside the queried interval"));
1031 if (aDCSString != v->GetChar())
1032 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1034 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1039 //__________________________________________________________________________________________________________________
1041 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1044 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1046 // parameters[0] = mean
1047 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1048 // parameters[2] = median
1049 // parameters[3] = standard deviation wrt mean
1050 // parameters[4] = standard deviation wrt median
1053 Float_t* parameters = new Float_t[5];
1054 Double_t aDCSArrayMean = 0; // Mean
1055 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1056 Double_t aDCSArrayMedian = 0; // Median
1057 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1058 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1059 Float_t aDCSArraySum = 0.0;
1064 Int_t nCounts = array->GetEntries();
1065 Float_t *tempArray = new Float_t[nCounts];
1066 for(Int_t i = 0; i < nCounts; i++) {
1067 AliDCSValue *v = (AliDCSValue *)array->At(i);
1068 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1069 aDCSArraySum += v->GetFloat();
1070 tempArray[i] = v->GetFloat();
1071 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1076 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
1078 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1079 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1080 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1081 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
1082 // computing standard deviation wrt median
1083 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1084 for (Int_t i = 0; i < iCounts; i++){
1085 AliDCSValue *v = (AliDCSValue *)array->At(i);
1086 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1087 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
1088 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
1089 temp1+=v->GetFloat();
1091 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
1093 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1095 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
1097 AliDebug(3,Form("temp after the ratio = %f", temp));
1099 aDCSArraySDMedian = TMath::Sqrt(temp);
1102 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1103 aDCSArraySDMedian = 0;
1106 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
1107 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1111 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1112 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1113 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1115 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
1117 aDCSArrayTruncMean = temp1/iCounts1;
1120 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1125 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1126 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1127 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1128 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1129 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
1131 parameters[0] = aDCSArrayMean;
1132 parameters[1] = aDCSArrayTruncMean;
1133 parameters[2] = aDCSArrayMedian;
1134 parameters[3] = aDCSArraySDMean;
1135 parameters[4] = aDCSArraySDMedian;
1137 // 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]));
1138 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]));
1144 //_______________________________________________________________
1146 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
1149 // processing Boolean values
1152 Bool_t aDCSBool = kTRUE;
1154 AliDCSValue *v = 0x0;
1156 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1157 v = (AliDCSValue *)array->At(iCount);
1158 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1159 AliError(Form("DCS values for the parameter outside the queried interval"));
1163 if (aDCSBool != v->GetBool())
1164 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1166 aDCSBool = v->GetBool(); // always keeping last value
1167 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1170 Char_t caDCSBool = (Char_t) aDCSBool;
1175 //_______________________________________________________________
1177 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1180 // processing Int values, returning mean
1183 Float_t aDCSArraySum = 0.0;
1184 Float_t aDCSArrayMean = 0.0;
1186 AliDCSValue* v = 0x0;
1188 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1189 v = (AliDCSValue *)array->At(iCount);
1190 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1191 aDCSArraySum += v->GetInt();
1196 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1197 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1199 return aDCSArrayMean;
1202 //_______________________________________________________________
1204 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1207 // processing Int values, returning mean
1210 Float_t aDCSArraySum = 0.0;
1211 Float_t aDCSArrayMean = 0.0;
1213 AliDCSValue* v = 0x0;
1215 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1216 v = (AliDCSValue *)array->At(iCount);
1217 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1218 aDCSArraySum += v->GetUInt();
1223 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1224 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1226 return aDCSArrayMean;
1231 //_______________________________________________________________
1233 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1235 // extract DCS pressure maps. Perform fits to save space
1237 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1239 fPressure->MakeSplineFit(map);
1240 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1241 if (fitFraction > kFitFraction ) {
1242 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1244 AliInfo("Too few pressure maps fitted!!!");
1247 AliInfo("no atmospheric pressure map extracted!!!");
1256 //_______________________________________________________________
1257 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)
1260 // Retrieves logbook and trigger information from the online logbook
1261 // This information is needed for prompt reconstruction
1265 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1269 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1270 // 0 on success and no run was found
1271 // negative on error
1273 // This function is NOT called during the preprocessor run in the Shuttle!
1281 AliCDBManager* cdb = AliCDBManager::Instance();
1282 cdb->SetDefaultStorage(cdbRoot);
1285 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1289 Printf("ERROR: Could not connect to DAQ LB");
1295 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1296 TSQLResult* result = server->Query(sqlQuery);
1299 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1303 if (result->GetRowCount() == 0)
1305 Printf("ERROR: Run %d not found", run);
1310 TSQLRow* row = result->Next();
1313 Printf("ERROR: Could not receive data from run %d", run);
1318 TString timeStartString(row->GetField(0));
1319 TString runType(row->GetField(1));
1320 TString detectorMaskString(row->GetField(2));
1321 TString l3CurrentString(row->GetField(3));
1322 TString dipoleCurrentString(row->GetField(4));
1323 time_t timeStart = (time_t)(timeStartString.Atoi());
1324 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1325 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1326 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1328 AliGRPObject * grpObj = new AliGRPObject();
1329 grpObj->SetTimeStart(timeStart);
1330 grpObj->SetRunType((TString)(row->GetField(1)));
1331 grpObj->SetDetectorMask(detectorMask);
1332 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1333 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1341 Printf("Storing GRP/GRP/Data object with the following content");
1344 AliCDBMetaData metadata;
1345 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
1346 metadata.SetComment("GRP Output parameters received during online running");
1348 AliCDBId id("GRP/GRP/Data", run, run);
1349 Bool_t success = cdb->Put(grpObj, id, &metadata);
1355 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1359 // Receive trigger information
1360 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1361 result = server->Query(sqlQuery);
1364 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1368 if (result->GetRowCount() == 0)
1370 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1375 row = result->Next();
1378 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1383 TString triggerConfig(row->GetField(0));
1391 Printf("Found trigger configuration: %s", triggerConfig.Data());
1393 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1396 Printf("ERROR: Could not create CTP configuration object");
1400 metadata.SetComment("CTP run configuration received during online running");
1402 AliCDBId id2("GRP/CTP/Config", run, run);
1403 success = cdb->Put(runcfg, id2, &metadata);
1410 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1414 // get last run with same run type that was already processed by the SHUTTLE
1416 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());
1417 result = server->Query(sqlQuery);
1420 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1424 if (result->GetRowCount() == 0)
1426 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1431 row = result->Next();
1434 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1439 TString lastRunStr(row->GetField(0));
1440 Int_t lastRun = lastRunStr.Atoi();
1442 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);