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

Annotation of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.4 - (hide annotations) (download)
Thu Dec 16 17:32:46 2004 UTC (19 years, 11 months ago) by kusanagi
Branch: MAIN
Changes since 2.3: +13 -5 lines
*** empty log message ***

1 kusanagi 1.1 /** @file
2 kusanagi 1.2 * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $
3 kusanagi 2.4 * $Id: EventCounter.cpp,v 2.3 2004/12/09 08:47:42 kusanagi Exp $
4 kusanagi 1.2 * $Author: kusanagi $
5 kusanagi 1.1 *
6     * Implementation of the EventCounter class.
7     */
8 kusanagi 1.7 #include <log4cxx/logger.h>
9     #include <sstream>
10 kusanagi 1.1
11     #include "EventCounter.h"
12     #include "PscuHeader.h"
13    
14    
15 kusanagi 1.7 static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter"));
16     static std::stringstream oss;
17 kusanagi 1.1 using namespace pamela;
18    
19     /**
20     * Create a new event counter for a certain run.
21     * @param run Run number.
22     */
23     EventCounter::EventCounter(int run):
24     // New Packets.
25 kusanagi 1.4 Pscu(0),
26 kusanagi 1.5 PhysEndRun(0),
27     CalibCalPulse1(0),
28     CalibCalPulse2(0),
29 kusanagi 1.4 Physics(0),
30 kusanagi 1.5 CalibTrkBoth(0),
31 kusanagi 1.4 Calib_Trk1(0),
32     Calib_Trk2(0),
33     Calib_Trd(0),
34     Calib_Tof(0),
35     Calib_S4(0),
36 kusanagi 1.5 Calib_CalPed(0),
37 kusanagi 2.4 Calib1_Ac1(0),
38     Calib1_Ac2(0),
39     Calib2_Ac1(0),
40     Calib2_Ac2(0),
41 kusanagi 1.4 Run_Header(0),
42     Run_Trailer(0),
43 kusanagi 1.5 CalibHeader(0),
44     CalibTrailer(0),
45     InitHeader(0),
46     InitTrailer(0),
47     EventTrk(0),
48     TestTrk(0),
49 kusanagi 1.7 TestTof(0),
50 kusanagi 1.4 Log(0),
51     VarDump(0),
52     ArrDump(0),
53     TabDump(0),
54     Tmtc(0),
55     Mcmd(0),
56 kusanagi 1.5 ForcedFECmd(0),
57 kusanagi 2.4 Ac1Init(0),
58 kusanagi 1.5 CalInit(0),
59     TrkInit(0),
60     TofInit(0),
61     TrgInit(0),
62 kusanagi 2.1 NdInit(0),
63 kusanagi 2.3 S4Init(0),
64 kusanagi 2.4 Ac2Init(0),
65 kusanagi 1.7 CalAlarm(0),
66     AcAlarm(0),
67     TrkAlarm(0),
68     TrgAlarm(0),
69     TofAlarm(0),
70 kusanagi 2.3 S4Alarm(0),
71 kusanagi 1.1 RunNumber(run) {
72 kusanagi 1.5 CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu));
73     CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun));
74 kusanagi 2.2 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1));
75 kusanagi 1.5 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2));
76     CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics));
77     CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth));
78     CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &Calib_Trk1));
79     CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &Calib_Trk2));
80     CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd));
81     CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof));
82     CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4));
83     CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &Calib_CalPed));
84 kusanagi 2.4 CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1, &Calib1_Ac1));
85     CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2, &Calib1_Ac2));
86     CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1, &Calib2_Ac1));
87     CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2, &Calib2_Ac2));
88 kusanagi 1.5 CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header));
89     CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer));
90     CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader));
91     CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer));
92     CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader));
93     CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer));
94     CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk));
95     CMap.insert(CounterMap::value_type(PacketType::TestTrk, &TestTrk));
96 kusanagi 1.7 CMap.insert(CounterMap::value_type(PacketType::TestTof, &TestTof));
97 kusanagi 1.5 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 kusanagi 2.4 CMap.insert(CounterMap::value_type(PacketType::Ac1Init, &Ac1Init));
105 kusanagi 1.5 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 kusanagi 2.3 CMap.insert(CounterMap::value_type(PacketType::NdInit, &NdInit));
109     CMap.insert(CounterMap::value_type(PacketType::S4Init, &S4Init));
110 kusanagi 2.4 CMap.insert(CounterMap::value_type(PacketType::Ac2Init, &Ac2Init));
111 kusanagi 1.7 CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm));
112     CMap.insert(CounterMap::value_type(PacketType::AcAlarm, &AcAlarm));
113     CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm));
114     CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm));
115     CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm));
116 kusanagi 2.3 CMap.insert(CounterMap::value_type(PacketType::S4Alarm, &S4Alarm));
117 kusanagi 1.1 }
118    
119     /**
120     * Increment the event counter for a certain packet.
121     * @param type Event type to be incremented.
122     */
123 kusanagi 2.2 void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
124 kusanagi 1.1 CounterMap::iterator p = CMap.find(type);
125     if (p != CMap.end()) {
126     int *counter = p->second;
127     (*counter)++;
128 kusanagi 2.2 oss.str("");
129 kusanagi 1.7 oss << " Counter." << type->GetName() << " = " << (*counter);
130     logger->debug(oss.str().c_str());
131 kusanagi 1.1 } else {
132 kusanagi 2.2 throw NotExistingCounterException(type->GetName().c_str());
133 kusanagi 1.1 }
134     }
135    
136     /**
137     * Get the counter corresponding to a certain packet type.
138     * @param type Event type to be incremented.
139     * @return The counter of that packet type. For the current event type,
140     * this is the actual event number. For all other types, this is the event
141     * number of the last read event of that type.
142     * @retval -1 if there was no event of this type.
143     */
144 kusanagi 2.2 int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){
145 kusanagi 1.1 const CounterMap::const_iterator p = CMap.find(type);
146     if (p != CMap.end()) {
147     const int *counter = p->second;
148     return *counter;
149     } else {
150 kusanagi 2.2 throw NotExistingCounterException(type->GetName().c_str());
151 kusanagi 1.1 return -1;
152     }
153     }
154    
155     /**
156     * Get the counter of the next event corresponding to a certain packet type.
157     * @param type Event type to be incremented.
158     * @return The next counter of that packet type.
159     * @retval -1 if there was no event of this type.
160     */
161 kusanagi 2.2 int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){
162 kusanagi 1.1 const CounterMap::const_iterator p = CMap.find(type);
163     if (p != CMap.end()) {
164     const int *counter = p->second;
165     return *counter + 1;
166     } else {
167 kusanagi 2.2 throw NotExistingCounterException(type->GetName().c_str());
168 kusanagi 1.1 return -1;
169     }
170     }
171    
172     /**
173     * Get the all the counters
174 kusanagi 1.7 * @retval 0 if there was no event of this type.
175 kusanagi 1.1 */
176     void EventCounter::PrintCounters() const {
177     for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
178 kusanagi 2.2 oss.str("");
179     oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second);
180 kusanagi 1.7 logger->warn(oss.str().c_str());
181 kusanagi 1.1 }
182     }

  ViewVC Help
Powered by ViewVC 1.1.23