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 <memory>
5 
6 #include "MHO_ContainerStore.hh"
7 #include "MHO_FringeData.hh"
9 #include "MHO_Message.hh"
10 #include "MHO_OperatorBuilder.hh"
11 #include "MHO_OperatorToolbox.hh"
12 #include "MHO_ParameterStore.hh"
13 
14 namespace hops
15 {
16 
26 {
27  public:
29  : fOperatorToolbox(toolbox), fFringeData(fdata), fContainerStore(fdata->GetContainerStore()),
30  fParameterStore(fdata->GetParameterStore())
31  {
32  fFormat = control_format;
33  };
34 
36 
42  void SetControlStatements(mho_json* statements) { fControl = statements; };
43 
48  void CreateDefaultBuilders();
49 
55  void BuildOperatorCategory(const char* cat)
56  {
57  std::string scat(cat);
59  };
60 
66  void BuildOperatorCategory(const std::string& cat);
67 
73  std::size_t GetNBuildersInCategory(std::string cat);
74 
82  template< typename XBuilderType > void AddBuilderType(const std::string& builder_name, const std::string& format_key)
83  {
84  auto format_it = fFormat.find(format_key);
85  if(format_it != fFormat.end())
86  {
87  auto it = fNameToBuilderMap.find(builder_name);
88  if(it == fNameToBuilderMap.end()) //not found, so make one
89  {
90  std::unique_ptr< XBuilderType > builder(new XBuilderType(fOperatorToolbox, fFringeData));
91  builder->SetFormat(fFormat[format_key]);
92 
93  //the builder's operator category comes from the format specification
94  std::string category = "unknown"; //default's to unknown
95  if(format_it->contains("operator_category"))
96  {
97  category = (*format_it)["operator_category"].get< std::string >();
98  }
99  auto* raw = builder.get();
100  fAllBuilders.push_back(std::move(builder));
101  fNameToBuilderMap.emplace(builder_name, raw);
102  fCategoryToBuilderMap.emplace(category, raw);
103  }
104  }
105  else
106  {
107  msg_error("initialization", "cannot add builder for operator with format key: " << format_key << eom);
108  }
109  };
110 
111  private:
115  void CreateNullFormatBuilders();
116 
124  template< typename XBuilderType > void AddBuilderTypeWithFormat(const std::string& builder_name, const mho_json& format)
125  {
126  auto it = fNameToBuilderMap.find(builder_name);
127  if(it == fNameToBuilderMap.end()) //not found, so make one
128  {
129  std::unique_ptr< XBuilderType > builder(new XBuilderType(fOperatorToolbox, fFringeData));
130  builder->SetFormat(format);
131 
132  //the builder's operator category comes from the format specification
133  std::string category = "unknown"; //default's to unknown
134  if(format.contains("operator_category"))
135  {
136  category = format["operator_category"].get< std::string >();
137  }
138  auto* raw = builder.get();
139  fAllBuilders.push_back(std::move(builder));
140  fNameToBuilderMap.emplace(builder_name, raw);
141  fCategoryToBuilderMap.emplace(category, raw);
142  }
143  };
144 
145  //internal data
146  mho_json fFormat; //control file statement formats
147  mho_json* fControl; //control file statements
148 
149  //constructed operators all get stashed here
150  MHO_OperatorToolbox* fOperatorToolbox;
151 
152  //data container and parameter stores
153  MHO_FringeData* fFringeData;
154  MHO_ContainerStore* fContainerStore;
155  MHO_ParameterStore* fParameterStore;
156 
157  // owned storage - unique_ptrs are the sole owners
158  std::vector< std::unique_ptr< MHO_OperatorBuilder > > fAllBuilders;
159 
160  //name -> builder map for lookup by name (non-owning)
161  std::map< std::string, MHO_OperatorBuilder* > fNameToBuilderMap;
162 
163  //operator category -> builder multimap for lookup by category (non-owning)
164  std::multimap< std::string, MHO_OperatorBuilder* > fCategoryToBuilderMap;
165 };
166 
167 } // namespace hops
168 
169 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_FringeData.
Definition: MHO_FringeData.hh:30
Manages all the various operator builders.
Definition: MHO_OperatorBuilderManager.hh:26
void BuildOperatorCategory(const char *cat)
Builds operator category from input string and calls BuildOperatorCategory with it.
Definition: MHO_OperatorBuilderManager.hh:55
void CreateDefaultBuilders()
Registers default operator builders for various purposes such as channel labeling,...
Definition: MHO_OperatorBuilderManager.cc:45
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:82
virtual ~MHO_OperatorBuilderManager()
Definition: MHO_OperatorBuilderManager.hh:35
MHO_OperatorBuilderManager(MHO_OperatorToolbox *toolbox, MHO_FringeData *fdata, mho_json control_format)
Definition: MHO_OperatorBuilderManager.hh:28
void SetControlStatements(mho_json *statements)
pass in parsed control file elements
Definition: MHO_OperatorBuilderManager.hh:42
std::size_t GetNBuildersInCategory(std::string cat)
return the number of operator builders in the specified category
Definition: MHO_OperatorBuilderManager.cc:32
Class MHO_OperatorToolbox.
Definition: MHO_OperatorToolbox.hh:28
Definition: MHO_AdhocFlagging.hh:18