We have a pointer to the eventNode already(ev). What if we would like to see the information in one of the eventNode's children(an erpNode for example)? Well, to do that there are a few special functions in FARFALLA to give you the information.
First of all it is useful to know how many(if there were any at all) children there are of a particular type. To get this information you use the numChildren() function. Here is an example of how to use it.
numErp = ev->numChildren(erpType);
So, you see that numChildren() is actually a member function of the eventNode. Just as run is a data member of the eventNode, numChildren() is a function member. In fact, numChildren() was defined in the general F_Node class so all inherited node types have this function because of the way inheritance works.
The parameter of numChildren()(in this case erpType) tells FARFALLA what sort of children we are interested in. In the FARFALLA tree represented in Figure 1 ev->numChildren(erpType) would return 2, while ev->numChildren(wireTrackType) would return 1. If we wanted to check if one of the erpNodes had children we could type erpBank->numChildren(someOtherType) which in the case of Figure 1 would return 0.
So if you have any pointer to some sort of node the way to find out how many children it has of a particular type is to use:
pointer->numChildren(childType)
Now that you have a way of knowing how many of a particular type of node there are how do you actually get a pointer to point at it? We have written a function called F_getchild() to do this for you. If you wanted the 0th erpNode child (in C/C++ we start counting at 0 not 1, so the first memeber of an array is array[0] and the first child is the 0th child) of the parent pointed to by ev you would type:
F_getchild(ev,erpBank,0); //make erpBank point at the first child of ev
erpBank is a pointer which you have already declared somewhere like this:
erpNode *erpBank;
So in this case F_getChild() finds the 0th child(of type erpType) of the parent pointed at by ev and makes erpBank(a pointer to an erpNode) point at it. Here is a way to go through all of the erpNodes and add up the energies(assuming that you already have the pointer ev to the eventNode at the top of the tree):
erpNode *erpBank; //declare a pointer to an erpNode
float totalEnergy; //declare a float called totalEnergy
totalEnergy = 0;
for (i=0; i < ev->numChildren(erpType); i=i+1) // loop on i from 0 to #children
{
F_getchild(ev,erpBank,i); //make erpBank point at the ith child
totalEnergy = totalEnergy + erpBank->energy;
}
In this example as long as i is less than the number of children of type erpType it will continue to loop through the children adding the energy in each erpNode to the total.
One interesting thing to note in this example is that we used the same pointer(erpBank) to point at different erpNodes each time through the for loop.
For the casual user these two routines(numChildren() and F_getchild()) are the only two routines you need to know. A more complete list of commands exists in the FARFALLA Programming Reference Guide. If you want to create your own node types and add them to a tree a later section will tell you how to do that. Now, let us give you a more complete example.