#!/usr/bin/env perl if($#ARGV < 0){&Usage();exit;} $classname = "__nada__"; foreach $arg (@ARGV){ if($arg eq "-plugin"){ $is_plugin=1; }else{ $classname = $arg; } } if($classname eq "__nada__"){&Usage();exit;} print "\n"; print "Generating files for event processor $classname ....\n"; $dhfile = $fname = "DEventProcessor_${classname}.h"; open(FILE,">$dhfile"); &PrintFileHeader(); &PrintClass(); close(FILE); print " - $dhfile\n"; $ccfile = $fname = "DEventProcessor_${classname}.cc"; open(FILE,">$ccfile"); &PrintFileHeader(); &PrintMethods($is_plugin); close(FILE); print " - $ccfile\n"; print "\n"; if($is_plugin!=0){ print "CAUTION: Code has been added to allow this to be compiled as a plugin.\n"; print "If mulitple processors exist in this same directory, only one should\n"; print "include the \"InitPlugin\" routine. Other processors will need to be\n"; print "added to the single InitPlugin routine by hand.\n"; } print "\n"; ############### # PrintFileHeader ############### sub PrintFileHeader() { # print a few lines at the very top of the file $uname = `uname -nprs`; chomp($uname); print FILE "// \$Id\$\n"; print FILE "//\n"; print FILE "// File: $fname\n"; print FILE "// Created: ".`date`; print FILE "// Creator: ".$ENV{"USER"}." (on $uname)\n"; print FILE "//\n"; } ############### # PrintClass ############### sub PrintClass() { $content = " \#ifndef _DEventProcessor_${classname}_ \#define _DEventProcessor_${classname}_ \#include class DEventProcessor_${classname}:public jana::JEventProcessor{ public: DEventProcessor_${classname}(); ~DEventProcessor_${classname}(); const char* className(void){return \"DEventProcessor_${classname}\";} private: jerror_t init(void); ///< Called once at program start. jerror_t brun(jana::JEventLoop *eventLoop, int runnumber); ///< Called everytime a new run number is detected. jerror_t evnt(jana::JEventLoop *eventLoop, int eventnumber); ///< Called every event. jerror_t erun(void); ///< Called everytime run number changes, provided brun has been called. jerror_t fini(void); ///< Called after last event of last event source has been processed. }; \#endif // _DEventProcessor_${classname}_ "; print FILE $content; } ############### # PrintMethods ############### sub PrintMethods { $content = " \#include \"DEventProcessor_${classname}.h\" using namespace jana; "; # If first argument is non-zero, then add code to make this a plugin if($_[0]!=0){ $content = $content." // Routine used to create our DEventProcessor \#include \ extern \"C\"{ void InitPlugin(JApplication *app){ InitJANAPlugin(app); app->AddProcessor(new DEventProcessor_${classname}()); } } // \"C\" "; } $content = $content." //------------------ // DEventProcessor_${classname} (Constructor) //------------------ DEventProcessor_${classname}::DEventProcessor_${classname}() { } //------------------ // ~DEventProcessor_${classname} (Destructor) //------------------ DEventProcessor_${classname}::~DEventProcessor_${classname}() { } //------------------ // init //------------------ jerror_t DEventProcessor_${classname}::init(void) { // Create histograms here return NOERROR; } //------------------ // brun //------------------ jerror_t DEventProcessor_${classname}::brun(JEventLoop *eventLoop, int runnumber) { return NOERROR; } //------------------ // evnt //------------------ jerror_t DEventProcessor_${classname}::evnt(JEventLoop *loop, int eventnumber) { // Fill histograms here return NOERROR; } //------------------ // erun //------------------ jerror_t DEventProcessor_${classname}::erun(void) { // Any final calculations on histograms (like dividing them) // should be done here. This may get called more than once. return NOERROR; } //------------------ // fini //------------------ jerror_t DEventProcessor_${classname}::fini(void) { // If another DEventProcessor is in the list ahead of this one, then // it will have finished before this is called. e.g. closed the // ROOT file! return NOERROR; } "; print FILE $content; } ############### # Usage ############### sub Usage() { print "\n"; print "Usage:\n\t mkprocessor [-plugin] name\n"; print "\n"; print "Generate the C++ source and header files to implement a new\n"; print "event processor for use with the Hall-D analysis framework.\n"; print "The files will define a class which inherits from.\n"; print "JEventProcessor and can therefore be added to a program\n"; print "using the the AddEventProcessor() method of JApplication.\n"; print "\n"; print "The \"name\" parameter specifies a unique name for the class.\n"; print "The class will, by default, be called DEventProcessor_name.\n"; print "This can lead to long names, but at least it is clear.\n"; print "what they are.\n"; print "\n"; print "Event processors are starting (or end) points in the analysis\n"; print "chain. They are typically used for creating histograms and trees.\n"; print "Only one (of each type) of event processor object is created\n"; print "in a program which is then used by all threads. This is in\n"; print "contrast to factories which are created for each thread.\n"; print "If you wish to generate data visible by other factories and\n"; print "event processors, then see mkfactory.\n"; print "\n"; print "One can add code to easily make this a plugin via the\n"; print "command line switch:\n"; print "\n"; print " -plugin \n"; print "\n"; print "If this switch is present on the command line, a \"InitPlugin\"\n"; print "routine will be added to the .cc file creating a DEventProcessor\n"; print "of this type and adding it to the JApplication.\n"; print "\n"; print "\n"; print "\n"; }