Skip to content

Commit

Permalink
ALIROOT-5433 Transition to CDHv3 in HLT
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreitne committed May 20, 2014
1 parent a54e242 commit ed0ad89
Show file tree
Hide file tree
Showing 53 changed files with 539 additions and 327 deletions.
125 changes: 125 additions & 0 deletions HLT/BASE/AliHLTCDHWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#ifndef ALIHLTCDHWRAPPER_H
#define ALIHLTCDHWRAPPER_H

#include <assert.h>
#include "AliRawDataHeader.h"
#include "AliRawDataHeaderV3.h"

#define CHECK_AND_CALL(func, args...) \
( GetVersion() == 2 ? \
reinterpret_cast<const AliRawDataHeader*>(fCDH)->func(args) : \
reinterpret_cast<const AliRawDataHeaderV3*>(fCDH)->func(args) )


class AliHLTCDHWrapper {
public:
AliHLTCDHWrapper() : fCDH(NULL) {}
AliHLTCDHWrapper(const AliHLTCDHWrapper& other) : fCDH(other.fCDH) { CheckVersion(); }
AliHLTCDHWrapper(const void* cdh) : fCDH(cdh) { CheckVersion(); }

~AliHLTCDHWrapper() {}

inline AliHLTCDHWrapper& operator=(const AliHLTCDHWrapper& other) {
fCDH = other.fCDH;
CheckVersion();
return *this;
}

inline AliHLTCDHWrapper& operator=(const void*& cdh) {
fCDH = cdh;
CheckVersion();
return *this;
}

inline void CheckVersion() {
if(fCDH)
assert(GetVersion() == 2 || GetVersion() == 3);
}

inline UChar_t GetVersion() const {
return (reinterpret_cast<const AliRawDataHeader*>(fCDH))->GetVersion();
}

inline UInt_t GetHeaderSize() {
return (GetVersion() == 2 ?
sizeof(AliRawDataHeader) : sizeof(AliRawDataHeaderV3) );
}

inline const void* GetHeader() const {
return fCDH;
}

inline UInt_t GetDataSize() const {
//first word, independent of Version
return *((UInt_t*)fCDH);
}

inline UShort_t GetEventID1() const {
return CHECK_AND_CALL(GetEventID1);
}

inline UInt_t GetEventID2() const {
return CHECK_AND_CALL(GetEventID2);
}

inline UChar_t GetL1TriggerMessage() const {
return CHECK_AND_CALL(GetL1TriggerMessage);
}

inline UChar_t GetAttributes() const {
return CHECK_AND_CALL(GetAttributes);
}

inline Bool_t TestAttribute(Int_t index) const {
return CHECK_AND_CALL(TestAttribute, index);
}

/*
inline void SetAttribute(Int_t index) {
CHECK_AND_CALL(SetAttribute, index);
}
*/

/*
inline void ResetAttribute(Int_t index) {
CHECK_AND_CALL(ResetAttribute, index);
}
*/

inline UInt_t GetSubDetectors() const {
return CHECK_AND_CALL(GetSubDetectors);
}

inline UInt_t GetStatus() const {
return CHECK_AND_CALL(GetStatus);
}

inline UInt_t GetMiniEventID() const {
return CHECK_AND_CALL(GetMiniEventID);
}

inline ULong64_t GetTriggerClasses() const {
return CHECK_AND_CALL(GetTriggerClasses);
}

inline ULong64_t GetTriggerClassesNext50() const {
return CHECK_AND_CALL(GetTriggerClassesNext50);
}

inline ULong64_t GetROI() const {
return CHECK_AND_CALL(GetROI);
}

/*
inline void SetTriggerClass(ULong64_t mask) {
CHECK_AND_CALL(SetTriggerClass, mask);
}
*/

private:
const void* fCDH;

};


#endif
112 changes: 72 additions & 40 deletions HLT/BASE/AliHLTCTPData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include "TObjString.h"
#include "TFormula.h"
#include "AliHLTComponent.h"
#include "AliRawDataHeader.h"
#include "AliHLTCDHWrapper.h"
#include <limits>
#include <sstream>

/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTCTPData)
Expand Down Expand Up @@ -191,7 +193,7 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
if (index<gkNCTPTriggerClasses) {
AliHLTReadoutList* pCTPClass=dynamic_cast<AliHLTReadoutList*>(fClassIds.At(index));
if (pCTPClass) {
fMask|=(AliHLTUInt64_t)0x1 << index;
fMask.set(index);
pCTPClass->SetTitle("CTP Class");
pCTPClass->SetName((((TObjString*)entryParams->At(kName))->GetString()).Data());
TObjArray* detectors=(((TObjString*)entryParams->At(kDetectors))->GetString()).Tokenize("-");
Expand All @@ -209,7 +211,7 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
} else {
}
} else {
// the trigger bitfield is fixed to 50 bits (gkNCTPTriggerClasses)
// the trigger bitfield is fixed to 100 bits (gkNCTPTriggerClasses)
HLTError("invalid trigger class entry %s, index width of trigger bitfield exceeded (%d)", entry.Data(), gkNCTPTriggerClasses);
}
} else {
Expand All @@ -227,39 +229,43 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
return 0;
}

