/[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.6 by kusanagi, Thu Aug 19 15:24:10 2004 UTC revision 2.1 by kusanagi, Fri Sep 24 11:57:32 2004 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.5 2004/07/29 16:18:53 kusanagi Exp $   * $Id: EventCounter.cpp,v 2.0 2004/09/21 20:49:57 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.techmodel.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 41  EventCounter::EventCounter(int run): Line 43  EventCounter::EventCounter(int run):
43    InitTrailer(0),    InitTrailer(0),
44    EventTrk(0),    EventTrk(0),
45    TestTrk(0),    TestTrk(0),
46      TestTof(0),
47    Log(0),    Log(0),
48    VarDump(0),    VarDump(0),
49    ArrDump(0),    ArrDump(0),
# Line 53  EventCounter::EventCounter(int run): Line 56  EventCounter::EventCounter(int run):
56    TrkInit(0),    TrkInit(0),
57    TofInit(0),    TofInit(0),
58    TrgInit(0),    TrgInit(0),
59      NdInit(0),
60      CalAlarm(0),
61      AcAlarm(0),
62      TrkAlarm(0),
63      TrgAlarm(0),
64      TofAlarm(0),
65    RunNumber(run) {    RunNumber(run) {
66      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));
67      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));
# Line 75  EventCounter::EventCounter(int run): Line 84  EventCounter::EventCounter(int run):
84      CMap.insert(CounterMap::value_type(PacketType::InitTrailer,     &InitTrailer));        CMap.insert(CounterMap::value_type(PacketType::InitTrailer,     &InitTrailer));  
85      CMap.insert(CounterMap::value_type(PacketType::EventTrk,        &EventTrk));        CMap.insert(CounterMap::value_type(PacketType::EventTrk,        &EventTrk));  
86      CMap.insert(CounterMap::value_type(PacketType::TestTrk,         &TestTrk));        CMap.insert(CounterMap::value_type(PacketType::TestTrk,         &TestTrk));  
87        CMap.insert(CounterMap::value_type(PacketType::TestTof,         &TestTof));  
88      CMap.insert(CounterMap::value_type(PacketType::Log,             &Log));      CMap.insert(CounterMap::value_type(PacketType::Log,             &Log));
89      CMap.insert(CounterMap::value_type(PacketType::VarDump,         &VarDump));      CMap.insert(CounterMap::value_type(PacketType::VarDump,         &VarDump));
90      CMap.insert(CounterMap::value_type(PacketType::ArrDump,         &ArrDump));      CMap.insert(CounterMap::value_type(PacketType::ArrDump,         &ArrDump));
# Line 87  EventCounter::EventCounter(int run): Line 97  EventCounter::EventCounter(int run):
97      CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));      CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));
98      CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));      CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));
99      CMap.insert(CounterMap::value_type(PacketType::TrgInit,         &TrgInit));      CMap.insert(CounterMap::value_type(PacketType::TrgInit,         &TrgInit));
100        CMap.insert(CounterMap::value_type(PacketType::TrgInit,         &NdInit));
101        CMap.insert(CounterMap::value_type(PacketType::CalAlarm,        &CalAlarm));
102        CMap.insert(CounterMap::value_type(PacketType::AcAlarm,         &AcAlarm));
103        CMap.insert(CounterMap::value_type(PacketType::TrkAlarm,        &TrkAlarm));
104        CMap.insert(CounterMap::value_type(PacketType::TrgAlarm,        &TrgAlarm));
105        CMap.insert(CounterMap::value_type(PacketType::TofAlarm,        &TofAlarm));
106  }  }
107    
108  /**  /**
# Line 98  void EventCounter::Increment(PacketType Line 114  void EventCounter::Increment(PacketType
114    if (p != CMap.end()) {    if (p != CMap.end()) {
115      int *counter = p->second;      int *counter = p->second;
116      (*counter)++;      (*counter)++;
117      cat <<  log4cpp::Priority::DEBUG      oss.flush();
118          <<  " Counter." <<  type->GetName() << " = " <<  (*counter)      oss << " Counter." <<  type->GetName() << " = " <<  (*counter);
119          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->debug(oss.str().c_str());
120    } else {    } else {
121      cat <<  log4cpp::Priority::WARN      oss.flush();
122          <<  " No counter for packet type " <<  type->GetName()      oss <<  " No counter for packet type " <<  type->GetName();
123          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->warn(oss.str().c_str());
124    }    }
125  }  }
126    
# Line 122  int EventCounter::Get(PacketType const * Line 138  int EventCounter::Get(PacketType const *
138      const int *counter = p->second;      const int *counter = p->second;
139      return *counter;      return *counter;
140    } else {    } else {
141          cat <<  log4cpp::Priority::WARN      oss.flush();
142          <<  " No counter for packet type " <<  type->GetName()      oss <<  " No counter for packet type " <<  type->GetName();
143          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->warn(oss.str().c_str());
144      return -1;      return -1;
145    }    }
146  }  }
# Line 141  int EventCounter::Next(PacketType const Line 157  int EventCounter::Next(PacketType const
157      const int *counter = p->second;      const int *counter = p->second;
158      return *counter + 1;      return *counter + 1;
159    } else {    } else {
160          cat <<  log4cpp::Priority::WARN      oss.flush();
161          <<  " No counter for packet type " <<  type->GetName()      oss <<  " No counter for packet type " <<  type->GetName();
162          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->warn(oss.str().c_str());
163      return -1;      return -1;
164    }    }
165  }  }
166    
167  /**  /**
168   * Get the all the counters   * Get the all the counters
169    * @retval -1 if there was no event of this type.    * @retval 0 if there was no event of this type.
170   */   */
171  void EventCounter::PrintCounters() const {  void EventCounter::PrintCounters() const {
172    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
173    cat <<  log4cpp::Priority::INFO <<  " Counter." <<  (p->first)->GetName()  <<   " = " <<  (*p->second)    oss.flush();
174        <<  "\n " << log4cpp::CategoryStream::ENDLINE;    oss <<  " Counter." <<  (p->first)->GetName()  <<   " = " <<  (*p->second);
175      logger->warn(oss.str().c_str());
176      std::cout <<  " Counter." <<  (p->first)->GetName()  <<   "\t = \t" <<  (*p->second) << "\n";
177    }    }
178  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.2.1

  ViewVC Help
Powered by ViewVC 1.1.23