1 |
/** @file |
/** @file |
2 |
* $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $ |
* $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $ |
3 |
* $Id: EventCounter.cpp,v 2.0 2004/09/21 20:49:57 kusanagi Exp $ |
* $Id: EventCounter.cpp,v 2.1 2004/09/24 11:57:32 kusanagi Exp $ |
4 |
* $Author: kusanagi $ |
* $Author: kusanagi $ |
5 |
* |
* |
6 |
* Implementation of the EventCounter class. |
* Implementation of the EventCounter class. |
65 |
RunNumber(run) { |
RunNumber(run) { |
66 |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
67 |
CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun)); |
CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun)); |
68 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse1)); |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1)); |
69 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2)); |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2)); |
70 |
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
71 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth)); |
CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth)); |
109 |
* Increment the event counter for a certain packet. |
* Increment the event counter for a certain packet. |
110 |
* @param type Event type to be incremented. |
* @param type Event type to be incremented. |
111 |
*/ |
*/ |
112 |
void EventCounter::Increment(PacketType const * type) { |
void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){ |
113 |
CounterMap::iterator p = CMap.find(type); |
CounterMap::iterator p = CMap.find(type); |
114 |
if (p != CMap.end()) { |
if (p != CMap.end()) { |
115 |
int *counter = p->second; |
int *counter = p->second; |
116 |
(*counter)++; |
(*counter)++; |
117 |
oss.flush(); |
oss.str(""); |
118 |
oss << " Counter." << type->GetName() << " = " << (*counter); |
oss << " Counter." << type->GetName() << " = " << (*counter); |
119 |
logger->debug(oss.str().c_str()); |
logger->debug(oss.str().c_str()); |
120 |
} else { |
} else { |
121 |
oss.flush(); |
throw NotExistingCounterException(type->GetName().c_str()); |
|
oss << " No counter for packet type " << type->GetName(); |
|
|
logger->warn(oss.str().c_str()); |
|
122 |
} |
} |
123 |
} |
} |
124 |
|
|
130 |
* number of the last read event of that type. |
* number of the last read event of that type. |
131 |
* @retval -1 if there was no event of this type. |
* @retval -1 if there was no event of this type. |
132 |
*/ |
*/ |
133 |
int EventCounter::Get(PacketType const * type) const { |
int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){ |
134 |
const CounterMap::const_iterator p = CMap.find(type); |
const CounterMap::const_iterator p = CMap.find(type); |
135 |
if (p != CMap.end()) { |
if (p != CMap.end()) { |
136 |
const int *counter = p->second; |
const int *counter = p->second; |
137 |
return *counter; |
return *counter; |
138 |
} else { |
} else { |
139 |
oss.flush(); |
throw NotExistingCounterException(type->GetName().c_str()); |
|
oss << " No counter for packet type " << type->GetName(); |
|
|
logger->warn(oss.str().c_str()); |
|
140 |
return -1; |
return -1; |
141 |
} |
} |
142 |
} |
} |
147 |
* @return The next counter of that packet type. |
* @return The next counter of that packet type. |
148 |
* @retval -1 if there was no event of this type. |
* @retval -1 if there was no event of this type. |
149 |
*/ |
*/ |
150 |
int EventCounter::Next(PacketType const * type) const { |
int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){ |
151 |
const CounterMap::const_iterator p = CMap.find(type); |
const CounterMap::const_iterator p = CMap.find(type); |
152 |
if (p != CMap.end()) { |
if (p != CMap.end()) { |
153 |
const int *counter = p->second; |
const int *counter = p->second; |
154 |
return *counter + 1; |
return *counter + 1; |
155 |
} else { |
} else { |
156 |
oss.flush(); |
throw NotExistingCounterException(type->GetName().c_str()); |
|
oss << " No counter for packet type " << type->GetName(); |
|
|
logger->warn(oss.str().c_str()); |
|
157 |
return -1; |
return -1; |
158 |
} |
} |
159 |
} |
} |
164 |
*/ |
*/ |
165 |
void EventCounter::PrintCounters() const { |
void EventCounter::PrintCounters() const { |
166 |
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
167 |
oss.flush(); |
oss.str(""); |
168 |
oss << " Counter." << (p->first)->GetName() << " = " << (*p->second); |
oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second); |
169 |
logger->warn(oss.str().c_str()); |
logger->warn(oss.str().c_str()); |
|
std::cout << " Counter." << (p->first)->GetName() << "\t = \t" << (*p->second) << "\n"; |
|
170 |
} |
} |
171 |
} |
} |