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