\hypertarget{ASC_8c}{
\section{ASC.c File Reference}
\label{ASC_8c}\index{ASC.c@{ASC.c}}
}
ACD Software Rate Counters, implementation file. 

{\tt \#include $<$string.h$>$}\par
{\tt \#include \char`\"{}PBS/FFS.ih\char`\"{}}\par
{\tt \#include \char`\"{}PBI/Endianness.h\char`\"{}}\par
{\tt \#include \char`\"{}EMP/ASC.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EBF\_\-cid.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EBF\_\-gem.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EDA\_\-acd.h\char`\"{}}\par
{\tt \#include \char`\"{}EDS/EDR\_\-acd.h\char`\"{}}\par
{\tt \#include \char`\"{}EMP/ASC\_\-pubdefs.h\char`\"{}}\par


Include dependency graph for ASC.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=186pt]{ASC_8c__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__LCB__header}{\_\-LCB\_\-header}
\begin{CompactList}\small\item\em Layouts out the header for an LCB packet. The header is represented in terms of 32-bit quantities to avoid BIG/ LITTLE endian problems. \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{ASC_8c_a0}{
\#define \hyperlink{ASC_8c_a0}{LCB\_\-M\_\-PACKET\_\-ALIGN}~0xf}
\label{ASC_8c_a0}

\begin{CompactList}\small\item\em The size of a contributor must be an even multiple of this number. Currently an LCB packet is 128 bits or 16 bytes. This means that the low nibble of each length contributor's field must be zero. \item\end{CompactList}\item 
\#define \hyperlink{ASC_8c_a1}{LCB\_\-EXTRACT\_\-CID}(hdr\_\-clen)~(((hdr\_\-clen) $>$$>$ 17) \& 0x1f)
\begin{CompactList}\small\item\em Extracts the contributor id from the first word of the LCB header. \item\end{CompactList}\item 
\#define \hyperlink{ASC_8c_a2}{LCB\_\-EXTRACT\_\-CLEN}(hdr\_\-clen)~((hdr\_\-clen) \& 0xffff)
\begin{CompactList}\small\item\em Extracts the contributor length (in bytes) from the first word of the LCB header. \item\end{CompactList}\item 
\#define \hyperlink{ASC_8c_a3}{\_\-ADVANCE}(\_\-ptr, \_\-nbytes)~(void $\ast$)((unsigned char $\ast$)(\_\-ptr) + (\_\-nbytes))
\begin{CompactList}\small\item\em Advances {\em \_\-ptr\/} by {\em \_\-nbytes\/}. The return value is always recast to the type of {\em \_\-ptr\/}. \item\end{CompactList}\item 
\#define \hyperlink{ASC_8c_a4}{\_\-SKIP\_\-EHDR}(\_\-ptr)~(void $\ast$)((unsigned char $\ast$)(\_\-ptr)+sizeof(\hyperlink{struct__LCB__header}{LCB\_\-header}))
\begin{CompactList}\small\item\em Skips over the event header (LATp header + summary word) recast to the type of {\em \_\-ptr\/}. \item\end{CompactList}\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{ASC_8c_a5}{
typedef \hyperlink{struct__LCB__header}{\_\-LCB\_\-header} \hyperlink{ASC_8c_a5}{LCB\_\-header}}
\label{ASC_8c_a5}

\begin{CompactList}\small\item\em Typedef for {\em struct\/} \hyperlink{struct__LCB__header}{\_\-LCB\_\-header}. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static void \hyperlink{ASC_8c_a6}{clear} (void $\ast$ptr, int nbytes)
\begin{CompactList}\small\item\em Zeroes the specified memory. \item\end{CompactList}\item 
static void \hyperlink{ASC_8c_a7}{accumulate\_\-cno} (\hyperlink{struct__ASC__cno}{ASC\_\-cno} $\ast$cno, unsigned int cno\-Req\-Vec)
\begin{CompactList}\small\item\em Accumulates the number of CNO triggers from each FREE board. \item\end{CompactList}\item 
static void \hyperlink{ASC_8c_a8}{accumulate} (\hyperlink{struct__ASC__list}{ASC\_\-list} $\ast$list, unsigned int v, unsigned int hb, unsigned int ha, unsigned int pb, unsigned int pa)
\begin{CompactList}\small\item\em Accumulates the statistics for list (32-bits) of ACD hits. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{ASC_8c_a9}{prepare} (unsigned int w)
\begin{CompactList}\small\item\em Prepares the initial word of being used in the formation of the pattern word. \item\end{CompactList}\item 
static \_\-\_\-inline const unsigned int $\ast$ \hyperlink{ASC_8c_a10}{locate\_\-aem} (const unsigned int $\ast$evt, int elen)
\begin{CompactList}\small\item\em Composes the directory of the contributors. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{ASC_8c_a11}{form} (unsigned int v, unsigned int hb, unsigned int ha, unsigned int pb, unsigned int pa, int left)
\begin{CompactList}\small\item\em Forms the 5 bit pattern word from the bits in column {\em left\/} {\bf and} appropriately shifts the pattern word so that it may be used directly as a byte offset into the correct statistics counters. \item\end{CompactList}\item 
void \hyperlink{ASC_8c_a12}{ASC\_\-clear} (\hyperlink{struct__ASC__counters}{ASC\_\-counters} $\ast$counters)
\begin{CompactList}\small\item\em Clears the specified statistics counters. \item\end{CompactList}\item 
void \hyperlink{ASC_8c_a13}{ASC\_\-accumulate\-U} (\hyperlink{struct__ASC__counters}{ASC\_\-counters} $\ast$counters, const struct \_\-EBF\_\-gem $\ast$gem, const struct \_\-EDR\_\-acd $\ast$acd)
\begin{CompactList}\small\item\em Accumulates the proper pattern words for each ACD hit. \item\end{CompactList}\item 
const \_\-\_\-inline struct \_\-EBF\_\-gem $\ast$ \hyperlink{ASC_8c_a14}{ASC\_\-gem\_\-locate} (const unsigned int $\ast$edata, int esize)
\begin{CompactList}\small\item\em Locates GEM contribution in an event. \item\end{CompactList}\item 
const \_\-\_\-inline unsigned int $\ast$ \hyperlink{ASC_8c_a15}{ASC\_\-aem\_\-locate} (const unsigned int $\ast$edata, int esize)
\begin{CompactList}\small\item\em Locates AEM contribution in an event. \item\end{CompactList}\item 
int \hyperlink{ASC_8c_a16}{ASC\_\-acd\_\-sizeof} (void)
\begin{CompactList}\small\item\em Returns the size, in bytes, of the data structure needed to hold an unpacked ACD event. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
ACD Software Rate Counters, implementation file. 

\begin{Desc}
\item[Author:]JJRussell - \href{mailto:russell@slac.stanford.edu}{\tt russell@slac.stanford.edu}\end{Desc}


\footnotesize\begin{verbatim}    CVS $Id: ASC.c,v 1.8 2006/03/01 01:44:41 russell Exp $
\end{verbatim}
\normalsize


\begin{Desc}
\item[SYNOPSIS]Defines the the implementation for accumulating the ACD software rate counters\end{Desc}


\subsection{Define Documentation}
\hypertarget{ASC_8c_a3}{
\index{ASC.c@{ASC.c}!_ADVANCE@{\_\-ADVANCE}}
\index{_ADVANCE@{\_\-ADVANCE}!ASC.c@{ASC.c}}
\subsubsection[\_\-ADVANCE]{\setlength{\rightskip}{0pt plus 5cm}\#define \_\-ADVANCE(\_\-ptr, \_\-nbytes)~(void $\ast$)((unsigned char $\ast$)(\_\-ptr) + (\_\-nbytes))}}
\label{ASC_8c_a3}


Advances {\em \_\-ptr\/} by {\em \_\-nbytes\/}. The return value is always recast to the type of {\em \_\-ptr\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-ptr}]The pointer to advance \item[{\em \_\-nbytes}]The number of nbytes to advance {\em \_\-ptr\/} by. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The advanced pointer, the pointer is recast to a void $\ast$.\end{Desc}
\hypertarget{ASC_8c_a4}{
\index{ASC.c@{ASC.c}!_SKIP_EHDR@{\_\-SKIP\_\-EHDR}}
\index{_SKIP_EHDR@{\_\-SKIP\_\-EHDR}!ASC.c@{ASC.c}}
\subsubsection[\_\-SKIP\_\-EHDR]{\setlength{\rightskip}{0pt plus 5cm}\#define \_\-SKIP\_\-EHDR(\_\-ptr)~(void $\ast$)((unsigned char $\ast$)(\_\-ptr)+sizeof(\hyperlink{struct__LCB__header}{LCB\_\-header}))}}
\label{ASC_8c_a4}


Skips over the event header (LATp header + summary word) recast to the type of {\em \_\-ptr\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em \_\-ptr}]The pointer to advance \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The advanced pointer, the pointer is recast to a void $\ast$.\end{Desc}
\hypertarget{ASC_8c_a1}{
\index{ASC.c@{ASC.c}!LCB_EXTRACT_CID@{LCB\_\-EXTRACT\_\-CID}}
\index{LCB_EXTRACT_CID@{LCB\_\-EXTRACT\_\-CID}!ASC.c@{ASC.c}}
\subsubsection[LCB\_\-EXTRACT\_\-CID]{\setlength{\rightskip}{0pt plus 5cm}\#define LCB\_\-EXTRACT\_\-CID(hdr\_\-clen)~(((hdr\_\-clen) $>$$>$ 17) \& 0x1f)}}
\label{ASC_8c_a1}


Extracts the contributor id from the first word of the LCB header. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hdr\_\-clen}]The first word of the LCB header \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The contributor id\end{Desc}
\hypertarget{ASC_8c_a2}{
\index{ASC.c@{ASC.c}!LCB_EXTRACT_CLEN@{LCB\_\-EXTRACT\_\-CLEN}}
\index{LCB_EXTRACT_CLEN@{LCB\_\-EXTRACT\_\-CLEN}!ASC.c@{ASC.c}}
\subsubsection[LCB\_\-EXTRACT\_\-CLEN]{\setlength{\rightskip}{0pt plus 5cm}\#define LCB\_\-EXTRACT\_\-CLEN(hdr\_\-clen)~((hdr\_\-clen) \& 0xffff)}}
\label{ASC_8c_a2}


Extracts the contributor length (in bytes) from the first word of the LCB header. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hdr\_\-clen}]The first word of the LCB header \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]The contributor's length (in bytes)\end{Desc}


\subsection{Function Documentation}
\hypertarget{ASC_8c_a8}{
\index{ASC.c@{ASC.c}!accumulate@{accumulate}}
\index{accumulate@{accumulate}!ASC.c@{ASC.c}}
\subsubsection[accumulate]{\setlength{\rightskip}{0pt plus 5cm}static void accumulate (\hyperlink{struct__ASC__list}{ASC\_\-list} $\ast$ {\em list}, unsigned int {\em v}, unsigned int {\em hb}, unsigned int {\em ha}, unsigned int {\em pb}, unsigned int {\em pa})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{ASC_8c_a8}


Accumulates the statistics for list (32-bits) of ACD hits. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em list}]Pointer to the statistics for this list of ACD hits \item[{\em v}]The GEM list of veto bits \item[{\em hb}]The ACD hit bits for side {\em b\/} \item[{\em ha}]The ACD hit bits for side {\em a\/} \item[{\em pb}]The ACD pulse height accept bits for side {\em b\/} \item[{\em pa}]The ACD pulse height accept bits for side {\em a\/} \end{description}
\end{Desc}
\hypertarget{ASC_8c_a7}{
\index{ASC.c@{ASC.c}!accumulate_cno@{accumulate\_\-cno}}
\index{accumulate_cno@{accumulate\_\-cno}!ASC.c@{ASC.c}}
\subsubsection[accumulate\_\-cno]{\setlength{\rightskip}{0pt plus 5cm}static void accumulate\_\-cno (\hyperlink{struct__ASC__cno}{ASC\_\-cno} $\ast$ {\em cno}, unsigned int {\em cno\-Reqvec})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{ASC_8c_a7}


Accumulates the number of CNO triggers from each FREE board. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cno}]The CNO statistics block \item[{\em cno\-Reqvec}]The CNO and trigger request vector. The CNO trigger information occupies the lower 12 of the upper 16 bits.\end{description}
\end{Desc}
\hypertarget{ASC_8c_a13}{
\index{ASC.c@{ASC.c}!ASC_accumulateU@{ASC\_\-accumulateU}}
\index{ASC_accumulateU@{ASC\_\-accumulateU}!ASC.c@{ASC.c}}
\subsubsection[ASC\_\-accumulateU]{\setlength{\rightskip}{0pt plus 5cm}void ASC\_\-accumulate\-U (\hyperlink{struct__ASC__counters}{ASC\_\-counters} $\ast$ {\em counters}, const struct \_\-EBF\_\-gem $\ast$ {\em gem}, const struct \_\-EDR\_\-acd $\ast$ {\em acd})}}
\label{ASC_8c_a13}


Accumulates the proper pattern words for each ACD hit. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em counters}]The statistics counters \item[{\em gem}]Pointer to the GEM record \item[{\em acd}]Pointer to an unpacked ACD record\end{description}
\end{Desc}
This function is called on the assumption that the GEM record has been located and the ACD data has been both located and successfully unpacked.\hypertarget{ASC_8c_a16}{
\index{ASC.c@{ASC.c}!ASC_acd_sizeof@{ASC\_\-acd\_\-sizeof}}
\index{ASC_acd_sizeof@{ASC\_\-acd\_\-sizeof}!ASC.c@{ASC.c}}
\subsubsection[ASC\_\-acd\_\-sizeof]{\setlength{\rightskip}{0pt plus 5cm}int ASC\_\-acd\_\-sizeof (void)}}
\label{ASC_8c_a16}


Returns the size, in bytes, of the data structure needed to hold an unpacked ACD event. 

\begin{Desc}
\item[Returns:]The size, in bytes, of the data structure needed to hold an unpacked ACD event\end{Desc}
\hypertarget{ASC_8c_a15}{
\index{ASC.c@{ASC.c}!ASC_aem_locate@{ASC\_\-aem\_\-locate}}
\index{ASC_aem_locate@{ASC\_\-aem\_\-locate}!ASC.c@{ASC.c}}
\subsubsection[ASC\_\-aem\_\-locate]{\setlength{\rightskip}{0pt plus 5cm}const \_\-\_\-inline unsigned int$\ast$ ASC\_\-aem\_\-locate (const unsigned int $\ast$ {\em edata}, int {\em esize})}}
\label{ASC_8c_a15}


Locates AEM contribution in an event. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em A}]pointer to the AEM contribution. \item[{\em NULL}]is return if the AEM contribution cannnot be found\end{description}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em edata}]Pointer to the event data structure \item[{\em esize}]Size, in bytes, of the event\end{description}
\end{Desc}
\hypertarget{ASC_8c_a12}{
\index{ASC.c@{ASC.c}!ASC_clear@{ASC\_\-clear}}
\index{ASC_clear@{ASC\_\-clear}!ASC.c@{ASC.c}}
\subsubsection[ASC\_\-clear]{\setlength{\rightskip}{0pt plus 5cm}void ASC\_\-clear (\hyperlink{struct__ASC__counters}{ASC\_\-counters} $\ast$ {\em counters})}}
\label{ASC_8c_a12}


Clears the specified statistics counters. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em counters}]The statistics counters to be cleared\end{description}
\end{Desc}
\begin{Desc}
\item[Warning:]Currently this is a NON-interlocked operation.\end{Desc}
\hypertarget{ASC_8c_a14}{
\index{ASC.c@{ASC.c}!ASC_gem_locate@{ASC\_\-gem\_\-locate}}
\index{ASC_gem_locate@{ASC\_\-gem\_\-locate}!ASC.c@{ASC.c}}
\subsubsection[ASC\_\-gem\_\-locate]{\setlength{\rightskip}{0pt plus 5cm}const struct \_\-EBF\_\-gem $\ast$ ASC\_\-gem\_\-locate (const unsigned int $\ast$ {\em edata}, int {\em esize})}}
\label{ASC_8c_a14}


