Skip to content

Commit

Permalink
Changes to Trigger Results from Martin Gruenewald
Browse files Browse the repository at this point in the history
  • Loading branch information
William Tanenbaum committed Apr 19, 2006
1 parent e16e382 commit 47664bd
Show file tree
Hide file tree
Showing 19 changed files with 404 additions and 239 deletions.
98 changes: 98 additions & 0 deletions DataFormats/Common/interface/HLTGlobalStatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#ifndef Common_HLTGlobalStatus_h
#define Common_HLTGlobalStatus_h

/** \class HLTGlobalStatus
*
*
* The HLT global status, summarising the status of the individual
* HLT triggers, is implemented as a vector of HLTPathStatus objects.
*
* If the user wants map-like indexing of HLT triggers through their
* names as key, s/he must use the TriggerNamesService.
*
* $Date: 2006/04/11 10:10:10 $
* $Revision: 1.0 $
*
* \author Martin Grunewald
*
*/

#include "DataFormats/Common/interface/HLTenums.h"
#include "DataFormats/Common/interface/HLTPathStatus.h"

#include <vector>
#include <iostream>

namespace edm
{
class HLTGlobalStatus {

private:

std::vector<HLTPathStatus> paths_;

public:

// constructor

HLTGlobalStatus(const unsigned int n=0) : paths_(n) {}

// member methods

unsigned int size() const { return paths_.size(); }

void reset() {
const unsigned int n(size());
for (unsigned int i=0; i!=n; i++) paths_[i].reset();
}

// global "state" variables calculated on the fly!

bool wasrun() const {return State(0);}
bool accept() const {return State(1);}
bool error() const {return State(2);}

// get hold of individual elements, using safe indexing with "at" which throws!

const HLTPathStatus& at (const unsigned int i) const { return paths_.at(i); }
HLTPathStatus& at (const unsigned int i) { return paths_.at(i); }
const HLTPathStatus& operator[](const unsigned int i) const { return paths_.at(i); }
HLTPathStatus& operator[](const unsigned int i) { return paths_.at(i); }

bool wasrun(const unsigned int i) const { return at(i).wasrun(); }
bool accept(const unsigned int i) const { return at(i).accept(); }
bool error(const unsigned int i) const { return at(i).error() ; }

hlt::HLTState state(const unsigned int i) const { return at(i).state(); }
unsigned int abort(const unsigned int i) const { return at(i).abort(); }

private:

bool State(unsigned int icase) const {
bool flags[3] = {false, false, false};
const unsigned int n(size());
for (unsigned int i=0; i!=n; i++) {
const hlt::HLTState s(state(i));
if (s!=hlt::Ready) {
flags[0]=true; // at least one trigger was run
if (s==hlt::Pass) {
flags[1]=true; // at least one trigger accepted
} else if (s==hlt::Exception) {
flags[2]=true; // at least one trigger with error
}
}
}
return flags[icase];
}

};

inline std::ostream& operator <<(std::ostream& ost, const HLTGlobalStatus& hlt) {
const unsigned int n(hlt.size());
for (unsigned int i=0; i!=n; i++) ost << (hlt.accept(i)==hlt::Pass) ;
return ost;
}

}

#endif // Common_HLTGlobalStatus_h
53 changes: 53 additions & 0 deletions DataFormats/Common/interface/HLTPathStatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef Common_HLTPathStatus_h
#define Common_HLTPathStatus_h

/** \class HLTPathStatus
*
* The status of a single HLT trigger (single trigger path consisting
* of modules on the path). Initially, the status is Ready (meaning
* that this trigger path has not run yet for this event). If all
* modules on the path pass (accept) the event, then the state is
* Pass. If any module on the path fails (rejects) the event, then
* the state of the whole trigger path is Fail. If any module on the
* path throws an unhandled error, then the trigger state is
* Exception. In the latter two cases, the position of the module in
* the path issuing the (first) fail/error is recorded. The Fw skips
* further processing of modules along this path, ie, path processing
* is aborted.
*
* $Date: 2006/04/11 10:10:10 $
* $Revision: 1.0 $
*
* \author Martin Grunewald
*
*/

