VManager.cc
Go to the documentation of this file.
1 #include <sstream>
2 
3 #include <det/VManager.h>
4 #include <utl/Reader.h>
5 #include <utl/ErrorLogger.h>
6 #include <fwk/CentralConfig.h>
7 #include <utl/AugerException.h>
8 
9 using namespace std;
10 using namespace fwk;
11 
12 
13 namespace det {
14 
15 void
16 VManager::Init(const string& configLink)
17 {
18  // default initialization
19  FindConfig(configLink);
20  fIsInitialized = true;
21 }
22 
23 
24 void
25 VManager::FindConfig(const string& configLink)
26 {
27  if (fIsInitialized) {
28  ostringstream warn;
29  warn << "Attempt to initialize an already initialized manager: " << configLink;
30  WARNING(warn);
31  return;
32  }
33 
34  fBranch = CentralConfig::GetInstance()->GetTopBranch(configLink);
35 
36  if (!fBranch) {
37  ostringstream err;
38  err << '\'' << configLink << "' manager requested in the manager configuration but "
39  "the bootstrap file does not specify a configuration file for it.";
40  ERROR(err);
41  throw utl::XMLParseException(err.str());
42  }
43 }
44 
45 
46 string
47 VManager::NotImplementedMessage(const string& type,
48  const string& componentProperty,
49  const string& componentName)
50  const
51 {
52  return QueryInfoMessage(componentProperty, componentName) +
53  " for type " + type + " not implemented in " + GetName() + "!";
54 }
55 
56 
57 string
58 VManager::QueryInfoMessage(const string& componentProperty,
59  const string& componentName,
60  const IndexMap& componentIndex)
61 {
62  ostringstream os;
63  os << "componentProperty = '" << componentProperty << "', "
64  "componentName = '" << componentName << "', "
65  "componentIndex = {";
66  IndexMap::const_iterator cIt = componentIndex.begin();
67  if (cIt != componentIndex.end()) {
68  os << " '" << cIt->first << "' => '" << cIt->second << '\'';
69  for (++cIt; cIt != componentIndex.end(); ++cIt)
70  os << " '" << cIt->first << "' => '" << cIt->second << '\'';
71  }
72  os << " }";
73  return os.str();
74 }
75 
76 
77 bool
78 VManager::CanAnswer(const Handle& returnData, const string& component)
79  const
80 {
81  if (IsReportingErrors()) {
82  if (fAvailability.empty()) {
83  const string warn = "The manager '" + GetName() + "' has an empty list of "
84  "available types and components. This should not happen. The "
85  "RegisterTypesAndComponents() for known types and components should be called "
86  "in the ctor of the manager.";
87  WARNING(warn);
88  return false;
89  }
90  }
91 
92  const AvailabilityMap::const_iterator typeIt =
93  fAvailability.find(returnData.GetTypeIdName());
94  if (typeIt != fAvailability.end()) {
95  const ComponentSet& components = typeIt->second;
96  if (components.find(component) != components.end())
97  return true;
98  }
99  if (IsReportingErrors()) {
100  INFO(string("Manager ") + GetName() + " cannot answer request " +
101  QueryInfoMessage(returnData, component));
102  }
103  return false;
104 }
105 
106 
107 string
108 VManager::QueryInfoMessage(const Handle& returnData,
109  const string& component)
110 {
111  ostringstream os;
112  os << "typeIdName = '" << returnData.GetTypeIdName() << "', "
113  "component = '" << component << '\'';
114  return os.str();
115 }
116 
117 
118 string
119 VManager::QueryInfoMessage(const Handle& returnData,
120  const string& component,
121  const string& property,
122  const IndexMap& componentIndex)
123 {
124  ostringstream os;
125  os << QueryInfoMessage(returnData, component) << ", "
126  "property = '" << property << "', "
127  "componentIndex = {";
128  IndexMap::const_iterator cIt = componentIndex.begin();
129  if (cIt != componentIndex.end()) {
130  os << " '" << cIt->first << "' => '" << cIt->second << '\'';
131  for (++cIt; cIt != componentIndex.end(); ++cIt)
132  os << " '" << cIt->first << "' => '" << cIt->second << '\'';
133  }
134  os << " }";
135  return os.str();
136 }
137 
138 }
139 
140 
141 // Configure (x)emacs for this file ...
142 // Local Variables:
143 // mode: c++
144 // End:
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Exception for errors encountered when parsing XML.
std::string GetTypeIdName() const
Definition: VManager.h:157
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
std::set< std::string > ComponentSet
Definition: VManager.h:413
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.