]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
adding support for similar class names (e.g 'mytrigger', 'mytriggerA'). This
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 8 Apr 2010 07:10:26 +0000 (07:10 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 8 Apr 2010 07:10:26 +0000 (07:10 +0000)
had been ommitted in the first implementation of EvaluateCTPTriggerClass

Adding new method to check the status of a trigger. Can be used instead of
EvaluateCTPTriggerClass as this function requires to have the exact class name
present in the running trigger configuration.
  /**
   * Check state of a trigger class.
   * If the class name is not part of the current trigger setup (i.e. ECS parameter
   * does not contain a trigger definition for this class name) the function
   * returns -1
   * @return -1 class name not initialized,
   *          0 trigger not active
   *          1 trigger active
   */
  int CheckTrigger(const char* name) const;

HLT/BASE/AliHLTCTPData.cxx
HLT/BASE/AliHLTCTPData.h

index d6a872490661ef6ab9fdb1c75b723294b324de8e..7f73f75c068ae9fb94866db70bff979bf0a5b70c 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"
@@ -38,7 +38,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 +55,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 +74,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());
@@ -92,6 +97,7 @@ AliHLTCTPData& AliHLTCTPData::operator=(const AliHLTCTPData& src)
     fCounters=src.Counters();
   }
 
+  ReadMap();
   return *this;
 }
 
@@ -215,6 +221,7 @@ int AliHLTCTPData::InitCTPTriggerClasses(const char* ctpString)
   }
 
   ResetCounters();
+  ReadMap();
 
   return 0;
 }
@@ -263,21 +270,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);
       }
     }
@@ -306,6 +319,14 @@ 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
@@ -382,6 +403,32 @@ const char* AliHLTCTPData::Name(int index) const
   return fClassIds.At(index)->GetName();
 }
 
+int AliHLTCTPData::ReadMap(vector<unsigned> &map) const
+{
+  // 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;
+}
+
+
 AliHLTEventDDL AliHLTCTPData::ReadoutList(const AliHLTComponentTriggerData& trigData) const
 {
   // see header file for function documentation
index 2548376e66727e2658ce0bb61d2db1de55f20202..427ff95fad46339577ceab068962a444e1defcef 100644 (file)
@@ -99,6 +99,17 @@ class AliHLTCTPData: public TNamed, public AliHLTLogging
    */
   int Index(const char* name) const;
 
+  /**
+   * Check state of a trigger class.
+   * If the class name is not part of the current trigger setup (i.e. ECS parameter
+   * does not contain a trigger definition for this class name) the function
+   * returns -1
+   * @return -1 class name not initialized, 
+   *          0 trigger not active
+   *          1 trigger active
+   */
+  int CheckTrigger(const char* name) const;
+
   /**
    * Increment counter for CTP trigger classes
    * @param classIds  comma separated list of class ids
@@ -169,12 +180,24 @@ class AliHLTCTPData: public TNamed, public AliHLTLogging
    */
   int Add(const AliHLTCTPData& src, int factor, int &skipped);
 
+  /**
+   * Read the map of trigger class indexes
+   * The map is used in the generation of the TFormula from the trigger
+   * expression in order to handle similar class names correctly.
+   * For names like 'base', 'baseA', 'baseB' the class with the longer name
+   * has to be replaced first.
+   */
+  int ReadMap(vector<unsigned> &map) const;
+
+  int ReadMap() {return ReadMap(fMap);}
+
   AliHLTUInt64_t fMask;      /// mask of initialized trigger classes
   AliHLTUInt64_t fTriggers;  /// current trigger
   TClonesArray   fClassIds;  /// array of trigger class ids
   TArrayL64      fCounters;  /// trigger class counters
+  vector<unsigned> fMap;     //! index map for trigger expression evaluation
 
-  ClassDef(AliHLTCTPData, 1)
+  ClassDef(AliHLTCTPData, 2)
 };
 
 #endif