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