]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTCTPData.cxx
Major update required to handle old and new AliHLTEventDDL structures within HLT...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTCTPData.cxx
index 4d5b7ea05f414fb4ce0ac6a219eaa6ed6476a13e..733b0733276c42d94979d6808063f5fc45999fe3 100644 (file)
 //* provided "as is" without express or implied warranty.                  *
 //**************************************************************************
 
-/** @file   AliHLTCTPData.cxx
-    @author Matthias Richter
-    @date   2009-08-20
-    @brief  Container for CTP trigger classes and counters
-*/
+/ @file   AliHLTCTPData.cxx
+//  @author Matthias Richter
+//  @date   2009-08-20
+//  @brief  Container for CTP trigger classes and counters
+//  @note
 
 #include "AliHLTCTPData.h"
-#include "AliHLTReadoutList.h"
 #include "TClass.h"
 #include "TObjString.h"
 #include "TFormula.h"
+#include "AliHLTComponent.h"
+#include "AliRawDataHeader.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTCTPData)
@@ -38,7 +39,9 @@ AliHLTCTPData::AliHLTCTPData()
   , fTriggers(0)
   , fClassIds(AliHLTReadoutList::Class(), gkNCTPTriggerClasses)
   , fCounters(gkNCTPTriggerClasses)
+  , fMap()
 {
+  // constructor
   // see header file for class documentation
   // or
   // refer to README to build package
@@ -53,14 +56,15 @@ AliHLTCTPData::AliHLTCTPData(const char* parameter)
   , fTriggers(0)
   , fClassIds(AliHLTReadoutList::Class(), gkNCTPTriggerClasses)
   , fCounters(gkNCTPTriggerClasses)
+  , fMap()
 {
-  // see header file for class documentation
+  // constructor, init the CTP trigger classes
   InitCTPTriggerClasses(parameter);
 }
 
 AliHLTCTPData::~AliHLTCTPData()
 {
-  // see header file for class documentation
+  // destructor
   fClassIds.Delete();
 }
 
@@ -71,13 +75,15 @@ AliHLTCTPData::AliHLTCTPData(const AliHLTCTPData& src)
   , fTriggers(src.fTriggers)
   , fClassIds(src.fClassIds)
   , fCounters(src.Counters())
+  , fMap()
 {
-  // see header file for class documentation
+  // copy constructor
+  ReadMap();
 }
 
 AliHLTCTPData& AliHLTCTPData::operator=(const AliHLTCTPData& src)
 {
-  // see header file for class documentation
+  // assignment operator, clone content
   if (this!=&src) {
     SetName(src.GetName());
     SetTitle(src.GetTitle());
@@ -85,12 +91,14 @@ AliHLTCTPData& AliHLTCTPData::operator=(const AliHLTCTPData& src)
     fClassIds.Delete();
     fClassIds.ExpandCreate(gkNCTPTriggerClasses);
     for (int i=0; i<gkNCTPTriggerClasses; i++) {
+      if (i>src.fClassIds.GetLast()) break;
       ((TNamed*)fClassIds.At(i))->SetName(src.fClassIds.At(i)->GetName());
       ((TNamed*)fClassIds.At(i))->SetTitle(src.fClassIds.At(i)->GetTitle());
     }
     fCounters=src.Counters();
   }
 
+  ReadMap();
   return *this;
 }
 
@@ -173,11 +181,11 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
   TObjArray* classEntries=string.Tokenize(",");
   if (classEntries) {
     enum {kBit=0, kName, kDetectors};
-    for (int i=0; i<classEntries->GetEntries(); i++) {
+    for (int i=0; i<classEntries->GetEntriesFast(); i++) {
       TString entry=((TObjString*)classEntries->At(i))->GetString();
       TObjArray* entryParams=entry.Tokenize(":");
       if (entryParams) {
-       if (entryParams->GetEntries()==3 &&
+       if (entryParams->GetEntriesFast()==3 &&
            (((TObjString*)entryParams->At(kBit))->GetString()).IsDigit()) {
          int index=(((TObjString*)entryParams->At(kBit))->GetString()).Atoi();
          if (index<gkNCTPTriggerClasses) {
@@ -214,6 +222,7 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
   }
 
   ResetCounters();
+  ReadMap();
 
   return 0;
 }
@@ -221,32 +230,25 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
 AliHLTUInt64_t AliHLTCTPData::ActiveTriggers(const AliHLTComponentTriggerData& trigData)
 {
   // extract active triggers from the trigger data
-  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) return (AliHLTUInt64_t)0;
 
+  const AliRawDataHeader* cdh = NULL;
+  if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) != 0) return (AliHLTUInt64_t)0;
   // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
-  AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
-  AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
-  triggerMask<<=32;
-  triggerMask|=evtData->fCommonHeader[5];
+  AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
   return triggerMask;
 }
 
 bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, const AliHLTComponentTriggerData& trigData) const
 {
   // see header file for function documentation
-  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
-    HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
-    return false;
-  }
-
+  
+  const AliRawDataHeader* cdh = NULL;
+  if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true) != 0) return false;
   // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
-  AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
-  AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
-  triggerMask<<=32;
-  triggerMask|=evtData->fCommonHeader[5];
+  AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
 
   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]);
     return false;
