ODIN
seqmeth.h
1 /***************************************************************************
2  seqmeth.h - description
3  -------------------
4  begin : Thu Aug 9 2001
5  copyright : (C) 2000-2021 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SEQMETH_H
19 #define SEQMETH_H
20 
21 #include <tjutils/tjstate.h>
22 #include <tjutils/tjhandler.h>
23 
24 #include <odinpara/protocol.h>
25 
26 #include <odinseq/seqlist.h>
27 #include <odinseq/seqplatform.h>
28 
29 
31 
32 // forward declarations
33 class SeqMethod;
34 class SeqPulsar;
35 
36 
38 
39 
44 class SeqMethodProxy : public StaticHandler<SeqMethodProxy> {
45 
46 
47  public:
48  SeqMethodProxy() {
49  Log<Seq> odinlog("SeqMethodProxy","SeqMethodProxy()");
50  }
51 
52  static void set_current_method(unsigned int index);
53  static SeqMethod* get_current_method();
54  static unsigned int get_numof_methods();
55  static unsigned int delete_methods();
56  static const char* get_method_label();
57 
58  static const char* get_status_string();
59 
60  // pointer-like syntax to access current method
61  SeqMethod* operator -> () {return get_current_method();}
62  SeqMethod& operator [] (unsigned int index);
63 
64  static bool load_method_so(const STD_string& so_filename);
65 
66  // functions to initialize/delete static members by the StaticHandler template class
67  static void init_static();
68  static void destroy_static();
69 
70 
71  protected:
72 
73  // called by derivedmethod classes to register themselves
74  static void register_method(SeqMethod* meth);
75 
76 
77  private:
78 
79  // struct to store references to all registered methods
80  struct MethodList : public STD_list<SeqMethod*>, public Labeled {};
81 
82  static SingletonHandler<MethodList,false> registered_methods;
83 
84 
85  // struct to store references to the current method
86  struct MethodPtr : public Labeled {
87  SeqMethod* ptr;
88  };
89 
90  static SingletonHandler<MethodPtr,false> current_method;
91 
92  static SeqMethod* empty_method;
93 
94 
95 };
96 
97 
98 
100 
101 /*
102  State diagram for SeqMethod, i.e. for all NMR sequences:
103 
104  Possible transitions between states are indicated by
105  the corresponding member functions that perform the transition.
106 
107 
108  empty <--------\
109  |
110  | | clear()
111  | init() |
112  | |
113  V |
114  |
115  initialised ---|
116  |
117  | |
118  | build() |
119  | |
120  V |
121  |
122  built ---------|
123  |
124  | |
125  | prepare() |
126  | |
127  V |
128  |
129  prepared ------'
130 
131 */
132 
133 
134 
135 
155 class SeqMethod : protected SeqMethodProxy, public SeqObjList, public virtual LDReditCaller, public StateMachine<SeqMethod> {
156 
157 
158  public:
159 
163  SeqMethod(const STD_string& method_label);
164 
168  virtual ~SeqMethod();
169 
170  // public interface to obtain the different states:
171 
175  bool clear() {return empty.obtain_state();}
176 
180  bool init() {return initialised.obtain_state();}
181 
185  bool build() {return built.obtain_state();}
186 
190  bool prepare() {return prepared.obtain_state();}
191 
198 
205  bool prep_acquisition() const;
206 
207 
211  const char* get_description() const {return description.c_str();}
212 
216  int process(int argc, char *argv[]);
217 
218 
222  int load_protocol(const STD_string& filename);
223 
227  int write_protocol(const STD_string& filename) const {create_protcache(); return protcache->write(filename);}
228 
229 
233  LDRblock& get_methodPars() {return *methodPars;}
234 
238  int load_sequencePars(const STD_string& filename);
239 
243  int write_sequencePars(const STD_string& filename) const;
244 
249  bool set_sequenceParameter(const STD_string& parameter_label, const STD_string& value);
250 
255 
260 
264  SeqMethod& set_geometry(const Geometry& geo) {geometryInfo->operator = (geo); return *this;}
265 
269  Geometry& get_geometry() {return *(geometryInfo.unlocked_ptr());}
270 
274  int load_geometry(const STD_string& filename) {return geometryInfo->load(filename);}
275 
279  int write_geometry(const STD_string& filename) const {return geometryInfo->write(filename);}
280 
284  Study& get_studyInfo() {return *(studyInfo.unlocked_ptr());}
285 
289  int write_systemInfo(const STD_string& filename) const {return systemInfo->write(filename);}
290 
294  int load_systemInfo(const STD_string& filename);
295 
299  SeqMethod& init_systemInfo(double basicfreq,double maxgrad,double slewrate);
300 
304  int write_recoInfo(const STD_string& filename) const;
305 
309  int write_meas_contex(const STD_string& prefix) const;
310 
314  double get_totalDuration() const;
315 
319  STD_string get_main_nucleus() const {return systemInfo->get_main_nucleus();}
320 
324  unsigned int get_numof_acquisitions() const;
325 
330  STD_list<const SeqPulsar*> get_active_pulsar_pulses() const;
331 
332  // overloaded virtual functions from SeqTreeObj
333  unsigned int event(eventContext& context) const;
334 
335  // leave this public for idea_emulation
336  void set_current_testcase(unsigned int index) {if(index<numof_testcases()) current_testcase=index;}
337 
338 
339  protected:
340 
345  virtual void method_pars_init() = 0;
346 
351  virtual void method_seq_init() = 0;
352 
358  virtual void method_rels() = 0;
359 
364  virtual void method_pars_set() = 0;
365 
366 
370  SeqMethod& append_parameter(LDRbase& ldr,const STD_string& label,parameterMode parmode=edit);
371 
376 
377 
381  SeqMethod& set_description(const char* descr) {description=descr;return *this;}
382 
383 
388  virtual unsigned int numof_testcases() const {return 1;}
389 
394  unsigned int get_current_testcase() const {return current_testcase;}
395 
396 
401 
402  private:
403  friend class SeqMethodProxy;
404  friend class SeqCmdLine;
405 
406  void set_parblock_labels();
407 
408  bool calc_timings();
409 
410 
411  // overloaded virtual function from LDReditCaller
412  void parameter_relations(LDReditWidget* editwidget);
413 
414  // interface for quick access to current platform
415  mutable SeqPlatformProxy platform;
416 
417  // block to hold method-specific parameters
418  LDRblock* methodPars;
419 
420  STD_string description;
421 
422  unsigned int current_testcase;
423 
424 
425  // cache handle to method plug-in so that it can be removed later
426  void *dl_handle;
427 
428 
429  void create_protcache() const;
430  mutable Protocol* protcache; // used for returning reference to protocol, local static object does not work on VxWorks
431 
432 
433 
434  // states and their transition functions:
435 
436  State<SeqMethod> empty;
437  bool reset();
438 
439  State<SeqMethod> initialised;
440  bool empty2initialised();
441 
442  State<SeqMethod> built;
443  bool initialised2built();
444 
445  State<SeqMethod> prepared;
446  bool built2prepared();
447 };
448 
450 
451 // Macro to include in every sequence file to create an entry point
452 
453 // Double-stage macros to stringize METHOD_LABEL, see http://c-faq.com/ansi/stringize.html
454 #define ODINMETHOD_STRINGIZE_MACRO(x) #x
455 #define ODINMETHOD_STRINGIZE(x) ODINMETHOD_STRINGIZE_MACRO(x)
456 
457 
458 #ifdef NO_CMDLINE
459 
460 #define ODINMETHOD_ENTRY_POINT \
461 int ODINMAIN(int argc, char *argv[]) {\
462  return (new METHOD_CLASS(ODINMETHOD_STRINGIZE(METHOD_LABEL)))->process(argc,argv); \
463 }
464 
465 #else
466 
467 #define ODINMETHOD_ENTRY_POINT \
468 int ODINMAIN(int argc, char *argv[]) {\
469  if(LogBase::set_log_levels(argc,argv,false)) return 0; \
470  return (new METHOD_CLASS(ODINMETHOD_STRINGIZE(METHOD_LABEL)))->process(argc,argv); \
471 }
472 
473 #endif
474 
475 
476 #endif
Geometry Settings.
Definition: geometry.h:179
int load(const STD_string &filename, const LDRserBase &serializer=LDRserJDX())
int write(const STD_string &filename, const LDRserBase &serializer=LDRserJDX()) const
Definition: tjlog.h:218
Protocol proxy.
Definition: protocol.h:33
Base class for methods (sequences)
Definition: seqmeth.h:155
SeqMethod & append_parameter(LDRbase &ldr, const STD_string &label, parameterMode parmode=edit)
SeqPars & get_commonPars()
Definition: seqmeth.h:259
bool update_timings()
SeqMethod & set_description(const char *descr)
Definition: seqmeth.h:381
const char * get_description() const
Definition: seqmeth.h:211
virtual void method_pars_init()=0
SeqMethod & set_geometry(const Geometry &geo)
Definition: seqmeth.h:264
int write_protocol(const STD_string &filename) const
Definition: seqmeth.h:227
SeqMethod & set_sequence(const SeqObjBase &s)
LDRblock & get_methodPars()
Definition: seqmeth.h:233
Study & get_studyInfo()
Definition: seqmeth.h:284
unsigned int event(eventContext &context) const
bool prep_acquisition() const
SeqPars * commonPars
Definition: seqmeth.h:400
STD_list< const SeqPulsar * > get_active_pulsar_pulses() const
SeqMethod & init_systemInfo(double basicfreq, double maxgrad, double slewrate)
int load_geometry(const STD_string &filename)
Definition: seqmeth.h:274
virtual ~SeqMethod()
unsigned int get_numof_acquisitions() const
bool set_sequenceParameter(const STD_string &parameter_label, const STD_string &value)
SeqMethod(const STD_string &method_label)
unsigned int get_current_testcase() const
Definition: seqmeth.h:394
int write_recoInfo(const STD_string &filename) const
virtual void method_rels()=0
virtual void method_seq_init()=0
int load_sequencePars(const STD_string &filename)
int process(int argc, char *argv[])
bool init()
Definition: seqmeth.h:180
SeqMethod & set_commonPars(const SeqPars &pars)
virtual void method_pars_set()=0
Geometry & get_geometry()
Definition: seqmeth.h:269
int write_sequencePars(const STD_string &filename) const
double get_totalDuration() const
STD_string get_main_nucleus() const
Definition: seqmeth.h:319
int write_meas_contex(const STD_string &prefix) const
int write_geometry(const STD_string &filename) const
Definition: seqmeth.h:279
int load_systemInfo(const STD_string &filename)
bool clear()
Definition: seqmeth.h:175
bool build()
Definition: seqmeth.h:185
int write_systemInfo(const STD_string &filename) const
Definition: seqmeth.h:289
int load_protocol(const STD_string &filename)
virtual unsigned int numof_testcases() const
Definition: seqmeth.h:388
bool prepare()
Definition: seqmeth.h:190
Container for sequence objects.
Definition: seqlist.h:87
Sequence Parameter proxy.
Definition: seqpars.h:35
Pulsar pulses, combines OdinPulse and SeqPulsNdim.
Definition: seqpulsar.h:41
T * unlocked_ptr()
Definition: tjhandler.h:196
Study information.
Definition: study.h:39
STD_string get_main_nucleus() const
Definition: system.h:143
parameterMode
Definition: ldrbase.h:44