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

Contents of /chewbacca/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Fri Jul 24 13:53:49 2009 UTC (15 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.1: +13 -9 lines
Runtime error with ROOT 5.24 fixed, many small changes and warnings fixing

1 /** @file
2 * $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/event/EventCounter.cpp,v $
3 * $Id: EventCounter.cpp,v 1.1.1.1 2008/09/23 07:19:51 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 using namespace pamela;
19
20 /**
21 * Create a new event counter for a certain run.
22 * @param run Run number.
23 */
24 EventCounter::EventCounter(int run):
25 // New Packets.
26 Pscu(0),
27 PhysEndRun(0),
28 CalibCalPulse1(0),
29 CalibCalPulse2(0),
30 Physics(0),
31 CalibTrkBoth(0),
32 CalibTrk1(0),
33 CalibTrk2(0),
34 CalibCal(0),
35 CalibTof(0),
36 CalibS4(0),
37 CalibCalPed(0),
38 Calib1_Ac1(0),
39 Calib1_Ac2(0),
40 Calib2_Ac1(0),
41 Calib2_Ac2(0),
42 RunHeader(0),
43 RunTrailer(0),
44 CalibHeader(0),
45 CalibTrailer(0),
46 InitHeader(0),
47 InitTrailer(0),
48 EventTrk(0),
49 Log(0),
50 VarDump(0),
51 ArrDump(0),
52 TabDump(0),
53 Tmtc(0),
54 Mcmd(0),
55 ForcedFECmd(0),
56 Ac1Init(0),
57 CalInit(0),
58 TrkInit(0),
59 TofInit(0),
60 TrgInit(0),
61 NdInit(0),
62 S4Init(0),
63 Ac2Init(0),
64 CalAlarm(0),
65 Ac1Alarm(0),
66 TrkAlarm(0),
67 TrgAlarm(0),
68 TofAlarm(0),
69 S4Alarm(0),
70 Ac2Alarm(0),
71 TsbT(0),
72 TsbB(0),
73 RunNumber(run) {
74 CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu));
75 CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun));
76 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1));
77 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2));
78 CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics));
79 CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth));
80 CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &CalibTrk1));
81 CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &CalibTrk2));
82 CMap.insert(CounterMap::value_type(PacketType::CalibTof, &CalibTof));
83 CMap.insert(CounterMap::value_type(PacketType::CalibS4, &CalibS4));
84 CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &CalibCalPed));
85 CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1, &Calib1_Ac1));
86 CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1, &Calib2_Ac1));
87 CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2, &Calib1_Ac2));
88 CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2, &Calib2_Ac2));
89 CMap.insert(CounterMap::value_type(PacketType::CalibCal, &CalibCal));
90 CMap.insert(CounterMap::value_type(PacketType::RunHeader, &RunHeader));
91 CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &RunTrailer));
92 CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader));
93 CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer));
94 CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader));
95 CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer));
96 CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk));
97 CMap.insert(CounterMap::value_type(PacketType::Log, &Log));
98 CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump));
99 CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump));
100 CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump));
101 CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc));
102 CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd));
103 CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd));
104 CMap.insert(CounterMap::value_type(PacketType::Ac1Init, &Ac1Init));
105 CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit));
106 CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit));
107 CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit));
108 CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit));
109 CMap.insert(CounterMap::value_type(PacketType::NdInit, &NdInit));
110 CMap.insert(CounterMap::value_type(PacketType::S4Init, &S4Init));
111 CMap.insert(CounterMap::value_type(PacketType::Ac2Init, &Ac2Init));
112 CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm));
113 CMap.insert(CounterMap::value_type(PacketType::Ac1Alarm, &Ac1Alarm));
114 CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm));
115 CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm));
116 CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm));
117 CMap.insert(CounterMap::value_type(PacketType::S4Alarm, &S4Alarm));
118 CMap.insert(CounterMap::value_type(PacketType::Ac2Alarm, &Ac2Alarm));
119 CMap.insert(CounterMap::value_type(PacketType::TsbT, &TsbT));
120 CMap.insert(CounterMap::value_type(PacketType::TsbB, &TsbB));
121
122 }
123
124 /**
125 * Increment the event counter for a certain packet.
126 * @param type Event type to be incremented.
127 */
128 void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
129 CounterMap::iterator p = CMap.find(type);
130 if (p != CMap.end()) {
131
132 int *counter = p->second;
133 (*counter)++;
134 oss.str("");
135 oss << " Counter." << type->GetName() << " = " << (*counter);
136 //marco
137 //std::cout<<oss.str()<<std::endl; //marco
138 //// logger->info(oss.str().c_str());
139 } else {
140
141 oss.str("");
142 // oss << "\n No counter of type " << type->GetName().c_str();
143 oss << "\n No counter of type " << type->GetName();
144 //std::cout<<oss.str()<<std::endl; //marco
145
146 throw NotExistingCounterException(oss.str().c_str());
147 }
148 }
149
150 /**
151 * Get the counter corresponding to a certain packet type.
152 * @param type Event type to be incremented.
153 * @return The counter of that packet type. For the current event type,
154 * this is the actual event number. For all other types, this is the event
155 * number of the last read event of that type.
156 * @retval -1 if there was no event of this type.
157 */
158 int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){
159 const CounterMap::const_iterator p = CMap.find(type);
160 if (p != CMap.end()) {
161 const int *counter = p->second;
162 return *counter;
163 } else {
164 // throw NotExistingCounterException(type->GetName().c_str());
165 throw NotExistingCounterException(type->GetName());
166 return -1;
167 }
168 }
169
170 /**
171 * Get the counter of the next event corresponding to a certain packet type.
172 * @param type Event type to be incremented.
173 * @return The next counter of that packet type.
174 * @retval -1 if there was no event of this type.
175 */
176 int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){
177 const CounterMap::const_iterator p = CMap.find(type);
178 if (p != CMap.end()) {
179 const int *counter = p->second;
180 return *counter + 1;
181 } else {
182 // throw NotExistingCounterException(type->GetName().c_str());
183 throw NotExistingCounterException(type->GetName());
184 return -1;
185 }
186 }
187
188 /**
189 * Get the all the counters
190 * @retval 0 if there was no event of this type.
191 */
192 void EventCounter::PrintCounters() const {
193 std::cout<<"PrintCounters:"<<std::endl;
194
195 for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
196 oss.str("");
197 oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second);
198 std::cout<<oss.str()<<std::endl;
199 //marco
200 //logger->info(oss.str().c_str());
201 }
202 }
203
204 ClassImp(EventCounter)

  ViewVC Help
Powered by ViewVC 1.1.23