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