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

Annotation of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.1 - (hide annotations) (download)
Wed Feb 15 15:47:14 2006 UTC (18 years, 10 months ago) by kusanagi
Branch: MAIN
CVS Tags: YODA6_2/01, YODA6_2/00, YODA6_1/00
Changes since 6.0: +2 -1 lines
Update. Because of misunderstanding the EventTrk packet had been removed from the unpacking. Now it is added again to the Yoda package.

1 kusanagi 1.1 /** @file
2 kusanagi 1.2 * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $
3 kusanagi 6.1 * $Id: EventCounter.cpp,v 6.0 2006/02/07 17:11:07 kusanagi Exp $
4 kusanagi 6.0 * $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 2.6 CalibTrk1(0),
31     CalibTrk2(0),
32     CalibTof(0),
33     CalibS4(0),
34     CalibCalPed(0),
35 kusanagi 2.4 Calib1_Ac1(0),
36     Calib1_Ac2(0),
37     Calib2_Ac1(0),
38     Calib2_Ac2(0),
39 kusanagi 2.6 RunHeader(0),
40     RunTrailer(0),
41 kusanagi 1.5 CalibHeader(0),
42     CalibTrailer(0),
43     InitHeader(0),
44     InitTrailer(0),
45 kusanagi 6.1 EventTrk(0),
46 kusanagi 1.4 Log(0),
47     VarDump(0),
48     ArrDump(0),
49     TabDump(0),
50     Tmtc(0),
51     Mcmd(0),
52 kusanagi 1.5 ForcedFECmd(0),
53 kusanagi 2.4 Ac1Init(0),
54 kusanagi 1.5 CalInit(0),
55     TrkInit(0),
56     TofInit(0),
57     TrgInit(0),
58 kusanagi 2.1 NdInit(0),
59 kusanagi 2.3 S4Init(0),
60 kusanagi 2.4 Ac2Init(0),
61 kusanagi 1.7 CalAlarm(0),
62     AcAlarm(0),
63     TrkAlarm(0),
64     TrgAlarm(0),
65     TofAlarm(0),
66 kusanagi 2.3 S4Alarm(0),
67 kusanagi 2.8 TsbT(0),
68     TsbB(0),
69 kusanagi 1.1 RunNumber(run) {
70 kusanagi 1.5 CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu));
71     CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun));
72 kusanagi 2.2 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1));
73 kusanagi 1.5 CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2));
74     CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics));
75 kusanagi 2.6 CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &CalibTrk1));
76     CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &CalibTrk2));
77     CMap.insert(CounterMap::value_type(PacketType::CalibTof, &CalibTof));
78     CMap.insert(CounterMap::value_type(PacketType::CalibS4, &CalibS4));
79     CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &CalibCalPed));
80 kusanagi 2.4 CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1, &Calib1_Ac1));
81     CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2, &Calib1_Ac2));
82     CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1, &Calib2_Ac1));
83     CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2, &Calib2_Ac2));
84 kusanagi 2.6 CMap.insert(CounterMap::value_type(PacketType::RunHeader, &RunHeader));
85     CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &RunTrailer));
86 kusanagi 1.5 CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader));
87     CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer));
88     CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader));
89     CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer));
90     CMap.insert(CounterMap::value_type(PacketType::Log, &Log));
91     CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump));
92     CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump));
93     CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump));
94     CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc));
95     CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd));
96     CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd));
97 kusanagi 2.4 CMap.insert(CounterMap::value_type(PacketType::Ac1Init, &Ac1Init));
98 kusanagi 1.5 CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit));
99     CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit));
100     CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit));
101 kusanagi 2.3 CMap.insert(CounterMap::value_type(PacketType::NdInit, &NdInit));
102     CMap.insert(CounterMap::value_type(PacketType::S4Init, &S4Init));
103 kusanagi 2.4 CMap.insert(CounterMap::value_type(PacketType::Ac2Init, &Ac2Init));
104 kusanagi 1.7 CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm));
105     CMap.insert(CounterMap::value_type(PacketType::AcAlarm, &AcAlarm));
106     CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm));
107     CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm));
108     CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm));
109 kusanagi 2.3 CMap.insert(CounterMap::value_type(PacketType::S4Alarm, &S4Alarm));
110 kusanagi 2.8 CMap.insert(CounterMap::value_type(PacketType::TsbT, &TsbT));
111     CMap.insert(CounterMap::value_type(PacketType::TsbB, &TsbB));
112 kusanagi 1.1 }
113    
114     /**
115     * Increment the event counter for a certain packet.
116     * @param type Event type to be incremented.
117     */
118 kusanagi 2.2 void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
119 kusanagi 1.1 CounterMap::iterator p = CMap.find(type);
120     if (p != CMap.end()) {
121     int *counter = p->second;
122     (*counter)++;
123 kusanagi 2.2 oss.str("");
124 kusanagi 1.7 oss << " Counter." << type->GetName() << " = " << (*counter);
125 kusanagi 2.7 logger->info(oss.str().c_str());
126 kusanagi 1.1 } else {
127 kusanagi 2.5 oss.str("");
128     oss << "\n No counter of type " << type->GetName().c_str();
129     throw NotExistingCounterException(oss.str().c_str());
130 kusanagi 1.1 }
131     }
132    
133     /**
134     * Get the counter corresponding to a certain packet type.
135     * @param type Event type to be incremented.
136     * @return The counter of that packet type. For the current event type,
137     * this is the actual event number. For all other types, this is the event
138     * number of the last read event of that type.
139     * @retval -1 if there was no event of this type.
140     */
141 kusanagi 2.2 int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){
142 kusanagi 1.1 const CounterMap::const_iterator p = CMap.find(type);
143     if (p != CMap.end()) {
144     const int *counter = p->second;
145     return *counter;
146     } else {
147 kusanagi 2.2 throw NotExistingCounterException(type->GetName().c_str());
148 kusanagi 1.1 return -1;
149     }
150     }
151    
152     /**
153     * Get the counter of the next event corresponding to a certain packet type.
154     * @param type Event type to be incremented.
155     * @return The next counter of that packet type.
156     * @retval -1 if there was no event of this type.
157     */
158 kusanagi 2.2 int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){
159 kusanagi 1.1 const CounterMap::const_iterator p = CMap.find(type);
160     if (p != CMap.end()) {
161     const int *counter = p->second;
162     return *counter + 1;
163     } else {
164 kusanagi 2.2 throw NotExistingCounterException(type->GetName().c_str());
165 kusanagi 1.1 return -1;
166     }
167     }
168    
169     /**
170     * Get the all the counters
171 kusanagi 1.7 * @retval 0 if there was no event of this type.
172 kusanagi 1.1 */
173     void EventCounter::PrintCounters() const {
174     for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
175 kusanagi 2.2 oss.str("");
176     oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second);
177 kusanagi 2.7 logger->info(oss.str().c_str());
178 kusanagi 1.1 }
179     }
180 kusanagi 5.1

  ViewVC Help
Powered by ViewVC 1.1.23