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

Diff of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by kusanagi, Thu Jul 29 16:18:53 2004 UTC revision 6.2 by kusanagi, Tue May 30 19:10:01 2006 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $   * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $
3   * $Id: EventCounter.cpp,v 1.4 2004/07/08 12:31:22 kusanagi Exp $   * $Id: EventCounter.cpp,v 6.1 2006/02/15 15:47:14 kusanagi Exp $
4   * $Author: kusanagi $   * $Author: kusanagi $
5   *   *
6   * Implementation of the EventCounter class.   * Implementation of the EventCounter class.
7   */   */
8  #include <log4cpp/Category.hh>  #include <log4cxx/logger.h>
9    #include <sstream>
10    
11  #include "EventCounter.h"  #include "EventCounter.h"
12  #include "PscuHeader.h"  #include "PscuHeader.h"
13    
 static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.raw.EventCounter");    
14    
15    static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter"));
16    static std::stringstream oss;
17  using namespace pamela;  using namespace pamela;
18    
19  /**  /**
# Line 26  EventCounter::EventCounter(int run): Line 28  EventCounter::EventCounter(int run):
28    CalibCalPulse2(0),    CalibCalPulse2(0),
29    Physics(0),    Physics(0),
30    CalibTrkBoth(0),    CalibTrkBoth(0),
31    Calib_Trk1(0),    CalibTrk1(0),
32    Calib_Trk2(0),    CalibTrk2(0),
33    Calib_Cal(0),    CalibTof(0),
34    Calib_Trd(0),    CalibS4(0),
35    Calib_Tof(0),    CalibCalPed(0),
36    Calib_S4(0),    Calib1_Ac1(0),
37    Calib_CalPed(0),    Calib2_Ac1(0),
38    Calib_Ac(0),    Calib1_Ac2(0),
39    Run_Header(0),    Calib2_Ac2(0),
40    Run_Trailer(0),    CalibCal(0),
41      RunHeader(0),
42      RunTrailer(0),
43    CalibHeader(0),    CalibHeader(0),
44    CalibTrailer(0),    CalibTrailer(0),
45    InitHeader(0),    InitHeader(0),
46    InitTrailer(0),    InitTrailer(0),
47    EventTrk(0),    EventTrk(0),
   TestTrk(0),  
48    Log(0),    Log(0),
49    VarDump(0),    VarDump(0),
50    ArrDump(0),    ArrDump(0),
# Line 49  EventCounter::EventCounter(int run): Line 52  EventCounter::EventCounter(int run):
52    Tmtc(0),    Tmtc(0),
53    Mcmd(0),    Mcmd(0),
54    ForcedFECmd(0),    ForcedFECmd(0),
55    AcInit(0),    Ac1Init(0),
56    CalInit(0),    CalInit(0),
57    TrkInit(0),    TrkInit(0),
58    TofInit(0),    TofInit(0),
59    TrgInit(0),    TrgInit(0),
60      NdInit(0),
61      S4Init(0),
62      Ac2Init(0),
63      CalAlarm(0),
64      Ac1Alarm(0),
65      TrkAlarm(0),
66      TrgAlarm(0),
67      TofAlarm(0),
68      S4Alarm(0),
69      Ac2Alarm(0),
70      TsbT(0),
71      TsbB(0),
72    RunNumber(run) {    RunNumber(run) {
73      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));
74      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));
75      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse1));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1,  &CalibCalPulse1));
76      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse2));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse2));
77      CMap.insert(CounterMap::value_type(PacketType::Physics,         &Physics));      CMap.insert(CounterMap::value_type(PacketType::Physics,         &Physics));
78      CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth,    &CalibTrkBoth));      CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth,    &CalibTrkBoth));
79      CMap.insert(CounterMap::value_type(PacketType::CalibTrk1,       &Calib_Trk1));      CMap.insert(CounterMap::value_type(PacketType::CalibTrk1,       &CalibTrk1));
80      CMap.insert(CounterMap::value_type(PacketType::CalibTrk2,       &Calib_Trk2));      CMap.insert(CounterMap::value_type(PacketType::CalibTrk2,       &CalibTrk2));
81      CMap.insert(CounterMap::value_type(PacketType::CalibCal,        &Calib_Cal));      CMap.insert(CounterMap::value_type(PacketType::CalibTof,        &CalibTof));
82      CMap.insert(CounterMap::value_type(PacketType::CalibTrd,        &Calib_Trd));      CMap.insert(CounterMap::value_type(PacketType::CalibS4,         &CalibS4));
83      CMap.insert(CounterMap::value_type(PacketType::CalibTof,        &Calib_Tof));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPed,     &CalibCalPed));
84      CMap.insert(CounterMap::value_type(PacketType::CalibS4,         &Calib_S4));      CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1,      &Calib1_Ac1));
85      CMap.insert(CounterMap::value_type(PacketType::CalibCalPed,     &Calib_CalPed));      CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1,      &Calib2_Ac1));
86      CMap.insert(CounterMap::value_type(PacketType::CalibAc,         &Calib_Ac));      CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2,      &Calib1_Ac2));
87      CMap.insert(CounterMap::value_type(PacketType::RunHeader,       &Run_Header));      CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2,      &Calib2_Ac2));
88      CMap.insert(CounterMap::value_type(PacketType::RunTrailer,      &Run_Trailer));      CMap.insert(CounterMap::value_type(PacketType::CalibCal,        &CalibCal));
89        CMap.insert(CounterMap::value_type(PacketType::RunHeader,       &RunHeader));
90        CMap.insert(CounterMap::value_type(PacketType::RunTrailer,      &RunTrailer));
91      CMap.insert(CounterMap::value_type(PacketType::CalibHeader,     &CalibHeader));      CMap.insert(CounterMap::value_type(PacketType::CalibHeader,     &CalibHeader));
92      CMap.insert(CounterMap::value_type(PacketType::CalibTrailer,    &CalibTrailer));        CMap.insert(CounterMap::value_type(PacketType::CalibTrailer,    &CalibTrailer));  
93      CMap.insert(CounterMap::value_type(PacketType::InitHeader,      &InitHeader));      CMap.insert(CounterMap::value_type(PacketType::InitHeader,      &InitHeader));
94      CMap.insert(CounterMap::value_type(PacketType::InitTrailer,     &InitTrailer));        CMap.insert(CounterMap::value_type(PacketType::InitTrailer,     &InitTrailer));  
95      CMap.insert(CounterMap::value_type(PacketType::EventTrk,        &EventTrk));        CMap.insert(CounterMap::value_type(PacketType::EventTrk,        &EventTrk));  
     CMap.insert(CounterMap::value_type(PacketType::TestTrk,         &TestTrk));    
96      CMap.insert(CounterMap::value_type(PacketType::Log,             &Log));      CMap.insert(CounterMap::value_type(PacketType::Log,             &Log));
97      CMap.insert(CounterMap::value_type(PacketType::VarDump,         &VarDump));      CMap.insert(CounterMap::value_type(PacketType::VarDump,         &VarDump));
98      CMap.insert(CounterMap::value_type(PacketType::ArrDump,         &ArrDump));      CMap.insert(CounterMap::value_type(PacketType::ArrDump,         &ArrDump));
# Line 84  EventCounter::EventCounter(int run): Line 100  EventCounter::EventCounter(int run):
100      CMap.insert(CounterMap::value_type(PacketType::Tmtc,            &Tmtc));      CMap.insert(CounterMap::value_type(PacketType::Tmtc,            &Tmtc));
101      CMap.insert(CounterMap::value_type(PacketType::Mcmd,            &Mcmd));      CMap.insert(CounterMap::value_type(PacketType::Mcmd,            &Mcmd));
102      CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd,     &ForcedFECmd));      CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd,     &ForcedFECmd));
103      CMap.insert(CounterMap::value_type(PacketType::AcInit,          &AcInit));      CMap.insert(CounterMap::value_type(PacketType::Ac1Init,         &Ac1Init));
104      CMap.insert(CounterMap::value_type(PacketType::CalInit,         &CalInit));      CMap.insert(CounterMap::value_type(PacketType::CalInit,         &CalInit));
105      CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));      CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));
106      CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));      CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));
107      CMap.insert(CounterMap::value_type(PacketType::TrgInit,         &TrgInit));      CMap.insert(CounterMap::value_type(PacketType::TrgInit,         &TrgInit));
108        CMap.insert(CounterMap::value_type(PacketType::NdInit,          &NdInit));
109        CMap.insert(CounterMap::value_type(PacketType::S4Init,          &S4Init));
110        CMap.insert(CounterMap::value_type(PacketType::Ac2Init,         &Ac2Init));
111        CMap.insert(CounterMap::value_type(PacketType::CalAlarm,        &CalAlarm));
112        CMap.insert(CounterMap::value_type(PacketType::Ac1Alarm,        &Ac1Alarm));
113        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        CMap.insert(CounterMap::value_type(PacketType::S4Alarm,         &S4Alarm));
117        CMap.insert(CounterMap::value_type(PacketType::Ac2Alarm,        &Ac2Alarm));
118        CMap.insert(CounterMap::value_type(PacketType::TsbT,            &TsbT));
119        CMap.insert(CounterMap::value_type(PacketType::TsbB,            &TsbB));
120  }  }
121    
122  /**  /**
123   * Increment the event counter for a certain packet.   * Increment the event counter for a certain packet.
124   * @param type Event type to be incremented.   * @param type Event type to be incremented.
125   */   */
126  void EventCounter::Increment(PacketType const * type) {  void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
127    CounterMap::iterator p = CMap.find(type);    CounterMap::iterator p = CMap.find(type);
128    if (p != CMap.end()) {    if (p != CMap.end()) {
129      int *counter = p->second;      int *counter = p->second;
130      (*counter)++;      (*counter)++;
131      cat <<  log4cpp::Priority::INFO      oss.str("");
132          <<  " Counter." <<  type->GetName() << " = " <<  (*counter)      oss << " Counter." <<  type->GetName() << " = " <<  (*counter);
133          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->info(oss.str().c_str());
134    } else {    } else {
135      cat <<  log4cpp::Priority::INFO      oss.str("");
136          <<  " No counter for packet type " <<  type->GetName()      oss << "\n No counter of type  " << type->GetName().c_str();
137          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      throw NotExistingCounterException(oss.str().c_str());
138    }    }
139  }  }
140    
# Line 118  void EventCounter::Increment(PacketType Line 146  void EventCounter::Increment(PacketType
146   * number of the last read event of that type.   * number of the last read event of that type.
147   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
148   */   */
149  int EventCounter::Get(PacketType const * type) const {  int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){
150    const CounterMap::const_iterator p = CMap.find(type);    const CounterMap::const_iterator p = CMap.find(type);
151    if (p != CMap.end()) {    if (p != CMap.end()) {
152      const int *counter = p->second;      const int *counter = p->second;
153      return *counter;      return *counter;
154    } else {    } else {
155          cat <<  log4cpp::Priority::INFO      throw NotExistingCounterException(type->GetName().c_str());
         <<  " No counter for packet type " <<  type->GetName()  
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
156      return -1;      return -1;
157    }    }
158  }  }
# Line 137  int EventCounter::Get(PacketType const * Line 163  int EventCounter::Get(PacketType const *
163   * @return The next counter of that packet type.   * @return The next counter of that packet type.
164   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
165   */   */
166  int EventCounter::Next(PacketType const * type) const {  int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){
167    const CounterMap::const_iterator p = CMap.find(type);    const CounterMap::const_iterator p = CMap.find(type);
168    if (p != CMap.end()) {    if (p != CMap.end()) {
169      const int *counter = p->second;      const int *counter = p->second;
170      return *counter + 1;      return *counter + 1;
171    } else {    } else {
172          cat <<  log4cpp::Priority::WARN      throw NotExistingCounterException(type->GetName().c_str());
         <<  " No counter for packet type " <<  type->GetName()  
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
173      return -1;      return -1;
174    }    }
175  }  }
176    
177  /**  /**
178   * Get the all the counters   * Get the all the counters
179    * @retval -1 if there was no event of this type.    * @retval 0 if there was no event of this type.
180   */   */
181  void EventCounter::PrintCounters() const {  void EventCounter::PrintCounters() const {
182    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
183    cat <<  log4cpp::Priority::INFO <<  " Counter." <<  (p->first)->GetName()  <<   " = " <<  (*p->second)    oss.str("");
184        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    oss <<  " Counter." <<  (p->first)->GetName()  <<   " \t \t " <<  (*p->second);
185      logger->info(oss.str().c_str());
186    }    }
187  }  }
188            

Legend:
Removed from v.1.5  
changed lines
  Added in v.6.2

  ViewVC Help
Powered by ViewVC 1.1.23