00001 /* -*- mode: c++ -*- */ 00002 #ifndef __DAQpp_RunManager_h__ 00003 #define __DAQpp_RunManager_h__ 00004 00005 #include <functional> 00006 #include <algorithm> 00007 #include <DAQ++/DAQObject.h> 00008 #include <DAQ++/RunCommand.h> 00009 #include <DAQ++/Module.h> 00010 #include <DAQ++/exception.h> 00011 #include <DAQ++/Monitor.h> 00012 00013 namespace DAQpp 00014 { 00015 00072 class RunManager : public DAQObject 00073 { 00074 private: 00076 static unsigned long cntr; 00078 RunCommand *cmd; 00080 Monitor *monitor; 00082 bool active; 00083 00085 bool has_to_stop; 00086 00095 int mxEvts; 00096 00098 void init(); 00099 00101 Mutex theCondition; 00102 00103 protected: 00105 int run_number; 00107 int event_number; 00108 00109 public: 00116 RunManager(RunCommand *rc = 0); 00118 RunManager(const DAQid &, RunCommand *rc = 0); 00120 virtual ~RunManager(); 00121 00122 00124 void set_run_number(int x) 00125 { 00126 run_number = x; 00127 } 00129 int get_run_number() const 00130 { 00131 return run_number; 00132 } 00134 int get_event_number() const 00135 { 00136 return event_number; 00137 } 00138 00139 //--------------------------------------------------------------------- 00140 // Module handling 00141 //--------------------------------------------------------------------- 00143 RunCommand *operator()() 00144 { 00145 return cmd; 00146 } 00148 void addModule(Module *o); 00149 00151 void deleteModule(Module *o); 00152 00154 void deleteModules(); 00155 00157 int countModules() 00158 { 00159 return cmd->countObservers(); 00160 } 00161 00163 static void moveModules(RunManager *from, RunManager *to); 00164 00166 template <class _Function> 00167 _Function for_each_module(_Function __f) 00168 { 00169 return cmd->for_each_observer(__f); 00170 } 00171 00172 //--------------------------------------------------------------------- 00173 // DAQ commands 00174 //--------------------------------------------------------------------- 00176 void PrepareToStop(bool z) 00177 { 00178 has_to_stop = z; 00179 } 00180 00182 bool HaveToStop() const 00183 { 00184 return has_to_stop; 00185 } 00186 00188 bool isActive() const 00189 { 00190 return active; 00191 } 00192 00194 void deActivate(); 00195 00197 void Activate(); 00198 00204 void set_MxEvts(int n) 00205 { 00206 mxEvts = n; 00207 } 00208 00210 int get_MxEvts() 00211 { 00212 return mxEvts; 00213 } 00214 00216 virtual void PrepareForRun() 00217 {} 00218 00219 00221 virtual void EndOfRun() 00222 {} 00223 00225 virtual bool CheckEndOfRun(); 00226 00228 virtual void GetReady(); 00229 00231 virtual void Start(); 00232 00234 virtual void Stop(); 00235 00237 virtual void Pause(); 00238 00240 virtual void Continue(); 00241 00247 virtual void Trigger() 00248 { 00249 cmd->send_command(RunCommand::trigger); 00250 } 00251 00255 virtual void EndOfEvent() 00256 {} 00257 00259 virtual void Reset(); 00260 00262 virtual void Acquire(); 00263 00268 virtual int writeData(int size, const char *data) 00269 { 00270 return size; 00271 }; 00272 00273 00275 Monitor *get_monitor() const 00276 { 00277 return monitor; 00278 } 00279 00283 void set_monitor( Monitor *m) 00284 { 00285 if ( monitor ) 00286 delete monitor; 00287 00288 monitor = m; 00289 } 00290 00291 //--------------------------------------------------------------------- 00292 // Functors to operate on the list of modules 00293 //--------------------------------------------------------------------- 00299 struct ModuleAcquire : public std::unary_function<Observer *, void> 00300 { 00302 ModuleAcquire(RunManager *m) : rm(m), ndata(0) 00303 {} 00305 void operator()( Observer *o); 00307 RunManager *rm; 00309 int ndata; 00310 }; 00311 }; 00312 } 00313 00314 00315 #endif