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

Contents of /chewbacca/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Mon Jan 19 12:34:17 2015 UTC (9 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +10 -2 lines
Memory leak fixed in pamela::mapval, pamela::mappa, pamela::EventCounter, new IGRF12 parameters added in DB

1 /** @file
2 * $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/event/EventCounter.cpp,v $
3 * $Id: EventCounter.cpp,v 1.5 2010/02/11 09:02:15 mocchiut Exp $
4 * $Author: mocchiut $
5 *
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
19 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.
97 * @param run Run number.
98 */
99 EventCounter::EventCounter(int run):
100 // New Packets.
101 RunNumber(run),
102 Pscu(0),
103 PhysEndRun(0),
104 CalibCalPulse1(0),
105 CalibCalPulse2(0),
106 Physics(0),
107 CalibTrkBoth(0),
108 CalibTrk1(0),
109 CalibTrk2(0),
110 CalibCal(0),
111 CalibTof(0),
112 CalibS4(0),
113 CalibCalPed(0),
114 Calib1_Ac1(0),
115 Calib1_Ac2(0),
116 Calib2_Ac1(0),
117 Calib2_Ac2(0),
118 RunHeader(0),
119 RunTrailer(0),
120 CalibHeader(0),
121 CalibTrailer(0),
122 InitHeader(0),
123 InitTrailer(0),
124 EventTrk(0),
125 Log(0),
126 VarDump(0),
127 ArrDump(0),
128 TabDump(0),
129 Tmtc(0),
130 Mcmd(0),
131 ForcedFECmd(0),
132 Ac1Init(0),
133 CalInit(0),
134 TrkInit(0),
135 TofInit(0),
136 TrgInit(0),
137 NdInit(0),
138 S4Init(0),
139 Ac2Init(0),
140 CalAlarm(0),
141 Ac1Alarm(0),
142 TrkAlarm(0),
143 TrgAlarm(0),
144 TofAlarm(0),
145 S4Alarm(0),
146 Ac2Alarm(0),
147 TsbT(0),
148 TsbB(0) {
149 CMap.Set();
150 CMap.Insert(PacketType::Physics->GetName(), &Physics);
151 CMap.Insert(PacketType::Pscu->GetName(), &Pscu);
152 CMap.Insert(PacketType::RunHeader->GetName(), &RunHeader);
153 CMap.Insert(PacketType::RunTrailer->GetName(), &RunTrailer);
154 CMap.Insert(PacketType::PhysEndRun->GetName(), &PhysEndRun);
155 CMap.Insert(PacketType::InitHeader->GetName(), &InitHeader);
156 CMap.Insert(PacketType::InitTrailer->GetName(), &InitTrailer);
157 CMap.Insert(PacketType::Log->GetName(), &Log);
158 CMap.Insert(PacketType::VarDump->GetName(), &VarDump);
159 CMap.Insert(PacketType::ArrDump->GetName(), &ArrDump);
160 CMap.Insert(PacketType::TabDump->GetName(), &TabDump);
161 CMap.Insert(PacketType::Tmtc->GetName(), &Tmtc);
162 CMap.Insert(PacketType::Mcmd->GetName(), &Mcmd);
163 CMap.Insert(PacketType::TsbT->GetName(), &TsbT);
164 CMap.Insert(PacketType::TsbB->GetName(), &TsbB);
165 CMap.Insert(PacketType::CalibHeader->GetName(), &CalibHeader);
166 CMap.Insert(PacketType::CalibTrailer->GetName(), &CalibTrailer);
167 CMap.Insert(PacketType::CalibCalPulse1->GetName(), &CalibCalPulse1);
168 CMap.Insert(PacketType::CalibCalPulse2->GetName(), &CalibCalPulse2);
169 CMap.Insert(PacketType::CalibTrkBoth->GetName(), &CalibTrkBoth);
170 CMap.Insert(PacketType::CalibTrk1->GetName(), &CalibTrk1);
171 CMap.Insert(PacketType::CalibTrk2->GetName(), &CalibTrk2);
172 CMap.Insert(PacketType::CalibS4->GetName(), &CalibS4);
173 CMap.Insert(PacketType::CalibCalPed->GetName(), &CalibCalPed);
174 CMap.Insert(PacketType::Calib1_Ac1->GetName(), &Calib1_Ac1);
175 CMap.Insert(PacketType::Calib2_Ac1->GetName(), &Calib2_Ac1);
176 CMap.Insert(PacketType::Calib1_Ac2->GetName(), &Calib1_Ac2);
177 CMap.Insert(PacketType::Calib2_Ac2->GetName(), &Calib2_Ac2);
178 CMap.Insert(PacketType::CalibCal->GetName(), &CalibCal);
179 CMap.Insert(PacketType::EventTrk->GetName(), &EventTrk);
180 CMap.Insert(PacketType::Ac1Init->GetName(), &Ac1Init);
181 CMap.Insert(PacketType::CalInit->GetName(), &CalInit);
182 CMap.Insert(PacketType::TrkInit->GetName(), &TrkInit);
183 CMap.Insert(PacketType::TofInit->GetName(), &TofInit);
184 CMap.Insert(PacketType::TrgInit->GetName(), &TrgInit);
185 CMap.Insert(PacketType::NdInit->GetName(), &NdInit);
186 CMap.Insert(PacketType::S4Init->GetName(), &S4Init);
187 CMap.Insert(PacketType::Ac2Init->GetName(), &Ac2Init);
188 CMap.Insert(PacketType::CalAlarm->GetName(), &CalAlarm);
189 CMap.Insert(PacketType::Ac1Alarm->GetName(), &Ac1Alarm);
190 CMap.Insert(PacketType::TrkAlarm->GetName(), &TrkAlarm);
191 CMap.Insert(PacketType::TrgAlarm->GetName(), &TrgAlarm);
192 CMap.Insert(PacketType::TofAlarm->GetName(), &TofAlarm);
193 CMap.Insert(PacketType::S4Alarm->GetName(), &S4Alarm);
194 CMap.Insert(PacketType::Ac2Alarm->GetName(), &Ac2Alarm);
195 CMap.Insert(PacketType::ForcedFECmd->GetName(), &ForcedFECmd);
196 CMap.Insert(PacketType::CalibTof->GetName(), &CalibTof);
197
198 }
199
200 /**
201 * Increment the event counter for a certain packet.
202 * @param type Event type to be incremented.
203 */
204 void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
205 // cout << " increment "<< endl;
206 mapval *p = CMap.Find(type->GetName());
207 if ( !CMap.end()) {
208 // cout << " A Counter." << type->GetName() << " = " << (*(&p->count)) << endl;
209 (*(p->count))++;
210 //(*(&p->count))++;
211 // cout << " B Counter." << type->GetName() << " = " << (*(&p->count)) << endl;
212 } else {
213 oss.str("");
214 oss << "\n No counter of type " << type->GetName();
215 throw NotExistingCounterException(oss.str().c_str());
216 }
217 }
218
219 /**
220 * Get the counter corresponding to a certain packet type.
221 * @param type Event type to be incremented.
222 * @return The counter of that packet type. For the current event type,
223 * this is the actual event number. For all other types, this is the event
224 * number of the last read event of that type.
225 * @retval -1 if there was no event of this type.
226 */
227 int EventCounter::Get(PacketType const * type) throw (NotExistingCounterException){
228 // cout << " get "<< endl;
229 mapval *p = CMap.Find(type->GetName());
230 if ( !CMap.end()) {
231 // cout << " C Counter." << type->GetName() << " = " << (*(p->count)) << endl;
232 return ((*(p->count)));
233 // return ((*(&p->count)));
234 } else {
235 throw NotExistingCounterException(type->GetName());
236 return -1;
237 }
238 }
239
240 /**
241 * Get the counter of the next event corresponding to a certain packet type.
242 * @param type Event type to be incremented.
243 * @return The next counter of that packet type.
244 * @retval -1 if there was no event of this type.
245 */
246 int EventCounter::Next(PacketType const * type) throw (NotExistingCounterException){
247 // cout << " next "<< endl;
248 mapval *p = CMap.Find(type->GetName());
249 if ( !CMap.end()) {
250 // 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 {
255 throw NotExistingCounterException(type->GetName());
256 return -1;
257 }
258 }
259
260 /**
261 * Get the all the counters
262 * @retval 0 if there was no event of this type.
263 */
264 void EventCounter::PrintCounters(){
265 std::cout<<"PrintCounters:"<<std::endl;
266 //
267 for (Int_t i=0; i < CMap.GetEntries(); i++){
268 mapval *p = CMap.Get(i);
269 oss.str("");
270 oss << " Counter." << (p->name).Data() << " \t \t " << (*(p->count));
271 // oss << " Counter." << (p->name).Data() << " \t \t " << (*(&p->count));
272 // 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)

  ViewVC Help
Powered by ViewVC 1.1.23