00001
00002 #ifndef TRIGNAVSTRUCTURE_TRIGGERELEMENT_H
00003 #define TRIGNAVSTRUCTURE_TRIGGERELEMENT_H
00004
00005 #include <map>
00006 #include <vector>
00007 #include <string>
00008 #include <stdint.h>
00009 #include <iostream>
00010
00011
00012 #include "TrigNavStructure/Types.h"
00013 namespace HLT {
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00041 class TriggerElement {
00042 public:
00043
00044 TriggerElement();
00045 TriggerElement( te_id_type id, bool ghost, bool nofwd=false);
00046 ~TriggerElement();
00047
00052
00053
00057 inline te_id_type getId() const { return m_id; }
00058
00062 inline bool getActiveState() const { return m_state & activeState; }
00063
00067 void setActiveState( bool state );
00068
00069 inline bool ghost() const { return m_state & ghostState; }
00070 bool getGhostState() const { return m_state & ghostState; }
00071 void setGhostState( bool t = true);
00072
00073 void setTransient(bool t = true) { m_transient = t; }
00074 bool transient() { return m_transient; }
00075
00076
00077 void setErrorState(bool state = true);
00078
00079 inline bool getErrorState() const { return m_state & errorState; }
00080
00081
00082
00083
00084
00093 class ObjectIndex {
00094 public:
00095
00096 ObjectIndex();
00097
00098 ObjectIndex(sub_index_type subType, index_type begin, index_type end);
00099 sub_index_type subTypeIndex() const;
00100 index_type objectsBegin() const;
00101 index_type objectsEnd() const;
00102 bool isSameOrWithin ( const ObjectIndex* idx) const;
00103 void updateBeginAndEnd( index_type begin, index_type end);
00104 bool operator<(const ObjectIndex& obj) const;
00105
00106 void serialize(std::vector<uint32_t>& output) const;
00107 void deserialize( std::vector<uint32_t>::const_iterator& inputIt);
00108
00109 void setSubTypeIndex(sub_index_type idx) { m_subTypeIndex = idx; }
00110 bool valid() const;
00111 bool operator==(const ObjectIndex& rhs) const {
00112 if (m_subTypeIndex != rhs.m_subTypeIndex || m_objIndexBegin != rhs.m_objIndexBegin
00113 || m_objIndexEnd != rhs.m_objIndexEnd)
00114 return false;
00115 return true;
00116 }
00117 bool operator!=(const ObjectIndex& rhs) const {
00118 return ! (*this == rhs);
00119 }
00120
00121 private:
00122 sub_index_type m_subTypeIndex;
00123 index_type m_objIndexBegin;
00124 index_type m_objIndexEnd;
00125 };
00126
00127
00128
00129
00130
00134 enum Relation {
00135 sameRoIRelation,
00136 seedsRelation,
00137 seededByRelation
00138 };
00139
00145 inline const std::vector<TriggerElement*>& getRelated( Relation rel ) const { return m_relations[rel];}
00146
00147 enum States {
00148 activeState = 0x1,
00149 ghostState = 0x2,
00150 nofwdState = 0x4,
00151 errorState = 0x8
00152 };
00153
00154 mutable std::map<Relation, std::vector<TriggerElement*> > m_relations;
00155
00162 void relate( TriggerElement* te, Relation r ) const;
00163
00169 void relate( const std::vector<TriggerElement*> tes, Relation r ) const;
00170
00171 static unsigned int enquireId( std::vector<uint32_t>::const_iterator& inputIt );
00172
00179 void serialize( std::vector<uint32_t>& output, const std::map<TriggerElement*, uint16_t>& keys, const TriggerElement* previous ) const;
00180
00187 void deserialize( std::vector<uint32_t>::const_iterator& inputIt, const std::map<uint16_t, TriggerElement*>& keys, const TriggerElement* previous );
00188
00189
00190
00203 class FeatureAccessHelper {
00204 public:
00205 FeatureAccessHelper()
00206 : m_CLID(0), m_forget(false) {}
00207
00208 FeatureAccessHelper( class_id_type clid, ObjectIndex index, bool forget=false)
00209 : m_CLID(clid), m_index(index),m_forget(forget) {}
00210
00211
00212
00213
00214
00215 void setCLIDandIndex(class_id_type clid, sub_index_type idx){
00216 m_CLID = clid;
00217 m_index.setSubTypeIndex(idx);
00218 }
00219 inline class_id_type getCLID() const {return m_CLID;}
00220 inline const ObjectIndex& getIndex() const {return m_index;}
00221
00222 inline void setForget( bool value = true ) { m_forget = value; }
00223 inline bool forget() const { return m_forget; }
00224 friend std::ostream& operator<<( std::ostream& o, const FeatureAccessHelper& f ) {
00225 o << " CLID:" << f.m_CLID
00226 << " idx:" << f.m_index.subTypeIndex()
00227 << ":" << f.m_index.objectsBegin()
00228 << ":" << f.m_index.objectsEnd() << std::dec;
00229 return o;
00230 }
00231 bool operator==(const FeatureAccessHelper& rhs) const {
00232 if (m_CLID != rhs.m_CLID || m_index != rhs.m_index)
00233 return false;
00234 return true;
00235 }
00236
00237 bool valid() const { return m_CLID != invalid_class_id and m_index.valid(); }
00238
00239 private:
00240 class_id_type m_CLID;
00241 ObjectIndex m_index;
00242 bool m_forget;
00243 };
00244 typedef std::vector< FeatureAccessHelper > FeatureVec;
00245
00249 const std::vector< FeatureAccessHelper >& getFeatureAccessHelpers() const { return m_uses; }
00250 std::vector< FeatureAccessHelper >& getFeatureAccessHelpers() { return m_uses; }
00251
00258 void addFeature( class_id_type clid, const ObjectIndex& index, bool forget=false );
00259 void addFeature( const FeatureAccessHelper& f);
00260
00261
00262 const std::vector<FeatureAccessHelper>& getPreviousFeatures() const {return m_prev; }
00263 std::vector<FeatureAccessHelper>& getPreviousFeatures() {return m_prev; }
00264
00265
00266 private:
00267 unsigned int m_state;
00268 te_id_type m_id;
00269 bool m_transient;
00270 std::vector< FeatureAccessHelper > m_uses;
00271 std::vector< FeatureAccessHelper > m_prev;
00272
00273 };
00274 }
00275
00276 #endif //TRIGNAVSTRUCTURE_TRIGGERELEMENT_H