MdModuleRejector.cc
Go to the documentation of this file.
1 #include "MdModuleRejector.h"
2 #include <fwk/CentralConfig.h>
3 #include <det/VManager.h>
4 #include <utl/Branch.h>
5 #include <utl/ErrorLogger.h>
6 #include <utl/String.h>
7 #include <evt/Event.h>
8 #include <mevt/MEvent.h>
9 #include <mevt/Module.h>
10 
11 #include <sstream>
12 
13 using namespace fwk;
14 using namespace det;
15 using namespace utl;
16 using namespace evt;
17 using namespace mevt;
18 using namespace MdModuleRejectorAG;
19 
20 
23 {
24  Branch topB =
25  CentralConfig::GetInstance()->GetTopBranch("MdModuleRejector");
26 
27  fRejectMap.clear();
28 
29  std::ostringstream msg;
30  for (Branch b = topB.GetFirstChild(); b;
31  b = b.GetNextSibling())
32  {
33  const size_t counterId = VManager::FindComponent<size_t>("counterId", b.GetAttributes());
34  const size_t moduleId = VManager::FindComponent<size_t>("moduleId", b.GetAttributes());
35  const std::string reason = VManager::FindComponent<std::string>("reason", b.GetAttributes());
36 
37  std::vector<utl::TimeStamp> range;
38  b.GetData(range);
39 
40  fRejectMap.insert( std::make_pair( range[0], boost::make_tuple(range[1], counterId, moduleId) ) );
41 
42  msg << "\n registered: counter = " << counterId << ", module = " << moduleId;
43  msg << " [" << range[0] << ", " << range[1] << ") due to " << reason;
44  }
45  INFO(msg);
46 
47 // return fRejectMap.empty() ? eFailure : eSuccess;
48  return eSuccess;
49 }
50 
51 
53 MdModuleRejector::Run(Event& event)
54 {
55  std::stringstream msg (std::ostringstream::out);
56 
57 
58  if (!event.HasMEvent())
59  return eSuccess;
60 
61  MEvent& mEvent = event.GetMEvent();
62 
63  const TimeStamp& time = det::Detector::GetInstance().GetTime();
64 
65  TimeRangeMap::IdCollection badIds = fRejectMap.GetBadStations(time);
66 
67  std::vector<std::string> rejectedIds;
68  for (TimeRangeMap::IdCollection::const_iterator it = badIds.begin();
69  it != badIds.end(); ++it)
70  {
71  size_t counterId = (*it).first;
72 
73  if (mEvent.HasCounter(counterId))
74  {
75  mevt::Counter& counter = mEvent.GetCounter(counterId);
76 
77  size_t moduleId = (*it).second;
78 
79  if (moduleId==0) { // reject the counter
80  counter.SetRejected("Rejected by MdModuleRejector");
81  std::ostringstream counterModule("");
82  counterModule << counterId << "-all";
83  rejectedIds.push_back(counterModule.str());
84  } else if (counter.HasModule(moduleId)) { // reject one module
85  counter.GetModule(moduleId).SetRejected("Rejected by MdModuleRejector"); // TO-DO put the reason defined in the xml file
86  std::ostringstream counterModule("");
87  counterModule << counterId << "-" << moduleId;
88  rejectedIds.push_back(counterModule.str());
89  }
90 
91  }
92 
93  } // end IdCollection loop
94 
95  // if there are rejected modules output info message
96  if (rejectedIds.size()!=0) {
97  msg.str("");
98  msg << "rejected counter-module: ";
99  for(std::vector<std::string>::iterator it = rejectedIds.begin(); it!=rejectedIds.end(); ++it) {
100  msg << *it << ", ";
101  }
102  INFO(msg.str());
103  }
104 
105  return eSuccess;
106 }
107 
109 MdModuleRejector::Finish()
110 {
111  TimeRangeMap().swap(fRejectMap);
112 
113  return eSuccess;
114 }
115 
116 // Configure (x)emacs for this file ...
117 // Local Variables:
118 // mode: c++
119 // End:
Module & GetModule(const int mId)
bool HasMEvent() const
Counter level event data.
std::vector< std::pair< size_t, size_t > > IdCollection
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
bool HasCounter(const int cId) const
Definition: MEvent.h:43
vector< t2list > out
output of the algorithm: a list of clusters
Definition: XbAlgo.cc:32
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
Class representing a document branch.
Definition: Branch.h:107
bool HasModule(const int mId) const
void SetRejected(const std::string &reason="")
void SetRejected(const std::string &reason="")
Set the status of all modules in this counter to rejected. As described for the muon counter status...
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
Counter & GetCounter(const int cId)
Definition: MEvent.h:34
Root of the Muon event hierarchy.
Definition: MEvent.h:25
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.