Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_Z2pi_trees.cc
Go to the documentation of this file.
1 // $Id$
2 // DEventProcessor_Z2pi_trees, modeled after DEventProcessor_p2pi_trees
3 //
4 // File: DEventProcessor_p2pi_trees.cc
5 // Created: Wed Mar 29 16:34:58 EDT 2017
6 // Creator: elton (on Linux ifarm1401.jlab.org 3.10.0-327.el7.x86_64 x86_64)
7 //
8 
10 
11 // Routine used to create our DEventProcessor
12 
13 extern "C"
14 {
15  void InitPlugin(JApplication *locApplication)
16  {
17  InitJANAPlugin(locApplication);
18  locApplication->AddProcessor(new DEventProcessor_Z2pi_trees()); //register this plugin
19  locApplication->AddFactoryGenerator(new DFactoryGenerator_Z2pi_trees()); //register the factory generator
20  }
21 } // "C"
22 
23 //------------------
24 // init
25 //------------------
27 {
28  // This is called once at program startup.
29 
30  /*
31  //OPTIONAL: Create an EventStore skim.
32  string locSkimFileName = "Z2pi_trees.idxa";
33  dEventStoreSkimStream.open(locSkimFileName.c_str());
34  dEventStoreSkimStream << "IDXA" << endl;
35  */
36 
37  return NOERROR;
38 }
39 
40 //------------------
41 // brun
42 //------------------
43 jerror_t DEventProcessor_Z2pi_trees::brun(jana::JEventLoop* locEventLoop, int32_t locRunNumber)
44 {
45  // This is called whenever the run number changes
46 
47  return NOERROR;
48 }
49 
50 //------------------
51 // evnt
52 //------------------
53 jerror_t DEventProcessor_Z2pi_trees::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber)
54 {
55  // This is called for every event. Use of common resources like writing
56  // to a file or filling a histogram should be mutex protected. Using
57  // locEventLoop->Get(...) to get reconstructed objects (and thereby activating the
58  // reconstruction algorithm) should be done outside of any mutex lock
59  // since multiple threads may call this method at the same time.
60  //
61  // Here's an example:
62  //
63  // vector<const MyDataClass*> mydataclasses;
64  // locEventLoop->Get(mydataclasses);
65  //
66  // japp->RootFillLock(this);
67  // ... fill historgrams or trees ...
68  // japp->RootFillUnLock(this);
69 
70  // DOCUMENTATION:
71  // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software
72 
73  /*********************************************************** REQUIRED ***********************************************************/
74 
75  //REQUIRED: To run an analysis, You MUST call one at least of the below code fragments.
76  //JANA is on-demand, so if you don't call one of these, then your analysis won't run.
77 
78 
79  //Recommended: Write surviving particle combinations (if any) to output ROOT TTree
80  //If no cuts are performed by the analysis actions added to a DReaction, then this saves all of its particle combinations.
81  //The event writer gets the DAnalysisResults objects from JANA, performing the analysis.
82  // string is DReaction factory tag: will fill trees for all DReactions that are defined in the specified factory
83  const DEventWriterROOT* locEventWriterROOT = NULL;
84  locEventLoop->GetSingle(locEventWriterROOT);
85  locEventWriterROOT->Fill_DataTrees(locEventLoop, "Z2pi_trees");
86 
87 
88 
89  //Optional: Get the analysis results for all DReactions.
90  //Getting these objects triggers the analysis, if it wasn't performed already.
91  //These objects contain the DParticleCombo objects that survived the DAnalysisAction cuts that were added to the DReactions
92  // vector<const DAnalysisResults*> locAnalysisResultsVector;
93  // locEventLoop->Get(locAnalysisResultsVector);
94 
95 
96  return NOERROR;
97 }
98 
99 int DEventProcessor_Z2pi_trees::Get_FileNumber(JEventLoop* locEventLoop) const
100 {
101  //Assume that the file name is in the format: *_X.ext, where:
102  //X is the file number (a string of numbers of any length)
103  //ext is the file extension (probably .evio or .hddm)
104 
105  //get the event source
106  JEventSource* locEventSource = locEventLoop->GetJEvent().GetJEventSource();
107  if(locEventSource == NULL)
108  return -1;
109 
110  //get the source file name (strip the path)
111  string locSourceFileName = locEventSource->GetSourceName();
112 
113  //find the last "_" & "." indices
114  size_t locUnderscoreIndex = locSourceFileName.rfind("_");
115  size_t locDotIndex = locSourceFileName.rfind(".");
116  if((locUnderscoreIndex == string::npos) || (locDotIndex == string::npos))
117  return -1;
118 
119  size_t locNumberLength = locDotIndex - locUnderscoreIndex - 1;
120  string locFileNumberString = locSourceFileName.substr(locUnderscoreIndex + 1, locNumberLength);
121 
122  int locFileNumber = -1;
123  istringstream locFileNumberStream(locFileNumberString);
124  locFileNumberStream >> locFileNumber;
125 
126  return locFileNumber;
127 }
128 
129 //------------------
130 // erun
131 //------------------
133 {
134  // This is called whenever the run number changes, before it is
135  // changed to give you a chance to clean up before processing
136  // events from the next run number.
137  return NOERROR;
138 }
139 
140 //------------------
141 // fini
142 //------------------
144 {
145  // Called before program exit after event processing is finished.
146  if(dEventStoreSkimStream.is_open())
147  dEventStoreSkimStream.close();
148  return NOERROR;
149 }
150 
int Get_FileNumber(JEventLoop *locEventLoop) const
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t locEventNumber)
Called every event.
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t init(void)
Called once at program start.
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t locRunNumber)
Called every time a new run number is detected.
InitPlugin_t InitPlugin
void Fill_DataTrees(JEventLoop *locEventLoop, string locDReactionTag) const
jerror_t erun(void)
Called every time run number changes, provided brun has been called.