1 #ifndef DataFormats_EventHypothesis_interface_EventHypothesis_h 2 #define DataFormats_EventHypothesis_interface_EventHypothesis_h 6 #include <boost/regex.hpp> 7 #include <boost/shared_ptr.hpp> 10 #include <type_traits> 15 namespace eventhypothesis {
template<
typename T>
class Looper; }
17 namespace eventhypothesis {
24 virtual bool operator()(
const CandRefType &
cand,
const std::string &role)
const = 0;
41 const_iterator
begin()
const {
return particles_.begin(); }
42 const_iterator
end()
const {
return particles_.end(); }
43 const_reverse_iterator
rbegin()
const {
return particles_.rbegin(); }
44 const_reverse_iterator
rend()
const {
return particles_.rend(); }
49 bool operator()(
const value_type &
p)
const {
return p.first == role_; }
58 const CandRefType &
get(
const ParticleFilter &
filter,
int index=0)
const ;
59 template<
typename T>
const T * getAs(
const std::string &role,
int index=0)
const ;
60 template<
typename T>
const T * getAs(
const ParticleFilter &filter,
int index=0)
const ;
62 const CandRefType &
operator[](
const ParticleFilter &filter)
const {
return get(
filter,0); }
67 std::vector<CandRefType>
all(
const ParticleFilter &filter)
const;
69 size_t count()
const {
return particles_.size(); }
73 size_t count(
const ParticleFilter &role)
const;
76 CandLooper
loop()
const ;
81 CandLooper
loop(
const ParticleFilter &filter)
const;
85 CandLooper
loop(
const ParticleFilter *filter)
const;
87 CandLooper
loop(
const ParticleFilterPtr &filter)
const;
103 template<
typename Iterator,
typename Predicate>
105 char * getDemangledSymbol(
const char* mangledSymbol)
const;
106 template<
typename T>
std::string createExceptionMessage(
const CandRefType &ref)
const;
112 namespace eventhypothesis {
124 return boost::regex_match(role, re_);
131 template<
typename Iterator,
typename Predicate>
135 while (it != realEnd) {
137 if (idx == 0)
return it;
148 std::stringstream message;
149 char *currentType = getDemangledSymbol(
typeid(std::remove_reference<decltype(ref)>::
type::value_type).
name());
150 char *targetType = getDemangledSymbol(
typeid(
T).
name());
151 if (currentType !=
nullptr && targetType !=
nullptr) {
152 message <<
"You can't convert a '" << currentType <<
"' to a '" << targetType <<
"'" << std::endl;
156 message <<
"You can't convert a '" <<
typeid(ref).
name() <<
"' to a '" <<
typeid(
T).
name() <<
"'" << std::endl;
157 message <<
"Note: you can use 'c++filt -t' command to convert the above in human readable types." << std::endl;
159 return message.str();
167 const T* ret =
dynamic_cast<const T*
>(ref.
get());
168 if ((ret == 0) && (ref.
get() !=
nullptr))
throw cms::Exception(
"Type Checking") << createExceptionMessage<T>(ref);
176 const T* ret =
dynamic_cast<const T*
>(ref.
get());
177 if ((ret == 0) && (ref.
get() !=
nullptr))
throw cms::Exception(
"Type Checking") << createExceptionMessage<T>(ref);
const std::string & role_
eventhypothesis::ParticleFilter ParticleFilter
std::vector< value_type > particles_
eventhypothesis::Looper< T > loopAs(const std::string &roleRegexp) const
Loops over particles which have certaint roles.
static const AcceptAllFilter s_dummyFilter
std::pair< std::string, CandRefType > value_type
Iterator realGet(const Iterator &realBegin, const Iterator &realEnd, const Predicate &p, size_t idx) const
RoleRegexpFilter(const std::string &roleRegexp)
T const * get() const
Returns C++ pointer to the item.
std::string createExceptionMessage(const CandRefType &ref) const
const T * getAs(const std::string &role, int index=0) const
boost::shared_ptr< const ParticleFilter > ParticleFilterPtr
const CandRefType & operator[](const std::string &role) const
reco::CandidatePtr CandRefType
Container::value_type value_type
const_iterator end() const
const CandRefType & operator[](const ParticleFilter &filter) const
eventhypothesis::CandRefType CandRefType
bool operator()(const value_type &p) const
eventhypothesis::Looper< reco::Candidate > CandLooper
bool operator()(const CandRefType &cand, const std::string &role) const override
virtual ~ParticleFilter()
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
std::vector< value_type > vector_type
eventhypothesis::ParticleFilterPtr ParticleFilterPtr
vector_type::const_iterator const_iterator
const_reverse_iterator rend() const
bool operator()(const CandRefType &cand, const std::string &role) const override
ByRole(const std::string &role)
const_iterator begin() const
vector_type::const_reverse_iterator const_reverse_iterator
bool operator()(const std::pair< std::string, CandRefType > &p) const
const_reverse_iterator rbegin() const