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

Annotation of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Jul 6 14:07:24 2004 UTC (20 years, 5 months ago) by kusanagi
Branch: MAIN
Changes since 1.2: +2 -1 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23