@@ -262,21 +264,27 @@ bool AliHLTCTPData::EvaluateCTPTriggerClass(const char* expression, AliHLTUInt64
   // use a TFormula to interprete the expression
   // all classname are replaced by '[n]' which means the n'th parameter in the formula
   // the parameters are set to 0 or 1 depending on the bit in the trigger mask
-  //
-  // TODO: this will most likely fail for class names like 'base', 'baseA', 'baseB'
-  // the class names must be fully unique, none must be contained as substring in
-  // another class name. Probably not needed for the moment but needs to be extended.
+  const vector<unsigned> *pMap=&fMap;
+  vector<unsigned> tmp;
+  if (fMap.size()==0 && fClassIds.GetLast()>=0) {
+    // read map into temporary array and use it
+    ReadMap(tmp);
+    pMap=&tmp;
+    static bool suppressWarning=false;
+    if (!suppressWarning) HLTWarning("map not yet initialized, creating local map (slow), suppressing further warnings");
+    suppressWarning=true;
+  }
   vector<Double_t> par;
   TString condition=expression;
-  for (int i=0; i<gkNCTPTriggerClasses; i++) {
-    const char* className=Name(i);
+  for (unsigned index=0; index<pMap->size(); index++) {
+    const char* className=Name((*pMap)[index]);
     if (className && strlen(className)>0) {
       //HLTDebug("checking trigger class %s", className.Data());
       if (condition.Contains(className)) {
        TString replace; replace.Form("[%d]", par.size());
        //HLTDebug("replacing %s with %s in \"%s\"", className.Data(), replace.Data(), condition.Data());
        condition.ReplaceAll(className, replace);
-       if (triggerMask&((AliHLTUInt64_t)0x1<<i)) par.push_back(1.0);
+       if (triggerMask&((AliHLTUInt64_t)0x1<<(*pMap)[index])) par.push_back(1.0);
        else par.push_back(0.0);
       }
     }
@@ -305,13 +313,21 @@ int AliHLTCTPData::Index(const char* name) const
   return obj!=NULL?fClassIds.IndexOf(obj):-1;
 }
 
+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;
+}
+
 void AliHLTCTPData::Increment(const char* classIds)
 {
   // see header file for function documentation
   TString string=classIds;
   TObjArray* classEntries=string.Tokenize(",");
   if (classEntries) {
-    for (int i=0; i<classEntries->GetEntries(); i++) {
+    for (int i=0; i<classEntries->GetEntriesFast(); i++) {
       int index=Index(((TObjString*)classEntries->At(i))->GetString().Data());
       if (index>=0 && index<fCounters.GetSize()) fCounters[index]++;
     }
@@ -342,18 +358,14 @@ void AliHLTCTPData::Increment(int classIdx)
 int AliHLTCTPData::Increment(AliHLTComponentTriggerData& trigData)
 {
   // see header file for function documentation
-  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
-    HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
-    return -EBADF;
-  }
-
+  const AliRawDataHeader* cdh = NULL;
+  int result = AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true);
+  if (result != 0) return result;
   // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
-  AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
-  AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
-  triggerMask<<=32;
-  triggerMask|=evtData->fCommonHeader[5];
+  AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
 
   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]);
   }
@@ -381,27 +393,52 @@ const char* AliHLTCTPData::Name(int index) const
   return fClassIds.At(index)->GetName();
 }
 
-AliHLTEventDDL AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trigData) const
+int AliHLTCTPData::ReadMap(vector<unsigned> &map) const
 {
-  // see header file for function documentation
-  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
-    HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
-    AliHLTEventDDL dummy;
-    memset(&dummy, 0, sizeof(AliHLTEventDDL));
-    return dummy;
+  // read the index map for class names
+  // for nested class names (e.g. 'myclass' is contained in
+  // 'myclassA') the longer names is added first to the map.
+  for (int index=0; index<=fClassIds.GetLast(); index++) {
+    vector<unsigned>::iterator element=map.begin();
+    for (; element!=map.end(); element++) {
+      TString name=Name(index);
+      if (name.Contains(Name(*element))) {
+       // current name contains another one already in the map
+       // -> add before and go to next entry
+       element=map.insert(element, index);
+       break;
+      }
+    }
+
+    if (element==map.end()) {
+      // unique class name, append to map
+      map.push_back(index);
+    }
   }
+  return 0;
+}
+
 
+AliHLTReadoutList AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trigData) const
+{
+  // see header file for function documentation
+
+  const AliRawDataHeader* cdh = NULL;
+  if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true) != 0) return AliHLTReadoutList();
   // trigger mask is 50 bit wide and is stored in word 5 and 6 of the CDH
-  AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
-  AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
-  triggerMask<<=32;
-  triggerMask|=evtData->fCommonHeader[5];
+  AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
 
   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]);
   }
 
+  return ReadoutList(triggerMask);
+}
+
+AliHLTReadoutList AliHLTCTPData::ReadoutList(AliHLTUInt64_t  triggerMask) const
+{
   // take an 'OR' of all active trigger classes 
   AliHLTReadoutList list;
   for (int i=0; i<gkNCTPTriggerClasses; i++) {
@@ -414,6 +451,7 @@ AliHLTEventDDL AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trig
   return list;
 }
 
+
 void AliHLTCTPData::Print(Option_t* /*option*/) const
 {
   // see header file for function documentation