Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JReconstruction/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 "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDAQHitRouter.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JSupport/JMeta.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JTreeScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JParallelFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JTrigger/JTriggerParameters.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JEvtToolkit.hh"
#include "JReconstruction/JEventSelector.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 JReconstruction/JDAQFilter.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 41 of file JReconstruction/JDAQFilter.cc.

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:1711
General exception.
Definition: JException.hh:24
Auxiliary class to uniquely identify PMT readout channel.
Definition: JPMTChannel.hh:31
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
Template const_iterator.
Definition: JDAQEvent.hh:66
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:84
string outputFile
int getRunNumber() const
Get run number.
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:2158
#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 The output file must have the wildcard in the e g root fi 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
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.
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