Commit dc7a4bcd authored by dauncey's avatar dauncey

More bug fixes

parent 2e079021
......@@ -22,11 +22,11 @@ public:
std::ostringstream sout;
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",
"09","10","11","12","13","14","15","16","17"};
/*
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);
hLabelsWordsVsChannels=new TH1I((sout.str()+"LabelsWordsVsChannels").c_str(),
......@@ -36,18 +36,19 @@ public:
";ECON total number of channels",1300,0,1300);
hTotalWords=new TH1D((sout.str()+"TotalWords").c_str(),
";ECON total number of words",1000,0,1000);
for(unsigned block(0);block<1;block++) {
hBlockTotalChannels[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"TotalChannels").c_str(),
";Block total number of channels",1300,0,1300);
hBlockTotalWords[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"TotalWords").c_str(),
";Block total number of words",1000,0,1000);
hEventBufferUsed[block]=new TH1D((sout.str()+"Block"+sHgcroc[block]+"EventBufferUsed").c_str(),
";Number of event buffer words used",50000,0,50000);
hEventBufferUsedHistory[block]=new TH1I((sout.str()+"Block"+sHgcroc[block]+"EventBufferUsedHistory").c_str(),
";BX;Number of event buffer words used",nHistory,0,nHistory);
}
*/
const SlinkArch &slinkArch(*(fBeSlinkSim->fSlinkArch));
for(unsigned e(0);e<slinkArch.numberOfEcons();e++) {
const EconArch &econArch(slinkArch.econArch(e));
for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
hEventBufferUsed[e][b]=new TH1D((sout.str()+"Econ"+sHgcroc[e]+"Block"+sHgcroc[b]+"EventBufferUsed").c_str(),
";Number of event buffer words used",1000,0,10000);
hEventBufferUsedHistory[e][b]=new TH1I((sout.str()+"Econ"+sHgcroc[e]+"Block"+sHgcroc[b]+"EventBufferUsedHistory").c_str(),
";BX;Number of event buffer words used",nHistory,0,nHistory);
}
}
/*
for(unsigned h(0);h<18;h++) {
hChannels[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Channels").c_str(),
";Number of channels per HGCROC packet",73,0,73);
......@@ -56,6 +57,7 @@ public:
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);
}
*/
}
void analyseL1Accept(uint64_t bx) {
......@@ -86,12 +88,14 @@ public:
}
void analyseBx(uint64_t bx) {
/*
for(unsigned block(0);block<fEconSim->fEconArch.fNumberOfBlocks;block++) {
hEventBufferUsed[block]->Fill(fEconSim->fEventBuffer[block].used());
hEventBufferUsedHistory[block]->Fill(bx,fEconSim->fEventBuffer[block].used());
const SlinkArch &slinkArch(*(fBeSlinkSim->fSlinkArch));
for(unsigned e(0);e<slinkArch.numberOfEcons();e++) {
const EconArch &econArch(slinkArch.econArch(e));
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() {
......@@ -100,21 +104,22 @@ public:
private:
const BeSlinkSim *fBeSlinkSim;
TH1I *hBitmapWordsVsChannels;
TH1I *hLabelsWordsVsChannels;
//TH1I *hBitmapWordsVsChannels;
//TH1I *hLabelsWordsVsChannels;
TH1D *hMeans;
//TH1D *hMeans;
TH1D *hChannels[18];
TH1D *hWords[18];
TH2D *hWordsVsChannels[18];
//TH1D *hChannels[18];
//TH1D *hWords[18];
//TH2D *hWordsVsChannels[18];
//TH1D *hTotalChannels;
//TH1D *hTotalWords;
//TH1D *hBlockTotalChannels[7];
//TH1D *hBlockTotalWords[7];
TH1D *hTotalChannels;
TH1D *hTotalWords;
TH1D *hBlockTotalChannels[7];
TH1D *hBlockTotalWords[7];
TH1D *hEventBufferUsed[7];
TH1I *hEventBufferUsedHistory[7];
TH1D *hEventBufferUsed[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
TH1I *hEventBufferUsedHistory[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
};
#endif
......@@ -13,6 +13,7 @@ class BeSlinkSim {
friend class BeSlinkAna;
public:
/*
enum {
NumberOfParallelBuffers=2
};
......@@ -36,13 +37,14 @@ public:
VariableHgcrocMap,
EventBuild
};
*/
//BeSlinkSim(unsigned e, unsigned h=18, unsigned m=0) : fEcon(e) {
BeSlinkSim() {
}
void boj(unsigned s, const SlinkArch &a) {
fSlink=a.slinkNumber();
void boj(const SlinkArch &a) {
//fSlink=a.slinkNumber();
fSlinkArch=&a;
if(fPrintLevel>0) {
......@@ -61,83 +63,88 @@ public:
const EconArch &econArch(fSlinkArch->econArch(e));
for(unsigned b(0);b<econArch.numberOfBlocks();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) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processL1Accept(" << bx << "," << l1a << ") "
<< "Saving Slink BOE" << std::endl;
sBoe.print();
}
}
/*
if(false) {
void processBx(uint64_t bx, const SlinkElinkData &d) {
fNumberOfBlocks=1;
for(unsigned h(0);h<18;h++) {
fHgcrocNumber[0].push_back(h);
}
for(unsigned e(0);e<7;e++) {
fElinkNumber[0].push_back(e);
}
if((bx%2)==0) {
fSlinkElinkData=d;
} else {
} else {
uint64_t word,word2;
for(unsigned e(0);e<fSlinkArch->numberOfEcons();e++) {
const EconArch &econArch(fSlinkArch->econArch(e));
fNumberOfBlocks=7;
for(unsigned b(0);b<econArch.numberOfBlocks();b++) {
const std::vector<unsigned> &elinkNumber(econArch.elinkNumber(b));
for(unsigned h(0);h<18;h++) {
fHgcrocNumber[h%7].push_back(h);
}
unsigned eo(0);
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 e(0);e<7;e++) {
fElinkNumber[e].push_back(e);
}
//if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
if(word!=0) assert(fEventBuffer[e][b].writeAndIncrementPtr(word));
}
eo++;
}
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);
//if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
if(word!=0) assert(fEventBuffer[e][b].writeAndIncrementPtr(word));
}
eo++;
}
/*
// 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];
if(fPrintLevel>1) {
std::cout << "BeSlinkSim::ctor() "
<< "Number of blocks = " << fNumberOfBlocks << std::endl;
if(word!=0) assert(fEventBuffer[e][fSlinkArch->econArch(e).numberOfBlocks()==1?0:w].writeAndIncrementPtr(word));
}
*/
}
for(unsigned block(0);block<fNumberOfBlocks;block++) {
std::cout << " Block " << block << ", HGCROCs =";
for(unsigned h(0);h<fHgcrocNumber[block].size();h++) {
std::cout << " " << fHgcrocNumber[block][h];
}
std::cout << ", Elinks =";
for(unsigned e(0);e<fElinkNumber[block].size();e++) {
std::cout << " " << fElinkNumber[block][e];
}
std::cout << std::endl;
//processEconBx(e,d.fData[e]);
}
}
*/
//fHgcrocToElink[h]=(h%7);
}
//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 << ") "
<< "Writing Slink BOE" << std::endl;
sboe.print();
}
}
void processBx(const SlinkElinkData &d) {
for(unsigned e(0);e<fSlinkArch->numberOfEcons();e++) processEconBx(e,d.fData[e]);
// Output to Slink
bool done(false);
uint128_t w;
......@@ -153,9 +160,9 @@ public:
}
if(!fEventActive) {
if(!cbBoe.empty()) {
assert(cbBoe.readAndIncrementPtr(w.first));
assert(cbBoe.readAndIncrementPtr(w.second));
if(!fSlinkBoeCb.empty()) {
assert(fSlinkBoeCb.readAndIncrementPtr(w.first));
assert(fSlinkBoeCb.readAndIncrementPtr(w.second));
fSlinkWord[fNumberOfSlinkWords]=std::pair<uint128_t,bool>(w,true);
fNumberOfSlinkWords++;
......@@ -169,6 +176,7 @@ public:
fBlockRead=0;
fNumberOfEventWords=0;
fEventActive=true;
} else {
done=true;
}
......@@ -190,28 +198,46 @@ public:
} else {
for(unsigned i(0);i<4 && fEconRead<fSlinkArch->numberOfEcons() && fArrayWrite<4;i++) {
if(!fEventBuffer[fEconRead][fBlockRead].empty()) {
uint64_t d;
assert(fEventBuffer[fEconRead][fBlockRead].readAndIncrementPtr(d));
fArrayWord[fArrayWrite]=(d&0xffffffff);
fArrayWrite++;
if(fPrintLevel>5) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() "
<< "Read buffer word = 0x" << std::hex << fArrayWord[fArrayWrite-1]
<< std::dec << std::endl;
for(unsigned i(0);/*i<4 &&*/ !done && fEconRead<fSlinkArch->numberOfEcons() && fArrayWrite<4;i++) {
if(!(fEventBuffer[fEconRead][fBlockRead].empty() && fBlockPair[fEconRead][fBlockRead].first)) {
uint32_t nextWord(0);
if(fBlockPair[fEconRead][fBlockRead].first) {
uint64_t d;
assert(fEventBuffer[fEconRead][fBlockRead].readAndIncrementPtr(d));
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(fBlockCheck[fEconRead][fBlockRead].processBx(fArrayWord[fArrayWrite-1])) fBlockRead++;
if(fBlockRead==fSlinkArch->econArch(fEconRead).numberOfBlocks()) {
fBlockRead=0;
fEconRead++;
if(nextWord!=0) {
fArrayWord[fArrayWrite]=nextWord;
fArrayWrite++;
if(fPrintLevel>5) {
std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() "
<< "Read buffer words = 0x" << std::hex
//<< fArrayWord[fArrayWrite-2] << " "
<< fArrayWord[fArrayWrite-1]
<< std::dec << std::endl;
}
if(fBlockCheck[fEconRead][fBlockRead].processBx(fArrayWord[fArrayWrite-1])) fBlockRead++;
if(fBlockRead==fSlinkArch->econArch(fEconRead).numberOfBlocks()) {
fBlockRead=0;
fEconRead++;
}
if(fEconRead==fSlinkArch->numberOfEcons()) fArrayWrite=4;
}
if(fEconRead==fSlinkArch->numberOfEcons()) fArrayWrite=4;
} else {
done=true;
......@@ -243,13 +269,8 @@ public:
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;
#ifdef NOT_YET
uint32_t a[7];
......@@ -257,7 +278,6 @@ public:
if(fDataFlowMethod==FixedHgcrocMap) {
#ifdef NOT_YET
// 4 words per BX for 7 eLinks
unsigned nWords(4);
......@@ -309,7 +329,6 @@ public:
}
}
#endif
} else if(fDataFlowMethod==VariableHgcrocMap) {
......@@ -418,6 +437,7 @@ public:
} else {
assert(false);
}
#endif
}
unsigned numberOfSlinkWords() const {
......@@ -429,13 +449,13 @@ public:
return fSlinkWord[n];
}
unsigned econSlink() const {
return fSlink;
unsigned slinkNumber() const {
return fSlinkArch->slinkNumber();
}
public:
static unsigned fPrintLevel;
/*
static DataRandomMethod fDataRandomMethod;
static DataFormatMethod fDataFormatMethod;
static DataFlowMethod fDataFlowMethod;
......@@ -444,13 +464,15 @@ public:
double fTotalNum;
double fTotalMean;
double fTotalWords;
*/
protected:
private:
unsigned fSlink;
//unsigned fSlink;
const SlinkArch *fSlinkArch;
unsigned fEcon;
SlinkElinkData fSlinkElinkData;
//unsigned fEcon;
EconFile fEconFile;
EconArch fEconArch;
......@@ -458,13 +480,13 @@ private:
//unsigned fNumberOfHgcrocs;
//double fHgcrocMean[18];
unsigned fHgcrocToElink[18];
//unsigned fHgcrocToElink[18];
CircularBuffer<1> fElink[7];
CircularBuffer<16> fEventBuffer[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
//PartitionedBuffer<7,16> fPartitionedBuffer[5];
unsigned fNumberOfChannels[18];
unsigned fNumberOfWords[18];
//unsigned fNumberOfChannels[18];
//unsigned fNumberOfWords[18];
bool fEventActive;
unsigned fEconRead;
......@@ -474,12 +496,13 @@ private:
unsigned fNumberOfEventWords;
BlockCheck fBlockCheck[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
std::pair<bool,uint32_t> fBlockPair[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
//unsigned fReadHgcroc[NumberOfParallelBuffers];
//unsigned fReadWord[NumberOfParallelBuffers];
unsigned fReadHgcrocNumber[NumberOfParallelBuffers][20];
unsigned fReadWord[NumberOfParallelBuffers][20];
//unsigned fReadHgcrocNumber[NumberOfParallelBuffers][20];
//unsigned fReadWord[NumberOfParallelBuffers][20];
unsigned fWriteElink;
//unsigned fNumberOfBlocks;
......@@ -487,18 +510,18 @@ private:
std::vector<unsigned> fElinkNumber[7];
unsigned fActiveInputBuffer;
std::vector<uint32_t> fFirstBuffer[NumberOfParallelBuffers][18];
//std::vector<uint32_t> fFirstBuffer[NumberOfParallelBuffers][18];
CircularBuffer<1> cbBoe;
CircularBuffer<1> fSlinkBoeCb;
unsigned fNumberOfSlinkWords;
std::pair<uint128_t,bool> fSlinkWord[3];
};
unsigned BeSlinkSim::fPrintLevel(1);
/*
BeSlinkSim::DataRandomMethod BeSlinkSim::fDataRandomMethod(BeSlinkSim::Binomial);
BeSlinkSim::DataFormatMethod BeSlinkSim::fDataFormatMethod(BeSlinkSim::FixedChannelBitmap);
BeSlinkSim::DataFlowMethod BeSlinkSim::fDataFlowMethod(BeSlinkSim::FixedHgcrocMap);
unsigned BeSlinkSim::fFormatBreakEven(0);
*/
#endif
......@@ -41,6 +41,8 @@ public:
<< "Entered" << std::endl;
}
//if(a==0) return false;
if(!fActivePacket) {
if(a!=0) {
fActivePacket=true;
......
......@@ -634,7 +634,7 @@ private:
//unsigned fNumberOfHgcrocs;
//double fHgcrocMean[18];
unsigned fHgcrocToElink[18];
//unsigned fHgcrocToElink[18];
CircularBuffer<1> fElink[7];
CircularBuffer<16> fEventBuffer[7];
......
......@@ -87,7 +87,7 @@ public:
}
void processEoj() {
void eoj() {
hCounts->SetBinContent(1,fNumberOfBx);
hCounts->SetBinContent(2,fNumberOfDeadtimeBx);
}
......
......@@ -15,7 +15,7 @@ public:
fWord=w;
}
HgcrocBoe(uint8_t e, uint8_t h, uint8_t b, uint8_t l, uint8_t n, bool s=false) {
HgcrocBoe(uint8_t e, uint8_t h, uint8_t b, uint8_t l, uint8_t n, bool s=true) {
assert(n<64);
fWord=(b<<24)+((18*e+h)<<16)+(l<<8)+(n&0x3f)+(s?0x40:0);
}
......
......@@ -188,7 +188,7 @@ private:
BlockCheck fBlockCheck[7];
unsigned fNumberOfHgcrocs;
//unsigned fNumberOfHgcrocs;
unsigned fHgcroc;
const EconArch *fEconArch;
......@@ -199,7 +199,7 @@ private:
uint8_t fL1Accept;
uint8_t fBx;
HgcrocBoe fHgcrocBoe;
unsigned fWords[7];
//unsigned fWords[7];
bool fHgcrocSeen[18];
};
......
......@@ -61,6 +61,12 @@ public:
assert(fBoe.valid());
fL1Accept=(fL1Accept+1)&0xffffffff;
assert(fBoe.eventId()==fL1Accept);
fEventDump.resize(0);
fEventDump.push_back(w.first&0xffffffff);
fEventDump.push_back(w.first>>32);
fEventDump.push_back(w.second&0xffffffff);
fEventDump.push_back(w.second>>32);
fEventActive=true;
fEconRead=0;
......@@ -77,6 +83,11 @@ public:
return;
}
fEventDump.push_back(w.first&0xffffffff);
fEventDump.push_back(w.first>>32);
fEventDump.push_back(w.second&0xffffffff);
fEventDump.push_back(w.second>>32);
if(be) {
fEoe.setWords(d);
......@@ -93,6 +104,20 @@ public:
assert(fEoe.crc()==0xff);
assert(fEoe.eventLength()==nWords);
if(fPrintLevel>5) {
std::cout << std::endl << "SlinkCheck::processWord() "
<< "Event dump for L1Accept " << fL1Accept << std::endl;
for(unsigned i(0);i<fEventDump.size();i++) {
std::cout << " Word " << std::setw(4) << i
<< " = " << std::setw(10) << std::setfill(' ')
<< fEventDump[i] << " = 0x"
<< std::hex << std::setw(8) << std::setfill('0')
<< fEventDump[i] << std::dec << std::endl;
}
std::cout << std::endl;
}
if(nWords==0) {
if(fPrintLevel>4) {
std::cout << "SlinkCheck::processWord() "
......@@ -228,6 +253,8 @@ private:
unsigned nHgcrocWords;
bool completedHgcroc[5][18];
std::vector<uint32_t> fEventDump;
};
unsigned SlinkCheck::fPrintLevel(1);
......
......@@ -891,7 +891,7 @@ int main(int argc, char* argv[]) {
}
if(doingBe) {
beSlinkSim[sl].boj(sl,slinkArch[sl]);
beSlinkSim[sl].boj(slinkArch[sl]);
beSlinkAna[sl].boj(beSlinkSim[sl],nHistory);
slinkCheck[sl].boj(slinkArch[sl]);
......@@ -1046,7 +1046,7 @@ int main(int argc, char* argv[]) {
beSlinkAna[sl].analyseL1Accept(bx);
}
beSlinkSim[sl].processBx(slinkElinkData[sl]);
beSlinkSim[sl].processBx(bx,slinkElinkData[sl]);
beSlinkAna[sl].analyseBx(bx);
for(unsigned w(0);w<beSlinkSim[sl].numberOfSlinkWords();w++) {
......@@ -1452,6 +1452,7 @@ int main(int argc, char* argv[]) {
} // End of doingEcon
// Increment some counters
if(newL1AIn) numberL1AIn++;
if(newL1AOut) numberL1AOut++;
......@@ -1468,7 +1469,9 @@ int main(int argc, char* argv[]) {
std::cout << "Number of HGCROC deadtime BXs = " << nHgcrocDeadtime
<< ", fraction = " << 1.0*nHgcrocDeadtime/maxBx << std::endl;
hgcrocAna.processEoj();
// Finish up
hgcrocAna.eoj();
for(unsigned sl(0);sl<NumberOfSlinks;sl++) {
for(unsigned ec(0);ec<5;ec++) {
......