Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "roc/ReadoutModule.h"
00016
00017 #include <stdlib.h>
00018
00019 #include "roc/Board.h"
00020
00021 #include "dabc/Port.h"
00022
00023 roc::ReadoutModule::ReadoutModule(const char* name, dabc::Command cmd) :
00024 dabc::ModuleAsync(name, cmd),
00025 fDataCond(),
00026 fCurrBuf(),
00027 fNextBuf()
00028 {
00029 int numoutputs = Cfg(dabc::xmlNumOutputs, cmd).AsInt(1);
00030 std::string poolname = Cfg("PoolName", cmd).AsStdStr(roc::xmlRocPool);
00031
00032 DOUT2(("new roc::ReadoutModule %s", GetName()));
00033
00034 CreatePoolHandle(poolname.c_str());
00035
00036 CreateInput("Input", Pool(), 10);
00037
00038
00039 for(int n=0; n<numoutputs; n++)
00040 CreateOutput(FORMAT(("Output%d", n)), Pool(), 10);
00041 }
00042
00043 roc::ReadoutModule::~ReadoutModule()
00044 {
00045 }
00046
00047 void roc::ReadoutModule::AfterModuleStop()
00048 {
00049 fCurrBuf.Release();
00050
00051 dabc::Buffer buf;
00052 {
00053 dabc::LockGuard lock(fDataCond.CondMutex());
00054 buf << fNextBuf;
00055 }
00056 buf.Release();
00057 }
00058
00059 void roc::ReadoutModule::ProcessInputEvent(dabc::Port* inport)
00060 {
00061 if (!inport->CanRecv()) return;
00062
00063
00064
00065
00066 if (!fNextBuf.null()) return;
00067
00068 dabc::Buffer buf = inport->Recv();
00069
00070
00071
00072 dabc::LockGuard lock(fDataCond.CondMutex());
00073 if (!fNextBuf.null()) {
00074 EOUT(("Something completely wrong"));
00075 exit(111);
00076 }
00077 fNextBuf << buf;
00078 if (!fNextBuf.null() && fDataCond._Waiting()) fDataCond._DoFire();
00079 }
00080
00081 void roc::ReadoutModule::ProcessOutputEvent(dabc::Port* inport)
00082 {
00083 }
00084
00085 bool roc::ReadoutModule::getNextBuffer(void* &buf, unsigned& len, double tmout)
00086 {
00087 if (!fCurrBuf.null()) fCurrBuf.Release();
00088
00089 Input()->FireInput();
00090
00091
00092 {
00093 dabc::LockGuard lock(fDataCond.CondMutex());
00094 if (fNextBuf.null()) fDataCond._DoWait(tmout);
00095 fCurrBuf << fNextBuf;
00096 }
00097
00098 if (fCurrBuf.null()) return false;
00099
00100 buf = fCurrBuf.SegmentPtr();
00101 len = fCurrBuf.SegmentSize();
00102
00103 return true;
00104 }