| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

CbltReadout.cc

Go to the documentation of this file.
00001 /*
00002  *  CbltReadout.cc
00003  *  CbltReadoutFormat
00004  *
00005  *  Created by Simon Patton on 7/22/10.
00006  *  Copyright 2010 DayaBay Collaboration. All rights reserved.
00007  *
00008  */
00009 #include "CbltReadoutFormat/CbltReadout.h"
00010 
00011 #include "CbltReadoutFormat/CbltBody.h"
00012 #include "CbltReadoutFormat/CbltFoot.h"
00013 #include "CbltReadoutFormat/CbltHead.h"
00014 #include "CbltReadoutFormat/CbltTraits.h"
00015 #include "DaqReadoutFormat/ByteBuffer.h"
00016 
00017 using DybDaq::ByteBuffer;
00018 using DybDaq::CbltBody;
00019 using DybDaq::CbltBuffer;
00020 using DybDaq::CbltFoot;
00021 using DybDaq::CbltHead;
00022 using DybDaq::CbltReadout;
00023 using DybDaq::CbltTraits;
00024 using DybDaq::DaqBuffer;
00025 using DybDaq::DaqTraits;
00026 
00027 // Used to fudge CBLT data
00028 #include "LtbReadoutFormat/LtbHead.h"
00029 #include "LtbReadoutFormat/LtbReadout.h"
00030 
00031 using DybDaq::LtbHead;
00032 using DybDaq::LtbReadout;
00033 
00034 CbltReadout::CbltReadout(const unsigned int moduleAddress,
00035                          const unsigned int moduleType,
00036                          const RomData* romData,
00037                          const CbltTraits& traits) :
00038 DaqContainer(),
00039 m_head(new CbltHead(moduleAddress,
00040                     moduleType,
00041                     traits)),
00042 m_body(new CbltBody(romData,
00043                     moduleType,
00044                     *this)),
00045 m_foot(0) {
00046     const LtbReadout* ltbReadout;
00047     if (0 != (ltbReadout = dynamic_cast<const LtbReadout*>(romData))) {
00048         // TODO: DAQ_ERROR, Fix LTB trigger number!
00049         const LtbHead& ltbHead = ltbReadout->head();
00050         if (ltbHead.ltbTraits().majorVersion() > 3) {
00051             // Set undocumented values
00052         const unsigned int triggerNumber = ltbHead.localTriggerNumber();
00053         *((unsigned int*)m_head->buffer()) = *((const unsigned int*)m_head->buffer())
00054             + ((triggerNumber % 256) * 256)
00055             + (triggerNumber % 256);
00056         }
00057     }
00058     CbltFoot& footToUse = foot();
00059     footToUse.setDataLength(footToUse.dataLength() + (m_body->bufferSize() * kBytesInInt));
00060 }
00061 
00062 CbltReadout::CbltReadout(const ByteBuffer& byteBuffer,
00063                          const unsigned int bufferSize) :
00064 DaqContainer(byteBuffer,
00065              bufferSize),
00066 m_head(0),
00067 m_body(0),
00068 m_foot(0) {
00069     byteBuffer.position(byteBuffer.position() + (bufferSize * kBytesInInt));
00070 }
00071 
00072 CbltReadout::~CbltReadout() {
00073     if (0 != m_foot) {
00074         delete m_foot;
00075     }
00076     if (0 != m_body) {
00077         delete m_body;
00078     }
00079     if (0 != m_head) {
00080         delete m_head;
00081     }
00082 }
00083 
00084 const DaqTraits& CbltReadout::daqTraits() const {
00085     return head().cbltTraits();
00086 }
00087 
00088 const CbltHead& CbltReadout::head() const {
00089     if (0 == m_head && hasByteBuffer()) {
00090         const ByteBuffer& buffer = byteBuffer();
00091         const unsigned int originalPosition = buffer.position();
00092         buffer.position(begin());
00093         m_head = new CbltHead(buffer);
00094         buffer.position(originalPosition);
00095     }
00096     return *m_head;
00097 }
00098 
00099 const CbltBody& CbltReadout::body() const {
00100     if (0 == m_body) {
00101         if (hasByteBuffer()) {
00102             const CbltTraits& traits = cbltTraits();
00103             const ByteBuffer& buffer = byteBuffer();
00104             
00105             const unsigned int originalPosition = buffer.position();
00106             buffer.position(begin() + (traits.headSize() * kBytesInInt));
00107             m_body = new CbltBody(buffer,
00108                                   head().moduleType(),
00109                                   containerSize() - (traits.headSize() + traits.footSize()),
00110                                   head().cbltTraits());
00111             buffer.position(originalPosition);
00112         }
00113     }
00114     return *m_body;
00115 }
00116 
00117 const CbltFoot& CbltReadout::foot() const {
00118     if (0 == m_foot && hasByteBuffer()) {
00119         const CbltTraits& traits = cbltTraits();
00120         const ByteBuffer& buffer = byteBuffer();
00121         
00122         const unsigned int originalPosition = buffer.position();
00123         buffer.position(begin() + ((containerSize() - traits.footSize()) * kBytesInInt));
00124         m_foot = new CbltFoot(buffer,
00125                               head().cbltTraits());
00126         buffer.position(originalPosition);
00127         
00128     }
00129     return *m_foot;
00130 }
00131 
00132 unsigned int CbltReadout::romSize() const {
00133     return bufferSize();
00134 }
00135 
00136 unsigned int CbltReadout::gatherRom(DaqBuffer::OutputBufferList& outputBuffers) const {
00137     return gather(outputBuffers);
00138 }
00139 
00140 unsigned int CbltReadout::inspectRom(DaqBuffer::Bytes& inspectors) const {
00141     return inspect(inspectors);
00142 }
00143 
00144 unsigned int CbltReadout::bufferSize() const {
00145     unsigned int result = head().bufferSize();
00146     result += body().bufferSize();
00147     result += foot().bufferSize();
00148     return result;
00149 }
00150 
00151 unsigned int CbltReadout::gatherComponents(DaqBuffer::OutputBufferList& outputBuffers) const {
00152     unsigned int result = head().gather(outputBuffers);
00153     result += body().gather(outputBuffers);
00154     
00155     result += foot().gather(outputBuffers);
00156     return result;
00157 }
00158 
00159 unsigned int CbltReadout::inspectComponents(DaqBuffer::Bytes& inspectors) const {
00160     unsigned int result = head().inspect(inspectors);
00161     result += body().inspect(inspectors);
00162     
00163     result += foot().inspect(inspectors);
00164     return result;
00165 }
00166 
00167 void CbltReadout::expanded(const unsigned int size) {
00168     CbltFoot& footToUse = foot();
00169     footToUse.setDataLength(footToUse.dataLength() + (size * kBytesInInt));
00170     notifyExpandable(size);
00171 }
00172 
00173 bool CbltReadout::setRomExpandable(DaqExpandable& expandable) {
00174     return setExpandable(expandable);
00175 }
00176 
00177 const CbltTraits& CbltReadout::cbltTraits() const {
00178     return dynamic_cast<const CbltTraits&>(daqTraits());
00179 }
00180 
00181 CbltFoot& CbltReadout::foot() {
00182     if (0 == m_foot) {
00183         m_foot = new CbltFoot(head());
00184     }
00185     return *m_foot;
00186 }
00187 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:08:16 2011 for CbltReadoutFormat by doxygen 1.4.7