45 #define G_ACCESS "GModels::operator[](std::string&)"
46 #define G_AT "GModels::at(int&)"
47 #define G_SET1 "GModels::set(int&, GModel&)"
48 #define G_SET2 "GModels::set(std::string&, GModel&)"
49 #define G_APPEND "GModels::append(GModel&)"
50 #define G_INSERT1 "GModels::insert(int&, GModel&)"
51 #define G_INSERT2 "GModels::insert(std::string&, GModel&)"
52 #define G_REMOVE1 "GModels::remove(int&)"
53 #define G_REMOVE2 "GModels::remove(std::string&)"
54 #define G_EXTEND "GModels::extend(GModels&)"
55 #define G_READ "GModels::read(GXml&)"
150 if (
this != &models) {
185 std::string msg =
"Model \""+name+
"\" not found in model container. "
186 "Please specify the name of an available model.";
212 std::string msg =
"Model \""+name+
"\" not found in model container. "
213 "Please specify the name of an available model.";
272 #if defined(G_RANGE_CHECK)
273 if (index < 0 || index >=
size()) {
296 #if defined(G_RANGE_CHECK)
297 if (index < 0 || index >=
size()) {
324 #if defined(G_RANGE_CHECK)
325 if (index < 0 || index >=
size()) {
332 if (inx != -1 && inx != index) {
334 "Attempt to set model with name \""+model.
name()+
"\" in model "
335 "container at index "+
gammalib::str(index)+
", but a model with "
337 " in the container. Every model in the model container needs a "
377 std::string msg =
"Model \""+name+
"\" not found in model container. "
378 "Please specify the name of an available model.";
384 if (inx != -1 && inx != index) {
386 "Attempt to set model with name \""+model.
name()+
"\" in model"
387 " container at index "+
gammalib::str(index)+
", but a model with"
388 " the same name exists already at index "+
gammalib::str(inx)+
389 " in the container.\n"
390 "Every model in the model container needs a unique name.";
426 "Attempt to append model with name \""+model.
name()+
"\" to model"
427 " container, but a model with the same name exists already at"
429 " Every model in the model container needs a unique name.";
462 #if defined(G_RANGE_CHECK)
470 if (index < 0 || index >=
size()) {
481 "Attempt to insert model with name \""+model.
name()+
"\" in model"
482 " container before index "+
gammalib::str(index)+
", but a model"
483 " with the same name exists already at index "+
gammalib::str(inx)+
484 " in the container.\n"
485 "Every model in the model container needs a unique name.";
522 std::string msg =
"Model \""+name+
"\" not found in model container. "
523 "Please specify the name of an available model.";
531 "Attempt to insert model with name \""+model.
name()+
"\" in model"
532 " container before index "+
gammalib::str(index)+
", but a model"
533 " with the same name exists already at index "+
gammalib::str(inx)+
534 " in the container.\n"
535 "Every model in the model container needs a unique name.";
563 #if defined(G_RANGE_CHECK)
564 if (index < 0 || index >=
size()) {
598 std::string msg =
"Model \""+name+
"\" not found in model container. "
599 "Please specify the name of an available model.";
629 int num = models.
size();
635 for (
int i = 0; i < num; ++i) {
641 "Attempt to append model with name \""+models[i]->name()+
642 "\" to model container, but a model with the same name"
645 "Every model in the model container needs a unique name.";
676 return (index != -1);
721 for (
int i = 0; i <
size(); ++i) {
780 for (
int i = 0; i < n; ++i) {
786 std::string type = src->
attribute(
"type");
799 std::string msg =
"Model type \""+type+
"\" unknown. The following "
800 "model types are available: "+registry.
content()+
801 ". Please specify one of the available model "
831 if (xml.
elements(
"source_library") == 0) {
839 for (
int i = 0; i <
size(); ++i) {
859 for (
int i = 0; i <
size(); ++i) {
884 for (
int i = 0; i <
size(); ++i) {
887 for (
int k = 0; k <
npars; ++k) {
888 pars.
attach(&((*model)[k]));
913 const bool& gradients)
const
919 for (
int i = 0; i <
size(); ++i) {
921 value +=
m_models[i]->eval(event, obs, gradients);
953 for (
int i = 0; i <
size(); ++i) {
955 values +=
m_models[i]->eval(obs, gradients);
981 result.append(
"=== GModels ===");
990 for (
int i = 0; i <
size(); ++i) {
1033 for (
int i = 0; i < models.
m_models.size(); ++i) {
1051 for (
int i = 0; i <
m_models.size(); ++i) {
1076 for (
int i = 0; i <
size(); ++i) {
Abstract XML node base class.
double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Evaluate sum of all models.
void copy_members(const GModels &models)
Copy class members.
Abstract model base class interface definition.
Sparse matrix class interface definition.
XML element node class interface definition.
void save(const GFilename &filename) const
Save XML document into file.
Interface definition for the model registry class.
virtual std::string instrument(void) const =0
void remove(const int &index)
Remove model from container.
Model container class definition.
void read(const GXml &xml)
Read models from XML document.
XML class interface definition.
GModels * clone(void) const
Clone instance.
GModels(void)
Void constructor.
GModel * operator[](const int &index)
Return pointer to model.
Optimizer parameter container class.
Abstract interface for the event classes.
void extend(const GModels &models)
Append model container.
GOptimizerPars pars(void) const
Return optimizer parameter container.
void save(const GFilename &filename) const
Save models into XML file.
virtual int elements(void) const
Return number of GXMLElement children of node.
void reserve(const int &num)
Reserves space for models in container.
void id(const std::string &id)
Set observation identifier.
GModel * insert(const int &index, const GModel &model)
Insert model into container.
int size(void) const
Return number of parameters in model.
void clear(void)
Clear object.
std::string content(void) const
Return list of names in registry.
std::vector< GModel * > m_models
List of models.
int get_index(const std::string &name) const
Return model index by name.
virtual void read(const GXmlElement &xml)=0
GXmlElement * element(const int &index)
Return pointer to child element.
int elements(void) const
Return number of child elements in XML document root.
void free_members(void)
Delete class members.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
const std::string & name(void) const
Return parameter name.
GModel * set(const int &index, const GModel &model)
Set model in container.
Optimizer parameters base class definition.
void attach(GOptimizerPar *par)
Attach parameter to container.
Abstract observation base class.
Vector class interface definition.
Abstract observation base class interface definition.
GModel * alloc(const std::string &name) const
Allocate model of given name.
virtual GModel * clone(void) const =0
Clones object.
std::string url(void) const
Return Uniform Resource Locator (URL)
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
void write(GXml &xml) const
Write models into XML document.
GModel * at(const int &index)
Return pointer to model.
void load(const GFilename &filename)
Load models from XML file.
bool contains(const std::string &name) const
Signals if model name exists.
Sparse matrix class definition.
std::string print(const GChatter &chatter=NORMAL) const
Print models.
void init_members(void)
Initialise class members.
virtual GEvents * events(void)
Return events.
Exception handler interface definition.
int npars(void) const
Return number of model parameters in container.
virtual ~GModels(void)
Destructor.
Model registry class definition.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
GModels & operator=(const GModels &models)
Assignment operator.
int size(void) const
Return number of models in container.
GModel * append(const GModel &model)
Append model to container.
Filename class interface definition.
GXmlNode * append(const GXmlNode &node)
Append child node to XML document root.
bool is_empty(void) const
Signals if there are no models in container.
virtual int size(void) const =0
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.