All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FileReducer.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <set>
7 
8 namespace ana
9 {
10  class Progress;
11 
12  // Example reduction steps
14 
15  /// \brief Create smaller CAFs
16  ///
17  /// This class produces new CAFs, removing entries that fail a cut. It also
18  /// allows the event record to be edited in custom ways.
20  {
21  public:
22  FileReducer(const std::string& wildcard,
23  const std::string& outfile);
24  FileReducer(const std::vector<std::string>& fnames,
25  const std::string& outfile);
26  virtual ~FileReducer();
27 
28  /// Only copy records to the output file if they pass this cut
29  void AddSpillCut(const SpillCut& cut);
30  void AddSliceCut(const SliceCut& cut);
31 
32  /// \brief If called, only events whose run/subrun/event occur in \a fname
33  /// will be retained.
34  void SetEventList(const std::string& fname);
35 
37  // typedef void (ReductionFuncWithProxy)(caf::StandardRecord*,
38  // const caf::Proxy<caf::StandardRecord>*);
39 
40  /// Run the specified reduction function over each event
41  void AddReductionStep(const std::function<ReductionFunc> &f) {fReductionFuncs.push_back(f);}
42  // void AddReductionStep(const std::function<ReductionFuncWithProxy> &f) {fReductionFuncsWithProxy.push_back(f);}
43 
44  /// Override any metadata key in the output file
45  void SetMetadata(const std::string& key, const std::string& val)
46  {
47  // Let's assume the user is just setting string keys
48  fMetaMap[key] = "\""+val+"\"";
49  }
50 
51  virtual void Go() override;
52 
53  protected:
54  void HandleFile(TFile* fin, TFile* fout, TTree*& trOut, Progress* prog,
55  long& nRecSeen, long& nRecPassed);
56 
57  void HandleNestedTree(TFile* fout, TTree* recTree, TTree*& trOut,
58  Progress* prog,
59  long& nRecSeen, long& nRecPassed);
60 
61  void HandleFlatTree(TFile* fout, TTree* recTree, TTree*& trOut,
62  Progress* prog,
63  long& nRecSeen, long& nRecPassed);
64 
65  void CopyGlobalTree(TFile* fin, TFile* fout);
66 
67  void UpdateMetadata(std::map<std::string, std::string>& meta,
68  const std::set<std::string>& mask,
69  const std::vector<std::string>& fnames) const;
70 
71  /// Strip all information out of this record and tag it as a husk
72  void Huskify(caf::StandardRecord* sr) const;
73 
74  std::string fOutfile;
77 
78  std::set<std::tuple<int, int, int>> fEventList;
79 
80  std::vector<std::function<ReductionFunc>> fReductionFuncs;
81  // std::vector<std::function<ReductionFuncWithProxy>> fReductionFuncsWithProxy;
82 
83  std::map<std::string, std::string> fMetaMap;
84  };
85 }
SliceCut * fSliceCut
Definition: FileReducer.h:76
string fname
Definition: demo.py:5
std::string fOutfile
Definition: FileReducer.h:74
void CopyGlobalTree(TFile *fin, TFile *fout)
void( ReductionFunc)(caf::StandardRecord *)
Definition: FileReducer.h:36
void HandleNestedTree(TFile *fout, TTree *recTree, TTree *&trOut, Progress *prog, long &nRecSeen, long &nRecPassed)
void SetMetadata(const std::string &key, const std::string &val)
Override any metadata key in the output file.
Definition: FileReducer.h:45
process_name opflashCryoW ana
void HandleFile(TFile *fin, TFile *fout, TTree *&trOut, Progress *prog, long &nRecSeen, long &nRecPassed)
void AddReductionStep(const std::function< ReductionFunc > &f)
Run the specified reduction function over each event.
Definition: FileReducer.h:41
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
std::map< std::string, std::string > fMetaMap
Definition: FileReducer.h:83
void ClearTrueParticles(caf::StandardRecord *sr)
Definition: FileReducer.cxx:25
FileReducer(const std::string &wildcard, const std::string &outfile)
Definition: FileReducer.cxx:32
void AddSpillCut(const SpillCut &cut)
Only copy records to the output file if they pass this cut.
Definition: FileReducer.cxx:58
j template void())
Definition: json.hpp:3108
virtual void Go() override
Load all the registered spectra.
Definition: FileReducer.cxx:95
void AddSliceCut(const SliceCut &cut)
Definition: FileReducer.cxx:69
Create smaller CAFs.
Definition: FileReducer.h:19
virtual ~FileReducer()
Definition: FileReducer.cxx:51
Base class for the various types of spectrum loader.
std::vector< std::function< ReductionFunc > > fReductionFuncs
Definition: FileReducer.h:80
SpillCut * fSpillCut
Definition: FileReducer.h:75
The StandardRecord is the primary top-level object in the Common Analysis File trees.
void HandleFlatTree(TFile *fout, TTree *recTree, TTree *&trOut, Progress *prog, long &nRecSeen, long &nRecPassed)
std::set< std::tuple< int, int, int > > fEventList
Definition: FileReducer.h:78
void UpdateMetadata(std::map< std::string, std::string > &meta, const std::set< std::string > &mask, const std::vector< std::string > &fnames) const
A simple ascii-art progress bar.
Definition: Progress.h:9
void Huskify(caf::StandardRecord *sr) const
Strip all information out of this record and tag it as a husk.
void SetEventList(const std::string &fname)
If called, only events whose run/subrun/event occur in fname will be retained.
Definition: FileReducer.cxx:80
prog
Definition: just_cmake.sh:3