Go to the documentation of this file.00001 #include <algorithm>
00002 #include <iterator>
00003 #include <ostream>
00004 #include <cctype>
00005
00006 #include "DataFormats/Provenance/interface/BranchDescription.h"
00007 #include "FWCore/Framework/interface/GroupSelector.h"
00008 #include "FWCore/Framework/interface/GroupSelectorRules.h"
00009 #include "FWCore/Utilities/interface/EDMException.h"
00010 #include "FWCore/Utilities/interface/Algorithms.h"
00011
00012
00013 namespace edm {
00014
00015
00016 typedef std::vector<edm::BranchDescription const*> VCBDP;
00017
00018 GroupSelector::GroupSelector() : groupsToSelect_(), initialized_(false) {}
00019
00020 void
00021 GroupSelector::initialize(GroupSelectorRules const& rules, VCBDP const& branchDescriptions) {
00022 typedef GroupSelectorRules::BranchSelectState BranchSelectState;
00023
00024
00025
00026 std::vector<BranchSelectState> branchstates;
00027 {
00028 branchstates.reserve(branchDescriptions.size());
00029
00030 VCBDP::const_iterator it = branchDescriptions.begin();
00031 VCBDP::const_iterator end = branchDescriptions.end();
00032 for (; it != end; ++it) branchstates.push_back(BranchSelectState(*it));
00033 }
00034
00035
00036
00037 rules.applyToAll(branchstates);
00038
00039
00040
00041
00042
00043 {
00044 std::vector<BranchSelectState>::const_iterator it = branchstates.begin();
00045 std::vector<BranchSelectState>::const_iterator end = branchstates.end();
00046 for (; it != end; ++it) {
00047 if (it->selectMe) groupsToSelect_.push_back(it->desc->branchName());
00048 }
00049 sort_all(groupsToSelect_);
00050 }
00051 initialized_ = true;
00052 }
00053
00054 bool GroupSelector::selected(BranchDescription const& desc) const {
00055 if (!initialized_) {
00056 throw edm::Exception(edm::errors::LogicError)
00057 << "GroupSelector::selected() called prematurely\n"
00058 << "before the product registry has been frozen.\n";
00059 }
00060
00061
00062 return binary_search_all(groupsToSelect_, desc.branchName());
00063 }
00064
00065 void
00066 GroupSelector::print(std::ostream& os) const {
00067 os << "GroupSelector at: "
00068 << static_cast<void const*>(this)
00069 << " has "
00070 << groupsToSelect_.size()
00071 << " groups to select:\n";
00072 copy_all(groupsToSelect_, std::ostream_iterator<std::string>(os, "\n"));
00073 }
00074
00075
00076
00077
00078
00079
00080 std::ostream&
00081 operator<< (std::ostream& os, const GroupSelector& gs)
00082 {
00083 gs.print(os);
00084 return os;
00085 }
00086
00087 }