HOPS
HOPS class reference
MHO_OperatorBuilderManager.hh
Go to the documentation of this file.
1 #ifndef MHO_OperatorBuilderManager_HH__
2 #define MHO_OperatorBuilderManager_HH__
3 
4 #include "MHO_ContainerStore.hh"
6 #include "MHO_Message.hh"
7 #include "MHO_OperatorBuilder.hh"
8 #include "MHO_OperatorToolbox.hh"
9 #include "MHO_FringeData.hh"
10 #include "MHO_ParameterStore.hh"
11 
12 namespace hops
13 {
14 
24 {
25  public:
27  MHO_FringeData* fdata,
28  mho_json control_format):
29  fOperatorToolbox(toolbox),
30  fFringeData(fdata),
31  fContainerStore(fdata->GetContainerStore() ),
32  fParameterStore(fdata->GetParameterStore() )
33  {
34  fFormat = control_format;
35  };
36 
38  {
39  for(std::size_t i = 0; i < fAllBuilders.size(); i++)
40  {
41  delete fAllBuilders[i];
42  }
43  fAllBuilders.clear();
44  fNameToBuilderMap.clear();
45  fCategoryToBuilderMap.clear();
46  }
47 
53  void SetControlStatements(mho_json* statements) { fControl = statements; };
54 
59  void CreateDefaultBuilders();
60 
66  void BuildOperatorCategory(const char* cat)
67  {
68  std::string scat(cat);
70  };
71 
77  void BuildOperatorCategory(const std::string& cat);
78 
84  std::size_t GetNBuildersInCategory(std::string cat);
85 
93  template< typename XBuilderType > void AddBuilderType(const std::string& builder_name, const std::string& format_key)
94  {
95  auto format_it = fFormat.find(format_key);
96  if(format_it != fFormat.end())
97  {
98  auto it = fNameToBuilderMap.find(builder_name);
99  if(it == fNameToBuilderMap.end()) //not found, so make one
100  {
101  auto builder = new XBuilderType(fOperatorToolbox, fFringeData);
102  builder->SetFormat(fFormat[format_key]);
103 
104  //the builder's operator category comes from the format specification
105  std::string category = "unknown"; //default's to unknown
106  if(format_it->contains("operator_category"))
107  {
108  category = (*format_it)["operator_category"].get< std::string >();
109  }
110  fAllBuilders.push_back(builder);
111  fNameToBuilderMap.emplace(builder_name, builder);
112  fCategoryToBuilderMap.emplace(category, builder);
113  }
114  }
115  else
116  {
117  msg_error("initialization", "cannot add builder for operator with format key: " << format_key << eom);
118  }
119  };
120 
121  private:
125  void CreateNullFormatBuilders();
126 
134  template< typename XBuilderType > void AddBuilderTypeWithFormat(const std::string& builder_name, const mho_json& format)
135  {
136  auto it = fNameToBuilderMap.find(builder_name);
137  if(it == fNameToBuilderMap.end()) //not found, so make one
138  {
139  // auto builder = new XBuilderType(fOperatorToolbox, fContainerStore, fParameterStore);
140  auto builder = new XBuilderType(fOperatorToolbox, fFringeData);
141  builder->SetFormat(format);
142 
143  //the builder's operator category comes from the format specification
144  std::string category = "unknown"; //default's to unknown
145  if(format.contains("operator_category"))
146  {
147  category = format["operator_category"].get< std::string >();
148  }
149  fAllBuilders.push_back(builder);
150  fNameToBuilderMap.emplace(builder_name, builder);
151  fCategoryToBuilderMap.emplace(category, builder);
152  }
153  };
154 
155  //internal data
156  mho_json fFormat; //control file statement formats
157  mho_json* fControl; //control file statements
158 
159  //constructed operators all get stashed here
160  MHO_OperatorToolbox* fOperatorToolbox;
161 
162  //data container and parameter stores
163  MHO_FringeData* fFringeData;
164  MHO_ContainerStore* fContainerStore;
165  MHO_ParameterStore* fParameterStore;
166 
167  //container to store all of the builders, for memory management
168  std::vector< MHO_OperatorBuilder* > fAllBuilders;
169 
170  //name -> builder map for lookup by name
171  std::map< std::string, MHO_OperatorBuilder* > fNameToBuilderMap;
172 
173  //operator category -> builder multimap for lookup by category
174  std::multimap< std::string, MHO_OperatorBuilder* > fCategoryToBuilderMap;
175 };
176 
177 } // namespace hops
178 
179 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
Class MHO_FringeData.
Definition: MHO_FringeData.hh:30
Manages all the various operator builders.
Definition: MHO_OperatorBuilderManager.hh:24
void BuildOperatorCategory(const char *cat)
Builds operator category from input string and calls BuildOperatorCategory with it.
Definition: MHO_OperatorBuilderManager.hh:66
void CreateDefaultBuilders()
Registers default operator builders for various purposes such as channel labeling,...
Definition: MHO_OperatorBuilderManager.cc:36
void AddBuilderType(const std::string &builder_name, const std::string &format_key)
Adds a new builder type with specified format, inserted into (builder) map for later use.
Definition: MHO_OperatorBuilderManager.hh:93
virtual ~MHO_OperatorBuilderManager()
Definition: MHO_OperatorBuilderManager.hh:37
MHO_OperatorBuilderManager(MHO_OperatorToolbox *toolbox, MHO_FringeData *fdata, mho_json control_format)
Definition: MHO_OperatorBuilderManager.hh:26
void SetControlStatements(mho_json *statements)
pass in parsed control file elements
Definition: MHO_OperatorBuilderManager.hh:53
std::size_t GetNBuildersInCategory(std::string cat)
return the number of operator builders in the specified category
Definition: MHO_OperatorBuilderManager.cc:26
Class MHO_OperatorToolbox.
Definition: MHO_OperatorToolbox.hh:26
Definition: MHO_ChannelLabeler.hh:17