Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_p4pi_hists.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_p4pi_hists.cc
4 // Created: Mon Aug 29 16:20:58 EDT 2016
5 // Creator: aaustreg (on Linux halld01.jlab.org 2.6.32-642.3.1.el6.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_p4pi_hists()); //register this plugin
18  locApplication->AddFactoryGenerator(new DFactoryGenerator_p4pi_hists()); //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 = "p4pi_hists.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_p4pi_hists::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_p4pi_hists::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  // DOCUMENTATION:
61  // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software
62 
63  /*********************************************************** REQUIRED ***********************************************************/
64 
65  //REQUIRED: To run an analysis, You MUST call one at least of the below code fragments.
66  //JANA is on-demand, so if you don't call one of these, then your analysis won't run.
67 
68 
69  //Recommended: Write surviving particle combinations (if any) to output ROOT TTree
70  //If no cuts are performed by the analysis actions added to a DReaction, then this saves all of its particle combinations.
71  //The event writer gets the DAnalysisResults objects from JANA, performing the analysis.
72  // string is DReaction factory tag: will fill trees for all DReactions that are defined in the specified factory
73  const DEventWriterROOT* locEventWriterROOT = NULL;
74  locEventLoop->GetSingle(locEventWriterROOT);
75  locEventWriterROOT->Fill_DataTrees(locEventLoop, "p4pi_hists");
76 
77 
78  /*
79  //Optional: Get the analysis results for all DReactions.
80  //Getting these objects triggers the analysis, if it wasn't performed already.
81  //These objects contain the DParticleCombo objects that survived the DAnalysisAction cuts that were added to the DReactions
82  vector<const DAnalysisResults*> locAnalysisResultsVector;
83  locEventLoop->Get(locAnalysisResultsVector);
84  */
85 
86 
87  return NOERROR;
88 }
89 
90 int DEventProcessor_p4pi_hists::Get_FileNumber(JEventLoop* locEventLoop) const
91 {
92  //Assume that the file name is in the format: *_X.ext, where:
93  //X is the file number (a string of numbers of any length)
94  //ext is the file extension (probably .evio or .hddm)
95 
96  //get the event source
97  JEventSource* locEventSource = locEventLoop->GetJEvent().GetJEventSource();
98  if(locEventSource == NULL)
99  return -1;
100 
101  //get the source file name (strip the path)
102  string locSourceFileName = locEventSource->GetSourceName();
103 
104  //find the last "_" & "." indices
105  size_t locUnderscoreIndex = locSourceFileName.rfind("_");
106  size_t locDotIndex = locSourceFileName.rfind(".");
107  if((locUnderscoreIndex == string::npos) || (locDotIndex == string::npos))
108  return -1;
109 
110  size_t locNumberLength = locDotIndex - locUnderscoreIndex - 1;
111  string locFileNumberString = locSourceFileName.substr(locUnderscoreIndex + 1, locNumberLength);
112 
113  int locFileNumber = -1;
114  istringstream locFileNumberStream(locFileNumberString);
115  locFileNumberStream >> locFileNumber;
116 
117  return locFileNumber;
118 }
119 
120 //------------------
121 // erun
122 //------------------
124 {
125  // This is called whenever the run number changes, before it is
126  // changed to give you a chance to clean up before processing
127  // events from the next run number.
128  return NOERROR;
129 }
130 
131 //------------------
132 // fini
133 //------------------
135 {
136  // Called before program exit after event processing is finished.
137  if(dEventStoreSkimStream.is_open())
138  dEventStoreSkimStream.close();
139  return NOERROR;
140 }
141 
jerror_t init(void)
Called once at program start.
int Get_FileNumber(JEventLoop *locEventLoop) const
jerror_t erun(void)
Called every time run number changes, provided brun has been called.
InitPlugin_t InitPlugin
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t locRunNumber)
Called every time a new run number is detected.
jerror_t fini(void)
Called after last event of last event source has been processed.
void Fill_DataTrees(JEventLoop *locEventLoop, string locDReactionTag) const
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t locEventNumber)
Called every event.