#include "DataFormats/Common/interface/HLTenums.h"
#include <cassert>

namespace edm
{
class HLTPathStatus {

private:
unsigned char item_; // packed data item: bits 0-1: state,
// bits 2-n: index of aborting module

public:

HLTPathStatus(const hlt::HLTState state = hlt::Ready, const unsigned int abort = 0)
: item_(abort*4+state) { assert(abort<64); }

hlt::HLTState state() const {return ((hlt::HLTState) (item_ % 4));}
unsigned int abort() const {return ((unsigned int) (item_ / 4));}

void reset() {item_=0;}

bool wasrun() const {return (state() != hlt::Ready);}
bool accept() const {return (state() == hlt::Pass );}
bool error() const {return (state() == hlt::Exception);}

};
}

#endif // Common_HLTPathStatus_h
38 changes: 38 additions & 0 deletions DataFormats/Common/interface/HLTenums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef Common_HLTenums_h
#define Common_HLTenums_h

/** \brief HLT enums
*
* Definition of common HLT enums
*
* $Date: 2006/04/11 10:10:10 $
* $Revision: 1.0 $
*
* \author Martin Grunewald
*
*/

namespace edm
{
namespace hlt
{

// status of a trigger path
enum HLTState {Ready=0, // not [yet] run
Pass =1, // accept
Fail =2, // reject
Exception=3 // error
};

// predefined scalar physics observables
enum HLTScalar {MET =0, // total MET
METx=1, // MET in x
METy=2, // MET in y
METz=3, // MET in z
ETOT=4, // total energy
HT=5, ST=6 /* ... */
};
}
}

#endif // Common_HLTenums_h
165 changes: 41 additions & 124 deletions DataFormats/Common/interface/TriggerResults.h
Original file line number Diff line number Diff line change
@@ -1,152 +1,69 @@
#ifndef Common_TriggerResults_h
#define Common_TriggerResults_h

/*
Author: Jim Kowalkowski 13-01-06
$Id: TriggerResults.h,v 1.3 2006/02/07 07:51:41 wmtan Exp $
The trigger path results are maintained here as a sequence of bits,
one per trigger path. They are assigned in the order they appeared in
the process-level pset.
Implementation notes:
1) cannot get bitset to store properly, so vector<bool> will be saved
for now
2) there is as of this writing, no place in the file to store parameter
sets or run information. The trigger bit descriptions need to be stored
in these sections. This object stores the parameter ID, which can be
used to locate the parameter in the file when that option becomes available.
For now, this object contains the trigger paths as a vector of strings.
/** \class TriggerResults
*
* Original Author: Jim Kowalkowski 13-01-06
* $Id: TriggerResults.h,v 1.1 2006/02/08 00:44:23 wmtan Exp $
*
* The trigger path results are maintained here as a sequence of
* entries, one per trigger path. They are assigned in the order
* they appeared in the process-level pset.
*
* Implementation note: there is as of this writing, no place in the
* file to store parameter sets or run information. The trigger bit
* descriptions need to be stored in these sections. This object
* stores the parameter ID, which can be used to locate the parameter
* in the file when that option becomes available. For now, this
* object contains the trigger path names as a vector of strings.
*
* $Date: 2006/04/11 10:10:10 $
* $Revision: 1.0 $
*
* \author Martin Grunewald
*
*/

#include "DataFormats/Common/interface/HLTGlobalStatus.h"
#include "DataFormats/Common/interface/ParameterSetID.h"

#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <bitset>
#include <iostream>
#include<cassert>

