\hypertarget{decode_8c}{
\section{decode.c File Reference}
\label{decode_8c}\index{decode.c@{decode.c}}
}
Routines to decode the event data. 

{\tt \#include \char`\"{}expand\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}decode.h\char`\"{}}\par
{\tt \#include \char`\"{}decompress.h\char`\"{}}\par
{\tt \#include \char`\"{}raw.h\char`\"{}}\par
{\tt \#include \char`\"{}QSEC\_\-ctx\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EBF\_\-ctb.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EBF\_\-gem.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EBF\_\-tem.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EBF\_\-cal.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EBF\_\-tkr.h\char`\"{}}\par
{\tt \#include \char`\"{}QSE/QSE\_\-ebf.h\char`\"{}}\par
{\tt \#include \char`\"{}QSE/QSE\_\-aemRepack.h\char`\"{}}\par
{\tt \#include \char`\"{}QSE/QSE\_\-aem.h\char`\"{}}\par
{\tt \#include \char`\"{}PBI/Endianness.h\char`\"{}}\par
{\tt \#include \char`\"{}LCBD/LATP.h\char`\"{}}\par
{\tt \#include $<$string.h$>$}\par
\subsection*{Classes}
\begin{CompactItemize}
\item 
struct \hyperlink{structQSEC__acdRaw}{QSEC\_\-acdRaw}
\begin{CompactList}\small\item\em Private structure holding raw data for an ACD contribution. \item\end{CompactList}\item 
struct \hyperlink{structQSEC__calRaw}{QSEC\_\-calRaw}
\begin{CompactList}\small\item\em Private structure holding \char`\"{}raw\char`\"{} data for a CAL event. \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{decode_8c_6851dc80fe65aa3d58c3d8f2b788e197}{
\#define \textbf{N\_\-INT\_\-BITS}~32}
\label{decode_8c_6851dc80fe65aa3d58c3d8f2b788e197}

\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static \_\-\_\-inline void \hyperlink{decode_8c_f86f667fda5e89ad76184dafccff3f5c}{fixCtbHdr} (EBF\_\-ctbHdr $\ast$hdr)
\begin{CompactList}\small\item\em When the ACD is not included in the output stream (as it is now), the final TEM contribution (if present) must have its response bit removed. \item\end{CompactList}\item 
static \_\-\_\-inline void \hyperlink{decode_8c_d9a8428308fa00777a722d0a78d16e99}{genCtbHdr} (int twr, unsigned int dMap, const EBF\_\-ctbHdr $\ast$gHdr, EBF\_\-ctbHdr $\ast$tHdr)
\begin{CompactList}\small\item\em Generate a TEM contribution header from the GEM header. \item\end{CompactList}\item 
static \_\-\_\-inline void $\ast$ \hyperlink{decode_8c_157bd64220158a010bdfc87b3ae622e9}{roundUpPtr} (void $\ast$ptr, int r)
\begin{CompactList}\small\item\em Round the specified pointer up to a specified binary boundary. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{decode_8c_ff331296d2e46df468f343e57bb1c810}{roundUpInt} (unsigned int ui, int r)
\begin{CompactList}\small\item\em Round the specified integer up to a binary boundary. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned short $\ast$ \hyperlink{decode_8c_e4808cd4566acbbde6d92671b609074e}{decodeShorts} (unsigned short $\ast$us, int cnt, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$dcmp, APD\_\-dtx $\ast$dtx)
\begin{CompactList}\small\item\em Decode the required number of symbols from the compressed stream and stores them as shorts. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{decode_8c_073071faeafccda9fd6756aff8471b65}{getWord} (int leng, const unsigned int $\ast$$\ast$bufp, int $\ast$boff)
\begin{CompactList}\small\item\em Get an arbitrary length word from an integer buffer. \item\end{CompactList}\item 
static \_\-\_\-inline void \hyperlink{decode_8c_10b783406ea6a0ed9e3054da2017dc4a}{setWord} (int leng, unsigned int value, unsigned int $\ast$$\ast$bufp, int $\ast$boff)
\begin{CompactList}\small\item\em Set an arbitrary length word into an integer buffer. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{decode_8c_ede2d0d033fe7f168ea8b4e06ab9b962}{getBit} (int index, const unsigned int $\ast$buff)
\begin{CompactList}\small\item\em Get a bit from an integer buffer. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{decode_8c_89d7f1e3ade1aeb8e12fd2947e33f500}{getNib} (int index, const unsigned int $\ast$buff)
\begin{CompactList}\small\item\em Get a nibble from an integer buffer. \item\end{CompactList}\item 
\hypertarget{decode_8c_0c5a704607f1ea427880b9afaf02ee8b}{
static unsigned int $\ast$ \textbf{copyContrib} (const unsigned char $\ast$$\ast$ctb, unsigned int $\ast$evt)}
\label{decode_8c_0c5a704607f1ea427880b9afaf02ee8b}

\item 
\hypertarget{decode_8c_876b6eb25b8ea1c0cdff6de646f8808a}{
static unsigned int $\ast$ \textbf{decodeAcd} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$aHdr, const \hyperlink{structQSEC__acdRaw}{QSEC\_\-acdRaw} $\ast$raw, unsigned int $\ast$evt)}
\label{decode_8c_876b6eb25b8ea1c0cdff6de646f8808a}

\item 
\hypertarget{decode_8c_ee16fc562e1310e4ee34a93998638ccd}{
static unsigned int $\ast$ \textbf{decodeCal} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$gHdr, const unsigned char $\ast$ibuf, unsigned int $\ast$evt)}
\label{decode_8c_ee16fc562e1310e4ee34a93998638ccd}

\item 
\hypertarget{decode_8c_820ced12c5ef5d805e4a7d0469dd05d1}{
static unsigned int $\ast$ \textbf{decodeCalV3} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$tHdr, const \hyperlink{structQSEC__calRaw}{QSEC\_\-calRaw} $\ast$raw, unsigned int $\ast$evt)}
\label{decode_8c_820ced12c5ef5d805e4a7d0469dd05d1}

\item 
\hypertarget{decode_8c_36a4b167db9716bd0d27621216cb81d4}{
static unsigned int $\ast$ \textbf{decodeCalV2} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$tHdr, unsigned int $\ast$evt)}
\label{decode_8c_36a4b167db9716bd0d27621216cb81d4}

\item 
\hypertarget{decode_8c_44909ccfdc4dcf3e7afb9ac8fba0817c}{
static unsigned int $\ast$ \textbf{decodeCalV1} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$tHdr, unsigned int $\ast$evt)}
\label{decode_8c_44909ccfdc4dcf3e7afb9ac8fba0817c}

\item 
\hypertarget{decode_8c_b4937d482a03cb2f225fb4a07de6d5fc}{
static unsigned int $\ast$ \textbf{decodeGem} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$gHdr, unsigned int $\ast$evt)}
\label{decode_8c_b4937d482a03cb2f225fb4a07de6d5fc}

\item 
\hypertarget{decode_8c_7c11d20a2c8265c9e818403d1c62a554}{
static unsigned int $\ast$ \textbf{decodeTkr} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$gHdr, const unsigned char $\ast$ibuf, unsigned int $\ast$evt)}
\label{decode_8c_7c11d20a2c8265c9e818403d1c62a554}

\item 
\hypertarget{decode_8c_c3e6d83cb2a07f8926a7c811f7490e18}{
static unsigned int $\ast$ \textbf{decodeTkrV1} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const EBF\_\-ctbHdr $\ast$tHdr, unsigned int $\ast$evt)}
\label{decode_8c_c3e6d83cb2a07f8926a7c811f7490e18}

\item 
\hypertarget{decode_8c_c9b592d6703298d02f495ecf35bf3450}{
static unsigned int $\ast$ \textbf{decodeTkrTots} (unsigned char $\ast$tot, int ntots, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$tots, APD\_\-dtx $\ast$dtx)}
\label{decode_8c_c9b592d6703298d02f495ecf35bf3450}

\item 
\hypertarget{decode_8c_a2c0e76549f01c1b0e52031e29ddf722}{
static void \textbf{expandGem} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, EBF\_\-gem $\ast$gem)}
\label{decode_8c_a2c0e76549f01c1b0e52031e29ddf722}

\item 
void \hyperlink{decode_8c_ba9ac8250f9a04ab05ae6aa4bdfa6a78}{QSEC\_\-update} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, EBF\_\-gem $\ast$gem, unsigned int $\ast$seq, const unsigned int $\ast$ievt)
\begin{CompactList}\small\item\em Decode the GEM contribution and extract the 17 bit event sequence. \item\end{CompactList}\item 
unsigned int \hyperlink{decode_8c_a5f6c15dc1ca8b02d1b36696384b37c6}{QSEC\_\-decode} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, QSE\_\-ebfEvt $\ast$oevt, const unsigned int $\ast$ievt)
\begin{CompactList}\small\item\em Decode the event held in the expansion structure into the QSE\_\-evt structure. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Routines to decode the event data. 

