CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TriggerObjectStandAlone.cc
Go to the documentation of this file.
1 //
2 // $Id: TriggerObjectStandAlone.cc,v 1.9 2011/02/02 17:06:24 vadler Exp $
3 //
4 
6 
7 #include <boost/algorithm/string.hpp>
9 
10 
11 using namespace pat;
12 
13 
14 // Const data members' definitions
15 
16 
18 
19 
20 // Private methods
21 
22 
23 // Checks a string vector for occurence of a certain string, incl. wild-card mechanism
24 bool TriggerObjectStandAlone::hasAnyName( const std::string & name, const std::vector< std::string > & nameVec ) const
25 {
26  // Special cases first
27  // Always false for empty vector to check
28  if ( nameVec.empty() ) return false;
29  // Always true for general wild-card(s)
30  if ( name.find_first_not_of( wildcard_ ) == std::string::npos ) return true;
31  // Split name to evaluate in parts, seperated by wild-cards
32  std::vector< std::string > namePartsVec;
33  boost::split( namePartsVec, name, boost::is_any_of( std::string( 1, wildcard_ ) ), boost::token_compress_on );
34  // Iterate over vector of names to search
35  for ( std::vector< std::string >::const_iterator iVec = nameVec.begin(); iVec != nameVec.end(); ++iVec ) {
36  // Not failed yet
37  bool failed( false );
38  // Start searching at the first character
39  size_type index( 0 );
40  // Iterate over evaluation name parts
41  for ( std::vector< std::string >::const_iterator iName = namePartsVec.begin(); iName != namePartsVec.end(); ++iName ) {
42  // Empty parts due to
43  // - wild-card at beginning/end or
44  // - multiple wild-cards (should be supressed by 'boost::token_compress_on')
45  if ( iName->length() == 0 ) continue;
46  // Search from current index and
47  // set index to found occurence
48  index = iVec->find( *iName, index );
49  // Failed and exit loop, if
50  // - part not found
51  // - part at beginning not found there
52  if ( index == std::string::npos || ( iName == namePartsVec.begin() && index > 0 ) ) {
53  failed = true;
54  break;
55  }
56  // Increase index by length of found part
57  index += iName->length();
58  }
59  // Failed, if end of name not reached
60  if ( index < iVec->length() && namePartsVec.back().length() != 0 ) failed = true;
61  // Match found!
62  if ( ! failed ) return true;
63  }
64  // No match found!
65  return false;
66 }
67 
68 
69 // Adds a new HLT path or L1 algorithm name
70 void TriggerObjectStandAlone::addPathOrAlgorithm( const std::string & name, bool firing )
71 {
72  // Check, if path is already assigned
73  if ( ! hasPathOrAlgorithm( name, false ) ) {
74  // The path itself
75  pathNames_.push_back( name );
76  // The corresponding usage of the trigger objects
77  pathLastFilterAccepted_.push_back( firing );
78  }
79 }
80 
81 
82 // Gets all HLT path or L1 algorithm names
83 std::vector< std::string > TriggerObjectStandAlone::pathsOrAlgorithms( bool firing ) const
84 {
85  // All path names, if usage not restricted (not required or not available)
86  if ( ! firing || ! hasFiring() ) return pathNames_;
87  // Temp vector of path names
88  std::vector< std::string > paths;
89  // Loop over usage vector and fill corresponding paths into temp vector
90  for ( unsigned iPath = 0; iPath < pathNames_.size(); ++iPath ) {
91  if ( pathLastFilterAccepted_.at( iPath ) ) paths.push_back( pathNames_.at( iPath ) );
92  }
93  // Return temp vector
94  return paths;
95 }
96 
97 
98 // Checks, if a certain HLT filter label or L1 condition name is assigned
99 bool TriggerObjectStandAlone::hasFilterOrCondition( const std::string & name ) const
100 {
101  // Move to wild-card parser, if needed
102  if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, filterLabels_ );
103  // Return, if filter label is assigned
104  return ( std::find( filterLabels_.begin(), filterLabels_.end(), name ) != filterLabels_.end() );
105 }
106 
107 
108 // Checks, if a certain path name is assigned
109 bool TriggerObjectStandAlone::hasPathOrAlgorithm( const std::string & name, bool firing ) const
110 {
111  // Move to wild-card parser, if needed
112  if ( name.find( wildcard_ ) != std::string::npos ) return hasAnyName( name, pathsOrAlgorithms( firing ) );
113  // Deal with older PAT-tuples, where trigger object usage is not available
114  if ( ! hasFiring() ) firing = false;
115  // Check, if path name is assigned at all
116  std::vector< std::string >::const_iterator match( std::find( pathNames_.begin(), pathNames_.end(), name ) );
117  // False, if path name not assigned
118  if ( match == pathNames_.end() ) return false;
119  // Return for assigned path name, if trigger object usage meets requirement
120  return ( firing ? pathLastFilterAccepted_.at( match - pathNames_.begin() ) : true );
121 }
122 
123 
124 // Methods
125 
126 
127 // Gets the pat::TriggerObject (parent class)
129 {
130  // Create a TriggerObjects
131  TriggerObject theObj( p4(), pdgId() );
132  // Set its collection and trigger objects types (no c'tor for that)
133  theObj.setCollection( collection() );
134  for ( size_t i = 0; i < triggerObjectTypes().size(); ++i ) theObj.addTriggerObjectType( triggerObjectTypes().at( i ) );
135  // Return TriggerObject
136  return theObj;
137 }
138 
139 
140 // Checks, if a certain label of original collection is assigned (method overrides)
141 bool TriggerObjectStandAlone::hasCollection( const std::string & collName ) const
142 {
143  // Move to wild-card parser, if needed only
144  if ( collName.find( wildcard_ ) != std::string::npos ) {
145  // True, if collection name is simply fine
146  if ( hasAnyName( collName, std::vector< std::string >( 1, collection() ) ) ) return true;
147  // Check, if collection name possibly fits in an edm::InputTag approach
148  const edm::InputTag collectionTag( collection() );
149  const edm::InputTag collTag( collName );
150  // If evaluated collection tag contains a process name, it must have been found already by identity check
151  if ( collTag.process().empty() ) {
152  // Check instance ...
153  if ( ( collTag.instance().empty() && collectionTag.instance().empty() ) || hasAnyName( collTag.instance(), std::vector< std::string >( 1, collectionTag.instance() ) ) ) {
154  // ... and label
155  return hasAnyName( collTag.label(), std::vector< std::string >( 1, collectionTag.label() ) );
156  }
157  }
158  return false;
159  }
160  // Use parent class's method otherwise
161  return TriggerObject::hasCollection( collName );
162 }
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
bool hasFiring() const
Checks, if the usage indicator vector has been filled.
size_t size_type
Definition: Candidate.h:32
virtual bool hasCollection(const std::string &collName) const
Checks, if a certain label of original collection is assigned (method overrides)
static const char wildcard_
Constants.
std::vector< std::string > pathNames_
Vector of names of all HLT paths or L1 algorithms the trigger objects has been used in...
std::vector< std::string > filterLabels_
Vector of labels of all HLT filters or names od L1 conditions the trigger objects has been used in...
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
Analysis-level trigger object class.
Definition: TriggerObject.h:49
bool hasAnyName(const std::string &name, const std::vector< std::string > &nameVec) const
Private methods.
TriggerObject triggerObject()
Gets the pat::TriggerObject (parent class)
void setCollection(const std::string &collName)
Methods.
Definition: TriggerObject.h:86
virtual bool hasCollection(const std::string &collName) const
Checks, if a certain label of original collection is assigned.
unsigned int index
Definition: LeafCandidate.h:33
std::string collection() const
Get the label of the collection the trigger object originates from.
Definition: TriggerObject.h:94
unsigned int index
index type
Definition: Candidate.h:53
std::string const & label() const
Definition: InputTag.h:25
std::string const & process() const
Definition: InputTag.h:29
bool hasPathOrAlgorithm(const std::string &name, bool firing=true) const
Checks, if a certain HLT path or L1 algorithm name is assigned.
std::vector< int > triggerObjectTypes() const
Get all trigger object type identifiers.
bool hasFilterOrCondition(const std::string &name) const
Checks, if a certain HLT filter label or L1 condition name is assigned.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
void addPathOrAlgorithm(const std::string &name, bool firing=true)
Adds a new HLT path or L1 algorithm name.
void addTriggerObjectType(trigger::TriggerObjectType triggerObjectType)
Add a new trigger object type identifier.
Definition: TriggerObject.h:89
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
std::string const & instance() const
Definition: InputTag.h:26
std::vector< bool > pathLastFilterAccepted_
double split
Definition: MVATrainer.cc:139
std::vector< std::string > pathsOrAlgorithms(bool firing=true) const
Gets all HLT path or L1 algorithm names.
list at
Definition: asciidump.py:428