Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_randomtrigger_skim.cc
Go to the documentation of this file.
1 //
2 // JEventProcessor_randomtrigger_skim.cc
3 //
4 // JANA event processor plugin to skim random triggers to HDDM files
5 //
6 // Author: Sean Dobbs
7 
9 #include "TRIGGER/DL1Trigger.h"
10 #include "BCAL/DBCALHit.h"
11 #include "DAQ/DL1Info.h"
12 #include <HDDM/DEventWriterHDDM.h>
13 #include <DAQ/DBeamCurrent.h>
14 
15 // for initializing plugins
16 extern "C" {
17  void InitPlugin(JApplication *app)
18  {
19  InitJANAPlugin(app);
20  app->AddProcessor(new JEventProcessor_randomtrigger_skim(), true);
21  }
22 } // "extern C"
23 
24 
25 // variables to control which triggers get read out
26 
27 //-------------------------------
28 // init
29 //-------------------------------
31 {
32  return NOERROR;
33 }
34 
35 //-------------------------------
36 // brun
37 //-------------------------------
38 jerror_t JEventProcessor_randomtrigger_skim::brun(JEventLoop *locEventLoop, int32_t runnumber)
39 {
42  dBeamCurrentFactory->brun(locEventLoop, runnumber);
43 
44  return NOERROR;
45 }
46 
47 //-------------------------------
48 // evnt
49 //-------------------------------
50 jerror_t JEventProcessor_randomtrigger_skim::evnt(JEventLoop *locEventLoop, uint64_t eventnumber)
51 {
52  // Get HDDM writer
53  vector<const DEventWriterHDDM*> locEventWriterHDDMVector;
54  locEventLoop->Get(locEventWriterHDDMVector);
55 
56  // beam current and fiducial definition
57  vector<const DBeamCurrent*> beamCurrent;
58  locEventLoop->Get(beamCurrent);
59 
60  //bool is_cosmic_trigger = false;
61  bool is_random_trigger = false;
62 
63  const DL1Trigger *trig = NULL;
64  try {
65  locEventLoop->GetSingle(trig);
66  } catch (...) {}
67 
68  // parse the triggers we want to save
69  if (trig) {
70 
71  if (trig->fp_trig_mask & 0x800) { // Trigger front-panel bit 11
72  // Periodic pulser trigger fired
73  is_random_trigger = true;
74  }
75 
76  }
77 
78  // make sure this is a random trigger event
79  if(!is_random_trigger)
80  return NOERROR;
81 
82  // make sure we can perform a fiducial beam current cut
83  if(beamCurrent.empty())
84  return NOERROR;
85 
86  // make sure the beam is on
87  if(!beamCurrent[0]->is_fiducial)
88  return NOERROR;
89 
90 
91  // Save events to skim file
92  locEventWriterHDDMVector[0]->Write_HDDMEvent(locEventLoop, "random");
93 
94  return NOERROR;
95 }
96 
97 //-------------------------------
98 // erun
99 //-------------------------------
101 {
102  return NOERROR;
103 }
104 
105 //-------------------------------
106 // fini
107 //-------------------------------
109 {
110  return NOERROR;
111 }
112 
jerror_t evnt(JEventLoop *loop, uint64_t eventnumber)
Called every event.
uint32_t fp_trig_mask
Definition: DL1Trigger.h:19
trig[33-1]
jerror_t init(void)
Called once at program start.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t brun(JEventLoop *loop, int32_t runnumber)
Called everytime a new run number is detected.
InitPlugin_t InitPlugin
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t init(void)
Called once at program start.