Babar logo
HEPIC E,S & H Databases PDG HEP preprints
Organization Detector Computing Physics Documentation
Personnel Glossary Sitemap Search Hypernews
Workbook Home Introduction Account Setup QuickTour Packages Modules Unwrap page!
Event Information Tcl Commands Editing Compile and Link Run the Job Debugging
Check this page with the
W3C Validator
(More checks...)
Parameters Tcl Files Find Data Batch Analysis ROOT Tutorial

Annotated QExample

Annotated QExample.hh

This is C++ code.

Everything following a double slash '//' is a comment. Comments are meant 
for individuals reading through code, and are completely ignored by the 

// QExample: Example analysis module for the Offline Workbook
// The workbook can be found on the web at:
//   /BFROOT/www/doc/workbook/workbook.html


These two lines are part of the preprocessor 
syntax to ensure that header files do not get included multiple times.

#include "Framework/AppModule.hh"
#include "AbsEvent/AbsEvent.hh"
#include "HepTuple/Histogram.h"

The classes and member functions defined in the 
included header files can be used anywhere in this header file and 
in the implementation file If there are commands or 
classes that you do not recognize when looking through code, the 
included header files are a reasonable first place to look. These are 
all BaBar specific header files so they are enclosed by double 

class QExample : public AppModule {

The QExample class inherits from the AppModule class. 
This means that it has a common interface and must supply implementation for 
any virtual functions declared in the AppModule class. The structure of the 
QExample class will be defined within the open and closed curly brackets 
'{' and '}'.


Public members can be freely used by all code. For 
general purposes constructors and destructors should be made public. The 
member functions and data members that this class should "export" or make 
available for use by other applications should also be made public.

  // Constructors
  QExample( const char* const theName, const char* const theDescription );

  // Destructor
  virtual ~QExample( );

  // Operations

  virtual AppResult  beginJob( AbsEvent* anEvent );
  virtual AppResult  event( AbsEvent* anEvent );
  virtual AppResult  endJob  ( AbsEvent* anEvent );

Protected members can only be used or altered by 
classes that have been designated as friends of this class and by 
friends of classes derived from this one. In this case there are no 
protected members.

Private members can only be used or altered by 
friends of this class. A class is a friend of itself. Typically, 
protected members contain the details of the class implementation.

  HepHistogram* _numTrkHisto;

The QExample class declaration contains a pointer that is only 
allowed to point to an object of type HepHistogram and is named _numTrkHisto. 
Just the pointer is the data member of the class. The memory for the 
object that is pointed to does not belong to the class.


The QExample class declaration is completed, the 
closed curly brace '}' ends the body and the semicolon ';' marks the end 
of the declaration.



// QExample: Example analysis module for the Offline Workbook
// The workbook can be found on the web at:
//   /BFROOT/www/doc/workbook/workbook.html

#include "BaBar/BaBar.hh"

#include "BetaMiniUser/QExample.hh"

The implementation file must always 
#include its own header file.

#include "AbsEnv/AbsEnv.hh"
#include "Beta/BtaCandidate.hh"
#include "GenEnv/GenEnv.hh"
#include "HepTuple/TupleManager.h"

If a C++ object is used only 
in the implementation file, but not in the header file, 
then you can put the #include for that object in the 
.cc file instead of the .hh file.

// Constructors --

// in general, a module constructor should not do much.  The beginJob
// function is a better place to put initialization

Right now, the QExample constructor does not 
do anything.  Later in the Workbook, you will use it to 
add run-time parameters to your module.

QExample::QExample( const char* const theName, 
		  const char* const theDescription )
  : AppModule( theName, theDescription )

// Destructor --

// The destructor should be limited to undoing the work of the constructor

In C++ code, destructors often do not do anything.

QExample::~QExample( )

// Operations --

// The beginJob member function is run before any events are
// processed.  In this example code, it opens the output histogram file
// and then books a histogram.

QExample::beginJob( AbsEvent* anEvent )
  HepTupleManager* manager = gblEnv->getGen()->ntupleManager();

  // book the number-of-tracks histogram
  _numTrkHisto = manager->histogram("Tracks per Event",  20, 0., 20. ); 

  return AppResult::OK;

Note that the beginJob, endJob, and event 
commands all end with "return AppResult::OK".  This (or another 
AppResult, like AppResult::ERROR) is required because all three 
functions must return an object of type AppResult.


// The endJob function is called after all events have been processed.

Like the destructor, the endJob function of a module 
often does not do anything.  Sometimes it is used to print messages 
like "QExample: endJob()", to let the user know that the module 
reached endJob.

QExample::endJob( AbsEvent* anEvent ) 
  return AppResult::OK;

// event function is called once per event

As you know, the event function is the key function, 
the place where you get event information.  Note how the get function 
uses QExample's AbsEvent pointer to find the ChargedTracks list 
in the Event Store.

QExample::event( AbsEvent* anEvent )

  // get list of input track candidates
  HepAList<BtaCandidate>* trkList  =
    Ifd<HepAList< BtaCandidate > >::get(anEvent, "ChargedTracks");

The length() function is a member function 
of the HepAList C++ class.  It returns the number of 
BtaCandidates in the list.  In this case, since the list is 
ChargedTracks, that means you get the number of tracks 
in the event.
  //histogram number of tracks in event
  _numTrkHisto->accumulate( trkList->length() );
  // done
  return AppResult::OK;

Back to Editing Code.