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