Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JReconstruction/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 
10 
11 #include "JDetector/JDetector.hh"
14 
15 #include "JDAQ/JDAQEventIO.hh"
17 
18 #include "JSupport/JMeta.hh"
19 #include "JSupport/JSupport.hh"
20 #include "JSupport/JTreeScanner.hh"
24 
26 
27 #include "JReconstruction/JEvt.hh"
30 
31 #include "Jeep/JParser.hh"
32 #include "Jeep/JMessage.hh"
33 
34 
35 /**
36  * \file
37  *
38  * Example program to select events based on hits in strings.
39  * \author mdejong
40  */
41 int main(int argc, char **argv)
42 {
43  using namespace std;
44  using namespace JPP;
45  using namespace KM3NETDAQ;
46 
47  typedef map<int, int> map_type;
48 
50 
51  typedef JParallelFileScanner< JTypeList<JDAQEvent, JEvt> > JParallelFileScanner_t;
52  typedef JParallelFileScanner_t::multi_pointer_type multi_pointer_type;
53 
54  JParallelFileScanner_t inputFile;
55  size_t numberOfEvents;
57  string detectorFile;
58  map_type selector;
59  int debug;
60 
61  try {
62 
63  JParser<> zap("Example program to select events based on hits in strings.");
64 
65  zap['f'] = make_field(inputFile, "input file (output of JXXXReconstruction.sh)");
66  zap['n'] = make_field(numberOfEvents, "maximum number of selected events")
67  = std::numeric_limits<size_t>::max();
68  zap['o'] = make_field(outputFile, "output file name")
69  = "extract.root";
70  zap['a'] = make_field(detectorFile, "detector file.");
71  zap['S'] = make_field(selector, "selection: pairs of <string number> <minimum number of triggered hits>");
72  zap['d'] = make_field(debug) = 2;
73 
74  zap['a'] = JPARSER::initialised();
75  zap['S'] = JPARSER::initialised();
76 
77  zap(argc, argv);
78  }
79  catch(const exception& error) {
80  FATAL(error.what() << endl);
81  }
82 
83 
85 
86  if (detectorFile != "") {
87 
88  try {
89  load(detectorFile, detector);
90  }
91  catch(const JException& error) {
92  FATAL(error);
93  }
94 
95  } else if (!selector.empty()) {
96 
97  FATAL("Missing detector file.");
98  }
99 
100  const JDAQHitRouter router(detector);
101 
102 
103  map<int, set<int> > buffer;
104 
105  outputFile.open();
106 
107  outputFile.put(JMeta(argc, argv));
108 
109  for (JTreeScanner<Evt> mc(inputFile); inputFile.hasNext(); ) {
110 
111  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
112 
113  multi_pointer_type ps = inputFile.next();
114 
115  JDAQEvent* tev = ps;
116  JEvt* in = ps;
117  Evt* event = NULL;
118 
119  if (in->empty()) { continue; }
120 
121  if (mc.getEntries() != 0) {
122  event = mc.getEntry(tev->getCounter());
123  }
124 
125  bool status = selector.empty();
126 
127  if (!status) {
128 
130 
131  typedef JDAQTriggeredHit JHit_t;
132 
133  for (JDAQEvent::const_iterator<JHit_t> hit = tev->begin<JHit_t>(); hit != tev->end<JHit_t>(); ++hit) {
134 
135  const JPMTChannel& channel = router.getPMTChannel(*hit);
136 
137  response[channel.getString()] += 1;
138  }
139 
140  for (map_type::const_iterator i = selector.begin(); i != selector.end() && !status; ++i) {
141  status = response[i->first] >= i->second;
142  }
143  }
144 
145  if (status) {
146 
147  if (event != NULL) {
148  outputFile.put(*event);
149  }
150  outputFile.put(*tev);
151  outputFile.put(*in);
152 
153  buffer[tev->getRunNumber()].insert(tev->getFrameIndex());
154  }
155  }
156  STATUS(endl);
157 
158 
159  for (JMultipleFileScanner<JDAQSummaryslice> in(inputFile); in.hasNext(); ) {
160 
161  STATUS("event: " << setw(10) << in.getCounter() << '\r'); DEBUG(endl);
162 
163  JDAQSummaryslice* summary = in.next();
164 
165  if (buffer[summary->getRunNumber()].count(summary->getFrameIndex())) {
166  outputFile.put(*summary);
167  }
168  }
169  STATUS(endl);
170 
171 
173 
174  io >> outputFile;
175 
176  outputFile.close();
177 }
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:1514
General exception.
Definition: JException.hh:24
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:66
Recording of objects on file according a format that follows from the file name extension.
General purpose class for parallel reading of objects from a single file or multiple files...
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
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.
const_iterator< T > end() const
Get end of data.
Detector file.
Definition: JHead.hh:226
Acoustic event fit.
const_iterator< T > begin() const
Get begin of data.
Auxiliary class for recursive type list generation.
Definition: JTypeList.hh:351
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Parallel scanning of objects from a single file or multiple files according a format that follows fro...
ROOT I/O of application specific meta data.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
int getString() const
Get string number.
Definition: JLocation.hh:134
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Data structure for set of track fit results.
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:48
Utility class to parse command line options.
char response[100000]
Definition: elog.cc:330
Auxiliary class to set-up Hit.
Definition: JSirene.hh:57
std::map< int, range_type > map_type
do set_variable DETECTOR_TXT $WORKDIR detector
JTriggerCounter_t getCounter() const
Get trigger counter.
JPMTChannel getPMTChannel(const JDAQKeyHit &hit) const
Get PMT channel.
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62