+
+int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
+{
+ // see header file for class documentation
+ 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)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!pHLTOUT) return -EINVAL;
+ HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
+
+ //
+ // process all kChain handlers first
+ //
+ 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;
+
+ // invalidate all blocks
+ 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();
+
+ // default handling for ESD data blocks does not require an explicite handler
+ if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
+ handlerType=AliHLTModuleAgent::kEsd;
+ }
+ const char* pMsg="invalid";
+ switch (handlerType) {
+ case AliHLTModuleAgent::kEsd:
+ {
+ if (pHandler) {
+ // schedule for later processing
+ 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);
+
+ // write directly
+ 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:
+ // handled in the AliRawReaderHLT
+ 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";
+ // fall trough intended
+ 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);
+ }
+ }
+ // TODO: the return value of SelectFirst/NextDataBlock must be
+ // changed in order to avoid this check
+ if (iResult==-ENOENT) iResult=0;
+
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
+
+ // process and write all esd data blocks
+ 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));
+ }
+
+ // process all kProprietary data blocks
+ 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));
+ }
+
+ // remove all empty handlers form the list (handlers which did not get a block this time)
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
+
+ return iResult;
+}
+
+int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
+{
+ // see header file for class documentation
+ 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;
+
+ // invalidate all blocks
+ AliHLTOUT::InvalidateBlocks(*pChainHandlers);
+
+ // fill the list
+ pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
+
+ // process all defined chain handlers
+ 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;
+ //AliHLTComponentDataType dt=desc;
+
+ pHandler->ReleaseProcessedData(pBuffer, size);
+ }
+ pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
+ }
+
+ // remove all empty handlers form the list (handlers which did not get a block this time)
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
+
+ return iResult;
+}
+
+int AliHLTSystem::LoadComponentLibraries(const char* libraries)
+{
+ // see header file for class documentation
+ 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++) {
+ iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->String()).Data());
+ }
+ delete pTokens;
+ }
+ if (iResult>=0) {
+ SetStatusFlags(kLibrariesLoaded);
+ } else {
+ // lets see if we need this, probably not
+ //fpComponentHandler->UnloadLibraries();
+ ClearStatusFlags(kLibrariesLoaded);
+ }
+ } else {
+ iResult=-EFAULT;
+ HLTFatal("no component handler available");
+ }
+ } else {
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTSystem::Configure(AliRunLoader* runloader)
+{
+ // see header file for class documentation
+ return Configure(NULL, runloader);
+}
+
+int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
+{
+ // see header file for class documentation
+ 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)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (options) {
+ //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
+ TString libs("");
+ TString excludelibs("");
+ TString alloptions(options);
+ TObjArray* pTokens=alloptions.Tokenize(" ");
+ if (pTokens) {
+ int iEntries=pTokens->GetEntriesFast();
+ for (int i=0; i<iEntries; i++) {
+ TString token=(((TObjString*)pTokens->At(i))->String());
+ 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=" "; // disable all chains
+ } 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=")) {
+ // The actual parameter for argument 'hltout-mode' is treated in AliSimulation.
+ // For AliHLTSystem the occurrence with parameter 'split' signals the use of the
+ // separated HLTOUTComponents for digit and raw data. All others indicate
+ // HLTOUTComponent type 'global' where the data generation is steered from global
+ // flags
+ 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)
+{
+ // see header file for class documentation
+ 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)
+{
+ // see header file for class documentation
+ if (CheckStatus(kRunning)) {
+ HLTError("HLT system in running state, can not configure");
+ return -EBUSY;
+ }
+ int iResult=0;
+ AliHLTModuleAgent* pAgent=NULL;
+
+ // first check for the required libraries and load those
+ 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());
+ }
+
+ // in order to register the configurations in the correct sequence
+ // all agents need to be ordered with respect to the required
+ // libraries. Ordering relies on the naming convention
+ // libAliHLT<Module>.so
+ 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++) {
+ TString module=((TObjString*)pTokens->At(n))->String();
+ 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) {
+ // insert right after the last dependency
+ agents.AddAfter(pPrevDep, pAgent);
+ HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId());
+ } else {
+ // insert at the beginning
+ agents.AddFirst(pAgent);
+ HLTDebug("insert %s at beginning", pAgent->GetModuleId());
+ }
+ }
+
+ // now we load the configurations
+ if (agents.GetEntries()) {
+ TIter next(&agents);
+ while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
+ HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
+ pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
+ }
+ }
+
+ return iResult;
+}
+
+int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
+{
+ // see header file for class documentation
+ if (CheckStatus(kRunning)) {
+ HLTError("HLT system in running state, can not configure");
+ return -EBUSY;
+ }
+ if (!CheckStatus(kConfigurationLoaded)) {
+ HLTWarning("configurations not yet loaded");
+ return 0;
+ }
+
+ int iResult=0;
+ int bHaveOutput=0;
+
+ // query chains
+ 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);
+ }
+ }
+ }
+
+ // build task list for chains
+ TObjArray* pTokens=chains.Tokenize(" ");
+ if (pTokens) {
+ int iEntries=pTokens->GetEntriesFast();
+ for (int i=0; i<iEntries && iResult>=0; i++) {
+ const char* pCID=((TObjString*)pTokens->At(i))->String().Data();
+ AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
+ if (pConf) {
+ iResult=BuildTaskList(pConf);
+ if (true) { // condition was deprecated but kept for sake of svn diff
+ // bHaveOutput variable has to be set for both running modes
+ // AliHLTSimulation and AliHLTReconstruction
+ assert(fpComponentHandler!=NULL);
+ TString cid=pConf->GetComponentID();
+ if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) {
+ // remove from the input of a global HLTOUT configuration
+ chains.ReplaceAll(pCID, "");
+ } else if (bHaveOutput==0) {
+ // check whether this configuration produces data output
+ if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
+ bHaveOutput=0;
+ chains.ReplaceAll(pCID, "");
+ }
+ }
+ }
+ } else {
+ HLTWarning("can not find configuration %s", pCID);
+ }
+ }
+ delete pTokens;
+ }
+
+ // build HLTOUT for simulation
+ if (iResult>=0 && runloader) {
+ if (bHaveOutput) {
+ // there are components in the chain which produce data which need to be
+ // piped to an HLTOUT
+
+ // add the SchemaEvolutionComponent which analyzes the ROOT objects in
+ // the output stream
+ if (fpComponentHandler->FindComponentIndex("ROOTSchemaEvolutionComponent")>=0 ||
+ fpComponentHandler->LoadLibrary("libAliHLTUtil.so")>=0) {
+ AliHLTConfiguration schemaevo("_schemaevolution_", "ROOTSchemaEvolutionComponent",
+ chains.Data(), "-file=HLT.StreamerInfo.root");
+ iResult=BuildTaskList("_schemaevolution_");
+ } else {
+ HLTWarning("can not load libAliHLTUtil.so and ROOTSchemaEvolutionComponent");
+ }
+
+ // add the HLTOUT component
+ if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
+ fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
+ // for the default HLTOUTComponent type 'global' the data generation is steered
+ // by global flags from AliSimulation. This allows for emulation of the old
+ // AliHLTSimulation behavior where only one chain is run on either digits or
+ // simulated raw data and the HLT digits and raw files have been generated
+ // depending on the configuration
+ const char* HLTOUTComponentId="HLTOUT";
+ if (!fUseHLTOUTComponentTypeGlobal) {
+ // choose the type of output depending on the availability of
+ // the raw reader
+ if (rawReader) HLTOUTComponentId="HLTOUTraw";
+ else HLTOUTComponentId="HLTOUTdigits";
+ }
+ AliHLTConfiguration globalout("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
+ iResult=BuildTaskList("_globalout_");
+ } else {
+ HLTError("can not load libHLTsim.so and HLTOUT component");
+ iResult=-EFAULT;
+ }
+ }
+ }
+
+ // build HLTOUT task for reconstruction
+ // Matthias 08.07.2008 the rawReader is never set when running embedded into
+ // AliReconstruction. The system is configured during AliHLTReconstructor::Init
+ // where the RawReader is not available. It is available in the first invocation
+ // of Reconstruct.
+ //
+ // That means that policy is slightly changed:
+ // - if the run loader is available -> AliSimulation
+ // - no run loader available -> AliReconstruction
+ if (iResult>=0 && !runloader) {
+ if (bHaveOutput) {
+ // there are components in the chain which produce data which need to be
+ // piped to an HLTOUT sub-collection
+ if (!fpHLTOUTTask) {
+ iResult=AddHLTOUTTask(chains.Data());
+ }
+ }
+ }
+
+ if (iResult>=0) SetStatusFlags(kTaskListCreated);
+
+ return iResult;
+}
+
+int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!hltoutchains || hltoutchains[0]==0) return 0;
+
+ // check chains for output
+ TString chains=hltoutchains;
+ TObjArray* pTokens=chains.Tokenize(" ");
+ if (pTokens) {
+ int iEntries=pTokens->GetEntriesFast();
+ for (int i=0; i<iEntries && iResult>=0; i++) {
+ const char* token=((TObjString*)pTokens->At(i))->String().Data();
+ 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);
+ }
+ // remove from the list of hltout chains
+ chains.ReplaceAll(token, "");
+ }
+ delete pTokens;
+ }
+
+ // do not create the HLTOUT task if none of the chains have output
+ if (chains.IsNull()) return 0;
+
+ // indicate the task to be available
+ 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()>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)
+{
+ // see header file for class documentation
+ if (flag==kUninitialized && flag==fState) return 1;
+ if ((fState&flag)==flag) return 1;
+ return 0;
+}
+
+int AliHLTSystem::GetStatusFlags()
+{
+ // see header file for class documentation
+ return fState;
+}
+
+int AliHLTSystem::SetStatusFlags(int flags)
+{
+ // see header file for class documentation
+ fState|=flags;
+ return fState;
+}
+
+int AliHLTSystem::ClearStatusFlags(int flags)
+{
+ // see header file for class documentation
+ fState&=~flags;
+ return fState;
+}
+
+AliHLTfctVoid AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
+{
+ // see header file for class documentation
+ if (fpComponentHandler==NULL) return NULL;
+ return fpComponentHandler->FindSymbol(library, symbol);
+}
+
+void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
+{
+ // see header file for class documentation
+ 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
+{
+ // see header file for function documentation
+ 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() /*append if non empty*/));
+ va_end(args);
+
+ return iResult;
+}
+
+int AliHLTSystem::InitHLTOUT(AliHLTOUT* instance)
+{
+ // Init the HLTOUT instance for the current event.
+ // The instance can be used by other classes to get hold on the data
+ // from HLTOUT.
+ if (!instance) return -EINVAL;
+ if (fpHLTOUT && fpHLTOUT!=instance) return -EBUSY;
+ fpHLTOUT=instance;
+ return 0;
+}
+
+int AliHLTSystem::InvalidateHLTOUT(AliHLTOUT** target)
+{
+ // Clear the HLTOUT instance.
+ 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()
+{
+ // Get the HLTOUT instance.
+ // User method for processing classes. To be released after use.
+ if (!fpHLTOUT) return NULL;
+ fHLTOUTUse++;
+ return fpHLTOUT;
+}
+
+int AliHLTSystem::ReleaseHLTOUT(const AliHLTOUT* instance)
+{
+ // Release the HLTOUT instance after use.
+ if (!instance) return -EINVAL;
+ if (instance!=fpHLTOUT) return -ENOENT;
+ fHLTOUTUse--;
+ return 0;
+}