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

Contents of /chewbacca/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Tue Aug 4 13:58:16 2009 UTC (15 years, 6 months ago) by mocchiut
Branch: MAIN
Changes since 1.3: +152 -86 lines
Changed to work with GCC 4.x (gfortran) + ROOT >= 5.24

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

  ViewVC Help
Powered by ViewVC 1.1.23