Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Functions
JDAQ/JDAQFilter.cc File Reference

Example program to select events based on hits in strings. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <set>
#include <map>
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDAQHitRouter.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to select events based on hits in strings.

Author
mdejong

Definition in file JDAQ/JDAQFilter.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JDAQ/JDAQFilter.cc.

31 {
32  using namespace std;
33  using namespace JPP;
34  using namespace KM3NETDAQ;
35 
36  typedef map<int, int> map_type;
37 
40  JLimit_t& numberOfEvents = inputFile.getLimit();
41  string detectorFile;
42  map_type selector;
43  int debug;
44 
45  try {
46 
47  JParser<> zap("Example program to select events based on hits in strings.");
48 
49  zap['f'] = make_field(inputFile, "input file.");
50  zap['o'] = make_field(outputFile, "output file.") = "filter.root";
51  zap['n'] = make_field(numberOfEvents) = JLimit::max();
52  zap['a'] = make_field(detectorFile, "detector file.");
53  zap['S'] = make_field(selector, "selection: pairs of <string number> <minimum number of triggered hits>");
54  zap['d'] = make_field(debug) = 2;
55 
56  zap['a'] = JPARSER::initialised();
57  zap['S'] = JPARSER::initialised();
58 
59  zap(argc, argv);
60  }
61  catch(const exception& error) {
62  FATAL(error.what() << endl);
63  }
64 
65 
67 
68  if (detectorFile != "") {
69 
70  try {
71  load(detectorFile, detector);
72  }
73  catch(const JException& error) {
74  FATAL(error);
75  }
76 
77  } else if (!selector.empty()) {
78 
79  FATAL("Missing detector file.");
80  }
81 
82  const JDAQHitRouter router(detector);
83 
84 
85  map<int, set<int> > buffer;
86 
87  outputFile.open();
88 
89  outputFile.put(JMeta(argc, argv));
90 
91  while (inputFile.hasNext()) {
92 
93  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
94 
95  JDAQEvent* event = inputFile.next();
96 
97  bool status = selector.empty();
98 
99  if (!status) {
100 
102 
103  typedef JDAQTriggeredHit JHit_t;
104 
105  for (JDAQEvent::const_iterator<JHit_t> hit = event->begin<JHit_t>(); hit != event->end<JHit_t>(); ++hit) {
106 
107  const JPMTChannel& channel = router.getPMTChannel(*hit);
108 
109  response[channel.getString()] += 1;
110  }
111 
112  for (map_type::const_iterator i = selector.begin(); i != selector.end() && !status; ++i) {
113  status = response[i->first] >= i->second;
114  }
115  }
116 
117  if (status) {
118 
119  outputFile.put(*event);
120 
121  buffer[event->getRunNumber()].insert(event->getFrameIndex());
122  }
123  }
124  STATUS(endl);
125 
126 
127  for (JMultipleFileScanner<JDAQSummaryslice> in(inputFile); in.hasNext(); ) {
128 
129  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
130 
131  JDAQSummaryslice* summary = in.next();
132 
133  if (buffer[summary->getRunNumber()].count(summary->getFrameIndex())) {
134  outputFile.put(*summary);
135  }
136  }
137  STATUS(endl);
138 
139 
141 
142  io >> outputFile;
143 
144  outputFile.close();
145 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
Detector data structure.
Definition: JDetector.hh:96
int getString() const
Get string number.
Definition: JLocation.hh:135
Auxiliary class to uniquely identify PMT readout channel.
Definition: JPMTChannel.hh:35
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1698
Object writing to file.
Template specialisation of JMultipleFileScanner for trigger parameters.
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
int getRunNumber() const
Get run number.
int getFrameIndex() const
Get frame index.
Template const_iterator.
Definition: JDAQEvent.hh:68
char response[100000]
Definition: elog.cc:330
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
std::map< int, range_type > map_type
Definition: JSTDTypes.hh:14
Detector file.
Definition: JHead.hh:227
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Auxiliary class to set-up Hit.
Definition: JSirene.hh:58
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72