Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDAQFilter.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <set>
6 #include <map>
7 
8 #include "JDAQ/JDAQEventIO.hh"
11 #include "JDetector/JDetector.hh"
14 
17 #include "JSupport/JMeta.hh"
18 #include "JSupport/JSupport.hh"
19 
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 
24 /**
25  * \file
26  *
27  * Example program to select events based on hits in strings.
28  * \author mdejong
29  */
30 int main(int argc, char **argv)
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 
66  cout.tie(&cerr);
67 
69 
70  if (detectorFile != "") {
71 
72  try {
73  load(detectorFile, detector);
74  }
75  catch(const JException& error) {
76  FATAL(error);
77  }
78 
79  } else if (!selector.empty()) {
80 
81  FATAL("Missing detector file.");
82  }
83 
84  const JDAQHitRouter router(detector);
85 
86 
87  map<int, set<int> > buffer;
88 
89  outputFile.open();
90 
91  outputFile.put(JMeta(argc, argv));
92 
93  while (inputFile.hasNext()) {
94 
95  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
96 
97  JDAQEvent* event = inputFile.next();
98 
99  bool status = selector.empty();
100 
101  if (!status) {
102 
103  map_type response;
104 
105  typedef JDAQTriggeredHit JHit_t;
106 
107  for (JDAQEvent::const_iterator<JHit_t> hit = event->begin<JHit_t>(); hit != event->end<JHit_t>(); ++hit) {
108 
109  const JPMTChannel& channel = router.getPMTChannel(*hit);
110 
111  response[channel.getString()] += 1;
112  }
113 
114  for (map_type::const_iterator i = selector.begin(); i != selector.end() && !status; ++i) {
115  status = response[i->first] >= i->second;
116  }
117  }
118 
119  if (status) {
120 
121  outputFile.put(*event);
122 
123  buffer[event->getRunNumber()].insert(event->getFrameIndex());
124  }
125  }
126  STATUS(endl);
127 
128 
129  for (JMultipleFileScanner<JDAQSummaryslice> in(inputFile); in.hasNext(); ) {
130 
131  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
132 
133  JDAQSummaryslice* summary = in.next();
134 
135  if (buffer[summary->getRunNumber()].count(summary->getFrameIndex())) {
136  outputFile.put(*summary);
137  }
138  }
139  STATUS(endl);
140 
141 
143 
144  io >> outputFile;
145 
146  outputFile.close();
147 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Template specialisation of JMultipleFileScanner for trigger parameters.
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
Direct access to PMT data in detector data structure for DAQ hits.
Auxiliary class to uniquely identify PMT readout channel.
Definition: JPMTChannel.hh:30
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Template const_iterator.
Definition: JDAQEvent.hh:68
Recording of objects on file according a format that follows from the file name extension.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
string outputFile
int getRunNumber() const
Get run number.
Data structure for detector geometry and calibration.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
int getFrameIndex() const
Get frame index.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:224
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
int debug
debug level
Definition: JSirene.cc:66
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
char response[100000]
Definition: elog.cc:330
Auxiliary class to set-up Hit.
Definition: JSirene.hh:55
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JPMTChannel getPMTChannel(const JDAQKeyHit &hit) const
Get PMT channel.
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62