\begin{Desc}
\item[Author:]James Swain \& Owen Saxton\end{Desc}
\begin{Desc}
\item[Id]\end{Desc}


\subsection{Function Documentation}
\hypertarget{decode_8c_e4808cd4566acbbde6d92671b609074e}{
\index{decode.c@{decode.c}!decodeShorts@{decodeShorts}}
\index{decodeShorts@{decodeShorts}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned short$\ast$ decodeShorts (unsigned short $\ast$ {\em us}, int {\em cnt}, {\bf QSEC\_\-decompression} $\ast$ {\em dcmp}, APD\_\-dtx $\ast$ {\em dtx})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_e4808cd4566acbbde6d92671b609074e}


Decode the required number of symbols from the compressed stream and stores them as shorts. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em us}]The pointer to the unsigned short storeage array\item[{\em cnt}]The number of symbols to decode and store as short integer\item[{\em dcmp}]The decompression context\item[{\em dtx}]The compressed bit stream\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The pointer to the next storage location \end{Desc}
\hypertarget{decode_8c_f86f667fda5e89ad76184dafccff3f5c}{
\index{decode.c@{decode.c}!fixCtbHdr@{fixCtbHdr}}
\index{fixCtbHdr@{fixCtbHdr}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void fixCtbHdr (EBF\_\-ctbHdr $\ast$ {\em hdr})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_f86f667fda5e89ad76184dafccff3f5c}


When the ACD is not included in the output stream (as it is now), the final TEM contribution (if present) must have its response bit removed. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hdr}]The contribution header to patch \end{description}
\end{Desc}
\hypertarget{decode_8c_d9a8428308fa00777a722d0a78d16e99}{
\index{decode.c@{decode.c}!genCtbHdr@{genCtbHdr}}
\index{genCtbHdr@{genCtbHdr}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void genCtbHdr (int {\em twr}, unsigned int {\em dMap}, const EBF\_\-ctbHdr $\ast$ {\em gHdr}, EBF\_\-ctbHdr $\ast$ {\em tHdr})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_d9a8428308fa00777a722d0a78d16e99}


Generate a TEM contribution header from the GEM header. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em twr}]The tower (TEM) number.\item[{\em dMap}]The map of TEMs with diagnostics, TEM 0 = MSB.\item[{\em gHdr}]The address of the GEM header.\item[{\em tHdr}]The address of the TEM contribution header to generate. \end{description}
\end{Desc}
\hypertarget{decode_8c_ede2d0d033fe7f168ea8b4e06ab9b962}{
\index{decode.c@{decode.c}!getBit@{getBit}}
\index{getBit@{getBit}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned int getBit (int {\em index}, const unsigned int $\ast$ {\em buff})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_ede2d0d033fe7f168ea8b4e06ab9b962}


Get a bit from an integer buffer. 

The bits are numbered from low to high order within each integer.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em index}]The index of the bit to be obtained.\item[{\em buff}]Address of the integer buffer.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The value of the specified bit. \end{Desc}
\hypertarget{decode_8c_89d7f1e3ade1aeb8e12fd2947e33f500}{
\index{decode.c@{decode.c}!getNib@{getNib}}
\index{getNib@{getNib}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned int getNib (int {\em index}, const unsigned int $\ast$ {\em buff})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_89d7f1e3ade1aeb8e12fd2947e33f500}


Get a nibble from an integer buffer. 

The bits are numbered from low to high order within each integer.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em index}]The index of the nibble to be obtained.\item[{\em buff}]Address of the integer buffer.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The value of the specified nibble. \end{Desc}
\hypertarget{decode_8c_073071faeafccda9fd6756aff8471b65}{
\index{decode.c@{decode.c}!getWord@{getWord}}
\index{getWord@{getWord}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned int getWord (int {\em leng}, const unsigned int $\ast$$\ast$ {\em bufp}, int $\ast$ {\em boff})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_073071faeafccda9fd6756aff8471b65}


Get an arbitrary length word from an integer buffer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em leng}]The length, in bits, of the word to get.\item[{\em bufp}]Pointer to a pointer to the current location in the buffer. The latter is updated whenever the requested word reaches or crosses an integer boundary.\item[{\em boff}]Pointer to the bit offset, from high order to low within the current (32-bit) integer in the buffer. The offset is updated to just beyond the fetched word.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The value obtained from the buffer. \end{Desc}
\hypertarget{decode_8c_a5f6c15dc1ca8b02d1b36696384b37c6}{
\index{decode.c@{decode.c}!QSEC_decode@{QSEC\_\-decode}}
\index{QSEC_decode@{QSEC\_\-decode}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned int QSEC\_\-decode ({\bf QSEC\_\-expansion} $\ast$ {\em exp}, QSE\_\-ebfEvt $\ast$ {\em oevt}, const unsigned int $\ast$ {\em ievt})}}
\label{decode_8c_a5f6c15dc1ca8b02d1b36696384b37c6}


