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

Generated on Fri May 16 2014 09:53:15 for EventReadoutFormat by doxygen 1.7.4