| 1 |
kusanagi |
1.1 |
/** @file |
| 2 |
kusanagi |
1.2 |
* $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $ |
| 3 |
|
|
* $Id: EventCounter.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $ |
| 4 |
|
|
* $Author: kusanagi $ |
| 5 |
kusanagi |
1.1 |
* |
| 6 |
|
|
* Implementation of the EventCounter class. |
| 7 |
|
|
*/ |
| 8 |
|
|
#include <log4cpp/Category.hh> |
| 9 |
|
|
|
| 10 |
|
|
#include "EventCounter.h" |
| 11 |
|
|
#include "PscuHeader.h" |
| 12 |
|
|
|
| 13 |
|
|
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.raw.EventCounter"); |
| 14 |
|
|
|
| 15 |
|
|
using namespace pamela; |
| 16 |
|
|
|
| 17 |
|
|
/** |
| 18 |
|
|
* Create a new event counter for a certain run. |
| 19 |
|
|
* @param run Run number. |
| 20 |
|
|
*/ |
| 21 |
|
|
EventCounter::EventCounter(int run): |
| 22 |
|
|
// New Packets. |
| 23 |
|
|
Pscu(-1), |
| 24 |
|
|
Physics(-1), |
| 25 |
|
|
Forced_Pkt(-1), |
| 26 |
kusanagi |
1.2 |
Calib_Trk1(-1), |
| 27 |
|
|
Calib_Trk2(-1), |
| 28 |
kusanagi |
1.1 |
Calib_Cal(-1), |
| 29 |
|
|
Calib_Trd(-1), |
| 30 |
|
|
Calib_Tof(-1), |
| 31 |
|
|
Calib_S4(-1), |
| 32 |
|
|
Run_Header(-1), |
| 33 |
|
|
Run_Trailer(-1), |
| 34 |
|
|
Alarm(-1), |
| 35 |
|
|
Khb(-1), |
| 36 |
|
|
Log(-1), |
| 37 |
|
|
VarDump(-1), |
| 38 |
|
|
ArrDump(-1), |
| 39 |
|
|
TabDump(-1), |
| 40 |
|
|
Tmtc(-1), |
| 41 |
|
|
Mcmd(-1), |
| 42 |
|
|
HA_Header_E5(-1), |
| 43 |
|
|
RunNumber(run) { |
| 44 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
| 45 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
| 46 |
|
|
CMap.insert(CounterMap::value_type(PacketType::ForcedPkt, &Forced_Pkt)); |
| 47 |
kusanagi |
1.2 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &Calib_Trk1)); |
| 48 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &Calib_Trk2)); |
| 49 |
kusanagi |
1.1 |
CMap.insert(CounterMap::value_type(PacketType::CalibCal, &Calib_Cal)); |
| 50 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd)); |
| 51 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof)); |
| 52 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4)); |
| 53 |
|
|
CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header)); |
| 54 |
|
|
CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer)); |
| 55 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Alarm, &Alarm)); |
| 56 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Khb, &Khb)); |
| 57 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); |
| 58 |
|
|
CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); |
| 59 |
|
|
CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); |
| 60 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); |
| 61 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); |
| 62 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); |
| 63 |
|
|
CMap.insert(CounterMap::value_type(PacketType::HA_Header_E5, &HA_Header_E5)); |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
|
/** |
| 67 |
|
|
* Increment the event counter for a certain packet. |
| 68 |
|
|
* @param type Event type to be incremented. |
| 69 |
|
|
*/ |
| 70 |
|
|
void EventCounter::Increment(PacketType const * type) { |
| 71 |
|
|
CounterMap::iterator p = CMap.find(type); |
| 72 |
|
|
if (p != CMap.end()) { |
| 73 |
|
|
int *counter = p->second; |
| 74 |
|
|
(*counter)++; |
| 75 |
|
|
cat << log4cpp::Priority::INFO |
| 76 |
|
|
<< " Counter." << type->GetName() << " = " << (*counter) |
| 77 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 78 |
|
|
} else { |
| 79 |
|
|
cat << log4cpp::Priority::INFO |
| 80 |
|
|
<< " No counter for packet type " << type->GetName() |
| 81 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 82 |
|
|
} |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
/** |
| 86 |
|
|
* Get the counter corresponding to a certain packet type. |
| 87 |
|
|
* @param type Event type to be incremented. |
| 88 |
|
|
* @return The counter of that packet type. For the current event type, |
| 89 |
|
|
* this is the actual event number. For all other types, this is the event |
| 90 |
|
|
* number of the last read event of that type. |
| 91 |
|
|
* @retval -1 if there was no event of this type. |
| 92 |
|
|
*/ |
| 93 |
|
|
int EventCounter::Get(PacketType const * type) const { |
| 94 |
|
|
const CounterMap::const_iterator p = CMap.find(type); |
| 95 |
|
|
if (p != CMap.end()) { |
| 96 |
|
|
const int *counter = p->second; |
| 97 |
|
|
return *counter; |
| 98 |
|
|
} else { |
| 99 |
|
|
cat << log4cpp::Priority::INFO |
| 100 |
|
|
<< " No counter for packet type " << type->GetName() |
| 101 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 102 |
|
|
return -1; |
| 103 |
|
|
} |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
|
/** |
| 107 |
|
|
* Get the counter of the next event corresponding to a certain packet type. |
| 108 |
|
|
* @param type Event type to be incremented. |
| 109 |
|
|
* @return The next counter of that packet type. |
| 110 |
|
|
* @retval -1 if there was no event of this type. |
| 111 |
|
|
*/ |
| 112 |
|
|
int EventCounter::Next(PacketType const * type) const { |
| 113 |
|
|
const CounterMap::const_iterator p = CMap.find(type); |
| 114 |
|
|
if (p != CMap.end()) { |
| 115 |
|
|
const int *counter = p->second; |
| 116 |
|
|
return *counter + 1; |
| 117 |
|
|
} else { |
| 118 |
|
|
cat << log4cpp::Priority::WARN |
| 119 |
|
|
<< " No counter for packet type " << type->GetName() |
| 120 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 121 |
|
|
return -1; |
| 122 |
|
|
} |
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
|
|
/** |
| 126 |
|
|
* Get the all the counters |
| 127 |
|
|
* @retval -1 if there was no event of this type. |
| 128 |
|
|
*/ |
| 129 |
|
|
void EventCounter::PrintCounters() const { |
| 130 |
|
|
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
| 131 |
|
|
cat << log4cpp::Priority::INFO << " Counter." << (p->first)->GetName() << " = " << (*p->second) |
| 132 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 133 |
|
|
} |
| 134 |
|
|
} |