]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliGRPPreprocessor.cxx
from Y. Schutz
[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 //-------------------------------------------------------------------------
23
24 #include <TChain.h>
25 #include <TList.h>
26 #include <TMap.h>
27 #include <TObjString.h>
28 #include <TTimeStamp.h>
29
30 #include "AliGRPPreprocessor.h"
31 #include "AliGRPDCS.h"
32 #include "AliDCSSensorArray.h"
33
34 #include "AliCDBMetaData.h"
35 #include "AliLog.h"
36
37 class AliDCSValue;
38 class AliShuttleInterface;
39
40 #include <TH1.h>
41
42 const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required
43
44 ClassImp(AliGRPPreprocessor)
45
46 //_______________________________________________________________
47   const char* AliGRPPreprocessor::fgkDCSDataPoints[12] = {"LHCState","LHCPeriod","LHCLuminosity","BeamIntensity","L3Current","L3Polarity","DipoleCurrent","DipolePolarity","CavernTemperature","CavernAtmosPressure","gva_cr5AtmosphericPressure","gva_meyrinAtmosphericPressure"};
48
49 //_______________________________________________________________
50 AliGRPPreprocessor::AliGRPPreprocessor():
51   AliPreprocessor("GRP",0), fPressure(0) {
52   // default constructor - Don't use this!
53   
54 }
55
56 //_______________________________________________________________
57 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
58   AliPreprocessor("GRP",shuttle), fPressure(0) {
59   // constructor - shuttle must be instantiated!
60   
61 }
62
63 //_______________________________________________________________
64 AliGRPPreprocessor::~AliGRPPreprocessor() {
65   //destructor
66   delete fPressure;
67 }
68
69 //_______________________________________________________________
70 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) {
71   // Initialize preprocessor
72   
73   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, TTimeStamp(startTime).AsString(), TTimeStamp(endTime).AsString()));
74   
75   fRun = run;
76   fStartTime = startTime;
77   fEndTime = endTime;
78   AliInfo("Initialization of the GRP preprocessor.");
79
80   TClonesArray * array = new TClonesArray("AliDCSSensor",2);
81   for(Int_t j = 0; j < 2; j++) {
82     AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
83     sens->SetStringID(fgkDCSDataPoints[j+10]);
84   }
85   AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
86
87   fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
88 }
89
90 //_______________________________________________________________
91 UInt_t AliGRPPreprocessor::Process(TMap* valueMap) {
92   // process data retrieved by the Shuttle
93   
94   //=================//
95   // DAQ logbook     //
96   //=================//
97   TList *daqlblist = ProcessDaqLB();
98   if(!daqlblist) {
99     Log(Form("Problem with the DAQ logbook parameters!!!"));
100     return 0;
101   }
102   TMap *m1 = (TMap *)daqlblist->At(0);
103   TObjString *s1 = (TObjString *)m1->GetValue("fAliceStartTime");
104   UInt_t iStartTime = atoi(s1->String().Data());
105   TMap *m2 = (TMap *)daqlblist->At(1);
106   TObjString *s2 = (TObjString *)m2->GetValue("fAliceStopTime");
107   UInt_t iStopTime = atoi(s2->String().Data());
108   TMap *m3 = (TMap *)daqlblist->At(6);
109   TObjString *s3 = (TObjString *)m3->GetValue("fLHCPeriod");
110   TString productionYear = "";
111
112   //=================//
113   // DAQ FXS         //
114   //=================//
115   UInt_t iDaqFxs = ProcessDaqFxs(s3->String(),productionYear);
116   if(iDaqFxs == 0) Log(Form("Raw data merged tags copied succesfully in AliEn!!!"));
117  
118   //=================//
119   // DCS data points //
120   //=================//
121   TList *dcsdplist = ProcessDcsDPs(valueMap, iStartTime, iStopTime);
122   if(!dcsdplist) {
123     Log(Form("Problem with the DCS data points!!!"));
124     return 0;
125   }    
126   if(dcsdplist->GetEntries() != 10) {
127     Log(Form("Problem with the DCS data points!!!"));
128     return 0;
129   }
130   //NEEDS TO BE REVISED - BREAKS!!!
131 //   AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap,fPressure);
132 //   if(!dcsSensorArray) {
133 //     Log(Form("Problem with the pressure sensor values!!!"));
134 //     return 0;
135 //   }
136
137   TList * list = new TList();
138   list = GetGlobalList(daqlblist,dcsdplist);
139   list->SetOwner(1);
140   AliInfo(Form("Final list entries: %d",list->GetEntries()));
141   
142   AliCDBMetaData md;
143   md.SetResponsible("Panos Christakoglou");
144   md.SetComment("Output parameters from the GRP preprocessor.");
145   
146   Bool_t result = Store("GRP", "Data", list, &md);
147   
148   delete list;
149   
150   if (result)
151     return 0;
152   else
153     return 1;
154 }
155
156 //_______________________________________________________________
157 TList *AliGRPPreprocessor::GetGlobalList(TList *l1, TList *l2) {
158   //Getting the global output TList
159   TList *list = new TList();
160   TMap *map = new TMap();
161   for(Int_t i = 0; i < l1->GetEntries(); i++) 
162     list->AddLast(map = (TMap *)l1->At(i));
163   for(Int_t i = 0; i < l2->GetEntries(); i++) 
164     list->AddLast(map = (TMap *)l2->At(i));
165
166   return list;
167 }
168
169 //_______________________________________________________________
170 TList *AliGRPPreprocessor::ProcessDaqLB() {
171   //Getting the DAQ lb informnation
172   const char* timeStart = GetRunParameter("time_start");
173   const char* timeEnd = GetRunParameter("time_end");
174   const char* beamEnergy = GetRunParameter("beamEnergy");
175   const char* beamType = GetRunParameter("beamType");
176   const char* numberOfDetectors = GetRunParameter("numberOfDetectors");
177   const char* detectorMask = GetRunParameter("detectorMask");
178   const char* lhcPeriod = GetRunParameter("LHCperiod");
179
180   if (timeStart) {
181     Log(Form("Start time for run %d: %s",fRun, timeStart));
182   } else {
183     Log(Form("Start time not put in logbook!"));
184   }
185   TMap *mapDAQ1 = new TMap();
186   mapDAQ1->Add(new TObjString("fAliceStartTime"),new TObjString(timeStart));
187
188   if (timeEnd) {
189     Log(Form("End time for run %d: %s",fRun, timeEnd));
190   } else {
191     Log(Form("End time not put in logbook!"));
192   }
193   TMap *mapDAQ2 = new TMap();
194   mapDAQ2->Add(new TObjString("fAliceStopTime"),new TObjString(timeEnd));
195
196   if (beamEnergy) {
197     Log(Form("Beam energy for run %d: %s",fRun, beamEnergy));
198   } else {
199     Log(Form("Beam energy not put in logbook!"));
200   }
201   TMap *mapDAQ3 = new TMap();
202   mapDAQ3->Add(new TObjString("fAliceBeamEnergy"),new TObjString(beamEnergy));
203
204   if (beamType) {
205     Log(Form("Beam type for run %d: %s",fRun, beamType));
206   } else {
207     Log(Form("Beam type not put in logbook!"));
208   }
209   TMap *mapDAQ4 = new TMap();
210   mapDAQ4->Add(new TObjString("fAliceBeamType"),new TObjString(beamType));
211
212   if (numberOfDetectors) {
213     Log(Form("Number of active detectors for run %d: %s",fRun, numberOfDetectors));
214   } else {
215     Log(Form("Number of active detectors not put in logbook!"));
216   }
217   TMap *mapDAQ5 = new TMap();
218   mapDAQ5->Add(new TObjString("fNumberOfDetectors"),new TObjString(numberOfDetectors));
219
220   if (detectorMask) {
221     Log(Form("Detector mask for run %d: %s",fRun, detectorMask));
222   } else {
223     Log(Form("Detector mask not put in logbook!"));
224   }
225   TMap *mapDAQ6 = new TMap();
226   mapDAQ6->Add(new TObjString("fDetectorMask"),new TObjString(detectorMask));
227
228   if (lhcPeriod) {
229     Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod));
230   } else {
231     Log(Form("LHCperiod not put in logbook!"));
232   }
233   TMap *mapDAQ7 = new TMap();
234   mapDAQ7->Add(new TObjString("fLHCPeriod"),new TObjString(lhcPeriod));
235
236   TList *list = new TList();
237   list->Add(mapDAQ1); list->Add(mapDAQ2);
238   list->Add(mapDAQ3); list->Add(mapDAQ4);
239   list->Add(mapDAQ5); list->Add(mapDAQ6);
240   list->Add(mapDAQ7);
241
242   return list;
243 }
244
245 //_______________________________________________________________
246 UInt_t AliGRPPreprocessor::ProcessDaqFxs(TString lhcperiod, TString productionYear) {
247   //======DAQ FXS======//
248   TChain *fRawTagChain = new TChain("T");
249   TString fRawDataFileName;
250   TList* list = GetFileSources(kDAQ);  
251   if (!list) {
252     Log("No raw data tag list found!!!");
253     return 1;
254   }
255   TIterator* iter = list->MakeIterator();
256   TObject* obj = 0;
257   while ((obj = iter->Next())) {
258     TObjString* objStr = dynamic_cast<TObjString*> (obj);
259     if (objStr) {
260       Log(Form("Found source %s", objStr->String().Data()));
261       TList* list2 = GetFileIDs(kDAQ, objStr->String());
262       if (!list2) {
263         Log("No list with ids from DAQ was found!!!");
264         return 2;
265       }
266       Log(Form("Number of ids: %d",list2->GetEntries()));
267       for(Int_t i = 0; i < list2->GetEntries(); i++) {
268         TObjString *idStr = (TObjString *)list2->At(i);
269         //Log(Form("Filename1: %s",idStr->String().Data()));
270         TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());      
271         Log(Form("Adding file in the chain: %s",fileName.Data()));
272         fRawTagChain->Add(fileName.Data());
273         fRawDataFileName = fileName(0,fileName.First("_"));
274       }
275       delete list2;
276     }
277   }
278   delete iter;
279   delete list;
280   fRawDataFileName += "_GRP_Merged.tag.root";
281   Log(Form("Merging raw data tags into file: %s",fRawDataFileName.Data()));
282
283   TString outputfile = "alien:///alice/data/"; 
284   outputfile += productionYear.Data(); outputfile += "/";
285   outputfile += lhcperiod.Data(); outputfile += "/";
286   outputfile += fRun; outputfile += "/raw/"; 
287   //StoreTagFiles(fRawDataFileName.Data(),outputfile.Data());
288
289   return 0;
290 }
291
292 //_______________________________________________________________
293 TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt_t iStopTime) {
294   //Getting the DCS dps
295   //===========//
296   
297   TList *list = new TList();
298
299   //DCS data points
300   //===========//
301   AliInfo(Form("==========LHCState==========="));
302   TObjArray *aliasLHCState = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[0]);
303   if(!aliasLHCState) {
304     Log(Form("LHCState not found!!!"));
305     return list;
306   }
307   AliGRPDCS *dcs1 = new AliGRPDCS(aliasLHCState,iStartTime,iStopTime);
308   TString sLHCState = dcs1->ProcessDCS(3);  
309   if (sLHCState) {
310     Log(Form("<LHCState> for run %d: %s",fRun, sLHCState.Data()));
311   } else {
312     Log(Form("LHCState not put in TMap!"));
313   }
314   TMap *mapDCS1 = new TMap();
315   mapDCS1->Add(new TObjString("fLHCState"),new TObjString(sLHCState));
316   list->Add(mapDCS1);
317
318   AliInfo(Form("==========LHCPeriod==========="));
319   TObjArray *aliasLHCPeriod = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[1]);
320   if(!aliasLHCPeriod) {
321     Log(Form("LHCPeriod not found!!!"));
322     return list;
323   }
324   AliGRPDCS *dcs2 = new AliGRPDCS(aliasLHCPeriod,iStartTime,iStopTime);
325   TString sLHCPeriod = dcs2->ProcessDCS(3);  
326   if (sLHCPeriod) {
327     Log(Form("<LHCPeriod> for run %d: %s",fRun, sLHCPeriod.Data()));
328   } else {
329     Log(Form("LHCPeriod not put in TMap!"));
330   }
331   TMap *mapDCS2 = new TMap();
332   mapDCS2->Add(new TObjString("fLHCCondition"),new TObjString(sLHCPeriod));
333   list->Add(mapDCS2);
334
335   AliInfo(Form("==========LHCLuminosity==========="));
336   TObjArray *aliasLHCLuminosity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[2]);
337   if(!aliasLHCLuminosity) {
338     Log(Form("LHCLuminosity not found!!!"));
339     return list;
340   }
341   AliGRPDCS *dcs3 = new AliGRPDCS(aliasLHCLuminosity,iStartTime,iStopTime);
342   TString sMeanLHCLuminosity = dcs3->ProcessDCS(2);  
343   if (sMeanLHCLuminosity) {
344     Log(Form("<LHCLuminosity> for run %d: %s",fRun, sMeanLHCLuminosity.Data()));
345   } else {
346     Log(Form("LHCLuminosity not put in TMap!"));
347   }
348   TMap *mapDCS3 = new TMap();
349   mapDCS3->Add(new TObjString("fLHCLuminosity"),new TObjString(sMeanLHCLuminosity));
350   list->Add(mapDCS3);
351
352   AliInfo(Form("==========BeamIntensity==========="));
353   TObjArray *aliasBeamIntensity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[3]);
354   if(!aliasBeamIntensity) {
355     Log(Form("BeamIntensity not found!!!"));
356     return list;
357   }
358   AliGRPDCS *dcs4 = new AliGRPDCS(aliasBeamIntensity,iStartTime,iStopTime);
359   TString sMeanBeamIntensity = dcs4->ProcessDCS(2);  
360   if (sMeanBeamIntensity) {
361     Log(Form("<BeamIntensity> for run %d: %s",fRun, sMeanBeamIntensity.Data()));
362   } else {
363     Log(Form("BeamIntensity not put in TMap!"));
364   }
365   TMap *mapDCS4 = new TMap();
366   mapDCS4->Add(new TObjString("fBeamIntensity"),new TObjString(sMeanBeamIntensity));
367   list->Add(mapDCS4);
368
369   AliInfo(Form("==========L3Current==========="));
370   TObjArray *aliasL3Current = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[4]);
371   if(!aliasL3Current) {
372     Log(Form("L3Current not found!!!"));
373     return list;
374   }
375   AliGRPDCS *dcs5 = new AliGRPDCS(aliasL3Current,iStartTime,iStopTime);
376   TString sMeanL3Current = dcs5->ProcessDCS(2);  
377   if (sMeanL3Current) {
378     Log(Form("<L3Current> for run %d: %s",fRun, sMeanL3Current.Data()));
379   } else {
380     Log(Form("L3Current not put in TMap!"));
381   }
382   TMap *mapDCS5 = new TMap();
383   mapDCS5->Add(new TObjString("fL3Current"),new TObjString(sMeanL3Current));
384   list->Add(mapDCS5);
385
386   AliInfo(Form("==========L3Polarity==========="));
387   TObjArray *aliasL3Polarity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[5]);
388   if(!aliasL3Polarity) {
389     Log(Form("L3Polarity not found!!!"));
390     return list;
391   }
392   AliGRPDCS *dcs6 = new AliGRPDCS(aliasL3Polarity,iStartTime,iStopTime);
393   TString sL3Polarity = dcs6->ProcessDCS(4);  
394   if (sL3Polarity) {
395     Log(Form("<L3Polarity> for run %d: %s",fRun, sL3Polarity.Data()));
396   } else {
397     Log(Form("L3Polarity not put in TMap!"));
398   }
399   TMap *mapDCS6 = new TMap();
400   mapDCS6->Add(new TObjString("fL3Polarity"),new TObjString(sL3Polarity));
401   list->Add(mapDCS6);
402
403   AliInfo(Form("==========DipoleCurrent==========="));
404   TObjArray *aliasDipoleCurrent = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[6]);
405   if(!aliasDipoleCurrent) {
406     Log(Form("DipoleCurrent not found!!!"));
407     return list;
408   }
409   AliGRPDCS *dcs7 = new AliGRPDCS(aliasDipoleCurrent,iStartTime,iStopTime);
410   TString sMeanDipoleCurrent = dcs7->ProcessDCS(2);  
411   if (sMeanDipoleCurrent) {
412     Log(Form("<DipoleCurrent> for run %d: %s",fRun, sMeanDipoleCurrent.Data()));
413   } else {
414     Log(Form("DipoleCurrent not put in TMap!"));
415   }
416   TMap *mapDCS7 = new TMap();
417   mapDCS7->Add(new TObjString("fDipoleCurrent"),new TObjString(sMeanDipoleCurrent));
418   list->Add(mapDCS7);
419
420   AliInfo(Form("==========DipolePolarity==========="));
421   TObjArray *aliasDipolePolarity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[7]);
422   if(!aliasDipolePolarity) {
423     Log(Form("DipolePolarity not found!!!"));
424     return list;
425   }
426   AliGRPDCS *dcs8 = new AliGRPDCS(aliasDipolePolarity,iStartTime,iStopTime);
427   TString sDipolePolarity = dcs8->ProcessDCS(4);  
428   if (sDipolePolarity) {
429     Log(Form("<DipolePolarity> for run %d: %s",fRun, sDipolePolarity.Data()));
430   } else {
431     Log(Form("DipolePolarity not put in TMap!"));
432   }
433   TMap *mapDCS8 = new TMap();
434   mapDCS8->Add(new TObjString("fDipolePolarity"),new TObjString(sDipolePolarity));
435   list->Add(mapDCS8);
436
437   AliInfo(Form("==========CavernTemperature==========="));
438   TObjArray *aliasCavernTemperature = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[8]);
439   if(!aliasCavernTemperature) {
440     Log(Form("CavernTemperature not found!!!"));
441     return list;
442   }
443   AliGRPDCS *dcs9 = new AliGRPDCS(aliasCavernTemperature,iStartTime,iStopTime);
444   TString sMeanCavernTemperature = dcs9->ProcessDCS(2);  
445   if (sMeanCavernTemperature) {
446     Log(Form("<CavernTemperature> for run %d: %s",fRun, sMeanCavernTemperature.Data()));
447   } else {
448     Log(Form("CavernTemperature not put in TMap!"));
449   }
450   TMap *mapDCS9 = new TMap();
451   mapDCS9->Add(new TObjString("fCavernTemperature"),new TObjString(sMeanCavernTemperature));
452   list->Add(mapDCS9);
453
454   AliInfo(Form("==========CavernPressure==========="));
455   TObjArray *aliasCavernPressure = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[9]);
456   if(!aliasCavernPressure) {
457     Log(Form("CavernPressure not found!!!"));
458     return list;
459   }
460   AliGRPDCS *dcs10 = new AliGRPDCS(aliasCavernPressure,iStartTime,iStopTime);
461   TString sMeanCavernPressure = dcs10->ProcessDCS(2);  
462   if (sMeanCavernPressure) {
463     Log(Form("<CavernPressure> for run %d: %s",fRun, sMeanCavernPressure.Data()));
464   } else {
465     Log(Form("CavernPressure not put in TMap!"));
466   }
467   TMap *mapDCS10 = new TMap();
468   mapDCS10->Add(new TObjString("fCavernPressure"),new TObjString(sMeanCavernPressure));
469   list->Add(mapDCS10);
470
471   return list;
472 }
473
474 //_______________________________________________________________
475 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap, AliDCSSensorArray *fPressure) {
476   // extract DCS pressure maps. Perform fits to save space
477   
478   TMap *map = fPressure->ExtractDCS(dcsAliasMap);
479   if (map) {
480     fPressure->MakeSplineFit(map);
481     Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors(); 
482     if (fitFraction > kFitFraction ) {
483       AliInfo(Form("Pressure values extracted, fits performed.\n"));
484     } else { 
485       AliInfo("Too few pressure maps fitted. \n");
486     }
487   } else {
488     AliInfo("AliGRPDCS: no atmospheric pressure map extracted. \n");
489   }
490   delete map;
491  
492   return fPressure;
493 }
494
495 //_______________________________________________________________
496 /*UInt_t AliGRPPreprocessor::MapPressure(TMap* dcsAliasMap) {
497   // extract DCS pressure maps. Perform fits to save space
498   
499   UInt_t result=0;
500   TMap *map = fPressure->ExtractDCS(dcsAliasMap);
501   if (map) {
502     fPressure->MakeSplineFit(map);
503     Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors(); 
504     if (fitFraction > kFitFraction ) {
505       AliInfo(Form("Pressure values extracted, fits performed.\n"));
506     } else { 
507       Log ("Too few pressure maps fitted. \n");
508       result = 9;
509     }
510   } else {
511     Log("AliTPCPreprocsessor: no atmospheric pressure map extracted. \n");
512     result=9;
513   }
514   delete map;
515   // Now store the final CDB file
516   
517   if ( result == 0 ) {
518     AliCDBMetaData metaData;
519     metaData.SetBeamPeriod(0);
520     metaData.SetResponsible("Panos Christakoglou");
521     metaData.SetComment("Preprocessor AliGRP data base pressure entries.");
522     
523     Bool_t storeOK = Store("Calib", "Pressure", fPressure, &metaData, 0, 0);
524     if ( !storeOK ) result=1; 
525   }
526   
527   return result; 
528   }*/