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.3 2009/07/29 15:47:19 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 |
|
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 |
|
if (!val) val = new TClonesArray("pamela::mapval",47); |
45 |
|
// cout << " out mappa set" << endl; |
46 |
|
} |
47 |
|
|
48 |
|
void mappa::Delete(Option_t *t){ |
49 |
|
// cout << " mappa del" << endl; |
50 |
|
if ( val ){ |
51 |
|
val->Delete(); |
52 |
|
val = 0; |
53 |
|
// delete val; |
54 |
|
}; |
55 |
|
delete this; |
56 |
|
} |
57 |
|
|
58 |
|
void mappa::Insert(TString nme, Int_t *valu){ |
59 |
|
// cout << " mappa insert " << nme.Data() << " valu " << *valu << endl; |
60 |
|
if ( !val ) this->Set(); |
61 |
|
TClonesArray &t = *val; |
62 |
|
new(t[entries]) mapval(nme,valu); |
63 |
|
entries++; |
64 |
|
} |
65 |
|
|
66 |
|
mapval::mapval(const mapval &t){ |
67 |
|
name = t.name; |
68 |
|
count = t.count; |
69 |
|
} |
70 |
|
|
71 |
|
mapval* mappa::Find(TString n){ |
72 |
|
Bool_t fo = false; |
73 |
|
fend = false; |
74 |
|
mapval *c = NULL; |
75 |
|
for (Int_t i=0; i < entries; i++){ |
76 |
|
c = (mapval*)val->At(i); |
77 |
|
if ( c && !strcmp(c->name.Data(),n.Data()) ){ |
78 |
|
fo = true; |
79 |
|
break; |
80 |
|
}; |
81 |
|
}; |
82 |
|
if ( !fo ) fend = true; |
83 |
|
return c; |
84 |
|
} |
85 |
|
|
86 |
/** |
/** |
87 |
* Create a new event counter for a certain run. |
* Create a new event counter for a certain run. |
88 |
* @param run Run number. |
* @param run Run number. |
89 |
*/ |
*/ |
90 |
EventCounter::EventCounter(int run): |
EventCounter::EventCounter(int run): |
91 |
// New Packets. |
// New Packets. |
92 |
|
RunNumber(run), |
93 |
Pscu(0), |
Pscu(0), |
94 |
PhysEndRun(0), |
PhysEndRun(0), |
95 |
CalibCalPulse1(0), |
CalibCalPulse1(0), |
98 |
CalibTrkBoth(0), |
CalibTrkBoth(0), |
99 |
CalibTrk1(0), |
CalibTrk1(0), |
100 |
CalibTrk2(0), |
CalibTrk2(0), |
101 |
|
CalibCal(0), |
102 |
CalibTof(0), |
CalibTof(0), |
103 |
CalibS4(0), |
CalibS4(0), |
104 |
CalibCalPed(0), |
CalibCalPed(0), |
105 |
Calib1_Ac1(0), |
Calib1_Ac1(0), |
|
Calib2_Ac1(0), |
|
106 |
Calib1_Ac2(0), |
Calib1_Ac2(0), |
107 |
|
Calib2_Ac1(0), |
108 |
Calib2_Ac2(0), |
Calib2_Ac2(0), |
|
CalibCal(0), |
|
109 |
RunHeader(0), |
RunHeader(0), |
110 |
RunTrailer(0), |
RunTrailer(0), |
111 |
CalibHeader(0), |
CalibHeader(0), |
136 |
S4Alarm(0), |
S4Alarm(0), |
137 |
Ac2Alarm(0), |
Ac2Alarm(0), |
138 |
TsbT(0), |
TsbT(0), |
139 |
TsbB(0), |
TsbB(0) { |
140 |
RunNumber(run) { |
CMap.Set(); |
141 |
CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); |
CMap.Insert(PacketType::Physics->GetName(), &Physics); |
142 |
CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun)); |
CMap.Insert(PacketType::Pscu->GetName(), &Pscu); |
143 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1)); |
CMap.Insert(PacketType::RunHeader->GetName(), &RunHeader); |
144 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2)); |
CMap.Insert(PacketType::RunTrailer->GetName(), &RunTrailer); |
145 |
CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); |
CMap.Insert(PacketType::PhysEndRun->GetName(), &PhysEndRun); |
146 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth)); |
CMap.Insert(PacketType::InitHeader->GetName(), &InitHeader); |
147 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &CalibTrk1)); |
CMap.Insert(PacketType::InitTrailer->GetName(), &InitTrailer); |
148 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &CalibTrk2)); |
CMap.Insert(PacketType::Log->GetName(), &Log); |
149 |
CMap.insert(CounterMap::value_type(PacketType::CalibTof, &CalibTof)); |
CMap.Insert(PacketType::VarDump->GetName(), &VarDump); |
150 |
CMap.insert(CounterMap::value_type(PacketType::CalibS4, &CalibS4)); |
CMap.Insert(PacketType::ArrDump->GetName(), &ArrDump); |
151 |
CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &CalibCalPed)); |
CMap.Insert(PacketType::TabDump->GetName(), &TabDump); |
152 |
CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1, &Calib1_Ac1)); |
CMap.Insert(PacketType::Tmtc->GetName(), &Tmtc); |
153 |
CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1, &Calib2_Ac1)); |
CMap.Insert(PacketType::Mcmd->GetName(), &Mcmd); |
154 |
CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2, &Calib1_Ac2)); |
CMap.Insert(PacketType::TsbT->GetName(), &TsbT); |
155 |
CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2, &Calib2_Ac2)); |
CMap.Insert(PacketType::TsbB->GetName(), &TsbB); |
156 |
CMap.insert(CounterMap::value_type(PacketType::CalibCal, &CalibCal)); |
CMap.Insert(PacketType::CalibHeader->GetName(), &CalibHeader); |
157 |
CMap.insert(CounterMap::value_type(PacketType::RunHeader, &RunHeader)); |
CMap.Insert(PacketType::CalibTrailer->GetName(), &CalibTrailer); |
158 |
CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &RunTrailer)); |
CMap.Insert(PacketType::CalibCalPulse1->GetName(), &CalibCalPulse1); |
159 |
CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader)); |
CMap.Insert(PacketType::CalibCalPulse2->GetName(), &CalibCalPulse2); |
160 |
CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer)); |
CMap.Insert(PacketType::CalibTrkBoth->GetName(), &CalibTrkBoth); |
161 |
CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader)); |
CMap.Insert(PacketType::CalibTrk1->GetName(), &CalibTrk1); |
162 |
CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer)); |
CMap.Insert(PacketType::CalibTrk2->GetName(), &CalibTrk2); |
163 |
CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk)); |
CMap.Insert(PacketType::CalibS4->GetName(), &CalibS4); |
164 |
CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); |
CMap.Insert(PacketType::CalibCalPed->GetName(), &CalibCalPed); |
165 |
CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); |
CMap.Insert(PacketType::Calib1_Ac1->GetName(), &Calib1_Ac1); |
166 |
CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); |
CMap.Insert(PacketType::Calib2_Ac1->GetName(), &Calib2_Ac1); |
167 |
CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); |
CMap.Insert(PacketType::Calib1_Ac2->GetName(), &Calib1_Ac2); |
168 |
CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); |
CMap.Insert(PacketType::Calib2_Ac2->GetName(), &Calib2_Ac2); |
169 |
CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); |
CMap.Insert(PacketType::CalibCal->GetName(), &CalibCal); |
170 |
CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd)); |
CMap.Insert(PacketType::EventTrk->GetName(), &EventTrk); |
171 |
CMap.insert(CounterMap::value_type(PacketType::Ac1Init, &Ac1Init)); |
CMap.Insert(PacketType::Ac1Init->GetName(), &Ac1Init); |
172 |
CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit)); |
CMap.Insert(PacketType::CalInit->GetName(), &CalInit); |
173 |
CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit)); |
CMap.Insert(PacketType::TrkInit->GetName(), &TrkInit); |
174 |
CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit)); |
CMap.Insert(PacketType::TofInit->GetName(), &TofInit); |
175 |
CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit)); |
CMap.Insert(PacketType::TrgInit->GetName(), &TrgInit); |
176 |
CMap.insert(CounterMap::value_type(PacketType::NdInit, &NdInit)); |
CMap.Insert(PacketType::NdInit->GetName(), &NdInit); |
177 |
CMap.insert(CounterMap::value_type(PacketType::S4Init, &S4Init)); |
CMap.Insert(PacketType::S4Init->GetName(), &S4Init); |
178 |
CMap.insert(CounterMap::value_type(PacketType::Ac2Init, &Ac2Init)); |
CMap.Insert(PacketType::Ac2Init->GetName(), &Ac2Init); |
179 |
CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm)); |
CMap.Insert(PacketType::CalAlarm->GetName(), &CalAlarm); |
180 |
CMap.insert(CounterMap::value_type(PacketType::Ac1Alarm, &Ac1Alarm)); |
CMap.Insert(PacketType::Ac1Alarm->GetName(), &Ac1Alarm); |
181 |
CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm)); |
CMap.Insert(PacketType::TrkAlarm->GetName(), &TrkAlarm); |
182 |
CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm)); |
CMap.Insert(PacketType::TrgAlarm->GetName(), &TrgAlarm); |
183 |
CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm)); |
CMap.Insert(PacketType::TofAlarm->GetName(), &TofAlarm); |
184 |
CMap.insert(CounterMap::value_type(PacketType::S4Alarm, &S4Alarm)); |
CMap.Insert(PacketType::S4Alarm->GetName(), &S4Alarm); |
185 |
CMap.insert(CounterMap::value_type(PacketType::Ac2Alarm, &Ac2Alarm)); |
CMap.Insert(PacketType::Ac2Alarm->GetName(), &Ac2Alarm); |
186 |
CMap.insert(CounterMap::value_type(PacketType::TsbT, &TsbT)); |
CMap.Insert(PacketType::ForcedFECmd->GetName(), &ForcedFECmd); |
187 |
CMap.insert(CounterMap::value_type(PacketType::TsbB, &TsbB)); |
CMap.Insert(PacketType::CalibTof->GetName(), &CalibTof); |
188 |
|
|
189 |
} |
} |
190 |
|
|
191 |
/** |
/** |
193 |
* @param type Event type to be incremented. |
* @param type Event type to be incremented. |
194 |
*/ |
*/ |
195 |
void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){ |
void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){ |
196 |
CounterMap::iterator p = CMap.find(type); |
// cout << " increment "<< endl; |
197 |
if (p != CMap.end()) { |
mapval *p = CMap.Find(type->GetName()); |
198 |
|
if ( !CMap.end()) { |
199 |
int *counter = p->second; |
// cout << " A Counter." << type->GetName() << " = " << (*(&p->count)) << endl; |
200 |
(*counter)++; |
(*(p->count))++; |
201 |
|
//(*(&p->count))++; |
202 |
|
// cout << " B Counter." << type->GetName() << " = " << (*(&p->count)) << endl; |
203 |
|
} else { |
204 |
oss.str(""); |
oss.str(""); |
205 |
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 |
|
|
|
|
206 |
throw NotExistingCounterException(oss.str().c_str()); |
throw NotExistingCounterException(oss.str().c_str()); |
207 |
} |
} |
208 |
} |
} |
215 |
* number of the last read event of that type. |
* number of the last read event of that type. |
216 |
* @retval -1 if there was no event of this type. |
* @retval -1 if there was no event of this type. |
217 |
*/ |
*/ |
218 |
int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){ |
int EventCounter::Get(PacketType const * type) throw (NotExistingCounterException){ |
219 |
const CounterMap::const_iterator p = CMap.find(type); |
// cout << " get "<< endl; |
220 |
if (p != CMap.end()) { |
mapval *p = CMap.Find(type->GetName()); |
221 |
const int *counter = p->second; |
if ( !CMap.end()) { |
222 |
return *counter; |
// cout << " C Counter." << type->GetName() << " = " << (*(p->count)) << endl; |
223 |
|
return ((*(p->count))); |
224 |
|
// return ((*(&p->count))); |
225 |
} else { |
} else { |
226 |
throw NotExistingCounterException(type->GetName().c_str()); |
throw NotExistingCounterException(type->GetName()); |
227 |
return -1; |
return -1; |
228 |
} |
} |
229 |
} |
} |
234 |
* @return The next counter of that packet type. |
* @return The next counter of that packet type. |
235 |
* @retval -1 if there was no event of this type. |
* @retval -1 if there was no event of this type. |
236 |
*/ |
*/ |
237 |
int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){ |
int EventCounter::Next(PacketType const * type) throw (NotExistingCounterException){ |
238 |
const CounterMap::const_iterator p = CMap.find(type); |
// cout << " next "<< endl; |
239 |
if (p != CMap.end()) { |
mapval *p = CMap.Find(type->GetName()); |
240 |
const int *counter = p->second; |
if ( !CMap.end()) { |
241 |
return *counter + 1; |
// cout << " NEXT Counter." << type->GetName() << " = " << (*(p->count))+1 << endl; |
242 |
|
return ((*(p->count)) + 1); |
243 |
|
// return ((*(&p->count)) + 1); |
244 |
|
// return ((&(p->count)) + 1); |
245 |
} else { |
} else { |
246 |
throw NotExistingCounterException(type->GetName().c_str()); |
throw NotExistingCounterException(type->GetName()); |
247 |
return -1; |
return -1; |
248 |
} |
} |
249 |
} |
} |
252 |
* Get the all the counters |
* Get the all the counters |
253 |
* @retval 0 if there was no event of this type. |
* @retval 0 if there was no event of this type. |
254 |
*/ |
*/ |
255 |
void EventCounter::PrintCounters() const { |
void EventCounter::PrintCounters(){ |
256 |
std::cout<<"PrintCounters:"<<std::endl; |
std::cout<<"PrintCounters:"<<std::endl; |
257 |
|
// |
258 |
for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { |
for (Int_t i=0; i < CMap.GetEntries(); i++){ |
259 |
oss.str(""); |
mapval *p = CMap.Get(i); |
260 |
oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second); |
oss.str(""); |
261 |
std::cout<<oss.str()<<std::endl; |
oss << " Counter." << (p->name).Data() << " \t \t " << (*(p->count)); |
262 |
//marco |
// oss << " Counter." << (p->name).Data() << " \t \t " << (*(&p->count)); |
263 |
//logger->info(oss.str().c_str()); |
// oss << " Counter." << (p->name).Data() << " \t \t " << (&(p->count)); |
264 |
} |
std::cout<<oss.str()<<std::endl; |
265 |
|
}; |
266 |
} |
} |
267 |
|
|
268 |
|
ClassImp(mapval) |
269 |
|
ClassImp(mappa) |
270 |
|
ClassImp(EventCounter) |