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

plugin/roc/CombinerModule.h (r4864/r3193)

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 #ifndef ROC_CombinerModule
00016 #define ROC_CombinerModule
00017 
00018 #include "dabc/ModuleAsync.h"
00019 #include "dabc/Pointer.h"
00020 
00021 #include "roc/BoardsVector.h"
00022 
00023 #include "roc/CombinerModule.h"
00024 
00025 #include "mbs/Iterator.h"
00026 
00027 #include <vector>
00028 
00029 
00030 namespace roc {
00031 
00032    extern const char* xmlBnetMode;         // true if combiner works within bnet environment
00033    extern const char* xmlSkipErrorData;      // if true, error data will be skipped
00034    extern const char* xmlIgnoreMissingEpoch; // workaround for fail FEET readout
00035    extern const char* xmlSyncNumber;       // specified sync channel, used for synchronization
00036    extern const char* xmlSyncScaleDown;    // identifies scale down of sync events
00037    extern const char* xmlSpillRoc;
00038    extern const char* xmlSpillAux;
00039    extern const char* xmlCalibrationPeriod;
00040    extern const char* xmlCalibrationLength;
00041    extern const char* xmlThrottleAux;
00042    extern const char* xmlGet4ResetPeriod;  // reset period of all GET4 chips
00043    extern const char* xmlGet4ResetLimit;  // how often automatic reset is allowed when GET4 error is detected
00044 
00045    class CombinerModule : public dabc::ModuleAsync {
00046 
00047       public:
00048 
00049          CombinerModule(const char* name, dabc::Command cmd);
00050          virtual ~CombinerModule();
00051 
00052          virtual void BeforeModuleStart();
00053 
00054          virtual void ProcessInputEvent(dabc::Port* port);
00055 
00056          virtual void ProcessOutputEvent(dabc::Port* port);
00057 
00058          virtual void ProcessTimerEvent(dabc::Timer* timer);
00059 
00060       protected:
00061 
00062          enum { MaxGet4 = 16, MaxGet4Ch = 4 };
00063 
00064          struct InputRec {
00065             unsigned      rocid;
00066             int           format;
00067             bool          isudp;  // indicate if optic or Ethernet transport are attached
00068 
00069             uint32_t   curr_epoch;
00070             bool       iscurrepoch;
00071             unsigned   curr_nbuf;
00072             unsigned   curr_indx;
00073 
00074             uint32_t   prev_epoch;  // previous epoch marker
00075             bool       isprev;
00076             unsigned   prev_nbuf;  // id of buffer where epoch is started
00077             unsigned   prev_indx;  // index inside buffer where epoch found
00078             uint32_t   prev_evnt;  // sync event number
00079             uint32_t   prev_stamp; // sync time stamp
00080 
00081             uint32_t   next_epoch;  // number of the next epoch
00082             bool       isnext;      //
00083             unsigned   next_nbuf;   // id of buffer where epoch is started
00084             unsigned   next_indx;  // index inside buffer where epoch found
00085             uint32_t   next_evnt;  // sync event number
00086             uint32_t   next_stamp; // sync time stamp
00087 
00088             bool       nummbssync;    // indicate how many mbs sync data we had
00089             uint32_t   firstmbssync;  // value of first found mbssync
00090 
00091             unsigned   data_length; // length of data between prev and next event
00092 
00093             bool       isready;    // indicate if epoch and next are defined and ready for combining
00094 
00095             bool          use;     // use input for combining
00096             bool          data_err; // event numbers are wrong
00097             dabc::Pointer ptr;     // used in combining
00098             unsigned      nbuf;    // used in combining
00099             uint32_t      epoch;   // original epoch used in combining
00100             unsigned      stamp;   // corrected stamp value in combining
00101             unsigned      stamp_shift; // (shift to event begin)
00102 
00103             uint64_t      last_thottle_tm; // last time, when threshold state was changed
00104             bool          last_throttle_state; // last state of throttle signal (on/off)
00105 
00106             uint32_t      lastEpoch2[MaxGet4]; // last epoch2 for each get4
00107             int           get4EdgeCnt[MaxGet4][MaxGet4Ch];  // edge counter for each get4 channel
00108             int           get4EdgeErrs[MaxGet4][MaxGet4Ch]; // number of errors when consequent same adges more than 3
00109             uint64_t      get4LastTm[MaxGet4][MaxGet4Ch]; // last time stamp on each channel (disregard edge)
00110             int           get4AllCnt[MaxGet4][MaxGet4Ch]; //  counter of all sign changes
00111             int           get4ErrCnt[MaxGet4][MaxGet4Ch]; //  counter of suspicious sign changes
00112             unsigned      lastEpoch2SyncErr[MaxGet4]; // last error difference between epoch2 when sync=1
00113             bool          canCheckGet4[MaxGet4]; // indicate if we could analyze data of GET4, on after first sync
00114             bool          canCheckAnyGet4; // true if any get4 can be checked, disabled after reconfig until sys message is available
00115 
00116             bool isrocid() const { return rocid!=0xffffffff; }
00117 
00118             bool IsDifferentRocId(unsigned id, bool& iserr)
00119             {
00120                iserr = false;
00121                if (rocid==id) return false;
00122 
00123                // in case of udp channel any different rocid is error
00124                if (isudp) { iserr = true; return true; }
00125 
00126                iserr = true;
00127                return true;
00128             }
00129 
00130             unsigned can_skip_buf() { return isprev ? prev_nbuf : 0; }
00131 
00132             void did_skip_buf(unsigned cnt)
00133             {
00134                curr_nbuf -= cnt;
00135                if (isprev) prev_nbuf -= cnt;
00136                if (isnext) next_nbuf -= cnt;
00137             }
00138 
00139             InputRec() :
00140                rocid(0xffffffff), format(formatEth1), isudp(true),
00141                curr_epoch(0), iscurrepoch(false), curr_nbuf(0), curr_indx(0),
00142                prev_epoch(0), isprev(false), prev_nbuf(0), prev_indx(0), prev_evnt(0), prev_stamp(0),
00143                next_epoch(0), isnext(false), next_nbuf(0), next_indx(0), next_evnt(0), next_stamp(0),
00144                nummbssync(0), firstmbssync(0),
00145                data_length(0), isready(false),
00146                use(false), data_err(false), ptr(), nbuf(0), epoch(0), stamp(0), stamp_shift(0),
00147                last_thottle_tm(0), last_throttle_state(false)
00148             {
00149                for (int n=0;n<MaxGet4;n++) {
00150                   lastEpoch2[n] = 0;
00151                   lastEpoch2SyncErr[n] = 0;
00152                   canCheckGet4[n] = false;
00153                   for(int ch=0;ch<MaxGet4Ch;ch++) {
00154                      get4EdgeCnt[n][ch] = 0;
00155                      get4EdgeErrs[n][ch] = 0;
00156                      get4LastTm[n][ch] = 0;
00157                      get4AllCnt[n][ch] = 0;
00158                      get4ErrCnt[n][ch] = 0;
00159                   }
00160                }
00161 
00162                canCheckAnyGet4 = true;
00163             }
00164 
00165              InputRec(const InputRec& r) :
00166                rocid(r.rocid), format(r.format), isudp(r.isudp),
00167                curr_epoch(r.curr_epoch), iscurrepoch(r.iscurrepoch), curr_nbuf(r.curr_nbuf), curr_indx(r.curr_indx),
00168                prev_epoch(r.prev_epoch), isprev(r.isprev), prev_nbuf(r.prev_nbuf), prev_indx(r.prev_indx), prev_evnt(r.prev_evnt), prev_stamp(r.prev_stamp),
00169                next_epoch(r.next_epoch), isnext(r.isnext), next_nbuf(r.next_nbuf), next_indx(r.next_indx), next_evnt(r.next_evnt), next_stamp(r.next_stamp),
00170                nummbssync(r.nummbssync), firstmbssync(r.firstmbssync),
00171                data_length(r.data_length), isready(r.isready),
00172                use(r.use), data_err(r.data_err), ptr(r.ptr), nbuf(r.nbuf), epoch(r.epoch), stamp(r.stamp), stamp_shift(r.stamp_shift),
00173                last_thottle_tm(r.last_thottle_tm), last_throttle_state(r.last_throttle_state)
00174              {
00175                 for (int n=0;n<MaxGet4;n++) {
00176                    lastEpoch2[n] = r.lastEpoch2[n];
00177                    canCheckGet4[n] = r.canCheckGet4[n];
00178                    lastEpoch2SyncErr[n] = r.lastEpoch2SyncErr[n];
00179                    for(int ch=0;ch<MaxGet4Ch;ch++) {
00180                       get4EdgeCnt[n][ch] = r.get4EdgeCnt[n][ch];
00181                       get4EdgeErrs[n][ch] = r.get4EdgeErrs[n][ch];
00182                       get4LastTm[n][ch] = r.get4LastTm[n][ch];
00183                       get4AllCnt[n][ch] = r.get4AllCnt[n][ch];
00184                       get4ErrCnt[n][ch] = r.get4ErrCnt[n][ch];
00185                    }
00186                 }
00187                 canCheckAnyGet4 = r.canCheckAnyGet4;
00188              }
00189          };
00190 
00191          virtual int ExecuteCommand(dabc::Command cmd);
00192 
00193          virtual void PoolHandleCleaned(dabc::PoolHandle* pool);
00194 
00195          virtual void ModuleCleanup();
00196 
00197          bool FindNextEvent(unsigned recid);
00198          bool SkipEvent(unsigned recid);
00199 
00200          void FillBuffer();
00201          void FillSimpleBuffer();
00202          bool FlushOutputBuffer();
00203 
00204          void InvokeAllGet4Reset();
00205          unsigned FillRawSubeventsBuffer(dabc::Buffer& buf, dabc::Pointer& outptr, roc::MessagesVector* extra = 0);
00206          void AddExtraMessagesToSubevent(dabc::Buffer& buf, roc::MessagesVector* extra, dabc::Pointer& outptr, unsigned& subeventsize, InputRec* rec);
00207 
00208          void DumpData(dabc::Buffer& buf);
00209 
00210          void SetInfo(const std::string& info, bool forceinfo = false);
00211 
00212          dabc::PoolHandle*    fInpPool;
00213          dabc::PoolHandle*    fOutPool;
00214          dabc::BufferSize_t   fBufferSize;
00215 
00216          bool                 fSimpleMode;
00217          bool                 fBnetMode;       // if true, format buffer to be accepted by other bnet modules
00218          int                  fSyncScaleDown;  // expected distance between two events ids, should be specified in config file or in command
00219          int                  fSyncNumber;     // specifies sync channel, used for synchronization
00220          bool                 fIgnoreMissingEpoch; // ignore missing epoch for sync marker, add artificial one
00221          bool                 fSkipErrorData;  // if true, skip error data - necessary for complex systems with MBS/susibo
00222 
00223          std::vector<InputRec> fInp;
00224 
00225          dabc::Buffer         fOutBuf;
00226          dabc::Pointer        f_outptr;
00227 
00228          int                  fSpillRoc;      // roc number, where spill on/off signal is connected
00229          int                  fSpillAux;      // number of Aux channel where spill on/off signal is measured
00230          bool                 fSpillState;    // current state of spill, known by module
00231          uint64_t             fLastSpillTime; // last time when spill signal was seen
00232 
00233          double               fCalibrationPeriod; // how often trigger mode should be started
00234          double               fCalibrationLength; // how long calibration should be switched on
00235          dabc::TimeStamp      fLastCalibrationTime; // last time when trigger was caused
00236 
00237          double               fGet4ResetPeriod;  // period how often reset of Get4 should be performed
00238 
00239          int                  fThrottleAux;  // defines AUX signal, which analyzed at throttled
00240 
00241          std::list<MessagesVector*>  fExtraMessages;
00242 
00243          bool                 fFlushFlag;     // boolean, indicate if buffer should be flushed in next timeout
00244 
00245          double               fGet4ResetLimit; // how often get4 can be reseted
00246          dabc::TimeStamp      fLastGet4ResetTm; // time when reset was send to application
00247          bool                 fDetectGet4Problem;
00248 
00249    };
00250 }
00251 
00252 #endif

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