Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

/var/pcce/usera/hill/rcc_1.2/RodDaq/RodCrate/RodPrimList.cxx

Go to the documentation of this file.
00001 // File: RodPrimList.cxx
00002 // $Header: /afs/cern.ch/user/s/sctpixel/private/cvsroot/RodDaq/RodCrate/RodPrimList.cxx,v 1.4 2002/12/17 20:08:31 tmeyer Exp $
00003 
00004 #include "RodPrimList.h"
00005 
00006 namespace SctPixelRod {
00007 
00008 //***************************Class PrimListException**************************
00009 //
00010 // Description:
00011 //   This is a class to handle exceptions in the PrimList Class.
00012 //
00013 //
00014 // @author Tom Meyer (meyer@iastate.edu) - originator
00015 //
00016 
00017 PrimListException::PrimListException( std::string descriptor, unsigned long data1,
00018                             unsigned long data2) {
00019   m_descriptor = descriptor;
00020   m_data1 = data1;
00021   m_data2 = data2;
00022   }
00023   
00024 // Description:
00025 //  Class RodPrimList is a list of the primitives that control ROD behavior.  
00026 // It is sent to the RodModule via its Send function.  As it is derived 
00027 // from the STL list, it inherits all the usual list functionality.
00028 //
00029 // @author Tom Meyer (meyer@iastate.edu) - originator
00030 //
00031 RodPrimList::RodPrimList(const RodPrimList &rhs) :
00032   list<RodPrimitive>(rhs) {
00033   m_index=rhs.getIndex();
00034   m_version=rhs.getVersion();
00035 }
00036 
00037 RodPrimList &RodPrimList::operator=(const RodPrimList &rhs) {
00038   if (this == &rhs)
00039     return *this;
00040   list<RodPrimitive>::operator=(rhs);
00041   m_index=rhs.getIndex();
00042   m_version=rhs.getVersion();
00043   if (rhs.m_buffer) {
00044     m_bufferSize=rhs.m_bufferSize;
00045     copy(rhs.m_buffer, rhs.m_buffer+rhs.m_bufferSize, m_buffer);
00046   } else {
00047     m_bufferSize=0;
00048     m_buffer=0;
00049   }
00050   return *this;
00051 }
00052 
00053 RodPrimList::~RodPrimList() {
00054   if (m_buffer) 
00055     delete [] m_buffer;
00056 }
00057 
00058 unsigned long RodPrimList::numWords() {
00059   unsigned long n=6; 
00060     // Head and tail make up 6 words
00061   RodPrimList::iterator i; 
00062   for (i = begin(); i != end(); i++)
00063     n += i->getLength();
00064   return n;
00065 }
00066 
00067 unsigned long RodPrimList::checkSum() {
00068   unsigned long c = m_buffer[0];; 
00069   for (unsigned long i = 1; i < m_bufferSize-1; i++) {
00070     c ^= m_buffer[i];
00071   }
00072   return c;
00073 }
00074 
00075 void RodPrimList::bufferBuild() throw(PrimListException &) {
00076   m_bufferSize = numWords();
00077   m_buffer = new unsigned long[m_bufferSize]; // call clear() to delete m_buffer
00078   if (0 == m_buffer) throw PrimListException(
00079       "Bufferbuild unable to allocate buffer, bufferSize, index:", m_bufferSize, 
00080       m_index);
00081   m_buffer[0] = m_bufferSize;
00082   m_buffer[1] = m_index;
00083   m_buffer[2] = this->size();  // Number of primitives in the list
00084   m_buffer[3] = m_version;
00085 
00086   long bufPos=4;
00087   long primLength;
00088   long *bodyBegin, *bodyEnd;
00089 
00090   for (RodPrimList::iterator i = this->begin(); i != this->end(); i++) {
00091     primLength = i->getLength();
00092     m_buffer[bufPos++] = primLength;
00093     m_buffer[bufPos++] = i->getIndex();
00094     m_buffer[bufPos++] = i->getId();
00095     m_buffer[bufPos++] = i->getVersion();
00096     bodyBegin=i->getBody(); bodyEnd=bodyBegin+primLength-4;
00097     for(long *j=bodyBegin; j < bodyEnd; j++, bufPos++) 
00098         m_buffer[bufPos]=(unsigned long) *j;
00099   } 
00100   m_buffer[bufPos++] = m_bufferSize;
00101   m_buffer[bufPos] = checkSum();
00102 }
00103 
00104 void RodPrimList::clear() {
00105   this->erase(begin(), end());
00106   m_bufferSize=0;
00107   if (m_buffer)
00108     delete [] m_buffer;
00109     m_buffer = 0;
00110 }
00111 
00112 void RodPrimList::print() {
00113   if (!m_buffer)
00114     cerr << "Please call bufferBuild before printing.\n";
00115   for (unsigned int i=0; i<m_bufferSize; i++) 
00116     cout << m_buffer[i] << endl;
00117 }
00118 } // End namespace SctPixelRod

Generated on Mon Mar 3 11:16:17 2003 for SCTPixelDAQ by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001