Decode the event held in the expansion structure into the QSE\_\-evt structure. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em exp}]Pointer to the expansion structure holding the histograms and encoder context\item[{\em oevt}]Pointer to the location to output the decoded event\item[{\em ievt}]Pointer to the location to input the encoded event\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Length, in bytes, of the event data \end{Desc}
\hypertarget{decode_8c_ba9ac8250f9a04ab05ae6aa4bdfa6a78}{
\index{decode.c@{decode.c}!QSEC_update@{QSEC\_\-update}}
\index{QSEC_update@{QSEC\_\-update}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void QSEC\_\-update ({\bf QSEC\_\-expansion} $\ast$ {\em exp}, EBF\_\-gem $\ast$ {\em gem}, unsigned int $\ast$ {\em seq}, const unsigned int $\ast$ {\em ievt})}}
\label{decode_8c_ba9ac8250f9a04ab05ae6aa4bdfa6a78}


Decode the GEM contribution and extract the 17 bit event sequence. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em exp}]Pointer to the expansion structure holding the histograms and encoder context\item[{\em gem}]Pointer to the location to place the decoded GEM contribution\item[{\em seq}]Pointer to the location to place the 17-bit event sequence number\item[{\em ievt}]Pointer to the location to input the encoded event number for use in QSE\_\-ctxUpdateAtEvent \end{description}
\end{Desc}
\hypertarget{decode_8c_ff331296d2e46df468f343e57bb1c810}{
\index{decode.c@{decode.c}!roundUpInt@{roundUpInt}}
\index{roundUpInt@{roundUpInt}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned int roundUpInt (unsigned int {\em ui}, int {\em r})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_ff331296d2e46df468f343e57bb1c810}


Round the specified integer up to a binary boundary. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ui}]The integer to round\item[{\em r}]The boundary to round to. This must be a power of 2, i.e. 1, 2, 4, 8 etc\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The rounded integer \end{Desc}
\hypertarget{decode_8c_157bd64220158a010bdfc87b3ae622e9}{
\index{decode.c@{decode.c}!roundUpPtr@{roundUpPtr}}
\index{roundUpPtr@{roundUpPtr}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void$\ast$ roundUpPtr (void $\ast$ {\em ptr}, int {\em r})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_157bd64220158a010bdfc87b3ae622e9}


Round the specified pointer up to a specified binary boundary. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]The pointer to round\item[{\em r}]The boundary to round to. This must be a power of 2, i.e. 1, 2, 4, 8 etc\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The rounded pointer \end{Desc}
\hypertarget{decode_8c_10b783406ea6a0ed9e3054da2017dc4a}{
\index{decode.c@{decode.c}!setWord@{setWord}}
\index{setWord@{setWord}!decode.c@{decode.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void setWord (int {\em leng}, unsigned int {\em value}, unsigned int $\ast$$\ast$ {\em bufp}, int $\ast$ {\em boff})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_10b783406ea6a0ed9e3054da2017dc4a}


Set an arbitrary length word into an integer buffer. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em leng}]The length, in bits, of the word to set.\item[{\em value}]The value of the word to set.\item[{\em bufp}]Pointer to a pointer to the current location in the buffer. The latter is updated whenever the set word reaches or crosses an integer boundary.\item[{\em boff}]Pointer to the bit offset, from high order to low within the current (32-bit) integer in the buffer. The offset is updated to just beyond the set word. \end{description}
\end{Desc}
