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

In This Package:

LtbReadout.cc

Go to the documentation of this file.
00001 /*
00002  *  LtbReadout.cc
00003  *  LtbReadoutFormat
00004  *
00005  *  Created by Simon Patton on 7/22/10.
00006  *  Copyright 2010 DayaBay Collaboration. All rights reserved.
00007  *
00008  */
00009 
00010 #include "LtbReadoutFormat/LtbReadout.h"
00011 
00012 #include "DaqReadoutFormat/ByteBuffer.h"
00013 #include "LtbReadoutFormat/LtbFrame.h"
00014 #include "LtbReadoutFormat/LtbFoot.h"
00015 #include "LtbReadoutFormat/LtbHead.h"
00016 #include "LtbReadoutFormat/LtbTraits.h"
00017 
00018 using DybDaq::ByteBuffer;
00019 using DybDaq::DaqBuffer;
00020 using DybDaq::DaqContainer;
00021 using DybDaq::DaqTraits;
00022 using DybDaq::LtbBuffer;
00023 using DybDaq::LtbFoot;
00024 using DybDaq::LtbFrame;
00025 using DybDaq::LtbHead;
00026 using DybDaq::LtbReadout;
00027 using DybDaq::LtbTraits;
00028 
00029 LtbReadout::LtbReadout(const unsigned int localTriggerNumber,
00030                        const unsigned int rawTriggerTotal,
00031                        const unsigned int ltbStatus,
00032                        const bool clockError,
00033                        const LtbTraits& traits) :
00034 DaqContainer(),
00035 m_head(new LtbHead(localTriggerNumber,
00036                    rawTriggerTotal,
00037                    ltbStatus,
00038                    clockError,
00039                    traits)),
00040 m_frames(0),
00041 m_foot(0) {
00042 }
00043 
00044 LtbReadout::LtbReadout(const ByteBuffer& byteBuffer,
00045                        const unsigned int bufferSize) :
00046 DaqContainer(byteBuffer,
00047              bufferSize),
00048 m_head(0),
00049 m_frames(0),
00050 m_foot(0) {
00051     byteBuffer.position(byteBuffer.position() + (bufferSize * kBytesInInt));
00052 }
00053 
00054 LtbReadout::~LtbReadout() {
00055     if (0 != m_foot) {
00056         delete m_foot;
00057     }
00058         if (0 != m_frames) {
00059                 LtbFramePtrList::iterator iterator;
00060                 for (iterator = m_frames->begin();
00061                          iterator != m_frames->end();
00062                          ++iterator) {
00063                         delete const_cast<LtbFrame*>(*iterator);
00064                 }
00065                 delete m_frames;
00066         }
00067     if (0 != m_head) {
00068         delete m_head;
00069     }
00070 }
00071 
00072 const DaqTraits& LtbReadout::daqTraits() const {
00073     return head().ltbTraits();
00074 }
00075 
00076 const LtbHead& LtbReadout::head() const {
00077     if (0 == m_head && hasByteBuffer()) {
00078         const ByteBuffer& buffer = byteBuffer();
00079         const unsigned int originalPosition = buffer.position();
00080         buffer.position(begin());
00081         m_head = new LtbHead(buffer);
00082         buffer.position(originalPosition);
00083     }
00084     return *m_head;
00085 }
00086 
00087 const LtbReadout::LtbFramePtrList& LtbReadout::ltbFrames() const {
00088     if (0 == m_frames) {
00089         m_frames = new LtbFramePtrList();
00090         if (hasByteBuffer()) {
00091             const LtbTraits& traits = head().ltbTraits();
00092             const ByteBuffer& buffer = byteBuffer();
00093             
00094             const unsigned int originalPosition = buffer.position();
00095             buffer.position(begin() + (traits.headSize() * kBytesInInt));
00096             const unsigned int finished = (containerSize() - (traits.headSize() + traits.footSize())) / traits.frameSize();
00097             for (unsigned int count = 0;
00098                  count != finished;
00099                  ++count) {
00100                 const LtbFrame* frame = new LtbFrame(buffer,
00101                                                      traits);    
00102                 m_frames->push_back(frame);
00103             }
00104             buffer.position(originalPosition);
00105         }
00106     }
00107     return *m_frames;
00108 }
00109 
00110 const LtbFoot& LtbReadout::foot() const {
00111     if (0 == m_foot && hasByteBuffer()) {
00112         const LtbTraits& traits = head().ltbTraits();
00113         const ByteBuffer& buffer = byteBuffer();
00114         
00115         const unsigned int originalPosition = buffer.position();
00116         buffer.position(begin() + ((containerSize() - traits.footSize()) * kBytesInInt));
00117         m_foot = new LtbFoot(buffer,
00118                              head().ltbTraits());
00119         buffer.position(originalPosition);
00120         
00121     }
00122     return *m_foot;
00123 }
00124 
00125 unsigned int LtbReadout::gatherRom(DaqBuffer::OutputBufferList& outputBuffers) const {
00126     return gather(outputBuffers);
00127 }
00128 
00129 unsigned int LtbReadout::inspectRom(DaqBuffer::Bytes& inspectors) const {
00130     return inspect(inspectors);
00131 }
00132 
00133 unsigned int LtbReadout::romSize() const {
00134     return bufferSize();
00135 }
00136 
00137 unsigned int LtbReadout::gatherComponents(OutputBufferList& outputBuffers) const {
00138     unsigned int result = head().gather(outputBuffers);
00139     const LtbFramePtrList& frames = ltbFrames();
00140     LtbFramePtrList::const_iterator frame;
00141     for (frame = frames.begin();
00142          frame != frames.end();
00143          ++frame) {
00144         result += (*frame)->gather(outputBuffers);
00145     }
00146     
00147     result += foot().gather(outputBuffers);
00148     return result;
00149 }
00150 
00151 unsigned int LtbReadout::inspectComponents(DaqBuffer::Bytes& inspectors) const {
00152     unsigned int result = head().inspect(inspectors);
00153     const LtbFramePtrList& frames = ltbFrames();
00154     LtbFramePtrList::const_iterator frame;
00155     for (frame = frames.begin();
00156          frame != frames.end();
00157          ++frame) {
00158         result += (*frame)->inspect(inspectors);
00159     }
00160     
00161     result += foot().inspect(inspectors);
00162     return result;
00163 }
00164     
00165 unsigned int LtbReadout::bufferSize() const {
00166     unsigned int result = head().bufferSize();
00167     const LtbFramePtrList& frames = ltbFrames();
00168     LtbFramePtrList::const_iterator frame;
00169     for (frame = frames.begin();
00170          frame != frames.end();
00171          ++frame) {
00172         result += (*frame)->bufferSize();
00173     }
00174     result += foot().bufferSize();
00175     return result;
00176 }
00177 
00178 void LtbReadout::expanded(const unsigned int size) {
00179     LtbFoot& footToUse = foot();
00180     footToUse.setDataLength(footToUse.dataLength() + (size * kBytesInInt));
00181     notifyExpandable(size);
00182 }
00183 
00184 bool LtbReadout::setRomExpandable(DaqExpandable& expandable) {
00185     return setExpandable(expandable);
00186 }
00187 
00188 const LtbFrame& LtbReadout::addFrame(const unsigned int readoutType,
00189                                      const unsigned int triggerMask,
00190                                      const LtbTraits::LtbDateTime& dateTime,
00191                                      const unsigned int halfNanoseconds,
00192                                      const int accumulation,
00193                                      const unsigned int hitSum,
00194                                      const bool totalEsum,
00195                                      const bool highEsum,
00196                                      const bool lowEsum,
00197                                      const unsigned int energySum,
00198                                      const unsigned int crossTriggerSource,
00199                                      const bool accumulationStatus,
00200                                      const bool validGps,
00201                                      const bool usingUtc,
00202                                      const bool validClockSystem,
00203                                      const bool feeBufferFull,
00204                                      const bool ltbBufferFull,
00205                                      const unsigned int blockedTriggerCount) {
00206     LtbFrame* result = new LtbFrame(readoutType,
00207                                     triggerMask,
00208                                     dateTime,
00209                                     halfNanoseconds,
00210                                     accumulation,
00211                                     hitSum,
00212                                     totalEsum,
00213                                     highEsum,
00214                                     lowEsum,
00215                                     energySum,
00216                                     crossTriggerSource,
00217                                     accumulationStatus,
00218                                     validGps,
00219                                     usingUtc,
00220                                     validClockSystem,
00221                                     feeBufferFull,
00222                                     ltbBufferFull,
00223                                     blockedTriggerCount,
00224                                     head().ltbTraits());
00225     return addFrame(result);
00226 }
00227 
00228 const LtbFrame& LtbReadout::addFrame(const LtbFrame* frame) {
00229     if (0 == m_frames) {
00230         m_frames = new LtbFramePtrList();
00231     }
00232     (const_cast<LtbFrame*>(frame))->setFrameNumber(m_frames->size());
00233     m_frames->push_back(frame);
00234     m_head->setRawTriggersSaved(m_frames->size());
00235     expanded(frame->bufferSize());
00236     return *frame;
00237 }
00238 
00239 LtbFoot& LtbReadout::foot() {
00240     if (0 == m_foot) {
00241         m_foot = new LtbFoot(head());
00242     }
00243     return *m_foot;
00244 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

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