AliHLTUInt64_t AliHLTCTPData::ActiveTriggers(const AliHLTComponentTriggerData& trigData)
AliHLTTriggerMask_t AliHLTCTPData::ActiveTriggers(const AliHLTComponentTriggerData& trigData)
{
// extract active triggers from the trigger data
AliHLTCDHWrapper cdh;
if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) != 0) return 0x0;
if ((cdh.GetL1TriggerMessage() & 0x1) == 0x1) return 0x0; // invalid for software triggers.

const AliRawDataHeader* cdh = NULL;
if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) != 0) return (AliHLTUInt64_t)0;
if ((cdh->GetL1TriggerMessage() & 0x1) == 0x1) return 0x0; // invalid for software triggers.
// trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
return triggerMask;
AliHLTTriggerMask_t triggerLow(cdh.GetTriggerClasses()); //low bits
AliHLTTriggerMask_t triggerHigh(cdh.GetTriggerClassesNext50()); // high bits

return triggerLow | (triggerHigh << 50);
}

bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, const AliHLTComponentTriggerData& trigData) const
{
// see header file for function documentation

const AliRawDataHeader* cdh = NULL;
AliHLTCDHWrapper cdh;
if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true) != 0) return false;
if ((cdh->GetL1TriggerMessage() & 0x1) == 0x1) return false; // invalid for software triggers.
// trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
if ((cdh.GetL1TriggerMessage() & 0x1) == 0x1) return false; // invalid for software triggers.

AliHLTTriggerMask_t triggerMask(cdh.GetTriggerClasses());
AliHLTTriggerMask_t triggerHigh(cdh.GetTriggerClassesNext50());
triggerMask |= (triggerHigh << 50);

if (fMask!=0 && (triggerMask & fMask)==0) {
AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
HLTWarning("invalid trigger mask %s, unknown CTP trigger, initialized %s",
TriggerMaskToString(triggerMask).c_str(), TriggerMaskToString(fMask).c_str() );
for (int i=0; i<gkAliHLTCommonHeaderCount; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
return false;
}

return EvaluateCTPTriggerClass(expression, triggerMask);
}

bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, AliHLTUInt64_t triggerMask) const
bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, AliHLTTriggerMask_t triggerMask) const
{
// see header file for function documentation

Expand All @@ -286,7 +292,7 @@ bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, AliHLTUInt64
TString replace; replace.Form("[%d]", (int)par.size());
//HLTDebug("replacing %s with %s in \"%s\"", className.Data(), replace.Data(), condition.Data());
condition.ReplaceAll(className, replace);
if (triggerMask&((AliHLTUInt64_t)0x1<<(*pMap)[index])) par.push_back(1.0);
if ( triggerMask.test((*pMap)[index]) ) par.push_back(1.0);
else par.push_back(0.0);
}
}
Expand Down Expand Up @@ -320,7 +326,7 @@ int AliHLTCTPData::CheckTrigger(const char* name) const
// check status of a trigger class
int index=Index(name);
if (index<0) return index;
return (fTriggers&(0x1<<index))>0?1:0;
return ( fTriggers.test(index) ? 1 : 0 );
}

void AliHLTCTPData::Increment(const char* classIds)
Expand All @@ -337,12 +343,12 @@ void AliHLTCTPData::Increment(const char* classIds)
}
}

