ASCII int map class

Task

Mapping ASCII strings to an integer value.

Description

This class maps an ASCII string to an interger value.
The string / integer combinations are defined in a C - structure:
typedef struct mapMember
{
   char name[40];
   int  value;
};
An array of type mapMember defines the map. In this the searched will be done by the int search(char *name) function, until the string is found or the end of the map has been reached. The returned integer is the corresponding integer value from the map.

Usage

To use this class, instantiate an pbject of type AsciiIntMap. The constructor takes two arguments:
  • Pointer to the map, which is an array of mapMember structurs.
  • Integer value, which is the number of entries in the map.

To search through the map, the function int search(char *name) is used. It takes one argument, which is the string to search for. It's return value is the corresponding integer value from the map.

map = new AsciiIntMap(<map of type mapMember[]>,<Size of map>);
val = map->search(<name>);

To construct the map in the case of HYDRA categories, a shell script catlist.sh exists. It will create one header file catlist.h which contains the map of category variables as string, to there corresponding integer value. It contains two important variables:
#define CATLISTSIZE 105
Size of the map
catMap Categories[105]
the map itself
The type catMap is defines as:
struct catMap { const char name[40]; Int_t value;};
and corresponds to the mapMember from the class definition.

The code in Hydra then should look like:
map = new AsciiIntMap(Categories,CATLISTSIZE);
if(notPersistentCat->Contains(","))
{
    name = strtok((char *)notPersistentCat->Data(),",");
    cat = ((HCategory *)event->getCategory(map->search(name)));
    if(cat) cat->setPersistency(kFALSE);
    do
    {
   name = strtok(NULL,",");
   if(name != NULL)
   {
      cat = ((HCategory *)event->getCategory(map->search(name)));
      if(cat){
      cat->setPersistency(kFALSE);
      }
   }
    }
    while(name!=NULL);
}
else
{
   cat = ((HCategory *)event->getCategory(map->search(name)));
   if(cat) cat->setPersistency(kFALSE);
}
With notPersistentCat contains catXXX names as a list seperated by ",", name is a char[] and cat a HCategory*. This code will set the corresponding categories to not persistent mode.

Comments to this class

 

-- JoernWuestenfeld - 05 Apr 2004
I Attachment Action Size Date WhoSorted ascending Comment
asciintmap.cccc asciintmap.cc manage 576 bytes 2004-04-05 - 11:06 JoernWuestenfeld Mapping ASCII strings to integer values
asciintmap.hh asciintmap.h manage 292 bytes 2004-04-05 - 10:41 JoernWuestenfeld Class definition
catlist.hh catlist.h manage 3 K 2004-04-05 - 10:42 JoernWuestenfeld Create mapping table of all categories from HYDRA
Topic revision: r3 - 2004-04-06, JoernWuestenfeld
Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki Send feedback | Imprint | Privacy Policy (in German)