/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

FeeReadout.cc
Go to the documentation of this file.
00001 /*
00002  *  FeeReadout.cc
00003  *  FeeReadoutFormat
00004  *
00005  *  Created by Simon Patton on 7/22/10.
00006  *  Copyright 2010 DayaBay Collaboration. All rights reserved.
00007  *
00008  */
00009 #include "FeeReadoutFormat/FeeReadout.h"
00010 
00011 #include "DaqReadoutFormat/ByteBuffer.h"
00012 #include "FeeReadoutFormat/FeeFoot.h"
00013 #include "FeeReadoutFormat/FeeHead.h"
00014 #include "FeeReadoutFormat/FeeHit.h"
00015 #include "FeeReadoutFormat/FeeTraits.h"
00016 
00017 using DybDaq::DaqBuffer;
00018 using DybDaq::DaqContainer;
00019 using DybDaq::DaqTraits;
00020 using DybDaq::FeeFoot;
00021 using DybDaq::FeeHead;
00022 using DybDaq::FeeHit;
00023 using DybDaq::FeeReadout;
00024 
00025 FeeReadout::FeeReadout(const unsigned int triggerNumber,
00026                        const unsigned int triggerType,
00027                        const bool checked,
00028                        const bool error,
00029                        const FeeTraits& traits) :
00030 DaqContainer(),
00031 m_head(new FeeHead(triggerNumber,
00032                    triggerType,
00033                    checked,
00034                    error,
00035                    traits)),
00036 m_hits(0),
00037 m_foot(0) {
00038 }
00039 
00040 FeeReadout::FeeReadout(const ByteBuffer& byteBuffer,
00041                        const unsigned int bufferSize) :
00042 DaqContainer(byteBuffer,
00043              bufferSize),
00044 m_head(0),
00045 m_hits(0),
00046 m_foot(0) {
00047     byteBuffer.position(byteBuffer.position() + (bufferSize * kBytesInInt));
00048 }
00049 
00050 FeeReadout::~FeeReadout() {
00051     if (0 != m_foot) {
00052         delete m_foot;
00053     }
00054         if (0 != m_hits) {
00055                 FeeHitPtrList::const_iterator hit;
00056                 for (hit = m_hits->begin();
00057                          hit != m_hits->end();
00058                          ++hit) {
00059                         delete const_cast<FeeHit*>(*hit);
00060                 }
00061                 delete m_hits;
00062         }
00063     if (0 != m_head) {
00064         delete m_head;
00065     }
00066 }
00067 
00068 const DaqTraits& FeeReadout::daqTraits() const {
00069     return head().feeTraits();
00070 }
00071 
00072 const FeeHead& FeeReadout::head() const {
00073     if (0 == m_head && hasByteBuffer()) {
00074         const ByteBuffer& buffer = byteBuffer();
00075         const unsigned int originalPosition = buffer.position();
00076         buffer.position(begin());
00077         m_head = new FeeHead(buffer);
00078         buffer.position(originalPosition);
00079     }
00080     return *m_head;
00081 }
00082 
00083 const FeeReadout::FeeHitPtrList& FeeReadout::feeHits() const {
00084     if (0 == m_hits) {
00085         m_hits = new FeeHitPtrList();
00086         if (hasByteBuffer()) {
00087             const FeeTraits& traits = head().feeTraits();
00088             const ByteBuffer& buffer = byteBuffer();
00089             
00090             const unsigned int originalPosition = buffer.position();
00091             buffer.position(begin() + (traits.headSize() * kBytesInInt));
00092             const unsigned int finished = (containerSize() - (traits.headSize() + traits.footSize())) / traits.hitSize();
00093             for (unsigned int count = 0;
00094                  count != finished;
00095                  ++count) {
00096                 FeeHit* hit = new FeeHit(buffer,
00097                                          traits);
00098                 m_hits->push_back(hit);
00099             }
00100             buffer.position(originalPosition);
00101         }
00102     }
00103     return *m_hits;
00104 }
00105 
00106 const FeeFoot& FeeReadout::foot() const {
00107     if (0 == m_foot) {
00108         if (hasByteBuffer()) {
00109             const FeeTraits& traits = head().feeTraits();
00110             const ByteBuffer& buffer = byteBuffer();
00111             
00112             const unsigned int originalPosition = buffer.position();
00113             buffer.position(begin() + ((containerSize() - traits.footSize()) * kBytesInInt));
00114             m_foot = new FeeFoot(buffer,
00115                                  head().feeTraits());
00116             buffer.position(originalPosition);
00117         } else {
00118             m_foot = new FeeFoot(head());
00119         }
00120     }
00121     return *m_foot;
00122 }
00123 
00124 unsigned int FeeReadout::gatherRom(DaqBuffer::OutputBufferList& outputBuffers) const {
00125     return gather(outputBuffers);
00126 }
00127 
00128 unsigned int FeeReadout::inspectRom(DaqBuffer::Bytes& inspectors) const {
00129     return inspect(inspectors);
00130 }
00131 
00132 unsigned int FeeReadout::romSize() const {
00133     return bufferSize();
00134 }
00135 
00136 unsigned int FeeReadout::gatherComponents(OutputBufferList& outputBuffers) const {
00137     unsigned int result = head().gather(outputBuffers);
00138     const FeeHitPtrList& hits = feeHits();
00139     FeeHitPtrList::const_iterator hit;
00140     for (hit = hits.begin();
00141          hit != hits.end();
00142          ++hit) {
00143         result += (*hit)->gather(outputBuffers);
00144     }
00145     
00146     result += foot().gather(outputBuffers);
00147     return result;
00148 }
00149 
00150 unsigned int FeeReadout::inspectComponents(DaqBuffer::Bytes& inspectors) const {
00151     unsigned int result = head().inspect(inspectors);
00152     const FeeHitPtrList& hits = feeHits();
00153     FeeHitPtrList::const_iterator hit;
00154     for (hit = hits.begin();
00155          hit != hits.end();
00156          ++hit) {
00157         result += (*hit)->inspect(inspectors);
00158     }
00159     
00160     result += foot().inspect(inspectors);
00161     return result;
00162 }
00163 
00164 unsigned int FeeReadout::bufferSize() const {
00165     unsigned int result = head().bufferSize();
00166     const FeeHitPtrList& hits = feeHits();
00167     FeeHitPtrList::const_iterator hit;
00168     for (hit = hits.begin();
00169          hit != hits.end();
00170          ++hit) {
00171         result += (*hit)->bufferSize();
00172     }
00173     result += foot().bufferSize();
00174     return result;
00175 }
00176 
00177 void FeeReadout::expanded(const unsigned int size) {
00178     FeeFoot& footToUse = foot();
00179     footToUse.setDataLength(footToUse.dataLength() + (size * kBytesInInt));
00180     notifyExpandable(size);
00181 }
00182 
00183 bool FeeReadout::setRomExpandable(DaqExpandable& expandable) {
00184     return setExpandable(expandable);
00185 }
00186 
00187 const FeeHit& FeeReadout::addHit(const unsigned int channel,
00188                                     const unsigned int peakCycle,
00189                                     const bool highRangeAdc,
00190                                     const unsigned int pedestal,
00191                                     const unsigned int charge,
00192                                     const unsigned int hitNumber,
00193                                     const unsigned int time) {
00194     const FeeTraits& traits = head().feeTraits();
00195     FeeHit* result = new FeeHit(channel,
00196                                 peakCycle,
00197                                 highRangeAdc,
00198                                 pedestal,
00199                                 charge,
00200                                 hitNumber,
00201                                 time,
00202                                 traits);
00203     return add(result);
00204 }
00205 
00206 const FeeHit& FeeReadout::add(const FeeHit* hit) {
00207     if (0 == m_hits) {
00208         m_hits = new FeeHitPtrList();
00209     }
00210     m_hits->push_back(hit);
00211     expanded(hit->bufferSize());
00212     return *hit;
00213 }
00214 
00215 FeeFoot& FeeReadout::foot() {
00216     if (0 == m_foot) {
00217         m_foot = new FeeFoot(head());
00218     }
00219     return *m_foot;
00220 }
00221 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:53:02 for FeeReadoutFormat by doxygen 1.7.4