ODIN
controller.h
1 /***************************************************************************
2  controller.h - description
3  -------------------
4  begin : Sat Dec 30 2006
5  copyright : (C) 2000-2021 by Thies 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 RECOCONTROLLER_H
19 #define RECOCONTROLLER_H
20 
21 #include <tjutils/tjthread.h>
22 #include <tjutils/tjfeedback.h>
23 
24 #include <odinreco/odinreco.h>
25 #include <odinreco/blackboard.h>
26 #include <odinreco/step.h>
27 
28 
29 
36 #define ODINRECO_THREAD_STACKSIZE 8*1024*1024 // 8 MB stack size
37 
38 
39 
40 class RecoReaderInterface; // forward declaration
41 class RecoStep; // forward declaration
42 
43 
44 
46 
47 
52 
53  public:
54 
59 
60  ~RecoController();
61 
66  bool init(RecoReaderInterface* reader, LDRblock& opts, int argc, char* argv[]);
67 
73  bool start();
74 
79 
84  TinyVector<float,3> reloffset() const;
85 
89  STD_string image_proc() const;
90 
95  TinyVector<int,3> image_size() const;
96 
100  TinyVector<float,3> kspace_extent() const;
101 
105  const Protocol& protocol() const {return prot_cache;}
106 
107 
111  void announce_data(const STD_string& label) {blackboard.announce(label);}
112 
116  void post_data(const STD_string& label, const RecoData& data) {blackboard.post(label,data);}
117 
121  bool data_announced(const STD_string& label) {return blackboard.announced(label);}
122 
129  bool inquire_data(const RecoStep& caller, const STD_string& label, RecoData& data);
130 
131 
137  const CoordCountMap* create_count_map(const RecoCoord& mask) const;
138 
144  bool create_numof(const RecoCoord& mask, unsigned short numof[n_recoDims], STD_string& printed) const;
145 
146 
152  RecoStep* create_pipeline(const STD_string& rec, const RecoCoord* initial_coord=0, int argc=0, char* argv[]=0) const;
153 
154 
158  STD_string stepmanual() const;
159 
160 
161  private:
162  friend class RecoThread;
163 
164 
165  // Options
166  LDRint jobs;
167  LDRstring recipe;
168  LDRstring recipeFile;
169  LDRstring select;
170  LDRint timeout;
171  LDRint maxrecursion;
172  LDRbool conjPhaseFT;
173  LDRbool slidingWindow;
174  LDRbool keyhole;
175  LDRbool sepChannels;
176  LDRbool dumpKspace;
177  LDRbool dumpGrappaTemplate;
178  LDRbool disablePhaseCorr;
179  LDRbool disableHomodyne;
180  LDRbool disableMultiFreq;
181  LDRbool disableDriftCorr;
182  LDRbool disableSliceTime;
183  LDRbool disableGrappa;
184  LDRbool phaseCourse;
185  LDRbool qcspike;
186  LDRstring preproc3d;
187  LDRstring postproc3d;
188  LDRstring dumpRawPrefix;
189  LDRstring fieldmapFile;
190 // LDRstring driftcorrFile;
191  LDRstring driftcorrSel;
192 
193  bool execute_pipeline();
194  bool prepare_pipeline();
195  bool finalize_pipeline();
196 
197  bool feed_pipeline();
198 
199  bool dump_raw() const;
200 
201  static void tracefunction(const LogMessage& msg);
202  static int controlthread;
203 
204  template<recoDim Dim, recoDim OrthoDim>
205  bool get_kspace_sampling_pattern(const RecoCoord& mask, unsigned int& reduction_factor, bool& partial_fourier, bool& half_fourier) const;
206 
207  bool autorecipe(const RecoCoord& mask, STD_string& result) const;
208 
209  bool create_selection_map(const STD_string& selstr, STD_map<recoDim,unsigned short>& selmap, RecoCoord* initcoord=0) const;
210 
211  typedef STD_map<int, STD_string> WaitingMap;
212  WaitingMap waiting;
213  STD_string waiting_error;
214  Mutex waiting_mutex;
215 
216  void incr_waiting_threads(const STD_string& condition) {MutexLock lock(waiting_mutex); waiting[Thread::self()]=condition;}
217  void decr_waiting_threads() {MutexLock lock(waiting_mutex); waiting.erase(waiting.find(Thread::self()));}
218  unsigned int numof_waiting_threads() {MutexLock lock(waiting_mutex); return waiting.size();}
219 
220  STD_map<int, UInt> thread_depth; // trace the depth (recursion level) of each thread
221  Mutex thread_depth_mutex;
222 
223  RecoReaderInterface* input;
224  mutable Mutex inputmutex;
225 
226  RecoStep* pipeline;
227  RecoStepFactory* factory;
228 
229  RecoBlackBoard blackboard;
230 
231  ProgressDisplayConsole display; // Create display before pmeter
232  ProgressMeter pmeter; // ProgressMeter is thread-safe
233 
234 
235  unsigned short numof_cache[n_recoDims];
236  mutable bool has_readoutshape;
237  mutable unsigned char has_flag_cache;
238  mutable bool has_templcorr_cache[n_templateTypes];
239  mutable bool has_navigator_cache[n_navigatorTypes];
240  mutable bool has_traj;
241  mutable bool has_oversampling_cache;
242  mutable bool has_relcenter_cache;
243 
244  Protocol prot_cache;
245 
246  volatile bool status; // Although it is used in different threads, we will assume that reads/writes to bool are atomic
247 
248  mutable STD_map<STD_string,const CoordCountMap*> countmap_cache; // cache countmap since the same countmap is calculated several times in create_count_map()
249  void delete_countmap_cache();
250 
251 };
252 
253 
254 
259 #endif
260 
Definition: tjthread.h:46
Protocol proxy.
Definition: protocol.h:33
bool announced(const STD_string &label) const
Definition: blackboard.h:59
void post(const STD_string &label, const RecoData &data)
void announce(const STD_string &label)
Definition: blackboard.h:49
RecoStep * create_pipeline(const STD_string &rec, const RecoCoord *initial_coord=0, int argc=0, char *argv[]=0) const
void announce_data(const STD_string &label)
Definition: controller.h:111
bool create_numof(const RecoCoord &mask, unsigned short numof[n_recoDims], STD_string &printed) const
TinyVector< float, 3 > kspace_extent() const
bool inquire_data(const RecoStep &caller, const STD_string &label, RecoData &data)
void post_data(const STD_string &label, const RecoData &data)
Definition: controller.h:116
dvector dim_values(recoDim dim) const
TinyVector< float, 3 > reloffset() const
bool data_announced(const STD_string &label)
Definition: controller.h:121
bool init(RecoReaderInterface *reader, LDRblock &opts, int argc, char *argv[])
const CoordCountMap * create_count_map(const RecoCoord &mask) const
RecoController(LDRblock &parblock)
STD_string image_proc() const
TinyVector< int, 3 > image_size() const
const Protocol & protocol() const
Definition: controller.h:105
STD_string stepmanual() const
static int self()
recoDim
Definition: reco.h:74
STD_map< RecoCoord, UInt > CoordCountMap
Definition: index.h:364
void(* tracefunction)(const LogMessage &msg)
Definition: tjlog.h:98