\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\_\-aem\-Repack.h\char`\"{}}\par
{\tt \#include \char`\"{}QSE/QSE\_\-aem.h\char`\"{}}\par
{\tt \#include \char`\"{}PBI/Endianness.h\char`\"{}}\par
{\tt \#include $<$string.h$>$}\par


Include dependency graph for decode.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=271pt]{decode_8c__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{structQSEC__acdRaw}{QSEC\_\-acd\-Raw}
\begin{CompactList}\small\item\em Private structure holding raw data for an ACD contribution. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static \_\-\_\-inline void \hyperlink{decode_8c_a0}{fixup\-Ctb\-Hdr} (EBF\_\-ctb\-Hdr $\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 must have its response bit removed. \item\end{CompactList}\item 
static \_\-\_\-inline void $\ast$ \hyperlink{decode_8c_a1}{round\-Up\-Ptr} (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_a2}{round\-Up\-Int} (unsigned int ui, int r)
\begin{CompactList}\small\item\em Round the specified integer up to a binary boundary. \item\end{CompactList}\item 
static unsigned short $\ast$ \hyperlink{decode_8c_a3}{decode\-Shorts} (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 unsigned int $\ast$ \hyperlink{decode_8c_a4}{decode\-Gem} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$sum, unsigned int $\ast$evt)
\begin{CompactList}\small\item\em Decode the GEM contribution. \item\end{CompactList}\item 
static unsigned int $\ast$ \hyperlink{decode_8c_a5}{decode\-Acd} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$sum, unsigned int $\ast$evt)
\begin{CompactList}\small\item\em Decode an ACD event. \item\end{CompactList}\item 
static unsigned int $\ast$ \hyperlink{decode_8c_a6}{decode\-Cal} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$sum, unsigned int $\ast$evt)
\begin{CompactList}\small\item\em Decode a CAL event. \item\end{CompactList}\item 
static unsigned int $\ast$ \hyperlink{decode_8c_a7}{decode\-Tkr} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$sum, unsigned int $\ast$evt)
\begin{CompactList}\small\item\em Decode a tracker event. \item\end{CompactList}\item 
static unsigned int $\ast$ \hyperlink{decode_8c_a8}{decode\-Tkr\-Tots} (unsigned char $\ast$tot, int ntots, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$tots, APD\_\-dtx $\ast$dtx)
\begin{CompactList}\small\item\em Decompress the tracker TOTS. \item\end{CompactList}\item 
static void \hyperlink{decode_8c_a9}{expand\-Gem} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, EBF\_\-gem $\ast$gem)
\begin{CompactList}\small\item\em Populate the data portion of a GEM contribution. \item\end{CompactList}\item 
void \hyperlink{decode_8c_a10}{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_a11}{QSEC\_\-decode} (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$exp, void $\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}\item 
static \_\-\_\-inline void \hyperlink{decode_8c_a12}{decode\-Cal\-Diag} (EBF\_\-tem\-Diag $\ast$diag\mbox{[}LSEC\_\-N\_\-TWR\mbox{]}, unsigned int map, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$dcmp, APD\_\-dtx $\ast$dtx)
\begin{CompactList}\small\item\em Decode the CAL portion of the diagnostic block. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned char $\ast$ \hyperlink{decode_8c_a13}{calc\-Tkr\-Tot\-Adr} (unsigned char $\ast$ptr, int nstrips)
\begin{CompactList}\small\item\em Encapsulate the calculation of the TOT storage address. \item\end{CompactList}\item 
static \_\-\_\-inline void \hyperlink{decode_8c_a14}{decode\-Tkr\-Diag} (EBF\_\-tem\-Diag $\ast$diag\mbox{[}LSEC\_\-N\_\-TWR\mbox{]}, unsigned int map, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$dcmp, APD\_\-dtx $\ast$dtx)
\begin{CompactList}\small\item\em Decode the tracker portion of the diagnostic block. \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]\hyperlink{decode_8c}{decode.c},v 1.17 2007/04/05 22:58:24 saxton Exp \end{Desc}


\subsection{Function Documentation}
\hypertarget{decode_8c_a13}{
\index{decode.c@{decode.c}!calcTkrTotAdr@{calcTkrTotAdr}}
\index{calcTkrTotAdr@{calcTkrTotAdr}!decode.c@{decode.c}}
\subsubsection[calcTkrTotAdr]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned char$\ast$ calc\-Tkr\-Tot\-Adr (unsigned char $\ast$ {\em ptr}, int {\em nstrips})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a13}


