C++ mpi module for stochmagnet_main Package
CORE_Run.h
1 #ifndef CORE_Run_H
2 #define CORE_Run_H
3 
4 #include "CORE_Object.h"
5 
6 //output
7 #include "CORE_Out.h"
8 
9 //class factory
10 #include "CORE_ClassFactory.h"
11 
12 //list of options header
13 #include "CORE_OptionsList.h"
14 
15 //options of the program
16 #include "CORE_Options.h"
17 
18 
44 class CORE_Run : public virtual CORE_Object {
45 
46  //attributes
47 private :
48 
49  //name of the soft
50  static tString mSoftName;
51 
52  //version of the progam
53  static tString mVersion;
54 
55  //options class name
56  tString mOptionsClassName;
57 
58  //output
59  static CORE_UniquePointer<CORE_Out> mOut;
60 
61  //class factory
62  static CORE_UniquePointer<CORE_ClassFactory> mClassFactory;
63 
64 
65 
66 public:
67  // CONSTRUCTORS
70  CORE_Run(void);
71 
72  // DESTRUCTORS
75  virtual ~CORE_Run(void);
76 
77 
78 
79 public :
80  // CREATE class
81 
89  virtual tMemSize getMemorySize() const override {
90  return sizeof(*this)+getContentsMemorySize();
91  }
100  virtual tMemSize getContentsMemorySize() const override {
101  return mOut->getMemorySize()+mClassFactory->getMemorySize();
102  }
103 
104  //SET & GET methods
105 public:
109  inline static void SetSoftName(const tString& soft) {
110  mSoftName=soft;
111  }
115  inline static const tString& GetSoftName() {
116  return mSoftName;
117  }
118 
123  inline static void SetVersion(const tString& version) {
124  mVersion=version;
125  }
129  inline static const tString& GetVersion() {
130  return mVersion;
131  }
132 
136  inline void setOptionsClassName(const tString& c) {
137  mOptionsClassName=c;
138  }
139 
140 
141 
142 
143 
144  //system methods
145  //===============
146 
150  inline static tBoolean Is64Architecture() {
151  return (sizeof(tLDouble)==16);
152  }
153 
157  inline static tBoolean Is32Architecture() {
158  return (sizeof(tLDouble)==8);
159  }
160 
161  //initialization of global variables
162  //=================================
163 
167  inline static void InitSeed(const unsigned int& seed) {
168  std::srand(seed);
169  }
172  inline static void InitSeed() {
173  std::srand(time(NULL));
174  }
175 
176 
177 public:
178 
179  //output methods
180  //==============
184  inline static CORE_Out& Out() {
185  return *mOut.get();
186  }
190  inline static CORE_Out& getOut() {
191  return *mOut.get();
192  }
193 
194 
195 
196 
197  //options methods
198  //===============
199 
200 
204  inline void initOptions(CORE_OptionsList& options) const {
205  CORE_UniquePointer<CORE_Options> optionsCL=GetClassFactory().NewInstance<CORE_Options>(mOptionsClassName);
206  if (optionsCL.get()!=null) {
207  optionsCL->initOptions(options);
208  optionsCL->initManOptions(options);
209  }
210 
211  }
212 
213 
214 
215 
216 
217  //classes factory
218  //===============
222  virtual void createClassFactories(const CORE_OptionsList& options) const;
223 
228  return *mClassFactory.get();
229  }
230 
231  //Options methods
232  //================
233 
239  static tString ReadPath(const CORE_OptionsList& options,
240  const tString& optName);
241 
247  static void ReadOutputOptions(const CORE_OptionsList& options,
248  tString& outputPath,
249  tString& outputPrefix);
250 
256  static void ReadInputOptions(const CORE_OptionsList& options,
257  tString& inputPath,
258  tString& inputPrefix);
259 
263  static void SetLogOptions(const CORE_OptionsList& options) ;
264 
268  virtual void setLogOptions(const CORE_OptionsList& options) const {
269  CORE_Run::SetLogOptions(options);
270  }
271 
275  inline static void SetDebugOptions(const CORE_OptionsList& options) {
276  tBoolean isMemoryChecked=false;
277  options.getOptionValue("check-memory",isMemoryChecked);
278  if (isMemoryChecked && (!CORE_Object::EnableMemoryStack(isMemoryChecked))) {
279  std::cout<<"memory checked is forced to be disabled because of release mode / OpenMP module \n";
280  }
281  options.getOptionValue("is-profiling-printed",CORE_Profiler::IS_PROFILING_ROUTINE_PRINTED);
282 
283 
284  }
285 
286  // Make Methods
287  //============
288 
289 
293  virtual void getManCommands(std::map<tString,tString>& commandsMan) const {
294  commandsMan["make run"]="run the program";
295  commandsMan["make tests"]="run the tests";
296  commandsMan["make help"]="show the help";
297  }
298 
299 
305  tBoolean executeRun(int argc,char* argv[]) const;
306 
312  virtual tBoolean makeRun(const tString& command,const CORE_OptionsList& options) const;
313 
314 
315 
320  virtual tBoolean makeTests(const CORE_OptionsList& options) const;
321 
326  virtual tBoolean printHelp(const CORE_OptionsList& options) const;
327 
328 
329 
330 
331 
332 
333 
334 };
335 
336 
337 #endif
this class describes a class factory to generate classes
Definition: CORE_ClassFactory.h:24
virtual CORE_UniquePointer< CORE_Object > NewInstance(const tString &name, const CORE_OptionsList &arguments) const
create an unique instance of a class as a general CORE_Object
Definition: CORE_ClassFactory.cpp:18
abstract base class for most classes.
Definition: CORE_Object.h:65
static void EnableMemoryStack()
enable the memory stack
Definition: CORE_Object.h:191
This class is an list of options.
Definition: CORE_OptionsList.h:36
tBoolean getOptionValue(const tString &optName, tString &optValue) const
get the option value
Definition: CORE_OptionsList.h:334
This class is the options of the runner.
Definition: CORE_Options.h:21
virtual void initOptions(CORE_OptionsList &options) const
default initialization of the options
Definition: CORE_Options.h:123
this class describes the output stream by default write on standart output
Definition: CORE_Out.h:28
static tBoolean IS_PROFILING_ROUTINE_PRINTED
indicates if the enter & leaving of method is printed on screen
Definition: CORE_Profiler.h:33
This class is a Run class for core package.
Definition: CORE_Run.h:44
static void InitSeed()
init the seed for uniform random generator
Definition: CORE_Run.h:172
virtual void getManCommands(std::map< tString, tString > &commandsMan) const
return the man of commands
Definition: CORE_Run.h:293
static void ReadOutputOptions(const CORE_OptionsList &options, tString &outputPath, tString &outputPrefix)
read the output path &prefix from options
Definition: CORE_Run.cpp:354
virtual ~CORE_Run(void)
destroy
Definition: CORE_Run.cpp:31
virtual tBoolean printHelp(const CORE_OptionsList &options) const
print the help
Definition: CORE_Run.cpp:209
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: CORE_Run.h:89
static tBoolean Is64Architecture()
return true if the machine is a 64 bits machine
Definition: CORE_Run.h:150
static CORE_ClassFactory & GetClassFactory()
return the class factory
Definition: CORE_Run.h:227
static CORE_Out & getOut()
return the output stream
Definition: CORE_Run.h:190
static void SetVersion(const tString &version)
set the version
Definition: CORE_Run.h:123
void setOptionsClassName(const tString &c)
set the options class name
Definition: CORE_Run.h:136
virtual tMemSize getContentsMemorySize() const override
return the memory size in byte
Definition: CORE_Run.h:100
static tBoolean Is32Architecture()
return true if the machine is a 32 bits machine
Definition: CORE_Run.h:157
static void SetSoftName(const tString &soft)
set soft name
Definition: CORE_Run.h:109
virtual tBoolean makeTests(const CORE_OptionsList &options) const
make tests command
Definition: CORE_Run.cpp:198
static void ReadInputOptions(const CORE_OptionsList &options, tString &inputPath, tString &inputPrefix)
read the input path & prefix from options
Definition: CORE_Run.cpp:376
virtual void createClassFactories(const CORE_OptionsList &options) const
create the class factories from options
Definition: CORE_Run.cpp:42
virtual void setLogOptions(const CORE_OptionsList &options) const
Definition: CORE_Run.h:268
static const tString & GetSoftName()
get soft name
Definition: CORE_Run.h:115
static CORE_Out & Out()
return the output stream
Definition: CORE_Run.h:184
static void InitSeed(const unsigned int &seed)
init the seed for uniform random generator
Definition: CORE_Run.h:167
tBoolean executeRun(int argc, char *argv[]) const
run the program from main class
Definition: CORE_Run.cpp:50
static tString ReadPath(const CORE_OptionsList &options, const tString &optName)
read the path from options with optName
Definition: CORE_Run.cpp:329
virtual tBoolean makeRun(const tString &command, const CORE_OptionsList &options) const
make Run command
Definition: CORE_Run.cpp:191
void initOptions(CORE_OptionsList &options) const
default initialization of the options
Definition: CORE_Run.h:204
static void SetDebugOptions(const CORE_OptionsList &options)
set the log options
Definition: CORE_Run.h:275
CORE_Run(void)
create
Definition: CORE_Run.cpp:25
static const tString & GetVersion()
get the version
Definition: CORE_Run.h:129
static void SetLogOptions(const CORE_OptionsList &options)
Definition: CORE_Run.cpp:256