#include <cassert>
#include "AliHLTStdIncludes.h"
#include "AliHLTSystem.h"
#include "AliHLTComponentHandler.h"
#include "AliHLTComponent.h"
#include "AliHLTConfiguration.h"
#include "AliHLTConfigurationHandler.h"
#include "AliHLTOnlineConfiguration.h"
#include "AliHLTTask.h"
#include "AliHLTModuleAgent.h"
#include "AliHLTOfflineInterface.h"
#include "AliHLTDataSource.h"
#include "AliHLTOUT.h"
#include "AliHLTOUTHandler.h"
#include "AliHLTOUTTask.h"
#include "AliHLTControlTask.h"
#include "AliHLTDataBuffer.h"
#include "AliHLTMisc.h"
#include <TObjArray.h>
#include <TObjString.h>
#include <TStopwatch.h>
#include <TList.h>
#include <TROOT.h>
const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
"libAliHLTUtil.so",
"libAliHLTRCU.so",
"libAliHLTTPC.so",
"libAliHLTCalo.so",
"libAliHLTEMCAL.so",
"libAliHLTPHOS.so",
"libAliHLTMUON.so",
"libAliHLTTRD.so",
"libAliHLTITS.so",
"libAliHLTVZERO.so",
"libAliHLTZDC.so",
"libAliHLTGlobal.so",
"libAliHLTTrigger.so",
NULL
};
ClassImp(AliHLTSystem)
AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name,
AliHLTComponentHandler* pCompHandler,
AliHLTConfigurationHandler* pConfHandler
)
: fpComponentHandler(pCompHandler==NULL?AliHLTComponentHandler::CreateHandler():pCompHandler)
, fpConfigurationHandler(pConfHandler==NULL?AliHLTConfigurationHandler::CreateHandler():pConfHandler),
fTaskList(),
fState(0),
fChains(),
fStopwatches(new TObjArray),
fEventCount(-1),
fGoodEvents(-1),
fpChainHandlers(NULL),
fpEsdHandlers(NULL),
fpProprietaryHandlers(NULL),
fpHLTOUTTask(NULL),
fpHLTOUT(NULL),
fHLTOUTUse(0),
fpControlTask(NULL),
fName(name)
, fECSParams()
, fUseHLTOUTComponentTypeGlobal(true)
, fDetMask(0)
{
if (fgNofInstances++>0) {
}
SetGlobalLoggingLevel(loglevel);
SetFrameworkLog(loglevel);
if (fpComponentHandler) {
AliHLTAnalysisEnvironment env;
memset(&env, 0, sizeof(AliHLTAnalysisEnvironment));
env.fStructSize=sizeof(AliHLTAnalysisEnvironment);
env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
env.fGetEventDoneDataFunc=AliHLTSystem::AllocEventDoneData;
env.fLoggingFunc=NULL;
fpComponentHandler->SetEnvironment(&env);
InitAliLogFunc(fpComponentHandler);
if (fgNofInstances==1) {
fpComponentHandler->AnnounceVersion();
}
} else {
HLTFatal("can not create Component Handler");
}
if (fpConfigurationHandler==NULL) {
HLTFatal("can not create Configuration Handler");
}
}
AliHLTSystem::~AliHLTSystem()
{
fgNofInstances--;
CleanupHLTOUTHandlers();
CleanTaskList();
if (fpConfigurationHandler) {
fpConfigurationHandler->Destroy();
}
fpConfigurationHandler=NULL;
if (fpComponentHandler) {
fpComponentHandler->Destroy();
}
fpComponentHandler=NULL;
delete fStopwatches;
}
int AliHLTSystem::fgNofInstances=0;
int AliHLTSystem::BuildTaskList(const char* id)
{
int iResult=0;
if (id) {
if (fpConfigurationHandler) {
AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
if (pConf) {
iResult=BuildTaskList(pConf);
} else {
HLTError("unknown configuration \"%s\"", id);
iResult=-EEXIST;
}
} else {
iResult=-EFAULT;
}
} else {
iResult=-EINVAL;
}
return iResult;
}
int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
{
int iResult=0;
if (pConf) {
AliHLTTask* pTask=NULL;
if ((pTask=FindTask(pConf->GetName()))!=NULL) {
if (pTask->GetConf()!=pConf) {
HLTError("configuration mismatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
iResult=-EEXIST;
}
pTask=NULL;
} else if (pConf->SourcesResolved()!=1 && pConf->ExtractSources(fpConfigurationHandler)!=1) {
HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
iResult=-ENOLINK;
} else {
pTask=new AliHLTTask(pConf);
if (pTask==NULL) {
iResult=-ENOMEM;
} else {
pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
}
}
static int iterationLevel=0;
if (pTask && iResult>=0) {
if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
pTask->PrintDependencyTree(pTask->GetName(), 1);
HLTError("aborted ...");
iResult=-ELOOP;
}
if (iResult>=0) {
fTaskList.Add(pTask);
AliHLTConfiguration* pDep=pConf->GetFirstSource();
while (pDep!=NULL && iResult>=0) {
HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
if (FindTask(pDep->GetName())==NULL) {
HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
iterationLevel++;
iResult=BuildTaskList(pDep);
iterationLevel--;
}
pDep=pConf->GetNextSource();
}
fTaskList.Remove(pTask);
if (iResult>=0) {
HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
iResult=InsertTask(pTask);
}
} else {
delete pTask;
pTask=NULL;
}
}
} else {
iResult=-EINVAL;
}
return iResult;
}
int AliHLTSystem::CleanTaskList()
{
int iResult=0;
fpHLTOUTTask=NULL;
fpControlTask=NULL;
TObjLink* lnk=NULL;
while ((lnk=fTaskList.LastLink())!=NULL) {
delete (lnk->GetObject());
fTaskList.Remove(lnk);
}
return iResult;
}
int AliHLTSystem::InsertTask(AliHLTTask* pTask)
{
int iResult=0;
if (fpControlTask==NULL) {
fpControlTask=new AliHLTControlTask;
if (!fpControlTask) return -ENOMEM;
fTaskList.AddFirst(fpControlTask);
}
TObjLink *controlLnk=NULL;
TObjLink *lnk = fTaskList.FirstLink();
assert(!lnk || lnk->GetObject()==fpControlTask || fpControlTask==NULL);
if (lnk && lnk->GetObject()==fpControlTask) {
if (pTask->GetConf() && pTask->GetConf()->GetFirstSource()==NULL) {
pTask->SetDependency(fpControlTask);
fpControlTask->SetTarget(pTask);
}
controlLnk=lnk;
lnk=lnk->Next();
}
if ((iResult=pTask->CheckDependencies())<=0)
lnk=NULL;
while (lnk && iResult>0) {
AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
iResult=pTask->Depends(pCurr);
if (iResult>0) {
iResult=pTask->SetDependency(pCurr);
pCurr->SetTarget(pTask);
HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
}
if (pCurr->Depends(pTask)) {
HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
iResult=-ELOOP;
} else if ((iResult=pTask->CheckDependencies())>0) {
lnk = lnk->Next();
}
}
if (iResult==0) {
if (lnk) {
fTaskList.AddAfter(lnk, pTask);
} else if (controlLnk) {
fTaskList.AddAfter(controlLnk, pTask);
} else {
fTaskList.AddFirst(pTask);
}
HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
} else if (iResult>0) {
HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
iResult=-ENOLINK;
}
return iResult;
}
AliHLTTask* AliHLTSystem::FindTask(const char* id)
{
AliHLTTask* pTask=NULL;
if (id) {
pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
}
return pTask;
}
void AliHLTSystem::PrintTaskList()
{
HLTLogKeyword("task list");
TObjLink *lnk = NULL;
HLTMessage("Task List");
lnk=fTaskList.FirstLink();
while (lnk) {
TObject* obj=lnk->GetObject();
if (obj) {
HLTMessage(" %s - status:", obj->GetName());
AliHLTTask* pTask=(AliHLTTask*)obj;
pTask->PrintStatus();
} else {
}
lnk = lnk->Next();
}
}
int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask,
AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
AliHLTUInt32_t participatingDetectors)
{
return Run(iNofEvents, bStop, AliHLTTriggerMask_t(trgMask),
timestamp, eventtype, participatingDetectors);
}
int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTTriggerMask_t trgMask,
AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
AliHLTUInt32_t participatingDetectors)
{
int iResult=0;
int iCount=0;
SetStatusFlags(kRunning);
if (fEventCount>=0 || (iResult=InitTasks())>=0) {
if (fEventCount>=0 || (iResult=StartTasks())>=0) {
if (fEventCount==0) {
InitBenchmarking(fStopwatches);
} else {
}
for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
if (fpHLTOUTTask) {
if (iNofEvents>1 && i==fEventCount) {
HLTWarning("can not add more than one event to the HLTOUT, skipping all but last block");
}
fpHLTOUTTask->Reset();
}
if (eventtype == 0) {
eventtype = gkAliEventTypeData;
participatingDetectors = 0x0;
}
if ((iResult=ProcessTasks(i, trgMask, timestamp, eventtype, participatingDetectors))>=0) {
fGoodEvents++;
iCount++;
} else {
iResult=0;
}
AliHLTDataBuffer::SetGlobalEventCount(iCount);
}
fEventCount+=iNofEvents;
if (bStop) StopTasks();
else PauseBenchmarking(fStopwatches);
}
if (bStop) DeinitTasks();
}
if (iResult>=0) {
iResult=iCount;
} else if (iResult==-126 ) {
iResult=0;
}
ClearStatusFlags(kRunning);
AliHLTDataBuffer::PrintStatistics();
return iResult;
}
int AliHLTSystem::InitTasks()
{
int iResult=0;
TObjLink *lnk=fTaskList.FirstLink();
if (lnk==NULL) {
HLTInfo("Task list is empty, skipping HLT");
return -126 ;
}
while (lnk && iResult>=0) {
TObject* obj=lnk->GetObject();
if (obj) {
AliHLTTask* pTask=(AliHLTTask*)obj;
iResult=pTask->Init(NULL, fpComponentHandler);
} else {
}
lnk = lnk->Next();
}
if (iResult<0) {
HLTError("can not initialize task list, error %d", iResult);
}
return iResult;
}
int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
{
int iResult=0;
if (pStopwatches==NULL) return 0;
for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
TStopwatch* pStopwatch= new TStopwatch;
if (pStopwatch) {
pStopwatch->Reset();
pStopwatches->AddAt(pStopwatch, i);
} else {
iResult=-ENOMEM;
break;
}
}
TObjLink *lnk=fTaskList.FirstLink();
while (lnk && iResult>=0) {
TObject* obj=lnk->GetObject();
if (obj) {
AliHLTTask* pTask=(AliHLTTask*)obj;
AliHLTComponent* pComp=NULL;
if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
switch (pComp->GetComponentType()) {
case AliHLTComponent::kProcessor:
pComp->SetStopwatches(pStopwatches);
break;
case AliHLTComponent::kSource:
{
int inputBase=(int)AliHLTComponent::kSWInput;
pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
}
break;
case AliHLTComponent::kSink:
{
int outputBase=(int)AliHLTComponent::kSWOutput;
pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
}
break;
default:
HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
}
}
} else {
}
lnk = lnk->Next();
}
return iResult;
}
int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
{
if (pStopwatches==NULL) return 0;
for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
if (!pStopwatches->At(i)) continue;
TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
if (pSw) pSw->Stop();
}
return 0;
}
int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
{
if (pStopwatches==NULL) return 0;
for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
if (!pStopwatches->At(i)) continue;
TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
if (pSw) pSw->Continue();
}
return 0;
}
int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
{
int iInitialized=1;
if (pStopwatches==NULL) return 0;
for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
iInitialized=0;
break;
}
}
if (iInitialized!=0) {
HLTImportant("HLT statistics:\n"
" base: R:%.3fs C:%.3fs\n"
" input: R:%.3fs C:%.3fs\n"
" output: R:%.3fs C:%.3fs\n"
" event processing : R:%.3fs C:%.3fs"
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
, dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
);
}
if (bClean) {
for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
TObject* pObj=pStopwatches->RemoveAt(i);
if (pObj) delete pObj;
}
}
return 0;
}
int AliHLTSystem::StartTasks()
{
int iResult=0;
TObjLink *lnk=fTaskList.FirstLink();
while (lnk && iResult>=0) {
TObject* obj=lnk->GetObject();
if (obj) {
AliHLTTask* pTask=(AliHLTTask*)obj;
iResult=pTask->StartRun();
} else {
}
lnk = lnk->Next();
}
if (iResult<0) {
HLTError("can not start task list, error %d", iResult);
} else {
SetStatusFlags(kStarted);
fEventCount=0;
fGoodEvents=0;
if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
HLTError("can not send SOR event: error %d", iResult);
}
}
return iResult;
}
int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTTriggerMask_t trgMask,
AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
AliHLTUInt32_t participatingDetectors)
{
int iResult=0;
HLTDebug("processing event no %d", eventNo);
TObjLink *lnk=fTaskList.FirstLink();
while (lnk) {
TObject* obj=lnk->GetObject();
if (obj) {
AliHLTTask* pTask=(AliHLTTask*)obj;
if (iResult>=0) {
iResult=pTask->ProcessTask(eventNo, eventtype, trgMask, timestamp, participatingDetectors);
} else {
pTask->SubscribeSourcesAndSkip();
}
} else {
}
lnk = lnk->Next();
}
if (iResult>=0) {
HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
iResult=0;
} else {
HLTError("Processing of event %d failed (%d)", eventNo, iResult);
}
return iResult;
}
int AliHLTSystem::StopTasks()
{
int iResult=0;
if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
HLTError("can not send EOR event");
}
if (fpHLTOUTTask)
fpHLTOUTTask->Reset();
TObjLink *lnk=fTaskList.FirstLink();
while (lnk) {
TObject* obj=lnk->GetObject();
if (obj) {
AliHLTTask* pTask=(AliHLTTask*)obj;
int locResult=pTask->EndRun();
if (iResult>=0 && locResult<0) iResult=locResult;
} else {
}
lnk = lnk->Next();
}
PrintBenchmarking(fStopwatches, 1 );
if (fEventCount!=fGoodEvents) {
HLTError("%d out of %d event(s) failed", fEventCount-fGoodEvents, fEventCount);
}
ClearStatusFlags(kStarted);
return iResult;
}
int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
{
int iResult=0;
AliHLTComponentBlockDataList controlBlocks;
AliHLTComponentBlockData bd;
AliHLTComponent::FillBlockData(bd);
AliHLTRunDesc runDesc;
memset(&runDesc, 0, sizeof(AliHLTRunDesc));
runDesc.fStructSize=sizeof(AliHLTRunDesc);
runDesc.fRunNo=AliHLTMisc::Instance().GetCDBRunNo();
bd.fPtr=&runDesc;
bd.fSize=sizeof(AliHLTRunDesc);
bd.fDataType=dt;
bd.fSpecification=kAliHLTVoidDataSpec;
controlBlocks.push_back(bd);
if (fECSParams.IsNull())
fECSParams="CTP_TRIGGER_CLASS=00:DUMMY-TRIGGER-ALL:00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17";
AliHLTComponent::FillBlockData(bd);
bd.fPtr=(void*)fECSParams.Data();
bd.fSize=fECSParams.Length()+1;
bd.fDataType=kAliHLTDataTypeECSParam;
bd.fSpecification=kAliHLTVoidDataSpec;
controlBlocks.push_back(bd);
AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, controlBlocks);
HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
TObjLink *lnk=fTaskList.FirstLink();
while (lnk && iResult>=0) {
TObject* obj=lnk->GetObject();
if (obj) {
AliHLTTask* pTask=(AliHLTTask*)obj;
AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun;
else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun;
else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str());
iResult=pTask->ProcessTask(-1, eventType, 0, 0);
} else {
}
lnk = lnk->Next();
}
if (fpHLTOUTTask)
fpHLTOUTTask->Reset();
HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
return iResult;
}
int AliHLTSystem::DeinitTasks()
{
int iResult=0;
TObjLink *lnk=fTaskList.LastLink();
while (lnk) {
TObject* obj=lnk->GetObject();
if (obj) {
AliHLTTask* pTask=(AliHLTTask*)obj;
int localRes=pTask->Deinit();
if (iResult>=0) iResult=localRes;
} else {
}
lnk = lnk->Prev();
}
fEventCount=-1;
fGoodEvents=-1;
return iResult;
}
int AliHLTSystem::CleanupHLTOUTHandlers()
{
if (fpChainHandlers) {
AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
fpChainHandlers=NULL;
if (pHandlers) {
AliHLTOUT::InvalidateBlocks(*pHandlers);
AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
}
assert(pHandlers->size()==0);
delete pHandlers;
}
if (fpEsdHandlers) {
AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
fpEsdHandlers=NULL;
if (pHandlers) {
AliHLTOUT::InvalidateBlocks(*pHandlers);
AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
}
assert(pHandlers->size()==0);
delete pHandlers;
}
if (fpProprietaryHandlers) {
AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
fpProprietaryHandlers=NULL;
if (pHandlers) {
AliHLTOUT::InvalidateBlocks(*pHandlers);
AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
}
assert(pHandlers->size()==0);
delete pHandlers;
}
return 0;
}
void* AliHLTSystem::AllocMemory( void* , unsigned long size )
{
void* p=NULL;
try {
p=(void*)new char[size];
}
catch (...) {
AliHLTLogging log;
log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
}
return p;
}
int AliHLTSystem::AllocEventDoneData( void* , AliHLTEventID_t , unsigned long size, AliHLTComponentEventDoneData** edd )
{
unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size;
void* block=AllocMemory(NULL, blocksize);
if (!block) return -ENOMEM;
memset(block, 0, blocksize);
*edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block);
(*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData);
(*edd)->fDataSize=size;
(*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData);
return 0;
}
int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
AliRawReader* rawReader)
{
int iResult=0;
if (runLoader || rawReader || nofEvents==0) {
if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
if (CheckStatus(kReady)) {
if (nofEvents==0) {
if (!CheckStatus(kError)) {
StopTasks();
DeinitTasks();
CleanupHLTOUTHandlers();
}
} else {
if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
AliHLTTriggerMask_t trgMask=0x1;
AliHLTUInt32_t timestamp=kMaxUInt;
AliHLTUInt32_t eventtype=0;
if (runLoader==NULL) {
trgMask=AliHLTMisc::Instance().GetTriggerMask(rawReader);
timestamp=AliHLTMisc::Instance().GetTimeStamp(rawReader);
eventtype=AliHLTMisc::Instance().GetEventType(rawReader);
}
if ((iResult=Run(nofEvents, 0, trgMask, timestamp, eventtype))<0) SetStatusFlags(kError);
}
}
if (fpHLTOUTTask) {
AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
if (pTask && (iResult=pTask->Init())>=0) {
if (pTask->GetNofDataBlocks()>0) {
AliHLTOUT* pHLTOUT=RequestHLTOUT();
if (pHLTOUT) {
pHLTOUT->AddSubCollection(pTask);
ReleaseHLTOUT(pHLTOUT);
} else {
HLTWarning("no HLTOUT instance available, output blocks of the chain are ignored");
}
}
} else {
HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
iResult=0;
}
}
} else {
HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
}
} else {
HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
iResult=-EINVAL;
}
return iResult;
}
int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
{
int iResult=0;
if (runLoader || esd) {
HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
} else {
HLTError("missing run loader/ESD instance(s)");
iResult=-EINVAL;
}
return iResult;
}
int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
{
int iResult=0;
if (!pHLTOUT) return -EINVAL;
HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
iResult=0;
}
if (!fpEsdHandlers)
fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
if (!fpProprietaryHandlers)
fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
AliHLTComponentDataTypeList esdBlocks;
for (iResult=pHLTOUT->SelectFirstDataBlock();
iResult>=0;
iResult=pHLTOUT->SelectNextDataBlock()) {
AliHLTComponentDataType dt=kAliHLTVoidDataType;
AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
pHLTOUT->GetDataBlockDescription(dt, spec);
AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
handlerType=AliHLTModuleAgent::kEsd;
}
const char* pMsg="invalid";
switch (handlerType) {
case AliHLTModuleAgent::kEsd:
{
if (pHandler) {
pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
} else {
AliHLTComponentDataTypeList::iterator element=esdBlocks.begin();
for (; element!=esdBlocks.end(); element++) {
if (*element==dt) {
HLTWarning("multiple ESDs of identical data type %s, please add appropriate handler to merge ESDs", AliHLTComponent::DataType2Text(dt).c_str());
break;
}
}
if (element==esdBlocks.end()) esdBlocks.push_back(dt);
const AliHLTUInt8_t* pBuffer=NULL;
AliHLTUInt32_t size=0;
if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
pHLTOUT->WriteESD(pBuffer, size, dt, esd);
pHLTOUT->ReleaseDataBuffer(pBuffer);
}
pHLTOUT->MarkDataBlockProcessed();
}
}
break;
case AliHLTModuleAgent::kRawReader:
break;
case AliHLTModuleAgent::kRawStream:
HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
AliHLTComponent::DataType2Text(dt).c_str(), spec);
break;
case AliHLTModuleAgent::kChain:
HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
"New block of this type added by the chain? Skipping data block ...",
pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
AliHLTComponent::DataType2Text(dt).c_str(), spec);
break;
case AliHLTModuleAgent::kProprietary:
HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
AliHLTComponent::DataType2Text(dt).c_str(), spec);
if (pHandler) {
AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
int res=pHandler->ProcessData(pHLTOUT);
if (res<0) {
HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
res, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
AliHLTComponent::DataType2Text(dt).c_str(), spec);
}
}
break;
case AliHLTModuleAgent::kUnknownOutput:
pMsg="unknown";
default:
HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
AliHLTComponent::DataType2Text(dt).c_str(), spec);
}
}
if (iResult==-ENOENT) iResult=0;
AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
AliHLTOUTHandler* pHandler=*handler;
const AliHLTUInt8_t* pBuffer=NULL;
AliHLTUInt32_t size=0;
pHandler->ProcessData(pHLTOUT);
if ((size=pHandler->GetProcessedData(pBuffer))>0) {
AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
AliHLTComponentDataType dt=desc;
pHLTOUT->WriteESD(pBuffer, size, dt, esd);
pHandler->ReleaseProcessedData(pBuffer, size);
}
pHLTOUT->MarkDataBlocksProcessed(&(*handler));
}
for (handler=pProprietaryHandlers->begin(); handler!=pProprietaryHandlers->end() && iResult>=0; handler++) {
AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
AliHLTOUTHandler* pHandler=*handler;
const AliHLTUInt8_t* pBuffer=NULL;
AliHLTUInt32_t size=0;
pHandler->ProcessData(pHLTOUT);
if ((size=pHandler->GetProcessedData(pBuffer))>0) {
HLTWarning("data produced by kProprietary handler ignored");
pHandler->ReleaseProcessedData(pBuffer, size);
}
pHLTOUT->MarkDataBlocksProcessed(&(*handler));
}
AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
return iResult;
}
int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
{
int iResult=0;
if (!pHLTOUT) return -EINVAL;
if (!fpChainHandlers)
fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
if (!pChainHandlers) return -ENOMEM;
AliHLTOUT::InvalidateBlocks(*pChainHandlers);
pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
if (chainHandler->IsEmpty()) continue;
AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));
AliHLTOUTHandler* pHandler=*chainHandler;
const AliHLTUInt8_t* pBuffer=NULL;
AliHLTUInt32_t size=0;
pHandler->ProcessData(pHLTOUT);
if ((size=pHandler->GetProcessedData(pBuffer))>0) {
AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
pHandler->ReleaseProcessedData(pBuffer, size);
}
pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
}
AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
return iResult;
}
int AliHLTSystem::LoadComponentLibraries(const char* libraries)
{
int iResult=0;
if (libraries) {
if (fpComponentHandler) {
TString libs(libraries);
TObjArray* pTokens=libs.Tokenize(" ");
if (pTokens) {
int iEntries=pTokens->GetEntriesFast();
for (int i=0; i<iEntries && iResult>=0; i++) {
if (!pTokens->At(i)) continue;
iResult=fpComponentHandler->LoadLibrary(pTokens->At(i)->GetName());
}
delete pTokens;
}
if (iResult>=0) {
SetStatusFlags(kLibrariesLoaded);
} else {
ClearStatusFlags(kLibrariesLoaded);
}
} else {
iResult=-EFAULT;
HLTFatal("no component handler available");
}
} else {
iResult=-EINVAL;
}
return iResult;
}
int AliHLTSystem::Configure(AliRunLoader* runloader)
{
return Configure(NULL, runloader);
}
int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
{
int iResult=0;
if (CheckStatus(kRunning)) {
HLTError("HLT system in running state, can not configure");
return -EBUSY;
}
ClearStatusFlags(kTaskListCreated);
if (CheckFilter(kHLTLogDebug))
AliHLTModuleAgent::PrintStatus();
if (CheckStatus(kConfigurationLoaded)==0) {
iResult=LoadConfigurations(rawReader, runloader);
} else {
if (fChains.Length()==0) {
HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
iResult=-ENOENT;
}
}
if (iResult>=0) {
SetStatusFlags(kConfigurationLoaded);
if (CheckFilter(kHLTLogDebug))
fpConfigurationHandler->PrintConfigurations();
iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
if (iResult>=0) {
SetStatusFlags(kTaskListCreated);
}
}
if (iResult<0) SetStatusFlags(kError);
return iResult;
}
int AliHLTSystem::ScanOptions(const char* options)
{
int iResult=0;
if (options) {
TString libs("");
TString excludelibs("");
TString alloptions(options);
TObjArray* pTokens=alloptions.Tokenize(" ");
if (pTokens) {
int iEntries=pTokens->GetEntriesFast();
for (int i=0; i<iEntries; i++) {
if (!pTokens->At(i)) continue;
TString token=pTokens->At(i)->GetName();
if (token.Contains("loglevel=")) {
TString param=token.ReplaceAll("loglevel=", "");
if (param.IsDigit()) {
SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
} else if (param.BeginsWith("0x") &&
param.Replace(0,2,"",0).IsHex()) {
int severity=0;
sscanf(param.Data(),"%x", &severity);
SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
} else {
HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
}
} else if (token.Contains("frameworklog=")) {
TString param=token.ReplaceAll("frameworklog=", "");
if (param.IsDigit()) {
SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
} else if (param.BeginsWith("0x") &&
param.Replace(0,2,"",0).IsHex()) {
int severity=0;
sscanf(param.Data(),"%x", &severity);
SetFrameworkLog((AliHLTComponentLogSeverity)severity);
} else {
HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
}
} else if (token.Contains("alilog=off")) {
SwitchAliLog(0);
} else if (token.Contains("config=") || token.Contains("run-online-config")) {
if (!CheckStatus(kConfigurationLoaded)) {
Int_t error=0;
AliHLTOnlineConfiguration* pConf = NULL;
if (token.Contains("run-online-config")) {
AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry("HLT/Calib/OnlineConfig");
if (pEntry) {
TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
if (pObject && pObject->IsA() == AliHLTOnlineConfiguration::Class())
pConf = (AliHLTOnlineConfiguration*)pObject;
}
}
if (token.Contains("config=")) {
TString param=token.ReplaceAll("config=", "");
if (token.EndsWith(".xml", TString::kIgnoreCase)) {
Int_t filesize = 0;
pConf = new AliHLTOnlineConfiguration;
filesize = pConf->LoadConfiguration(param.Data());
if (filesize <= 0) {
HLTError("cannot load config \'%s\'", param.Data());
iResult=-EBADF;
}
} else {
gROOT->Macro(param.Data(), &error);
if (error==0) {
SetStatusFlags(kConfigurationLoaded);
} else {
HLTError("cannot execute macro \'%s\'", param.Data());
iResult=-EBADF;
}
}
}
if (pConf) {
error = pConf->Parse();
if (error==0) {
fChains = pConf->GetDefaultChains();
libs = pConf->GetComponentLibraries();
libs += " ";
SetStatusFlags(kConfigurationLoaded);
} else {
HLTError("cannot parse online configuration");
iResult=-EBADF;
}
}
delete pConf; pConf=NULL;
} else {
HLTWarning("HLT options has both a config file and run-online-config set");
}
} else if (token.Contains("chains=")) {
TString param=token.ReplaceAll("chains=", "");
fChains=param.ReplaceAll(",", " ");
if (fChains.IsNull()) fChains=" ";
} else if (token.Contains("libmode=")) {
TString param=token.ReplaceAll("libmode=", "");
param.ReplaceAll(",", " ");
if (fpComponentHandler) {
if (param.CompareTo("static")==0) {
fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
} else if (param.CompareTo("dynamic")==0) {
fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
} else {
HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
}
}
} else if (token.BeginsWith("ECS=")) {
fECSParams=token.ReplaceAll("ECS=", "");
} else if (token.BeginsWith("hltout-mode=")) {
fUseHLTOUTComponentTypeGlobal=token.CompareTo("hltout-mode=split")!=0;
} else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
libs+=token;
libs+=" ";
} else if (token.BeginsWith("!lib") && token.EndsWith(".so")) {
excludelibs+=token;
excludelibs+=" ";
} else {
HLTWarning("unknown option \'%s\'", token.Data());
}
}
delete pTokens;
}
if (iResult>=0) {
if (libs.IsNull()) {
const char** deflib=fgkHLTDefaultLibs;
for (;*deflib; deflib++) {
if (excludelibs.Contains(*deflib)) continue;
libs+=*deflib;
libs+=" ";
}
}
if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
(LoadComponentLibraries(libs.Data())<0)) {
HLTError("error while loading HLT libraries");
iResult=-EFAULT;
}
}
}
return iResult;
}
int AliHLTSystem::Reset(int bForce)
{
int iResult=0;
if (!bForce && CheckStatus(kRunning)) {
HLTError("HLT system in running state, can not configure");
return -EBUSY;
}
CleanTaskList();
ClearStatusFlags(~kUninitialized);
return iResult;
}
int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
{
if (CheckStatus(kRunning)) {
HLTError("HLT system in running state, can not configure");
return -EBUSY;
}
int iResult=0;
AliHLTModuleAgent* pAgent=NULL;
TString extralibs;
for (pAgent=AliHLTModuleAgent::GetFirstAgent();
pAgent && iResult>=0;
pAgent=AliHLTModuleAgent::GetNextAgent()) {
const char* deplibs=pAgent->GetRequiredComponentLibraries();
if (deplibs) {
HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
extralibs+=" ";
extralibs+=deplibs;
}
}
if (iResult>=0) {
iResult=LoadComponentLibraries(extralibs.Data());
}
TList agents;
for (pAgent=AliHLTModuleAgent::GetFirstAgent();
pAgent && iResult>=0;
pAgent=AliHLTModuleAgent::GetNextAgent()) {
AliHLTModuleAgent* pPrevDep=NULL;
TString dependencies=pAgent->GetRequiredComponentLibraries();
TObjArray* pTokens=dependencies.Tokenize(" ");
if (pTokens) {
for (int n=0; n<pTokens->GetEntriesFast(); n++) {
if (!pTokens->At(n)) continue;
TString module=pTokens->At(n)->GetName();
HLTDebug(" checking %s", module.Data());
module.ReplaceAll("libAliHLT", "");
module.ReplaceAll(".so", "");
for (AliHLTModuleAgent* pCurrent=dynamic_cast<AliHLTModuleAgent*>(pPrevDep==NULL?agents.First():agents.After(pPrevDep));
pCurrent!=NULL; pCurrent=dynamic_cast<AliHLTModuleAgent*>(agents.After(pCurrent))) {
HLTDebug(" checking %s == %s", module.Data(), pCurrent->GetModuleId());
if (module.CompareTo(pCurrent->GetModuleId())==0) {
pPrevDep=pCurrent;
break;
}
}
}
delete pTokens;
}
if (pPrevDep) {
agents.AddAfter(pPrevDep, pAgent);
HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId());
} else {
agents.AddFirst(pAgent);
HLTDebug("insert %s at beginning", pAgent->GetModuleId());
}
}
if (agents.GetEntries()) {
TIter next(&agents);
while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
if(fDetMask && !(fDetMask & pAgent->GetDetectorMask())) {
HLTInfo("Skipping %s due to active detector mask.", pAgent->GetName());
} else {
HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
}
}
}
return iResult;
}
int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
{
if (CheckStatus(kRunning)) {
HLTError("HLT system in running state, can not configure");
return -EBUSY;
}
if (!CheckStatus(kConfigurationLoaded)) {
HLTWarning("configurations not yet loaded");
return 0;
}
if (!fpConfigurationHandler || !fpComponentHandler) return -EFAULT;
int iResult=0;
int bHaveOutput=0;
TString chains;
if (fChains.Length()>0) {
chains=fChains;
HLTImportant("custom reconstruction chain: %s", chains.Data());
} else {
for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
pAgent && iResult>=0;
pAgent=AliHLTModuleAgent::GetNextAgent()) {
const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
if (agentchains) {
if (!chains.IsNull()) chains+=" ";
chains+=agentchains;
HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
}
}
}
TObjArray* pTokens=chains.Tokenize(" ");
if (pTokens) {
int iEntries=pTokens->GetEntriesFast();
for (int i=0; i<iEntries && iResult>=0; i++) {
if (!pTokens->At(i)) continue;
const char* pCID=pTokens->At(i)->GetName();
AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
if (pConf) {
iResult=BuildTaskList(pConf);
if (true) {
TString cid=pConf->GetComponentID();
if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) {
chains.ReplaceAll(pCID, "");
} else if (bHaveOutput==0) {
if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
bHaveOutput=0;
chains.ReplaceAll(pCID, "");
}
}
}
} else {
HLTWarning("can not find configuration %s", pCID);
}
}
delete pTokens;
}
if (iResult>=0 && runloader) {
if (bHaveOutput) {
if (fpComponentHandler->FindComponentIndex("ROOTSchemaEvolutionComponent")>=0 ||
fpComponentHandler->LoadLibrary("libAliHLTUtil.so")>=0) {
fpConfigurationHandler->CreateConfiguration("_schemaevolution_", "ROOTSchemaEvolutionComponent",
chains.Data(), "-file=HLT.StreamerInfo.root");
iResult=BuildTaskList("_schemaevolution_");
} else {
HLTWarning("can not load libAliHLTUtil.so and ROOTSchemaEvolutionComponent");
}
if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
const char* HLTOUTComponentId="HLTOUT";
if (!fUseHLTOUTComponentTypeGlobal) {
if (rawReader) HLTOUTComponentId="HLTOUTraw";
else HLTOUTComponentId="HLTOUTdigits";
}
fpConfigurationHandler->CreateConfiguration("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
iResult=BuildTaskList("_globalout_");
} else {
HLTError("can not load libHLTsim.so and HLTOUT component");
iResult=-EFAULT;
}
}
}
if (iResult>=0 && !runloader) {
if (bHaveOutput) {
if (!fpHLTOUTTask) {
iResult=AddHLTOUTTask(chains.Data());
}
}
}
if (iResult>=0) SetStatusFlags(kTaskListCreated);
return iResult;
}
int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
{
int iResult=0;
if (!hltoutchains || hltoutchains[0]==0) return 0;
TString chains=hltoutchains;
TObjArray* pTokens=chains.Tokenize(" ");
if (pTokens) {
int iEntries=pTokens->GetEntriesFast();
for (int i=0; i<iEntries && iResult>=0; i++) {
if (!pTokens->At(i)) continue;
const char* token=pTokens->At(i)->GetName();
AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token);
if (pConf) {
TString cid=pConf->GetComponentID();
if (fpComponentHandler->HasOutputData(cid.Data())) {
continue;
}
} else {
HLTWarning("can not find configuration %s", token);
}
chains.ReplaceAll(token, "");
}
delete pTokens;
}
if (chains.IsNull()) return 0;
iResult=1;
if (fpHLTOUTTask) {
if (strcmp(chains.Data(), fpHLTOUTTask->GetSourceChains())==0) {
HLTWarning("HLTOUT task already added for chains \"%s\" %p", chains.Data(), fpHLTOUTTask);
} else {
HLTError("HLTOUT task already added for chains \"%s\" %p, ignoring new chains \"%s\"",
fpHLTOUTTask->GetSourceChains(), fpHLTOUTTask, chains.Data());
}
return iResult;
}
fpHLTOUTTask=new AliHLTOUTTask(chains);
if (fpHLTOUTTask) {
if (fpHLTOUTTask->GetConf() &&
(fpHLTOUTTask->GetConf()->SourcesResolved()>0 ||
fpHLTOUTTask->GetConf()->ExtractSources(fpConfigurationHandler)>0)) {
iResult=InsertTask(fpHLTOUTTask);
} else {
HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
iResult=-ENOENT;
}
if (iResult<0) {
delete fpHLTOUTTask;
}
} else {
iResult=-ENOMEM;
}
return iResult;
}
int AliHLTSystem::CheckStatus(int flag)
{
if (flag==kUninitialized && flag==fState) return 1;
if ((fState&flag)==flag) return 1;
return 0;
}
int AliHLTSystem::GetStatusFlags()
{
return fState;
}
int AliHLTSystem::SetStatusFlags(int flags)
{
fState|=flags;
return fState;
}
int AliHLTSystem::ClearStatusFlags(int flags)
{
fState&=~flags;
return fState;
}
AliHLTfctVoid AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
{
if (fpComponentHandler==NULL) return NULL;
return fpComponentHandler->FindSymbol(library, symbol);
}
void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
{
SetLocalLoggingLevel(level);
if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
}
int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity,
const char* originClass, const char* originFunc,
const char* file, int line, ... ) const
{
int iResult=0;
va_list args;
va_start(args, line);
if (!fName.IsNull())
AliHLTLogging::SetLogString(this, " (%p)", "%s_pfmt_: ", fName.Data());
iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, !fName.IsNull() ));
va_end(args);
return iResult;
}
int AliHLTSystem::InitHLTOUT(AliHLTOUT* instance)
{
if (!instance) return -EINVAL;
if (fpHLTOUT && fpHLTOUT!=instance) return -EBUSY;
fpHLTOUT=instance;
return 0;
}
int AliHLTSystem::InvalidateHLTOUT(AliHLTOUT** target)
{
int iResult=0;
if (fHLTOUTUse>0) {
HLTWarning("HLTOUT instance still in use, potential problem due to invalid pointer ahead");
fHLTOUTUse=0;
iResult=-EBUSY;
}
if (target) *target=fpHLTOUT;
fpHLTOUT=NULL;
return iResult;
}
AliHLTOUT* AliHLTSystem::RequestHLTOUT()
{
if (!fpHLTOUT) return NULL;
fHLTOUTUse++;
return fpHLTOUT;
}
int AliHLTSystem::ReleaseHLTOUT(const AliHLTOUT* instance)
{
if (!instance) return -EINVAL;
if (instance!=fpHLTOUT) return -ENOENT;
fHLTOUTUse--;
return 0;
}