00001 #include "FecReadoutFormat/FecReadout.h"
00002 #include "FecReadoutFormat/FecTraits.h"
00003 #include "FecReadoutFormat/FecData.h"
00004 #include "DaqReadoutFormat/ByteBuffer.h"
00005
00006 #include <iostream>
00007
00008 using DybDaq::DaqTraits;
00009 using DybDaq::FecData;
00010 using DybDaq::FecTraits;
00011 using DybDaq::FecReadout;
00012
00013
00014 FecReadout::FecReadout(const FecTraits& traits)
00015 : DaqContainer(),
00016 m_fecList(0),
00017 m_verFormat(0),
00018 m_fecTraits(&traits)
00019 {
00020 }
00021
00022 FecReadout::FecReadout(const ByteBuffer& byteBuffer,
00023 const unsigned int bufferSize,
00024 const unsigned int verFormat)
00025 : DaqContainer(byteBuffer, bufferSize),
00026 m_fecList(0),
00027 m_verFormat(verFormat),
00028 m_fecTraits(0)
00029 {
00030 byteBuffer.position( byteBuffer.position() + bufferSize * kBytesInInt );
00031 }
00032
00033 FecReadout::~FecReadout()
00034 {
00035 if ( m_fecList != 0 ) {
00036 FecDataPtrList::iterator it = m_fecList->begin();
00037 while ( it != m_fecList->end() ) {
00038 delete *it;
00039 ++it;
00040 }
00041 delete m_fecList;
00042 }
00043 }
00044
00045 const DaqTraits& FecReadout::daqTraits() const
00046 {
00047 return fecTraits();
00048 }
00049
00050 const FecReadout::FecDataPtrList& FecReadout::fecDataList() const
00051 {
00052 if ( m_fecList == 0 ) {
00053 m_fecList = new FecDataPtrList();
00054 if ( hasByteBuffer() ) {
00055 const FecTraits& traits = fecTraits();
00056 const ByteBuffer& buffer = byteBuffer();
00057
00058 const unsigned int originalPosition = buffer.position();
00059 buffer.position( begin() );
00060 const unsigned int finished = containerSize() / traits.fecSize();
00061 for ( unsigned int count = 0; count != finished; ++count ) {
00062 FecData* fecData = new FecData(buffer, traits);
00063 m_fecList->push_back(fecData);
00064 }
00065 buffer.position( originalPosition );
00066 }
00067 }
00068 return *m_fecList;
00069 }
00070
00071 unsigned int FecReadout::romSize() const
00072 {
00073 return bufferSize();
00074 }
00075
00076 unsigned int FecReadout::gatherRom(OutputBufferList& outputBuffers) const
00077 {
00078 return gather(outputBuffers);
00079 }
00080
00081 unsigned int FecReadout::inspectRom(DaqBuffer::Bytes& inspectors) const
00082 {
00083 return inspect(inspectors);
00084 }
00085
00086 unsigned int FecReadout::bufferSize() const
00087 {
00088 unsigned int result = 0;
00089 const FecDataPtrList& fecList = fecDataList();
00090
00091 FecDataPtrList::const_iterator it = fecList.begin();
00092 while ( it != fecList.end() ) {
00093 result += (*it)->bufferSize();
00094 ++it;
00095 }
00096
00097 return result;
00098 }
00099
00100 const FecData& FecReadout::addFecData(const unsigned int rpcCFId,
00101 const unsigned int rpcFecId,
00102 const bool transErr1,
00103 const bool transErr2,
00104 const unsigned int trigType,
00105 const bool fullFlag,
00106 const bool validGPS,
00107 const bool validCLK,
00108 const bool usingUTC,
00109 const unsigned int second,
00110 const unsigned int nanoSecond,
00111 const unsigned int hitMap)
00112 {
00113 FecData* result = new FecData(rpcCFId,
00114 rpcFecId,
00115 transErr1,
00116 transErr2,
00117 trigType,
00118 fullFlag,
00119 validGPS,
00120 validCLK,
00121 usingUTC,
00122 second,
00123 nanoSecond,
00124 hitMap,
00125 fecTraits() );
00126 return add( result );
00127 }
00128
00129 unsigned int FecReadout::gatherComponents(OutputBufferList& outputBuffers) const
00130 {
00131 unsigned int result = 0;
00132 const FecDataPtrList& fecList = fecDataList();
00133
00134 FecDataPtrList::const_iterator it = fecList.begin();
00135 while ( it != fecList.end() ) {
00136 result += (*it)->gather(outputBuffers);
00137 ++it;
00138 }
00139
00140 return result;
00141 }
00142
00143 unsigned int FecReadout::inspectComponents(DaqBuffer::Bytes& inspectors) const
00144 {
00145 unsigned int result = 0;
00146 const FecDataPtrList& fecList = fecDataList();
00147
00148 FecDataPtrList::const_iterator it = fecList.begin();
00149 while ( it != fecList.end() ) {
00150 result += (*it)->inspect(inspectors);
00151 ++it;
00152 }
00153
00154 return result;
00155 }
00156
00157 void FecReadout::expanded(const unsigned int size)
00158 {
00159 notifyExpandable(size);
00160 }
00161
00162 bool FecReadout::setRomExpandable(DaqExpandable& expandable)
00163 {
00164 return setExpandable(expandable);
00165 }
00166
00167 const FecTraits& FecReadout::fecTraits() const
00168 {
00169 if ( m_fecTraits == 0 ) {
00170 m_fecTraits = FecTraits::getTraits(m_verFormat);
00171 }
00172 return *m_fecTraits;
00173 }
00174
00175 const FecData& FecReadout::add(const FecData* fecData)
00176 {
00177 if ( m_fecList == 0 ) {
00178 m_fecList = new FecDataPtrList();
00179 }
00180
00181 m_fecList->push_back(fecData);
00182 expanded( fecData->bufferSize() );
00183
00184 return *fecData;
00185 }