#include "AliHLTComponent.h"
#include "AliHLTComponentHandler.h"
#include "AliHLTMessage.h"
+#include "AliHLTCTPData.h"
#include "TString.h"
#include "TMath.h"
#include "TObjArray.h"
#include "TObjectTable.h"
#include "TClass.h"
#include "TStopwatch.h"
+#include "TFormula.h"
#include "AliHLTMemoryFile.h"
#include "AliHLTMisc.h"
#include <cassert>
+#include <ctime>
#include <stdint.h>
/**
fEventDoneDataSize(0),
fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
, fLastObjectSize(0)
+ , fpCTPData(NULL)
+ , fPushbackPeriod(0)
+ , fLastPushBackTime(-1)
{
// see header file for class documentation
// or
}
if (fEventDoneData)
delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
+ fEventDoneData=NULL;
+
+ if (fpCTPData) {
+ delete fpCTPData;
+ }
+ fpCTPData=NULL;
}
AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
return SetGlobalComponentHandler(NULL,1);
}
-int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
+int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
{
// see header file for function documentation
HLTLogKeyword(fChainId.c_str());
fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
fEnvironment.fParam=environParam;
}
+ return iResult;
+}
+
+int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
+{
+ // see header file for function documentation
+ HLTLogKeyword(fChainId.c_str());
+ int iResult=0;
+ if (comenv) {
+ SetComponentEnvironment(comenv, environParam);
+ }
+ fPushbackPeriod=0;
+ fLastPushBackTime=-1;
+
fComponentArgs="";
const char** pArguments=NULL;
int iNofChildArgs=0;
} else {
HLTError("wrong parameter for argument -object-compression, number expected");
}
+ // -pushback-period=
+ } else if (argument.BeginsWith("-pushback-period=")) {
+ argument.ReplaceAll("-pushback-period=", "");
+ if (argument.IsDigit()) {
+ fPushbackPeriod=argument.Atoi();
+ } else {
+ HLTError("wrong parameter for argument -pushback-period, number expected");
+ }
} else {
pArguments[iNofChildArgs++]=argv[i];
}
int iResult=0;
iResult=DoDeinit();
if (fpRunDesc) {
- HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
+ // TODO: the warning should be kept, but the condition is wrong since the
+ // AliHLTRunDesc is set before the SOR event in the SetRunDescription
+ // method. A couple of state flags should be defined but that is a bit more
+ // work to do. For the moment disable the warning (2009-07-01)
+ // 2009-09-08: now, the info is not cleared in the ProcessEvent, because it
+ // might be needed by components during the event processing.
+ //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
AliHLTRunDesc* pRunDesc=fpRunDesc;
fpRunDesc=NULL;
delete pRunDesc;
}
+ if (fpCTPData) {
+ delete fpCTPData;
+ }
+ fpCTPData=NULL;
+
fEventCount=0;
return iResult;
}
{
// see header file for function documentation
int iResult=0;
+ HLTInfo("Using CDB: %s", cdbPath);
if (pHandler) {
// I have to think about separating the library handling from the
- // component handler. Requiring the component hanlder here is not
+ // component handler. Requiring the component handler here is not
// the cleanest solution.
- // We presume the library already to be loaded
+ // We presume the library already to be loaded, which is the case
+ // because it is loaded in the initialization of the logging functionality
+ //
// find the symbol
AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
if (pFunc) {
TString descriptor=desc;
TObjArray* pTokens=descriptor.Tokenize(" ");
if (pTokens) {
- for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
+ for (int i=0; i<pTokens->GetEntriesFast() && iResult>=0; i++) {
TString argument=((TObjString*)pTokens->At(i++))->GetString();
if (!argument || argument.IsNull()) continue;
return iResult;
}
+int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
+{
+ // see header file for function documentation
+ int iResult=0;
+ vector<const char*> array;
+ TObjArray choppedArguments;
+ TString argument="";
+ int i=0;
+ for (i=0; i<argc && iResult>=0; i++) {
+ argument=argv[i];
+ if (argument.IsNull()) continue;
+ TObjArray* pTokens=argument.Tokenize(" ");
+ if (pTokens) {
+ if (pTokens->GetEntriesFast()>0) {
+ for (int n=0; n<pTokens->GetEntriesFast(); n++) {
+ choppedArguments.AddLast(pTokens->At(n));
+ TString data=((TObjString*)pTokens->At(n))->GetString();
+ if (!data.IsNull()) {
+ array.push_back(data.Data());
+ }
+ }
+ pTokens->SetOwner(kFALSE);
+ }
+ delete pTokens;
+ }
+ }
+
+ for (i=0; (unsigned)i<array.size() && iResult>=0;) {
+ int result=ScanConfigurationArgument(array.size()-i, &array[i]);
+ if (result==0) {
+ HLTWarning("unknown component argument %s", array[i]);
+ i++;
+ } else if (result>0) {
+ i+=result;
+ } else {
+ iResult=result;
+ if (iResult==-EINVAL) {
+ HLTError("unknown argument %s", array[i]);
+ } else if (iResult==-EPROTO) {
+ HLTError("missing/wrong parameter for argument %s (%s)", array[i], (array.size()>(unsigned)i+1)?array[i+1]:"missing");
+ } else {
+ HLTError("scan of argument %s failed (%d)", array[i], iResult);
+ }
+ }
+ }
+
+ return iResult;
+}
+
+int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries)
+{
+ // see header file for function documentation
+ int iResult=0;
+ TString arguments;
+ TString confEntries=entries;
+ TObjArray* pTokens=confEntries.Tokenize(" ");
+ if (pTokens) {
+ for (int n=0; n<pTokens->GetEntriesFast(); n++) {
+ const char* path=((TObjString*)pTokens->At(n))->GetString().Data();
+ const char* chainId=GetChainId();
+ HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+ TObject* pOCDBObject = LoadAndExtractOCDBObject(path);
+ if (pOCDBObject) {
+ TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
+ if (pString) {
+ HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
+ arguments+=pString->GetString().Data();
+ arguments+=" ";
+ } else {
+ HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
+ iResult=-EINVAL;
+ }
+ } else {
+ HLTError("can not fetch object \"%s\" from OCDB", path);
+ iResult=-ENOENT;
+ }
+ }
+ delete pTokens;
+ }
+ if (iResult>=0 && !arguments.IsNull()) {
+ const char* array=arguments.Data();
+ iResult=ConfigureFromArgumentString(1, &array);
+ }
+ return iResult;
+}
+
+TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion)
+{
+ // see header file for function documentation
+ AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
+ if (!pEntry) return NULL;
+ return AliHLTMisc::Instance().ExtractObject(pEntry);
+}
+
int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
{
// default implementation, childs can overload
return 0;
}
+int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
+{
+ // default implementation, childs can overload
+ HLTLogKeyword("dummy");
+ HLTWarning("The function needs to be implemented by the component");
+ return 0;
+}
+
int AliHLTComponent::StartOfRun()
{
// default implementation, childs can overload
// see header file for function documentation
int iResult=0;
-
- if (size>fEventDoneDataSize) {
- AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+size ] );
+ unsigned long capacity=fEventDoneDataSize;
+ if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
+ if (size>capacity) {
+ unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
+ AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
if (!newEDD)
return -ENOMEM;
newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
}
fEventDoneData = newEDD;
- fEventDoneDataSize = size;
+ fEventDoneDataSize = newSize;
}
return iResult;
AliHLTComponentDataTypeList itypes;
AliHLTComponentDataTypeList otypes;
otypes.push_back(GetOutputDataType());
- if (otypes[0]==kAliHLTMultipleDataType) {
+ if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
otypes.clear();
int count=0;
if ((count=GetOutputDataTypes(otypes))>0) {
if (!fpInputObjects) return 0;
TObjArray* array=fpInputObjects;
fpInputObjects=NULL;
- for (int i=0; i<array->GetEntries(); i++) {
+ for (int i=0; i<array->GetEntriesFast(); i++) {
TObject* pObj=array->At(i);
// grrr, garbage collection strikes back: When read via AliHLTMessage
// (CreateInputObject), and written to a TFile afterwards, the
ALIHLTCOMPONENT_BASE_STOPWATCH();
int iResult=0;
fLastObjectSize=0;
+ if (fPushbackPeriod>0) {
+ // suppress the output
+ TDatime time;
+ if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
+ }
if (pObject) {
AliHLTMessage msg(kMESS_OBJECT);
msg.SetCompressionLevel(fCompressionLevel);
{
// see header file for function documentation
ALIHLTCOMPONENT_BASE_STOPWATCH();
+ if (fPushbackPeriod>0) {
+ // suppress the output
+ TDatime time;
+ if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime<fPushbackPeriod) return 0;
+ }
+
return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
}
int indexUpdtDCSEvent=-1;
int indexSOREvent=-1;
int indexEOREvent=-1;
+ int indexECSParamBlock=-1;
for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
indexSOREvent=i;
} else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
forwardedBlocks.push_back(fpInputBlocks[i]);
parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
+ } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
+ indexECSParamBlock=i;
} else {
// the processing function is called if there is at least one
// non-steering data block. Steering blocks are not filtered out
} else {
iResult=-ENOMEM;
}
+
+ if (indexECSParamBlock>=0) {
+ if (fpInputBlocks[indexECSParamBlock].fSize>0) {
+ const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
+ TString paramString;
+ if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
+ HLTWarning("ECS parameter string not terminated");
+ paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
+ paramString+="";
+ } else {
+ paramString=param;
+ }
+ ScanECSParam(paramString.Data());
+ } else {
+ HLTWarning("empty ECS parameter received");
+ }
+ } else {
+ // TODO: later on we might throw a warning here since the CTP trigger classes
+ // should be mandatory
+ }
}
if (indexEOREvent>=0) {
+ fLastPushBackTime=0; // always send at EOR
bAddComponentTableEntry=true;
if (fpRunDesc!=NULL) {
if (fpRunDesc) {
HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
}
}
- AliHLTRunDesc* pRunDesc=fpRunDesc;
- fpRunDesc=NULL;
- delete pRunDesc;
+ // we do not unload the fpRunDesc struct here in order to have the run information
+ // available during the event processing
+ // https://savannah.cern.ch/bugs/?39711
+ // the info will be cleared in DeInit
}
} else {
HLTWarning("did not receive SOR, ignoring EOR");
// for the private blocks
if (fRequireSteeringBlocks) bSkipDataProcessing=0;
+ if (fpCTPData) {
+ // set the active triggers for this event
+ fpCTPData->SetTriggers(trigData);
+ // increment CTP trigger counters if available
+ if (IsDataEvent()) fpCTPData->Increment(trigData);
+ }
+
AliHLTComponentBlockDataList blockData;
if (iResult>=0 && !bSkipDataProcessing)
{ // dont delete, sets the scope for the stopwatch guard
// no output blocks, set size to 0
size=0;
}
+
+ // reset the internal EventData struct
FillEventData(fCurrentEventData);
+
+ // reset the active triggers
+ if (fpCTPData) fpCTPData->SetTriggers(0);
+
+ // set the time for the pushback period
+ if (fPushbackPeriod>0) {
+ // suppress the output
+ TDatime time;
+ if (fLastPushBackTime<0 || (int)time.Get()-fLastPushBackTime>=fPushbackPeriod) {
+ fLastPushBackTime=time.Get();
+ }
+ }
+
return iResult;
}
if (pStopwatches==NULL) return -EINVAL;
int iResult=0;
- for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
+ for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntriesFast(); i++)
SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
return iResult;
}
return fpRunDesc->fRunType;
}
+AliHLTUInt32_t AliHLTComponent::GetTimeStamp() const
+{
+ // see header file for function documentation
+ if (fCurrentEventData.fEventCreation_s) {
+ return fCurrentEventData.fEventCreation_s;
+ }
+ // using the actual UTC if the time stamp was not set by the framework
+ return static_cast<AliHLTUInt32_t>(time(NULL));
+}
+
+AliHLTUInt32_t AliHLTComponent::GetPeriodNumber() const
+{
+ // see header file for function documentation
+ return (GetEventId()>>36)&0xfffffff;
+}
+
+AliHLTUInt32_t AliHLTComponent::GetOrbitNumber() const
+{
+ // see header file for function documentation
+ return (GetEventId()>>12)&0xffffff;
+}
+
+AliHLTUInt16_t AliHLTComponent::GetBunchCrossNumber() const
+{
+ // see header file for function documentation
+ return GetEventId()&0xfff;
+}
+
bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt)
{
// see header file for function documentation
TObjArray* pTokens=descriptor.Tokenize("{");
if (pTokens) {
int n=0;
- if (pTokens->GetEntries()>n) {
+ if (pTokens->GetEntriesFast()>n) {
retChainId=((TObjString*)pTokens->At(n++))->GetString();
}
- if (pTokens->GetEntries()>n) {
+ if (pTokens->GetEntriesFast()>n) {
compId=((TObjString*)pTokens->At(n++))->GetString();
}
delete pTokens;
}
if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
int n=0;
- if (pTokens->GetEntries()>n) {
+ if (pTokens->GetEntriesFast()>n) {
compId=((TObjString*)pTokens->At(n++))->GetString();
}
- if (pTokens->GetEntries()>n) {
+ if (pTokens->GetEntriesFast()>n) {
compArgs=((TObjString*)pTokens->At(n++))->GetString();
}
delete pTokens;
// without problems. But at this point we face the problem with virtual members which
// are not necessarily const.
AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
- AliHLTLogging::SetLogString("%s (%s, %p): ",
+ AliHLTLogging::SetLogString(this, ", %p", "%s (%s_pfmt_): ",
fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
- nonconst->GetComponentID(), this);
+ nonconst->GetComponentID());
iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
va_end(args);
return iResult;
}
+
+int AliHLTComponent::ScanECSParam(const char* ecsParam)
+{
+ // see header file for function documentation
+
+ // format of the parameter string from ECS
+ // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
+ // search for a subset of the parameterkeys
+ // RUN_TYPE=
+ // RUN_NUMBER=
+ // HLT_IN_DDL_LIST=
+ // CTP_TRIGGER_CLASS=
+ // DATA_FORMAT_VERSION=
+ // BEAM_TYPE=
+ // HLT_OUT_DDL_LIST=
+ // HLT_TRIGGER_CODE=
+ // DETECTOR_LIST=
+ // HLT_MODE=
+ // The command apears not to be sent by the online framework
+ int iResult=0;
+ TString string=ecsParam;
+ TObjArray* parameter=string.Tokenize(";");
+ if (parameter) {
+ for (int i=0; i<parameter->GetEntriesFast(); i++) {
+ TString entry=((TObjString*)parameter->At(i))->GetString();
+ HLTDebug("scanning ECS entry: %s", entry.Data());
+ TObjArray* entryParams=entry.Tokenize("=");
+ if (entryParams) {
+ if (entryParams->GetEntriesFast()>1) {
+ if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
+ int result=InitCTPTriggerClasses((((TObjString*)entryParams->At(1))->GetString()).Data());
+ if (iResult>=0 && result<0) iResult=result;
+ } else {
+ // TODO: scan the other parameters
+ // e.g. consistency check of run number
+ }
+ }
+ delete entryParams;
+ }
+ }
+ delete parameter;
+ }
+
+ return iResult;
+}
+
+int AliHLTComponent::SetupCTPData()
+{
+ // see header file for function documentation
+ if (fpCTPData) delete fpCTPData;
+ fpCTPData=new AliHLTCTPData;
+ if (!fpCTPData) return -ENOMEM;
+ return 0;
+}
+
+int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
+{
+ // see header file for function documentation
+ if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
+ return fpCTPData->InitCTPTriggerClasses(ctpString);
+}
+
+bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
+{
+ // see header file for function documentation
+ if (!fpCTPData) {
+ static bool bWarningThrown=false;
+ if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
+ bWarningThrown=true;
+ return false;
+ }
+
+ return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);
+}
+
+Double_t AliHLTComponent::GetBz()
+{
+ // Returns Bz.
+ return AliHLTMisc::Instance().GetBz();
+}
+
+Double_t AliHLTComponent::GetBz(const Double_t *r)
+{
+ // Returns Bz (kG) at the point "r" .
+ return AliHLTMisc::Instance().GetBz(r);
+}
+
+void AliHLTComponent::GetBxByBz(const Double_t r[3], Double_t b[3])
+{
+ // Returns Bx, By and Bz (kG) at the point "r" .
+ AliHLTMisc::Instance().GetBxByBz(r, b);
+}