artdaq_mfextensions  v1_06_02
ma_participants.cpp
1 
2 #include "ErrorHandler/MessageAnalyzer/ma_participants.h"
3 
4 #include <sstream>
5 #include <stdexcept>
6 
7 using namespace novadaq::errorhandler;
8 
9 // -----------------------------------------------------------------
10 // add group
11 
12 void ma_participants::add_group(std::string const& group)
13 {
14  groups_t::const_iterator it = groups.find(group);
15 
16  if (it != groups.end())
17  throw std::runtime_error(group + " already exists while creating new group");
18 
19  string_set_t apps;
20  groups.insert(std::make_pair(group, apps));
21 }
22 
23 void ma_participants::add_group(std::string const& group, size_t size)
24 {
25  groups_t::const_iterator it = groups.find(group);
26 
27  if (it != groups.end())
28  throw std::runtime_error(group + " already exists while creating new group");
29 
30  string_set_t apps;
31  std::stringstream ss;
32 
33  for (size_t i = 0; i < size; ++i)
34  {
35  ss.str(group);
36  ss << "-" << i;
37  apps.insert(ss.str());
38  all_apps.insert(ss.str());
39  }
40 
41  groups.insert(std::make_pair(group, apps));
42 }
43 
44 // -----------------------------------------------------------------
45 // add participant
46 
47 void ma_participants::add_participant(std::string const& group, std::string const& app)
48 {
49  groups_t::iterator it = groups.find(group);
50 
51  if (it == groups.end())
52  throw std::runtime_error(group + " does not exist while inserting participants");
53 
54  it->second.insert(app);
55  all_apps.insert(app);
56 }
57 
58 void ma_participants::add_participant(std::string const& app)
59 {
60  ungrouped_apps.insert(app);
61  all_apps.insert(app);
62 }
63 
64 // -----------------------------------------------------------------
65 // get count
66 
67 size_t ma_participants::
68  get_group_participant_count(std::string const& group) const
69 {
70  groups_t::const_iterator it = groups.find(group);
71 
72  if (it == groups.end())
73  throw std::runtime_error(group + " does not exist while getting participant count");
74 
75  return it->second.size();
76 }
77 
78 size_t ma_participants::
79  get_participant_count() const
80 {
81  return all_apps.size();
82 }
83 
84 // -----------------------------------------------------------------
85 // reset
86 void ma_participants::reset()
87 {
88  ungrouped_apps.clear();
89  all_apps.clear();
90  groups.clear();
91 }