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

Annotation of /chewbacca/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Tue Sep 23 07:19:51 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
Branch point for: v0r00
Initial revision

1 mocchiut 1.1 /** @file
2     * $Source: /repository/event/EventCounter.cpp,v $
3     * $Id: EventCounter.cpp,v 1.2 2008-02-07 18:17:23 messineo Exp $
4     * $Author: messineo $
5     *
6     * Implementation of the EventCounter class.
7     */
8     ////#include <log4cxx/logger.h>
9     #include <sstream>
10     #include <iostream>//mmmm
11    
12     #include "EventCounter.h"
13     #include "PscuHeader.h"
14    
15     //marco
16     ////static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter"));
17     static std::stringstream oss;
18     using namespace pamela;
19    
20     /**
21     * Create a new event counter for a certain run.
22     * @param run Run number.
23     */
24     EventCounter::EventCounter(int run):
25     // New Packets.
26     Pscu(0),
27     PhysEndRun(0),
28     CalibCalPulse1(0),
29     CalibCalPulse2(0),
30     Physics(0),
31     CalibTrkBoth(0),
32     CalibTrk1(0),
33     CalibTrk2(0),
34     CalibTof(0),
35     CalibS4(0),
36     CalibCalPed(0),
37     Calib1_Ac1(0),
38     Calib2_Ac1(0),
39     Calib1_Ac2(0),
40     Calib2_Ac2(0),
41     CalibCal(0),
42     RunHeader(0),
43     RunTrailer(0),
44     CalibHeader(0),
45     CalibTrailer(0),
46     InitHeader(0),
47     InitTrailer(0),
48     EventTrk(0),
49     Log(0),
50     VarDump(0),
51     ArrDump(0),
52     TabDump(0),
53     Tmtc(0),
54     Mcmd(0),
55     ForcedFECmd(0),
56     Ac1Init(0),
57     CalInit(0),
58     TrkInit(0),
59     TofInit(0),
60     TrgInit(0),
61     NdInit(0),
62     S4Init(0),
63     Ac2Init(0),
64     CalAlarm(0),
65     Ac1Alarm(0),
66     TrkAlarm(0),
67     TrgAlarm(0),
68     TofAlarm(0),
69     S4Alarm(0),
70     Ac2Alarm(0),
71     TsbT(0),
72     TsbB(0),
73     RunNumber(run) {
74     CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu));
75     CMap.insert(CounterMap::value_type(PacketType::PhysEndRun, &PhysEndRun));
76     CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1, &CalibCalPulse1));
77     CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2, &CalibCalPulse2));
78     CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics));
79     CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth, &CalibTrkBoth));
80     CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &CalibTrk1));
81     CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &CalibTrk2));
82     CMap.insert(CounterMap::value_type(PacketType::CalibTof, &CalibTof));
83     CMap.insert(CounterMap::value_type(PacketType::CalibS4, &CalibS4));
84     CMap.insert(CounterMap::value_type(PacketType::CalibCalPed, &CalibCalPed));
85     CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1, &Calib1_Ac1));
86     CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1, &Calib2_Ac1));
87     CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2, &Calib1_Ac2));
88     CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2, &Calib2_Ac2));
89     CMap.insert(CounterMap::value_type(PacketType::CalibCal, &CalibCal));
90     CMap.insert(CounterMap::value_type(PacketType::RunHeader, &RunHeader));
91     CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &RunTrailer));
92     CMap.insert(CounterMap::value_type(PacketType::CalibHeader, &CalibHeader));
93     CMap.insert(CounterMap::value_type(PacketType::CalibTrailer, &CalibTrailer));
94     CMap.insert(CounterMap::value_type(PacketType::InitHeader, &InitHeader));
95     CMap.insert(CounterMap::value_type(PacketType::InitTrailer, &InitTrailer));
96     CMap.insert(CounterMap::value_type(PacketType::EventTrk, &EventTrk));
97     CMap.insert(CounterMap::value_type(PacketType::Log, &Log));
98     CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump));
99     CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump));
100     CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump));
101     CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc));
102     CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd));
103     CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd, &ForcedFECmd));
104     CMap.insert(CounterMap::value_type(PacketType::Ac1Init, &Ac1Init));
105     CMap.insert(CounterMap::value_type(PacketType::CalInit, &CalInit));
106     CMap.insert(CounterMap::value_type(PacketType::TrkInit, &TrkInit));
107     CMap.insert(CounterMap::value_type(PacketType::TofInit, &TofInit));
108     CMap.insert(CounterMap::value_type(PacketType::TrgInit, &TrgInit));
109     CMap.insert(CounterMap::value_type(PacketType::NdInit, &NdInit));
110     CMap.insert(CounterMap::value_type(PacketType::S4Init, &S4Init));
111     CMap.insert(CounterMap::value_type(PacketType::Ac2Init, &Ac2Init));
112     CMap.insert(CounterMap::value_type(PacketType::CalAlarm, &CalAlarm));
113     CMap.insert(CounterMap::value_type(PacketType::Ac1Alarm, &Ac1Alarm));
114     CMap.insert(CounterMap::value_type(PacketType::TrkAlarm, &TrkAlarm));
115     CMap.insert(CounterMap::value_type(PacketType::TrgAlarm, &TrgAlarm));
116     CMap.insert(CounterMap::value_type(PacketType::TofAlarm, &TofAlarm));
117     CMap.insert(CounterMap::value_type(PacketType::S4Alarm, &S4Alarm));
118     CMap.insert(CounterMap::value_type(PacketType::Ac2Alarm, &Ac2Alarm));
119     CMap.insert(CounterMap::value_type(PacketType::TsbT, &TsbT));
120     CMap.insert(CounterMap::value_type(PacketType::TsbB, &TsbB));
121    
122     }
123    
124     /**
125     * Increment the event counter for a certain packet.
126     * @param type Event type to be incremented.
127     */
128     void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
129     CounterMap::iterator p = CMap.find(type);
130     if (p != CMap.end()) {
131    
132     int *counter = p->second;
133     (*counter)++;
134     oss.str("");
135     oss << " Counter." << type->GetName() << " = " << (*counter);
136     //marco
137     //std::cout<<oss.str()<<std::endl; //marco
138     //// logger->info(oss.str().c_str());
139     } else {
140    
141     oss.str("");
142     oss << "\n No counter of type " << type->GetName().c_str();
143     //std::cout<<oss.str()<<std::endl; //marco
144    
145     throw NotExistingCounterException(oss.str().c_str());
146     }
147     }
148    
149     /**
150     * Get the counter corresponding to a certain packet type.
151     * @param type Event type to be incremented.
152     * @return The counter of that packet type. For the current event type,
153     * this is the actual event number. For all other types, this is the event
154     * number of the last read event of that type.
155     * @retval -1 if there was no event of this type.
156     */
157     int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){
158     const CounterMap::const_iterator p = CMap.find(type);
159     if (p != CMap.end()) {
160     const int *counter = p->second;
161     return *counter;
162     } else {
163     throw NotExistingCounterException(type->GetName().c_str());
164     return -1;
165     }
166     }
167    
168     /**
169     * Get the counter of the next event corresponding to a certain packet type.
170     * @param type Event type to be incremented.
171     * @return The next counter of that packet type.
172     * @retval -1 if there was no event of this type.
173     */
174     int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){
175     const CounterMap::const_iterator p = CMap.find(type);
176     if (p != CMap.end()) {
177     const int *counter = p->second;
178     return *counter + 1;
179     } else {
180     throw NotExistingCounterException(type->GetName().c_str());
181     return -1;
182     }
183     }
184    
185     /**
186     * Get the all the counters
187     * @retval 0 if there was no event of this type.
188     */
189     void EventCounter::PrintCounters() const {
190     std::cout<<"PrintCounters:"<<std::endl;
191    
192     for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
193     oss.str("");
194     oss << " Counter." << (p->first)->GetName() << " \t \t " << (*p->second);
195     std::cout<<oss.str()<<std::endl;
196     //marco
197     //logger->info(oss.str().c_str());
198     }
199     }
200    

  ViewVC Help
Powered by ViewVC 1.1.23