/[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.1.1.1 by kusanagi, Tue Jul 6 12:20:23 2004 UTC revision 4.4 by kusanagi, Sat May 28 10:44:09 2005 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /home/cvspamela/yoda/event/EventCounter.cpp,v $   * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $
3   * $Id: EventCounter.cpp,v 1.10 2004/06/09 23:18:20 nagni Exp $   * $Id: EventCounter.cpp,v 4.1 2005/05/28 08:30:01 kusanagi Exp $
4   * $Author: nagni $   * $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 20  using namespace pamela; Line 22  using namespace pamela;
22   */   */
23  EventCounter::EventCounter(int run):  EventCounter::EventCounter(int run):
24    // New Packets.    // New Packets.
25    Pscu(-1),    Pscu(0),
26    Physics(-1),    PhysEndRun(0),
27    Forced_Pkt(-1),    CalibCalPulse1(0),
28    Calib_Trk(-1),    CalibCalPulse2(0),
29    Calib_Trg(-1),    Physics(0),
30    Calib_Cal(-1),    CalibTrk1(0),
31    Calib_Trd(-1),    CalibTrk2(0),
32    Calib_Tof(-1),    CalibTof(0),
33    Calib_S4(-1),    CalibS4(0),
34    Run_Header(-1),    CalibCalPed(0),
35    Run_Trailer(-1),    Calib1_Ac1(0),
36    Alarm(-1),    Calib1_Ac2(0),
37    Khb(-1),    Calib2_Ac1(0),
38    Log(-1),    Calib2_Ac2(0),
39    VarDump(-1),    RunHeader(0),
40    ArrDump(-1),    RunTrailer(0),
41    TabDump(-1),    CalibHeader(0),
42    Tmtc(-1),    CalibTrailer(0),
43    Mcmd(-1),    InitHeader(0),
44    HA_Header_E5(-1),    InitTrailer(0),
45      EventTrk(0),
46      TestTrk(0),
47      TestTof(0),
48      Log(0),
49      VarDump(0),
50      ArrDump(0),
51      TabDump(0),
52      Tmtc(0),
53      Mcmd(0),
54      ForcedFECmd(0),
55      Ac1Init(0),
56      CalInit(0),
57      TrkInit(0),
58      TofInit(0),
59      TrgInit(0),
60      NdInit(0),
61      S4Init(0),
62      Ac2Init(0),
63      CalAlarm(0),
64      AcAlarm(0),
65      TrkAlarm(0),
66      TrgAlarm(0),
67      TofAlarm(0),
68      S4Alarm(0),
69      TsbT(0),
70      TsbB(0),
71    RunNumber(run) {    RunNumber(run) {
72    CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu));      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));
73    CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics));      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));
74    CMap.insert(CounterMap::value_type(PacketType::ForcedPkt, &Forced_Pkt));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1,  &CalibCalPulse1));
75    CMap.insert(CounterMap::value_type(PacketType::CalibTrk, &Calib_Trk));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse2));
76    CMap.insert(CounterMap::value_type(PacketType::CalibTrg, &Calib_Trg));      CMap.insert(CounterMap::value_type(PacketType::Physics,         &Physics));
77    CMap.insert(CounterMap::value_type(PacketType::CalibCal, &Calib_Cal));      CMap.insert(CounterMap::value_type(PacketType::CalibTrk1,       &CalibTrk1));
78    CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd));      CMap.insert(CounterMap::value_type(PacketType::CalibTrk2,       &CalibTrk2));
79    CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof));      CMap.insert(CounterMap::value_type(PacketType::CalibTof,        &CalibTof));
80    CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4));      CMap.insert(CounterMap::value_type(PacketType::CalibS4,         &CalibS4));
81    CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPed,     &CalibCalPed));
82    CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer));      CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1,      &Calib1_Ac1));
83    CMap.insert(CounterMap::value_type(PacketType::Alarm, &Alarm));      CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2,      &Calib1_Ac2));
84    CMap.insert(CounterMap::value_type(PacketType::Khb, &Khb));      CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1,      &Calib2_Ac1));
85    CMap.insert(CounterMap::value_type(PacketType::Log, &Log));      CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2,      &Calib2_Ac2));
86    CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump));      CMap.insert(CounterMap::value_type(PacketType::RunHeader,       &RunHeader));
87    CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump));      CMap.insert(CounterMap::value_type(PacketType::RunTrailer,      &RunTrailer));
88    CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump));      CMap.insert(CounterMap::value_type(PacketType::CalibHeader,     &CalibHeader));
89    CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc));      CMap.insert(CounterMap::value_type(PacketType::CalibTrailer,    &CalibTrailer));  
90    CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd));      CMap.insert(CounterMap::value_type(PacketType::InitHeader,      &InitHeader));
91    CMap.insert(CounterMap::value_type(PacketType::HA_Header_E5, &HA_Header_E5));      CMap.insert(CounterMap::value_type(PacketType::InitTrailer,     &InitTrailer));  
92        CMap.insert(CounterMap::value_type(PacketType::EventTrk,        &EventTrk));  
93        CMap.insert(CounterMap::value_type(PacketType::TestTrk,         &TestTrk));  
94        CMap.insert(CounterMap::value_type(PacketType::TestTof,         &TestTof));  
95        CMap.insert(CounterMap::value_type(PacketType::Log,             &Log));
96        CMap.insert(CounterMap::value_type(PacketType::VarDump,         &VarDump));
97        CMap.insert(CounterMap::value_type(PacketType::ArrDump,         &ArrDump));
98        CMap.insert(CounterMap::value_type(PacketType::TabDump,         &TabDump));
99        CMap.insert(CounterMap::value_type(PacketType::Tmtc,            &Tmtc));
100        CMap.insert(CounterMap::value_type(PacketType::Mcmd,            &Mcmd));
101        CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd,     &ForcedFECmd));
102        CMap.insert(CounterMap::value_type(PacketType::Ac1Init,         &Ac1Init));
103        CMap.insert(CounterMap::value_type(PacketType::CalInit,         &CalInit));
104        CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));
105        CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));
106        CMap.insert(CounterMap::value_type(PacketType::NdInit,          &NdInit));
107        CMap.insert(CounterMap::value_type(PacketType::S4Init,          &S4Init));
108        CMap.insert(CounterMap::value_type(PacketType::Ac2Init,         &Ac2Init));
109        CMap.insert(CounterMap::value_type(PacketType::CalAlarm,        &CalAlarm));
110        CMap.insert(CounterMap::value_type(PacketType::AcAlarm,         &AcAlarm));
111        CMap.insert(CounterMap::value_type(PacketType::TrkAlarm,        &TrkAlarm));
112        CMap.insert(CounterMap::value_type(PacketType::TrgAlarm,        &TrgAlarm));
113        CMap.insert(CounterMap::value_type(PacketType::TofAlarm,        &TofAlarm));
114        CMap.insert(CounterMap::value_type(PacketType::S4Alarm,         &S4Alarm));
115        CMap.insert(CounterMap::value_type(PacketType::TsbT,            &TsbT));
116        CMap.insert(CounterMap::value_type(PacketType::TsbB,            &TsbB));
117  }  }
118    
119  /**  /**
120   * Increment the event counter for a certain packet.   * Increment the event counter for a certain packet.
121   * @param type Event type to be incremented.   * @param type Event type to be incremented.
122   */   */
123  void EventCounter::Increment(PacketType const * type) {  void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
124    CounterMap::iterator p = CMap.find(type);    CounterMap::iterator p = CMap.find(type);
125    if (p != CMap.end()) {    if (p != CMap.end()) {
126      int *counter = p->second;      int *counter = p->second;
127      (*counter)++;      (*counter)++;
128      cat <<  log4cpp::Priority::INFO      oss.str("");
129          <<  " Counter." <<  type->GetName() << " = " <<  (*counter)      oss << " Counter." <<  type->GetName() << " = " <<  (*counter);
130          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->info(oss.str().c_str());
131    } else {    } else {
132      cat <<  log4cpp::Priority::INFO      oss.str("");
133          <<  " No counter for packet type " <<  type->GetName()      oss << "\n No counter of type  " << type->GetName().c_str();
134          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      throw NotExistingCounterException(oss.str().c_str());
135    }    }
136  }  }
137    
# Line 90  void EventCounter::Increment(PacketType Line 143  void EventCounter::Increment(PacketType
143   * number of the last read event of that type.   * number of the last read event of that type.
144   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
145   */   */
146  int EventCounter::Get(PacketType const * type) const {  int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){
147    const CounterMap::const_iterator p = CMap.find(type);    const CounterMap::const_iterator p = CMap.find(type);
148    if (p != CMap.end()) {    if (p != CMap.end()) {
149      const int *counter = p->second;      const int *counter = p->second;
150      return *counter;      return *counter;
151    } else {    } else {
152          cat <<  log4cpp::Priority::INFO      throw NotExistingCounterException(type->GetName().c_str());
         <<  " No counter for packet type " <<  type->GetName()  
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
153      return -1;      return -1;
154    }    }
155  }  }
# Line 109  int EventCounter::Get(PacketType const * Line 160  int EventCounter::Get(PacketType const *
160   * @return The next counter of that packet type.   * @return The next counter of that packet type.
161   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
162   */   */
163  int EventCounter::Next(PacketType const * type) const {  int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){
164    const CounterMap::const_iterator p = CMap.find(type);    const CounterMap::const_iterator p = CMap.find(type);
165    if (p != CMap.end()) {    if (p != CMap.end()) {
166      const int *counter = p->second;      const int *counter = p->second;
167      return *counter + 1;      return *counter + 1;
168    } else {    } else {
169          cat <<  log4cpp::Priority::WARN      throw NotExistingCounterException(type->GetName().c_str());
         <<  " No counter for packet type " <<  type->GetName()  
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
170      return -1;      return -1;
171    }    }
172  }  }
173    
174  /**  /**
175   * Get the all the counters   * Get the all the counters
176    * @retval -1 if there was no event of this type.    * @retval 0 if there was no event of this type.
177   */   */
178  void EventCounter::PrintCounters() const {  void EventCounter::PrintCounters() const {
179    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
180    cat <<  log4cpp::Priority::INFO <<  " Counter." <<  (p->first)->GetName()  <<   " = " <<  (*p->second)    oss.str("");
181        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    oss <<  " Counter." <<  (p->first)->GetName()  <<   " \t \t " <<  (*p->second);
182      logger->info(oss.str().c_str());
183    }    }
184  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.4.4

  ViewVC Help
Powered by ViewVC 1.1.23