Encapsulate the calculation of the TOT storage address. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]The address of the end of the last 12-byte block of strips\item[{\em nstrips}]The number of strips stored in this 12-byte block\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The byte address to begin storing the TOTs\end{Desc}
\hypertarget{decode_8c_a5}{
\index{decode.c@{decode.c}!decodeAcd@{decodeAcd}}
\index{decodeAcd@{decodeAcd}!decode.c@{decode.c}}
\subsubsection[decodeAcd]{\setlength{\rightskip}{0pt plus 5cm}unsigned int $\ast$ decode\-Acd (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$ {\em exp}, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$ {\em sum}, unsigned int $\ast$ {\em evt})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a5}


Decode an ACD event. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em exp}]Expansion structure\item[{\em sum}]Pointer to the collection of contribution headers\item[{\em evt}]Pointer to the event to fill\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Pointer to the end of the space occupied by this contribution\end{Desc}
\hypertarget{decode_8c_a6}{
\index{decode.c@{decode.c}!decodeCal@{decodeCal}}
\index{decodeCal@{decodeCal}!decode.c@{decode.c}}
\subsubsection[decodeCal]{\setlength{\rightskip}{0pt plus 5cm}unsigned int $\ast$ decode\-Cal (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$ {\em exp}, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$ {\em sum}, unsigned int $\ast$ {\em evt})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a6}


Decode a CAL event. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em exp}]Expansion structure\item[{\em sum}]Pointer to the collection of contribution headers\item[{\em evt}]Pointer to the event to fill\end{description}
\end{Desc}
\hypertarget{decode_8c_a12}{
\index{decode.c@{decode.c}!decodeCalDiag@{decodeCalDiag}}
\index{decodeCalDiag@{decodeCalDiag}!decode.c@{decode.c}}
\subsubsection[decodeCalDiag]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void decode\-Cal\-Diag (EBF\_\-tem\-Diag $\ast$ {\em diag}\mbox{[}LSEC\_\-N\_\-TWR\mbox{]}, unsigned int {\em map}, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$ {\em dcmp}, APD\_\-dtx $\ast$ {\em dtx})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a12}


Decode the CAL portion of the diagnostic block. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em diag}]An array of pointers to each towers diagnostic block\item[{\em map}]The map of struck towers, MSB = Tower 0\item[{\em dcmp}]The decoding tables\item[{\em dtx}]The bit stream to be decoded\end{description}
\end{Desc}
\hypertarget{decode_8c_a4}{
\index{decode.c@{decode.c}!decodeGem@{decodeGem}}
\index{decodeGem@{decodeGem}!decode.c@{decode.c}}
\subsubsection[decodeGem]{\setlength{\rightskip}{0pt plus 5cm}unsigned int $\ast$ decode\-Gem (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$ {\em exp}, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$ {\em sum}, unsigned int $\ast$ {\em evt})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a4}


Decode the GEM contribution. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em exp}]Expansion structure\item[{\em sum}]Pointer to the collection of contribution headers\item[{\em evt}]Pointer to the event to fill.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Pointer to the end of the space occupied by this contribution\end{Desc}
\hypertarget{decode_8c_a3}{
\index{decode.c@{decode.c}!decodeShorts@{decodeShorts}}
\index{decodeShorts@{decodeShorts}!decode.c@{decode.c}}
\subsubsection[decodeShorts]{\setlength{\rightskip}{0pt plus 5cm}static unsigned short$\ast$ decode\-Shorts (unsigned short $\ast$ {\em us}, int {\em cnt}, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$ {\em dcmp}, APD\_\-dtx $\ast$ {\em dtx})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a3}


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_a7}{
\index{decode.c@{decode.c}!decodeTkr@{decodeTkr}}
\index{decodeTkr@{decodeTkr}!decode.c@{decode.c}}
\subsubsection[decodeTkr]{\setlength{\rightskip}{0pt plus 5cm}unsigned int $\ast$ decode\-Tkr (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$ {\em exp}, const \hyperlink{structQSEC__summary}{QSEC\_\-summary} $\ast$ {\em sum}, unsigned int $\ast$ {\em evt})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a7}


Decode a tracker event. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em exp}]Expansion structure\item[{\em sum}]Pointer to the collection of contribution headers\item[{\em evt}]Pointer to the event to be filled.\end{description}
\end{Desc}
\hypertarget{decode_8c_a14}{
\index{decode.c@{decode.c}!decodeTkrDiag@{decodeTkrDiag}}
\index{decodeTkrDiag@{decodeTkrDiag}!decode.c@{decode.c}}
\subsubsection[decodeTkrDiag]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void decode\-Tkr\-Diag (EBF\_\-tem\-Diag $\ast$ {\em diag}\mbox{[}LSEC\_\-N\_\-TWR\mbox{]}, unsigned int {\em map}, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$ {\em dcmp}, APD\_\-dtx $\ast$ {\em dtx})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a14}


