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");
198 //_______________________________________________________________
200 AliGRPPreprocessor::~AliGRPPreprocessor()
207 //_______________________________________________________________
209 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
211 // Initialize preprocessor
213 AliPreprocessor::Initialize(run, startTime, endTime);
215 AliInfo("Initialization of the GRP preprocessor.");
216 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
217 for(Int_t j = 0; j < kNumSensors; j++) {
218 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
219 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
221 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
223 // fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
224 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
227 //_______________________________________________________________
229 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
231 // process data retrieved by the Shuttle
233 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
235 //=================//
237 //=================//
240 grpobj = ProcessDaqLB();
242 //=================//
244 //=================//
245 UInt_t iDaqFxs = ProcessDaqFxs();
247 Log(Form("DAQ FXS, successful!"));
249 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
253 //=================//
255 //=================//
256 UInt_t iDcsFxs = ProcessDcsFxs();
258 Log(Form("DCS FXS, successful!"));
260 Log(Form("DCS FXS, Could not store CTP run configuration and scalers!!!"));
264 //=================//
265 // DCS data points //
266 //=================//
267 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
268 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
269 Log(Form("entries found = %d",entries));
270 if( entries < fgknDCSDP-7 ) { // FIXME (!= ) LHState and pressure map are not working yet... and removing the 4 values for the missing HP
271 Log(Form("Problem with the DCS data points!!!"));
273 } else Log(Form("DCS data points, successful!"));
275 //=======================//
276 // Trigger Configuration //
277 //=======================//
278 // either from DAQ logbook.....
279 const char * triggerConf = GetTriggerConfiguration();
280 if (triggerConf!= NULL) {
281 Log("Found trigger configuration in DAQ logbook");
282 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
284 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
288 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
289 runcfg->SetTitle(titleCTPcfg);
290 AliCDBMetaData metaData;
291 metaData.SetBeamPeriod(0);
292 metaData.SetResponsible("Roman Lietava");
293 metaData.SetComment("CTP run configuration from DAQ logbook");
294 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
295 Log("Unable to store the CTP run configuration object to OCDB!");
300 /* the DCS should not been used any more to access this stuff!!!
301 // ...or from DCS FXS
303 Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS...");
304 TString runcfgfile = GetFile(kDCS, "CTP_runconfig", "");
305 if (runcfgfile.IsNull()) {
306 Log("No CTP runconfig files has been found in DCS FXS!");
310 Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data()));
311 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
313 Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!");
317 TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun);
318 runcfg->SetTitle(titleCTPcfg);
319 AliCDBMetaData metaData;
320 metaData.SetBeamPeriod(0);
321 metaData.SetResponsible("Roman Lietava");
322 metaData.SetComment("CTP run configuration from DCS FXS");
323 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
324 Log("Unable to store the CTP run configuration object to OCDB!");
332 md.SetResponsible("Ernesto Lopez Torres");
333 md.SetComment("Output parameters from the GRP preprocessor.");
335 Bool_t result = kTRUE;
336 Log("Before storing");
337 result = Store("GRP", "Data", grpobj, &md);
340 if (result && !error ) {
341 Log("GRP Preprocessor Success");
344 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s",
345 kppError[(error&1)?1:0],
346 kppError[(error&2)?2:0],
347 kppError[(error&4)?3:0],
348 kppError[(error&8)?4:0],
349 kppError[(error&16)?5:0]
355 //_______________________________________________________________
357 AliGRPObject* AliGRPPreprocessor::ProcessDaqLB()
359 //Getting the DAQ lb information
361 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
362 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
363 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
364 TString beamType = (TString)GetRunParameter("beamType");
365 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
366 UInt_t detectorMask= (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
367 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
368 TString runType = (TString)GetRunType();
370 AliGRPObject* grpObj = new AliGRPObject();
373 grpObj->SetTimeStart(timeStart);
374 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
377 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
381 grpObj->SetTimeEnd(timeEnd);
382 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
385 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
388 if (beamEnergy != 0){
389 grpObj->SetBeamEnergy(beamEnergy);
390 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
393 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry!"));
396 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
398 if (beamType.Length() != 0){
399 grpObj->SetBeamType(beamType);
400 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
403 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
406 if (numberOfDetectors != 0){
407 grpObj->SetNumberOfDetectors(numberOfDetectors);
408 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
411 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
414 if (detectorMask != 0){
415 grpObj->SetDetectorMask(detectorMask);
416 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
419 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
422 if (lhcPeriod.Length() != 0) {
423 grpObj->SetLHCPeriod(lhcPeriod);
424 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
426 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
428 if (runType.Length() != 0) {
429 grpObj->SetRunType(runType);
430 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
432 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
438 //_______________________________________________________________
440 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
442 //======DAQ FXS======//
444 TList* list = GetFileSources(kDAQ);
446 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
450 if (list->GetEntries() == 0) {
451 Log("no raw data tags in this run: nothing to merge!");
456 TChain *fRawTagChain = new TChain("T");
458 TIterator* iter = list->MakeIterator();
460 while ((obj = iter->Next())) {
461 TObjString* objStr = dynamic_cast<TObjString*> (obj);
463 Log(Form("Found source %s", objStr->String().Data()));
464 TList* list2 = GetFileIDs(kDAQ, objStr->String());
466 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
467 delete fRawTagChain; fRawTagChain=0;
470 Log(Form("Number of ids: %d",list2->GetEntries()));
471 for(Int_t i = 0; i < list2->GetEntries(); i++) {
472 TObjString *idStr = (TObjString *)list2->At(i);
473 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
474 if (fileName.Length() > 0) {
475 Log(Form("Adding file in the chain: %s",fileName.Data()));
476 fRawTagChain->Add(fileName.Data());
479 Log(Form("Could not retrieve file with id %s from source %s: "
480 "connection problems with DAQ FXS!",
481 idStr->String().Data(), objStr->String().Data()));
483 delete list2; list2=0;
484 delete fRawTagChain; fRawTagChain=0;
492 TString fRawDataFileName = "GRP_Merged.tag.root";
493 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
495 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
496 Log("Error merging raw data files!!!");
500 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
501 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
504 Log("Problem storing raw data tags in local file!!!");
506 Log("Raw data tags merged successfully!!");
511 delete fRawTagChain; fRawTagChain=0;
513 if (result == kFALSE) {
521 //_______________________________________________________________
522 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
525 // processing the info
526 // stored in the DCS FXS
527 // coming from the trigger
530 // Get the CTP counters information
531 TList* list = GetFileSources(kDCS,"CTP_xcounters");
533 Log("No CTP counters file: connection problems with DAQ FXS logbook!");
537 if (list->GetEntries() == 0) {
538 Log("No CTP counters file to be processed!");
544 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
545 TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
546 if (countersfile.IsNull()) {
547 Log("No CTP counters files has been found: empty source!");
550 Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
551 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
553 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
557 AliCDBMetaData metaData;
558 metaData.SetBeamPeriod(0);
559 metaData.SetResponsible("Roman Lietava");
560 metaData.SetComment("CTP scalers");
561 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
562 Log("Unable to store the CTP scalers object to OCDB!");
573 //_______________________________________________________________
575 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
579 // processing DCS DPs
582 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
583 Int_t nLHCEntries = 0;
584 Int_t nL3Entries = 0;
585 Int_t nDipoleEntries = 0;
586 Int_t nEnvEntries = 0;
587 Int_t nHallProbesEntries = 0;
588 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
589 nL3Entries = ProcessL3DPs(valueMap, grpObj);
590 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
591 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
592 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
594 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
599 //_______________________________________________________________
601 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
608 Int_t nL3Entries = 0;
609 TObjArray *array = 0x0;
612 AliInfo(Form("==========L3Polarity==========="));
613 indexDP = kL3Polarity;
614 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
616 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
619 if (array->GetEntries() == 0){
620 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
623 Char_t charDCS = ProcessBool(array);
624 grpObj->SetL3Polarity(charDCS);
625 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
630 if (array) array = 0x0;
632 AliInfo(Form("==========L3Current==========="));
633 indexDP = kL3Current;
634 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
636 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
639 if (array->GetEntries() == 0){
640 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
643 Float_t *floatDCS = ProcessFloatAll(array);
644 grpObj->SetL3Current(floatDCS);
653 //_______________________________________________________________
655 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
661 Int_t nDipoleEntries = 0;
662 TObjArray *array = 0x0;
665 AliInfo(Form("==========DipolePolarity==========="));
666 indexDP = kDipolePolarity;
667 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
669 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
672 if (array->GetEntries() == 0){
673 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
676 Char_t charDCS = ProcessBool(array);
677 grpObj->SetDipolePolarity(charDCS);
678 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
683 if (array) array = 0x0;
685 AliInfo(Form("==========DipoleCurrent==========="));
686 indexDP = kDipoleCurrent;
687 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
689 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
692 if (array->GetEntries() == 0){
693 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
696 Float_t *floatDCS = ProcessFloatAll(array);
697 grpObj->SetDipoleCurrent(floatDCS);
703 return nDipoleEntries;
706 //_______________________________________________________________
708 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
712 // evironment conditions (temperature, pressure) info
714 Int_t nEnvEntries = 0;
715 TObjArray *array = 0x0;
718 AliInfo(Form("==========CavernTemperature==========="));
719 indexDP = kCavernTemperature;
720 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
722 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
725 if (array->GetEntries() == 0){
726 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
729 Float_t *floatDCS = ProcessFloatAll(array);
730 grpObj->SetCavernTemperature(floatDCS);
736 if (array) array = 0x0;
738 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
739 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
740 dcsSensorArray->Print();
741 if( fPressure->NumFits()==0 ) {
742 Log("Problem with the pressure sensor values!!!");
745 AliInfo(Form("==========CavernAtmosPressure==========="));
746 indexDP = kCavernAtmosPressure;
747 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
748 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
749 if( sensorCavernP2->GetFit() ) {
750 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
751 grpObj->SetCavernAtmosPressure(sensorCavernP2);
754 //if (sensorP2) delete sensorP2;
756 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
758 AliInfo(Form("==========SurfaceAtmosPressure==========="));
759 indexDP = kSurfaceAtmosPressure;
760 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
761 AliDebug(2,Form("sensorP2 = %p", sensorP2));
762 if( sensorP2->GetFit() ) {
763 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
764 grpObj->SetSurfaceAtmosPressure(sensorP2);
767 //if (sensorP2) delete sensorP2;
769 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
774 /* indexDP = kCavernAtmosPressure;
775 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
777 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
780 Float_t *floatDCS = ProcessFloatAll(array);
781 grpObj->SetCavernAtmosPressure(floatDCS);
787 if (array) array = 0x0;
789 AliInfo(Form("==========SurfaceAtmosPressure==========="));
790 indexDP = kSurfaceAtmosPressure;
791 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
792 dcsSensorArray->Print();
793 AliInfo(Form("fPressure = %p",fPressure));
794 AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
795 if( fPressure->NumFits()==0 ) {
796 Log("Problem with the pressure sensor values!!!");
799 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
800 AliDebug(2,Form("sensorP2 = %p", sensorP2));
801 if( sensorP2->GetFit() ) {
802 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
803 grpObj->SetSurfaceAtmosPressure(sensorP2);
806 //if (sensorP2) delete sensorP2;
808 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
816 //_______________________________________________________________
818 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
824 Int_t nHPEntries = 0;
825 TObjArray *array = 0x0;
828 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
829 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()));
831 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
832 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
833 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
835 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
838 if (array->GetEntries() == 0){
839 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
842 Float_t *floatDCS = ProcessFloatAll(array);
843 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]));
844 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
845 for (Int_t kk = 0 ; kk< 5; kk++){
846 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
854 Log(Form("Hall Probes = %d ", nHPEntries));
858 //_______________________________________________________________
860 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
864 // processing of LHC related DCS DPs, i.e.:
870 Int_t nLHCEntries = 0;
871 TObjArray *array = 0x0;
874 AliInfo(Form("==========LHCState==========="));
876 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
878 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
881 if (array->GetEntries() == 0){
882 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
885 TString stringDCS = ProcessChar(array);
886 if (stringDCS.Length()!=0) {
887 Bool_t found = kFALSE;
888 for( Int_t i=0; i<20; i+=2 ) {
889 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
890 stringDCS = fgkLHCState[i+1];
896 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
897 grpObj->SetLHCState(stringDCS);
900 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
901 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
905 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
906 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
912 if (array) array = 0x0;
914 AliInfo(Form("==========LHCLuminosity==========="));
915 indexDP = kLHCLuminosity;
916 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
918 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
921 if (array->GetEntries() == 0){
922 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
925 Float_t *floatDCS = ProcessFloatAll(array);
926 grpObj->SetLHCLuminosity(floatDCS);
928 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
929 grpObj->SetLHCLuminositySplineFit(splfit);
935 if (array) array = 0x0;
937 AliInfo(Form("==========BeamIntensity==========="));
938 indexDP = kBeamIntensity;
939 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
941 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
944 if (array->GetEntries() == 0){
945 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
948 Float_t *floatDCS = ProcessFloatAll(array);
949 grpObj->SetBeamIntensity(floatDCS);
951 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
952 grpObj->SetBeamIntensitySplineFit(splfit1);
960 //_________________________________________________________________________
962 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
966 // returning Spline Fit
969 Int_t entriesarray = array->GetEntries();
970 Float_t* value = new Float_t[entriesarray];
971 Float_t* time = new Float_t[entriesarray];
972 AliDCSValue* v = 0x0;
973 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
974 v = (AliDCSValue*)array->At(iarray);
975 value[iarray] = v->GetFloat();
976 time[iarray] = v->GetTimeStamp();
977 AliInfo(Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
979 TGraph* gr = new TGraph(entriesarray,value,time);
981 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
984 AliSplineFit *fit = new AliSplineFit();
985 fit->SetMinPoints(10);
986 fit->InitKnots(gr,10,10,0.0);
990 AliWarning(Form("%s: no fit performed",stringID.Data()));
996 //_________________________________________________________________________
998 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1005 TString aDCSString="";
1007 AliDCSValue *v = 0x0;
1008 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1009 v = (AliDCSValue *)array->At(iCount);
1010 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1011 AliError(Form("DCS values for the parameter outside the queried interval"));
1015 if (aDCSString != v->GetChar())
1016 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1018 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1023 //__________________________________________________________________________________________________________________
1025 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1028 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1030 // parameters[0] = mean
1031 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1032 // parameters[2] = median
1033 // parameters[3] = standard deviation wrt mean
1034 // parameters[4] = standard deviation wrt median
1037 Float_t* parameters = new Float_t[5];
1038 Double_t aDCSArrayMean = 0; // Mean
1039 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1040 Double_t aDCSArrayMedian = 0; // Median
1041 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1042 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1043 Float_t aDCSArraySum = 0.0;
1048 Int_t nCounts = array->GetEntries();
1049 Float_t *tempArray = new Float_t[nCounts];
1050 for(Int_t i = 0; i < nCounts; i++) {
1051 AliDCSValue *v = (AliDCSValue *)array->At(i);
1052 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1053 aDCSArraySum += v->GetFloat();
1054 tempArray[i] = v->GetFloat();
1055 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1060 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
1062 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1063 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1064 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1065 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
1066 // computing standard deviation wrt median
1067 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1068 for (Int_t i = 0; i < iCounts; i++){
1069 AliDCSValue *v = (AliDCSValue *)array->At(i);
1070 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1071 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
1072 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
1073 temp1+=v->GetFloat();
1075 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
1077 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1079 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
1081 AliDebug(3,Form("temp after the ratio = %f", temp));
1083 aDCSArraySDMedian = TMath::Sqrt(temp);
1086 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1087 aDCSArraySDMedian = 0;
1090 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
1091 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1095 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1096 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1097 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1099 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
1101 aDCSArrayTruncMean = temp1/iCounts1;
1104 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1109 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1110 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1111 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1112 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1113 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
1115 parameters[0] = aDCSArrayMean;
1116 parameters[1] = aDCSArrayTruncMean;
1117 parameters[2] = aDCSArrayMedian;
1118 parameters[3] = aDCSArraySDMean;
1119 parameters[4] = aDCSArraySDMedian;
1121 // 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]));
1122 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]));
1128 //_______________________________________________________________
1130 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
1133 // processing Boolean values
1136 Bool_t aDCSBool = kTRUE;
1138 AliDCSValue *v = 0x0;
1140 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1141 v = (AliDCSValue *)array->At(iCount);
1142 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1143 AliError(Form("DCS values for the parameter outside the queried interval"));
1147 if (aDCSBool != v->GetBool())
1148 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1150 aDCSBool = v->GetBool(); // always keeping last value
1151 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1154 Char_t caDCSBool = (Char_t) aDCSBool;
1159 //_______________________________________________________________
1161 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1164 // processing Int values, returning mean
1167 Float_t aDCSArraySum = 0.0;
1168 Float_t aDCSArrayMean = 0.0;
1170 AliDCSValue* v = 0x0;
1172 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1173 v = (AliDCSValue *)array->At(iCount);
1174 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1175 aDCSArraySum += v->GetInt();
1180 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1181 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1183 return aDCSArrayMean;
1186 //_______________________________________________________________
1188 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1191 // processing Int values, returning mean
1194 Float_t aDCSArraySum = 0.0;
1195 Float_t aDCSArrayMean = 0.0;
1197 AliDCSValue* v = 0x0;
1199 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1200 v = (AliDCSValue *)array->At(iCount);
1201 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1202 aDCSArraySum += v->GetUInt();
1207 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1208 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1210 return aDCSArrayMean;
1215 //_______________________________________________________________
1217 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
1219 // extract DCS pressure maps. Perform fits to save space
1221 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1223 fPressure->MakeSplineFit(map);
1224 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1225 if (fitFraction > kFitFraction ) {
1226 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1228 AliInfo("Too few pressure maps fitted!!!");
1231 AliInfo("no atmospheric pressure map extracted!!!");
1240 //_______________________________________________________________
1241 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)
1244 // Retrieves logbook and trigger information from the online logbook
1245 // This information is needed for prompt reconstruction
1249 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1253 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1254 // 0 on success and no run was found
1255 // negative on error
1257 // This function is NOT called during the preprocessor run in the Shuttle!
1265 AliCDBManager* cdb = AliCDBManager::Instance();
1266 cdb->SetDefaultStorage(cdbRoot);
1269 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1273 Printf("ERROR: Could not connect to DAQ LB");
1279 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
1280 TSQLResult* result = server->Query(sqlQuery);
1283 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1287 if (result->GetRowCount() == 0)
1289 Printf("ERROR: Run %d not found", run);
1294 TSQLRow* row = result->Next();
1297 Printf("ERROR: Could not receive data from run %d", run);
1302 TString timeStartString(row->GetField(0));
1303 TString runType(row->GetField(1));
1304 TString detectorMaskString(row->GetField(2));
1305 TString l3CurrentString(row->GetField(3));
1306 TString dipoleCurrentString(row->GetField(4));
1307 time_t timeStart = (time_t)(timeStartString.Atoi());
1308 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1309 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1310 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
1312 AliGRPObject * grpObj = new AliGRPObject();
1313 grpObj->SetTimeStart(timeStart);
1314 grpObj->SetRunType((TString)(row->GetField(1)));
1315 grpObj->SetDetectorMask(detectorMask);
1316 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1317 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1325 Printf("Storing GRP/GRP/Data object with the following content");
1328 AliCDBMetaData metadata;
1329 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
1330 metadata.SetComment("GRP Output parameters received during online running");
1332 AliCDBId id("GRP/GRP/Data", run, run);
1333 Bool_t success = cdb->Put(grpObj, id, &metadata);
1339 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1343 // Receive trigger information
1344 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1345 result = server->Query(sqlQuery);
1348 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1352 if (result->GetRowCount() == 0)
1354 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1359 row = result->Next();
1362 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1367 TString triggerConfig(row->GetField(0));
1375 Printf("Found trigger configuration: %s", triggerConfig.Data());
1377 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1380 Printf("ERROR: Could not create CTP configuration object");
1384 metadata.SetComment("CTP run configuration received during online running");
1386 AliCDBId id2("GRP/CTP/Config", run, run);
1387 success = cdb->Put(runcfg, id2, &metadata);
1394 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1398 // get last run with same run type that was already processed by the SHUTTLE
1400 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());
1401 result = server->Query(sqlQuery);
1404 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1408 if (result->GetRowCount() == 0)
1410 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1415 row = result->Next();
1418 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1423 TString lastRunStr(row->GetField(0));
1424 Int_t lastRun = lastRunStr.Atoi();
1426 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);