StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTriggerId.cxx
1 /***************************************************************************
2  *
3  * $Id: StTriggerId.cxx,v 2.5 2011/02/02 20:20:10 ullrich Exp $
4  *
5  * Author: Thomas Ullrich, January 2003
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: StTriggerId.cxx,v $
13  * Revision 2.5 2011/02/02 20:20:10 ullrich
14  * Extend to 64 bit (Jamie)
15  *
16  * Revision 2.4 2005/08/16 22:36:27 ullrich
17  * Fixed bug in copy and assignement operator (mMask not assigned).
18  *
19  * Revision 2.3 2004/10/11 23:00:20 ullrich
20  * Add copy constructor and assign. op., implement ostream op., define to enum.
21  *
22  * Revision 2.2 2003/02/18 21:34:46 jeromel
23  * Changed vector to arrays
24  *
25  * Revision 2.1 2003/01/30 18:14:15 ullrich
26  * Initial Revision.
27  *
28  **************************************************************************/
29 #include "StTriggerId.h"
30 #include "StMessMgr.h"
31 
32 
33 ClassImp(StTriggerId)
34 
35 StTriggerId::StTriggerId() : mMask(0) {
36  mIdx = 0;
37  for(int i=0 ; i < mMaxTriggerIds ; ++i) {
38  mId[i] = 0;
39  mVersion[i] = 0;
40  mNameVersion[i] = 0;
41  mThresholdVersion[i] = 0;
42  mPrescaleVersion[i] = 0;
43  }
44 }
45 
46 StTriggerId::~StTriggerId() {/* noop */}
47 
48 StTriggerId::StTriggerId(const StTriggerId &id) {
49  mIdx = id.mIdx;
50  mMask = id.mMask;
51  for(int i=0 ; i < mMaxTriggerIds ; ++i){
52  mId[i] = id.mId[i];
53  mVersion[i] = id.mVersion[i];
54  mNameVersion[i] = id.mNameVersion[i];
55  mThresholdVersion[i] = id.mThresholdVersion[i];
56  mPrescaleVersion[i] = id.mPrescaleVersion[i];
57  }
58 }
59 
60 const StTriggerId &StTriggerId::operator=(const StTriggerId &id) {
61  if (&id==this) return id;
62 
63  mIdx = id.mIdx;
64  mMask = id.mMask;
65 
66  for(int i=0 ; i < mMaxTriggerIds ; ++i) {
67  mId[i] = id.mId[i];
68  mVersion[i] = id.mVersion[i];
69  mNameVersion[i] = id.mNameVersion[i];
70  mThresholdVersion[i] = id.mThresholdVersion[i];
71  mPrescaleVersion[i] = id.mPrescaleVersion[i];
72  }
73  return *this;
74 }
75 
76 unsigned int
77 StTriggerId::index(unsigned int id) const
78 {
79  for (unsigned int i=0; i<mMaxTriggerIds; i++)
80  if (id == mId[i]) return i;
81  return mMaxTriggerIds; // no index found (no such trigger id)
82 }
83 
84 uint64_t
85 StTriggerId::mask() const {return mMask;}
86 
87 bool
88 StTriggerId::isTrigger(unsigned int id) const
89 {
90  return index(id) < mMaxTriggerIds;
91 }
92 
93 unsigned int
94 StTriggerId::version(unsigned int id) const
95 {
96  unsigned int i = index(id);
97  if (i < mMaxTriggerIds)
98  return mVersion[i];
99  else
100  return 0;
101 }
102 
103 unsigned int
104 StTriggerId::nameVersion(unsigned int id) const
105 {
106  unsigned int i = index(id);
107  if (i < mMaxTriggerIds)
108  return mNameVersion[i];
109  else
110  return 0;
111 }
112 
113 unsigned int
114 StTriggerId::thresholdVersion(unsigned int id) const
115 {
116  unsigned int i = index(id);
117  if (i < mMaxTriggerIds)
118  return mThresholdVersion[i];
119  else
120  return 0;
121 }
122 
123 unsigned int
124 StTriggerId::prescaleVersion(unsigned int id) const
125 {
126  unsigned int i = index(id);
127  if (i < mMaxTriggerIds)
128  return mPrescaleVersion[i];
129  else
130  return 0;
131 }
132 
133 vector<unsigned int>
134 StTriggerId::triggerIds() const {
135  vector<unsigned int> retVec;
136  for (unsigned int i=0; i< mMaxTriggerIds; ++i) {
137  if (mId[i]) retVec.push_back(mId[i]);
138  }
139 
140  return retVec;
141 }
142 
143 void
144 StTriggerId::setMask(uint64_t val) {mMask = val;}
145 
146 void
147 StTriggerId::addTrigger(unsigned int id, unsigned int v,
148  unsigned int nv, unsigned int tv,
149  unsigned int pv)
150 {
151  if( mIdx >= mMaxTriggerIds){
152  gMessMgr->Warning() << "StTriggerId::addTrigger : MAX Dimension reached. Cannot add !!" << endm;
153  }
154  else {
155  mId[mIdx] = id;
156  mVersion[mIdx] = v;
157  mNameVersion[mIdx] = nv;
158  mThresholdVersion[mIdx] = tv;
159  mPrescaleVersion[mIdx] = pv;
160  ++mIdx;
161  }
162 }
163 
164 ostream& operator<<(ostream& os, const StTriggerId& id)
165 {
166  for (unsigned int i=0; i<id.maxTriggerIds(); i++) {
167  os << i << '\t'
168  << id.mId[i] << '\t'
169  << id.mVersion[i] << '\t'
170  << id.mNameVersion[i] << '\t'
171  << id.mThresholdVersion[i] << '\t'
172  << id.mPrescaleVersion[i] << endl;
173  }
174  return os;
175 }