/[PAMELA software]/yoda/event/EventCounter.cpp
ViewVC logotype

Contents of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.3 - (show annotations) (download)
Thu Dec 9 08:47:42 2004 UTC (20 years, 2 months ago) by kusanagi
Branch: MAIN
Changes since 2.2: +6 -3 lines
Fixed bug of Stack overflow in case of Log CRCError
Added S4Init & S4Alarm packets

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

  ViewVC Help
Powered by ViewVC 1.1.23