Crombie Tools
EventDump.h
Go to the documentation of this file.
1 #ifndef CROMBIE_EVENTDUMP_H
2 #define CROMBIE_EVENTDUMP_H
3 
4 #include <list>
5 
6 #include "crombie/Types.h"
7 #include "crombie/FileConfig.h"
8 #include "crombie/LoadTree.h"
9 
10 namespace crombie {
11  namespace EventDump {
12 
13  using SingleOut = std::vector<std::vector<double>>;
15 
17  SingleFile(const std::string& cut,
18  const Types::strings& exprs);
19 
21 
22  // IMPLEMENTATIONS BELOW HERE //
23 
24  SingleFunc SingleFile(const std::string& cut,
25  const Types::strings& exprs) {
26  return SingleFunc {
27  [&cut, &exprs] (const FileConfig::FileInfo& info) {
28  LoadTree::Tree loaded{info.name, cut, exprs};
29  SingleOut output {};
30  auto& track_cut = loaded.result(cut);
31  std::vector<double*> results;
32  for (auto& expr : exprs)
33  results.push_back(&(loaded.result(expr)));
34 
35  std::vector<double> eventout;
36 
37  while (loaded.next()) {
38  if (track_cut) {
39  eventout.clear();
40  for (auto* val : results)
41  eventout.push_back(*val);
42 
43  output.push_back(eventout);
44  }
45  }
46  return output;
47  }
48  };
49  }
50 
52  SingleOut output {};
53  for (auto& outs : outputs) {
54  // We don't care about the key
55  for (auto& single : outs.second)
56  output.insert(output.end(), single.begin(), single.end());
57  }
58 
59  // Sort vector of vectors recursively
60  sort(output.begin(), output.end(),
61  [] (auto& a, auto& b) {
62  for (unsigned i = 0; i < a.size(); ++i) {
63  if (a[i] == b[i])
64  continue;
65  return a[i] < b[i];
66  }
67  return false;
68  });
69 
70  return output;
71  }
72  }
73 }
74 
75 #endif