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");
209 //_______________________________________________________________
211 AliGRPPreprocessor::~AliGRPPreprocessor()
218 //_______________________________________________________________
220 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
222 // Initialize preprocessor
224 AliPreprocessor::Initialize(run, startTime, endTime);
226 AliInfo("Initialization of the GRP preprocessor.");
227 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
228 for(Int_t j = 0; j < kNumSensors; j++) {
229 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
230 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
232 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
234 // fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
235 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
238 //_______________________________________________________________
240 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
242 // process data retrieved by the Shuttle
244 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
246 //=================//
248 //=================//
251 grpobj = ProcessDaqLB();
253 //=================//
255 //=================//
256 UInt_t iDaqFxs = ProcessDaqFxs();
258 Log(Form("DAQ FXS, successful!"));
260 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
264 //=================//
266 //=================//
267 UInt_t iDcsFxs = ProcessDcsFxs();
269 Log(Form("DCS FXS, successful!"));
271 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
275 //=================//
276 // DCS data points //
277 //=================//
278 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
279 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
280 Log(Form("entries found = %d",entries));
281 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, LH3_BSF4_H3 are not working yet...
282 Log(Form("Problem with the DCS data points!!!"));
284 } else Log(Form("DCS data points, successful!"));
286 //=======================//
287 // Trigger Configuration //
288 //=======================//
289 // either from DAQ logbook.....
290 const char * triggerConf = GetTriggerConfiguration();
291 if (triggerConf!= NULL) {
292 Log("Found trigger configuration in DAQ logbook");
293 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
295 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
299 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
300 runcfg->SetTitle(titleCTPcfg);
301 AliCDBMetaData metaData;
302 metaData.SetBeamPeriod(0);
303 metaData.SetResponsible("Roman Lietava");
304 metaData.SetComment("CTP run configuration from DAQ logbook");
305 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
306 Log("Unable to store the CTP run configuration object to OCDB!");
311 /* the DCS should not been used any more to access this stuff!!!
312 // ...or from DCS FXS
314 Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS...");
315 TString runcfgfile = GetFile(kDCS, "CTP_runconfig", "");
316 if (runcfgfile.IsNull()) {
317 Log("No CTP runconfig files has been found in DCS FXS!");
321 Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data()));
322 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
324 Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!");
328 TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun);
329 runcfg->SetTitle(titleCTPcfg);
330 AliCDBMetaData metaData;
331 metaData.SetBeamPeriod(0);
332 metaData.SetResponsible("Roman Lietava");
333 metaData.SetComment("CTP run configuration from DCS FXS");
334 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
335 Log("Unable to store the CTP run configuration object to OCDB!");
343 md.SetResponsible("Ernesto Lopez Torres");
344 md.SetComment("Output parameters from the GRP preprocessor.");
346 Bool_t result = kTRUE;
347 Log("Before storing");
348 result = Store("GRP", "Data", grpobj, &md);
351 if (result && !error ) {
352 Log("GRP Preprocessor Success");
355 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s",
356 kppError[(error&1)?1:0],
357 kppError[(error&2)?2:0],
358 kppError[(error&4)?3:0],
359 kppError[(error&8)?4:0],
360 kppError[(error&16)?5:0]
366 //_______________________________________________________________
368 AliGRPObject* AliGRPPreprocessor::ProcessDaqLB()
370 //Getting the DAQ lb information
372 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
373 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
374 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
375 TString beamType = (TString)GetRunParameter("beamType");
376 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
377 UInt_t detectorMask= (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
378 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
379 TString runType = (TString)GetRunType();
381 AliGRPObject* grpObj = new AliGRPObject();
384 grpObj->SetTimeStart(timeStart);
385 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
388 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
392 grpObj->SetTimeEnd(timeEnd);
393 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
396 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
399 if (beamEnergy != 0){
400 grpObj->SetBeamEnergy(beamEnergy);
401 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
404 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry!"));
407 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
409 if (beamType.Length() != 0){
410 grpObj->SetBeamType(beamType);
411 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
414 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
417 if (numberOfDetectors != 0){
418 grpObj->SetNumberOfDetectors(numberOfDetectors);
419 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
422 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
425 if (detectorMask != 0){
426 grpObj->SetDetectorMask(detectorMask);
427 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
430 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
433 if (lhcPeriod.Length() != 0) {
434 grpObj->SetLHCPeriod(lhcPeriod);
435 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
437 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
439 if (runType.Length() != 0) {
440 grpObj->SetRunType(runType);
441 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
443 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
449 //_______________________________________________________________
451 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
453 //======DAQ FXS======//
455 TList* list = GetFileSources(kDAQ);
457 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
461 if (list->GetEntries() == 0) {
462 Log("no raw data tags in this run: nothing to merge!");
467 TChain *fRawTagChain = new TChain("T");
469 TIterator* iter = list->MakeIterator();
471 while ((obj = iter->Next())) {
472 TObjString* objStr = dynamic_cast<TObjString*> (obj);
474 Log(Form("Found source %s", objStr->String().Data()));
475 TList* list2 = GetFileIDs(kDAQ, objStr->String());
477 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
478 delete fRawTagChain; fRawTagChain=0;
481 Log(Form("Number of ids: %d",list2->GetEntries()));
482 for(Int_t i = 0; i < list2->GetEntries(); i++) {
483 TObjString *idStr = (TObjString *)list2->At(i);
484 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
485 if (fileName.Length() > 0) {
486 Log(Form("Adding file in the chain: %s",fileName.Data()));
487 fRawTagChain->Add(fileName.Data());
490 Log(Form("Could not retrieve file with id %s from source %s: "
491 "connection problems with DAQ FXS!",
492 idStr->String().Data(), objStr->String().Data()));
494 delete list2; list2=0;
495 delete fRawTagChain; fRawTagChain=0;
503 TString fRawDataFileName = "GRP_Merged.tag.root";
504 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
506 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
507 Log("Error merging raw data files!!!");
511 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
512 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
515 Log("Problem storing raw data tags in local file!!!");
517 Log("Raw data tags merged successfully!!");
522 delete fRawTagChain; fRawTagChain=0;
524 if (result == kFALSE) {
532 //_______________________________________________________________
533 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
536 // processing the info
537 // stored in the DCS FXS
538 // coming from the trigger
541 // Get the CTP counters information
542 TList* list = GetFileSources(kDCS,"CTP_xcounters");
544 Log("No CTP counters file: connection problems with DCS FXS logbook!");
548 if (list->GetEntries() == 0) {
549 Log("No CTP counters file to be processed!");
555 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
556 TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
557 if (countersfile.IsNull()) {
558 Log("No CTP counters files has been found: empty source!");
561 Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
562 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
564 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
568 AliCDBMetaData metaData;
569 metaData.SetBeamPeriod(0);
570 metaData.SetResponsible("Roman Lietava");
571 metaData.SetComment("CTP scalers");
572 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
573 Log("Unable to store the CTP scalers object to OCDB!");
584 //_______________________________________________________________
586 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
590 // processing DCS DPs
593 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
594 Int_t nLHCEntries = 0;
595 Int_t nL3Entries = 0;
596 Int_t nDipoleEntries = 0;
597 Int_t nEnvEntries = 0;
598 Int_t nHallProbesEntries = 0;
599 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
600 nL3Entries = ProcessL3DPs(valueMap, grpObj);
601 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
602 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
603 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
605 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
610 //_______________________________________________________________
612 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
619 Int_t nL3Entries = 0;
620 TObjArray *array = 0x0;
623 AliInfo(Form("==========L3Polarity==========="));
624 indexDP = kL3Polarity;
625 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
627 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
630 if (array->GetEntries() == 0){
631 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
634 Char_t charDCS = ProcessBool(array);
635 grpObj->SetL3Polarity(charDCS);
636 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
641 if (array) array = 0x0;
643 AliInfo(Form("==========L3Current==========="));
644 indexDP = kL3Current;
645 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
647 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
650 if (array->GetEntries() == 0){
651 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
654 Float_t *floatDCS = ProcessFloatAll(array);
655 grpObj->SetL3Current(floatDCS);
664 //_______________________________________________________________
666 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
672 Int_t nDipoleEntries = 0;
673 TObjArray *array = 0x0;
676 AliInfo(Form("==========DipolePolarity==========="));
677 indexDP = kDipolePolarity;
678 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
680 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
683 if (array->GetEntries() == 0){
684 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
687 Char_t charDCS = ProcessBool(array);
688 grpObj->SetDipolePolarity(charDCS);
689 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
694 if (array) array = 0x0;
696 AliInfo(Form("==========DipoleCurrent==========="));
697 indexDP = kDipoleCurrent;
698 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
700 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
703 if (array->GetEntries() == 0){
704 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
707 Float_t *floatDCS = ProcessFloatAll(array);
708 grpObj->SetDipoleCurrent(floatDCS);
714 return nDipoleEntries;
717 //_______________________________________________________________
719 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
723 // evironment conditions (temperature, pressure) info
725 Int_t nEnvEntries = 0;
726 TObjArray *array = 0x0;
729 AliInfo(Form("==========CavernTemperature==========="));
730 indexDP = kCavernTemperature;
731 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
733 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
736 if (array->GetEntries() == 0){
737 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
740 Float_t *floatDCS = ProcessFloatAll(array);
741 grpObj->SetCavernTemperature(floatDCS);
747 if (array) array = 0x0;
749 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
750 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
751 dcsSensorArray->Print();
752 if( fPressure->NumFits()==0 ) {
753 Log("Problem with the pressure sensor values!!!");
756 AliInfo(Form("==========CavernAtmosPressure==========="));
757 indexDP = kCavernAtmosPressure;
758 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
759 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
760 if( sensorCavernP2->GetFit() ) {
761 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
762 grpObj->SetCavernAtmosPressure(sensorCavernP2);
765 //if (sensorP2) delete sensorP2;
767 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
769 AliInfo(Form("==========SurfaceAtmosPressure==========="));
770 indexDP = kSurfaceAtmosPressure;
771 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
772 AliDebug(2,Form("sensorP2 = %p", sensorP2));
773 if( sensorP2->GetFit() ) {
774 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
775 grpObj->SetSurfaceAtmosPressure(sensorP2);
778 //if (sensorP2) delete sensorP2;
780 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
785 /* indexDP = kCavernAtmosPressure;
786 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
788 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
791 Float_t *floatDCS = ProcessFloatAll(array);
792 grpObj->SetCavernAtmosPressure(floatDCS);
798 if (array) array = 0x0;
800 AliInfo(Form("==========SurfaceAtmosPressure==========="));
801 indexDP = kSurfaceAtmosPressure;
802 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
803 dcsSensorArray->Print();
804 AliInfo(Form("fPressure = %p",fPressure));
805 AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
806 if( fPressure->NumFits()==0 ) {
807 Log("Problem with the pressure sensor values!!!");
810 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
811 AliDebug(2,Form("sensorP2 = %p", sensorP2));
812 if( sensorP2->GetFit() ) {
813 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
814 grpObj->SetSurfaceAtmosPressure(sensorP2);
817 //if (sensorP2) delete sensorP2;
819 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
827 //_______________________________________________________________
829 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
835 Int_t nHPEntries = 0;
836 TObjArray *array = 0x0;
839 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
840 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()));
842 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
843 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
844 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
846 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
849 if (array->GetEntries() == 0){
850 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
853 Float_t *floatDCS = ProcessFloatAll(array);
854 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]));
855 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
856 for (Int_t kk = 0 ; kk< 5; kk++){
857 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
865 Log(Form("Hall Probes = %d ", nHPEntries));
869 //_______________________________________________________________
871 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
875 // processing of LHC related DCS DPs, i.e.:
881 Int_t nLHCEntries = 0;
882 TObjArray *array = 0x0;
885 AliInfo(Form("==========LHCState==========="));
887 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
889 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
892 if (array->GetEntries() == 0){
893 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
896 TString stringDCS = ProcessChar(array);
897 if (stringDCS.Length()!=0) {
898 Bool_t found = kFALSE;
899 for( Int_t i=0; i<20; i+=2 ) {
900 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
901 stringDCS = fgkLHCState[i+1];
907 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
908 grpObj->SetLHCState(stringDCS);
911 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
912 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
916 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
917 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
923 if (array) array = 0x0;
925 AliInfo(Form("==========LHCLuminosity==========="));
926 indexDP = kLHCLuminosity;
927 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
929 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
932 if (array->GetEntries() == 0){
933 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
936 Float_t *floatDCS = ProcessFloatAll(array);
937 grpObj->SetLHCLuminosity(floatDCS);
939 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
940 grpObj->SetLHCLuminositySplineFit(splfit);
946 if (array) array = 0x0;
948 AliInfo(Form("==========BeamIntensity==========="));
949 indexDP = kBeamIntensity;
950 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
952 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
955 if (array->GetEntries() == 0){
956 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
959 Float_t *floatDCS = ProcessFloatAll(array);
960 grpObj->SetBeamIntensity(floatDCS);
962 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
963 grpObj->SetBeamIntensitySplineFit(splfit1);
971 //_________________________________________________________________________
973 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
977 // returning Spline Fit
980 Int_t entriesarray = array->GetEntries();
981 Float_t* value = new Float_t[entriesarray];
982 Float_t* time = new Float_t[entriesarray];
983 AliDCSValue* v = 0x0;
984 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
985 v = (AliDCSValue*)array->At(iarray);
986 value[iarray] = v->GetFloat();
987 time[iarray] = v->GetTimeStamp();
988 AliInfo(Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
990 TGraph* gr = new TGraph(entriesarray,value,time);
992 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
995 AliSplineFit *fit = new AliSplineFit();
996 fit->SetMinPoints(10);
997 fit->InitKnots(gr,10,10,0.0);
1001 AliWarning(Form("%s: no fit performed",stringID.Data()));
1007 //_________________________________________________________________________
1009 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1016 TString aDCSString="";
1018 AliDCSValue *v = 0x0;
1019 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1020 v = (AliDCSValue *)array->At(iCount);
1021 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1022 AliError(Form("DCS values for the parameter outside the queried interval"));
1026 if (aDCSString != v->GetChar())
1027 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1029 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1034 //__________________________________________________________________________________________________________________
1036 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1039 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1041 // parameters[0] = mean
1042 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1043 // parameters[2] = median
1044 // parameters[3] = standard deviation wrt mean
1045 // parameters[4] = standard deviation wrt median
1048 Float_t* parameters = new Float_t[5];
1049 Double_t aDCSArrayMean = 0; // Mean
1050 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1051 Double_t aDCSArrayMedian = 0; // Median
1052 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1053 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1054 Float_t aDCSArraySum = 0.0;
1059 Int_t nCounts = array->GetEntries();
1060 Float_t *tempArray = new Float_t[nCounts];
1061 for(Int_t i = 0; i < nCounts; i++) {
1062 AliDCSValue *v = (AliDCSValue *)array->At(i);
1063 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1064 aDCSArraySum += v->GetFloat();
1065 tempArray[i] = v->GetFloat();
1066 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1071 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
1073 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1074 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1075 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1076 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
1077 // computing standard deviation wrt median
1078 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1079 for (Int_t i = 0; i < iCounts; i++){
1080 AliDCSValue *v = (AliDCSValue *)array->At(i);
1081 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1082 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
1083 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
1084 temp1+=v->GetFloat();
1086 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
1088 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1090 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
1092 AliDebug(3,Form("temp after the ratio = %f", temp));
1094 aDCSArraySDMedian = TMath::Sqrt(temp);
1097 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1098 aDCSArraySDMedian = 0;
1101 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
1102 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1106 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1107 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1108 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1110 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
1112 aDCSArrayTruncMean = temp1/iCounts1;
1115 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1120 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1121 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1122 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1123 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1124 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
1126 parameters[0] = aDCSArrayMean;
1127 parameters[1] = aDCSArrayTruncMean;
1128 parameters[2] = aDCSArrayMedian;
1129 parameters[3] = aDCSArraySDMean;
1130 parameters[4] = aDCSArraySDMedian;
1132 // 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]));
1133 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]));
1139 //_______________________________________________________________
1141 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
1144 // processing Boolean values
1147 Bool_t aDCSBool = kTRUE;
1149 AliDCSValue *v = 0x0;
1151 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1152 v = (AliDCSValue *)array->At(iCount);
1153 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1154 AliError(Form("DCS values for the parameter outside the queried interval"));
1158 if (aDCSBool != v->GetBool())
1159 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1161 aDCSBool = v->GetBool(); // always keeping last value
1162 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1165 Char_t caDCSBool = (Char_t) aDCSBool;
1170 //_______________________________________________________________
1172 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1175 // processing Int values, returning mean
1178 Float_t aDCSArraySum = 0.0;
1179 Float_t aDCSArrayMean = 0.0;
1181 AliDCSValue* v = 0x0;
1183 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1184 v = (AliDCSValue *)array->At(iCount);
1185 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1186 aDCSArraySum += v->GetInt();
1191 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1192 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1194 return aDCSArrayMean;
1197 //_______________________________________________________________
1199 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1202 // processing Int values, returning mean
1205 Float_t aDCSArraySum = 0.0;
1206 Float_t aDCSArrayMean = 0.0;
1208 AliDCSValue* v = 0x0;
1210 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1211 v = (AliDCSValue *)array->At(iCount);
1212 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1213 aDCSArraySum += v->GetUInt();
1218 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1219 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1221 return aDCSArrayMean;
1226 //_______________________________________________________________
1228 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1230 // extract DCS pressure maps. Perform fits to save space
1232 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1234 fPressure->MakeSplineFit(map);
1235 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1236 if (fitFraction > kFitFraction ) {
1237 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1239 AliInfo("Too few pressure maps fitted!!!");
1242 AliInfo("no atmospheric pressure map extracted!!!");
1251 //_______________________________________________________________
1252 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)
1255 // Retrieves logbook and trigger information from the online logbook
1256 // This information is needed for prompt reconstruction
1260 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1264 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1265 // 0 on success and no run was found
1266 // negative on error
1268 // This function is NOT called during the preprocessor run in the Shuttle!
1276 AliCDBManager* cdb = AliCDBManager::Instance();
1277 cdb->SetDefaultStorage(cdbRoot);
1280 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1284 Printf("ERROR: Could not connect to DAQ LB");
1290 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1291 TSQLResult* result = server->Query(sqlQuery);
1294 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1298 if (result->GetRowCount() == 0)
1300 Printf("ERROR: Run %d not found", run);
1305 TSQLRow* row = result->Next();
1308 Printf("ERROR: Could not receive data from run %d", run);
1313 TString timeStartString(row->GetField(0));
1314 TString runType(row->GetField(1));
1315 TString detectorMaskString(row->GetField(2));
1316 TString l3CurrentString(row->GetField(3));
1317 TString dipoleCurrentString(row->GetField(4));
1318 time_t timeStart = (time_t)(timeStartString.Atoi());
1319 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1320 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1321 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1323 AliGRPObject * grpObj = new AliGRPObject();
1324 grpObj->SetTimeStart(timeStart);
1325 grpObj->SetRunType((TString)(row->GetField(1)));
1326 grpObj->SetDetectorMask(detectorMask);
1327 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1328 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1336 Printf("Storing GRP/GRP/Data object with the following content");
1339 AliCDBMetaData metadata;
1340 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
1341 metadata.SetComment("GRP Output parameters received during online running");
1343 AliCDBId id("GRP/GRP/Data", run, run);
1344 Bool_t success = cdb->Put(grpObj, id, &metadata);
1350 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1354 // Receive trigger information
1355 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1356 result = server->Query(sqlQuery);
1359 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1363 if (result->GetRowCount() == 0)
1365 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1370 row = result->Next();
1373 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1378 TString triggerConfig(row->GetField(0));
1386 Printf("Found trigger configuration: %s", triggerConfig.Data());
1388 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1391 Printf("ERROR: Could not create CTP configuration object");
1395 metadata.SetComment("CTP run configuration received during online running");
1397 AliCDBId id2("GRP/CTP/Config", run, run);
1398 success = cdb->Put(runcfg, id2, &metadata);
1405 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1409 // get last run with same run type that was already processed by the SHUTTLE
1411 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());
1412 result = server->Query(sqlQuery);
1415 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1419 if (result->GetRowCount() == 0)
1421 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1426 row = result->Next();
1429 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1434 TString lastRunStr(row->GetField(0));
1435 Int_t lastRun = lastRunStr.Atoi();
1437 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);