evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtModel.cpp
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
21 #include "EvtGenBase/EvtModel.hh"
22 
24 #include "EvtGenBase/EvtPDL.hh"
25 #include "EvtGenBase/EvtParser.hh"
28 #include "EvtGenBase/EvtPatches.hh"
29 #include "EvtGenBase/EvtRandom.hh"
30 #include "EvtGenBase/EvtReport.hh"
31 
32 #include <assert.h>
33 #include <ctype.h>
34 #include <fstream>
35 #include <iomanip>
36 #include <iostream>
37 #include <stdlib.h>
38 #include <string>
39 using std::fstream;
40 
42 
44 {
45 }
46 
47 EvtDecayBase* EvtModel::getFcn( std::string model_name )
48 {
49  EvtDecayBase* model = 0;
50  if ( _modelNameHash.find( model_name ) != _modelNameHash.end() ) {
51  model = _modelNameHash[model_name];
52  }
53 
54  if ( model == 0 ) {
55  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
56  << "Did not find the right model:" << model_name.c_str() << "\n";
57  return 0;
58  }
59 
60  return model->clone();
61 }
62 
64 {
65  std::string modelName = prototype->getName();
66 
67  _modelNameHash[modelName] = prototype;
68 
69  std::string commandName = prototype->commandName();
70 
71  if ( commandName != "" ) {
72  _commandNameHash[commandName] = prototype;
73  }
74 }
75 
76 int EvtModel::isModel( std::string model_name )
77 {
78  if ( _modelNameHash.find( model_name ) != _modelNameHash.end() ) {
79  return 1;
80  }
81  return 0;
82 }
83 
84 int EvtModel::isCommand( std::string cmd )
85 {
86  if ( _commandNameHash.find( cmd ) != _commandNameHash.end() ) {
87  return 1;
88  }
89  return 0;
90 }
91 
92 void EvtModel::storeCommand( std::string cmd, std::string cnfgstr )
93 {
94  EvtDecayBase* model = 0;
95  if ( _commandNameHash.find( cmd ) != _commandNameHash.end() ) {
96  model = _commandNameHash[cmd];
97  }
98 
99  assert( model != 0 );
100 
101  model->command( cnfgstr );
102 }
virtual std::string commandName()
EvtDecayBase * getFcn(std::string model_name)
Definition: EvtModel.cpp:47
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
void registerModel(EvtDecayBase *prototype)
Definition: EvtModel.cpp:63
std::map< std::string, EvtDecayBase * > _modelNameHash
Definition: EvtModel.hh:52
std::map< std::string, EvtDecayBase * > _commandNameHash
Definition: EvtModel.hh:53
virtual std::string getName()=0
virtual EvtDecayBase * clone()=0
virtual void command(std::string cmd)
void storeCommand(std::string cmd, std::string cnfgstr)
Definition: EvtModel.cpp:92
int isCommand(std::string cmd)
Definition: EvtModel.cpp:84
static EvtModel * _instance
Definition: EvtModel.hh:50
int isModel(std::string name)
Definition: EvtModel.cpp:76
EvtModel()
Definition: EvtModel.cpp:43