namespace edm
{
class TriggerResults
{
public:
typedef std::bitset<2048> BitMask;
typedef std::vector<bool> BitVector;
typedef std::vector<std::string> Strings;

TriggerResults(): insync_(false),bits_(),stored_(),id_(),saved_names_() { }

TriggerResults(const BitMask& in,const Strings& trigger_names):
insync_(true),bits_(in),stored_(trigger_names.size()),id_(),saved_names_(trigger_names)
{ toVector(); }
class TriggerResults : public HLTGlobalStatus {

// Cannot work until parameter set ID can be resolved
// TriggerResults(const BitMask& in,edm::ParameterSetID id):
// insync_(true),bits_(in),stored_(),id_(),saved_names_()
// { toVector(); }

TriggerResults(const BitMask& in,edm::ParameterSetID id,
const Strings& trigger_names):
insync_(true),bits_(in),stored_(trigger_names.size()),id_(id),saved_names_(trigger_names)
{ toVector(); }

bool fail() const { toBitset(); return bits_.none(); }
bool pass() const { toBitset(); return bits_.any(); }

int numBitsUsed() const { return saved_names_.size(); }

// these are not efficient ways to implement these functions
// and need to be improved

bool isSet(const std::string& path_name) const
{
toBitset();
Strings::const_iterator i = find(saved_names_.begin(),
saved_names_.end(),path_name);
return i==saved_names_.end() ? false :
bits_[distance(saved_names_.begin(),i)];
}
typedef std::vector<std::string> Strings;

bool isSet(int bit_pos) const
{
toBitset();
return bits_[bit_pos];
}

bool isSet(const BitMask& compare) const
{
toBitset();
return (bits_ & compare).any();
}
private:
edm::ParameterSetID id_;
Strings triggernames_;

bool isSet(const BitVector& compare) const
{
toBitset();
bool result = false;
public:
TriggerResults() : HLTGlobalStatus(), id_(), triggernames_() {}

if(stored_.size() <= compare.size())
result = std::inner_product(stored_.begin(),stored_.end(),
compare.begin(),false);
else
result = std::inner_product(compare.begin(),compare.end(),
stored_.begin(),false);
TriggerResults(const HLTGlobalStatus& hlt, const Strings& triggernames)
: HLTGlobalStatus(hlt), id_(), triggernames_(triggernames) { }

return result;
TriggerResults(const HLTGlobalStatus& hlt, const edm::ParameterSetID& id, const Strings& triggernames)
: HLTGlobalStatus(hlt), id_(id), triggernames_(triggernames) {
assert (hlt.size()==triggernames.size());
}

bool applyMasks(const BitVector& accept,const BitVector& veto) const
{
toBitset();
// not implemented
return false;
}
//

private:
void toBitset() const
{
if(insync_) return;
for(unsigned int i=0;i<saved_names_.size();++i)
{
bits_[i]=stored_[i];
vetobits_[i]=!stored_[i];
}
insync_=true;
}
const std::string& name(unsigned int i) const {return triggernames_.at(i);}

void toVector()
{
// needed until bitset can be successfully stored/retrieved
for(unsigned int i=0;i<saved_names_.size();++i) stored_[i]=bits_[i];
unsigned int find (const std::string name) const {
const unsigned int n(size());
for (unsigned int i=0; i!=n; i++) if (triggernames_[i]==name) return i;
return n;
}

// current implementation is a simple one
// could change in the future
mutable bool insync_; // transient
mutable BitMask bits_; // transient for now
mutable BitMask vetobits_; // transient for now
BitVector stored_;
edm::ParameterSetID id_;
Strings saved_names_;
// job that generated this pset, used to locate path names
// next is needed until the file metadata caches psets
};

inline std::ostream& operator<<(std::ostream& ost, const TriggerResults& tr)
{
int tot = tr.numBitsUsed();
for(int i=0;i<tot;++i)
{
ost << tr.isSet(i)?"1":"0";
}
return ost;
}

}

#endif
Loading

0 comments on commit 47664bd

Please sign in to comment.