]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliGRPPreprocessor.cxx
Exchange information only through a data member
[u/mrichter/AliRoot.git] / STEER / AliGRPPreprocessor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
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 //-------------------------------------------------------------------------
24
25 #include <TChain.h>
26 #include <TList.h>
27 #include <TMap.h>
28 #include <TObjString.h>
29 #include <TTimeStamp.h>
30 #include <TSystem.h>
31 #include <TFile.h>
32
33 #include "AliGRPPreprocessor.h"
34 #include "AliGRPDCS.h"
35 #include "AliDCSSensorArray.h"
36
37 #include "AliTriggerConfiguration.h"
38 #include "AliTriggerRunScalers.h"
39
40 #include "AliCDBMetaData.h"
41 #include "AliLog.h"
42
43 class AliDCSValue;
44 class AliShuttleInterface;
45
46 #include <TH1.h>
47
48 // needed for ReceivePromptRecoParameters
49 #include <TSQLServer.h>
50 #include <TSQLResult.h>
51 #include <TSQLRow.h>
52 #include <AliCDBManager.h>
53 #include <AliCDBMetaData.h>
54 #include <AliCDBId.h>
55 #include <AliTriggerConfiguration.h>
56
57 const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required
58
59 ClassImp(AliGRPPreprocessor)
60
61 //_______________________________________________________________
62   const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook
63   const Int_t AliGRPPreprocessor::fgknDCSDP = 11;   // number of dcs dps
64   const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
65                    "LHCState",                  // missing in DCS
66                    "L3Polarity",
67                    "DipolePolarity",
68                    "LHCLuminosity",             // missing in DCS
69                    "BeamIntensity",             // missing in DCS
70                    "L3Current",
71                    "DipoleCurrent",
72                    "CavernTemperature",
73                    "CavernAtmosPressure",
74                    "gva_cr5AtmosphericPressure", // missing in DCS
75                    "gva_meyrinAtmosphericPressure" // missing in DCS
76                  };
77                  
78   const Short_t kSensors = 9; // start index position of sensor in DCS DPs
79
80   const char* AliGRPPreprocessor::fgkLHCState[20] = {
81                    "P", "PREPARE",
82                    "J", "PREINJECTION",
83                    "I", "INJECTION",
84                    "F", "FILLING",
85                    "A", "ADJUST",
86                    "U", "UNSTABLE BEAMS",
87                    "S", "STABLE BEAMS",
88                    "D", "BEAM DUMP",
89                    "R", "RECOVER",
90                    "C", "PRECYCLE"
91                  };
92
93   const char* kppError[] = {
94                    "",
95                    "(DAQ logbook ERROR)",
96                    "(DAQ FXS ERROR)",
97                    "(DCS FXS ERROR)",
98                    "(DCS data points ERROR)"
99   };
100
101 //_______________________________________________________________
102 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
103   AliPreprocessor("GRP",shuttle), fPressure(0)
104 {
105   // constructor - shuttle must be instantiated!
106
107   AddRunType("PHYSICS");
108 }
109
110 //_______________________________________________________________
111 AliGRPPreprocessor::~AliGRPPreprocessor()
112 {
113   //destructor
114
115   delete fPressure;
116 }
117
118 //_______________________________________________________________
119 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
120 {
121   // Initialize preprocessor
122
123   AliPreprocessor::Initialize(run, startTime, endTime);
124
125   AliInfo("Initialization of the GRP preprocessor.");
126
127   TClonesArray * array = new TClonesArray("AliDCSSensor",2);
128   for(Int_t j = 0; j < 2; j++) {
129     AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
130     sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
131   }
132   AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
133
134   fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
135 }
136
137 //_______________________________________________________________
138 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
139 {
140   // process data retrieved by the Shuttle
141   
142   //=================//
143   // DAQ logbook     //
144   //=================//
145   UInt_t error = 0;
146   
147   TMap *grpmap = ProcessDaqLB();
148   if( grpmap->GetEntries() == fgknDAQLbPar ) {
149     Log(Form("DAQ logbook, successful!"));
150   } else {
151     Log(Form("DAQ logbook, missing parameters!!!"));
152     error |= 1;
153   }
154   //=================//
155   // DAQ FXS         //
156   //=================//
157   UInt_t iDaqFxs = ProcessDaqFxs();
158   if( iDaqFxs == 0 ) {
159     Log(Form("DAQ FXS, successful!"));
160   } else {
161     Log(Form("DAQ FXS, could not store run raw tag file!!!"));
162     error |= 2;
163   }
164   
165   //=================//
166   // DCS FXS         //
167   //=================//
168   UInt_t iDcsFxs = ProcessDcsFxs();
169   if( iDcsFxs == 0 ) {
170      Log(Form("DCS FXS, successful!"));
171   } else {
172      Log(Form("DCS FXS, Could not store CTP run configuration and scalers!!!"));
173     error |= 4;
174   }
175   
176   //=================//
177   // DCS data points //
178   //=================//
179   Int_t entries = ProcessDcsDPs( valueMap, grpmap );
180   if( entries < fgknDCSDP-5 ) { // FIXME (!= ) LHCState and pressure map are not working yet...
181     Log(Form("Problem with the DCS data points!!!"));
182     error |= 8;
183   } else  Log(Form("DCS data points, successful!"));
184
185   grpmap->SetOwner(1);
186   AliInfo(Form("Final list entries: %d",grpmap->GetEntries()));
187   
188   AliCDBMetaData md;
189   md.SetResponsible("Ernesto Lopez Torres");
190   md.SetComment("Output parameters from the GRP preprocessor.");
191   
192   Bool_t result = Store("GRP", "Data", grpmap, &md);
193   
194   delete grpmap;
195   
196   if (result && !error ) {
197     Log("GRP Preprocessor Success");
198     return 0;
199   } else {
200     Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s",
201                                  kppError[(error&1)?1:0],
202                                  kppError[(error&2)?2:0],
203                                  kppError[(error&4)?3:0],
204                                  kppError[(error&8)?4:0]
205                                   ));
206     return error;
207   }
208 }
209
210 //_______________________________________________________________
211 TMap *AliGRPPreprocessor::ProcessDaqLB()
212 {
213   //Getting the DAQ lb information
214   
215   const char* timeStart         = GetRunParameter("time_start");
216   const char* timeEnd           = GetRunParameter("time_end");
217   const char* beamEnergy        = GetRunParameter("beamEnergy");
218   const char* beamType          = GetRunParameter("beamType");
219   const char* numberOfDetectors = GetRunParameter("numberOfDetectors");
220   const char* detectorMask      = GetRunParameter("detectorMask");
221   const char* lhcPeriod         = GetRunParameter("LHCperiod");
222   
223   TMap *mapDAQ = new TMap();
224   
225   if (timeStart) {
226     Log(Form("Start time for run %d: %s",fRun, timeStart));
227   } else {
228     Log(Form("Start time not put in logbook!"));
229   }
230   mapDAQ->Add(new TObjString("fAliceStartTime"), new TObjString(timeStart));
231
232   if (timeEnd) {
233     Log(Form("End time for run %d: %s",fRun, timeEnd));
234   } else {
235     Log(Form("End time not put in logbook!"));
236   }
237   mapDAQ->Add(new TObjString("fAliceStopTime"), new TObjString(timeEnd));
238
239   if (beamEnergy) {
240     Log(Form("Beam energy for run %d: %s",fRun, beamEnergy));
241   } else {
242     Log(Form("Beam energy not put in logbook!"));
243   }
244   mapDAQ->Add(new TObjString("fAliceBeamEnergy"), new TObjString(beamEnergy));
245
246   if (beamType) {
247     Log(Form("Beam type for run %d: %s",fRun, beamType));
248   } else {
249     Log(Form("Beam type not put in logbook!"));
250   }
251   mapDAQ->Add(new TObjString("fAliceBeamType"), new TObjString(beamType));
252
253   if (numberOfDetectors) {
254     Log(Form("Number of active detectors for run %d: %s",fRun, numberOfDetectors));
255   } else {
256     Log(Form("Number of active detectors not put in logbook!"));
257   }
258   mapDAQ->Add(new TObjString("fNumberOfDetectors"), new TObjString(numberOfDetectors));
259
260   if (detectorMask) {
261     Log(Form("Detector mask for run %d: %s",fRun, detectorMask));
262   } else {
263     Log(Form("Detector mask not put in logbook!"));
264   }
265   mapDAQ->Add(new TObjString("fDetectorMask"), new TObjString(detectorMask));
266
267   if (lhcPeriod) {
268     Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod));
269   } else {
270     Log(Form("LHCperiod not put in logbook!"));
271   }
272   mapDAQ->Add(new TObjString("fLHCPeriod"), new TObjString(lhcPeriod));
273   
274   mapDAQ->Add(new TObjString("fRunType"), new TObjString(GetRunType()));
275   Log( Form("Retrived %d parameters from logbook", mapDAQ->GetEntries() ) );
276
277   return mapDAQ;
278 }
279
280 //_______________________________________________________________
281 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
282 {
283   //======DAQ FXS======//
284
285   TList* list = GetFileSources(kDAQ);  
286   if (!list) {
287     Log("No raw data tag list: connection problems with DAQ FXS logbook!");
288     return 1;
289   }
290
291   if (list->GetEntries() == 0) {
292     Log("no raw data tags in this run: nothing to merge!");
293     delete  list; list=0;
294     return 0;
295   }
296
297   TChain *fRawTagChain = new TChain("T");
298   Int_t nFiles=0;
299   TIterator* iter = list->MakeIterator();
300   TObject* obj = 0;
301   while ((obj = iter->Next())) {
302     TObjString* objStr = dynamic_cast<TObjString*> (obj);
303     if (objStr) {
304       Log(Form("Found source %s", objStr->String().Data()));
305       TList* list2 = GetFileIDs(kDAQ, objStr->String());
306       if (!list2) {
307         Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
308         delete fRawTagChain; fRawTagChain=0;
309         return 1;
310       }
311       Log(Form("Number of ids: %d",list2->GetEntries()));
312       for(Int_t i = 0; i < list2->GetEntries(); i++) {
313         TObjString *idStr = (TObjString *)list2->At(i);
314         TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
315         if (fileName.Length() > 0) {
316            Log(Form("Adding file in the chain: %s",fileName.Data()));
317            fRawTagChain->Add(fileName.Data());
318            nFiles++;
319         } else {
320            Log(Form("Could not retrieve file with id %s from source %s: "
321                     "connection problems with DAQ FXS!",
322                      idStr->String().Data(), objStr->String().Data()));
323            delete list; list=0;
324            delete list2; list2=0;
325            delete fRawTagChain; fRawTagChain=0;
326            return 2;
327         }
328       }
329       delete list2;
330     }
331   }
332   
333   TString fRawDataFileName = "GRP_Merged.tag.root";
334   Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
335   if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
336     Log("Error merging raw data files!!!");
337     return 3;
338   }
339   
340   TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
341   Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
342   
343   if (!result) {
344     Log("Problem storing raw data tags in local file!!!");
345   } else {
346     Log("Raw data tags merged successfully!!");
347   }
348   
349   delete iter;
350   delete list;
351   delete fRawTagChain; fRawTagChain=0;
352
353   if (result == kFALSE) {
354     return 4;
355   }
356
357   return 0;
358
359 }
360
361 //_______________________________________________________________
362 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
363 {
364   //======DCS FXS======//
365   // Get the CTP run configuration
366   // and scalers from DCS FXS
367
368   {
369     // Get the CTP run configuration
370     TList* list = GetFileSources(kDCS,"CTP_runconfig");  
371     if (!list) {
372       Log("No CTP runconfig file: connection problems with DCS FXS logbook!");
373       return 1;
374     }
375   
376     if (list->GetEntries() == 0) {
377       Log("No CTP runconfig file to be processed!");
378       return 1;
379     }
380     else {
381       TIter iter(list);
382       TObjString *source;
383       while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
384         TString runcfgfile = GetFile(kDCS, "CTP_runconfig", source->GetName());
385         if (runcfgfile.IsNull()) {
386           Log("No CTP runconfig files has been found: empty source!");
387         }
388         else {
389           Log(Form("File with Id CTP_runconfig found in source %s! Copied to %s",source->GetName(),runcfgfile.Data()));
390           AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
391           if (!runcfg) {
392             Log("Bad CTP run configuration file! The corresponding CDB entry will not be filled!");
393             return 1;
394           }
395           else {
396             AliCDBMetaData metaData;
397             metaData.SetBeamPeriod(0);
398             metaData.SetResponsible("Roman Lietava");
399             metaData.SetComment("CTP run configuration");
400             if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
401               Log("Unable to store the CTP run configuration object to OCDB!");
402             }
403           }
404         }
405       }
406     }
407     delete list;
408   }
409
410   {
411     // Get the CTP counters information
412     TList* list = GetFileSources(kDCS,"CTP_xcounters");  
413     if (!list) {
414       Log("No CTP counters file: connection problems with DAQ FXS logbook!");
415       return 1;
416     }
417   
418     if (list->GetEntries() == 0) {
419       Log("No CTP counters file to be processed!");
420       return 1;
421     }
422     else {
423       TIter iter(list);
424       TObjString *source;
425       while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
426         TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
427         if (countersfile.IsNull()) {
428           Log("No CTP counters files has been found: empty source!");
429         }
430         else {
431           Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
432           AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
433           if (!scalers) {
434             Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
435             return 1;
436           }
437           else {
438             AliCDBMetaData metaData;
439             metaData.SetBeamPeriod(0);
440             metaData.SetResponsible("Roman Lietava");
441             metaData.SetComment("CTP scalers");
442             if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
443               Log("Unable to store the CTP scalers object to OCDB!");
444             }
445           }
446         }
447       }
448     }
449     delete list;
450   }
451
452   return 0;
453 }
454
455 //_______________________________________________________________
456 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, TMap* mapDCS)
457 {
458   //Getting the DCS dps
459   //===========//
460
461   //DCS data points
462   //===========//
463   
464   Int_t entries = 0;
465
466   AliInfo(Form("==========LHCState==========="));
467   TObjArray *aliasLHCState = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[0]);
468   if(!aliasLHCState) {
469     Log(Form("LHCState not found!!!"));
470   } else {
471     AliGRPDCS *dcs1 = new AliGRPDCS(aliasLHCState,fStartTime,fEndTime);
472     TString sLHCState = dcs1->ProcessDCS(2);
473     if (sLHCState) {
474       for( Int_t i=0; i<20; i+=2 ) {
475          if( sLHCState.CompareTo(fgkLHCState[i]) == 0 ) {
476             sLHCState = fgkLHCState[i+1];
477             break;
478          }
479       }
480       Log(Form("<LHCState> for run %d: %s",fRun, sLHCState.Data()));
481     } else {
482       Log("LHCState not put in TMap!");
483     }
484     mapDCS->Add(new TObjString("fLHCState"),new TObjString(sLHCState));
485     ++entries;
486   }
487
488   AliInfo(Form("==========L3Polarity==========="));
489   TObjArray *aliasL3Polarity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[1]);
490   if(!aliasL3Polarity) {
491     Log(Form("L3Polarity not found!!!"));
492   } else {
493     AliGRPDCS *dcs6 = new AliGRPDCS(aliasL3Polarity,fStartTime,fEndTime);
494     TString sL3Polarity = dcs6->ProcessDCS(1);  
495     if (sL3Polarity) {
496       Log(Form("<L3Polarity> for run %d: %s",fRun, sL3Polarity.Data()));
497     } else {
498       Log("L3Polarity not put in TMap!");
499     }
500     mapDCS->Add(new TObjString("fL3Polarity"),new TObjString(sL3Polarity));
501     ++entries;
502   }
503
504   AliInfo(Form("==========DipolePolarity==========="));
505   TObjArray *aliasDipolePolarity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[2]);
506   if(!aliasDipolePolarity) {
507     Log(Form("DipolePolarity not found!!!"));
508   } else {
509     AliGRPDCS *dcs8 = new AliGRPDCS(aliasDipolePolarity,fStartTime,fEndTime);
510     TString sDipolePolarity = dcs8->ProcessDCS(1);  
511     if (sDipolePolarity) {
512       Log(Form("<DipolePolarity> for run %d: %s",fRun, sDipolePolarity.Data()));
513     } else {
514       Log("DipolePolarity not put in TMap!");
515     }
516     mapDCS->Add(new TObjString("fDipolePolarity"),new TObjString(sDipolePolarity));
517     ++entries;
518   }
519
520   AliInfo(Form("==========LHCLuminosity==========="));
521   TObjArray *aliasLHCLuminosity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[3]);
522   if(!aliasLHCLuminosity) {
523     Log(Form("LHCLuminosity not found!!!"));
524   } else {
525     AliGRPDCS *dcs3 = new AliGRPDCS(aliasLHCLuminosity,fStartTime,fEndTime);
526     TString sMeanLHCLuminosity = dcs3->ProcessDCS(5);  
527     if (sMeanLHCLuminosity) {
528       Log(Form("<LHCLuminosity> for run %d: %s",fRun, sMeanLHCLuminosity.Data()));
529     } else {
530       Log("LHCLuminosity not put in TMap!");
531     }
532     mapDCS->Add(new TObjString("fLHCLuminosity"), new TObjString(sMeanLHCLuminosity));
533     ++entries;
534   }
535
536   AliInfo(Form("==========BeamIntensity==========="));
537   TObjArray *aliasBeamIntensity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[4]);
538   if(!aliasBeamIntensity) {
539     Log(Form("BeamIntensity not found!!!"));
540   } else {
541     AliGRPDCS *dcs4 = new AliGRPDCS(aliasBeamIntensity,fStartTime,fEndTime);
542     TString sMeanBeamIntensity = dcs4->ProcessDCS(5);  
543     if (sMeanBeamIntensity) {
544       Log(Form("<BeamIntensity> for run %d: %s",fRun, sMeanBeamIntensity.Data()));
545     } else {
546       Log("BeamIntensity not put in TMap!");
547     }
548     mapDCS->Add(new TObjString("fBeamIntensity"),new TObjString(sMeanBeamIntensity));
549     ++entries;
550   }
551
552   AliInfo(Form("==========L3Current==========="));
553   TObjArray *aliasL3Current = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[5]);
554   if(!aliasL3Current) {
555     Log(Form("L3Current not found!!!"));
556   } else {
557     AliGRPDCS *dcs5 = new AliGRPDCS(aliasL3Current,fStartTime,fEndTime);
558     TString sMeanL3Current = dcs5->ProcessDCS(5);  
559     if (sMeanL3Current) {
560       Log(Form("<L3Current> for run %d: %s",fRun, sMeanL3Current.Data()));
561     } else {
562       Log("L3Current not put in TMap!");
563     }
564     mapDCS->Add(new TObjString("fL3Current"),new TObjString(sMeanL3Current));
565     ++entries;
566   }
567
568
569   AliInfo(Form("==========DipoleCurrent==========="));
570   TObjArray *aliasDipoleCurrent = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[6]);
571   if(!aliasDipoleCurrent) {
572     Log(Form("DipoleCurrent not found!!!"));
573   }  else {
574     AliGRPDCS *dcs7 = new AliGRPDCS(aliasDipoleCurrent,fStartTime,fEndTime);
575     TString sMeanDipoleCurrent = dcs7->ProcessDCS(5);  
576     if (sMeanDipoleCurrent) {
577       Log(Form("<DipoleCurrent> for run %d: %s",fRun, sMeanDipoleCurrent.Data()));
578     } else {
579       Log("DipoleCurrent not put in TMap!");
580     }
581     mapDCS->Add(new TObjString("fDipoleCurrent"),new TObjString(sMeanDipoleCurrent));
582     ++entries;
583   }
584
585   AliInfo(Form("==========CavernTemperature==========="));
586   TObjArray *aliasCavernTemperature = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[7]);
587   if(!aliasCavernTemperature) {
588     Log(Form("CavernTemperature not found!!!"));
589   }  else {
590     AliGRPDCS *dcs9 = new AliGRPDCS(aliasCavernTemperature,fStartTime,fEndTime);
591     TString sMeanCavernTemperature = dcs9->ProcessDCS(5);  
592     if (sMeanCavernTemperature) {
593       Log(Form("<CavernTemperature> for run %d: %s",fRun, sMeanCavernTemperature.Data()));
594     } else {
595       Log("CavernTemperature not put in TMap!");
596     }
597     mapDCS->Add(new TObjString("fCavernTemperature"),new TObjString(sMeanCavernTemperature));
598     ++entries;
599   }
600
601   AliInfo(Form("==========CavernPressure==========="));
602   TObjArray *aliasCavernPressure = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[8]);
603   if(!aliasCavernPressure) {
604     Log("CavernPressure not found!!!");
605   } else {
606     AliGRPDCS *dcs10 = new AliGRPDCS(aliasCavernPressure,fStartTime,fEndTime);
607     TString sMeanCavernPressure = dcs10->ProcessDCS(5);  
608     if (sMeanCavernPressure) {
609       Log(Form("<CavernPressure> for run %d: %s",fRun, sMeanCavernPressure.Data()));
610     } else {
611       Log("CavernPressure not put in TMap!");
612     }
613     mapDCS->Add(new TObjString("fCavernPressure"),new TObjString(sMeanCavernPressure));
614     ++entries;
615   }
616
617
618    // NEEDS TO BE REVISED, CONFIRMED
619    AliInfo(Form("==========GenevaPressureMaps==========="));
620    AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
621    if( fPressure->NumFits()==0 ) {
622      Log("Problem with the pressure sensor values!!!");
623    } else {
624       AliDCSSensor* sensorCr5 = dcsSensorArray->GetSensor(fgkDCSDataPoints[9]);
625       if( sensorCr5->GetFit() ) {
626         Log(Form("<GvaCr5Pressure> for run %d: Sensor Fit found",fRun));
627         mapDCS->Add( new TObjString("fCr5Pressure"), sensorCr5 );
628         ++entries;
629       } else {
630         Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[9] ));
631       }
632       
633       AliDCSSensor* sensorMeyrin = dcsSensorArray->GetSensor(fgkDCSDataPoints[10]);
634       if( sensorMeyrin->GetFit() ) {
635         Log(Form("<MeyrinPressure> for run %d: Sensor Fit found",fRun));
636         mapDCS->Add( new TObjString("fMeyrinPressure"), sensorMeyrin );
637         ++entries;
638       } else {
639         Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[10] ));
640       }
641
642    }
643
644   return entries;
645 }
646
647 //_______________________________________________________________
648 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
649 {
650   // extract DCS pressure maps. Perform fits to save space
651   
652   TMap *map = fPressure->ExtractDCS(dcsAliasMap);
653   if (map) {
654     fPressure->MakeSplineFit(map);
655     Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors(); 
656     if (fitFraction > kFitFraction ) {
657       AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
658     } else { 
659       AliInfo("Too few pressure maps fitted!!!");
660     }
661   } else {
662     AliInfo("no atmospheric pressure map extracted!!!");
663   }
664   delete map;
665  
666   return fPressure;
667 }
668
669 //_______________________________________________________________
670 /*UInt_t AliGRPPreprocessor::MapPressure(TMap* dcsAliasMap) {
671   // extract DCS pressure maps. Perform fits to save space
672   
673   UInt_t result=0;
674   TMap *map = fPressure->ExtractDCS(dcsAliasMap);
675   if (map) {
676     fPressure->MakeSplineFit(map);
677     Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors(); 
678     if (fitFraction > kFitFraction ) {
679       AliInfo(Form("Pressure values extracted, fits performed.\n"));
680     } else { 
681       Log ("Too few pressure maps fitted. \n");
682       result = 9;
683     }
684   } else {
685     Log("AliTPCPreprocsessor: no atmospheric pressure map extracted. \n");
686     result=9;
687   }
688   delete map;
689   // Now store the final CDB file
690   
691   if ( result == 0 ) {
692     AliCDBMetaData metaData;
693     metaData.SetBeamPeriod(0);
694     metaData.SetResponsible("Panos Christakoglou");
695     metaData.SetComment("Preprocessor AliGRP data base pressure entries.");
696     
697     Bool_t storeOK = Store("Calib", "Pressure", fPressure, &metaData, 0, 0);
698     if ( !storeOK ) result=1; 
699   }
700   
701   return result; 
702   }*/
703
704   
705 //_______________________________________________________________
706 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)
707 {
708    //
709    // Retrieves logbook and trigger information from the online logbook
710    // This information is needed for prompt reconstruction
711    //
712    // Parameters are:
713    // Run number
714    // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
715    // cdbRoot
716    //
717    // returns:
718    //         positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
719    //         0 on success and no run was found
720    //         negative on error
721    //
722    // This function is NOT called during the preprocessor run in the Shuttle!
723    //
724
725    // defaults
726    if (dbPort == 0)
727      dbPort = 3306;
728
729    // CDB connection
730    AliCDBManager* cdb = AliCDBManager::Instance();
731    cdb->SetDefaultStorage(cdbRoot);
732
733    // SQL connection
734    TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
735
736    if (!server)
737    {
738      Printf("ERROR: Could not connect to DAQ LB");
739      return -1;
740    }
741
742    // main logbook
743    TString sqlQuery;
744    sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask FROM logbook WHERE run = %d", run);
745    TSQLResult* result = server->Query(sqlQuery);
746    if (!result)
747    {
748      Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
749      return -2;
750    }
751
752    if (result->GetRowCount() == 0)
753    {
754      Printf("ERROR: Run %d not found", run);
755      delete result;
756      return -3;
757    }
758
759    TSQLRow* row = result->Next();
760    if (!row)
761    {
762      Printf("ERROR: Could not receive data from run %d", run);
763      delete result;
764      return -4;
765    }
766
767    TString runType(row->GetField(1));
768
769    TMap grpData;
770    grpData.Add(new TObjString("DAQ_time_start"), new TObjString(row->GetField(0)));
771    grpData.Add(new TObjString("run_type"), new TObjString(runType));
772    grpData.Add(new TObjString("detectorMask"), new TObjString(row->GetField(2)));
773
774    delete row;
775    row = 0;
776
777    delete result;
778    result = 0;
779
780    Printf("Storing GRP/GRP/Data object with the following content");
781    grpData.Print();
782
783    AliCDBMetaData metadata;
784    metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus");
785    metadata.SetComment("GRP Output parameters received during online running");
786
787    AliCDBId id("GRP/GRP/Data", run, run);
788    Bool_t success = cdb->Put(&grpData, id, &metadata);
789
790    grpData.DeleteAll();
791
792    if (!success)
793    {
794      Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
795      return -5;
796    }
797
798    // Receive trigger information
799    sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
800    result = server->Query(sqlQuery);
801    if (!result)
802    {
803      Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
804      return -11;
805    }
806
807    if (result->GetRowCount() == 0)
808    {
809      Printf("ERROR: Run %d not found in logbook_trigger_config", run);
810      delete result;
811      return -12;
812    }
813
814    row = result->Next();
815    if (!row)
816    {
817      Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
818      delete result;
819      return -13;
820    }
821
822    TString triggerConfig(row->GetField(0));
823
824    delete row;
825    row = 0;
826
827    delete result;
828    result = 0;
829
830    Printf("Found trigger configuration: %s", triggerConfig.Data());
831
832    AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
833    if (!runcfg)
834    {
835      Printf("ERROR: Could not create CTP configuration object");
836      return -14;
837    }
838
839    metadata.SetComment("CTP run configuration received during online running");
840
841    AliCDBId id2("GRP/CTP/Config", run, run);
842    success = cdb->Put(runcfg, id2, &metadata);
843
844    delete runcfg;
845    runcfg = 0;
846
847    if (!success)
848    {
849      Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
850      return -15;
851    }
852
853    // get last run with same run type that was already processed by the SHUTTLE
854
855    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());
856    result = server->Query(sqlQuery);
857    if (!result)
858    {
859      Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
860      return -21;
861    }
862
863    if (result->GetRowCount() == 0)
864    {
865      Printf("ERROR: No result with query <%s>", sqlQuery.Data());
866      delete result;
867      return -22;
868    }
869
870    row = result->Next();
871    if (!row)
872    {
873      Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
874      delete result;
875      return -23;
876    }
877
878    TString lastRunStr(row->GetField(0));
879    Int_t lastRun = lastRunStr.Atoi();
880
881    Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
882
883    delete row;
884    row = 0;
885
886    delete result;
887    result = 0;
888
889    server->Close();
890    delete server;
891    server = 0;
892
893    return lastRun;
894 }