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 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $ |
* $Id: EventCounter.cpp,v 1.7 2004/09/21 20:23:37 kusanagi Exp $ |
4 |
* $Author: kusanagi $ |
* $Author: kusanagi $ |
5 |
* |
* |
6 |
* Implementation of the EventCounter class. |
* Implementation of the EventCounter class. |
7 |
*/ |
*/ |
8 |
#include <log4cpp/Category.hh> |
#include <log4cxx/logger.h> |
9 |
|
#include <sstream> |
10 |
|
|
11 |
#include "EventCounter.h" |
#include "EventCounter.h" |
12 |
#include "PscuHeader.h" |
#include "PscuHeader.h" |
13 |
|
|
|
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.raw.EventCounter"); |
|
14 |
|
|
15 |
|
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter")); |
16 |
|
static std::stringstream oss; |
17 |
using namespace pamela; |
using namespace pamela; |
18 |
|
|
19 |
/** |
/** |
22 |
*/ |
*/ |
23 |
EventCounter::EventCounter(int run): |
EventCounter::EventCounter(int run): |
24 |
// New Packets. |
// New Packets. |
25 |
Pscu(-1), |
Pscu(0), |
26 |
Physics(-1), |
PhysEndRun(0), |
27 |
Forced_Pkt(-1), |
CalibCalPulse1(0), |
28 |
Calib_Trk1(-1), |
CalibCalPulse2(0), |
29 |
Calib_Trk2(-1), |
Physics(0), |
30 |
Calib_Cal(-1), |
CalibTrkBoth(0), |
31 |
Calib_Trd(-1), |
Calib_Trk1(0), |
32 |
Calib_Tof(-1), |
Calib_Trk2(0), |
33 |
Calib_S4(-1), |
Calib_Trd(0), |
34 |
Run_Header(-1), |
Calib_Tof(0), |
35 |
Run_Trailer(-1), |
Calib_S4(0), |
36 |
Alarm(-1), |
Calib_CalPed(0), |
37 |
Khb(-1), |
Calib_Ac(0), |
38 |
Log(-1), |
Run_Header(0), |
39 |
VarDump(-1), |
Run_Trailer(0), |
40 |
ArrDump(-1), |
CalibHeader(0), |
41 |
TabDump(-1), |
CalibTrailer(0), |
42 |
Tmtc(-1), |
InitHeader(0), |
43 |
Mcmd(-1), |
InitTrailer(0), |
44 |
HA_Header_E5(-1), |
EventTrk(0), |
45 |
|
TestTrk(0), |
46 |
|
TestTof(0), |
47 |
|
Log(0), |
48 |
|
VarDump(0), |
49 |
|
ArrDump(0), |
50 |
|
TabDump(0), |
51 |
|
Tmtc(0), |
52 |
|
Mcmd(0), |
53 |
|
ForcedFECmd(0), |
54 |
|
AcInit(0), |
55 |
|
CalInit(0), |
56 |
|
TrkInit(0), |
57 |
|
TofInit(0), |
58 |
|
TrgInit(0), |
59 |
|
CalAlarm(0), |
60 |
|
AcAlarm(0), |
61 |
|
TrkAlarm(0), |
62 |
|
TrgAlarm(0), |
63 |
|
TofAlarm(0), |
64 |
RunNumber(run) { |
RunNumber(run) { |
65 |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
66 |
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun)); |
67 |
CMap.insert(CounterMap::value_type(PacketType::ForcedPkt, &Forced_Pkt)); |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse1)); |
68 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &Calib_Trk1)); |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2)); |
69 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &Calib_Trk2)); |
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
70 |
CMap.insert(CounterMap::value_type(PacketType::CalibCal, &Calib_Cal)); |
CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth)); |
71 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd)); |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &Calib_Trk1)); |
72 |
CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof)); |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &Calib_Trk2)); |
73 |
CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4)); |
CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd)); |
74 |
CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header)); |
CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof)); |
75 |
CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer)); |
CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4)); |
76 |
CMap.insert(CounterMap::value_type(PacketType::Alarm, &Alarm)); |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &Calib_CalPed)); |
77 |
CMap.insert(CounterMap::value_type(PacketType::Khb, &Khb)); |
CMap.insert(CounterMap::value_type(PacketType::CalibAc, &Calib_Ac)); |
78 |
CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); |
CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header)); |
79 |
CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); |
CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer)); |
80 |
CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); |
CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader)); |
81 |
CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); |
CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer)); |
82 |
CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); |
CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader)); |
83 |
CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); |
CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer)); |
84 |
CMap.insert(CounterMap::value_type(PacketType::HA_Header_E5, &HA_Header_E5)); |
CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk)); |
85 |
|
CMap.insert(CounterMap::value_type(PacketType::TestTrk, &TestTrk)); |
86 |
|
CMap.insert(CounterMap::value_type(PacketType::TestTof, &TestTof)); |
87 |
|
CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); |
88 |
|
CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); |
89 |
|
CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); |
90 |
|
CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); |
91 |
|
CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); |
92 |
|
CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); |
93 |
|
CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd)); |
94 |
|
CMap.insert(CounterMap::value_type(PacketType::AcInit, &AcInit)); |
95 |
|
CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit)); |
96 |
|
CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit)); |
97 |
|
CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit)); |
98 |
|
CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit)); |
99 |
|
CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm)); |
100 |
|
CMap.insert(CounterMap::value_type(PacketType::AcAlarm, &AcAlarm)); |
101 |
|
CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm)); |
102 |
|
CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm)); |
103 |
|
CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm)); |
104 |
} |
} |
105 |
|
|
106 |
/** |
/** |
112 |
if (p != CMap.end()) { |
if (p != CMap.end()) { |
113 |
int *counter = p->second; |
int *counter = p->second; |
114 |
(*counter)++; |
(*counter)++; |
115 |
cat << log4cpp::Priority::INFO |
oss.flush(); |
116 |
<< " Counter." << type->GetName() << " = " << (*counter) |
oss << " Counter." << type->GetName() << " = " << (*counter); |
117 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
logger->debug(oss.str().c_str()); |
118 |
} else { |
} else { |
119 |
cat << log4cpp::Priority::INFO |
oss.flush(); |
120 |
<< " No counter for packet type " << type->GetName() |
oss << " No counter for packet type " << type->GetName(); |
121 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
logger->warn(oss.str().c_str()); |
122 |
} |
} |
123 |
} |
} |
124 |
|
|
136 |
const int *counter = p->second; |
const int *counter = p->second; |
137 |
return *counter; |
return *counter; |
138 |
} else { |
} else { |
139 |
cat << log4cpp::Priority::INFO |
oss.flush(); |
140 |
<< " No counter for packet type " << type->GetName() |
oss << " No counter for packet type " << type->GetName(); |
141 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
logger->warn(oss.str().c_str()); |
142 |
return -1; |
return -1; |
143 |
} |
} |
144 |
} |
} |
155 |
const int *counter = p->second; |
const int *counter = p->second; |
156 |
return *counter + 1; |
return *counter + 1; |
157 |
} else { |
} else { |
158 |
cat << log4cpp::Priority::WARN |
oss.flush(); |
159 |
<< " No counter for packet type " << type->GetName() |
oss << " No counter for packet type " << type->GetName(); |
160 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
logger->warn(oss.str().c_str()); |
161 |
return -1; |
return -1; |
162 |
} |
} |
163 |
} |
} |
164 |
|
|
165 |
/** |
/** |
166 |
* Get the all the counters |
* Get the all the counters |
167 |
* @retval -1 if there was no event of this type. |
* @retval 0 if there was no event of this type. |
168 |
*/ |
*/ |
169 |
void EventCounter::PrintCounters() const { |
void EventCounter::PrintCounters() const { |
170 |
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
171 |
cat << log4cpp::Priority::INFO << " Counter." << (p->first)->GetName() << " = " << (*p->second) |
oss.flush(); |
172 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
oss << " Counter." << (p->first)->GetName() << " = " << (*p->second); |
173 |
|
logger->warn(oss.str().c_str()); |
174 |
|
std::cout << " Counter." << (p->first)->GetName() << "\t = \t" << (*p->second) << "\n"; |
175 |
} |
} |
176 |
} |
} |