Commit 6bdfd169 authored by dauncey's avatar dauncey

Change to using Buffering subdirectory

parent ff2aea7f
#ifndef CircularBuffer_HH
#define CircularBuffer_HH
// Write pointer points to next location to write to
// Read pointer points to next location to read from
#include "MultipleUltraRam.hh"
template <unsigned NumberOfUltraRams>
class CircularBuffer {
public:
enum {
CircularBufferLength=NumberOfUltraRams*UltraRam::UltraRamBufferLength
};
CircularBuffer() {
reset();
}
bool writeAndIncrementPtr(uint64_t d) {
if(((fWritePtr+1)%CircularBufferLength)==fReadPtr) return false;
fMultipleUltraRam.write(fWritePtr,d);
fWritePtr++;
if(fWritePtr>=CircularBufferLength) fWritePtr-=CircularBufferLength;
return true;
}
bool read(uint64_t& d) const {
if(fReadPtr==fWritePtr) return false;
d=fMultipleUltraRam.read(fReadPtr);
return true;
}
bool incrementReadPtr() {
if(fReadPtr==fWritePtr) return false;
fReadPtr++;
if(fReadPtr>=CircularBufferLength) fReadPtr-=CircularBufferLength;
return true;
}
bool readAndIncrementPtr(uint64_t& d) {
if(!read(d)) return false;
return incrementReadPtr();
}
unsigned space() const {
if(fWritePtr<fReadPtr) return fReadPtr-fWritePtr-1;
return fReadPtr+CircularBufferLength-fWritePtr-1;
}
unsigned used() const {
if(fReadPtr<fWritePtr) return fWritePtr-fReadPtr;
return fWritePtr+CircularBufferLength-fReadPtr;
}
bool empty() const {
return fWritePtr==fReadPtr;
}
void reset() {
fWritePtr=0;
fReadPtr=0;
}
private:
MultipleUltraRam<NumberOfUltraRams> fMultipleUltraRam;
unsigned fWritePtr;
unsigned fReadPtr;
};
#endif
#ifndef MultipleUltraRam_HH
#define MultipleUltraRam_HH
#include "UltraRam.hh"
template <unsigned NumberOfUltraRams>
class MultipleUltraRam {
public:
enum {
MultipleUltraRamBufferLength=NumberOfUltraRams*UltraRam::UltraRamBufferLength
};
MultipleUltraRam() {
}
void write(unsigned a, uint64_t d) {
assert(a<MultipleUltraRamBufferLength);
fUltraRam[a/UltraRam::UltraRamBufferLength].write(a%UltraRam::UltraRamBufferLength,d);
}
uint64_t read(unsigned a) const {
assert(a<MultipleUltraRamBufferLength);
return fUltraRam[a/UltraRam::UltraRamBufferLength].read(a%UltraRam::UltraRamBufferLength);
}
protected:
private:
UltraRam fUltraRam[NumberOfUltraRams];
};
#endif
#ifndef PartitionedBuffer_HH
#define PartitionedBuffer_HH
// Write pointer points to next location to write to
// Read pointer points to next location to read from
#include "MultipleUltraRam.hh"
template <unsigned NumberOfPartitions, unsigned NumberOfUltraRams>
class PartitionedBuffer {
public:
enum {
PartitionedBufferLength=NumberOfUltraRams*UltraRam::UltraRamBufferLength,
PartitionLength=PartitionedBufferLength/NumberOfPartitions
};
PartitionedBuffer() {
std::cout << "PartitionedBuffer<" << NumberOfPartitions << "><"
<< NumberOfUltraRams << ">::ctor() partition length = "
<< PartitionLength << " words" << std::endl;
reset();
}
bool writeAndIncrementPtr(unsigned p, uint64_t d) {
assert(p<NumberOfPartitions);
if(((fWritePtr[p]+1)%PartitionLength)==fReadPtr[p]) return false;
fMultipleUltraRam.write(fWritePtr[p]+p*PartitionLength,d);
fWritePtr[p]++;
if(fWritePtr[p]>=PartitionLength) fWritePtr[p]-=PartitionLength;
return true;
}
bool read(unsigned p, uint64_t& d) const {
assert(p<NumberOfPartitions);
if(fReadPtr[p]==fWritePtr[p]) return false;
d=fMultipleUltraRam.read(fReadPtr[p]+p*PartitionLength);
return true;
}
bool incrementReadPtr(unsigned p) {
assert(p<NumberOfPartitions);
if(fReadPtr[p]==fWritePtr[p]) return false;
fReadPtr[p]++;
if(fReadPtr[p]>=PartitionLength) fReadPtr[p]-=PartitionLength;
return true;
}
bool readAndIncrementPtr(unsigned p, uint64_t& d) {
if(!read(p,d)) return false;
return incrementReadPtr(p);
}
unsigned space(unsigned p) const {
assert(p<NumberOfPartitions);
if(fWritePtr[p]<fReadPtr[p]) return fReadPtr[p]-fWritePtr[p]-1;
return fReadPtr[p]+PartitionLength-fWritePtr[p]-1;
}
unsigned used(unsigned p) const {
assert(p<NumberOfPartitions);
if(fReadPtr[p]<fWritePtr[p]) return fWritePtr[p]-fReadPtr[p];
return fWritePtr[p]+PartitionLength-fReadPtr[p];
}
bool empty(unsigned p) const {
assert(p<NumberOfPartitions);
return fWritePtr[p]==fReadPtr[p];
}
void reset() {
for(unsigned p(0);p<NumberOfPartitions;p++) {
fWritePtr[p]=0;
fReadPtr[p]=0;
}
}
private:
MultipleUltraRam<NumberOfUltraRams> fMultipleUltraRam;
unsigned fWritePtr[NumberOfPartitions];
unsigned fReadPtr[NumberOfPartitions];
};
#endif
#ifndef UltraRam_HH
#define UltraRam_HH
#include <iostream>
#include <iomanip>
#include <cassert>
class UltraRam {
public:
enum {
UltraRamBufferLength=4096
};
UltraRam() {
fRam=new uint64_t[UltraRamBufferLength];
}
virtual ~UltraRam() {
delete [] fRam;
}
void write(unsigned a, uint64_t d) {
assert(a<UltraRamBufferLength);
fRam[a]=d;
}
uint64_t read(unsigned a) const {
assert(a<UltraRamBufferLength);
return fRam[a];
}
protected:
private:
uint64_t *fRam;
};
#endif
......@@ -11,8 +11,8 @@
#include "TFileHandler.hh"
#include "Random.hh"
#include "CircularBuffer.hh"
#include "PartitionedBuffer.hh"
#include "Buffering/CircularBuffer.hh"
#include "Buffering/PartitionedBuffer.hh"
class SlinkBoe {
public:
......
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