SlicePrescale_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: SlicePrescale
3 // Module Type: filter
4 // File: SlicePrescale_module.cc
5 //
6 // Generated at Thu Feb 13 05:14:01 2014 by Matthew Tamsett using artmod
7 // from cetpkgsupport v1_04_02.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
18 
19 #include <iostream>
20 #include <memory>
21 
22 #include <stdlib.h> // for rand
23 #include <time.h> // for rand seed
27 
28 //---------------------------------------------------------------------
29 namespace novaddt {
30  class SlicePrescale;
31 }
32 //---------------------------------------------------------------------
34  public:
35  explicit SlicePrescale(fhicl::ParameterSet const & p);
36  virtual ~SlicePrescale();
37  bool filter(art::Event & e) override;
38  void endJob() override;
39  private:
40  // Declare member data here.
41  // Configuration options
42  unsigned int _prescale; ///< prescale factor (1 out of every this many passes are issued as real triggers)
43  std::string _slice_label; ///< label of module making slices
44  std::string _slice_instance; ///< instance of module making slices
45  std::string _mode; ///< prescale mode, can be either fixed or random
46  unsigned int _seed; ///< random number generator seed
47  // counters
48  unsigned int _nEvents = 0;
49  unsigned int _nSlices = 0;
50  unsigned int _nAccepted = 0;
51 
52 };
53 //---------------------------------------------------------------------
55 : _prescale (p.get<unsigned int>("prescale" ))
56 , _slice_label (p.get<std::string >("slice_label" ))
57 , _slice_instance (p.get<std::string >("slice_instance" ))
58 , _mode (p.get<std::string >("mode" ))
59 , _seed (p.get<unsigned int>("seed", time(NULL)))
60 {
61  std::cout << "--- novaddt::SlicePrescale instantiate" << std::endl;
62  std::cout << "\t prescale: " << _prescale << std::endl;
63  std::cout << "\t slice label: " << _slice_label << std::endl;
64  std::cout << "\t slice instance: " << _slice_instance<< std::endl;
65  std::cout << "\t mode: " << _mode << std::endl;
66  std::cout << "\t seed: " << _seed << std::endl;
67 
68  // assert that the mode requested is configured
69  assert( (_mode == "fixed") || (_mode == "random") );
70 
71  // seed the random number generator, use a random default if not specified
72  // in the configuration file.
73  srand(_seed);
74 
75  // Call appropriate Produces<>() functions here.
76  produces<std::vector<HitList>>("Prescaled"+_slice_instance);
77 }
78 //---------------------------------------------------------------------
80 {
81  // Clean up dynamic memory and other resources here.
82 }
83 //---------------------------------------------------------------------
85 {
86  LOG_DEBUG("SlicePrescale")<< "--- novaddt::SlicePrescale filter. Event: "
87  << event.id().event()
88  << std::endl;
89  _nEvents++;
90 
91  // make output product
92  std::unique_ptr< std::vector<HitList> >product(new std::vector<HitList>);
93 
94  // get input product
96  event.getByLabel(_slice_label, _slice_instance, slices);
97  LOG_DEBUG("SlicePrescale") << "\t - got " << slices->size() << " slices" << std::endl;
98 
99  // loop over slices
100  for(size_t i = 0; i < slices->size(); ++i){
101  _nSlices++;
102  // check prescale
103  if ( ((_mode=="fixed") && ( _nSlices%_prescale == _prescale-1)) ||
104  ((_mode=="random") && (rand()%_prescale == _prescale-1)) ){
105  _nAccepted++;
106  LOG_DEBUG("SlicePrescale")<< "\t - not prescaled" << std::endl;
107  // add this hit list into our output product
108  HitList slice = slices->at(i);
109  product->push_back(slice);
110  } // end of check on prescale
111  } // end of loop over slices
112 
113  // put the hits into the event for later use
114  event.put(std::move(product),"Prescaled"+_slice_instance);
115 
116  // always return true
117  return true;
118 }
119 //---------------------------------------------------------------------
121 {
122  std::cout << "--- novaddt::SlicePrescale endJob" << std::endl;
123  std::cout << "\tNumber of events seen: " << _nEvents << std::endl;
124  std::cout << "\tNumber of slices seen: " << _nSlices << std::endl;
125  std::cout << "\tNumber of slices accepted: " << _nAccepted << std::endl;
126 }
127 //---------------------------------------------------------------------
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::string _mode
prescale mode, can be either fixed or random
std::string _slice_instance
instance of module making slices
std::vector< DAQHit > HitList
Definition: HitList.h:15
const char * p
Definition: xmltok.h:285
DEFINE_ART_MODULE(TestTMapFile)
bool filter(art::Event &e) override
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T product(std::vector< T > dims)
std::string _slice_label
label of module making slices
assert(nhit_max >=nhit_nbins)
unsigned int _prescale
prescale factor (1 out of every this many passes are issued as real triggers)
SlicePrescale(fhicl::ParameterSet const &p)
Float_t e
Definition: plot.C:35
unsigned int _seed
random number generator seed