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

Annotation of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.2 - (hide annotations) (download)
Tue May 30 19:10:01 2006 UTC (18 years, 6 months ago) by kusanagi
Branch: MAIN
Changes since 6.1: +13 -5 lines
Major update.
All the packet officially produced by PAMELA are implemented and unpacked.
The RegistryEvent Packet has been removed and put into another library.
New version, releasd by D.Campana, of tofunpack.

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

  ViewVC Help
Powered by ViewVC 1.1.23