ASCII int map class


Mapping ASCII strings to an integer value.


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.


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 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);
    name = strtok((char *)notPersistentCat->Data(),",");
    cat = ((HCategory *)event->getCategory(map->search(name)));
    if(cat) cat->setPersistency(kFALSE);
   name = strtok(NULL,",");
   if(name != NULL)
      cat = ((HCategory *)event->getCategory(map->search(name)));
   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
Topic attachments
I Attachment Action Size Date WhoSorted ascending Comment
asciintmap.cccc manage 0.6 K 05 Apr 2004 - 09:06 JoernWuestenfeld Mapping ASCII strings to integer values
asciintmap.hh asciintmap.h manage 0.3 K 05 Apr 2004 - 08:41 JoernWuestenfeld Class definition
catlist.hh catlist.h manage 3.4 K 05 Apr 2004 - 08:42 JoernWuestenfeld Create mapping table of all categories from HYDRA
Topic revision: r3 - 06 Apr 2004, JoernWuestenfeld
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Hades Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)