1 |
kusanagi |
1.1 |
/** @file |
2 |
kusanagi |
1.2 |
* $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $ |
3 |
kusanagi |
2.1 |
* $Id: EventCounter.cpp,v 2.0 2004/09/21 20:49:57 kusanagi Exp $ |
4 |
kusanagi |
1.2 |
* $Author: kusanagi $ |
5 |
kusanagi |
1.1 |
* |
6 |
|
|
* Implementation of the EventCounter class. |
7 |
|
|
*/ |
8 |
kusanagi |
1.7 |
#include <log4cxx/logger.h> |
9 |
|
|
#include <sstream> |
10 |
kusanagi |
1.1 |
|
11 |
|
|
#include "EventCounter.h" |
12 |
|
|
#include "PscuHeader.h" |
13 |
|
|
|
14 |
|
|
|
15 |
kusanagi |
1.7 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter")); |
16 |
|
|
static std::stringstream oss; |
17 |
kusanagi |
1.1 |
using namespace pamela; |
18 |
|
|
|
19 |
|
|
/** |
20 |
|
|
* Create a new event counter for a certain run. |
21 |
|
|
* @param run Run number. |
22 |
|
|
*/ |
23 |
|
|
EventCounter::EventCounter(int run): |
24 |
|
|
// New Packets. |
25 |
kusanagi |
1.4 |
Pscu(0), |
26 |
kusanagi |
1.5 |
PhysEndRun(0), |
27 |
|
|
CalibCalPulse1(0), |
28 |
|
|
CalibCalPulse2(0), |
29 |
kusanagi |
1.4 |
Physics(0), |
30 |
kusanagi |
1.5 |
CalibTrkBoth(0), |
31 |
kusanagi |
1.4 |
Calib_Trk1(0), |
32 |
|
|
Calib_Trk2(0), |
33 |
|
|
Calib_Trd(0), |
34 |
|
|
Calib_Tof(0), |
35 |
|
|
Calib_S4(0), |
36 |
kusanagi |
1.5 |
Calib_CalPed(0), |
37 |
|
|
Calib_Ac(0), |
38 |
kusanagi |
1.4 |
Run_Header(0), |
39 |
|
|
Run_Trailer(0), |
40 |
kusanagi |
1.5 |
CalibHeader(0), |
41 |
|
|
CalibTrailer(0), |
42 |
|
|
InitHeader(0), |
43 |
|
|
InitTrailer(0), |
44 |
|
|
EventTrk(0), |
45 |
|
|
TestTrk(0), |
46 |
kusanagi |
1.7 |
TestTof(0), |
47 |
kusanagi |
1.4 |
Log(0), |
48 |
|
|
VarDump(0), |
49 |
|
|
ArrDump(0), |
50 |
|
|
TabDump(0), |
51 |
|
|
Tmtc(0), |
52 |
|
|
Mcmd(0), |
53 |
kusanagi |
1.5 |
ForcedFECmd(0), |
54 |
|
|
AcInit(0), |
55 |
|
|
CalInit(0), |
56 |
|
|
TrkInit(0), |
57 |
|
|
TofInit(0), |
58 |
|
|
TrgInit(0), |
59 |
kusanagi |
2.1 |
NdInit(0), |
60 |
kusanagi |
1.7 |
CalAlarm(0), |
61 |
|
|
AcAlarm(0), |
62 |
|
|
TrkAlarm(0), |
63 |
|
|
TrgAlarm(0), |
64 |
|
|
TofAlarm(0), |
65 |
kusanagi |
1.1 |
RunNumber(run) { |
66 |
kusanagi |
1.5 |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
67 |
|
|
CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun)); |
68 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse1)); |
69 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2)); |
70 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
71 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth)); |
72 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &Calib_Trk1)); |
73 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &Calib_Trk2)); |
74 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd)); |
75 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof)); |
76 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4)); |
77 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &Calib_CalPed)); |
78 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibAc, &Calib_Ac)); |
79 |
|
|
CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header)); |
80 |
|
|
CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer)); |
81 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader)); |
82 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer)); |
83 |
|
|
CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader)); |
84 |
|
|
CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer)); |
85 |
|
|
CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk)); |
86 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TestTrk, &TestTrk)); |
87 |
kusanagi |
1.7 |
CMap.insert(CounterMap::value_type(PacketType::TestTof, &TestTof)); |
88 |
kusanagi |
1.5 |
CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); |
89 |
|
|
CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); |
90 |
|
|
CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); |
91 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); |
92 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); |
93 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); |
94 |
|
|
CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd)); |
95 |
|
|
CMap.insert(CounterMap::value_type(PacketType::AcInit, &AcInit)); |
96 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit)); |
97 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit)); |
98 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit)); |
99 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit)); |
100 |
kusanagi |
2.1 |
CMap.insert(CounterMap::value_type(PacketType::TrgInit, &NdInit)); |
101 |
kusanagi |
1.7 |
CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm)); |
102 |
|
|
CMap.insert(CounterMap::value_type(PacketType::AcAlarm, &AcAlarm)); |
103 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm)); |
104 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm)); |
105 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm)); |
106 |
kusanagi |
1.1 |
} |
107 |
|
|
|
108 |
|
|
/** |
109 |
|
|
* Increment the event counter for a certain packet. |
110 |
|
|
* @param type Event type to be incremented. |
111 |
|
|
*/ |
112 |
|
|
void EventCounter::Increment(PacketType const * type) { |
113 |
|
|
CounterMap::iterator p = CMap.find(type); |
114 |
|
|
if (p != CMap.end()) { |
115 |
|
|
int *counter = p->second; |
116 |
|
|
(*counter)++; |
117 |
kusanagi |
1.7 |
oss.flush(); |
118 |
|
|
oss << " Counter." << type->GetName() << " = " << (*counter); |
119 |
|
|
logger->debug(oss.str().c_str()); |
120 |
kusanagi |
1.1 |
} else { |
121 |
kusanagi |
1.7 |
oss.flush(); |
122 |
|
|
oss << " No counter for packet type " << type->GetName(); |
123 |
|
|
logger->warn(oss.str().c_str()); |
124 |
kusanagi |
1.1 |
} |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
/** |
128 |
|
|
* Get the counter corresponding to a certain packet type. |
129 |
|
|
* @param type Event type to be incremented. |
130 |
|
|
* @return The counter of that packet type. For the current event type, |
131 |
|
|
* this is the actual event number. For all other types, this is the event |
132 |
|
|
* number of the last read event of that type. |
133 |
|
|
* @retval -1 if there was no event of this type. |
134 |
|
|
*/ |
135 |
|
|
int EventCounter::Get(PacketType const * type) const { |
136 |
|
|
const CounterMap::const_iterator p = CMap.find(type); |
137 |
|
|
if (p != CMap.end()) { |
138 |
|
|
const int *counter = p->second; |
139 |
|
|
return *counter; |
140 |
|
|
} else { |
141 |
kusanagi |
1.7 |
oss.flush(); |
142 |
|
|
oss << " No counter for packet type " << type->GetName(); |
143 |
|
|
logger->warn(oss.str().c_str()); |
144 |
kusanagi |
1.1 |
return -1; |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
/** |
149 |
|
|
* Get the counter of the next event corresponding to a certain packet type. |
150 |
|
|
* @param type Event type to be incremented. |
151 |
|
|
* @return The next counter of that packet type. |
152 |
|
|
* @retval -1 if there was no event of this type. |
153 |
|
|
*/ |
154 |
|
|
int EventCounter::Next(PacketType const * type) const { |
155 |
|
|
const CounterMap::const_iterator p = CMap.find(type); |
156 |
|
|
if (p != CMap.end()) { |
157 |
|
|
const int *counter = p->second; |
158 |
|
|
return *counter + 1; |
159 |
|
|
} else { |
160 |
kusanagi |
1.7 |
oss.flush(); |
161 |
|
|
oss << " No counter for packet type " << type->GetName(); |
162 |
|
|
logger->warn(oss.str().c_str()); |
163 |
kusanagi |
1.1 |
return -1; |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
/** |
168 |
|
|
* Get the all the counters |
169 |
kusanagi |
1.7 |
* @retval 0 if there was no event of this type. |
170 |
kusanagi |
1.1 |
*/ |
171 |
|
|
void EventCounter::PrintCounters() const { |
172 |
|
|
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
173 |
kusanagi |
1.7 |
oss.flush(); |
174 |
|
|
oss << " Counter." << (p->first)->GetName() << " = " << (*p->second); |
175 |
|
|
logger->warn(oss.str().c_str()); |
176 |
|
|
std::cout << " Counter." << (p->first)->GetName() << "\t = \t" << (*p->second) << "\n"; |
177 |
kusanagi |
1.1 |
} |
178 |
|
|
} |