Commit 3d4daafc authored by dauncey's avatar dauncey

Cleaning up buffer classes

parent dc7a4bcd
......@@ -5,6 +5,7 @@
#include <iomanip>
#include <cassert>
#include "Buffering/CircularBufferUR.hh"
#include "Buffering/SlinkBoe.hh"
#include "Buffering/SlinkEoe.hh"
#include "Buffering/SlinkArch.hh"
......@@ -481,8 +482,8 @@ private:
//double fHgcrocMean[18];
//unsigned fHgcrocToElink[18];
CircularBuffer<1> fElink[7];
CircularBuffer<16> fEventBuffer[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
CircularBufferUR<1> fElink[7];
CircularBufferUR<16> fEventBuffer[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
//PartitionedBuffer<7,16> fPartitionedBuffer[5];
//unsigned fNumberOfChannels[18];
......@@ -512,7 +513,7 @@ private:
unsigned fActiveInputBuffer;
//std::vector<uint32_t> fFirstBuffer[NumberOfParallelBuffers][18];
CircularBuffer<1> fSlinkBoeCb;
CircularBufferUR<1> fSlinkBoeCb;
unsigned fNumberOfSlinkWords;
std::pair<uint128_t,bool> fSlinkWord[3];
};
......
#ifndef CircularBuffer_HH
#define CircularBuffer_HH
#include <vector>
// Write pointer points to next location to write to
// Read pointer points to next location to read from
#include "MultipleUltraRam.hh"
template <unsigned NumberOfUltraRams>
template <class Payload>
class CircularBuffer {
public:
enum {
CircularBufferLength=NumberOfUltraRams*UltraRam::UltraRamBufferLength
};
CircularBuffer() {
reset();
CircularBuffer(unsigned n=0) {
reset(n);
}
void reset(unsigned n) {
fRam.resize(n);
fWritePtr=0;
fReadPtr=0;
}
bool writeAndIncrementPtr(uint64_t d) {
if(((fWritePtr+1)%CircularBufferLength)==fReadPtr) return false;
bool writeAndIncrementPtr(const Payload &d) {
if(((fWritePtr+1)%fRam.size())==fReadPtr) return false;
assert(fWritePtr<fRam.size());
fRam[fWritePtr]=d;
fMultipleUltraRam.write(fWritePtr,d);
fWritePtr++;
if(fWritePtr>=CircularBufferLength) fWritePtr-=CircularBufferLength;
if(fWritePtr>=fRam.size()) fWritePtr-=fRam.size();
return true;
}
bool read(uint64_t& d) const {
bool read(Payload &d) const {
if(fReadPtr==fWritePtr) return false;
d=fMultipleUltraRam.read(fReadPtr);
assert(fReadPtr<fRam.size());
d=fRam[fReadPtr];
return true;
}
......@@ -38,39 +43,37 @@ public:
if(fReadPtr==fWritePtr) return false;
fReadPtr++;
if(fReadPtr>=CircularBufferLength) fReadPtr-=CircularBufferLength;
if(fReadPtr>=fRam.size()) fReadPtr-=fRam.size();
return true;
}
bool readAndIncrementPtr(uint64_t& d) {
bool readAndIncrementPtr(Payload &d) {
if(!read(d)) return false;
return incrementReadPtr();
}
unsigned space() const {
if(fWritePtr<fReadPtr) return fReadPtr-fWritePtr-1;
return fReadPtr+CircularBufferLength-fWritePtr-1;
return fReadPtr+fRam.size()-fWritePtr-1;
}
unsigned used() const {
if(fReadPtr<=fWritePtr) return fWritePtr-fReadPtr;
return fWritePtr+CircularBufferLength-fReadPtr;
return fWritePtr+fRam.size()-fReadPtr;
}
bool empty() const {
return fWritePtr==fReadPtr;
}
void reset() {
fWritePtr=0;
fReadPtr=0;
}
private:
MultipleUltraRam<NumberOfUltraRams> fMultipleUltraRam;
std::vector<Payload> fRam;
unsigned fWritePtr;
unsigned fReadPtr;
};
typedef CircularBuffer<uint32_t> CircularBuffer32;
typedef CircularBuffer<uint64_t> CircularBuffer64;
#endif
......@@ -5,6 +5,8 @@
#include <iomanip>
#include <cassert>
#include "Buffering/CircularBuffer.hh"
#include "Buffering/CircularBufferUR.hh"
#include "Buffering/HgcrocBoe.hh"
#include "Buffering/EconArch.hh"
#include "Buffering/EconFile.hh"
......@@ -125,6 +127,10 @@ public:
fEcon=e;
fEconFile=&f;
fEconArch=&a;
for(unsigned block(0);block<fEconArch->fNumberOfBlocks;block++) {
fEventBuffer[block].reset(16*4096);
}
}
#ifdef CRAP
......@@ -492,9 +498,11 @@ public:
}
}
uint64_t d;
//uint64_t d;
uint32_t d;
for(unsigned e(0);e<fEconArch->fElinkNumber[block].size();e++) {
if(fEventBuffer[block].readAndIncrementPtr(d)) a[fEconArch->fElinkNumber[block][e]]=(d&0xffffffff);
//if(fEventBuffer[block].readAndIncrementPtr(d)) a[fEconArch->fElinkNumber[block][e]]=(d&0xffffffff);
if(fEventBuffer[block].readAndIncrementPtr(d)) a[fEconArch->fElinkNumber[block][e]]=d;
else a[fEconArch->fElinkNumber[block][e]]=0;
}
}
......@@ -516,7 +524,7 @@ public:
unsigned numberOfHgcrocs() const {
return fEconFile->fNumberOfHgcrocs;
}
/*
unsigned space(unsigned elink) {
assert(elink<7);
return fElink[elink].space();
......@@ -526,7 +534,7 @@ public:
assert(elink<7);
return fElink[elink].used();
}
*/
unsigned numberOfChannels(unsigned h) const {
assert(h<18);
return fNumberOfChannels[h];
......@@ -536,13 +544,13 @@ public:
assert(h<18);
return fNumberOfWords[h];
}
/*
void reset() {
for(unsigned e(0);e<7;e++) {
fElink[e].reset();
}
}
*/
static unsigned channelsToWords(unsigned c, bool map) {
if(map) return 3+(c+1)/2;
else return 1+3*(c+1)/4;
......@@ -635,8 +643,10 @@ private:
//double fHgcrocMean[18];
//unsigned fHgcrocToElink[18];
CircularBuffer<1> fElink[7];
CircularBuffer<16> fEventBuffer[7];
//CircularBufferUR<1> fElink[7];
//CircularBufferUR<16> fEventBuffer[7];
CircularBuffer32 fEventBuffer[7];
unsigned fNumberOfChannels[18];
unsigned fNumberOfWords[18];
......
......@@ -27,8 +27,6 @@ public:
std::string sName("HgcrocAna");
hCounts=new TH1D((sName+"Counts").c_str(),
";Counts",10,0,10);
hEvents=new TH1D((sName+"Events").c_str(),
";Number of events in buffer;BXs",
bd,0,bd);
......@@ -88,8 +86,6 @@ public:
}
void eoj() {
hCounts->SetBinContent(1,fNumberOfBx);
hCounts->SetBinContent(2,fNumberOfDeadtimeBx);
}
private:
......@@ -102,7 +98,6 @@ private:
uint64_t fBxPreviousEventComplete;
unsigned fBusyLength;
TH1D *hCounts;
TH1D *hEvents;
TH1D *hL1AEvents;
TH1D *hL1AcceptSeparation;
......
......@@ -7,7 +7,7 @@
class HgcrocSim {
public:
HgcrocSim(){
HgcrocSim() {
}
void boj(unsigned e=7, unsigned w=44) {
......@@ -18,6 +18,9 @@ public:
std::cout << "HgcrocSim::ctor(" << e << "," << w << ") "
<<"Entered, buffer depth = " << fBufferDepth << std::endl;
}
fNumberOfEvents=0;
fNumberOfWords=0;
}
bool processBx(bool l1A=false) {
......@@ -53,6 +56,7 @@ public:
<< fNumberOfWords << std::endl;
}
assert(fNumberOfWords<=fEventLength);
fEventComplete=(fNumberOfWords==fEventLength);
if(fEventComplete) {
......
......@@ -12,13 +12,9 @@ public:
};
UltraRam() {
fRam=new uint64_t[UltraRamBufferLength];
fRam.resize(UltraRamBufferLength);
}
virtual ~UltraRam() {
delete [] fRam;
}
void write(unsigned a, uint64_t d) {
assert(a<UltraRamBufferLength);
fRam[a]=d;
......@@ -28,11 +24,9 @@ public:
assert(a<UltraRamBufferLength);
return fRam[a];
}
protected:
private:
uint64_t *fRam;
std::vector<uint64_t> fRam;
};
#endif
......@@ -24,7 +24,7 @@ public:
};
#include "Buffering/CircularBuffer.hh"
#include "Buffering/CircularBufferUR.hh"
#include "Buffering/PartitionedBuffer.hh"
#include "Buffering/HgcrocSim.hh"
#include "Buffering/HgcrocAna.hh"
......@@ -706,9 +706,9 @@ int main(int argc, char* argv[]) {
Random random;
random.random().SetSeed(rSeed);
CircularBuffer<1> cbBoe;
CircularBuffer<1> cb;
CircularBuffer<1> cbFinal;
CircularBufferUR<1> cbBoe;
CircularBufferUR<1> cb;
CircularBufferUR<1> cbFinal;
PartitionedBuffer<18,4> pb[5];
BeReadState brs;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment