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.
--
JoernWuestenfeld - 05 Apr 2004