00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SEQMETH_H
00019 #define SEQMETH_H
00020
00021 #include <tjutils/tjstate.h>
00022 #include <tjutils/tjhandler.h>
00023
00024 #include <odinpara/protocol.h>
00025
00026 #include <odinseq/seqlist.h>
00027 #include <odinseq/seqplatform.h>
00028
00029
00031
00032
00033 class SeqMethod;
00034 class SeqPulsar;
00035
00036
00038
00039
00044 class SeqMethodProxy : public StaticHandler<SeqMethodProxy> {
00045
00046
00047 public:
00048 SeqMethodProxy() {
00049 Log<Seq> odinlog("SeqMethodProxy","SeqMethodProxy()");
00050 }
00051
00052 static void set_current_method(unsigned int index);
00053 static SeqMethod* get_current_method();
00054 static unsigned int get_numof_methods();
00055 static unsigned int delete_methods();
00056 static const char* get_method_label();
00057
00058 static const char* get_status_string();
00059
00060
00061 SeqMethod* operator -> () {return get_current_method();}
00062 SeqMethod& operator [] (unsigned int index);
00063
00064 static bool load_method_so(const STD_string& so_filename);
00065
00066
00067 static void init_static();
00068 static void destroy_static();
00069
00070
00071 protected:
00072
00073
00074 static void register_method(SeqMethod* meth);
00075
00076
00077 private:
00078
00079
00080 struct MethodList : public STD_list<SeqMethod*>, public Labeled {};
00081
00082 static SingletonHandler<MethodList,false> registered_methods;
00083
00084
00085
00086 struct MethodPtr : public Labeled {
00087 SeqMethod* ptr;
00088 };
00089
00090 static SingletonHandler<MethodPtr,false> current_method;
00091
00092 static SeqMethod* empty_method;
00093
00094
00095 };
00096
00097
00098
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00155 class SeqMethod : protected SeqMethodProxy, public SeqObjList, public virtual JDXeditCaller, public StateMachine<SeqMethod> {
00156
00157
00158 public:
00159
00163 SeqMethod(const STD_string& method_label);
00164
00168 virtual ~SeqMethod();
00169
00170
00171
00175 bool clear() {return empty.obtain_state();}
00176
00180 bool init() {return initialised.obtain_state();}
00181
00185 bool build() {return built.obtain_state();}
00186
00190 bool prepare() {return prepared.obtain_state();}
00191
00197 bool update_timings();
00198
00205 bool prep_acquisition() const;
00206
00207
00211 const char* get_description() const {return description.c_str();}
00212
00216 int process(int argc, char *argv[]);
00217
00218
00222 int load_protocol(const STD_string& filename);
00223
00227 int write_protocol(const STD_string& filename) const {create_protcache(); return protcache->write(filename);}
00228
00229
00233 JcampDxBlock& get_methodPars() {return *methodPars;}
00234
00238 int load_sequencePars(const STD_string& filename);
00239
00243 int write_sequencePars(const STD_string& filename) const;
00244
00249 bool set_sequenceParameter(const STD_string& parameter_label, const STD_string& value);
00250
00254 SeqMethod& set_commonPars(const SeqPars& pars);
00255
00259 SeqPars& get_commonPars() {return (*commonPars);}
00260
00264 SeqMethod& set_geometry(const Geometry& geo) {geometryInfo->operator = (geo); return *this;}
00265
00269 Geometry& get_geometry() {return *(geometryInfo.unlocked_ptr());}
00270
00274 int load_geometry(const STD_string& filename) {return geometryInfo->load(filename);}
00275
00279 int write_geometry(const STD_string& filename) const {return geometryInfo->write(filename);}
00280
00284 Study& get_studyInfo() {return *(studyInfo.unlocked_ptr());}
00285
00289 int write_systemInfo(const STD_string& filename) const {return systemInfo->write(filename);}
00290
00294 int load_systemInfo(const STD_string& filename);
00295
00299 SeqMethod& init_systemInfo(double basicfreq,double maxgrad,double slewrate);
00300
00304 int write_recoInfo(const STD_string& filename) const;
00305
00309 int write_meas_contex(const STD_string& prefix) const;
00310
00314 double get_totalDuration() const;
00315
00319 STD_string get_main_nucleus() const {return systemInfo->get_main_nucleus();}
00320
00324 unsigned int get_numof_acquisitions() const;
00325
00330 STD_list<const SeqPulsar*> get_active_pulsar_pulses() const;
00331
00332
00333 unsigned int event(eventContext& context) const;
00334
00335
00336 void set_current_testcase(unsigned int index) {if(index<numof_testcases()) current_testcase=index;}
00337
00338
00339 protected:
00340
00345 virtual void method_pars_init() = 0;
00346
00351 virtual void method_seq_init() = 0;
00352
00358 virtual void method_rels() = 0;
00359
00364 virtual void method_pars_set() = 0;
00365
00366
00370 SeqMethod& append_parameter(JcampDxClass& ldr,const STD_string& label,parameterMode parmode=edit);
00371
00375 SeqMethod& set_sequence(const SeqObjBase& s);
00376
00377
00381 SeqMethod& set_description(const char* descr) {description=descr;return *this;}
00382
00383
00388 virtual unsigned int numof_testcases() const {return 1;}
00389
00394 unsigned int get_current_testcase() const {return current_testcase;}
00395
00396
00400 SeqPars* commonPars;
00401
00402 private:
00403 friend class SeqMethodProxy;
00404 friend class SeqCmdLine;
00405
00406 void set_parblock_labels();
00407
00408 bool calc_timings();
00409
00410
00411
00412 void parameter_relations(JDXeditWidget* editwidget);
00413
00414
00415 mutable SeqPlatformProxy platform;
00416
00417
00418 JcampDxBlock* methodPars;
00419
00420 STD_string description;
00421
00422 unsigned int current_testcase;
00423
00424
00425
00426 void *dl_handle;
00427
00428
00429 void create_protcache() const;
00430 mutable Protocol* protcache;
00431
00432
00433
00434
00435
00436 State<SeqMethod> empty;
00437 bool reset();
00438
00439 State<SeqMethod> initialised;
00440 bool empty2initialised();
00441
00442 State<SeqMethod> built;
00443 bool initialised2built();
00444
00445 State<SeqMethod> prepared;
00446 bool built2prepared();
00447 };
00448
00450
00451
00452
00453
00454 #define ODINMETHOD_STRINGIZE_MACRO(x) #x
00455 #define ODINMETHOD_STRINGIZE(x) ODINMETHOD_STRINGIZE_MACRO(x)
00456
00457
00458 #ifdef NO_CMDLINE
00459
00460 #define ODINMETHOD_ENTRY_POINT \
00461 int ODINMAIN(int argc, char *argv[]) {\
00462 return (new METHOD_CLASS(ODINMETHOD_STRINGIZE(METHOD_LABEL)))->process(argc,argv); \
00463 }
00464
00465 #else
00466
00467 #define ODINMETHOD_ENTRY_POINT \
00468 int ODINMAIN(int argc, char *argv[]) {\
00469 if(LogBase::set_log_levels(argc,argv,false)) return 0; \
00470 return (new METHOD_CLASS(ODINMETHOD_STRINGIZE(METHOD_LABEL)))->process(argc,argv); \
00471 }
00472
00473 #endif
00474
00475
00476 #endif