It is possible to write stand alone FARFALLA programs which read data in from the disk and analyze them. We suggest using the DASH system written be Ed Kearns however. We have completely integrated FARFALLA into DASH and we have written DASH READ and WRITE modules to read FARFALLA structured data on and off of disk. If you are interested in using DASH and don't know about it refer to ``DASH: A Data Analysis Shell Manual for MACRO Users V2.1[Int Memo 1021/93]''.
No matter how you read your FARFALLA data off the disk however you will need to do basically the same thing. In this example we assume that after the program reads an event off of disk it puts the tree into memory and makes a global pointer called ev which points at the top of the data structure(an eventNode). In fact, this is what our DASH READ module does.
Here is a complete small analysis routine which analyzes FARFALLA data. It fills an HBOOK histogram with the value of the ERP adc0u. The name of the routine is erpEvent, and we have included the complete contents of the file.
#include <farfalla.h> // We must always include this header file
#include <eventNode.h> // This header contains the event class definition
#include <erpNode.h> // This header contains the erp class definition
#include <hbook.h> // A file with definitions for HBOOK functions
extern eventNode *ev; //This is the global pointer to ev
//extern means it is global(shared
//among other files and routines)
void erpEvent() //The start of our function
{
erpNode *erpBank; //Declare an erpNode pointer
for (int i=0; i < ev->numChildren(erpType); i=i+1) //Loop over children
{
F_getChild(ev,erpBank,i); //Get the child
hfill_(100,(float)erpBank->adc0u,0.0F,1.0F); //Fill the HISTO
}
}
That's really all there is to it. We should make some comments about a few things we did here that we didn't mention before. The first thing is the line:
#include <farfalla.h>
As you might expect this tells the compiler to include a file called farfalla.h . The ``<'' and ``>'' symbols tell the compiler to look in a special directory for the file. If you were to type:
#include "farfalla.h"
then the compiler would look for farfalla.h in the directory you were compiling in.
The file farfalla.h contains various definitions for the FARFALLA package. You should always include this file in the top of any files with routines using FARFALLA. The file erpNode.h referred to in the second line has the erpNode class definition contained in it. If you did not include this file the compiler would not know what erpNode* or erpBank->adc0u meant.
Next you see the line:
#include <hbook.h>
This is a file which has declarations of the CERN library HBOOK routines in it. It is what tells our program about the HFILL routine and the fact that it is actually a FORTRAN program.
In the for loop there is something new also. In C++ you can initialize your variables when you declare them. So the statement:
int i=0;
both declares i to be an integer and also sets it equal to 0.
Also notice in the line where we call HFILL the numbers are followed by F. This is because in C++ a constant with a decimal point is by default a double precision variable. The F converts it into a float(which is the C/C++ equivalent of the FORTRAN REAL and the type of variable that the HFILL routine expects).