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