#!/usr/bin/env perl if($#ARGV < 0){&Usage();exit;} $pluginname = "__nada__"; foreach $arg (@ARGV){ $pluginname = $arg; } if($pluginname eq "__nada__"){&Usage();exit;} print "\n"; print "Generating files for plugin $pluginname ....\n"; # Create directory to hold source mkdir($pluginname); # Create C++ Header File $dhfile = $fname = "DEventProcessor_${pluginname}.h"; open(FILE,">$pluginname/$dhfile"); &PrintFileHeader(); &PrintClass(); close(FILE); print " - $dhfile\n"; # Create C++ Implementation file $ccfile = $fname = "DEventProcessor_${pluginname}.cc"; open(FILE,">$pluginname/$ccfile"); &PrintFileHeader(); &PrintMethods(); close(FILE); print " - $ccfile\n"; # Create Makefile open(FILE,">$pluginname/Makefile"); &PrintMakefile(); close(FILE); print " - Makefile\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_${pluginname}_ \#define _DEventProcessor_${pluginname}_ \#include class DEventProcessor_${pluginname}:public jana::JEventProcessor{ public: DEventProcessor_${pluginname}(); ~DEventProcessor_${pluginname}(); const char* className(void){return \"DEventProcessor_${pluginname}\";} 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_${pluginname}_ "; print FILE $content; } ############### # PrintMethods ############### sub PrintMethods { $content = " \#include \"DEventProcessor_${pluginname}.h\" using namespace jana; // Routine used to create our DEventProcessor \#include \ extern \"C\"{ void InitPlugin(JApplication *app){ InitJANAPlugin(app); app->AddProcessor(new DEventProcessor_${pluginname}()); } } // \"C\" //------------------ // DEventProcessor_${pluginname} (Constructor) //------------------ DEventProcessor_${pluginname}::DEventProcessor_${pluginname}() { } //------------------ // ~DEventProcessor_${pluginname} (Destructor) //------------------ DEventProcessor_${pluginname}::~DEventProcessor_${pluginname}() { } //------------------ // init //------------------ jerror_t DEventProcessor_${pluginname}::init(void) { // Create histograms here return NOERROR; } //------------------ // brun //------------------ jerror_t DEventProcessor_${pluginname}::brun(JEventLoop *eventLoop, int runnumber) { return NOERROR; } //------------------ // evnt //------------------ jerror_t DEventProcessor_${pluginname}::evnt(JEventLoop *loop, int eventnumber) { // Fill histograms here return NOERROR; } //------------------ // erun //------------------ jerror_t DEventProcessor_${pluginname}::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_${pluginname}::fini(void) { // Called at very end. This will be called only once return NOERROR; } "; print FILE $content; } ############### # PrintMakefile ############### sub PrintMakefile() { # Contents of default Makefile for plugins print FILE "\n"; print FILE "PACKAGES = ROOT:JANA\n"; print FILE "\n"; print FILE "include \$(HALLD_HOME)/src/BMS/Makefile.shlib\n"; print FILE "\n"; } ############### # Usage ############### sub Usage() { print "\n"; print "Usage:\n\t mkplugin name\n"; print "\n"; print "Generate the C++ source and header files to implement a new\n"; print "plugin for use with the Hall-D analysis framework.\n"; print "\n"; print "This script superceeds some similar functionality in the mkprocessor\n"; print "script. Unlike mkprocessor, the mkplugin script will create a directory\n"; print "for the files and write the files to it. In addition, it will create\n"; print "a default Makefile so that one can immediately compile the new plugin.\n"; print "\n"; print "The C++ files generated will define a class based on JEventProcessor.\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 "It should be noted that plugins do not require and are not limited\n"; print "to implementing JEventProcessor objects. This is just forseen as the\n"; print "most common use and so a skeleton implementation is provided here.\n"; print "\n"; print "\n"; print "\n"; }