ACQ2XX_API
ProcessController.h
Go to the documentation of this file.
00001 /*
00002  * ProcessController.h
00003  *
00004  *  Created on: Feb 12, 2011
00005  *      Author: pgm
00006  */
00007 
00008 #ifndef PROCESSCONTROLLER_H_
00009 #define PROCESSCONTROLLER_H_
00010 
00011 #include <popt.h>               /** ugly */
00012 #include <string>
00013 #include <map>
00014 
00015 using namespace std;
00016 
00017 class AcqDataModel;
00018 class ProcessController;
00019 
00020 class ValidatorData {
00021         ProcessController& pc;
00022         unsigned pss;
00023         bool adjusted;
00024         unsigned msecs_at_esoff;        /* optional timestamp at event */
00025         unsigned msecs_at_tblock_start;
00026         unsigned tblockN;
00027 
00028         ValidatorData(ProcessController& _pc);
00029 
00030 public:
00031         unsigned esoff;
00032         unsigned esoff2;
00033 
00034         int tblock;
00035         int blocks123[3];               /* before, during, after blocks */
00036         int ecount[3];
00037         int nblocks;
00038 
00039         virtual ~ValidatorData() {}
00040 
00041         unsigned getSampleOffset(unsigned offset_in_block);
00042 
00043         void adjust(int samples);
00044 
00045         static ValidatorData *create(ProcessController&, char *input_line);
00046         static int evnum;
00047 };
00048 
00049 class ProcessControllerCreator;
00050 
00051 class ProcessController {
00052 public:
00053         AcqDataModel& dataModel;
00054 
00055 protected:
00056         bool use_fork;
00057         int nice2;
00058         int euid;
00059         const char* src_fmt;
00060         int show_exit_level;
00061 
00062         ValidatorData* validatorData;
00063 
00064         virtual void processAction(void *pdata, int len, int tblock);
00065 
00066         void processRaw(const char* rawfname, int tblock = 0);
00067 
00068         virtual void processRawFiles(const char* tbdef);
00069         virtual int processTblock(const char *tbdef);
00070         /**< returns # events, <0 :: error */
00071         virtual int dump() = 0;
00072         /**< returns # events, <0 :: error */
00073 
00074         virtual void parentDump() {}
00075         /**< executed on parent side of fork() after dump. */
00076 
00077 public:
00078         ProcessController(AcqDataModel& _dataModel);
00079         virtual ~ProcessController() {}
00080 
00081         virtual void run(poptContext& opt_context) = 0;
00082 
00083         static int flen(const char *fname);
00084 
00085         /** factory */
00086         static ProcessController* create(
00087                         const string key, AcqDataModel& dataModel);
00088 
00089 
00090         void addCal(const char *rawfname);
00091 };
00092 
00093 /** Why the crazy stuff below?.
00094  * Well, ProcessControllerRegistry and  ProcessControllerCreator
00095  * allow new ProcessControllers to be added by static data initialization.
00096  * in other words, a plug-in.
00097  * @@todo there's probably a simpler way, but this works.
00098  */
00099 
00100 class ProcessControllerRegistry
00101 /** singleton */
00102 {
00103         ProcessControllerRegistry() {
00104 
00105         }
00106 public:
00107         static ProcessControllerRegistry& instance();
00108         void registerController(const string key, ProcessControllerCreator* pcc);
00109 
00110         map<const string, ProcessControllerCreator*> creators;
00111 };
00112 
00113 class ProcessControllerCreator {
00114 public:
00115         virtual ProcessController* create(AcqDataModel& _dataModel) const = 0;
00116 
00117         virtual ~ProcessControllerCreator() {}
00118 };
00119 #endif /* PROCESSCONTROLLER_H_ */