]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliGRPPreprocessor.cxx
disable doxygen latex output
[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
e7a6790f 22// Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN
3dedb44a 23//-------------------------------------------------------------------------
24
836d8b4f 25#include <TChain.h>
7ca4655f 26#include <TList.h>
27#include <TMap.h>
28#include <TObjString.h>
29#include <TTimeStamp.h>
29cc8704 30#include <TSystem.h>
31#include <TFile.h>
7ca4655f 32
3dedb44a 33#include "AliGRPPreprocessor.h"
34#include "AliGRPDCS.h"
17984b61 35#include "AliDCSSensorArray.h"
3dedb44a 36
48b1b444 37#include "AliTriggerConfiguration.h"
38#include "AliTriggerRunScalers.h"
39
3dedb44a 40#include "AliCDBMetaData.h"
41#include "AliLog.h"
42
3dedb44a 43class AliDCSValue;
44class AliShuttleInterface;
45
46#include <TH1.h>
47
1e27bb6b 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
17984b61 57const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
58
3dedb44a 59ClassImp(AliGRPPreprocessor)
60
17984b61 61//_______________________________________________________________
e7a6790f 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",
66 "L3Polarity",
67 "DipolePolarity",
68 "LHCLuminosity",
69 "BeamIntensity",
70 "L3Current",
71 "DipoleCurrent",
72 "CavernTemperature",
73 "CavernAtmosPressure",
74 "gva_cr5AtmosphericPressure",
75 "gva_meyrinAtmosphericPressure"
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 };
17984b61 100
3dedb44a 101//_______________________________________________________________
102AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
e7a6790f 103 AliPreprocessor("GRP",shuttle), fPressure(0)
104{
3dedb44a 105 // constructor - shuttle must be instantiated!
ad103e84 106
107 AddRunType("PHYSICS");
3dedb44a 108}
109
110//_______________________________________________________________
e7a6790f 111AliGRPPreprocessor::~AliGRPPreprocessor()
112{
3dedb44a 113 //destructor
e7a6790f 114
17984b61 115 delete fPressure;
3dedb44a 116}
117
118//_______________________________________________________________
e7a6790f 119void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
120{
3dedb44a 121 // Initialize preprocessor
5a5052e5 122
123 AliPreprocessor::Initialize(run, startTime, endTime);
e7a6790f 124
17984b61 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;
e7a6790f 130 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
17984b61 131 }
132 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
133
134 fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
3dedb44a 135}
136
137//_______________________________________________________________
e7a6790f 138UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
139{
3dedb44a 140 // process data retrieved by the Shuttle
17984b61 141
142 //=================//
143 // DAQ logbook //
144 //=================//
e7a6790f 145 UInt_t error = 0;
29cc8704 146
e7a6790f 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;
17984b61 153 }
17984b61 154 //=================//
155 // DAQ FXS //
156 //=================//
bba57327 157 UInt_t iDaqFxs = ProcessDaqFxs();
e7a6790f 158 if( iDaqFxs == 0 ) {
159 Log(Form("DAQ FXS, successful!"));
b49acef7 160 } else {
e7a6790f 161 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
162 error |= 2;
b49acef7 163 }
164
48b1b444 165 //=================//
166 // DCS FXS //
167 //=================//
168 UInt_t iDcsFxs = ProcessDcsFxs();
e7a6790f 169 if( iDcsFxs == 0 ) {
170 Log(Form("DCS FXS, successful!"));
48b1b444 171 } else {
e7a6790f 172 Log(Form("DCS FXS, Could not store CTP run configuration and scalers!!!"));
173 error |= 4;
48b1b444 174 }
b49acef7 175
17984b61 176 //=================//
177 // DCS data points //
178 //=================//
e7a6790f 179 Int_t entries = ProcessDcsDPs( valueMap, grpmap );
180 if( entries < fgknDCSDP-3 ) { // FIXME (!= ) LHState and pressure map are not working yet...???
17984b61 181 Log(Form("Problem with the DCS data points!!!"));
e7a6790f 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()));
17984b61 187
188 AliCDBMetaData md;
e7a6790f 189 md.SetResponsible("Ernesto Lopez Torres");
17984b61 190 md.SetComment("Output parameters from the GRP preprocessor.");
191
e7a6790f 192 Bool_t result = Store("GRP", "Data", grpmap, &md);
17984b61 193
e7a6790f 194 delete grpmap;
17984b61 195
e7a6790f 196 if (result && !error ) {
197 Log("GRP Preprocessor Success");
17984b61 198 return 0;
e7a6790f 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 }
17984b61 208}
209
17984b61 210//_______________________________________________________________
e7a6790f 211TMap *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");
125567f8 219 const char* numberOfDetectors = GetRunParameter("numberOfDetectors");
e7a6790f 220 const char* detectorMask = GetRunParameter("detectorMask");
221 const char* lhcPeriod = GetRunParameter("LHCperiod");
222
223 TMap *mapDAQ = new TMap();
224
17984b61 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 }
e7a6790f 230 mapDAQ->Add(new TObjString("fAliceStartTime"), new TObjString(timeStart));
17984b61 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 }
e7a6790f 237 mapDAQ->Add(new TObjString("fAliceStopTime"), new TObjString(timeEnd));
17984b61 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 }
e7a6790f 244 mapDAQ->Add(new TObjString("fAliceBeamEnergy"), new TObjString(beamEnergy));
17984b61 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 }
e7a6790f 251 mapDAQ->Add(new TObjString("fAliceBeamType"), new TObjString(beamType));
17984b61 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 }
e7a6790f 258 mapDAQ->Add(new TObjString("fNumberOfDetectors"), new TObjString(numberOfDetectors));
17984b61 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 }
e7a6790f 265 mapDAQ->Add(new TObjString("fDetectorMask"), new TObjString(detectorMask));
17984b61 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 }
e7a6790f 272 mapDAQ->Add(new TObjString("fLHCPeriod"), new TObjString(lhcPeriod));
5a5052e5 273
e7a6790f 274 mapDAQ->Add(new TObjString("fRunType"), new TObjString(GetRunType()));
275 Log( Form("Retrived %d parameters from logbook", mapDAQ->GetEntries() ) );
17984b61 276
e7a6790f 277 return mapDAQ;
17984b61 278}
279
280//_______________________________________________________________
e7a6790f 281UInt_t AliGRPPreprocessor::ProcessDaqFxs()
282{
836d8b4f 283 //======DAQ FXS======//
29cc8704 284
c865efca 285 TList* list = GetFileSources(kDAQ);
286 if (!list) {
ff97356e 287 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
288 return 1;
289 }
e7a6790f 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;
c865efca 295 }
ff97356e 296
297 TChain *fRawTagChain = new TChain("T");
298 Int_t nFiles=0;
4a33bdd9 299 TIterator* iter = list->MakeIterator();
300 TObject* obj = 0;
958ecabf 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());
836d8b4f 306 if (!list2) {
e7a6790f 307 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
308 delete fRawTagChain; fRawTagChain=0;
309 return 1;
836d8b4f 310 }
311 Log(Form("Number of ids: %d",list2->GetEntries()));
312 for(Int_t i = 0; i < list2->GetEntries(); i++) {
e7a6790f 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 }
836d8b4f 328 }
958ecabf 329 delete list2;
330 }
331 }
ff97356e 332
29cc8704 333 TString fRawDataFileName = "GRP_Merged.tag.root";
ff97356e 334 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
e7a6790f 335 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
336 Log("Error merging raw data files!!!");
337 return 3;
338 }
29cc8704 339
b49acef7 340 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
bba57327 341 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
ff97356e 342
e7a6790f 343 if (!result) {
344 Log("Problem storing raw data tags in local file!!!");
8b5f35a9 345 } else {
e7a6790f 346 Log("Raw data tags merged successfully!!");
ff97356e 347 }
348
349 delete iter;
350 delete list;
351 delete fRawTagChain; fRawTagChain=0;
e7a6790f 352
353 if (result == kFALSE) {
354 return 4;
8b5f35a9 355 }
e7a6790f 356
073502c9 357 return 0;
e7a6790f 358
17984b61 359}
360
48b1b444 361//_______________________________________________________________
e7a6790f 362UInt_t AliGRPPreprocessor::ProcessDcsFxs()
363{
48b1b444 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) {
cbdd8439 372 Log("No CTP runconfig file: connection problems with DCS FXS logbook!");
48b1b444 373 return 1;
374 }
375
376 if (list->GetEntries() == 0) {
377 Log("No CTP runconfig file to be processed!");
e7a6790f 378 return 1;
48b1b444 379 }
380 else {
381 TIter iter(list);
382 TObjString *source;
383 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
e7a6790f 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 }
48b1b444 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!");
e7a6790f 420 return 1;
48b1b444 421 }
422 else {
423 TIter iter(list);
424 TObjString *source;
425 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
e7a6790f 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 }
48b1b444 447 }
448 }
449 delete list;
450 }
451
452 return 0;
453}
454
17984b61 455//_______________________________________________________________
e7a6790f 456Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, TMap* mapDCS)
457{
17984b61 458 //Getting the DCS dps
e97cc90e 459 //===========//
17984b61 460
e97cc90e 461 //DCS data points
462 //===========//
e7a6790f 463
464 Int_t entries = 0;
465
17984b61 466 AliInfo(Form("==========LHCState==========="));
467 TObjArray *aliasLHCState = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[0]);
e97cc90e 468 if(!aliasLHCState) {
469 Log(Form("LHCState not found!!!"));
e7a6790f 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;
8ecdaed6 486 }
e7a6790f 487
488 AliInfo(Form("==========L3Polarity==========="));
489 TObjArray *aliasL3Polarity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[1]);
490 if(!aliasL3Polarity) {
491 Log(Form("L3Polarity not found!!!"));
e97cc90e 492 } else {
e7a6790f 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!!!"));
3dedb44a 508 } else {
e7a6790f 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;
3dedb44a 518 }
125567f8 519
17984b61 520 AliInfo(Form("==========LHCLuminosity==========="));
e7a6790f 521 TObjArray *aliasLHCLuminosity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[3]);
e97cc90e 522 if(!aliasLHCLuminosity) {
523 Log(Form("LHCLuminosity not found!!!"));
e97cc90e 524 } else {
e7a6790f 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;
e97cc90e 534 }
535
17984b61 536 AliInfo(Form("==========BeamIntensity==========="));
e7a6790f 537 TObjArray *aliasBeamIntensity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[4]);
e97cc90e 538 if(!aliasBeamIntensity) {
539 Log(Form("BeamIntensity not found!!!"));
e97cc90e 540 } else {
e7a6790f 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;
e97cc90e 550 }
551
17984b61 552 AliInfo(Form("==========L3Current==========="));
e7a6790f 553 TObjArray *aliasL3Current = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[5]);
e97cc90e 554 if(!aliasL3Current) {
555 Log(Form("L3Current not found!!!"));
e97cc90e 556 } else {
e7a6790f 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;
e97cc90e 566 }
567
e97cc90e 568
17984b61 569 AliInfo(Form("==========DipoleCurrent==========="));
570 TObjArray *aliasDipoleCurrent = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[6]);
e97cc90e 571 if(!aliasDipoleCurrent) {
572 Log(Form("DipoleCurrent not found!!!"));
e7a6790f 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;
e97cc90e 583 }
584
17984b61 585 AliInfo(Form("==========CavernTemperature==========="));
e7a6790f 586 TObjArray *aliasCavernTemperature = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[7]);
e97cc90e 587 if(!aliasCavernTemperature) {
588 Log(Form("CavernTemperature not found!!!"));
e7a6790f 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;
e97cc90e 599 }
600
17984b61 601 AliInfo(Form("==========CavernPressure==========="));
e7a6790f 602 TObjArray *aliasCavernPressure = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[8]);
e97cc90e 603 if(!aliasCavernPressure) {
e7a6790f 604 Log("CavernPressure not found!!!");
e97cc90e 605 } else {
e7a6790f 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,fPressure);
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 }
e97cc90e 643
e7a6790f 644 return entries;
17984b61 645}
125567f8 646
17984b61 647//_______________________________________________________________
e7a6790f 648AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap, AliDCSSensorArray *fPressure)
649{
17984b61 650 // extract DCS pressure maps. Perform fits to save space
3dedb44a 651
17984b61 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 ) {
e7a6790f 657 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
17984b61 658 } else {
e7a6790f 659 AliInfo("Too few pressure maps fitted!!!");
17984b61 660 }
661 } else {
e7a6790f 662 AliInfo("no atmospheric pressure map extracted!!!");
17984b61 663 }
664 delete map;
665
666 return fPressure;
667}
e97cc90e 668
17984b61 669//_______________________________________________________________
670/*UInt_t AliGRPPreprocessor::MapPressure(TMap* dcsAliasMap) {
671 // extract DCS pressure maps. Perform fits to save space
3dedb44a 672
17984b61 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
3dedb44a 690
17984b61 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 }
3dedb44a 700
17984b61 701 return result;
702 }*/
1e27bb6b 703
704
705//_______________________________________________________________
3dfcd47d 706Int_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 707{
e7a6790f 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;
1e27bb6b 894}