HitSubtract_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: HitSubtract
3 // Module Type: producer
4 // File: HitSubtract_module.cc
5 //
6 // Generated at Mon May 30 08:42:27 2016 by Andrey Sheshukov using artmod
7 // from cetpkgsupport v1_08_07.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
21 #include <boost/algorithm/string.hpp>
22 #include <boost/tokenizer.hpp>
23 #include <exception>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 #include <iomanip>
28 
29 /// a class for expression parsing.
30 //Example: expr="A+B-C+D-E" means that we take hits from A
31 class Expression {
32  public:
33  Expression(const std::string& expr){Parse(expr);}
35  const std::map<std::string,uint64_t>& GetStatistics(){return fSeenHits;}
36  private:
37  void Parse(const std::string& s);
39  auto handle=e.getValidHandle<novaddt::HitList>(tag);
40  return novaddt::HitSet(*handle);
41  };
44  auto handle=e.getValidHandle<std::vector<novaddt::HitList>>(tag);
45  for(const auto& hitlist: *handle)
46  hits.add(hitlist);
47  return hits;
48  };
50  if(boost::ends_with(tag,"[]")){
51  return fetchAll(boost::erase_tail_copy(tag,2),e);
52  }
53  else
54  return fetchOne(tag,e);
55  }
56  private:
57  std::vector<std::string> fTokens;
58  std::map<std::string,uint64_t> fSeenHits;
59 };
60 
62  mf::LogInfo("HitSub expression")<<"parse string:\'"<<str<<"\'";
63 
64  boost::char_separator<char> sep{"", "-+"};
65  boost::tokenizer<boost::char_separator<char>> tok{str, sep};
66  for (std::string t : tok){
67  boost::trim(t);
68  fTokens.push_back(t);
69  }
70 }
71 
74  char next_op='+';
75  auto stream=mf::LogDebug("HitSub eval");
76  for(const auto& t: fTokens){
77  if(t[0]=='-'||t[0]=='+'){next_op=t[0]; continue;}
79  fSeenHits[t]+=hits.size();
80  stream<<next_op<<" Hits["<<t<<"]= "<<hits.size()<<"\n";
81  switch(next_op){
82  case '-': result.subtract(hits); break;
83  case '+': result.add(hits); break;
84  default: throw std::logic_error("Wrong operation:"+std::to_string(next_op));
85  }
86  }
87  stream<<"Result="<<result.size();
88  fSeenHits["result"]+=result.size();
89  return result;
90 }
91 
92 namespace novaddt {
93  class HitSubtract;
94 }
95 
97 public:
98  explicit HitSubtract(fhicl::ParameterSet const & p);
99  // The destructor generated by the compiler is fine for classes
100  // without bare pointers or other resource use.
101 
102  // Plugins should not be copied or assigned.
103  HitSubtract(HitSubtract const &) = delete;
104  HitSubtract(HitSubtract &&) = delete;
105  HitSubtract & operator = (HitSubtract const &) = delete;
106  HitSubtract & operator = (HitSubtract &&) = delete;
107 
108  // Required functions.
109  void produce(art::Event & e) override;
110  void endJob() override;
111 
112 
113 private:
116 };
117 
118 
120  : EDProducer(p),
121  fExpr(p.get<std::string>("expr")),fLabel(p.get<std::string>("label"))
122  // Initialize member data here.
123 {
124  // Call appropriate produces<>() functions here.
125  produces<novaddt::HitList>(fLabel);
126 }
127 
129 {
130  // Implementation of required member function here.
131  auto hitSet=fExpr.Eval(e);
132  std::unique_ptr<novaddt::HitList>hits(new novaddt::HitList(hitSet.begin(),hitSet.end()));
133  e.put(std::move(hits),fLabel);
134 }
135 
137  auto stream = mf::LogInfo("HitSub statistics");
138  auto stats = fExpr.GetStatistics();
139  stream<<" Hits statistics: ";
140  for(const auto &t: stats){
141  stream<<"\n "<<std::setw(25)<<t.first<<" = "<<std::setw(25)<<t.second;
142  }
143 }
144 
Expression(const std::string &expr)
Definition: structs.h:27
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< DAQHit > HitList
Definition: HitList.h:15
const char * p
Definition: xmltok.h:285
int stats(TString inputFilePath, Int_t firstRun, Int_t lastRun, Float_t thresh, TString myDet)
Definition: stats.C:13
string trim(string in)
Definition: rootgINukeVal.C:65
const std::map< std::string, uint64_t > & GetStatistics()
DEFINE_ART_MODULE(TestTMapFile)
void add(const AnyCollection &v)
Definition: HitSet.h:24
const XML_Char * s
Definition: expat.h:262
novaddt::HitSet fetchAll(const std::string &tag, const art::Event &e)
novaddt::HitSet fetch(const std::string &tag, const art::Event &e)
a class for expression parsing.
novaddt::HitSet fetchOne(const std::string &tag, const art::Event &e)
void hits()
Definition: readHits.C:15
HitSubtract(fhicl::ParameterSet const &p)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:491
const char sep
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::map< std::string, uint64_t > fSeenHits
void Parse(const std::string &s)
novaddt::HitSet Eval(const art::Event &e)
void produce(art::Event &e) override
Float_t e
Definition: plot.C:35
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
void subtract(const AnyCollection &v)
Definition: HitSet.h:30
std::vector< std::string > fTokens
enum BeamMode string