controller.h
1 /***************************************************************************
2  controller.h - description
3  -------------------
4  begin : Sat Dec 30 2006
5  copyright : (C) 2000-2015 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 
38 class RecoReaderInterface; // forward declaration
39 class RecoStep; // forward declaration
40 
41 
42 
44 
45 
50 
51  public:
52 
56  RecoController(LDRblock& parblock);
57 
58  ~RecoController();
59 
64  bool init(RecoReaderInterface* reader, LDRblock& opts, int argc, char* argv[]);
65 
71  bool start();
72 
76  dvector dim_values(recoDim dim) const;
77 
82  TinyVector<float,3> reloffset() const;
83 
87  STD_string image_proc() const;
88 
93  TinyVector<int,3> image_size() const;
94 
98  TinyVector<float,3> kspace_extent() const;
99 
103  const Protocol& protocol() const {return prot_cache;}
104 
105 
109  void announce_data(const STD_string& label) {blackboard.announce(label);}
110 
114  void post_data(const STD_string& label, const RecoData& data) {blackboard.post(label,data);}
115 
119  bool data_announced(const STD_string& label) {return blackboard.announced(label);}
120 
126  bool inquire_data(const STD_string& label, RecoData& data);
127 
128 
134  const CoordCountMap* create_count_map(const RecoCoord& mask) const;
135 
141  bool create_numof(const RecoCoord& mask, unsigned short numof[n_recoDims], STD_string& printed) const;
142 
143 
149  RecoStep* create_pipeline(const STD_string& rec, const RecoCoord* initial_coord=0, int argc=0, char* argv[]=0) const;
150 
151 
155  STD_string stepmanual() const;
156 
157 
158  private:
159  friend class RecoThread;
160 
161 
162  // Options
163  LDRint jobs;
164  LDRstring recipe;
165  LDRstring recipeFile;
166  LDRstring select;
167  LDRint timeout;
168  LDRint maxrecursion;
169  LDRbool conjPhaseFT;
170  LDRbool slidingWindow;
171  LDRbool keyhole;
172  LDRbool sepChannels;
173  LDRbool dumpKspace;
174  LDRbool dumpGrappaTemplate;
175  LDRbool disablePhaseCorr;
176  LDRbool disableHomodyne;
177  LDRbool disableMultiFreq;
178  LDRbool disableDriftCorr;
179  LDRbool disableSliceTime;
180  LDRbool disableGrappa;
181  LDRbool phaseCourse;
182  LDRbool qcspike;
183  LDRstring preproc3d;
184  LDRstring postproc3d;
185  LDRstring dumpRawPrefix;
186  LDRstring fieldmapFile;
187 // LDRstring driftcorrFile;
188  LDRstring driftcorrSel;
189 
190  bool execute_pipeline();
191  bool prepare_pipeline();
192  bool finalize_pipeline();
193 
194  bool feed_pipeline();
195 
196  bool dump_raw() const;
197 
198  static void tracefunction(const LogMessage& msg);
199  static int controlthread;
200 
201  template<recoDim Dim, recoDim OrthoDim>
202  bool get_kspace_sampling_pattern(const RecoCoord& mask, unsigned int& reduction_factor, bool& partial_fourier, bool& half_fourier) const;
203 
204  bool autorecipe(const RecoCoord& mask, STD_string& result) const;
205 
206  bool create_selection_map(const STD_string& selstr, STD_map<recoDim,unsigned short>& selmap, RecoCoord* initcoord=0) const;
207 
208  typedef STD_map<int, STD_string> WaitingMap;
209  WaitingMap waiting;
210  STD_string waiting_error;
211  Mutex waiting_mutex;
212 
213  void incr_waiting_threads(const STD_string& condition) {MutexLock lock(waiting_mutex); waiting[Thread::self()]=condition;}
214  void decr_waiting_threads() {MutexLock lock(waiting_mutex); waiting.erase(waiting.find(Thread::self()));}
215  unsigned int numof_waiting_threads() {MutexLock lock(waiting_mutex); return waiting.size();}
216 
217  STD_map<int, UInt> thread_depth; // trace the depth (recursion level) of each thread
218 
219  RecoReaderInterface* input;
220  mutable Mutex inputmutex;
221 
222  RecoStep* pipeline;
223  RecoStepFactory* factory;
224 
225  RecoBlackBoard blackboard;
226 
227  ProgressDisplayConsole display; // Create display before pmeter
228  ProgressMeter pmeter; // ProgressMeter is thread-safe
229 
230 
231  unsigned short numof_cache[n_recoDims];
232  mutable bool has_readoutshape;
233  mutable unsigned char has_flag_cache;
234  mutable bool has_templcorr_cache[n_templateTypes];
235  mutable bool has_navigator_cache[n_navigatorTypes];
236  mutable bool has_traj;
237  mutable bool has_oversampling_cache;
238  mutable bool has_relcenter_cache;
239 
240  Protocol prot_cache;
241 
242  volatile bool status; // Although it is used in different threads, we will assume that reads/writes to bool are atomic
243 
244  mutable STD_map<STD_string,const CoordCountMap*> countmap_cache; // cache countmap since the same countmap is calculated several times in create_count_map()
245  void delete_countmap_cache();
246 
247 };
248 
249 
250 
255 #endif
256 
TinyVector< int, 3 > image_size() const
const CoordCountMap * create_count_map(const RecoCoord &mask) const
Definition: tjthread.h:46
bool inquire_data(const STD_string &label, RecoData &data)
bool init(RecoReaderInterface *reader, LDRblock &opts, int argc, char *argv[])
TinyVector< float, 3 > reloffset() const
TinyVector< float, 3 > kspace_extent() const
bool create_numof(const RecoCoord &mask, unsigned short numof[n_recoDims], STD_string &printed) const
STD_string stepmanual() const
STD_map< RecoCoord, UInt > CoordCountMap
Definition: index.h:364
void(* tracefunction)(const LogMessage &msg)
Definition: tjlog.h:98
const Protocol & protocol() const
Definition: controller.h:103
RecoController(LDRblock &parblock)
void announce_data(const STD_string &label)
Definition: controller.h:109
void post_data(const STD_string &label, const RecoData &data)
Definition: controller.h:114
bool data_announced(const STD_string &label)
Definition: controller.h:119
Protcol proxy.
Definition: protocol.h:33
dvector dim_values(recoDim dim) const
STD_string image_proc() const
void post(const STD_string &label, const RecoData &data)
void announce(const STD_string &label)
Definition: blackboard.h:49
static int self()
recoDim
Definition: reco.h:74
bool announced(const STD_string &label) const
Definition: blackboard.h:59
RecoStep * create_pipeline(const STD_string &rec, const RecoCoord *initial_coord=0, int argc=0, char *argv[]=0) const