Skip to topic | Skip to bottom
Home
ILC
ILC.EnGeneralr1.1 - 08 Jan 2009 - 10:11 - Main.iglesiastopic end

Start of topic | Skip to actions

3. Crear tu propio procesador

3.a. En general

Unless you want to add an processor to an existing package you should add a new package if you develop new processors to carry out reconstruction or analysis tasks. All additional packages are expected to live in the $MARLIN/packages directory. To decouple Marlin form the additional processors, the subdirectories holding these processors are linked using symbolic links to Marlin’s packages directory. The actual source code is placed in an individual subdirectory - for example MyPackage - in $LCSoft/packages and have the structure:

$LCSoft/packages/MyPackage/include
./src/
./src/GNUmakefile
./lib

The GNUmakefile has a target ’lib’, that creates a library

$LCSoft/packages/MyPackage/lib/libMyPackage.a

To set up a new package you can execute the following commands:

cd $LCSoft/packages
mkdir MyPackage
cd MyPackage
mkdir include
mkdir src
mkdir lib
cd src
cp $LCSoft/Marlin/examples/mymarlin/GNUmakefile .
Edit the GNUmakefile to assign the name of your package (in this case MyPackage) to the variable PROGNAME.

Lets assume we want to write a processor with the name MyProcessor. Each Marlin processor inherits from the class Processor and has to have at least the following methods implemented:

virtual Processor newProcessor(): Returns a pointer to a object of type MyProcessor, needed for internal processor management.

MyProcessor() : Constructor of the class.

virtual void init() : Called at the begin of the job before anything is read. Use to initialise the processor, e.g. book histograms.

virtual void processRunHeader( LCRunHeader * run ) : Called for every run.

virtual void processEvent( LCEvent * evt ) : Called for every event - the working horse.

virtual void check( LCEvent * evt ): Called for each event after processing to produce checks or plots.

virtual void end(): Called after data processing for clean up.

Figures 2 and 3 (at the end of this page)show a very simple example for a processor which counts the number of runs and events in a LCIO file. In addition it prints for each event the number of Monte Carlo particles. The collection name of the Monte Carlo particles can be given to the processor via a steering parameter. The default setting is MCParticle. The two include statements in the header file

#include "marlin/Processor.h"
#include "lcio.h"
are mandatory because the class inherits from the Marlin class Processor. Furthermore Marlin uses LCIO also as the internal data model and thus every processor needs to know about it. Besides the methods already described above, there are three variables declared which are used to count the number of runs and events in the LCIO file ( nRun, nEvt) and hold the collection name of Monte Carlo particles ( colName). Of course the implementation file has to include the corresponding header file. All additional include directives include header files which are required by the user. The line registers the processor MyProcessor at the Marlin framework. In the initialisation part of the constructor of MyProcessor? the constructor of Processor is called with the name of the processor. A short description of the processor is stored in the string description. The function call to registerProcessorParameter() allows to register a processor parameter which can be set in the steering file.Together with the name of the processor parameter a short description, a default value and a variable that holds the value of the parameter is specified.

In the function init() the processor parameters and their values as used in the program are printed to the standard output and some parameters are initialised. While processRunHeader() is only used to count the number of runs, processEvent() is used to print the number of Monte Carlo particles for each event and count the number of events found in the LCIO file. Since no checks are performed check() is empty. At the end of data processing end() prints the total number of runs and events processed.

Header file of defining the class MyProcessor. (Figure 2)

MyProcessor aMyProcessor ;
#ifndef MyProcessor_h
#define MyProcessor_h 1
#include "marlin/Processor.h"
#include "lcio.h"
#include <string>
using namespace lcio ;
using namespace marlin ;
class MyProcessor : public Processor {
public:
virtual Processor* newProcessor() { return new MyProcessor ; }
MyProcessor() ;
virtual void init() ;
virtual void processRunHeader( LCRunHeader* run ) ;
virtual void processEvent( LCEvent * evt ) ;
virtual void check( LCEvent * evt ) ;
virtual void end() ;
protected:
std::string _colName ;
int _nRun ;
int _nEvt ;
} ;
#endif

Implementation of the class MyProcessor. (Figure 3)

#include "MyProcessor.h"
#include <iostream>
#include <EVENT/LCCollection.h>
#include <EVENT/MCParticle.h>
using namespace lcio ;
using namespace marlin ;
MyProcessor aMyProcessor ;
MyProcessor::MyProcessor() : Processor("MyProcessor") {
_description = "MyProcessor does whatever it does ..." ;
registerProcessorParameter( "CollectionName" ,
"Name of the MCParticle collection" ,
_colName ,
std::string("MCParticle") ) ;
}
void MyProcessor::init() {
printParameters() ;
_nRun = 0 ;
_nEvt = 0 ;
}
void MyProcessor::processRunHeader( LCRunHeader* run) {
_nRun++ ;
}
void MyProcessor::processEvent( LCEvent * evt ) {
_nEvt ++ ;
LCCollection* inParVec = evt->getCollection(_colname) ;
std::cout << "Event no. " << _nEvt << " has "
<< inParVec->getNumberOfElements()
<< " Monte Carlo particles" << std::endl;
}
void MyProcessor::check( LCEvent * evt ) {
// nothing to check here - could be used to fill checkplots
// in reconstruction processor
}
void MyProcessor::end(){
std::cout << "MyProcessor::end() " << name()
<< " processed " << _nEvt << " events in " << _nRun << " runs "
<< std::endl ;
}

3.a.i. Primer paso

-- Main.iglesias - 08 Jan 2009
to top


You are here: ILC > EnGeneral

to top

Copyright © 1999-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding this material Send feedback