using namespace std;
#endif
-#include "AliHLTStdIncludes.h"
+//#include "AliHLTStdIncludes.h"
#include "AliHLTComponent.h"
#include "AliHLTComponentHandler.h"
#include "AliHLTMessage.h"
#include "TString.h"
#include "TObjArray.h"
#include "TClass.h"
+#include "TStopwatch.h"
/** ROOT macro for the implementation of ROOT specific class methods */
-ClassImp(AliHLTComponent)
+ClassImp(AliHLTComponent);
+
+/** stopwatch macro using the stopwatch guard */
+#define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
+//#define ALIHLTCOMPONENT_STOPWATCH(type)
+
+/** stopwatch macro for operations of the base class */
+#define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
+/** stopwatch macro for operations of the detector algorithm (DA) */
+#define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
AliHLTComponent::AliHLTComponent()
:
fpOutputBuffer(NULL),
fOutputBufferSize(0),
fOutputBufferFilled(0),
- fOutputBlocks()
+ fOutputBlocks(),
+ fpStopwatches(new TObjArray(kSWTypeCount))
{
// see header file for class documentation
// or
memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
if (fgpComponentHandler)
fgpComponentHandler->ScheduleRegister(this);
+ SetLocalLoggingLevel(kHLTLogDefault);
}
AliHLTComponent::AliHLTComponent(const AliHLTComponent&)
fpOutputBuffer(NULL),
fOutputBufferSize(0),
fOutputBufferFilled(0),
- fOutputBlocks()
+ fOutputBlocks(),
+ fpStopwatches(NULL)
{
// see header file for class documentation
HLTFatal("copy constructor untested");
AliHLTComponent::~AliHLTComponent()
{
// see header file for function documentation
+ CleanupInputObjects();
+ if (fpStopwatches!=NULL) delete fpStopwatches;
+ fpStopwatches=NULL;
}
AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
fEnvironment.fParam=environParam;
}
- iResult=DoInit(argc, argv);
+ const char** pArguments=NULL;
+ int iNofChildArgs=0;
+ TString argument="";
+ int bMissingParam=0;
+ if (argc>0) {
+ pArguments=new const char*[argc];
+ if (pArguments) {
+ for (int i=0; i<argc && iResult>=0; i++) {
+ argument=argv[i];
+ if (argument.IsNull()) continue;
+
+ // benchmark
+ if (argument.CompareTo("benchmark")==0) {
+
+ // loglevel
+ } else if (argument.CompareTo("loglevel")==0) {
+ if ((bMissingParam=(++i>=argc))) break;
+ TString parameter(argv[i]);
+ parameter.Remove(TString::kLeading, ' '); // remove all blanks
+ if (parameter.BeginsWith("0x") &&
+ parameter.Replace(0,2,"",0).IsHex()) {
+ AliHLTComponentLogSeverity loglevel=kHLTLogNone;
+ sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel);
+ SetLocalLoggingLevel(loglevel);
+ } else {
+ HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
+ iResult=-EINVAL;
+ }
+ } else {
+ pArguments[iNofChildArgs++]=argv[i];
+ }
+ }
+ } else {
+ iResult=-ENOMEM;
+ }
+ }
+ if (bMissingParam) {
+ HLTError("missing parameter for argument %s", argument.Data());
+ iResult=-EINVAL;
+ }
+ if (iResult>=0) {
+ iResult=DoInit(iNofChildArgs, pArguments);
+ }
if (iResult>=0) fEventCount=0;
+ if (pArguments) delete [] pArguments;
return iResult;
}
if (argc==0 && argv==NULL) {
// this is currently just to get rid of the warning "unused parameter"
}
+ fEventCount=0;
return 0;
}
int AliHLTComponent::DoDeinit()
{
// see header file for function documentation
+ fEventCount=0;
return 0;
}
void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const
{
+ // see header file for function documentation
const char* fmt="publisher \'%s\'";
if (format) fmt=format;
HLTMessage(fmt, (DataType2Text(dt)).c_str());
return fEventCount;
}
-int AliHLTComponent::GetNumberOfInputBlocks()
+int AliHLTComponent::GetNumberOfInputBlocks() const
{
// see header file for function documentation
if (fpInputBlocks!=NULL) {
int bForce)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
fSearchDataType=dt;
if (classname) fClassName=classname;
else fClassName.clear();
- int idx=FindInputBlock(fSearchDataType, 0);
- //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
+ int idx=FindInputBlock(fSearchDataType, 0, 1);
+ HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
TObject* pObj=NULL;
if (idx>=0) {
if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
int bForce)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
AliHLTComponentDataType dt;
SetDataType(dt, dtID, dtOrigin);
return GetFirstInputObject(dt, classname, bForce);
const TObject* AliHLTComponent::GetNextInputObject(int bForce)
{
// see header file for function documentation
- int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
+ int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
//HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
TObject* pObj=NULL;
if (idx>=0) {
return pObj;
}
-int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx)
+int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
{
// see header file for function documentation
int iResult=-ENOENT;
if (fpInputBlocks!=NULL) {
int idx=startIdx<0?0:startIdx;
for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
+ if (bObject!=0) {
+ if (fpInputBlocks[idx].fPtr==NULL) continue;
+ AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
+ if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
+ }
if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
iResult=idx;
}
if (fpInputBlocks[idx].fPtr) {
AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
- //HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
+ HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
- pObj=msg.ReadObject(msg.GetClass());
- if (pObj && msg.GetClass()) {
- //HLTDebug("object %p type %s created", pObj, msg.GetClass()->GetName());
+ TClass* objclass=msg.GetClass();
+ pObj=msg.ReadObject(objclass);
+ if (pObj && objclass) {
+ HLTDebug("object %p type %s created", pObj, objclass->GetName());
} else {
}
- } else {
- // } else if (bForce!=0) {
+ //} else {
+ } else if (bForce!=0) {
HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
}
} else {
return pObj;
}
+int AliHLTComponent::CleanupInputObjects()
+{
+ // see header file for function documentation
+ if (!fpInputObjects) return 0;
+ TObjArray* array=fpInputObjects;
+ fpInputObjects=NULL;
+ for (int i=0; i<array->GetEntries(); i++) {
+ TObject* pObj=array->At(i);
+ if (pObj) delete pObj;
+ }
+ delete array;
+ return 0;
+}
+
AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
AliHLTComponentDataType dt=kAliHLTVoidDataType;
int idx=fCurrentInputBlock;
if (pObject) {
AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
int idx=fCurrentInputBlock;
if (pObject) {
const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
fSearchDataType=dt;
fClassName.clear();
int idx=FindInputBlock(fSearchDataType, 0);
if (idx>=0) {
// check for fpInputBlocks pointer done in FindInputBlock
pBlock=&fpInputBlocks[idx];
+ fCurrentInputBlock=idx;
}
return pBlock;
}
const char* dtOrigin)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
AliHLTComponentDataType dt;
SetDataType(dt, dtID, dtOrigin);
return GetFirstInputBlock(dt);
const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
const AliHLTComponentBlockData* pBlock=NULL;
if (idx>=0) {
// check for fpInputBlocks pointer done in FindInputBlock
pBlock=&fpInputBlocks[idx];
+ fCurrentInputBlock=idx;
}
return pBlock;
}
-int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock)
+int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
{
// see header file for function documentation
int iResult=-ENOENT;
AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
int idx=fCurrentInputBlock;
if (pBlock) {
int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
int iResult=0;
if (pObject) {
AliHLTMessage msg(kMESS_OBJECT);
msg.SetLength(); // sets the length to the first (reserved) word
iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec);
if (iResult>=0) {
- //HLTDebug("object %s (%p) inserted to output", pObject->ClassName(), pObject);
+ HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
}
} else {
HLTError("object serialization failed for object %p", pObject);
int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
AliHLTComponentDataType dt;
SetDataType(dt, dtID, dtOrigin);
return PushBack(pObject, dt, spec);
int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
return InsertOutputBlock(pBuffer, iSize, dt, spec);
}
int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
AliHLTComponentDataType dt;
SetDataType(dt, dtID, dtOrigin);
return PushBack(pBuffer, iSize, dt, spec);
// see header file for function documentation
int iResult=0;
if (pBuffer) {
- if (fpOutputBuffer && (fOutputBufferSize-fOutputBufferFilled)) {
+ if (fpOutputBuffer && iSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
AliHLTComponentBlockData bd;
FillBlockData( bd );
return iResult;
}
+int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
+{
+ // see header file for function documentation
+ if (!pObject) return -EINVAL;
+ AliHLTMessage msg(kMESS_OBJECT);
+ msg.WriteObject(pObject);
+ return msg.Length();
+}
+
int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
{
// see header file for function documentation
AliHLTComponentEventDoneData*& edd )
{
// see header file for function documentation
+ ALIHLTCOMPONENT_BASE_STOPWATCH();
int iResult=0;
fCurrentEvent=evtData.fEventID;
fCurrentEventData=evtData;
fOutputBlocks.clear();
vector<AliHLTComponentBlockData> blockData;
- iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
+ { // dont delete, sets the scope for the stopwatch guard
+ ALIHLTCOMPONENT_DA_STOPWATCH();
+ iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
+ } // end of the scope of the stopwatch guard
if (iResult>=0) {
if (fOutputBlocks.size()>0) {
//HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
outputBlockCnt=0;
outputBlocks=NULL;
}
+ CleanupInputObjects();
IncrementEventCounter();
return iResult;
}
+AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
+ :
+ fpStopwatch(NULL),
+ fpPrec(NULL)
+{
+ // standard constructor (not for use)
+}
+
+AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
+ :
+ fpStopwatch(pStopwatch),
+ fpPrec(NULL)
+{
+ // constructor
+
+ // check for already existing guard
+ if (fgpCurrent) fpPrec=fgpCurrent;
+ fgpCurrent=this;
+
+ // stop the preceeding guard if it controls a different stopwatch
+ int bStart=1;
+ if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
+
+ // start the stopwatch if the current guard controls a different one
+ if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
+}
+
+AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(AliHLTStopwatchGuard&)
+ :
+ fpStopwatch(NULL),
+ fpPrec(NULL)
+{
+ // copy constructor (not for use)
+}
+
+AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
+
+AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
+{
+ // destructor
+
+ // resume the preceeding guard if it controls a different stopwatch
+ int bStop=1;
+ if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
+
+ // stop the stopwatch if the current guard controls a different one
+ if (fpStopwatch && bStop==1) fpStopwatch->Stop();
+
+ // resume to the preceeding guard
+ fgpCurrent=fpPrec;
+}
+
+int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
+{
+ // see header file for function documentation
+ if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
+ return fpStopwatch!=pSucc?1:0;
+}
+
+int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
+{
+ // see header file for function documentation
+ if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
+ return fpStopwatch!=pSucc?1:0;
+}
+
+int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
+{
+ // see header file for function documentation
+ int iResult=0;
+ if (pSW!=NULL && type<kSWTypeCount) {
+ if (fpStopwatches) {
+ TObject* pObj=fpStopwatches->At((int)type);
+ if (pSW==NULL // explicit reset
+ || pObj==NULL) { // explicit set
+ fpStopwatches->AddAt(pSW, (int)type);
+ } else if (pObj!=pSW) {
+ HLTWarning("stopwatch %d already set, reset first", (int)type);
+ iResult=-EBUSY;
+ }
+ }
+ } else {
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
+{
+ // see header file for function documentation
+ if (pStopwatches==NULL) return -EINVAL;
+
+ int iResult=0;
+ for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
+ SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
+ return iResult;
+}