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

Annotation of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Thu Aug 19 15:24:10 2004 UTC (20 years, 3 months ago) by kusanagi
Branch: MAIN
Changes since 1.5: +5 -7 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23