1 |
/** @file |
/** @file |
2 |
* $Source: /repository/event/EventCounter.cpp,v $ |
* $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/event/EventCounter.cpp,v $ |
3 |
* $Id: EventCounter.cpp,v 1.2 2008-02-07 18:17:23 messineo Exp $ |
* $Id: EventCounter.cpp,v 1.5 2010/02/11 09:02:15 mocchiut Exp $ |
4 |
* $Author: messineo $ |
* $Author: mocchiut $ |
5 |
* |
* |
6 |
* Implementation of the EventCounter class. |
* Implementation of the EventCounter class. |
7 |
*/ |
*/ |
15 |
//marco |
//marco |
16 |
////static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter")); |
////static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter")); |
17 |
static std::stringstream oss; |
static std::stringstream oss; |
18 |
|
|
19 |
using namespace pamela; |
using namespace pamela; |
20 |
|
|
21 |
|
|
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 |
|
// printf("val delete in clear\n"); |
36 |
|
val->Delete(); |
37 |
|
delete val; |
38 |
|
val = 0; |
39 |
|
}; |
40 |
|
fend = false; |
41 |
|
entries = 0; |
42 |
|
} |
43 |
|
|
44 |
|
void mappa::Set(){ |
45 |
|
// cout << " in mappa set" << endl; |
46 |
|
if (val){ |
47 |
|
val->Delete(); |
48 |
|
delete val; |
49 |
|
val = 0; |
50 |
|
} |
51 |
|
val = new TClonesArray("pamela::mapval",47); |
52 |
|
// cout << " out mappa set" << endl; |
53 |
|
} |
54 |
|
|
55 |
|
void mappa::Delete(Option_t *t){ |
56 |
|
// cout << " mappa del" << endl; |
57 |
|
if ( val ){ |
58 |
|
// printf("val delete in delete\n"); |
59 |
|
val->Delete(); |
60 |
|
delete val; |
61 |
|
val = 0; |
62 |
|
// delete val; |
63 |
|
}; |
64 |
|
delete this; |
65 |
|
} |
66 |
|
|
67 |
|
void mappa::Insert(TString nme, Int_t *valu){ |
68 |
|
// cout << " mappa insert " << nme.Data() << " valu " << *valu << endl; |
69 |
|
if ( !val ) this->Set(); |
70 |
|
TClonesArray &t = *val; |
71 |
|
new(t[entries]) mapval(nme,valu); |
72 |
|
entries++; |
73 |
|
} |
74 |
|
|
75 |
|
mapval::mapval(const mapval &t){ |
76 |
|
name = t.name; |
77 |
|
count = t.count; |
78 |
|
} |
79 |
|
|
80 |
|
mapval* mappa::Find(TString n){ |
81 |
|
Bool_t fo = false; |
82 |
|
fend = false; |
83 |
|
mapval *c = NULL; |
84 |
|
for (Int_t i=0; i < entries; i++){ |
85 |
|
c = (mapval*)val->At(i); |
86 |
|
if ( c && !strcmp(c->name.Data(),n.Data()) ){ |
87 |
|
fo = true; |
88 |
|
break; |
89 |
|
}; |
90 |
|
}; |
91 |
|
if ( !fo ) fend = true; |
92 |
|
return c; |
93 |
|
} |
94 |
|
|
95 |
/** |
/** |
96 |
* Create a new event counter for a certain run. |
* Create a new event counter for a certain run. |
97 |
* @param run Run number. |
* @param run Run number. |
98 |
*/ |
*/ |
99 |
EventCounter::EventCounter(int run): |
EventCounter::EventCounter(int run): |
100 |
// New Packets. |
// New Packets. |
101 |
|
RunNumber(run), |
102 |
Pscu(0), |
Pscu(0), |
103 |
PhysEndRun(0), |
PhysEndRun(0), |
104 |
CalibCalPulse1(0), |
CalibCalPulse1(0), |
107 |
CalibTrkBoth(0), |
CalibTrkBoth(0), |
108 |
CalibTrk1(0), |
CalibTrk1(0), |
109 |
CalibTrk2(0), |
CalibTrk2(0), |
110 |
|
CalibCal(0), |
111 |
CalibTof(0), |
CalibTof(0), |
112 |
CalibS4(0), |
CalibS4(0), |
113 |
CalibCalPed(0), |
CalibCalPed(0), |
114 |
Calib1_Ac1(0), |
Calib1_Ac1(0), |
|
Calib2_Ac1(0), |
|
115 |
Calib1_Ac2(0), |
Calib1_Ac2(0), |
116 |
|
Calib2_Ac1(0), |
117 |
Calib2_Ac2(0), |
Calib2_Ac2(0), |
|
CalibCal(0), |
|
118 |
RunHeader(0), |
RunHeader(0), |
119 |
RunTrailer(0), |
RunTrailer(0), |
120 |
CalibHeader(0), |
CalibHeader(0), |
145 |
S4Alarm(0), |
S4Alarm(0), |
146 |
Ac2Alarm(0), |
Ac2Alarm(0), |
147 |
TsbT(0), |
TsbT(0), |
148 |
TsbB(0), |
TsbB(0) { |
149 |
RunNumber(run) { |
CMap.Set(); |
150 |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
CMap.Insert(PacketType::Physics->GetName(), &Physics); |
151 |
CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun)); |
CMap.Insert(PacketType::Pscu->GetName(), &Pscu); |
152 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1)); |
CMap.Insert(PacketType::RunHeader->GetName(), &RunHeader); |
153 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2)); |
CMap.Insert(PacketType::RunTrailer->GetName(), &RunTrailer); |
154 |
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
CMap.Insert(PacketType::PhysEndRun->GetName(), &PhysEndRun); |
155 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth)); |
CMap.Insert(PacketType::InitHeader->GetName(), &InitHeader); |
156 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &CalibTrk1)); |
CMap.Insert(PacketType::InitTrailer->GetName(), &InitTrailer); |
157 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &CalibTrk2)); |
CMap.Insert(PacketType::Log->GetName(), &Log); |
158 |
CMap.insert(CounterMap::value_type(PacketType::CalibTof, &CalibTof)); |
CMap.Insert(PacketType::VarDump->GetName(), &VarDump); |
159 |
CMap.insert(CounterMap::value_type(PacketType::CalibS4, &CalibS4)); |
CMap.Insert(PacketType::ArrDump->GetName(), &ArrDump); |
160 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &CalibCalPed)); |
CMap.Insert(PacketType::TabDump->GetName(), &TabDump); |
161 |
CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1, &Calib1_Ac1)); |
CMap.Insert(PacketType::Tmtc->GetName(), &Tmtc); |
162 |
CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1, &Calib2_Ac1)); |
CMap.Insert(PacketType::Mcmd->GetName(), &Mcmd); |
163 |
CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2, &Calib1_Ac2)); |
CMap.Insert(PacketType::TsbT->GetName(), &TsbT); |
164 |
CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2, &Calib2_Ac2)); |
CMap.Insert(PacketType::TsbB->GetName(), &TsbB); |
165 |
CMap.insert(CounterMap::value_type(PacketType::CalibCal, &CalibCal)); |
CMap.Insert(PacketType::CalibHeader->GetName(), &CalibHeader); |
166 |
CMap.insert(CounterMap::value_type(PacketType::RunHeader, &RunHeader)); |
CMap.Insert(PacketType::CalibTrailer->GetName(), &CalibTrailer); |
167 |
CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &RunTrailer)); |
CMap.Insert(PacketType::CalibCalPulse1->GetName(), &CalibCalPulse1); |
168 |
CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader)); |
CMap.Insert(PacketType::CalibCalPulse2->GetName(), &CalibCalPulse2); |
169 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer)); |
CMap.Insert(PacketType::CalibTrkBoth->GetName(), &CalibTrkBoth); |
170 |
CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader)); |
CMap.Insert(PacketType::CalibTrk1->GetName(), &CalibTrk1); |
171 |
CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer)); |
CMap.Insert(PacketType::CalibTrk2->GetName(), &CalibTrk2); |
172 |
CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk)); |
CMap.Insert(PacketType::CalibS4->GetName(), &CalibS4); |
173 |
CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); |
CMap.Insert(PacketType::CalibCalPed->GetName(), &CalibCalPed); |
174 |
CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); |
CMap.Insert(PacketType::Calib1_Ac1->GetName(), &Calib1_Ac1); |
175 |
CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); |
CMap.Insert(PacketType::Calib2_Ac1->GetName(), &Calib2_Ac1); |
176 |
CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); |
CMap.Insert(PacketType::Calib1_Ac2->GetName(), &Calib1_Ac2); |
177 |
CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); |
CMap.Insert(PacketType::Calib2_Ac2->GetName(), &Calib2_Ac2); |
178 |
CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); |
CMap.Insert(PacketType::CalibCal->GetName(), &CalibCal); |
179 |
CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd)); |
CMap.Insert(PacketType::EventTrk->GetName(), &EventTrk); |
180 |
CMap.insert(CounterMap::value_type(PacketType::Ac1Init, &Ac1Init)); |
CMap.Insert(PacketType::Ac1Init->GetName(), &Ac1Init); |
181 |
CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit)); |
CMap.Insert(PacketType::CalInit->GetName(), &CalInit); |
182 |
CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit)); |
CMap.Insert(PacketType::TrkInit->GetName(), &TrkInit); |
183 |
CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit)); |
CMap.Insert(PacketType::TofInit->GetName(), &TofInit); |
184 |
CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit)); |
CMap.Insert(PacketType::TrgInit->GetName(), &TrgInit); |
185 |
CMap.insert(CounterMap::value_type(PacketType::NdInit, &NdInit)); |
CMap.Insert(PacketType::NdInit->GetName(), &NdInit); |
186 |
CMap.insert(CounterMap::value_type(PacketType::S4Init, &S4Init)); |
CMap.Insert(PacketType::S4Init->GetName(), &S4Init); |
187 |
CMap.insert(CounterMap::value_type(PacketType::Ac2Init, &Ac2Init)); |
CMap.Insert(PacketType::Ac2Init->GetName(), &Ac2Init); |
188 |
CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm)); |
CMap.Insert(PacketType::CalAlarm->GetName(), &CalAlarm); |
189 |
CMap.insert(CounterMap::value_type(PacketType::Ac1Alarm, &Ac1Alarm)); |
CMap.Insert(PacketType::Ac1Alarm->GetName(), &Ac1Alarm); |
190 |
CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm)); |
CMap.Insert(PacketType::TrkAlarm->GetName(), &TrkAlarm); |
191 |
CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm)); |
CMap.Insert(PacketType::TrgAlarm->GetName(), &TrgAlarm); |
192 |
CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm)); |
CMap.Insert(PacketType::TofAlarm->GetName(), &TofAlarm); |
193 |
CMap.insert(CounterMap::value_type(PacketType::S4Alarm, &S4Alarm)); |
CMap.Insert(PacketType::S4Alarm->GetName(), &S4Alarm); |
194 |
CMap.insert(CounterMap::value_type(PacketType::Ac2Alarm, &Ac2Alarm)); |
CMap.Insert(PacketType::Ac2Alarm->GetName(), &Ac2Alarm); |
195 |
CMap.insert(CounterMap::value_type(PacketType::TsbT, &TsbT)); |
CMap.Insert(PacketType::ForcedFECmd->GetName(), &ForcedFECmd); |
196 |
CMap.insert(CounterMap::value_type(PacketType::TsbB, &TsbB)); |
CMap.Insert(PacketType::CalibTof->GetName(), &CalibTof); |
197 |
|
|
198 |
} |
} |
199 |
|
|
200 |
/** |
/** |
202 |
* @param type Event type to be incremented. |
* @param type Event type to be incremented. |
203 |
*/ |
*/ |
204 |
void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){ |
void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){ |
205 |
CounterMap::iterator p = CMap.find(type); |
// cout << " increment "<< endl; |
206 |
if (p != CMap.end()) { |
mapval *p = CMap.Find(type->GetName()); |
207 |
|
if ( !CMap.end()) { |
208 |
int *counter = p->second; |
// cout << " A Counter." << type->GetName() << " = " << (*(&p->count)) << endl; |
209 |
(*counter)++; |
(*(p->count))++; |
210 |
|
//(*(&p->count))++; |
211 |
|
// cout << " B Counter." << type->GetName() << " = " << (*(&p->count)) << endl; |
212 |
|
} else { |
213 |
oss.str(""); |
oss.str(""); |
214 |
oss << " Counter." << type->GetName() << " = " << (*counter); |
oss << "\n No counter of type " << type->GetName(); |
|
//marco |
|
|
//std::cout<<oss.str()<<std::endl; //marco |
|
|
//// logger->info(oss.str().c_str()); |
|
|
} else { |
|
|
|
|
|
oss.str(""); |
|
|
oss << "\n No counter of type " << type->GetName().c_str(); |
|
|
//std::cout<<oss.str()<<std::endl; //marco |
|
|
|
|
215 |
throw NotExistingCounterException(oss.str().c_str()); |
throw NotExistingCounterException(oss.str().c_str()); |
216 |
} |
} |
217 |
} |
} |
224 |
* number of the last read event of that type. |
* number of the last read event of that type. |
225 |
* @retval -1 if there was no event of this type. |
* @retval -1 if there was no event of this type. |
226 |
*/ |
*/ |
227 |
int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){ |
int EventCounter::Get(PacketType const * type) throw (NotExistingCounterException){ |
228 |
const CounterMap::const_iterator p = CMap.find(type); |
// cout << " get "<< endl; |
229 |
if (p != CMap.end()) { |
mapval *p = CMap.Find(type->GetName()); |
230 |
const int *counter = p->second; |
if ( !CMap.end()) { |
231 |
return *counter; |
// cout << " C Counter." << type->GetName() << " = " << (*(p->count)) << endl; |
232 |
|
return ((*(p->count))); |
233 |
|
// return ((*(&p->count))); |
234 |
} else { |
} else { |
235 |
throw NotExistingCounterException(type->GetName().c_str()); |
throw NotExistingCounterException(type->GetName()); |
236 |
return -1; |
return -1; |
237 |
} |
} |
238 |
} |
} |
243 |
* @return The next counter of that packet type. |
* @return The next counter of that packet type. |
244 |
* @retval -1 if there was no event of this type. |
* @retval -1 if there was no event of this type. |
245 |
*/ |
*/ |
246 |
int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){ |
int EventCounter::Next(PacketType const * type) throw (NotExistingCounterException){ |
247 |
const CounterMap::const_iterator p = CMap.find(type); |
// cout << " next "<< endl; |
248 |
if (p != CMap.end()) { |
mapval *p = CMap.Find(type->GetName()); |
249 |
const int *counter = p->second; |
if ( !CMap.end()) { |
250 |
return *counter + 1; |
// cout << " NEXT Counter." << type->GetName() << " = " << (*(p->count))+1 << endl; |
251 |
|
return ((*(p->count)) + 1); |
252 |
|
// return ((*(&p->count)) + 1); |
253 |
|
// return ((&(p->count)) + 1); |
254 |
} else { |
} else { |
255 |
throw NotExistingCounterException(type->GetName().c_str()); |
throw NotExistingCounterException(type->GetName()); |
256 |
return -1; |
return -1; |
257 |
} |
} |
258 |
} |
} |
261 |
* Get the all the counters |
* Get the all the counters |
262 |
* @retval 0 if there was no event of this type. |
* @retval 0 if there was no event of this type. |
263 |
*/ |
*/ |
264 |
void EventCounter::PrintCounters() const { |
void EventCounter::PrintCounters(){ |
265 |
std::cout<<"PrintCounters:"<<std::endl; |
std::cout<<"PrintCounters:"<<std::endl; |
266 |
|
// |
267 |
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
for (Int_t i=0; i < CMap.GetEntries(); i++){ |
268 |
oss.str(""); |
mapval *p = CMap.Get(i); |
269 |
oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second); |
oss.str(""); |
270 |
std::cout<<oss.str()<<std::endl; |
oss << " Counter." << (p->name).Data() << " \t \t " << (*(p->count)); |
271 |
//marco |
// oss << " Counter." << (p->name).Data() << " \t \t " << (*(&p->count)); |
272 |
//logger->info(oss.str().c_str()); |
// oss << " Counter." << (p->name).Data() << " \t \t " << (&(p->count)); |
273 |
} |
std::cout<<oss.str()<<std::endl; |
274 |
|
}; |
275 |
} |
} |
276 |
|
|
277 |
|
ClassImp(mapval) |
278 |
|
ClassImp(mappa) |
279 |
|
ClassImp(EventCounter) |