void AliHLTCTPData::Increment(AliHLTUInt64_t triggerPattern)
void AliHLTCTPData::Increment(AliHLTTriggerMask_t triggerPattern)
{
// see header file for function documentation
AliHLTUInt64_t pattern=triggerPattern&fMask;
AliHLTTriggerMask_t pattern=triggerPattern&fMask;
for (int i=0; i<fCounters.GetSize(); i++) {
if ((pattern&((AliHLTUInt64_t)0x1<<i))==0) continue;
if (!pattern.test(i)) continue;
fCounters[i]++;
}
}
Expand All @@ -351,7 +357,7 @@ void AliHLTCTPData::Increment(int classIdx)
{
// see header file for function documentation
if (classIdx<fCounters.GetSize() &&
(fMask&((AliHLTUInt64_t)0x1<<classIdx))) {
fMask.test(classIdx)) {
fCounters[classIdx]++;
}

Expand All @@ -360,17 +366,21 @@ void AliHLTCTPData::Increment(int classIdx)
int AliHLTCTPData::Increment(AliHLTComponentTriggerData& trigData)
{
// see header file for function documentation
const AliRawDataHeader* cdh = NULL;
AliHLTCDHWrapper cdh;
int result = AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true);
if (result != 0) return result;
if ((cdh->GetL1TriggerMessage() & 0x1) == 0x1) return 0; // invalid for software triggers.
// trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
if ((cdh.GetL1TriggerMessage() & 0x1) == 0x1) return 0; // invalid for software triggers.

if (fMask!=0 && (triggerMask & fMask)==0) {
AliHLTTriggerMask_t triggerMask(cdh.GetTriggerClasses());
AliHLTTriggerMask_t triggerHigh(cdh.GetTriggerClassesNext50());
triggerMask |= (triggerHigh << 50);

if (fMask.any() && (triggerMask & fMask).none()) {
AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
HLTWarning("invalid trigger mask %s, unknown CTP trigger, initialized %s",
TriggerMaskToString(triggerMask).c_str(), TriggerMaskToString(fMask).c_str());
for (int i=0; i<gkAliHLTCommonHeaderCount; i++)
HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
}
Increment(triggerMask);
return 0;
Expand Down Expand Up @@ -426,31 +436,35 @@ AliHLTReadoutList AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& t
{
// see header file for function documentation

const AliRawDataHeader* cdh = NULL;
AliHLTCDHWrapper cdh;
if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true) != 0) return AliHLTReadoutList();
// Check if we are dealing with a software trigger. If so then we need to return
// a readout list with everything set because the CTP trigger bits are invalid.
// Thus we assume that everything should be read out.
if ((cdh->GetL1TriggerMessage() & 0x1) == 0x1) return ~ AliHLTReadoutList();
// trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
if ((cdh.GetL1TriggerMessage() & 0x1) == 0x1) return ~ AliHLTReadoutList();

if (fMask!=0 && (triggerMask & fMask)==0) {
AliHLTTriggerMask_t triggerMask(cdh.GetTriggerClasses());
AliHLTTriggerMask_t triggerHigh(cdh.GetTriggerClassesNext50());
triggerMask |= (triggerHigh << 50);

if (fMask.any() && (triggerMask & fMask).none()) {
AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
HLTWarning("invalid trigger mask 0x%llx, unknown CTP trigger, initialized 0x%llx", triggerMask, fMask);
for (int i=0; i<8; i++) HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
HLTWarning("invalid trigger mask %s, unknown CTP trigger, initialized %s",
TriggerMaskToString(triggerMask).c_str(), TriggerMaskToString(fMask).c_str());
for (int i=0; i<gkAliHLTCommonHeaderCount; i++)
HLTWarning("\t CDH[%d]=0x%lx", i, evtData->fCommonHeader[i]);
}

return ReadoutList(triggerMask);
}

AliHLTReadoutList AliHLTCTPData::ReadoutList(AliHLTUInt64_t triggerMask) const
AliHLTReadoutList AliHLTCTPData::ReadoutList(AliHLTTriggerMask_t triggerMask) const
{
// take an 'OR' of all active trigger classes
AliHLTReadoutList list;
for (int i=0; i<gkNCTPTriggerClasses; i++) {
if (i>fClassIds.GetLast()) break;
if ((triggerMask&((AliHLTUInt64_t)0x1<<i))==0) continue;
if (! triggerMask.test(i)) continue;
AliHLTReadoutList* tcrl=(AliHLTReadoutList*)fClassIds.At(i);
list.OrEq(*tcrl);
}
Expand All @@ -468,9 +482,27 @@ void AliHLTCTPData::Print(Option_t* /*option*/) const
for (int i=0; i<gkNCTPTriggerClasses; i++) {
if (i>=Counters().GetSize()) break;
if (i>fClassIds.GetLast()) break;
if ((fMask&((AliHLTUInt64_t)0x1<<i))==0) continue;
if (! fMask.test(i)) continue;
count++;
cout << "\t" << i << "\t" << Name(i) << "\t" << Counter(i) << endl;
}
if (count==0) cout << "\t(none)" << endl;
}


std::string AliHLTCTPData::TriggerMaskToString(AliHLTTriggerMask_t mask) const
{
AliHLTTriggerMask_t max(std::numeric_limits<unsigned long>::max());
int digits = std::numeric_limits<unsigned long>::digits;
int numberOfWords = (mask.size() + digits - 1)/digits;
std::stringstream stream;
stream << "0x";
stream << std::hex << std::right;
for(int i=numberOfWords-1; i>=0; --i){
stream.width(digits/4);
stream.fill('0');
stream << ((mask >> (digits*i)) & max).to_ulong() << " ";
}
return stream.str();
}

Loading

0 comments on commit ed0ad89

Please sign in to comment.