// $Id$ // // File: DEventProcessor_pomegapi.cc // Created: Fri Oct 28 09:29:50 EDT 2016 // Creator: jrsteven (on Linux ifarm1401 2.6.32-431.el6.x86_64 x86_64) // #include "DEventProcessor_pomegapi.h" // Routine used to create our DEventProcessor extern "C" { void InitPlugin(JApplication *locApplication) { InitJANAPlugin(locApplication); locApplication->AddProcessor(new DEventProcessor_pomegapi()); //register this plugin locApplication->AddFactoryGenerator(new DFactoryGenerator_pomegapi()); //register the factory generator } } // "C" //------------------ // init //------------------ jerror_t DEventProcessor_pomegapi::init(void) { // This is called once at program startup. /* //OPTIONAL: Create an EventStore skim. string locSkimFileName = "pomegapi.idxa"; dEventStoreSkimStream.open(locSkimFileName.c_str()); dEventStoreSkimStream << "IDXA" << endl; */ return NOERROR; } //------------------ // brun //------------------ jerror_t DEventProcessor_pomegapi::brun(jana::JEventLoop* locEventLoop, int32_t locRunNumber) { // This is called whenever the run number changes return NOERROR; } //------------------ // evnt //------------------ jerror_t DEventProcessor_pomegapi::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber) { // This is called for every event. Use of common resources like writing // to a file or filling a histogram should be mutex protected. Using // locEventLoop->Get(...) to get reconstructed objects (and thereby activating the // reconstruction algorithm) should be done outside of any mutex lock // since multiple threads may call this method at the same time. // // Here's an example: // // vector mydataclasses; // locEventLoop->Get(mydataclasses); // // japp->RootFillLock(this); // ... fill historgrams or trees ... // japp->RootFillUnLock(this); // DOCUMENTATION: // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software /*********************************************************** REQUIRED ***********************************************************/ //REQUIRED: To run an analysis, You MUST call one at least of the below code fragments. //JANA is on-demand, so if you don't call one of these, then your analysis won't run. //Recommended: Write surviving particle combinations (if any) to output ROOT TTree //If no cuts are performed by the analysis actions added to a DReaction, then this saves all of its particle combinations. //The event writer gets the DAnalysisResults objects from JANA, performing the analysis. // string is DReaction factory tag: will fill trees for all DReactions that are defined in the specified factory const DEventWriterROOT* locEventWriterROOT = NULL; locEventLoop->GetSingle(locEventWriterROOT); locEventWriterROOT->Fill_DataTrees(locEventLoop, "pomegapi"); return NOERROR; } int DEventProcessor_pomegapi::Get_FileNumber(JEventLoop* locEventLoop) const { //Assume that the file name is in the format: *_X.ext, where: //X is the file number (a string of numbers of any length) //ext is the file extension (probably .evio or .hddm) //get the event source JEventSource* locEventSource = locEventLoop->GetJEvent().GetJEventSource(); if(locEventSource == NULL) return -1; //get the source file name (strip the path) string locSourceFileName = locEventSource->GetSourceName(); //find the last "_" & "." indices size_t locUnderscoreIndex = locSourceFileName.rfind("_"); size_t locDotIndex = locSourceFileName.rfind("."); if((locUnderscoreIndex == string::npos) || (locDotIndex == string::npos)) return -1; size_t locNumberLength = locDotIndex - locUnderscoreIndex - 1; string locFileNumberString = locSourceFileName.substr(locUnderscoreIndex + 1, locNumberLength); int locFileNumber = -1; istringstream locFileNumberStream(locFileNumberString); locFileNumberStream >> locFileNumber; return locFileNumber; } //------------------ // erun //------------------ jerror_t DEventProcessor_pomegapi::erun(void) { // This is called whenever the run number changes, before it is // changed to give you a chance to clean up before processing // events from the next run number. return NOERROR; } //------------------ // fini //------------------ jerror_t DEventProcessor_pomegapi::fini(void) { // Called before program exit after event processing is finished. if(dEventStoreSkimStream.is_open()) dEventStoreSkimStream.close(); return NOERROR; }