• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

plugin/src/ReadoutModule.cxx (r4864/r2882)

Go to the documentation of this file.
00001 /********************************************************************
00002  * The Data Acquisition Backbone Core (DABC)
00003  ********************************************************************
00004  * Copyright (C) 2009-
00005  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
00006  * Planckstr. 1
00007  * 64291 Darmstadt
00008  * Germany
00009  * Contact:  http://dabc.gsi.de
00010  ********************************************************************
00011  * This software can be used under the GPL license agreements as stated
00012  * in LICENSE.txt file which is part of the distribution.
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 //   CreateRateParameter("InputRate", false, 3., "Input")->SetDebugOutput(true);
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    // one may avoid locking while here is basic type check is done
00064    // if mutex is locked and user just reading last byte, it will
00065    // fire new event after buffer set to 0
00066    if (!fNextBuf.null()) return;
00067 
00068    dabc::Buffer buf = inport->Recv();
00069 
00070 //   DOUT1(("Read buffer %p from input", buf));
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    // lock only when new complete buffer is required
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 }

Generated on Tue Dec 10 2013 04:52:23 for ROCsoft by  doxygen 1.7.1