Locates GEM contribution in an event. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em A}]pointer to the GEM contribution. \item[{\em NULL}]is return if the GEM contribution cannnot be found\end{description}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em edata}]Pointer to the event data structure \item[{\em esize}]Size, in bytes, of the event\end{description}
\end{Desc}
\hypertarget{ASC_8c_a6}{
\index{ASC.c@{ASC.c}!clear@{clear}}
\index{clear@{clear}!ASC.c@{ASC.c}}
\subsubsection[clear]{\setlength{\rightskip}{0pt plus 5cm}void clear (void $\ast$ {\em ptr}, int {\em nbytes})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{ASC_8c_a6}


Zeroes the specified memory. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ptr}]Pointer to the memory to zero \item[{\em nbytes}]The number of bytes to zero\end{description}
\end{Desc}
This provides a fast way of zeroing large chunks of memory on PPC platforms using the {\em dcbz\/} instruction. This instruction zeroes a cache line at a time. The savings in speed various by processor, but factors of 5 or more are in the ballpark. For example, on the mv2304, zeroing 32K of memory

On other platforms, the generic memset routine is used.\hypertarget{ASC_8c_a11}{
\index{ASC.c@{ASC.c}!form@{form}}
\index{form@{form}!ASC.c@{ASC.c}}
\subsubsection[form]{\setlength{\rightskip}{0pt plus 5cm}unsigned int form (unsigned int {\em v}, unsigned int {\em hb}, unsigned int {\em ha}, unsigned int {\em pb}, unsigned int {\em pa}, int {\em left})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{ASC_8c_a11}


Forms the 5 bit pattern word from the bits in column {\em left\/} {\bf and} appropriately shifts the pattern word so that it may be used directly as a byte offset into the correct statistics counters. 

\begin{Desc}
\item[Returns:]A word that can be used to increment the statistics pattern counter.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em v}]The GEM list of veto bits \item[{\em hb}]The ACD hit bits for side {\em b\/} \item[{\em ha}]The ACD hit bits for side {\em a\/} \item[{\em pb}]The ACD pulse height accept bits for side {\em b\/} \item[{\em pa}]The ACD pulse height accept bits for side {\em a\/} \item[{\em left}]The bit number of the channel (counting from the left or MSB)\end{description}
\end{Desc}
\hypertarget{ASC_8c_a10}{
\index{ASC.c@{ASC.c}!locate_aem@{locate\_\-aem}}
\index{locate_aem@{locate\_\-aem}!ASC.c@{ASC.c}}
\subsubsection[locate\_\-aem]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline const unsigned int $\ast$ locate\_\-aem (const unsigned int $\ast$ {\em evt}, int {\em elen})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{ASC_8c_a10}


Composes the directory of the contributors. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em evt}]The source event. \item[{\em elen}]The size of the event in bytes \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]Pointer to the ACD data or NULL if it cannot be located.\end{Desc}
\hypertarget{ASC_8c_a9}{
\index{ASC.c@{ASC.c}!prepare@{prepare}}
\index{prepare@{prepare}!ASC.c@{ASC.c}}
\subsubsection[prepare]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned int prepare (unsigned int {\em w})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{ASC_8c_a9}


Prepares the initial word of being used in the formation of the pattern word. 

\begin{Desc}
\item[Returns:]The prepared word\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em w}]The word to prepare\end{description}
\end{Desc}
On the Power\-PC, 1 instruction in the accumulation loop is saved by preshifting the intial word used in the formation of the pattern word. All other platforms do the straightforward thing of shifting and oring each bit and this routine is a NOOP. By doing defining this routine, the bulk of the code is portable across platforms.