Decode the tracker portion of the diagnostic block. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em diag}]An array of pointers to each towers diagnostic block\item[{\em map}]The map of struck towers, MSB = Tower 0\item[{\em dcmp}]The decoding tables\item[{\em dtx}]The bit stream to be decoded\end{description}
\end{Desc}
\hypertarget{decode_8c_a8}{
\index{decode.c@{decode.c}!decodeTkrTots@{decodeTkrTots}}
\index{decodeTkrTots@{decodeTkrTots}!decode.c@{decode.c}}
\subsubsection[decodeTkrTots]{\setlength{\rightskip}{0pt plus 5cm}unsigned int $\ast$ decode\-Tkr\-Tots (unsigned char $\ast$ {\em tot}, int {\em ntots}, \hyperlink{structQSEC__decompression__}{QSEC\_\-decompression} $\ast$ {\em tots}, APD\_\-dtx $\ast$ {\em dtx})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a8}


Decompress the tracker TOTS. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em tot}]Pointer to where to store the decoded tots\item[{\em ntots}]The number of TOTs to decode and fill\item[{\em tots}]The decompression context for the TOTs\item[{\em dtx}]The compressed bit stream descriptor\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Pointer to the next 32-bit word to be filled in\end{Desc}
\hypertarget{decode_8c_a9}{
\index{decode.c@{decode.c}!expandGem@{expandGem}}
\index{expandGem@{expandGem}!decode.c@{decode.c}}
\subsubsection[expandGem]{\setlength{\rightskip}{0pt plus 5cm}void expand\-Gem (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$ {\em exp}, EBF\_\-gem $\ast$ {\em gem})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a9}


Populate the data portion of a GEM contribution. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em exp}]Pointer to the expansion structure\item[{\em gem}]Pointer to the GEM structure to populate\end{description}
\end{Desc}
\hypertarget{decode_8c_a0}{
\index{decode.c@{decode.c}!fixupCtbHdr@{fixupCtbHdr}}
\index{fixupCtbHdr@{fixupCtbHdr}!decode.c@{decode.c}}
\subsubsection[fixupCtbHdr]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void fixup\-Ctb\-Hdr (EBF\_\-ctb\-Hdr $\ast$ {\em hdr})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a0}


When the ACD is not included in the output stream (as it is now), the final TEM contribution 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_a11}{
\index{decode.c@{decode.c}!QSEC_decode@{QSEC\_\-decode}}
\index{QSEC_decode@{QSEC\_\-decode}!decode.c@{decode.c}}
\subsubsection[QSEC\_\-decode]{\setlength{\rightskip}{0pt plus 5cm}unsigned int QSEC\_\-decode (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$ {\em exp}, void $\ast$ {\em oevt}, const unsigned int $\ast$ {\em ievt})}}
\label{decode_8c_a11}


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_a10}{
\index{decode.c@{decode.c}!QSEC_update@{QSEC\_\-update}}
\index{QSEC_update@{QSEC\_\-update}!decode.c@{decode.c}}
\subsubsection[QSEC\_\-update]{\setlength{\rightskip}{0pt plus 5cm}void QSEC\_\-update (\hyperlink{structQSEC__expansion__}{QSEC\_\-expansion} $\ast$ {\em exp}, EBF\_\-gem $\ast$ {\em gem}, unsigned int $\ast$ {\em seq}, const unsigned int $\ast$ {\em ievt})}}
\label{decode_8c_a10}


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\_\-ctx\-Update\-At\-Event\end{description}
\end{Desc}
\hypertarget{decode_8c_a2}{
\index{decode.c@{decode.c}!roundUpInt@{roundUpInt}}
\index{roundUpInt@{roundUpInt}!decode.c@{decode.c}}
\subsubsection[roundUpInt]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned int round\-Up\-Int (unsigned int {\em ui}, int {\em r})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a2}


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_a1}{
\index{decode.c@{decode.c}!roundUpPtr@{roundUpPtr}}
\index{roundUpPtr@{roundUpPtr}!decode.c@{decode.c}}
\subsubsection[roundUpPtr]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void$\ast$ round\-Up\-Ptr (void $\ast$ {\em ptr}, int {\em r})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{decode_8c_a1}


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}
