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

Contents of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Tue Jul 6 12:20:23 2004 UTC (20 years, 7 months ago) by kusanagi
Branch: MAIN
Initial revision

1 /** @file
2 * $Source: /home/cvspamela/yoda/event/EventCounter.cpp,v $
3 * $Id: EventCounter.cpp,v 1.10 2004/06/09 23:18:20 nagni Exp $
4 * $Author: nagni $
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(-1),
24 Physics(-1),
25 Forced_Pkt(-1),
26 Calib_Trk(-1),
27 Calib_Trg(-1),
28 Calib_Cal(-1),
29 Calib_Trd(-1),
30 Calib_Tof(-1),
31 Calib_S4(-1),
32 Run_Header(-1),
33 Run_Trailer(-1),
34 Alarm(-1),
35 Khb(-1),
36 Log(-1),
37 VarDump(-1),
38 ArrDump(-1),
39 TabDump(-1),
40 Tmtc(-1),
41 Mcmd(-1),
42 HA_Header_E5(-1),
43 RunNumber(run) {
44 CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu));
45 CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics));
46 CMap.insert(CounterMap::value_type(PacketType::ForcedPkt, &Forced_Pkt));
47 CMap.insert(CounterMap::value_type(PacketType::CalibTrk, &Calib_Trk));
48 CMap.insert(CounterMap::value_type(PacketType::CalibTrg, &Calib_Trg));
49 CMap.insert(CounterMap::value_type(PacketType::CalibCal, &Calib_Cal));
50 CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd));
51 CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof));
52 CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4));
53 CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header));
54 CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer));
55 CMap.insert(CounterMap::value_type(PacketType::Alarm, &Alarm));
56 CMap.insert(CounterMap::value_type(PacketType::Khb, &Khb));
57 CMap.insert(CounterMap::value_type(PacketType::Log, &Log));
58 CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump));
59 CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump));
60 CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump));
61 CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc));
62 CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd));
63 CMap.insert(CounterMap::value_type(PacketType::HA_Header_E5, &HA_Header_E5));
64 }
65
66 /**
67 * Increment the event counter for a certain packet.
68 * @param type Event type to be incremented.
69 */
70 void EventCounter::Increment(PacketType const * type) {
71 CounterMap::iterator p = CMap.find(type);
72 if (p != CMap.end()) {
73 int *counter = p->second;
74 (*counter)++;
75 cat << log4cpp::Priority::INFO
76 << " Counter." << type->GetName() << " = " << (*counter)
77 << "\n " << log4cpp::CategoryStream::ENDLINE;
78 } else {
79 cat << log4cpp::Priority::INFO
80 << " No counter for packet type " << type->GetName()
81 << "\n " << log4cpp::CategoryStream::ENDLINE;
82 }
83 }
84
85 /**
86 * Get the counter corresponding to a certain packet type.
87 * @param type Event type to be incremented.
88 * @return The counter of that packet type. For the current event type,
89 * this is the actual event number. For all other types, this is the event
90 * number of the last read event of that type.
91 * @retval -1 if there was no event of this type.
92 */
93 int EventCounter::Get(PacketType const * type) const {
94 const CounterMap::const_iterator p = CMap.find(type);
95 if (p != CMap.end()) {
96 const int *counter = p->second;
97 return *counter;
98 } else {
99 cat << log4cpp::Priority::INFO
100 << " No counter for packet type " << type->GetName()
101 << "\n " << log4cpp::CategoryStream::ENDLINE;
102 return -1;
103 }
104 }
105
106 /**
107 * Get the counter of the next event corresponding to a certain packet type.
108 * @param type Event type to be incremented.
109 * @return The next counter of that packet type.
110 * @retval -1 if there was no event of this type.
111 */
112 int EventCounter::Next(PacketType const * type) const {
113 const CounterMap::const_iterator p = CMap.find(type);
114 if (p != CMap.end()) {
115 const int *counter = p->second;
116 return *counter + 1;
117 } else {
118 cat << log4cpp::Priority::WARN
119 << " No counter for packet type " << type->GetName()
120 << "\n " << log4cpp::CategoryStream::ENDLINE;
121 return -1;
122 }
123 }
124
125 /**
126 * Get the all the counters
127 * @retval -1 if there was no event of this type.
128 */
129 void EventCounter::PrintCounters() const {
130 for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
131 cat << log4cpp::Priority::INFO << " Counter." << (p->first)->GetName() << " = " << (*p->second)
132 << "\n " << log4cpp::CategoryStream::ENDLINE;
133 }
134 }

  ViewVC Help
Powered by ViewVC 1.1.23