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!");
312 /* the DCS should not been used any more to access this stuff!!!
313 // ...or from DCS FXS
315 Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS...");
316 TString runcfgfile = GetFile(kDCS, "CTP_runconfig", "");
317 if (runcfgfile.IsNull()) {
318 Log("No CTP runconfig files has been found in DCS FXS!");
322 Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data()));
323 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
325 Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!");
329 TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun);
330 runcfg->SetTitle(titleCTPcfg);
331 AliCDBMetaData metaData;
332 metaData.SetBeamPeriod(0);
333 metaData.SetResponsible("Roman Lietava");
334 metaData.SetComment("CTP run configuration from DCS FXS");
335 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
336 Log("Unable to store the CTP run configuration object to OCDB!");
344 md.SetResponsible("Ernesto Lopez Torres");
345 md.SetComment("Output parameters from the GRP preprocessor.");
347 Bool_t result = kTRUE;
348 Log("Before storing");
349 result = Store("GRP", "Data", grpobj, &md);
352 if (result && !error ) {
353 Log("GRP Preprocessor Success");
356 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s",
357 kppError[(error&1)?1:0],
358 kppError[(error&2)?2:0],
359 kppError[(error&4)?3:0],
360 kppError[(error&8)?4:0],
361 kppError[(error&16)?5:0]
367 //_______________________________________________________________
369 AliGRPObject* AliGRPPreprocessor::ProcessDaqLB()
371 //Getting the DAQ lb information
373 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
374 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
375 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
376 TString beamType = (TString)GetRunParameter("beamType");
377 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
378 UInt_t detectorMask= (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
379 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
380 TString runType = (TString)GetRunType();
382 AliGRPObject* grpObj = new AliGRPObject();
385 grpObj->SetTimeStart(timeStart);
386 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
389 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
393 grpObj->SetTimeEnd(timeEnd);
394 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
397 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
400 if (beamEnergy != 0){
401 grpObj->SetBeamEnergy(beamEnergy);
402 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
405 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry!"));
408 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
410 if (beamType.Length() != 0){
411 grpObj->SetBeamType(beamType);
412 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
415 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
418 if (numberOfDetectors != 0){
419 grpObj->SetNumberOfDetectors(numberOfDetectors);
420 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
423 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
426 if (detectorMask != 0){
427 grpObj->SetDetectorMask(detectorMask);
428 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
431 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
434 if (lhcPeriod.Length() != 0) {
435 grpObj->SetLHCPeriod(lhcPeriod);
436 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
438 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
440 if (runType.Length() != 0) {
441 grpObj->SetRunType(runType);
442 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
444 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
450 //_______________________________________________________________
452 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
454 //======DAQ FXS======//
456 TList* list = GetFileSources(kDAQ);
458 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
462 if (list->GetEntries() == 0) {
463 Log("no raw data tags in this run: nothing to merge!");
468 TChain *fRawTagChain = new TChain("T");
470 TIterator* iter = list->MakeIterator();
472 while ((obj = iter->Next())) {
473 TObjString* objStr = dynamic_cast<TObjString*> (obj);
475 Log(Form("Found source %s", objStr->String().Data()));
476 TList* list2 = GetFileIDs(kDAQ, objStr->String());
478 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
479 delete fRawTagChain; fRawTagChain=0;
482 Log(Form("Number of ids: %d",list2->GetEntries()));
483 for(Int_t i = 0; i < list2->GetEntries(); i++) {
484 TObjString *idStr = (TObjString *)list2->At(i);
485 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
486 if (fileName.Length() > 0) {
487 Log(Form("Adding file in the chain: %s",fileName.Data()));
488 fRawTagChain->Add(fileName.Data());
491 Log(Form("Could not retrieve file with id %s from source %s: "
492 "connection problems with DAQ FXS!",
493 idStr->String().Data(), objStr->String().Data()));
495 delete list2; list2=0;
496 delete fRawTagChain; fRawTagChain=0;
504 TString fRawDataFileName = "GRP_Merged.tag.root";
505 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
507 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
508 Log("Error merging raw data files!!!");
512 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
513 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
516 Log("Problem storing raw data tags in local file!!!");
518 Log("Raw data tags merged successfully!!");
523 delete fRawTagChain; fRawTagChain=0;
525 if (result == kFALSE) {
533 //_______________________________________________________________
534 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
537 // processing the info
538 // stored in the DCS FXS
539 // coming from the trigger
542 // Get the CTP counters information
543 TList* list = GetFileSources(kDCS,"CTP_xcounters");
545 Log("No CTP counters file: connection problems with DCS FXS logbook!");
549 if (list->GetEntries() == 0) {
550 Log("No CTP counters file to be processed!");
556 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
557 TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
558 if (countersfile.IsNull()) {
559 Log("No CTP counters files has been found: empty source!");
562 Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
563 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
565 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
569 AliCDBMetaData metaData;
570 metaData.SetBeamPeriod(0);
571 metaData.SetResponsible("Roman Lietava");
572 metaData.SetComment("CTP scalers");
573 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
574 Log("Unable to store the CTP scalers object to OCDB!");
585 //_______________________________________________________________
587 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
591 // processing DCS DPs
594 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
595 Int_t nLHCEntries = 0;
596 Int_t nL3Entries = 0;
597 Int_t nDipoleEntries = 0;
598 Int_t nEnvEntries = 0;
599 Int_t nHallProbesEntries = 0;
600 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
601 nL3Entries = ProcessL3DPs(valueMap, grpObj);
602 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
603 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
604 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
606 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
611 //_______________________________________________________________
613 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
620 Int_t nL3Entries = 0;
621 TObjArray *array = 0x0;
624 AliInfo(Form("==========L3Polarity==========="));
625 indexDP = kL3Polarity;
626 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
628 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
631 if (array->GetEntries() == 0){
632 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
635 Char_t charDCS = ProcessBool(array);
636 grpObj->SetL3Polarity(charDCS);
637 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
642 if (array) array = 0x0;
644 AliInfo(Form("==========L3Current==========="));
645 indexDP = kL3Current;
646 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
648 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
651 if (array->GetEntries() == 0){
652 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
655 Float_t *floatDCS = ProcessFloatAll(array);
656 grpObj->SetL3Current(floatDCS);
665 //_______________________________________________________________
667 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
673 Int_t nDipoleEntries = 0;
674 TObjArray *array = 0x0;
677 AliInfo(Form("==========DipolePolarity==========="));
678 indexDP = kDipolePolarity;
679 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
681 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
684 if (array->GetEntries() == 0){
685 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
688 Char_t charDCS = ProcessBool(array);
689 grpObj->SetDipolePolarity(charDCS);
690 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
695 if (array) array = 0x0;
697 AliInfo(Form("==========DipoleCurrent==========="));
698 indexDP = kDipoleCurrent;
699 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
701 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
704 if (array->GetEntries() == 0){
705 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
708 Float_t *floatDCS = ProcessFloatAll(array);
709 grpObj->SetDipoleCurrent(floatDCS);
715 return nDipoleEntries;
718 //_______________________________________________________________
720 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
724 // evironment conditions (temperature, pressure) info
726 Int_t nEnvEntries = 0;
727 TObjArray *array = 0x0;
730 AliInfo(Form("==========CavernTemperature==========="));
731 indexDP = kCavernTemperature;
732 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
734 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
737 if (array->GetEntries() == 0){
738 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
741 Float_t *floatDCS = ProcessFloatAll(array);
742 grpObj->SetCavernTemperature(floatDCS);
748 if (array) array = 0x0;
750 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
751 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
752 dcsSensorArray->Print();
753 if( fPressure->NumFits()==0 ) {
754 Log("Problem with the pressure sensor values!!!");
757 AliInfo(Form("==========CavernAtmosPressure==========="));
758 indexDP = kCavernAtmosPressure;
759 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
760 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
761 if( sensorCavernP2->GetFit() ) {
762 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
763 grpObj->SetCavernAtmosPressure(sensorCavernP2);
766 //if (sensorP2) delete sensorP2;
768 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
770 AliInfo(Form("==========SurfaceAtmosPressure==========="));
771 indexDP = kSurfaceAtmosPressure;
772 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
773 AliDebug(2,Form("sensorP2 = %p", sensorP2));
774 if( sensorP2->GetFit() ) {
775 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
776 grpObj->SetSurfaceAtmosPressure(sensorP2);
779 //if (sensorP2) delete sensorP2;
781 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
786 /* indexDP = kCavernAtmosPressure;
787 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
789 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
792 Float_t *floatDCS = ProcessFloatAll(array);
793 grpObj->SetCavernAtmosPressure(floatDCS);
799 if (array) array = 0x0;
801 AliInfo(Form("==========SurfaceAtmosPressure==========="));
802 indexDP = kSurfaceAtmosPressure;
803 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
804 dcsSensorArray->Print();
805 AliInfo(Form("fPressure = %p",fPressure));
806 AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
807 if( fPressure->NumFits()==0 ) {
808 Log("Problem with the pressure sensor values!!!");
811 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
812 AliDebug(2,Form("sensorP2 = %p", sensorP2));
813 if( sensorP2->GetFit() ) {
814 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
815 grpObj->SetSurfaceAtmosPressure(sensorP2);
818 //if (sensorP2) delete sensorP2;
820 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
828 //_______________________________________________________________
830 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
836 Int_t nHPEntries = 0;
837 TObjArray *array = 0x0;
840 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
841 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()));
843 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
844 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
845 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
847 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
850 if (array->GetEntries() == 0){
851 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
854 Float_t *floatDCS = ProcessFloatAll(array);
855 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]));
856 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
857 for (Int_t kk = 0 ; kk< 5; kk++){
858 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
866 Log(Form("Hall Probes = %d ", nHPEntries));
870 //_______________________________________________________________
872 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
876 // processing of LHC related DCS DPs, i.e.:
882 Int_t nLHCEntries = 0;
883 TObjArray *array = 0x0;
886 AliInfo(Form("==========LHCState==========="));
888 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
890 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
893 if (array->GetEntries() == 0){
894 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
897 TString stringDCS = ProcessChar(array);
898 if (stringDCS.Length()!=0) {
899 Bool_t found = kFALSE;
900 for( Int_t i=0; i<20; i+=2 ) {
901 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
902 stringDCS = fgkLHCState[i+1];
908 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
909 grpObj->SetLHCState(stringDCS);
912 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
913 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
917 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
918 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
924 if (array) array = 0x0;
926 AliInfo(Form("==========LHCLuminosity==========="));
927 indexDP = kLHCLuminosity;
928 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
930 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
933 if (array->GetEntries() == 0){
934 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
937 Float_t *floatDCS = ProcessFloatAll(array);
938 grpObj->SetLHCLuminosity(floatDCS);
940 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
941 grpObj->SetLHCLuminositySplineFit(splfit);
947 if (array) array = 0x0;
949 AliInfo(Form("==========BeamIntensity==========="));
950 indexDP = kBeamIntensity;
951 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
953 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
956 if (array->GetEntries() == 0){
957 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
960 Float_t *floatDCS = ProcessFloatAll(array);
961 grpObj->SetBeamIntensity(floatDCS);
963 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
964 grpObj->SetBeamIntensitySplineFit(splfit1);
972 //_________________________________________________________________________
974 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
978 // returning Spline Fit
981 Int_t entriesarray = array->GetEntries();
982 Float_t* value = new Float_t[entriesarray];
983 Float_t* time = new Float_t[entriesarray];
984 AliDCSValue* v = 0x0;
985 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
986 v = (AliDCSValue*)array->At(iarray);
987 value[iarray] = v->GetFloat();
988 time[iarray] = v->GetTimeStamp();
989 AliInfo(Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
991 TGraph* gr = new TGraph(entriesarray,value,time);
993 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
996 AliSplineFit *fit = new AliSplineFit();
997 fit->SetMinPoints(10);
998 fit->InitKnots(gr,10,10,0.0);
1002 AliWarning(Form("%s: no fit performed",stringID.Data()));
1008 //_________________________________________________________________________
1010 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1017 TString aDCSString="";
1019 AliDCSValue *v = 0x0;
1020 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1021 v = (AliDCSValue *)array->At(iCount);
1022 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1023 AliError(Form("DCS values for the parameter outside the queried interval"));
1027 if (aDCSString != v->GetChar())
1028 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1030 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1035 //__________________________________________________________________________________________________________________
1037 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1040 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1042 // parameters[0] = mean
1043 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1044 // parameters[2] = median
1045 // parameters[3] = standard deviation wrt mean
1046 // parameters[4] = standard deviation wrt median
1049 Float_t* parameters = new Float_t[5];
1050 Double_t aDCSArrayMean = 0; // Mean
1051 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1052 Double_t aDCSArrayMedian = 0; // Median
1053 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1054 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1055 Float_t aDCSArraySum = 0.0;
1060 Int_t nCounts = array->GetEntries();
1061 Float_t *tempArray = new Float_t[nCounts];
1062 for(Int_t i = 0; i < nCounts; i++) {
1063 AliDCSValue *v = (AliDCSValue *)array->At(i);
1064 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1065 aDCSArraySum += v->GetFloat();
1066 tempArray[i] = v->GetFloat();
1067 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1072 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
1074 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1075 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1076 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1077 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
1078 // computing standard deviation wrt median
1079 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1080 for (Int_t i = 0; i < iCounts; i++){
1081 AliDCSValue *v = (AliDCSValue *)array->At(i);
1082 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1083 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
1084 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
1085 temp1+=v->GetFloat();
1087 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
1089 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1091 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
1093 AliDebug(3,Form("temp after the ratio = %f", temp));
1095 aDCSArraySDMedian = TMath::Sqrt(temp);
1098 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1099 aDCSArraySDMedian = 0;
1102 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
1103 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1107 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1108 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1109 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1111 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
1113 aDCSArrayTruncMean = temp1/iCounts1;
1116 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1121 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1122 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1123 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1124 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1125 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
1127 parameters[0] = aDCSArrayMean;
1128 parameters[1] = aDCSArrayTruncMean;
1129 parameters[2] = aDCSArrayMedian;
1130 parameters[3] = aDCSArraySDMean;
1131 parameters[4] = aDCSArraySDMedian;
1133 // 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]));
1134 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]));
1140 //_______________________________________________________________
1142 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
1145 // processing Boolean values
1148 Bool_t aDCSBool = kTRUE;
1150 AliDCSValue *v = 0x0;
1152 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1153 v = (AliDCSValue *)array->At(iCount);
1154 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1155 AliError(Form("DCS values for the parameter outside the queried interval"));
1159 if (aDCSBool != v->GetBool())
1160 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1162 aDCSBool = v->GetBool(); // always keeping last value
1163 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1166 Char_t caDCSBool = (Char_t) aDCSBool;
1171 //_______________________________________________________________
1173 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1176 // processing Int values, returning mean
1179 Float_t aDCSArraySum = 0.0;
1180 Float_t aDCSArrayMean = 0.0;
1182 AliDCSValue* v = 0x0;
1184 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1185 v = (AliDCSValue *)array->At(iCount);
1186 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1187 aDCSArraySum += v->GetInt();
1192 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1193 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1195 return aDCSArrayMean;
1198 //_______________________________________________________________
1200 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1203 // processing Int values, returning mean
1206 Float_t aDCSArraySum = 0.0;
1207 Float_t aDCSArrayMean = 0.0;
1209 AliDCSValue* v = 0x0;
1211 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1212 v = (AliDCSValue *)array->At(iCount);
1213 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1214 aDCSArraySum += v->GetUInt();
1219 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1220 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1222 return aDCSArrayMean;
1227 //_______________________________________________________________
1229 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1231 // extract DCS pressure maps. Perform fits to save space
1233 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1235 fPressure->MakeSplineFit(map);
1236 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1237 if (fitFraction > kFitFraction ) {
1238 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1240 AliInfo("Too few pressure maps fitted!!!");
1243 AliInfo("no atmospheric pressure map extracted!!!");
1252 //_______________________________________________________________
1253 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)
1256 // Retrieves logbook and trigger information from the online logbook
1257 // This information is needed for prompt reconstruction
1261 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1265 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1266 // 0 on success and no run was found
1267 // negative on error
1269 // This function is NOT called during the preprocessor run in the Shuttle!
1277 AliCDBManager* cdb = AliCDBManager::Instance();
1278 cdb->SetDefaultStorage(cdbRoot);
1281 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1285 Printf("ERROR: Could not connect to DAQ LB");
1291 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1292 TSQLResult* result = server->Query(sqlQuery);
1295 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1299 if (result->GetRowCount() == 0)
1301 Printf("ERROR: Run %d not found", run);
1306 TSQLRow* row = result->Next();
1309 Printf("ERROR: Could not receive data from run %d", run);
1314 TString timeStartString(row->GetField(0));
1315 TString runType(row->GetField(1));
1316 TString detectorMaskString(row->GetField(2));
1317 TString l3CurrentString(row->GetField(3));
1318 TString dipoleCurrentString(row->GetField(4));
1319 time_t timeStart = (time_t)(timeStartString.Atoi());
1320 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1321 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1322 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1324 AliGRPObject * grpObj = new AliGRPObject();
1325 grpObj->SetTimeStart(timeStart);
1326 grpObj->SetRunType((TString)(row->GetField(1)));
1327 grpObj->SetDetectorMask(detectorMask);
1328 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1329 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1337 Printf("Storing GRP/GRP/Data object with the following content");
1340 AliCDBMetaData metadata;
1341 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
1342 metadata.SetComment("GRP Output parameters received during online running");
1344 AliCDBId id("GRP/GRP/Data", run, run);
1345 Bool_t success = cdb->Put(grpObj, id, &metadata);
1351 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1355 // Receive trigger information
1356 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1357 result = server->Query(sqlQuery);
1360 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1364 if (result->GetRowCount() == 0)
1366 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1371 row = result->Next();
1374 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1379 TString triggerConfig(row->GetField(0));
1387 Printf("Found trigger configuration: %s", triggerConfig.Data());
1389 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1392 Printf("ERROR: Could not create CTP configuration object");
1396 metadata.SetComment("CTP run configuration received during online running");
1398 AliCDBId id2("GRP/CTP/Config", run, run);
1399 success = cdb->Put(runcfg, id2, &metadata);
1406 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1410 // get last run with same run type that was already processed by the SHUTTLE
1412 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());
1413 result = server->Query(sqlQuery);
1416 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1420 if (result->GetRowCount() == 0)
1422 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1427 row = result->Next();
1430 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1435 TString lastRunStr(row->GetField(0));
1436 Int_t lastRun = lastRunStr.Atoi();
1438 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);