Skip to content

Commit 404e02e

Browse files
committed
use MemoryBankManager
1 parent 7f3451d commit 404e02e

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/ReadoutEquipmentDummy.cxx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "ReadoutEquipment.h"
2+
#include "MemoryBankManager.h"
3+
#include "ReadoutUtils.h"
24

35
#include <InfoLogger/InfoLogger.hxx>
46
using namespace AliceO2::InfoLogger;
57
extern InfoLogger theLog;
68

9+
710
class ReadoutEquipmentDummy : public ReadoutEquipment {
811

912
public:
@@ -12,34 +15,42 @@ class ReadoutEquipmentDummy : public ReadoutEquipment {
1215
DataBlockContainerReference getNextBlock();
1316

1417
private:
15-
std::shared_ptr<MemPool> mp; // a memory pool from which to allocate data pages
18+
std::shared_ptr<MemoryPagesPool> mp; // a memory pool from which to allocate data pages
1619
Thread::CallbackResult populateFifoOut(); // iterative callback
1720

18-
DataBlockId currentId; // current block id
21+
DataBlockId currentId; // current block id
1922
int eventMaxSize; // maximum data block size
2023
int eventMinSize; // minimum data block size
24+
int fillData; // if set, data pages filled with incremental values
2125
};
2226

2327
ReadoutEquipmentDummy::ReadoutEquipmentDummy(ConfigFile &cfg, std::string cfgEntryPoint) : ReadoutEquipment(cfg, cfgEntryPoint) {
2428

25-
int memPoolNumberOfElements=10000;
26-
int memPoolElementSize=0.01*1024*1024;
27-
29+
int memoryPoolPageSize=0.01*1024*1024;
30+
int memoryPoolNumberOfPages=10000;
31+
std::string memoryBankName=""; // by default, this uses the first memory bank available
32+
2833
// get configuration values
29-
cfg.getOptionalValue<int>(cfgEntryPoint + ".memPoolNumberOfElements", memPoolNumberOfElements);
30-
cfg.getOptionalValue<int>(cfgEntryPoint + ".memPoolElementSize", memPoolElementSize);
34+
cfg.getOptionalValue<std::string>(cfgEntryPoint + ".memoryBankName", memoryBankName);
35+
cfg.getOptionalValue<int>(cfgEntryPoint + ".memoryPoolPageSize", memoryPoolPageSize);
36+
cfg.getOptionalValue<int>(cfgEntryPoint + ".memoryPoolNumberOfPages", memoryPoolNumberOfPages);
3137
cfg.getOptionalValue<int>(cfgEntryPoint + ".eventMaxSize", eventMaxSize, (int)1024);
3238
cfg.getOptionalValue<int>(cfgEntryPoint + ".eventMinSize", eventMinSize, (int)1024);
39+
cfg.getOptionalValue<int>(cfgEntryPoint + ".fillData", fillData, (int)0);
3340

41+
theLog.log("%s : buffer %d pages x %d bytes, eventSize: %d -> %d",
42+
cfgEntryPoint.c_str(),(int) memoryPoolNumberOfPages, (int) memoryPoolPageSize, eventMinSize, eventMaxSize);
43+
44+
3445
// ensure generated events will fit in blocks allocated from memory pool
3546
int maxElementSize=eventMaxSize+sizeof(DataBlockHeaderBase);
36-
if (maxElementSize>memPoolElementSize) {
37-
theLog.log("memPoolElementSize too small, need at least %d bytes",maxElementSize);
47+
if (maxElementSize>memoryPoolPageSize) {
48+
theLog.log("memoryPoolPageSize too small, need at least %d bytes",maxElementSize);
3849
throw __LINE__;
3950
}
4051

4152
// create memory pool
42-
mp=std::make_shared<MemPool>(memPoolNumberOfElements,memPoolElementSize);
53+
mp=theMemoryBankManager.getPagedPool(memoryPoolPageSize, memoryPoolNumberOfPages, memoryBankName);
4354

4455
// init variables
4556
currentId=0;
@@ -48,7 +59,7 @@ ReadoutEquipmentDummy::ReadoutEquipmentDummy(ConfigFile &cfg, std::string cfgEnt
4859
ReadoutEquipmentDummy::~ReadoutEquipmentDummy() {
4960
// check if mempool still referenced
5061
if (!mp.unique()) {
51-
printf("Warning: mempool still %d references\n",(int)mp.use_count());
62+
printf("Warning: mempool still has %d references\n",(int)mp.use_count());
5263
}
5364
}
5465

@@ -57,7 +68,7 @@ DataBlockContainerReference ReadoutEquipmentDummy::getNextBlock() {
5768
// query memory pool for a free block
5869
DataBlockContainerReference nextBlock=nullptr;
5970
try {
60-
nextBlock=std::make_shared<DataBlockContainerFromMemPool>(mp);
71+
nextBlock=mp->getNewDataBlockContainer();
6172
}
6273
catch (...) {
6374
}
@@ -80,8 +91,10 @@ DataBlockContainerReference ReadoutEquipmentDummy::getNextBlock() {
8091
b->data=&(((char *)b)[sizeof(DataBlock)]);
8192

8293
// fill (a bit of) data
83-
for (int k=0;k<100;k++) {
84-
b->data[k]=(char)k;
94+
if (fillData==1) {
95+
for (int k=0;k<dSize;k++) {
96+
b->data[k]=(char)k;
97+
}
8598
}
8699
}
87100
return nextBlock;

0 commit comments

Comments
 (0)