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

include/sp605/Message.h (r4864/r3416)

Go to the documentation of this file.
00001 #ifndef SP605_MESSAGE_H
00002 #define SP605_MESSAGE_H
00003 
00004 #include <stdint.h>
00005 #include <iostream>
00006 #include <vector>
00007 
00008 #define SP605_SPADIC_MAX_CHANNEL 0xF // 4 bit max channel id
00009 #define SP605_SPADIC_MAX_GROUP   0xFF // 8 bit max group id
00010 #define SP605_SPADIC_MAX_SAMPLE 0x3F // 6 bit maximum number of samples per message
00011 
00012 //#define DEBUG605 1
00013 
00014 #ifndef DEBUG605
00015 #define DPRINT605( args ...) ;
00016 #else
00017 #define DPRINT605( args ...) printf( args )
00018 #endif
00019 
00020 
00021 namespace sp605 {
00022 
00023    /* JAM: start implementing after
00024     * spadic specs at http://spadic.uni-hd.de/spadic10/data/spadic10spec.pdf
00025     * */
00026 
00027 
00028    enum MessageFormat {
00029       formatSpadic10Direct = 5, // data as they coming from the spadic without any additional CBMnet padding
00030       formatSpadic10Optic  = 6  // current optical format, including SYNC/AUX messages and
00031    };
00032 
00033 
00034    enum MessageTypes {
00035       MSG_NOP = 0,
00036       MSG_HIT = 1,
00037       MSG_EPOCH = 2,
00038       MSG_OVERFLOW = 3,
00039       MSG_INFO = 4,
00040       MSG_LASTID = 5
00041    };
00042 
00043    /* following values reflect bitvalues of hittype data:*/
00044    enum HitTrgTypes {
00045       TRIG_GLOBAL = 0,
00046       TRIG_SELF = 1,
00047       TRIG_NEIGHBOR = 2,
00048       TRIG_BOTH = 3
00049    };
00050 
00051    /* following values reflect bitvalues of stoptype data:*/
00052    enum MsgStopTypes {
00053       STOP_NORMAL = 0,
00054       STOP_OUTBUFFULL = 1,
00055       STOP_FIFOFULL = 2,
00056       STOP_MULTIHIT = 3,
00057       STOP_OUTBUFFULLMULTIHIT = 4,
00058       STOP_FIFOFULLMULTIHIT = 5
00059    };
00060 
00061    /* following values reflect bitvalues of info data:*/
00062    enum InfoTypes {
00063       INFO_DIS = 0, // channel disabled during readout, c: channel ID
00064       INFO_NGT = 1, // corruption, next grant timeout in switch, c: channel ID
00065       INFO_NRT = 2, // corruption, next request timeout in switch
00066       INFO_NBE = 3, // corruption, new grant but channel empty in switch, c: channel ID
00067       INFO_MSB = 4, // corruption, unknown metadata type in message builder, c: channel ID
00068       INFO_NOP = 5, // empty word (may appear within other messages)
00069       INFO_SYN = 6  // out of sync warning, e: least significant bits of epoch counter
00070    };
00071 
00072 
00073 
00074 
00075 
00076    class Message {
00077       protected:
00078          uint8_t  fMsgType; //  message type as defined in MessageTypes
00079          uint16_t fSpadicId; // TODO: id of spadic?
00080          uint8_t  fGroup; // group id
00081          uint8_t  fChan; //  channel  id
00082          uint8_t  fHitType; // hit type
00083          uint8_t  fInfoType; // stop type, or info type
00084          uint16_t fTimeStamp; // message timestamp
00085          uint16_t fEpoch;   // field for epoch in different messages
00086          uint8_t  fTraceSize;
00087          std::vector<int16_t> fTraces;  // contains unfolded samples.
00088 
00089 
00090          /* will unpack the message bits:*/
00091          void InitTraceBuffer(uint16_t* fRDA);
00092 
00093          /* helper function to set value to trace buffer.
00094           * arguments: sample index bin, sampled value and length of trace len
00095           * returns false if we have just set the last sample
00096           * otherwise true*/
00097          bool SetTrace(unsigned bin, int16_t value, unsigned len)
00098          {
00099             if (bin >= fTraces.size()) return false;
00100             fTraces[bin] = (value>256) ? value-512 : value;
00101             return (bin + 1 == len) ? false : true;
00102          }
00103 
00104       public:
00105 
00106          Message() { clear(); }
00107          ~Message() { }
00108 
00109          void clear()
00110          {
00111             fMsgType=MSG_NOP;
00112             fSpadicId=0;
00113             fGroup=0xff;
00114             fChan=0xff;
00115             fHitType=0;
00116             fEpoch=0;
00117             fTimeStamp=0;
00118             fTraceSize=0;
00119             fTraces.clear();
00120          }
00121 
00122 
00130          size_t assign(void* buf, unsigned fullsz);
00131 
00132 
00133 
00134 
00135 
00136 
00137          uint8_t getMsgType() const { return fMsgType; }
00138 
00139          // TODO
00140          uint16_t getSpadicNumber() const { return fSpadicId; }
00141 
00142          //TODO! DUMMY Sets the spadic  number field in the current message
00143          void setSpadicNumber(uint16_t id) { fSpadicId=id;}
00144 
00145 
00146          uint8_t getGroup() const
00147          {
00148             return fGroup;
00149          }
00150 
00151          // channel number of current trace
00152          uint8_t getChNum() const
00153          {
00154             return fChan;
00155          }
00156 
00157          // return channel num, where group id already included
00158          unsigned getFullChNum() const
00159          {
00160              return getGroup() * 16 + getChNum();
00161          }
00162 
00163          // ******* HIT message ***********
00164 
00165          uint8_t getHitType() const
00166          {
00167             return fHitType;
00168          }
00169 
00170          uint8_t getStopType() const
00171          {
00172             return fInfoType;
00173          }
00174 
00175 
00176          /* length of actual trace in this message.
00177           * this is the number of samples*/
00178          uint8_t getTraceSize() const
00179          {
00180             return fTraceSize;
00181          }
00182 
00183          uint16_t getTimeStamp() const
00184          {
00185             return fTimeStamp;
00186          }
00187 
00188 
00189          // **** OVERFLOW message ********
00190          uint8_t getOverflowHits() const
00191          { return fEpoch; }
00192 
00193 
00194          // ***** INFO message ************
00195 
00196          uint8_t getInfoType() const
00197          {
00198             return fInfoType;
00199          }
00200 
00201          uint8_t getInfoChannel() const
00202          {
00203             return fChan;
00204          }
00205 
00206          uint8_t getInfoEpoch() const
00207          {
00208             return fEpoch;
00209          }
00210 
00211 
00212 
00214          // frontend group at current spadic
00215          uint8_t evalGroup(uint16_t* pSOM) const
00216          {
00217             if(pSOM==0) return 0;
00218             return (uint8_t) (( *pSOM >> 4) & 0xFF);
00219          }
00220 
00221          // channel number of current trace
00222          uint8_t evalChNum(uint16_t* pSOM) const
00223          {
00224             if (pSOM == 0)
00225                return 0;
00226             return (uint8_t)(*pSOM & 0xF);
00227          }
00228 
00229 
00230          uint8_t evalHitType(uint16_t* pEOM) const
00231          {
00232             if (getMsgType() != MSG_HIT || pEOM == 0)
00233                return 0;
00234             return (uint8_t)((*pEOM >> 4) & 0x3);
00235          }
00236 
00237          uint8_t evalStopType(uint16_t* pEOM) const
00238          {
00239             if (getMsgType() != MSG_HIT || pEOM == 0)
00240                return 0;
00241             return (uint8_t)(*pEOM & 0x7);
00242          }
00243 
00244 
00245 
00246 
00247          /* length of actual trace in this message.
00248           * this is the number of samples*/
00249          size_t evalTraceSize(uint16_t* pEOM) const
00250          {
00251             if (getMsgType() != MSG_HIT || pEOM == 0)
00252                return 0;
00253             return (size_t)((*pEOM >> 6) & 0x3F);
00254          }
00255 
00256 
00257          /* access trace sample*/
00258          int16_t getTrace(unsigned bin)
00259          {
00260             if(getMsgType()!=MSG_HIT) return -1024;
00261             if(bin>=getTraceSize()) return -2048;
00262             //if(!isReadyTracebuffer) InitTraceBuffer();
00263             return fTraces[bin];
00264          }
00265 
00266 
00267          unsigned getEpoch() const { return fEpoch; }
00268 
00269          uint16_t evalTimeStamp(uint16_t* fTSW) const
00270          {
00271             if(fTSW==0) return 0;
00272             return (*fTSW  & 0xFFF);
00273          }
00274 
00275 
00276          uint32_t getMsgFullTime(uint16_t epoch=0) const;
00277 
00278          double getMsgFullTimeD(uint16_t epoch=0) const;
00279 
00281          // ts unit is 40ns, epoch wraps after 671.1 ms
00282          inline static uint32_t FullTimeStamp(uint16_t epoch, uint16_t stamp)
00283          { return 40 * (((uint32_t) epoch << 12) | (stamp & 0xfff)); }
00284 
00285 
00286          void printData();
00287 
00288 
00289          bool isTrace() const { return isHitMsg(); }
00290 
00291          bool isEpoch() const { return isEpochMsg(); }
00292 
00293          inline bool isNopMsg() const { return getMsgType() == MSG_NOP; }
00294          inline bool isHitMsg() const { return getMsgType() == MSG_HIT; }
00295          inline bool isEpochMsg() const { return getMsgType() == MSG_EPOCH;}
00296          inline bool isOverflowMsg() const { return getMsgType() == MSG_OVERFLOW; }
00297          inline bool isInfoMsg() const { return getMsgType() == MSG_INFO; }
00298 
00299 
00300    };
00301 }
00302 
00303 #endif

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