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

Contents of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Thu Jul 29 16:18:53 2004 UTC (20 years, 4 months ago) by kusanagi
Branch: MAIN
Changes since 1.4: +53 -29 lines
*** empty log message ***

1 /** @file
2 * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $
3 * $Id: EventCounter.cpp,v 1.4 2004/07/08 12:31:22 kusanagi Exp $
4 * $Author: kusanagi $
5 *
6 * Implementation of the EventCounter class.
7 */
8 #include <log4cpp/Category.hh>
9
10 #include "EventCounter.h"
11 #include "PscuHeader.h"
12
13 static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.raw.EventCounter");
14
15 using namespace pamela;
16
17 /**
18 * Create a new event counter for a certain run.
19 * @param run Run number.
20 */
21 EventCounter::EventCounter(int run):
22 // New Packets.
23 Pscu(0),
24 PhysEndRun(0),
25 CalibCalPulse1(0),
26 CalibCalPulse2(0),
27 Physics(0),
28 CalibTrkBoth(0),
29 Calib_Trk1(0),
30 Calib_Trk2(0),
31 Calib_Cal(0),
32 Calib_Trd(0),
33 Calib_Tof(0),
34 Calib_S4(0),
35 Calib_CalPed(0),
36 Calib_Ac(0),
37 Run_Header(0),
38 Run_Trailer(0),
39 CalibHeader(0),
40 CalibTrailer(0),
41 InitHeader(0),
42 InitTrailer(0),
43 EventTrk(0),
44 TestTrk(0),
45 Log(0),
46 VarDump(0),
47 ArrDump(0),
48 TabDump(0),
49 Tmtc(0),
50 Mcmd(0),
51 ForcedFECmd(0),
52 AcInit(0),
53 CalInit(0),
54 TrkInit(0),
55 TofInit(0),
56 TrgInit(0),
57 RunNumber(run) {
58 CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu));
59 CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun));
60 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse1));
61 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2));
62 CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics));
63 CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth));
64 CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &Calib_Trk1));
65 CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &Calib_Trk2));
66 CMap.insert(CounterMap::value_type(PacketType::CalibCal, &Calib_Cal));
67 CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd));
68 CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof));
69 CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4));
70 CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &Calib_CalPed));
71 CMap.insert(CounterMap::value_type(PacketType::CalibAc, &Calib_Ac));
72 CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header));
73 CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer));
74 CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader));
75 CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer));
76 CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader));
77 CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer));
78 CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk));
79 CMap.insert(CounterMap::value_type(PacketType::TestTrk, &TestTrk));
80 CMap.insert(CounterMap::value_type(PacketType::Log, &Log));
81 CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump));
82 CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump));
83 CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump));
84 CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc));
85 CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd));
86 CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd));
87 CMap.insert(CounterMap::value_type(PacketType::AcInit, &AcInit));
88 CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit));
89 CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit));
90 CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit));
91 CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit));
92 }
93
94 /**
95 * Increment the event counter for a certain packet.
96 * @param type Event type to be incremented.
97 */
98 void EventCounter::Increment(PacketType const * type) {
99 CounterMap::iterator p = CMap.find(type);
100 if (p != CMap.end()) {
101 int *counter = p->second;
102 (*counter)++;
103 cat << log4cpp::Priority::INFO
104 << " Counter." << type->GetName() << " = " << (*counter)
105 << "\n " << log4cpp::CategoryStream::ENDLINE;
106 } else {
107 cat << log4cpp::Priority::INFO
108 << " No counter for packet type " << type->GetName()
109 << "\n " << log4cpp::CategoryStream::ENDLINE;
110 }
111 }
112
113 /**
114 * Get the counter corresponding to a certain packet type.
115 * @param type Event type to be incremented.
116 * @return The counter of that packet type. For the current event type,
117 * this is the actual event number. For all other types, this is the event
118 * number of the last read event of that type.
119 * @retval -1 if there was no event of this type.
120 */
121 int EventCounter::Get(PacketType const * type) const {
122 const CounterMap::const_iterator p = CMap.find(type);
123 if (p != CMap.end()) {
124 const int *counter = p->second;
125 return *counter;
126 } else {
127 cat << log4cpp::Priority::INFO
128 << " No counter for packet type " << type->GetName()
129 << "\n " << log4cpp::CategoryStream::ENDLINE;
130 return -1;
131 }
132 }
133
134 /**
135 * Get the counter of the next event corresponding to a certain packet type.
136 * @param type Event type to be incremented.
137 * @return The next counter of that packet type.
138 * @retval -1 if there was no event of this type.
139 */
140 int EventCounter::Next(PacketType const * type) const {
141 const CounterMap::const_iterator p = CMap.find(type);
142 if (p != CMap.end()) {
143 const int *counter = p->second;
144 return *counter + 1;
145 } else {
146 cat << log4cpp::Priority::WARN
147 << " No counter for packet type " << type->GetName()
148 << "\n " << log4cpp::CategoryStream::ENDLINE;
149 return -1;
150 }
151 }
152
153 /**
154 * Get the all the counters
155 * @retval -1 if there was no event of this type.
156 */
157 void EventCounter::PrintCounters() const {
158 for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
159 cat << log4cpp::Priority::INFO << " Counter." << (p->first)->GetName() << " = " << (*p->second)
160 << "\n " << log4cpp::CategoryStream::ENDLINE;
161 }
162 }

  ViewVC Help
Powered by ViewVC 1.1.23