Jpp
 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 <map>
6 
7 #include "JDAQ/JDAQEventIO.hh"
10 #include "JDetector/JDetector.hh"
13 
16 #include "JSupport/JMeta.hh"
17 #include "JSupport/JSupport.hh"
18 
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 /**
24  * \file
25  *
26  * Example program to select events based on hits in strings.
27  * \author mdejong
28  */
29 int main(int argc, char **argv)
30 {
31  using namespace std;
32  using namespace JPP;
33  using namespace KM3NETDAQ;
34 
35  typedef map<int, int> map_type;
36 
39  JLimit_t& numberOfEvents = inputFile.getLimit();
40  string detectorFile;
41  map_type selector;
42  int debug;
43 
44  try {
45 
46  JParser<> zap("Example program to select events based on hits in strings.");
47 
48  zap['f'] = make_field(inputFile, "input file.");
49  zap['o'] = make_field(outputFile, "output file.") = "filter.root";
50  zap['n'] = make_field(numberOfEvents) = JLimit::max();
51  zap['a'] = make_field(detectorFile, "detector file.");
52  zap['S'] = make_field(selector, "selection: pairs of <string number> <minimum number of triggered hits>");
53  zap['d'] = make_field(debug) = 2;
54 
55  zap(argc, argv);
56  }
57  catch(const exception& error) {
58  FATAL(error.what() << endl);
59  }
60 
61 
62  cout.tie(&cerr);
63 
64 
66 
67  try {
68  load(detectorFile, detector);
69  }
70  catch(const JException& error) {
71  FATAL(error);
72  }
73 
74  const JDAQHitRouter router(detector);
75 
76 
77  outputFile.open();
78 
79  outputFile.put(JMeta(argc, argv));
80 
81  while (inputFile.hasNext()) {
82 
83  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
84 
85  JDAQEvent* event = inputFile.next();
86 
87  map_type response;
88 
89  typedef JDAQTriggeredHit JHit_t;
90 
91  for (JDAQEvent::const_iterator<JHit_t> hit = event->begin<JHit_t>(); hit != event->end<JHit_t>(); ++hit) {
92 
93  const JPMTChannel& channel = router.getPMTChannel(*hit);
94 
95  response[channel.getString()] += 1;
96  }
97 
98  bool status = false;
99 
100  for (map_type::const_iterator i = selector.begin(); i != selector.end() && !status; ++i) {
101  status = response[i->first] >= i->second;
102  }
103 
104  if (status) {
105  outputFile.put(*event);
106  }
107  }
108  STATUS(endl);
109 
110 
112 
113  io >> outputFile;
114 
115  outputFile.close();
116 }
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
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:28
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:80
Template const_iterator.
Definition: JDAQEvent.hh:68
Recording of objects on file according a format that follows from the file name extension.
string outputFile
Data structure for detector geometry and calibration.
Simple wrapper around JModuleRouter class for direct addressing of PMT data in detector data structur...
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Detector file.
Definition: JHead.hh:196
#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:63
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
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
JPMTChannel getPMTChannel(const JDAQKeyHit &hit) const
Get PMT channel.
JTriggerCounter_t next()
Increment trigger counter.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62