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.5 |
* $Id: EventCounter.cpp,v 1.4 2009/08/04 13:58:16 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 |
mocchiut |
1.4 |
|
19 |
mocchiut |
1.1 |
using namespace pamela; |
20 |
|
|
|
21 |
mocchiut |
1.4 |
|
22 |
|
|
mapval::mapval(): count(0), name(""){ } |
23 |
|
|
|
24 |
|
|
mapval::mapval(TString n, Int_t *i): count(i), name(n){ } |
25 |
|
|
|
26 |
|
|
mappa::mappa(){ |
27 |
|
|
val = 0; |
28 |
|
|
this->Clear(); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
void mappa::Clear(Option_t *t){ |
32 |
|
|
// cout << " mappa clear" << endl; |
33 |
|
|
t=""; |
34 |
|
|
if ( val ){ |
35 |
|
|
val->Delete(); |
36 |
|
|
val = 0; |
37 |
|
|
}; |
38 |
|
|
fend = false; |
39 |
|
|
entries = 0; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
void mappa::Set(){ |
43 |
|
|
// cout << " in mappa set" << endl; |
44 |
mocchiut |
1.5 |
if (val) delete val; |
45 |
|
|
val = new TClonesArray("pamela::mapval",47); |
46 |
mocchiut |
1.4 |
// cout << " out mappa set" << endl; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
void mappa::Delete(Option_t *t){ |
50 |
|
|
// cout << " mappa del" << endl; |
51 |
|
|
if ( val ){ |
52 |
|
|
val->Delete(); |
53 |
|
|
val = 0; |
54 |
|
|
// delete val; |
55 |
|
|
}; |
56 |
|
|
delete this; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
void mappa::Insert(TString nme, Int_t *valu){ |
60 |
|
|
// cout << " mappa insert " << nme.Data() << " valu " << *valu << endl; |
61 |
|
|
if ( !val ) this->Set(); |
62 |
|
|
TClonesArray &t = *val; |
63 |
|
|
new(t[entries]) mapval(nme,valu); |
64 |
|
|
entries++; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
mapval::mapval(const mapval &t){ |
68 |
|
|
name = t.name; |
69 |
|
|
count = t.count; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
mapval* mappa::Find(TString n){ |
73 |
|
|
Bool_t fo = false; |
74 |
|
|
fend = false; |
75 |
|
|
mapval *c = NULL; |
76 |
|
|
for (Int_t i=0; i < entries; i++){ |
77 |
|
|
c = (mapval*)val->At(i); |
78 |
|
|
if ( c && !strcmp(c->name.Data(),n.Data()) ){ |
79 |
|
|
fo = true; |
80 |
|
|
break; |
81 |
|
|
}; |
82 |
|
|
}; |
83 |
|
|
if ( !fo ) fend = true; |
84 |
|
|
return c; |
85 |
|
|
} |
86 |
|
|
|
87 |
mocchiut |
1.1 |
/** |
88 |
|
|
* Create a new event counter for a certain run. |
89 |
|
|
* @param run Run number. |
90 |
|
|
*/ |
91 |
|
|
EventCounter::EventCounter(int run): |
92 |
|
|
// New Packets. |
93 |
mocchiut |
1.3 |
RunNumber(run), |
94 |
mocchiut |
1.1 |
Pscu(0), |
95 |
|
|
PhysEndRun(0), |
96 |
|
|
CalibCalPulse1(0), |
97 |
|
|
CalibCalPulse2(0), |
98 |
|
|
Physics(0), |
99 |
|
|
CalibTrkBoth(0), |
100 |
|
|
CalibTrk1(0), |
101 |
|
|
CalibTrk2(0), |
102 |
mocchiut |
1.2 |
CalibCal(0), |
103 |
mocchiut |
1.1 |
CalibTof(0), |
104 |
|
|
CalibS4(0), |
105 |
|
|
CalibCalPed(0), |
106 |
|
|
Calib1_Ac1(0), |
107 |
mocchiut |
1.2 |
Calib1_Ac2(0), |
108 |
mocchiut |
1.1 |
Calib2_Ac1(0), |
109 |
|
|
Calib2_Ac2(0), |
110 |
|
|
RunHeader(0), |
111 |
|
|
RunTrailer(0), |
112 |
|
|
CalibHeader(0), |
113 |
|
|
CalibTrailer(0), |
114 |
|
|
InitHeader(0), |
115 |
|
|
InitTrailer(0), |
116 |
|
|
EventTrk(0), |
117 |
|
|
Log(0), |
118 |
|
|
VarDump(0), |
119 |
|
|
ArrDump(0), |
120 |
|
|
TabDump(0), |
121 |
|
|
Tmtc(0), |
122 |
|
|
Mcmd(0), |
123 |
|
|
ForcedFECmd(0), |
124 |
|
|
Ac1Init(0), |
125 |
|
|
CalInit(0), |
126 |
|
|
TrkInit(0), |
127 |
|
|
TofInit(0), |
128 |
|
|
TrgInit(0), |
129 |
|
|
NdInit(0), |
130 |
|
|
S4Init(0), |
131 |
|
|
Ac2Init(0), |
132 |
|
|
CalAlarm(0), |
133 |
|
|
Ac1Alarm(0), |
134 |
|
|
TrkAlarm(0), |
135 |
|
|
TrgAlarm(0), |
136 |
|
|
TofAlarm(0), |
137 |
|
|
S4Alarm(0), |
138 |
|
|
Ac2Alarm(0), |
139 |
|
|
TsbT(0), |
140 |
mocchiut |
1.3 |
TsbB(0) { |
141 |
mocchiut |
1.4 |
CMap.Set(); |
142 |
|
|
CMap.Insert(PacketType::Physics->GetName(), &Physics); |
143 |
|
|
CMap.Insert(PacketType::Pscu->GetName(), &Pscu); |
144 |
|
|
CMap.Insert(PacketType::RunHeader->GetName(), &RunHeader); |
145 |
|
|
CMap.Insert(PacketType::RunTrailer->GetName(), &RunTrailer); |
146 |
|
|
CMap.Insert(PacketType::PhysEndRun->GetName(), &PhysEndRun); |
147 |
|
|
CMap.Insert(PacketType::InitHeader->GetName(), &InitHeader); |
148 |
|
|
CMap.Insert(PacketType::InitTrailer->GetName(), &InitTrailer); |
149 |
|
|
CMap.Insert(PacketType::Log->GetName(), &Log); |
150 |
|
|
CMap.Insert(PacketType::VarDump->GetName(), &VarDump); |
151 |
|
|
CMap.Insert(PacketType::ArrDump->GetName(), &ArrDump); |
152 |
|
|
CMap.Insert(PacketType::TabDump->GetName(), &TabDump); |
153 |
|
|
CMap.Insert(PacketType::Tmtc->GetName(), &Tmtc); |
154 |
|
|
CMap.Insert(PacketType::Mcmd->GetName(), &Mcmd); |
155 |
|
|
CMap.Insert(PacketType::TsbT->GetName(), &TsbT); |
156 |
|
|
CMap.Insert(PacketType::TsbB->GetName(), &TsbB); |
157 |
|
|
CMap.Insert(PacketType::CalibHeader->GetName(), &CalibHeader); |
158 |
|
|
CMap.Insert(PacketType::CalibTrailer->GetName(), &CalibTrailer); |
159 |
|
|
CMap.Insert(PacketType::CalibCalPulse1->GetName(), &CalibCalPulse1); |
160 |
|
|
CMap.Insert(PacketType::CalibCalPulse2->GetName(), &CalibCalPulse2); |
161 |
|
|
CMap.Insert(PacketType::CalibTrkBoth->GetName(), &CalibTrkBoth); |
162 |
|
|
CMap.Insert(PacketType::CalibTrk1->GetName(), &CalibTrk1); |
163 |
|
|
CMap.Insert(PacketType::CalibTrk2->GetName(), &CalibTrk2); |
164 |
|
|
CMap.Insert(PacketType::CalibS4->GetName(), &CalibS4); |
165 |
|
|
CMap.Insert(PacketType::CalibCalPed->GetName(), &CalibCalPed); |
166 |
|
|
CMap.Insert(PacketType::Calib1_Ac1->GetName(), &Calib1_Ac1); |
167 |
|
|
CMap.Insert(PacketType::Calib2_Ac1->GetName(), &Calib2_Ac1); |
168 |
|
|
CMap.Insert(PacketType::Calib1_Ac2->GetName(), &Calib1_Ac2); |
169 |
|
|
CMap.Insert(PacketType::Calib2_Ac2->GetName(), &Calib2_Ac2); |
170 |
|
|
CMap.Insert(PacketType::CalibCal->GetName(), &CalibCal); |
171 |
|
|
CMap.Insert(PacketType::EventTrk->GetName(), &EventTrk); |
172 |
|
|
CMap.Insert(PacketType::Ac1Init->GetName(), &Ac1Init); |
173 |
|
|
CMap.Insert(PacketType::CalInit->GetName(), &CalInit); |
174 |
|
|
CMap.Insert(PacketType::TrkInit->GetName(), &TrkInit); |
175 |
|
|
CMap.Insert(PacketType::TofInit->GetName(), &TofInit); |
176 |
|
|
CMap.Insert(PacketType::TrgInit->GetName(), &TrgInit); |
177 |
|
|
CMap.Insert(PacketType::NdInit->GetName(), &NdInit); |
178 |
|
|
CMap.Insert(PacketType::S4Init->GetName(), &S4Init); |
179 |
|
|
CMap.Insert(PacketType::Ac2Init->GetName(), &Ac2Init); |
180 |
|
|
CMap.Insert(PacketType::CalAlarm->GetName(), &CalAlarm); |
181 |
|
|
CMap.Insert(PacketType::Ac1Alarm->GetName(), &Ac1Alarm); |
182 |
|
|
CMap.Insert(PacketType::TrkAlarm->GetName(), &TrkAlarm); |
183 |
|
|
CMap.Insert(PacketType::TrgAlarm->GetName(), &TrgAlarm); |
184 |
|
|
CMap.Insert(PacketType::TofAlarm->GetName(), &TofAlarm); |
185 |
|
|
CMap.Insert(PacketType::S4Alarm->GetName(), &S4Alarm); |
186 |
|
|
CMap.Insert(PacketType::Ac2Alarm->GetName(), &Ac2Alarm); |
187 |
|
|
CMap.Insert(PacketType::ForcedFECmd->GetName(), &ForcedFECmd); |
188 |
|
|
CMap.Insert(PacketType::CalibTof->GetName(), &CalibTof); |
189 |
|
|
|
190 |
mocchiut |
1.1 |
} |
191 |
|
|
|
192 |
|
|
/** |
193 |
|
|
* Increment the event counter for a certain packet. |
194 |
|
|
* @param type Event type to be incremented. |
195 |
|
|
*/ |
196 |
|
|
void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){ |
197 |
mocchiut |
1.4 |
// cout << " increment "<< endl; |
198 |
|
|
mapval *p = CMap.Find(type->GetName()); |
199 |
|
|
if ( !CMap.end()) { |
200 |
|
|
// cout << " A Counter." << type->GetName() << " = " << (*(&p->count)) << endl; |
201 |
|
|
(*(p->count))++; |
202 |
|
|
//(*(&p->count))++; |
203 |
|
|
// cout << " B Counter." << type->GetName() << " = " << (*(&p->count)) << endl; |
204 |
|
|
} else { |
205 |
mocchiut |
1.1 |
oss.str(""); |
206 |
mocchiut |
1.2 |
oss << "\n No counter of type " << type->GetName(); |
207 |
mocchiut |
1.1 |
throw NotExistingCounterException(oss.str().c_str()); |
208 |
|
|
} |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
/** |
212 |
|
|
* Get the counter corresponding to a certain packet type. |
213 |
|
|
* @param type Event type to be incremented. |
214 |
|
|
* @return The counter of that packet type. For the current event type, |
215 |
|
|
* this is the actual event number. For all other types, this is the event |
216 |
|
|
* number of the last read event of that type. |
217 |
|
|
* @retval -1 if there was no event of this type. |
218 |
|
|
*/ |
219 |
mocchiut |
1.4 |
int EventCounter::Get(PacketType const * type) throw (NotExistingCounterException){ |
220 |
|
|
// cout << " get "<< endl; |
221 |
|
|
mapval *p = CMap.Find(type->GetName()); |
222 |
|
|
if ( !CMap.end()) { |
223 |
|
|
// cout << " C Counter." << type->GetName() << " = " << (*(p->count)) << endl; |
224 |
|
|
return ((*(p->count))); |
225 |
|
|
// return ((*(&p->count))); |
226 |
mocchiut |
1.1 |
} else { |
227 |
mocchiut |
1.2 |
throw NotExistingCounterException(type->GetName()); |
228 |
mocchiut |
1.1 |
return -1; |
229 |
|
|
} |
230 |
|
|
} |
231 |
|
|
|
232 |
|
|
/** |
233 |
|
|
* Get the counter of the next event corresponding to a certain packet type. |
234 |
|
|
* @param type Event type to be incremented. |
235 |
|
|
* @return The next counter of that packet type. |
236 |
|
|
* @retval -1 if there was no event of this type. |
237 |
|
|
*/ |
238 |
mocchiut |
1.4 |
int EventCounter::Next(PacketType const * type) throw (NotExistingCounterException){ |
239 |
|
|
// cout << " next "<< endl; |
240 |
|
|
mapval *p = CMap.Find(type->GetName()); |
241 |
|
|
if ( !CMap.end()) { |
242 |
|
|
// cout << " NEXT Counter." << type->GetName() << " = " << (*(p->count))+1 << endl; |
243 |
|
|
return ((*(p->count)) + 1); |
244 |
|
|
// return ((*(&p->count)) + 1); |
245 |
|
|
// return ((&(p->count)) + 1); |
246 |
mocchiut |
1.1 |
} else { |
247 |
mocchiut |
1.2 |
throw NotExistingCounterException(type->GetName()); |
248 |
mocchiut |
1.1 |
return -1; |
249 |
|
|
} |
250 |
|
|
} |
251 |
|
|
|
252 |
|
|
/** |
253 |
|
|
* Get the all the counters |
254 |
|
|
* @retval 0 if there was no event of this type. |
255 |
|
|
*/ |
256 |
mocchiut |
1.4 |
void EventCounter::PrintCounters(){ |
257 |
|
|
std::cout<<"PrintCounters:"<<std::endl; |
258 |
|
|
// |
259 |
|
|
for (Int_t i=0; i < CMap.GetEntries(); i++){ |
260 |
|
|
mapval *p = CMap.Get(i); |
261 |
|
|
oss.str(""); |
262 |
|
|
oss << " Counter." << (p->name).Data() << " \t \t " << (*(p->count)); |
263 |
|
|
// oss << " Counter." << (p->name).Data() << " \t \t " << (*(&p->count)); |
264 |
|
|
// oss << " Counter." << (p->name).Data() << " \t \t " << (&(p->count)); |
265 |
|
|
std::cout<<oss.str()<<std::endl; |
266 |
|
|
}; |
267 |
mocchiut |
1.1 |
} |
268 |
mocchiut |
1.2 |
|
269 |
mocchiut |
1.4 |
ClassImp(mapval) |
270 |
|
|
ClassImp(mappa) |
271 |
mocchiut |
1.2 |
ClassImp(EventCounter) |