20 if (!iConfig.
empty()){
25 if (iConfig.
exists(
"description"))
94 const std::map<std::string, Filter*> &
filters){
98 ss<<
"Filter doing an OR of: ";
103 size_t orPos = filterORlistCopy.find(
"_OR_");
104 if (orPos == std::string::npos && !filterORlistCopy.empty()){
105 size=filterORlistCopy.size();
114 filterORlistCopy = filterORlistCopy.substr(0+size+4);
116 std::map<std::string, Filter*>::const_iterator it=filters.find(filter);
117 if (it==filters.end()){
119 <<
" OR expression is: "<<filterORlist;
122 filters_.push_back(std::make_pair(it->first, it->second));
128 for (
unsigned int i=0 ;
i!=filters_.size();++
i)
129 if (filters_[
i].
second->accept(iEvent))
134 std::vector <std::pair<std::string , Filter * > >
filters_;
148 ntuplize_(iConfig.getParameter<
bool>(
"ntuplize")),
149 makeContentPlots_(iConfig.getParameter<
bool>(
"makeContentPlots")),
150 makeFinalPlots_(iConfig.getParameter<
bool>(
"makeFinalPlots")),
151 makeCumulativePlots_(iConfig.getParameter<
bool>(
"makeCumulativePlots")),
152 makeAllButOnePlots_(iConfig.getParameter<
bool>(
"makeAllButOnePlots")),
154 makeSummaryTable_(iConfig.getParameter<
bool>(
"makeSummaryTable")),
155 makeDetailledPrintout_(iConfig.exists(
"detailledPrintoutCategory"))
159 if (iConfig.
exists(
"nMonitor"))
160 nMonitor_=iConfig.
getParameter<
unsigned int>(
"nMonitor");
164 if (makeDetailledPrintout_)
179 this->acceptMap(iEvent);
187 if (nMonitor_!=0 && nSeen_%nMonitor_==0){
188 if (nSeen_==nMonitor_)
print();
191 std::map<std::string, bool> ret;
197 bool decision=(*filter)->accept(iEvent);
198 bool inverted=(*filter).inverted();
199 if (inverted) decision=!decision;
201 if (decision) count.
nPass_++;
202 global=global && decision;
206 if (makeDetailledPrintout_){
208 summary<<std::setw(20)<<
name().substr(0,19)<<
" : " 209 <<std::setw(10)<<iEvent.
id().
run()<<
" : " 210 <<std::setw(10)<<iEvent.
id().
event();
213 summary<<
" : "<<std::setw(10)<<(ret[fName]?
"pass":
"reject");
224 if (makeDetailledPrintout_){
226 summary<<std::setw(20)<<
" selection name "<<
" : " 227 <<std::setw(10)<<
" run "<<
" : " 228 <<std::setw(10)<<
" event ";
230 summary<<
" : "<<std::setw(10)<<(*filter)->name().substr(0,9);
237 if (!makeSummaryTable_)
return;
239 unsigned int maxFnameSize = 20;
241 if ((*filter)->name().size() > maxFnameSize) maxFnameSize = (*filter)->name().size()+1;
247 summary<<
" Summary table for selection: "<<
name()<<
" with: "<<nSeen_<<
" events run."<<std::endl;
248 if (nSeen_==0)
return;
252 summary<<
"filter: "<<std::right<<std::setw(10)<<fName<<
"\n" 253 <<(*filter)->descriptionText()<<
"\n";
256 summary<<
" filter stand-alone pass: "<<std::endl;
257 summary<<std::right<<std::setw(maxFnameSize)<<
"total read"<<
": " 258 <<std::right<<std::setw(10)<<nSeen_<<std::endl;
262 if ((*filter).inverted()) fName=
'!'+fName;
263 summary<<std::right<<std::setw(maxFnameSize)<<fName<<
": " 264 <<std::right<<std::setw(10)<<count.
nPass_<<
" passed events. " 265 <<std::right<<std::setw(10)<<std::setprecision (5)<<(count.
nPass_/(
float)count.
nSeen_)*100.<<
" [%]"<<std::endl;
267 summary<<
" filter cumulative pass:"<<std::endl;
268 summary<<std::right<<std::setw(maxFnameSize)<<
"total read"<<
": " 269 <<std::right<<std::setw(10)<<nSeen_<<std::endl;
270 unsigned int lastCount=nSeen_;
274 if ((*filter).inverted()) fName=
'!'+fName;
275 summary<<std::right<<std::setw(maxFnameSize)<<fName<<
": " 276 <<std::right<<std::setw(10)<<count.
nCumulative_<<
" passed events. " 279 summary<<
" (to previous count) "<<std::right<<std::setw(10)<<std::setprecision (5)<<(count.
nCumulative_/(
float)lastCount)*100.<<
" [%]";
284 summary<<
"-------------------------------------\n";
324 typedef std::vector<FilterSelection>::iterator
iterator;
333 std::vector<std::string> filterNames;
334 unsigned int nF=filtersPSet_.getParameterSetNames(filterNames);
335 for (
unsigned int iF=0;iF!=nF;iF++){
337 filters_.
insert(std::make_pair(filterNames[iF],
new Filter(filterNames[iF],pset, iC)));
341 std::vector<std::string> selectionNames;
342 std::map<std::string, std::vector<std::string> > selectionFilters;
343 unsigned int nS=selectionPSet_.getParameterSetNames(selectionNames);
344 for (
unsigned int iS=0;iS!=nS;iS++){
350 selectionFilters[selectionNames[iS]]=pset.
getParameter<std::vector<std::string> >(
"filterOrder");
358 for (
std::map<
std::string, std::vector<std::string> >::iterator sIt= selectionFilters.begin();sIt!=selectionFilters.end();++sIt)
361 for (std::vector<std::string>::iterator fOrS=sIt->second.begin();fOrS!=sIt->second.end();++fOrS)
363 if (filters_.find(*fOrS)==filters_.end())
366 if (fOrS->find(
"_OR_") != std::string::npos){
367 filters_.insert(std::make_pair((*fOrS),
new FilterOR((*fOrS),filters_)));
371 std::map<std::string, std::vector<std::string> >
::iterator s=selectionFilters.find(*fOrS);
372 if (s==selectionFilters.end()){
374 if ((*fOrS)[0] !=
'!'){
375 edm::LogError(
"SelectionHelper")<<
"unresolved filter/selection name: "<<*fOrS;
381 std::vector<std::string>::iterator newLoc=sIt->second.erase(fOrS);
383 sIt->second.insert(newLoc,s->second.begin(),s->second.end());
399 for (std::vector<FilterSelection>::iterator sIt=selections_.begin();sIt!=selections_.end();++sIt){
404 std::vector<std::string> & listOfFilters=selectionFilters[sName];
405 for (std::vector<std::string>::iterator fIt=listOfFilters.begin();fIt!=listOfFilters.end();++fIt)
409 if (fOsName[0]==
'!'){
411 fOsName = fOsName.substr(1);
413 std::map<std::string, Filter*>::iterator filterInstance=filters_.find(fOsName);
414 if (filterInstance==filters_.end()){
416 bool replaceBySelection=
false;
418 for ( std::vector<FilterSelection>::iterator sit=selections_.begin(); sit!= selections_.end() ; ++sit){
419 if (fOsName == sit->name_){
421 replaceBySelection=
true;
424 if (!replaceBySelection){
431 selection.
filters_.push_back(
SFilter(filterInstance->second,inverted));
436 for (iterator sIt =
begin(); sIt!=
end();++sIt)
437 sIt->printDetailledPrintoutHeader();
441 iterator
begin() {
return selections_.begin(); }
442 iterator
end() {
return selections_.end();}
445 void print(){
for (std::vector<FilterSelection>::iterator sIt=selections_.begin();sIt!=selections_.end();++sIt) sIt->print();}
edm::ParameterSet selectionPSet_
T getParameter(std::string const &) const
EventNumber_t event() const
unsigned long CacheIdentifier_t
std::vector< std::string > description_
std::vector< FilterSelection >::iterator iterator
void printDetailledPrintoutHeader()
bool makeCumulativePlots_
virtual bool accept(edm::Event &iEvent)
std::vector< FilterSelection > selections_
std::string dump(unsigned int indent=0) const
edm::Event::CacheIdentifier_t eventCacheID_
bool accept(edm::Event &iEvent) override
FilterSelections(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
std::vector< SFilter > filters_
std::map< std::string, bool > acceptMap(edm::Event &iEvent)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::ParameterSet filtersPSet_
void insert(bool ok_to_replace, char const *, Entry const &)
S & print(S &os, JobReport::InputFile const &f)
const std::string & dump()
std::vector< SFilter >::iterator iterator
std::vector< TPRegexp > filters
const std::string & name()
std::string detailledPrintoutCategory_
U second(std::pair< T, U > const &p)
bool accept(edm::Event &iEvent) override
unsigned int nCumulative_
bool makeCumulativePlots()
CacheIdentifier_t cacheIdentifier() const
FilterOR(const std::string &filterORlist, const std::map< std::string, Filter * > &filters)
const std::vector< std::string > description()
Filter(std::string name, edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
const std::string & name()
const std::string descriptionText()
std::pair< int, edm::FunctionWithDict > OK
void addUntrackedParameter(std::string const &name, T const &value)
std::unique_ptr< EventSelector > selector_
Filter & operator=(const Filter &)=delete
SFilter(Filter *f, bool i)
FilterSelection(std::string name, const edm::ParameterSet &iConfig)
std::map< std::string, Count > counts_
std::vector< std::pair< std::string, Filter * > > filters_
bool makeAllButOnePlots()
void print(bool description=true)
bool makeDetailledPrintout_
T get(const Candidate &c)
std::map< std::string, Filter * > filters_