]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliHLTReconstructor.cxx
more consistent use of cuts, new cut number 1008
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTReconstructor.cxx
CommitLineData
3e820254 1// $Id$
2
c5123824 3//**************************************************************************
a31bc263 4//* This file is property of and copyright by the *
c5123824 5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
c5123824 8//* *
9//* Permission to use, copy, modify and distribute this software and its *
10//* documentation strictly for non-commercial purposes is hereby granted *
11//* without fee, provided that the above copyright notice appears in all *
12//* copies and that both the copyright notice and this permission notice *
13//* appear in the supporting documentation. The authors make no claims *
14//* about the suitability of this software for any purpose. It is *
15//* provided "as is" without express or implied warranty. *
16//**************************************************************************
c534985b 17
69edd0d6 18// @file AliHLTReconstructor.cxx
19// @author Matthias Richter
20// @date
21// @brief Binding class for HLT reconstruction in AliRoot
22// Implements bot the interface to run HLT chains embedded into
23// AliReconstruction and the unpacking and treatment of HLTOUT
3e820254 24
25#include <TSystem.h>
26#include <TObjString.h>
032c5e5e 27#include "TFile.h"
28#include "TTree.h"
dc5556e5 29#include "TObject.h"
30#include "TObjArray.h"
31#include "TClass.h"
32#include "TStreamerInfo.h"
3e820254 33#include "AliHLTReconstructor.h"
34#include "AliLog.h"
032c5e5e 35#include "AliRawReader.h"
c5123824 36#include "AliESDEvent.h"
3e820254 37#include "AliHLTSystem.h"
c5123824 38#include "AliHLTOUTRawReader.h"
39#include "AliHLTOUTDigitReader.h"
40#include "AliHLTEsdManager.h"
00ddfaca 41#include "AliHLTPluginBase.h"
dc5556e5 42#include "AliHLTMisc.h"
43#include "AliCDBManager.h"
44#include "AliCDBEntry.h"
d3382be1 45#include "AliHLTMessage.h"
c4ffab2c 46#include "AliCentralTrigger.h"
47#include "AliTriggerConfiguration.h"
48#include "AliTriggerClass.h"
49#include "AliTriggerCluster.h"
50#include "AliDAQ.h"
56c9a306 51#include "AliRunLoader.h"
dc5556e5 52
53class AliCDBEntry;
3e820254 54
69edd0d6 55/** ROOT macro for the implementation of ROOT specific class methods */
3e820254 56ClassImp(AliHLTReconstructor)
57
58AliHLTReconstructor::AliHLTReconstructor()
69edd0d6 59 : AliReconstructor()
60 , fpEsdManager(NULL)
61 , fpPluginBase(new AliHLTPluginBase)
3eb6bcbe 62 , fFlags(0)
a31bc263 63 , fProcessingStep(kProcessingStepUndefined)
3e820254 64{
65 //constructor
66}
67
032c5e5e 68AliHLTReconstructor::AliHLTReconstructor(const char* options)
69edd0d6 69 : AliReconstructor()
70 , fpEsdManager(NULL)
71 , fpPluginBase(new AliHLTPluginBase)
3eb6bcbe 72 , fFlags(0)
a31bc263 73 , fProcessingStep(kProcessingStepUndefined)
032c5e5e 74{
75 //constructor
76 if (options) Init(options);
77}
78
3e820254 79AliHLTReconstructor::~AliHLTReconstructor()
80{
81 //destructor
dee38f1b 82
56c9a306 83 if (fpEsdManager) AliHLTEsdManager::Delete(fpEsdManager);
84 fpEsdManager=NULL;
85
00ddfaca 86 if (fpPluginBase) {
87 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
a3ef3c1d 88 if (pSystem) {
00ddfaca 89 AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
3dd8541e 90 if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
dee38f1b 91 // send specific 'event' to execute the stop sequence
a3ef3c1d 92 pSystem->Reconstruct(0, NULL, NULL);
dee38f1b 93 }
3e820254 94 }
00ddfaca 95 delete fpPluginBase;
96 }
97 fpPluginBase=NULL;
c5123824 98
3e820254 99}
100
032c5e5e 101void AliHLTReconstructor::Init(const char* options)
102{
103 // init the reconstructor
104 SetOption(options);
105 Init();
106}
107
3e820254 108void AliHLTReconstructor::Init()
109{
110 // init the reconstructor
00ddfaca 111 if (!fpPluginBase) {
112 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
113 return;
114 }
115
116 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
a3ef3c1d 117 if (!pSystem) {
3e820254 118 AliError("can not create AliHLTSystem object");
119 return;
120 }
a3ef3c1d 121 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
3e820254 122 AliError("HLT system in error state");
123 return;
124 }
125
21d97a90 126 TString esdManagerOptions;
127
3e820254 128 // the options scan has been moved to AliHLTSystem, the old code
129 // here is kept to be able to run an older version of the HLT code
130 // with newer AliRoot versions.
3e820254 131 TString option = GetOption();
132 TObjArray* pTokens=option.Tokenize(" ");
133 option="";
134 if (pTokens) {
135 int iEntries=pTokens->GetEntries();
136 for (int i=0; i<iEntries; i++) {
137 TString token=(((TObjString*)pTokens->At(i))->GetString());
138 if (token.Contains("loglevel=")) {
139 TString param=token.ReplaceAll("loglevel=", "");
140 if (param.IsDigit()) {
a3ef3c1d 141 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
3e820254 142 } else if (param.BeginsWith("0x") &&
143 param.Replace(0,2,"",0).IsHex()) {
144 int severity=0;
145 sscanf(param.Data(),"%x", &severity);
a3ef3c1d 146 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
3e820254 147 } else {
148 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
149 }
150 } else if (token.Contains("alilog=off")) {
a3ef3c1d 151 pSystem->SwitchAliLog(0);
3eb6bcbe 152 } else if (token.CompareTo("ignore-hltout")==0) {
153 fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
930201f4 154 } else if (token.CompareTo("run-online-config")==0) {
155 fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
156 if (option.Length()>0) option+=" ";
157 option+=token;
75cbb181 158 } else if (token.CompareTo("ignore-ctp")==0) {
159 fFlags|=kAliHLTReconstructorIgnoreCTP;
21d97a90 160 } else if (token.Contains("esdmanager=")) {
161 token.ReplaceAll("esdmanager=", "");
162 token.ReplaceAll(","," ");
163 token.ReplaceAll("'","");
164 esdManagerOptions=token;
3e820254 165 } else {
166 if (option.Length()>0) option+=" ";
167 option+=token;
168 }
169 }
170 delete pTokens;
171 }
7f9ab840 172
c4ffab2c 173 TString ecsParam;
174 TString ctpParam;
75cbb181 175 if ((fFlags&kAliHLTReconstructorIgnoreCTP)==0 &&
176 BuildCTPTriggerClassString(ctpParam)>=0) {
c4ffab2c 177 if (!ecsParam.IsNull()) ecsParam+=";";
178 ecsParam+="CTP_TRIGGER_CLASS=";
179 ecsParam+=ctpParam;
180 }
181
182 if (!ecsParam.IsNull()) {
183 option+=" ECS=";
184 option+=ecsParam;
185 }
186
a3ef3c1d 187 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
69edd0d6 188 if (pSystem->ScanOptions(option.Data())<0) {
3e820254 189 AliError("error setting options for HLT system");
3e820254 190 return;
191 }
a3ef3c1d 192 if ((pSystem->Configure())<0) {
3e820254 193 AliError("error during HLT system configuration");
194 return;
195 }
196 }
c5123824 197
f1207f29 198 fpEsdManager=AliHLTEsdManager::New();
27a77ce0 199 if (fpEsdManager) {
200 fpEsdManager->SetOption(esdManagerOptions.Data());
201 }
dc5556e5 202
b251fffc 203 AliHLTMisc::Instance().InitStreamerInfos(fgkCalibStreamerInfoEntry);
dc5556e5 204}
205
824ab48a 206void AliHLTReconstructor::Terminate()
76797417 207{
a31bc263 208 /// overloaded from AliReconstructor: terminate event processing
209
210 // indicate step 'Terminate'
211 SetProcessingStep(kProcessingStepTerminate);
212
76797417 213 if (fpPluginBase) {
a31bc263 214 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
215 if (pSystem) {
06b7d051 216 // 2012-04-02
217 // clean up the HLTOUT instance if still existing, currently FinishEvent
218 // is not called at the end of the event processing and the cleanup
219 // needs to be done here to avoid a warning message. Later it can be
220 // declared a malfunction if the HLTOUT instance is still existing at
221 // this point.
222 AliHLTOUT* pHLTOUT=NULL;
223 pSystem->InvalidateHLTOUT(&pHLTOUT);
224 if (pHLTOUT) {
225 pHLTOUT->Reset();
226 delete pHLTOUT;
227 pHLTOUT=NULL;
228 }
229
a31bc263 230 AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
231 if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
232 // send specific 'event' to execute the stop sequence
233 pSystem->Reconstruct(0, NULL, NULL);
234 }
235 }
236 }
237}
238
239void AliHLTReconstructor::FinishEvent()
240{
241 /// overloaded from AliReconstructor: finish current event
242 if (!fpPluginBase) return;
243
244 // indicate step 'FinishEvent'
245 SetProcessingStep(kProcessingStepFinishEvent);
246
247 AliInfo("finishing event");
76797417 248 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
249 if (pSystem) {
a31bc263 250 // this is the end of the lifetime of the HLTOUT instance
251 // called after all other modules have been reconstructed
252 AliHLTOUT* pHLTOUT=NULL;
253 pSystem->InvalidateHLTOUT(&pHLTOUT);
254 if (pHLTOUT) {
255 pHLTOUT->Reset();
256 delete pHLTOUT;
257 pHLTOUT=NULL;
76797417 258 }
259 }
76797417 260}
261
dc5556e5 262const char* AliHLTReconstructor::fgkCalibStreamerInfoEntry="HLT/Calib/StreamerInfo";
263
06995b88 264void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clustersTree*/) const
3e820254 265{
266 // reconstruction of real data without writing of ESD
c5123824 267 // For each event, HLT reconstruction chains can be executed and
268 // added to the existing HLTOUT data
269 // The HLTOUT data is finally processed in FillESD
56c9a306 270
00ddfaca 271 if (!fpPluginBase) {
272 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
273 return;
274 }
275
3e820254 276 int iResult=0;
00ddfaca 277 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
06995b88 278
a3ef3c1d 279 if (pSystem) {
d82bb2b6 280 AliHLTOUT* pHLTOUT=NULL;
281 pSystem->InvalidateHLTOUT(&pHLTOUT);
282 if (pHLTOUT) {
a31bc263 283 // at this stage we always have a new event, regardless state of
284 // fProcessingStep; build the HLTOUT instance from scratch
285 pHLTOUT->Reset();
d82bb2b6 286 delete pHLTOUT;
287 pHLTOUT=NULL;
288 }
a3ef3c1d 289 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
3e820254 290 AliError("HLT system in error state");
291 return;
292 }
a3ef3c1d 293 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
3e820254 294 AliError("HLT system in wrong state");
295 return;
296 }
56c9a306 297
a31bc263 298 // indicate the local reconstruction step
299 SetProcessingStep(kProcessingStepLocal);
300
56c9a306 301 // init the HLTOUT instance for the current event
302 // not nice. Have to query the global run loader to get the current event no.
303 Int_t eventNo=-1;
304 AliRunLoader* runloader = AliRunLoader::Instance();
305 if (runloader) {
306 eventNo=runloader->GetEventNumber();
307 }
308 if (eventNo>=0) {
309 AliRawReader* input=NULL;
310 if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
311 input=rawReader;
312 }
d82bb2b6 313 pHLTOUT=new AliHLTOUTRawReader(input, eventNo, fpEsdManager);
56c9a306 314 if (pHLTOUT) {
315 if (pHLTOUT->Init()>=0) {
316 pSystem->InitHLTOUT(pHLTOUT);
317 } else {
318 AliError("error : initialization of HLTOUT handler failed");
319 }
320 } else {
321 AliError("memory allocation failed: can not create AliHLTOUT object");
322 }
323 } else {
324 AliError("can not get event number");
325 }
326
a3ef3c1d 327 if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
c5123824 328 }
329 }
06995b88 330}
331
332void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/,
333 AliESDEvent* esd) const
334{
335 // reconstruct real data and fill ESD
336 if (!rawReader || !esd) {
337 AliError("missing raw reader or esd object");
338 return;
339 }
340
00ddfaca 341 if (!fpPluginBase) {
342 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
343 return;
344 }
345
346 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 347
348 if (pSystem) {
349 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
350 AliError("HLT system in error state");
351 return;
352 }
353 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
354 AliError("HLT system in wrong state");
355 return;
356 }
357 pSystem->FillESD(-1, NULL, esd);
358
56c9a306 359 // the HLTOUT handler has either been created in the AliHLTReconstructor::Reconstruct
360 // step of this event or is created now. In either case the instance is deleted after
361 // the processing
362 AliHLTOUT* pHLTOUT=NULL;
363 pSystem->InvalidateHLTOUT(&pHLTOUT);
a31bc263 364 if (pHLTOUT && fProcessingStep!=kProcessingStepLocal) {
365 // this is a new event, if local reconstruction would have been executed
366 // the HLTOUT instance would have been created for the current event already,
367 // in all other cases one has to create the HLTOUT instance here
368 pHLTOUT->Reset();
369 delete pHLTOUT;
370 pHLTOUT=NULL;
371 }
56c9a306 372 if (!pHLTOUT) {
373 AliRawReader* input=NULL;
374 if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
375 input=rawReader;
376 }
377 pHLTOUT=new AliHLTOUTRawReader(input, esd->GetEventNumberInFile(), fpEsdManager);
3eb6bcbe 378 }
a31bc263 379
380 // indicate step 'ESD filling'
381 SetProcessingStep(kProcessingStepESD);
382
c5123824 383 if (pHLTOUT) {
0bba252a 384 ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
a31bc263 385 // 2012-03-30: a change in the module sequence of AliReconstruction is soon
386 // going to be applied: HLT reconstruction is executed fully (i.e. both local
387 // reconstruction and FillESD) before all the other modules. In order to make the
388 // HLTOUT data available for other modules it is kept here and released in the method
389 // FinishEvent
390 pSystem->InitHLTOUT(pHLTOUT);
c5123824 391 } else {
392 AliError("error creating HLTOUT handler");
3e820254 393 }
394 }
395}
7f9ab840 396
29312178 397void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
7f9ab840 398{
399 // reconstruct simulated data
400
56c9a306 401 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
402
403 if (pSystem) {
404 // create the HLTOUT instance in order to be available for other detector reconstruction
d82bb2b6 405 // first cleanup any existing instance
406 AliHLTOUT* pHLTOUT=NULL;
407 pSystem->InvalidateHLTOUT(&pHLTOUT);
408 if (pHLTOUT) {
a31bc263 409 // at this stage we always have a new event, regardless state of
410 // fProcessingStep; build the HLTOUT instance from scratch
411 pHLTOUT->Reset();
d82bb2b6 412 delete pHLTOUT;
413 pHLTOUT=NULL;
414 }
56c9a306 415
a31bc263 416 // indicate the local reconstruction step
417 SetProcessingStep(kProcessingStepLocal);
418
56c9a306 419 // not nice. Have to query the global run loader to get the current event no.
420 // This is related to the missing AliLoader for HLT.
421 // Since AliReconstruction can not provide a digits tree, the file needs to be accessed
422 // explicitely, and the corresponding event needs to be selected.
423 Int_t eventNo=-1;
424 AliRunLoader* runloader = AliRunLoader::Instance();
425 if (runloader) {
426 eventNo=runloader->GetEventNumber();
427 }
428 if (eventNo>=0) {
429 const char* digitfile=NULL;
430 if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
431 digitfile="HLT.Digits.root";
432 }
433
d82bb2b6 434 pHLTOUT=new AliHLTOUTDigitReader(eventNo, fpEsdManager, digitfile);
56c9a306 435 if (pHLTOUT) {
436 if (pHLTOUT->Init()>=0) {
437 pSystem->InitHLTOUT(pHLTOUT);
438 } else {
439 AliError("error : initialization of HLTOUT handler failed");
440 }
441 } else {
442 AliError("memory allocation failed: can not create AliHLTOUT object");
443 }
444 } else {
445 AliError("can not get event number");
446 }
447
448 // all data processing happens in FillESD
449 }
7f9ab840 450}
451
c5123824 452void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
7f9ab840 453{
454 // reconstruct simulated data and fill ESD
455
456 // later this is the place to extract the simulated HLT data
457 // for now it's only an user failure condition as he tries to run HLT reconstruction
458 // on simulated data
459 TString option = GetOption();
c5123824 460 if (!option.IsNull() &&
461 (option.Contains("config=") || option.Contains("chains="))) {
7ae41d91 462 AliWarning(Form("You are trying to run a custom HLT chain on digits data.\n\n"
463 "HLT reconstruction can be run embedded into AliReconstruction from\n"
464 "raw data (real or simulated)). Reconstruction of digit data takes\n"
465 "place in AliSimulation, appropriate input conversion is needed to\n"
466 "feed data from the detector digits into the HLT chain.\n"
467 "Consider running embedded into AliSimulation.\n"
7f9ab840 468 " /*** run macro *****************************************/\n"
469 " AliSimulation sim;\n"
470 " sim.SetRunHLT(\"%s\");\n"
471 " sim.SetRunGeneration(kFALSE);\n"
472 " sim.SetMakeDigits(\"\");\n"
473 " sim.SetMakeSDigits(\"\");\n"
474 " sim.SetMakeDigitsFromHits(\"\");\n"
475 " sim.Run();\n"
7ae41d91 476 " /*********************************************************/\n\n",
477 option.Data()));
7f9ab840 478 }
00ddfaca 479 if (!fpPluginBase) {
480 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
481 return;
482 }
483
484 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 485 if (pSystem) {
486 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
487 AliError("HLT system in error state");
488 return;
489 }
490 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
491 AliError("HLT system in wrong state");
492 return;
493 }
494
56c9a306 495 // the HLTOUT handler has either been created in the AliHLTReconstructor::Reconstruct
496 // step of this event or is created now. In either case the instance is deleted after
497 // the processing
498 AliHLTOUT* pHLTOUT=NULL;
499 pSystem->InvalidateHLTOUT(&pHLTOUT);
a31bc263 500 if (pHLTOUT && fProcessingStep!=kProcessingStepLocal) {
501 // this is a new event, if local reconstruction would have been executed
502 // the HLTOUT instance would have been created for the current event already,
503 // in all other cases one has to create the HLTOUT instance here
504 pHLTOUT->Reset();
505 delete pHLTOUT;
506 pHLTOUT=NULL;
507 }
56c9a306 508 if (!pHLTOUT) {
509 const char* digitfile=NULL;
510 if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
511 digitfile="HLT.Digits.root";
512 }
513 pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager, digitfile);
7ae41d91 514 }
515
a31bc263 516 // indicate step 'ESD filling'
517 SetProcessingStep(kProcessingStepESD);
518
c5123824 519 if (pHLTOUT) {
fbe9adaf 520 ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
a31bc263 521 // 2012-03-30: a change in the module sequence of AliReconstruction is soon
522 // going to be applied: HLT reconstruction is executed fully (i.e. both local
523 // reconstruction and FillESD) before all the other modules. In order to make the
524 // HLTOUT data available for other modules it is kept here and released in the method
525 // FinishEvent
526 pSystem->InitHLTOUT(pHLTOUT);
c5123824 527 } else {
528 AliError("error creating HLTOUT handler");
529 }
530 }
531}
532
b005ef92 533void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd, bool bVerbose) const
c5123824 534{
f94e8c27 535 // treatment of simulated or real HLTOUT data
c5123824 536 if (!pHLTOUT) return;
00ddfaca 537 if (!fpPluginBase) {
538 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
539 return;
540 }
541
542 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 543 if (!pSystem) {
544 AliError("error getting HLT system instance");
545 return;
546 }
547
548 if (pHLTOUT->Init()<0) {
549 AliError("error : initialization of HLTOUT handler failed");
550 return;
551 }
552
b005ef92 553 if (bVerbose)
554 PrintHLTOUTContent(pHLTOUT);
555
d3382be1 556 int blockindex=pHLTOUT->SelectFirstDataBlock(kAliHLTDataTypeStreamerInfo);
557 if (blockindex>=0) {
558 const AliHLTUInt8_t* pBuffer=NULL;
559 AliHLTUInt32_t size=0;
560 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
561 TObject* pObject=AliHLTMessage::Extract(pBuffer, size);
562 if (pObject) {
563 TObjArray* pArray=dynamic_cast<TObjArray*>(pObject);
564 if (pArray) {
b251fffc 565 AliHLTMisc::Instance().InitStreamerInfos(pArray);
d3382be1 566 } else {
567 AliError(Form("wrong class type of streamer info list: expected TObjArray, but object is of type %s", pObject->Class()->GetName()));
568 }
569 } else {
570 AliError(Form("failed to extract object from data block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
571 }
572 } else {
573 AliError(Form("failed to get data buffer for block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
574 }
575 }
576
69edd0d6 577 if (pSystem->ProcessHLTOUT(pHLTOUT, esd)<0) {
578 AliError("error processing HLTOUT");
c5123824 579 }
69edd0d6 580
9e31b43e 581 if (bVerbose && esd) {
fbe9adaf 582 AliInfo("HLT ESD content:");
583 esd->Print();
584 }
7f9ab840 585}
032c5e5e 586
587void AliHLTReconstructor::ProcessHLTOUT(const char* digitFile, AliESDEvent* pEsd) const
588{
589 // debugging/helper function to examine simulated data
590 if (!digitFile) return;
591
592 // read the number of events
593 TFile f(digitFile);
594 if (f.IsZombie()) return;
595 TTree* pTree=NULL;
596 f.GetObject("rawhltout", pTree);
597 if (!pTree) {
598 AliWarning(Form("can not find tree rawhltout in file %s", digitFile));
599 return ;
600 }
601 int nofEvents=pTree->GetEntries();
602 f.Close();
603 //delete pTree; OF COURSE NOT! its an object in the file
604 pTree=NULL;
605
606 for (int event=0; event<nofEvents; event++) {
607 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(event, fpEsdManager, digitFile);
608 if (pHLTOUT) {
609 AliInfo(Form("event %d", event));
b005ef92 610 ProcessHLTOUT(pHLTOUT, pEsd, true);
032c5e5e 611 delete pHLTOUT;
612 } else {
613 AliError("error creating HLTOUT handler");
614 }
615 }
616}
617
618void AliHLTReconstructor::ProcessHLTOUT(AliRawReader* pRawReader, AliESDEvent* pEsd) const
619{
620 // debugging/helper function to examine simulated or real HLTOUT data
621 if (!pRawReader) return;
622
623 pRawReader->RewindEvents();
624 for (int event=0; pRawReader->NextEvent(); event++) {
625 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(pRawReader, event, fpEsdManager);
626 if (pHLTOUT) {
627 AliInfo(Form("event %d", event));
c63e8be4 628 // the two event fields contain: period - orbit - bunch crossing counter
629 // id[0] id[1]
630 // |32 0|32 0|
631 //
91dc3cdd 632 // | 28 bit | 24 bit | 12|
c63e8be4 633 // period orbit bcc
634 AliHLTUInt64_t eventId=0;
635 const UInt_t* rawreaderEventId=pRawReader->GetEventId();
636 if (rawreaderEventId) {
637 eventId=rawreaderEventId[0];
638 eventId=eventId<<32;
639 eventId|=rawreaderEventId[1];
640 }
641 AliInfo(Form("Event Id from rawreader:\t 0x%016llx", eventId));
b005ef92 642 ProcessHLTOUT(pHLTOUT, pEsd, true);
032c5e5e 643 delete pHLTOUT;
644 } else {
645 AliError("error creating HLTOUT handler");
646 }
647 }
648}
649
650void AliHLTReconstructor::PrintHLTOUTContent(AliHLTOUT* pHLTOUT) const
651{
652 // print the block specifications of the HLTOUT data blocks
653 if (!pHLTOUT) return;
654 int iResult=0;
655
c63e8be4 656 AliInfo(Form("Event Id from hltout:\t 0x%016llx", pHLTOUT->EventId()));
032c5e5e 657 for (iResult=pHLTOUT->SelectFirstDataBlock();
658 iResult>=0;
659 iResult=pHLTOUT->SelectNextDataBlock()) {
660 AliHLTComponentDataType dt=kAliHLTVoidDataType;
661 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
662 pHLTOUT->GetDataBlockDescription(dt, spec);
663 const AliHLTUInt8_t* pBuffer=NULL;
664 AliHLTUInt32_t size=0;
665 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
666 pHLTOUT->ReleaseDataBuffer(pBuffer);
667 pBuffer=NULL; // just a dummy
668 }
669 AliInfo(Form(" %s 0x%x: size %d", AliHLTComponent::DataType2Text(dt).c_str(), spec, size));
670 }
671}
c4ffab2c 672
673int AliHLTReconstructor::BuildCTPTriggerClassString(TString& triggerclasses) const
674{
675 // build the CTP trigger class string from the OCDB entry of the CTP trigger
676 int iResult=0;
677
678 triggerclasses.Clear();
679 AliCentralTrigger* pCTP = new AliCentralTrigger();
680 AliTriggerConfiguration *config=NULL;
681 TString configstr("");
682 if (pCTP->LoadConfiguration(configstr) &&
683 (config = pCTP->GetConfiguration())!=NULL) {
684 const TObjArray& classesArray = config->GetClasses();
685 int nclasses = classesArray.GetEntriesFast();
686 for( int iclass=0; iclass < nclasses; iclass++ ) {
687 AliTriggerClass* trclass = NULL;
688 if (classesArray.At(iclass) && (trclass=dynamic_cast<AliTriggerClass*>(classesArray.At(iclass)))!=NULL) {
689 TString entry;
690 int trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
691 entry.Form("%02d:%s:", trindex, trclass->GetName());
692 AliTriggerCluster* cluster=NULL;
693 TObject* clusterobj=config->GetClusters().FindObject(trclass->GetCluster());
694 if (clusterobj && (cluster=dynamic_cast<AliTriggerCluster*>(clusterobj))!=NULL) {
695 TString detectors=cluster->GetDetectorsInCluster();
696 TObjArray* pTokens=detectors.Tokenize(" ");
697 if (pTokens) {
698 for (int dix=0; dix<pTokens->GetEntriesFast(); dix++) {
699 int id=AliDAQ::DetectorID(((TObjString*)pTokens->At(dix))->GetString());
700 if (id>=0) {
701 TString detstr; detstr.Form("%s%02d", dix>0?"-":"", id);
702 entry+=detstr;
703 } else {
704 AliError(Form("invalid detector name extracted from trigger cluster: %s (%s)", ((TObjString*)pTokens->At(dix))->GetString().Data(), detectors.Data()));
705 iResult=-EPROTO;
706 break;
707 }
708 }
709 delete pTokens;
710 }
711 } else {
b251fffc 712 AliError(Form("can not find trigger cluster %s in config", trclass->GetCluster()?trclass->GetCluster()->GetName():"NULL"));
c4ffab2c 713 iResult=-EPROTO;
714 break;
715 }
716 if (!triggerclasses.IsNull()) triggerclasses+=",";
717 triggerclasses+=entry;
718 }
719 }
720 }
721
722 return iResult;
723}