1 |
mocchiut |
1.1 |
/** @file |
2 |
mocchiut |
1.2 |
* $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/event/EventCounter.cpp,v $ |
3 |
mocchiut |
1.3 |
* $Id: EventCounter.cpp,v 1.2 2009/07/24 13:53:49 mocchiut Exp $ |
4 |
mocchiut |
1.2 |
* $Author: mocchiut $ |
5 |
mocchiut |
1.1 |
* |
6 |
|
|
* Implementation of the EventCounter class. |
7 |
|
|
*/ |
8 |
|
|
////#include <log4cxx/logger.h> |
9 |
|
|
#include <sstream> |
10 |
|
|
#include <iostream>//mmmm |
11 |
|
|
|
12 |
|
|
#include "EventCounter.h" |
13 |
|
|
#include "PscuHeader.h" |
14 |
|
|
|
15 |
|
|
//marco |
16 |
|
|
////static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter")); |
17 |
|
|
static std::stringstream oss; |
18 |
|
|
using namespace pamela; |
19 |
|
|
|
20 |
|
|
/** |
21 |
|
|
* Create a new event counter for a certain run. |
22 |
|
|
* @param run Run number. |
23 |
|
|
*/ |
24 |
|
|
EventCounter::EventCounter(int run): |
25 |
|
|
// New Packets. |
26 |
mocchiut |
1.3 |
RunNumber(run), |
27 |
mocchiut |
1.1 |
Pscu(0), |
28 |
|
|
PhysEndRun(0), |
29 |
|
|
CalibCalPulse1(0), |
30 |
|
|
CalibCalPulse2(0), |
31 |
|
|
Physics(0), |
32 |
|
|
CalibTrkBoth(0), |
33 |
|
|
CalibTrk1(0), |
34 |
|
|
CalibTrk2(0), |
35 |
mocchiut |
1.2 |
CalibCal(0), |
36 |
mocchiut |
1.1 |
CalibTof(0), |
37 |
|
|
CalibS4(0), |
38 |
|
|
CalibCalPed(0), |
39 |
|
|
Calib1_Ac1(0), |
40 |
mocchiut |
1.2 |
Calib1_Ac2(0), |
41 |
mocchiut |
1.1 |
Calib2_Ac1(0), |
42 |
|
|
Calib2_Ac2(0), |
43 |
|
|
RunHeader(0), |
44 |
|
|
RunTrailer(0), |
45 |
|
|
CalibHeader(0), |
46 |
|
|
CalibTrailer(0), |
47 |
|
|
InitHeader(0), |
48 |
|
|
InitTrailer(0), |
49 |
|
|
EventTrk(0), |
50 |
|
|
Log(0), |
51 |
|
|
VarDump(0), |
52 |
|
|
ArrDump(0), |
53 |
|
|
TabDump(0), |
54 |
|
|
Tmtc(0), |
55 |
|
|
Mcmd(0), |
56 |
|
|
ForcedFECmd(0), |
57 |
|
|
Ac1Init(0), |
58 |
|
|
CalInit(0), |
59 |
|
|
TrkInit(0), |
60 |
|
|
TofInit(0), |
61 |
|
|
TrgInit(0), |
62 |
|
|
NdInit(0), |
63 |
|
|
S4Init(0), |
64 |
|
|
Ac2Init(0), |
65 |
|
|
CalAlarm(0), |
66 |
|
|
Ac1Alarm(0), |
67 |
|
|
TrkAlarm(0), |
68 |
|
|
TrgAlarm(0), |
69 |
|
|
TofAlarm(0), |
70 |
|
|
S4Alarm(0), |
71 |
|
|
Ac2Alarm(0), |
72 |
|
|
TsbT(0), |
73 |
mocchiut |
1.3 |
TsbB(0) { |
74 |
mocchiut |
1.1 |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
75 |
|
|
CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun)); |
76 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1)); |
77 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2)); |
78 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
79 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth)); |
80 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &CalibTrk1)); |
81 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &CalibTrk2)); |
82 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTof, &CalibTof)); |
83 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibS4, &CalibS4)); |
84 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &CalibCalPed)); |
85 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1, &Calib1_Ac1)); |
86 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1, &Calib2_Ac1)); |
87 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2, &Calib1_Ac2)); |
88 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2, &Calib2_Ac2)); |
89 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibCal, &CalibCal)); |
90 |
|
|
CMap.insert(CounterMap::value_type(PacketType::RunHeader, &RunHeader)); |
91 |
|
|
CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &RunTrailer)); |
92 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader)); |
93 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer)); |
94 |
|
|
CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader)); |
95 |
|
|
CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer)); |
96 |
|
|
CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk)); |
97 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); |
98 |
|
|
CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); |
99 |
|
|
CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); |
100 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); |
101 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); |
102 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); |
103 |
|
|
CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd)); |
104 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Ac1Init, &Ac1Init)); |
105 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit)); |
106 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit)); |
107 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit)); |
108 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit)); |
109 |
|
|
CMap.insert(CounterMap::value_type(PacketType::NdInit, &NdInit)); |
110 |
|
|
CMap.insert(CounterMap::value_type(PacketType::S4Init, &S4Init)); |
111 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Ac2Init, &Ac2Init)); |
112 |
|
|
CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm)); |
113 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Ac1Alarm, &Ac1Alarm)); |
114 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm)); |
115 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm)); |
116 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm)); |
117 |
|
|
CMap.insert(CounterMap::value_type(PacketType::S4Alarm, &S4Alarm)); |
118 |
|
|
CMap.insert(CounterMap::value_type(PacketType::Ac2Alarm, &Ac2Alarm)); |
119 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TsbT, &TsbT)); |
120 |
|
|
CMap.insert(CounterMap::value_type(PacketType::TsbB, &TsbB)); |
121 |
|
|
|
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
/** |
125 |
|
|
* Increment the event counter for a certain packet. |
126 |
|
|
* @param type Event type to be incremented. |
127 |
|
|
*/ |
128 |
|
|
void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){ |
129 |
|
|
CounterMap::iterator p = CMap.find(type); |
130 |
|
|
if (p != CMap.end()) { |
131 |
|
|
|
132 |
|
|
int *counter = p->second; |
133 |
|
|
(*counter)++; |
134 |
|
|
oss.str(""); |
135 |
|
|
oss << " Counter." << type->GetName() << " = " << (*counter); |
136 |
|
|
//marco |
137 |
|
|
//std::cout<<oss.str()<<std::endl; //marco |
138 |
|
|
//// logger->info(oss.str().c_str()); |
139 |
|
|
} else { |
140 |
|
|
|
141 |
|
|
oss.str(""); |
142 |
mocchiut |
1.2 |
// oss << "\n No counter of type " << type->GetName().c_str(); |
143 |
|
|
oss << "\n No counter of type " << type->GetName(); |
144 |
mocchiut |
1.1 |
//std::cout<<oss.str()<<std::endl; //marco |
145 |
|
|
|
146 |
|
|
throw NotExistingCounterException(oss.str().c_str()); |
147 |
|
|
} |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/** |
151 |
|
|
* Get the counter corresponding to a certain packet type. |
152 |
|
|
* @param type Event type to be incremented. |
153 |
|
|
* @return The counter of that packet type. For the current event type, |
154 |
|
|
* this is the actual event number. For all other types, this is the event |
155 |
|
|
* number of the last read event of that type. |
156 |
|
|
* @retval -1 if there was no event of this type. |
157 |
|
|
*/ |
158 |
|
|
int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){ |
159 |
|
|
const CounterMap::const_iterator p = CMap.find(type); |
160 |
|
|
if (p != CMap.end()) { |
161 |
|
|
const int *counter = p->second; |
162 |
|
|
return *counter; |
163 |
|
|
} else { |
164 |
mocchiut |
1.2 |
// throw NotExistingCounterException(type->GetName().c_str()); |
165 |
|
|
throw NotExistingCounterException(type->GetName()); |
166 |
mocchiut |
1.1 |
return -1; |
167 |
|
|
} |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
/** |
171 |
|
|
* Get the counter of the next event corresponding to a certain packet type. |
172 |
|
|
* @param type Event type to be incremented. |
173 |
|
|
* @return The next counter of that packet type. |
174 |
|
|
* @retval -1 if there was no event of this type. |
175 |
|
|
*/ |
176 |
|
|
int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){ |
177 |
|
|
const CounterMap::const_iterator p = CMap.find(type); |
178 |
|
|
if (p != CMap.end()) { |
179 |
|
|
const int *counter = p->second; |
180 |
|
|
return *counter + 1; |
181 |
|
|
} else { |
182 |
mocchiut |
1.2 |
// throw NotExistingCounterException(type->GetName().c_str()); |
183 |
|
|
throw NotExistingCounterException(type->GetName()); |
184 |
mocchiut |
1.1 |
return -1; |
185 |
|
|
} |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
/** |
189 |
|
|
* Get the all the counters |
190 |
|
|
* @retval 0 if there was no event of this type. |
191 |
|
|
*/ |
192 |
|
|
void EventCounter::PrintCounters() const { |
193 |
|
|
std::cout<<"PrintCounters:"<<std::endl; |
194 |
|
|
|
195 |
|
|
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
196 |
|
|
oss.str(""); |
197 |
|
|
oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second); |
198 |
|
|
std::cout<<oss.str()<<std::endl; |
199 |
|
|
//marco |
200 |
|
|
//logger->info(oss.str().c_str()); |
201 |
|
|
} |
202 |
|
|
} |
203 |
mocchiut |
1.2 |
|
204 |
|
|
ClassImp(EventCounter) |