]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliHLTReconstructor.cxx
The LHC clock phase stored also in the Raw2SDigits method. Temporary solution
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTReconstructor.cxx
CommitLineData
3e820254 1// $Id$
2
c5123824 3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
10//* Permission to use, copy, modify and distribute this software and its *
11//* documentation strictly for non-commercial purposes is hereby granted *
12//* without fee, provided that the above copyright notice appears in all *
13//* copies and that both the copyright notice and this permission notice *
14//* appear in the supporting documentation. The authors make no claims *
15//* about the suitability of this software for any purpose. It is *
16//* provided "as is" without express or implied warranty. *
17//**************************************************************************
c534985b 18
69edd0d6 19// @file AliHLTReconstructor.cxx
20// @author Matthias Richter
21// @date
22// @brief Binding class for HLT reconstruction in AliRoot
23// Implements bot the interface to run HLT chains embedded into
24// AliReconstruction and the unpacking and treatment of HLTOUT
3e820254 25
26#include <TSystem.h>
27#include <TObjString.h>
032c5e5e 28#include "TFile.h"
29#include "TTree.h"
dc5556e5 30#include "TObject.h"
31#include "TObjArray.h"
32#include "TClass.h"
33#include "TStreamerInfo.h"
3e820254 34#include "AliHLTReconstructor.h"
35#include "AliLog.h"
032c5e5e 36#include "AliRawReader.h"
c5123824 37#include "AliESDEvent.h"
3e820254 38#include "AliHLTSystem.h"
c5123824 39#include "AliHLTOUTRawReader.h"
40#include "AliHLTOUTDigitReader.h"
41#include "AliHLTEsdManager.h"
00ddfaca 42#include "AliHLTPluginBase.h"
dc5556e5 43#include "AliHLTMisc.h"
44#include "AliCDBManager.h"
45#include "AliCDBEntry.h"
d3382be1 46#include "AliHLTMessage.h"
c4ffab2c 47#include "AliCentralTrigger.h"
48#include "AliTriggerConfiguration.h"
49#include "AliTriggerClass.h"
50#include "AliTriggerCluster.h"
51#include "AliDAQ.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)
3e820254 63{
64 //constructor
65}
66
032c5e5e 67AliHLTReconstructor::AliHLTReconstructor(const char* options)
69edd0d6 68 : AliReconstructor()
69 , fpEsdManager(NULL)
70 , fpPluginBase(new AliHLTPluginBase)
3eb6bcbe 71 , fFlags(0)
032c5e5e 72{
73 //constructor
74 if (options) Init(options);
75}
76
3e820254 77AliHLTReconstructor::~AliHLTReconstructor()
78{
79 //destructor
dee38f1b 80
00ddfaca 81 if (fpPluginBase) {
82 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
a3ef3c1d 83 if (pSystem) {
00ddfaca 84 AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
3dd8541e 85 if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
dee38f1b 86 // send specific 'event' to execute the stop sequence
a3ef3c1d 87 pSystem->Reconstruct(0, NULL, NULL);
dee38f1b 88 }
3e820254 89 }
00ddfaca 90 delete fpPluginBase;
91 }
92 fpPluginBase=NULL;
c5123824 93
f1207f29 94 if (fpEsdManager) AliHLTEsdManager::Delete(fpEsdManager);
c5123824 95 fpEsdManager=NULL;
3e820254 96}
97
032c5e5e 98void AliHLTReconstructor::Init(const char* options)
99{
100 // init the reconstructor
101 SetOption(options);
102 Init();
103}
104
3e820254 105void AliHLTReconstructor::Init()
106{
107 // init the reconstructor
00ddfaca 108 if (!fpPluginBase) {
109 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
110 return;
111 }
112
113 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
a3ef3c1d 114 if (!pSystem) {
3e820254 115 AliError("can not create AliHLTSystem object");
116 return;
117 }
a3ef3c1d 118 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
3e820254 119 AliError("HLT system in error state");
120 return;
121 }
122
21d97a90 123 TString esdManagerOptions;
124
3e820254 125 // the options scan has been moved to AliHLTSystem, the old code
126 // here is kept to be able to run an older version of the HLT code
127 // with newer AliRoot versions.
3e820254 128 TString option = GetOption();
129 TObjArray* pTokens=option.Tokenize(" ");
130 option="";
131 if (pTokens) {
132 int iEntries=pTokens->GetEntries();
133 for (int i=0; i<iEntries; i++) {
134 TString token=(((TObjString*)pTokens->At(i))->GetString());
135 if (token.Contains("loglevel=")) {
136 TString param=token.ReplaceAll("loglevel=", "");
137 if (param.IsDigit()) {
a3ef3c1d 138 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
3e820254 139 } else if (param.BeginsWith("0x") &&
140 param.Replace(0,2,"",0).IsHex()) {
141 int severity=0;
142 sscanf(param.Data(),"%x", &severity);
a3ef3c1d 143 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
3e820254 144 } else {
145 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
146 }
147 } else if (token.Contains("alilog=off")) {
a3ef3c1d 148 pSystem->SwitchAliLog(0);
3eb6bcbe 149 } else if (token.CompareTo("ignore-hltout")==0) {
150 fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
75cbb181 151 } else if (token.CompareTo("ignore-ctp")==0) {
152 fFlags|=kAliHLTReconstructorIgnoreCTP;
21d97a90 153 } else if (token.Contains("esdmanager=")) {
154 token.ReplaceAll("esdmanager=", "");
155 token.ReplaceAll(","," ");
156 token.ReplaceAll("'","");
157 esdManagerOptions=token;
3e820254 158 } else {
159 if (option.Length()>0) option+=" ";
160 option+=token;
161 }
162 }
163 delete pTokens;
164 }
7f9ab840 165
c4ffab2c 166 TString ecsParam;
167 TString ctpParam;
75cbb181 168 if ((fFlags&kAliHLTReconstructorIgnoreCTP)==0 &&
169 BuildCTPTriggerClassString(ctpParam)>=0) {
c4ffab2c 170 if (!ecsParam.IsNull()) ecsParam+=";";
171 ecsParam+="CTP_TRIGGER_CLASS=";
172 ecsParam+=ctpParam;
173 }
174
175 if (!ecsParam.IsNull()) {
176 option+=" ECS=";
177 option+=ecsParam;
178 }
179
a3ef3c1d 180 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
69edd0d6 181 if (pSystem->ScanOptions(option.Data())<0) {
3e820254 182 AliError("error setting options for HLT system");
3e820254 183 return;
184 }
a3ef3c1d 185 if ((pSystem->Configure())<0) {
3e820254 186 AliError("error during HLT system configuration");
187 return;
188 }
189 }
c5123824 190
f1207f29 191 fpEsdManager=AliHLTEsdManager::New();
21d97a90 192 fpEsdManager->SetOption(esdManagerOptions.Data());
dc5556e5 193
194 InitStreamerInfos();
195}
196
197const char* AliHLTReconstructor::fgkCalibStreamerInfoEntry="HLT/Calib/StreamerInfo";
198
199int AliHLTReconstructor::InitStreamerInfos()
200{
201 // init streamer infos for HLT reconstruction
202 // Root schema evolution is not enabled for AliHLTMessage and all streamed objects.
203 // Objects in the raw data payload rely on the availability of the correct stream info.
204 // The relevant streamer info for a specific run is stored in the OCDB.
205 // The method evaluates the following entries:
206 // - HLT/Calib/StreamerInfo
04fa92ff 207 int iResult=0;
dc5556e5 208
209 // to be activated later, this is supposed to go as patch into the v4-17-Release branch
210 // which doe snot have the AliHLTMisc implementation
211 //AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(fgkCalibStreamerInfoEntry);
212 AliCDBEntry* pEntry=AliCDBManager::Instance()->Get(fgkCalibStreamerInfoEntry);
213 TObject* pObject=NULL;
214 //if (pEntry && (pObject=AliHLTMisc::Instance().ExtractObject(pEntry))!=NULL)
215 if (pEntry && (pObject=pEntry->GetObject())!=NULL)
216 {
217 TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject);
218 if (pSchemas) {
04fa92ff 219 iResult=InitStreamerInfos(pSchemas);
d3382be1 220 } else {
221 AliError(Form("internal mismatch in OCDB entry %s: wrong class type", fgkCalibStreamerInfoEntry));
222 }
223 } else {
224 AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", fgkCalibStreamerInfoEntry));
225 }
04fa92ff 226 return iResult;
d3382be1 227}
228
229int AliHLTReconstructor::InitStreamerInfos(TObjArray* pSchemas) const
230{
231 // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects
232
233 for (int i=0; i<pSchemas->GetEntriesFast(); i++) {
234 if (pSchemas->At(i)) {
235 TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i));
236 if (pSchema) {
237 int version=pSchema->GetClassVersion();
238 TClass* pClass=TClass::GetClass(pSchema->GetName());
239 if (pClass) {
240 if (pClass->GetClassVersion()==version) {
241 AliDebug(0,Form("skipping schema definition %d version %d to class %s as this is the native version", i, version, pSchema->GetName()));
242 continue;
243 }
244 TObjArray* pInfos=pClass->GetStreamerInfos();
245 if (pInfos /*&& version<pInfos->GetEntriesFast()*/) {
246 if (pInfos->At(version)==NULL) {
247 TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone();
248 if (pClone) {
249 pClone->SetClass(pClass);
250 pClone->BuildOld();
251 pInfos->AddAtAndExpand(pClone, version);
252 AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName()));
dc5556e5 253 } else {
d3382be1 254 AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName()));
dc5556e5 255 }
256 } else {
d3382be1 257 TStreamerInfo* pInfo=dynamic_cast<TStreamerInfo*>(pInfos->At(version));
258 if (pInfo && pInfo->GetClassVersion()==version) {
259 AliDebug(0,Form("schema definition %d version %d already available in class %s, skipping ...", i, version, pSchema->GetName()));
260 } else {
261 AliError(Form("can not verify version for already existing schema definition %d (%s) version %d: version of existing definition is %d", i, pSchema->GetName(), version, pInfo?pInfo->GetClassVersion():-1));
262 }
dc5556e5 263 }
264 } else {
d3382be1 265 AliError(Form("skipping schema definition %d (%s), unable to set version %d in info array of size %d", i, pSchema->GetName(), version, pInfos?pInfos->GetEntriesFast():-1));
dc5556e5 266 }
d3382be1 267 } else {
268 AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName()));
dc5556e5 269 }
d3382be1 270 } else {
271 AliError(Form("skipping schema definition %d, not of TStreamerInfo", i));
dc5556e5 272 }
dc5556e5 273 }
dc5556e5 274 }
df0cb666 275
276 return 0;
3e820254 277}
278
06995b88 279void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clustersTree*/) const
3e820254 280{
281 // reconstruction of real data without writing of ESD
c5123824 282 // For each event, HLT reconstruction chains can be executed and
283 // added to the existing HLTOUT data
284 // The HLTOUT data is finally processed in FillESD
00ddfaca 285 if (!fpPluginBase) {
286 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
287 return;
288 }
289
3e820254 290 int iResult=0;
00ddfaca 291 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
06995b88 292
a3ef3c1d 293 if (pSystem) {
294 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
3e820254 295 AliError("HLT system in error state");
296 return;
297 }
a3ef3c1d 298 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
3e820254 299 AliError("HLT system in wrong state");
300 return;
301 }
a3ef3c1d 302 if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
c5123824 303 }
304 }
06995b88 305}
306
307void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/,
308 AliESDEvent* esd) const
309{
310 // reconstruct real data and fill ESD
311 if (!rawReader || !esd) {
312 AliError("missing raw reader or esd object");
313 return;
314 }
315
00ddfaca 316 if (!fpPluginBase) {
317 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
318 return;
319 }
320
321 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 322
323 if (pSystem) {
324 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
325 AliError("HLT system in error state");
326 return;
327 }
328 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
329 AliError("HLT system in wrong state");
330 return;
331 }
332 pSystem->FillESD(-1, NULL, esd);
333
3eb6bcbe 334 AliRawReader* input=NULL;
335 if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
336 input=rawReader;
337 }
338 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(input, esd->GetEventNumberInFile(), fpEsdManager);
c5123824 339 if (pHLTOUT) {
0bba252a 340 ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
f94e8c27 341 delete pHLTOUT;
c5123824 342 } else {
343 AliError("error creating HLTOUT handler");
3e820254 344 }
345 }
346}
7f9ab840 347
29312178 348void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
7f9ab840 349{
350 // reconstruct simulated data
351
352 // all reconstruction has been moved to FillESD
353 //AliReconstructor::Reconstruct(digitsTree,clustersTree);
032c5e5e 354 AliInfo("running digit data reconstruction");
7f9ab840 355}
356
c5123824 357void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
7f9ab840 358{
359 // reconstruct simulated data and fill ESD
360
361 // later this is the place to extract the simulated HLT data
362 // for now it's only an user failure condition as he tries to run HLT reconstruction
363 // on simulated data
364 TString option = GetOption();
c5123824 365 if (!option.IsNull() &&
366 (option.Contains("config=") || option.Contains("chains="))) {
f8e0e3d3 367 AliWarning(Form("HLT reconstruction can be run embedded into Alireconstruction from\n"
368 "raw data (real or simulated)). Reconstruction of of digit data takes\n"
369 "place in AliSimulation, appropriate input conversion is needed.\n"
370 "Consider running embedded into AliSimulation."
7f9ab840 371 " /*** run macro *****************************************/\n"
372 " AliSimulation sim;\n"
373 " sim.SetRunHLT(\"%s\");\n"
374 " sim.SetRunGeneration(kFALSE);\n"
375 " sim.SetMakeDigits(\"\");\n"
376 " sim.SetMakeSDigits(\"\");\n"
377 " sim.SetMakeDigitsFromHits(\"\");\n"
378 " sim.Run();\n"
379 " /*********************************************************/", option.Data()));
380 }
00ddfaca 381 if (!fpPluginBase) {
382 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
383 return;
384 }
385
386 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 387 if (pSystem) {
388 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
389 AliError("HLT system in error state");
390 return;
391 }
392 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
393 AliError("HLT system in wrong state");
394 return;
395 }
396
397 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
398 if (pHLTOUT) {
fbe9adaf 399 ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
f94e8c27 400 delete pHLTOUT;
c5123824 401 } else {
402 AliError("error creating HLTOUT handler");
403 }
404 }
405}
406
b005ef92 407void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd, bool bVerbose) const
c5123824 408{
f94e8c27 409 // treatment of simulated or real HLTOUT data
c5123824 410 if (!pHLTOUT) return;
00ddfaca 411 if (!fpPluginBase) {
412 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
413 return;
414 }
415
416 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 417 if (!pSystem) {
418 AliError("error getting HLT system instance");
419 return;
420 }
421
422 if (pHLTOUT->Init()<0) {
423 AliError("error : initialization of HLTOUT handler failed");
424 return;
425 }
426
b005ef92 427 if (bVerbose)
428 PrintHLTOUTContent(pHLTOUT);
429
d3382be1 430 int blockindex=pHLTOUT->SelectFirstDataBlock(kAliHLTDataTypeStreamerInfo);
431 if (blockindex>=0) {
432 const AliHLTUInt8_t* pBuffer=NULL;
433 AliHLTUInt32_t size=0;
434 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
435 TObject* pObject=AliHLTMessage::Extract(pBuffer, size);
436 if (pObject) {
437 TObjArray* pArray=dynamic_cast<TObjArray*>(pObject);
438 if (pArray) {
439 InitStreamerInfos(pArray);
440 } else {
441 AliError(Form("wrong class type of streamer info list: expected TObjArray, but object is of type %s", pObject->Class()->GetName()));
442 }
443 } else {
444 AliError(Form("failed to extract object from data block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
445 }
446 } else {
447 AliError(Form("failed to get data buffer for block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
448 }
449 }
450
69edd0d6 451 if (pSystem->ProcessHLTOUT(pHLTOUT, esd)<0) {
452 AliError("error processing HLTOUT");
c5123824 453 }
69edd0d6 454
fbe9adaf 455 if (bVerbose) {
456 AliInfo("HLT ESD content:");
457 esd->Print();
458 }
b005ef92 459 pHLTOUT->Reset();
7f9ab840 460}
032c5e5e 461
462void AliHLTReconstructor::ProcessHLTOUT(const char* digitFile, AliESDEvent* pEsd) const
463{
464 // debugging/helper function to examine simulated data
465 if (!digitFile) return;
466
467 // read the number of events
468 TFile f(digitFile);
469 if (f.IsZombie()) return;
470 TTree* pTree=NULL;
471 f.GetObject("rawhltout", pTree);
472 if (!pTree) {
473 AliWarning(Form("can not find tree rawhltout in file %s", digitFile));
474 return ;
475 }
476 int nofEvents=pTree->GetEntries();
477 f.Close();
478 //delete pTree; OF COURSE NOT! its an object in the file
479 pTree=NULL;
480
481 for (int event=0; event<nofEvents; event++) {
482 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(event, fpEsdManager, digitFile);
483 if (pHLTOUT) {
484 AliInfo(Form("event %d", event));
b005ef92 485 ProcessHLTOUT(pHLTOUT, pEsd, true);
032c5e5e 486 delete pHLTOUT;
487 } else {
488 AliError("error creating HLTOUT handler");
489 }
490 }
491}
492
493void AliHLTReconstructor::ProcessHLTOUT(AliRawReader* pRawReader, AliESDEvent* pEsd) const
494{
495 // debugging/helper function to examine simulated or real HLTOUT data
496 if (!pRawReader) return;
497
498 pRawReader->RewindEvents();
499 for (int event=0; pRawReader->NextEvent(); event++) {
500 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(pRawReader, event, fpEsdManager);
501 if (pHLTOUT) {
502 AliInfo(Form("event %d", event));
c63e8be4 503 // the two event fields contain: period - orbit - bunch crossing counter
504 // id[0] id[1]
505 // |32 0|32 0|
506 //
91dc3cdd 507 // | 28 bit | 24 bit | 12|
c63e8be4 508 // period orbit bcc
509 AliHLTUInt64_t eventId=0;
510 const UInt_t* rawreaderEventId=pRawReader->GetEventId();
511 if (rawreaderEventId) {
512 eventId=rawreaderEventId[0];
513 eventId=eventId<<32;
514 eventId|=rawreaderEventId[1];
515 }
516 AliInfo(Form("Event Id from rawreader:\t 0x%016llx", eventId));
b005ef92 517 ProcessHLTOUT(pHLTOUT, pEsd, true);
032c5e5e 518 delete pHLTOUT;
519 } else {
520 AliError("error creating HLTOUT handler");
521 }
522 }
523}
524
525void AliHLTReconstructor::PrintHLTOUTContent(AliHLTOUT* pHLTOUT) const
526{
527 // print the block specifications of the HLTOUT data blocks
528 if (!pHLTOUT) return;
529 int iResult=0;
530
c63e8be4 531 AliInfo(Form("Event Id from hltout:\t 0x%016llx", pHLTOUT->EventId()));
032c5e5e 532 for (iResult=pHLTOUT->SelectFirstDataBlock();
533 iResult>=0;
534 iResult=pHLTOUT->SelectNextDataBlock()) {
535 AliHLTComponentDataType dt=kAliHLTVoidDataType;
536 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
537 pHLTOUT->GetDataBlockDescription(dt, spec);
538 const AliHLTUInt8_t* pBuffer=NULL;
539 AliHLTUInt32_t size=0;
540 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
541 pHLTOUT->ReleaseDataBuffer(pBuffer);
542 pBuffer=NULL; // just a dummy
543 }
544 AliInfo(Form(" %s 0x%x: size %d", AliHLTComponent::DataType2Text(dt).c_str(), spec, size));
545 }
546}
c4ffab2c 547
548int AliHLTReconstructor::BuildCTPTriggerClassString(TString& triggerclasses) const
549{
550 // build the CTP trigger class string from the OCDB entry of the CTP trigger
551 int iResult=0;
552
553 triggerclasses.Clear();
554 AliCentralTrigger* pCTP = new AliCentralTrigger();
555 AliTriggerConfiguration *config=NULL;
556 TString configstr("");
557 if (pCTP->LoadConfiguration(configstr) &&
558 (config = pCTP->GetConfiguration())!=NULL) {
559 const TObjArray& classesArray = config->GetClasses();
560 int nclasses = classesArray.GetEntriesFast();
561 for( int iclass=0; iclass < nclasses; iclass++ ) {
562 AliTriggerClass* trclass = NULL;
563 if (classesArray.At(iclass) && (trclass=dynamic_cast<AliTriggerClass*>(classesArray.At(iclass)))!=NULL) {
564 TString entry;
565 int trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
566 entry.Form("%02d:%s:", trindex, trclass->GetName());
567 AliTriggerCluster* cluster=NULL;
568 TObject* clusterobj=config->GetClusters().FindObject(trclass->GetCluster());
569 if (clusterobj && (cluster=dynamic_cast<AliTriggerCluster*>(clusterobj))!=NULL) {
570 TString detectors=cluster->GetDetectorsInCluster();
571 TObjArray* pTokens=detectors.Tokenize(" ");
572 if (pTokens) {
573 for (int dix=0; dix<pTokens->GetEntriesFast(); dix++) {
574 int id=AliDAQ::DetectorID(((TObjString*)pTokens->At(dix))->GetString());
575 if (id>=0) {
576 TString detstr; detstr.Form("%s%02d", dix>0?"-":"", id);
577 entry+=detstr;
578 } else {
579 AliError(Form("invalid detector name extracted from trigger cluster: %s (%s)", ((TObjString*)pTokens->At(dix))->GetString().Data(), detectors.Data()));
580 iResult=-EPROTO;
581 break;
582 }
583 }
584 delete pTokens;
585 }
586 } else {
587 AliError(Form("can not find trigger cluster %s in config", trclass->GetCluster()));
588 iResult=-EPROTO;
589 break;
590 }
591 if (!triggerclasses.IsNull()) triggerclasses+=",";
592 triggerclasses+=entry;
593 }
594 }
595 }
596
597 return iResult;
598}