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

In This Package:

RomFragment.cc

Go to the documentation of this file.
00001 /*
00002  *  RomFragment.cc
00003  *  RawFileReading
00004  *
00005  *  Created by Simon Patton on 7/20/10.
00006  *  Copyright 2010 DayaBay Collaboration. All rights reserved.
00007  *
00008  */
00009 #include "EventReadoutFormat/RomFragment.h"
00010 
00011 #include "CbltReadoutFormat/CbltBody.h"
00012 #include "CbltReadoutFormat/CbltReadout.h"
00013 #include "DaqReadoutFormat/ByteBuffer.h"
00014 #include "DaqReadoutFormat/RomData.h"
00015 #include "FadcReadoutFormat/FadcReadout.h"
00016 #include "FeeReadoutFormat/FeeReadout.h"
00017 #include "LtbReadoutFormat/LtbReadout.h"
00018 #include "FecReadoutFormat/FecReadout.h"
00019 #include "RtmReadoutFormat/RtmReadout.h"
00020 #include "EventReadoutFormat/EventTraits.h"
00021 #include "EventReadoutFormat/RomHeader.h"
00022 
00023 using DybDaq::ByteBuffer;
00024 using DybDaq::CbltBody;
00025 using DybDaq::CbltReadout;
00026 using DybDaq::DaqBuffer;
00027 using DybDaq::EventTraits;
00028 using DybDaq::FadcReadout;
00029 using DybDaq::FeeReadout;
00030 using DybDaq::LtbReadout;
00031 using DybDaq::RomData;
00032 using DybDaq::RomFragment;
00033 using DybDaq::RomHeader;
00034 
00035 RomFragment::RomFragment(const unsigned int site,
00036                          const unsigned int detector,
00037                          const unsigned int moduleType,
00038                          const unsigned int slot,
00039                          const RomData* data,
00040                          const EventTraits& traits,
00041                          const bool cbltWrapping,
00042                          DaqExpandable& expandable) :
00043 DaqContainer(expandable),
00044 m_header(new RomHeader(site,
00045                        detector,
00046                        moduleType,
00047                        slot,
00048                        traits)),
00049 m_data(data),
00050 m_cbltWrapping(cbltWrapping) {
00051     expandedByRomData(data);
00052     m_header->setTotalSize(m_header->headerSize() + data->romSize());
00053 }
00054 
00055 
00056 RomFragment::RomFragment(const ByteBuffer& byteBuffer,
00057                          const EventTraits& traits,
00058                          const bool cbltWrapping) :
00059 DaqContainer(byteBuffer,
00060              traits,
00061              0),
00062 m_header(0),
00063 m_data(0),
00064 m_cbltWrapping(cbltWrapping) {
00065     byteBuffer.position(byteBuffer.position() + (header().totalSize() * kBytesInInt));
00066 }
00067 
00068 RomFragment::~RomFragment() {
00069     if (0 != m_data) {
00070         delete m_data;
00071     }
00072     if (0 != m_header) {
00073         delete m_header;
00074     }
00075 }
00076 
00077 const RomHeader& RomFragment::header() const {
00078     if (0 == m_header && hasByteBuffer()) {
00079         const ByteBuffer& buffer = byteBuffer();
00080         const unsigned int originalPosition = buffer.position();
00081         buffer.position(begin());
00082         m_header = new RomHeader(buffer,
00083                                  dynamic_cast<const EventTraits&>(daqTraits()));
00084         buffer.position(originalPosition);
00085     }
00086     return *m_header;
00087 }
00088 
00089 const RomData& RomFragment::data() const {
00090     if (0 == m_data && hasByteBuffer()) {
00091         const ByteBuffer& buffer = byteBuffer();
00092         const unsigned int originalPosition = buffer.position();
00093         const RomHeader& romHeader = header();
00094         const unsigned int headerSize = romHeader.headerSize();
00095         buffer.position(begin() + (headerSize * kBytesInInt));
00096         unsigned dataSize = romHeader.totalSize() - headerSize;
00097         // Check whether data contains CBLT wrappings
00098         static const unsigned int cbltMask = 0xf0000000U;
00099         static const unsigned int cbltValue = 0x20000000U;
00100         const unsigned int peek = *((unsigned int*)(buffer.cursor()));
00101         //
00102         if (m_cbltWrapping || (cbltValue == (peek & cbltMask))) {
00103             m_data = new CbltReadout(buffer,
00104                                      dataSize);
00105             
00106         } else {
00107             const EventTraits& traits = romHeader.eventTraits();
00108             const unsigned int moduleType = romHeader.moduleType();
00109             if (moduleType == traits.moduleType(EventTraits::kFadcModule)) {
00110                 m_data = new FadcReadout(buffer,
00111                                          dataSize);
00112             } else if (moduleType == traits.moduleType(EventTraits::kFeeModule)) {
00113                 m_data = new FeeReadout(buffer,
00114                                         dataSize);
00115             } else if (moduleType == traits.moduleType(EventTraits::kLtbModule)) {
00116                 m_data = new LtbReadout(buffer,
00117                                         dataSize);
00118             }
00119             else if (moduleType == traits.moduleType(EventTraits::kRpcRomModule)) {
00120                m_data = new FecReadout(buffer, dataSize);
00121             }
00122             else if (moduleType == traits.moduleType(EventTraits::kRpcRtmModule)) {
00123                m_data = new RtmReadout(buffer, dataSize);
00124             }
00125         }
00126         buffer.position(originalPosition);
00127     }
00128     return *m_data;
00129 }
00130 
00131 const RomData& RomFragment::unwrappedData() const {
00132     // Make sure m_data is filled
00133     data();
00134     const CbltReadout* cbltReadout = dynamic_cast<const CbltReadout*> (m_data);
00135     if (0 == cbltReadout) {
00136         return *m_data;
00137     }
00138     return cbltReadout->body().data();
00139 }
00140 
00141 
00142 unsigned int RomFragment::bufferSize() const {
00143     return header().totalSize();
00144 }
00145 
00146 unsigned int RomFragment::gatherComponents(DaqBuffer::OutputBufferList& outputBuffers) const {
00147     unsigned int result = header().gather(outputBuffers);
00148     
00149     result += data().gatherRom(outputBuffers);
00150     return result;
00151 }
00152 
00153 unsigned int RomFragment::inspectComponents(DaqBuffer::Bytes& inspectors) const {
00154     unsigned int result = header().inspect(inspectors);
00155     
00156     result += data().inspectRom(inspectors);
00157     return result;
00158 }
00159 
00160 void RomFragment::expanded(const unsigned int size) {
00161     // If this is non-const, then header must already exist.
00162     m_header->setTotalSize(m_header->totalSize() + size);
00163     notifyExpandable(size);
00164 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:08:24 2011 for EventReadoutFormat by doxygen 1.4.7