]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTCTPData.cxx
removing custom streamer of AliHLTCTPData
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTCTPData.cxx
index 4d5b7ea05f414fb4ce0ac6a219eaa6ed6476a13e..c14026e0dd993441184371d5e46ec0ff2d706544 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 "AliHLTCDHWrapper.h"
+#include <limits>
+#include <sstream>
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTCTPData)
@@ -38,7 +41,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 +58,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 +77,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 +93,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,17 +183,17 @@ 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) {
            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("-");
@@ -201,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 {
@@ -214,69 +224,75 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
   }
 
   ResetCounters();
+  ReadMap();
 
   return 0;
 }
 
-AliHLTUInt64_t AliHLTCTPData::ActiveTriggers(const AliHLTComponentTriggerData& trigData)
+AliHLTTriggerMask_t AliHLTCTPData::ActiveTriggers(const AliHLTComponentTriggerData& trigData)
 {
   // extract active triggers from the trigger data
-  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) 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];
-  return triggerMask;
+  AliHLTCDHWrapper cdh;
+  if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL) != 0) return 0x0;
+  if ((cdh.GetL1TriggerMessage() & 0x1) == 0x1) return 0x0;  // invalid for software triggers.
+
+  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
-  if (trigData.fDataSize != sizeof(AliHLTEventTriggerData)) {
-    HLTError("invalid trigger data size: %d expected %d", trigData.fDataSize, sizeof(AliHLTEventTriggerData));
-    return false;
-  }
+  
+  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
-  AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
-  AliHLTUInt64_t triggerMask=evtData->fCommonHeader[6]&0x3ffff;
-  triggerMask<<=32;
-  triggerMask|=evtData->fCommonHeader[5];
+  AliHLTTriggerMask_t triggerMask(cdh.GetTriggerClasses());
+  AliHLTTriggerMask_t triggerHigh(cdh.GetTriggerClassesNext50());
+  triggerMask |= (triggerHigh << 50);
 
   if (fMask!=0 && (triggerMask & fMask)==0) {
-    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]);
+    AliHLTEventTriggerData* evtData=reinterpret_cast<AliHLTEventTriggerData*>(trigData.fData);
+    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
 
   // 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());
+       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<<i)) par.push_back(1.0);
+       if ( triggerMask.test((*pMap)[index]) ) par.push_back(1.0);
        else par.push_back(0.0);
       }
     }
@@ -305,13 +321,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.test(index) ? 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]++;
     }
@@ -319,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]++;    
   }
 }
@@ -333,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]++;    
   }
   
@@ -342,20 +366,21 @@ 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;
-  }
-
-  // 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];
-
-  if (fMask!=0 && (triggerMask & fMask)==0) {
-    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]);
+  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.
+
+  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 %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;
@@ -381,32 +406,65 @@ 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;
+}
 
-  // 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];
 
-  if (fMask!=0 && (triggerMask & fMask)==0) {
-    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]);
+AliHLTReadoutList AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trigData) const
+{
+  // see header file for function documentation
+
+  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();
+
+  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 %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(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);
   }
@@ -414,6 +472,7 @@ AliHLTEventDDL AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trig
   return list;
 }
 
+
 void AliHLTCTPData::Print(Option_t* /*option*/) const
 {
   // see header file for function documentation
@@ -423,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();
+}
+