Commit dc7a4bcd authored by dauncey's avatar dauncey

More bug fixes

parent 2e079021
...@@ -22,11 +22,11 @@ public: ...@@ -22,11 +22,11 @@ public:
std::ostringstream sout; std::ostringstream sout;
sout << "BeSlinkAna" << std::setw(2) << std::setfill('0') sout << "BeSlinkAna" << std::setw(2) << std::setfill('0')
<< fBeSlinkSim->fSlink; << fBeSlinkSim->slinkNumber();
std::string sHgcroc[18]={"00","01","02","03","04","05","06","07","08", std::string sHgcroc[18]={"00","01","02","03","04","05","06","07","08",
"09","10","11","12","13","14","15","16","17"}; "09","10","11","12","13","14","15","16","17"};
/*
hBitmapWordsVsChannels=new TH1I((sout.str()+"BitmapWordsVsChannels").c_str(), hBitmapWordsVsChannels=new TH1I((sout.str()+"BitmapWordsVsChannels").c_str(),
";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5); ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5);
hLabelsWordsVsChannels=new TH1I((sout.str()+"LabelsWordsVsChannels").c_str(), hLabelsWordsVsChannels=new TH1I((sout.str()+"LabelsWordsVsChannels").c_str(),
...@@ -36,18 +36,19 @@ public: ...@@ -36,18 +36,19 @@ public:
";ECON total number of channels",1300,0,1300); ";ECON total number of channels",1300,0,1300);
hTotalWords=new TH1D((sout.str()+"TotalWords").c_str(), hTotalWords=new TH1D((sout.str()+"TotalWords").c_str(),
";ECON total number of words",1000,0,1000); ";ECON total number of words",1000,0,1000);
*/
for(unsigned block(0);block<1;block++) { const SlinkArch &slinkArch(*(fBeSlinkSim->fSlinkArch));
hBlockTotalChannels[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"TotalChannels").c_str(), for(unsigned e(0);e<slinkArch.numberOfEcons();e++) {
";Block total number of channels",1300,0,1300); const EconArch &econArch(slinkArch.econArch(e));
hBlockTotalWords[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"TotalWords").c_str(), for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
";Block total number of words",1000,0,1000); hEventBufferUsed[e][b]=new TH1D((sout.str()+"Econ"+sHgcroc[e]+"Block"+sHgcroc[b]+"EventBufferUsed").c_str(),
hEventBufferUsed[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"EventBufferUsed").c_str(), ";Number of event buffer words used",1000,0,10000);
";Number of event buffer words used",50000,0,50000); hEventBufferUsedHistory[e][b]=new TH1I((sout.str()+"Econ"+sHgcroc[e]+"Block"+sHgcroc[b]+"EventBufferUsedHistory").c_str(),
hEventBufferUsedHistory[block]=new TH1I((sout.str()+"Block"+sHgcroc[block]+"EventBufferUsedHistory").c_str(),
";BX;Number of event buffer words used",nHistory,0,nHistory); ";BX;Number of event buffer words used",nHistory,0,nHistory);
} }
}
/*
for(unsigned h(0);h<18;h++) { for(unsigned h(0);h<18;h++) {
hChannels[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Channels").c_str(), hChannels[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Channels").c_str(),
";Number of channels per HGCROC packet",73,0,73); ";Number of channels per HGCROC packet",73,0,73);
...@@ -56,6 +57,7 @@ public: ...@@ -56,6 +57,7 @@ public:
hWordsVsChannels[h]=new TH2D((sout.str()+"Hgcroc"+sHgcroc[h]+"WordsVsChannels").c_str(), hWordsVsChannels[h]=new TH2D((sout.str()+"Hgcroc"+sHgcroc[h]+"WordsVsChannels").c_str(),
";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5,60,-0.5,59.5); ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5,60,-0.5,59.5);
} }
*/
} }
void analyseL1Accept(uint64_t bx) { void analyseL1Accept(uint64_t bx) {
...@@ -86,12 +88,14 @@ public: ...@@ -86,12 +88,14 @@ public:
} }
void analyseBx(uint64_t bx) { void analyseBx(uint64_t bx) {
/* const SlinkArch &slinkArch(*(fBeSlinkSim->fSlinkArch));
for(unsigned block(0);block<fEconSim->fEconArch.fNumberOfBlocks;block++) { for(unsigned e(0);e<slinkArch.numberOfEcons();e++) {
hEventBufferUsed[block]->Fill(fEconSim->fEventBuffer[block].used()); const EconArch &econArch(slinkArch.econArch(e));
hEventBufferUsedHistory[block]->Fill(bx,fEconSim->fEventBuffer[block].used()); for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
hEventBufferUsed[e][b]->Fill(fBeSlinkSim->fEventBuffer[e][b].used());
hEventBufferUsedHistory[e][b]->Fill(bx,fBeSlinkSim->fEventBuffer[e][b].used());
}
} }
*/
} }
void eoj() { void eoj() {
...@@ -100,21 +104,22 @@ public: ...@@ -100,21 +104,22 @@ public:
private: private:
const BeSlinkSim *fBeSlinkSim; const BeSlinkSim *fBeSlinkSim;
TH1I *hBitmapWordsVsChannels; //TH1I *hBitmapWordsVsChannels;
TH1I *hLabelsWordsVsChannels; //TH1I *hLabelsWordsVsChannels;
//TH1D *hMeans;
TH1D *hMeans; //TH1D *hChannels[18];
//TH1D *hWords[18];
//TH2D *hWordsVsChannels[18];
TH1D *hChannels[18]; //TH1D *hTotalChannels;
TH1D *hWords[18]; //TH1D *hTotalWords;
TH2D *hWordsVsChannels[18]; //TH1D *hBlockTotalChannels[7];
//TH1D *hBlockTotalWords[7];
TH1D *hTotalChannels; TH1D *hEventBufferUsed[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
TH1D *hTotalWords; TH1I *hEventBufferUsedHistory[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
TH1D *hBlockTotalChannels[7];
TH1D *hBlockTotalWords[7];
TH1D *hEventBufferUsed[7];
TH1I *hEventBufferUsedHistory[7];
}; };
#endif #endif
...@@ -13,6 +13,7 @@ class BeSlinkSim { ...@@ -13,6 +13,7 @@ class BeSlinkSim {
friend class BeSlinkAna; friend class BeSlinkAna;
public: public:
/*
enum { enum {
NumberOfParallelBuffers=2 NumberOfParallelBuffers=2
}; };
...@@ -36,13 +37,14 @@ public: ...@@ -36,13 +37,14 @@ public:
VariableHgcrocMap, VariableHgcrocMap,
EventBuild EventBuild
}; };
*/
//BeSlinkSim(unsigned e, unsigned h=18, unsigned m=0) : fEcon(e) { //BeSlinkSim(unsigned e, unsigned h=18, unsigned m=0) : fEcon(e) {
BeSlinkSim() { BeSlinkSim() {
} }
void boj(unsigned s, const SlinkArch &a) { void boj(const SlinkArch &a) {
fSlink=a.slinkNumber(); //fSlink=a.slinkNumber();
fSlinkArch=&a; fSlinkArch=&a;
if(fPrintLevel>0) { if(fPrintLevel>0) {
...@@ -61,83 +63,88 @@ public: ...@@ -61,83 +63,88 @@ public:
const EconArch &econArch(fSlinkArch->econArch(e)); const EconArch &econArch(fSlinkArch->econArch(e));
for(unsigned b(0);b<econArch.numberOfBlocks();b++) { for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
fBlockCheck[e][b].initialise(fSlinkArch->slinkNumber(),e,b,econArch.hgcrocNumber(b)); fBlockCheck[e][b].initialise(fSlinkArch->slinkNumber(),e,b,econArch.hgcrocNumber(b));
fBlockPair[e][b].first=true;
}
} }
} }
void processL1Accept(uint64_t bx, uint64_t l1a) {
uint64_t d[2];
SlinkBoe sBoe(0xce00,bx&0xffffffff,l1a&0xffffffff,0xab);
sBoe.words(d);
assert(fSlinkBoeCb.writeAndIncrementPtr(d[0]));
assert(fSlinkBoeCb.writeAndIncrementPtr(d[1]));
/* if(fPrintLevel>4) {
if(false) { std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processL1Accept(" << bx << "," << l1a << ") "
<< "Saving Slink BOE" << std::endl;
fNumberOfBlocks=1; sBoe.print();
for(unsigned h(0);h<18;h++) {
fHgcrocNumber[0].push_back(h);
} }
for(unsigned e(0);e<7;e++) {
fElinkNumber[0].push_back(e);
} }
} else { void processBx(uint64_t bx, const SlinkElinkData &d) {
fNumberOfBlocks=7;
for(unsigned h(0);h<18;h++) {
fHgcrocNumber[h%7].push_back(h);
}
for(unsigned e(0);e<7;e++) { if((bx%2)==0) {
fElinkNumber[e].push_back(e); fSlinkElinkData=d;
}
} } else {
uint64_t word,word2;
for(unsigned e(0);e<fSlinkArch->numberOfEcons();e++) {
const EconArch &econArch(fSlinkArch->econArch(e));
if(fPrintLevel>1) { for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
std::cout << "BeSlinkSim::ctor() " const std::vector<unsigned> &elinkNumber(econArch.elinkNumber(b));
<< "Number of blocks = " << fNumberOfBlocks << std::endl;
for(unsigned block(0);block<fNumberOfBlocks;block++) { unsigned eo(0);
std::cout << " Block " << block << ", HGCROCs ="; for(unsigned w(0);w<elinkNumber.size();w++) {
if((eo%2)==0) {
word=fSlinkElinkData.fData[e][elinkNumber[w]];
} else {
word2=fSlinkElinkData.fData[e][elinkNumber[w]];
word+=(word2<<32);
for(unsigned h(0);h<fHgcrocNumber[block].size();h++) { //if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
std::cout << " " << fHgcrocNumber[block][h]; if(word!=0) assert(fEventBuffer[e][b].writeAndIncrementPtr(word));
}
eo++;
} }
std::cout << ", Elinks ="; for(unsigned w(0);w<elinkNumber.size();w++) {
if((eo%2)==0) {
word=d.fData[e][elinkNumber[w]];
} else {
word2=d.fData[e][elinkNumber[w]];
word+=(word2<<32);
for(unsigned e(0);e<fElinkNumber[block].size();e++) { //if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
std::cout << " " << fElinkNumber[block][e]; if(word!=0) assert(fEventBuffer[e][b].writeAndIncrementPtr(word));
} }
eo++;
std::cout << std::endl;
} }
/*
// DO BY ARCH PROPERLY!!!
for(unsigned w(0);w<Dimensions::MaxNumberOfElinksPerEcon;w++) {
word=fSlinkElinkData.fData[e][w];
if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
} }
*/
for(unsigned w(0);w<Dimensions::MaxNumberOfElinksPerEcon;w++) {
word=d.fData[e][w];
//word=(word<<32)+fSlinkElinkData.fData[e][w];
//fHgcrocToElink[h]=(h%7); if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
}
*/
} }
//void slinkNumber(unsigned s) {
// fSlink=s;
//}
void processL1Accept(uint64_t bx, uint64_t l1a) {
uint64_t d[2];
SlinkBoe sboe(0xce00,bx&0xffffffff,l1a&0xffffffff,0xab);
sboe.words(d);
assert(cbBoe.writeAndIncrementPtr(d[0]));
assert(cbBoe.writeAndIncrementPtr(d[1]));
if(fPrintLevel>4) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processL1Accept(" << bx << "," << l1a << ") " //processEconBx(e,d.fData[e]);
<< "Writing Slink BOE" << std::endl;
sboe.print();
} }
} }
void processBx(const SlinkElinkData &d) { // Output to Slink
for(unsigned e(0);e<fSlinkArch->numberOfEcons();e++) processEconBx(e,d.fData[e]);
bool done(false); bool done(false);
uint128_t w; uint128_t w;
...@@ -153,9 +160,9 @@ public: ...@@ -153,9 +160,9 @@ public:
} }
if(!fEventActive) { if(!fEventActive) {
if(!cbBoe.empty()) { if(!fSlinkBoeCb.empty()) {
assert(cbBoe.readAndIncrementPtr(w.first)); assert(fSlinkBoeCb.readAndIncrementPtr(w.first));
assert(cbBoe.readAndIncrementPtr(w.second)); assert(fSlinkBoeCb.readAndIncrementPtr(w.second));
fSlinkWord[fNumberOfSlinkWords]=std::pair<uint128_t,bool>(w,true); fSlinkWord[fNumberOfSlinkWords]=std::pair<uint128_t,bool>(w,true);
fNumberOfSlinkWords++; fNumberOfSlinkWords++;
...@@ -169,6 +176,7 @@ public: ...@@ -169,6 +176,7 @@ public:
fBlockRead=0; fBlockRead=0;
fNumberOfEventWords=0; fNumberOfEventWords=0;
fEventActive=true; fEventActive=true;
} else { } else {
done=true; done=true;
} }
...@@ -190,17 +198,34 @@ public: ...@@ -190,17 +198,34 @@ public:
} else { } else {
for(unsigned i(0);i<4 && fEconRead<fSlinkArch->numberOfEcons() && fArrayWrite<4;i++) { for(unsigned i(0);/*i<4 &&*/ !done && fEconRead<fSlinkArch->numberOfEcons() && fArrayWrite<4;i++) {
if(!fEventBuffer[fEconRead][fBlockRead].empty()) { if(!(fEventBuffer[fEconRead][fBlockRead].empty() && fBlockPair[fEconRead][fBlockRead].first)) {
uint32_t nextWord(0);
if(fBlockPair[fEconRead][fBlockRead].first) {
uint64_t d; uint64_t d;
assert(fEventBuffer[fEconRead][fBlockRead].readAndIncrementPtr(d)); assert(fEventBuffer[fEconRead][fBlockRead].readAndIncrementPtr(d));
fArrayWord[fArrayWrite]=(d&0xffffffff); nextWord=(d&0xffffffff);
fBlockPair[fEconRead][fBlockRead].second=(d>>32);
fBlockPair[fEconRead][fBlockRead].first=false;
} else {
nextWord=fBlockPair[fEconRead][fBlockRead].second;
fBlockPair[fEconRead][fBlockRead].first=true;
}
//fArrayWord[fArrayWrite ]=(d&0xffffffff);
//fArrayWord[fArrayWrite+1]=(d>>32);
//fArrayWrite+=2;
if(nextWord!=0) {
fArrayWord[fArrayWrite]=nextWord;
fArrayWrite++; fArrayWrite++;
if(fPrintLevel>5) { if(fPrintLevel>5) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() " std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() "
<< "Read buffer word = 0x" << std::hex << fArrayWord[fArrayWrite-1] << "Read buffer words = 0x" << std::hex
//<< fArrayWord[fArrayWrite-2] << " "
<< fArrayWord[fArrayWrite-1]
<< std::dec << std::endl; << std::dec << std::endl;
} }
...@@ -212,6 +237,7 @@ public: ...@@ -212,6 +237,7 @@ public:
} }
if(fEconRead==fSlinkArch->numberOfEcons()) fArrayWrite=4; if(fEconRead==fSlinkArch->numberOfEcons()) fArrayWrite=4;
}
} else { } else {
done=true; done=true;
...@@ -243,13 +269,8 @@ public: ...@@ -243,13 +269,8 @@ public:
void processEconBx(unsigned ec, const uint32_t *d) { void processEconBx(unsigned ec, const uint32_t *d) {
// Switch for different dataflow methods
for(unsigned w(0);w<Dimensions::MaxNumberOfElinksPerEcon;w++) {
if(d[w]!=0) assert(fEventBuffer[ec][fSlinkArch->econArch(ec).numberOfBlocks()==1?0:w].writeAndIncrementPtr(d[w]));
}
return; return;
#ifdef NOT_YET
uint32_t a[7]; uint32_t a[7];
...@@ -257,7 +278,6 @@ public: ...@@ -257,7 +278,6 @@ public:
if(fDataFlowMethod==FixedHgcrocMap) { if(fDataFlowMethod==FixedHgcrocMap) {
#ifdef NOT_YET
// 4 words per BX for 7 eLinks // 4 words per BX for 7 eLinks
unsigned nWords(4); unsigned nWords(4);
...@@ -309,7 +329,6 @@ public: ...@@ -309,7 +329,6 @@ public:
} }
} }
#endif
} else if(fDataFlowMethod==VariableHgcrocMap) { } else if(fDataFlowMethod==VariableHgcrocMap) {
...@@ -418,6 +437,7 @@ public: ...@@ -418,6 +437,7 @@ public:
} else { } else {
assert(false); assert(false);
} }
#endif
} }
unsigned numberOfSlinkWords() const { unsigned numberOfSlinkWords() const {
...@@ -429,13 +449,13 @@ public: ...@@ -429,13 +449,13 @@ public:
return fSlinkWord[n]; return fSlinkWord[n];
} }
unsigned econSlink() const { unsigned slinkNumber() const {
return fSlink; return fSlinkArch->slinkNumber();
} }
public: public:
static unsigned fPrintLevel; static unsigned fPrintLevel;
/*
static DataRandomMethod fDataRandomMethod; static DataRandomMethod fDataRandomMethod;
static DataFormatMethod fDataFormatMethod; static DataFormatMethod fDataFormatMethod;
static DataFlowMethod fDataFlowMethod; static DataFlowMethod fDataFlowMethod;
...@@ -444,13 +464,15 @@ public: ...@@ -444,13 +464,15 @@ public:
double fTotalNum; double fTotalNum;
double fTotalMean; double fTotalMean;
double fTotalWords; double fTotalWords;
*/
protected: protected:
private: private:
unsigned fSlink; //unsigned fSlink;
const SlinkArch *fSlinkArch; const SlinkArch *fSlinkArch;
unsigned fEcon; SlinkElinkData fSlinkElinkData;
//unsigned fEcon;
EconFile fEconFile; EconFile fEconFile;
EconArch fEconArch; EconArch fEconArch;
...@@ -458,13 +480,13 @@ private: ...@@ -458,13 +480,13 @@ private:
//unsigned fNumberOfHgcrocs; //unsigned fNumberOfHgcrocs;
//double fHgcrocMean[18]; //double fHgcrocMean[18];
unsigned fHgcrocToElink[18]; //unsigned fHgcrocToElink[18];
CircularBuffer<1> fElink[7]; CircularBuffer<1> fElink[7];
CircularBuffer<16> fEventBuffer[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon]; CircularBuffer<16> fEventBuffer[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
//PartitionedBuffer<7,16> fPartitionedBuffer[5]; //PartitionedBuffer<7,16> fPartitionedBuffer[5];
unsigned fNumberOfChannels[18]; //unsigned fNumberOfChannels[18];
unsigned fNumberOfWords[18]; //unsigned fNumberOfWords[18];
bool fEventActive; bool fEventActive;
unsigned fEconRead; unsigned fEconRead;
...@@ -474,12 +496,13 @@ private: ...@@ -474,12 +496,13 @@ private:
unsigned fNumberOfEventWords; unsigned fNumberOfEventWords;
BlockCheck fBlockCheck[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon]; BlockCheck fBlockCheck[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
std::pair<bool,uint32_t> fBlockPair[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
//unsigned fReadHgcroc[NumberOfParallelBuffers]; //unsigned fReadHgcroc[NumberOfParallelBuffers];
//unsigned fReadWord[NumberOfParallelBuffers]; //unsigned fReadWord[NumberOfParallelBuffers];
unsigned fReadHgcrocNumber[NumberOfParallelBuffers][20]; //unsigned fReadHgcrocNumber[NumberOfParallelBuffers][20];
unsigned fReadWord[NumberOfParallelBuffers][20]; //unsigned fReadWord[NumberOfParallelBuffers][20];
unsigned fWriteElink; unsigned fWriteElink;
//unsigned fNumberOfBlocks; //unsigned fNumberOfBlocks;
...@@ -487,18 +510,18 @@ private: ...@@ -487,18 +510,18 @@ private:
std::vector<unsigned> fElinkNumber[7]; std::vector<unsigned> fElinkNumber[7];
unsigned fActiveInputBuffer; unsigned fActiveInputBuffer;
std::vector<uint32_t> fFirstBuffer[NumberOfParallelBuffers][18]; //std::vector<uint32_t> fFirstBuffer[NumberOfParallelBuffers][18];
CircularBuffer<1> cbBoe; CircularBuffer<1> fSlinkBoeCb;
unsigned fNumberOfSlinkWords; unsigned fNumberOfSlinkWords;
std::pair<uint128_t,bool> fSlinkWord[3]; std::pair<uint128_t,bool> fSlinkWord[3];
}; };
unsigned BeSlinkSim::fPrintLevel(1); unsigned BeSlinkSim::fPrintLevel(1);
/*
BeSlinkSim::DataRandomMethod BeSlinkSim::fDataRandomMethod(BeSlinkSim::Binomial); BeSlinkSim::DataRandomMethod BeSlinkSim::fDataRandomMethod(BeSlinkSim::Binomial);
BeSlinkSim::DataFormatMethod BeSlinkSim::fDataFormatMethod(BeSlinkSim::FixedChannelBitmap); BeSlinkSim::DataFormatMethod BeSlinkSim::fDataFormatMethod(BeSlinkSim::FixedChannelBitmap);
BeSlinkSim::DataFlowMethod BeSlinkSim::fDataFlowMethod(BeSlinkSim::FixedHgcrocMap); BeSlinkSim::DataFlowMethod BeSlinkSim::fDataFlowMethod(BeSlinkSim::FixedHgcrocMap);
unsigned BeSlinkSim::fFormatBreakEven(0); unsigned BeSlinkSim::fFormatBreakEven(0);
*/
#endif #endif
...@@ -41,6 +41,8 @@ public: ...@@ -41,6 +41,8 @@ public:
<< "Entered" << std::endl; << "Entered" << std::endl;
} }
//if(a==0) return false;