diff --git a/interface/Buffering/BeSlinkAna.hh b/interface/Buffering/BeSlinkAna.hh new file mode 100644 index 0000000000000000000000000000000000000000..db92a95b95e832e90213cbe46edb539d8a0e6694 --- /dev/null +++ b/interface/Buffering/BeSlinkAna.hh @@ -0,0 +1,120 @@ +#ifndef BeSlinkAna_HH +#define BeSlinkAna_HH + +#include +#include +#include + +#include "TH1D.h" +#include "TH2D.h" +#include "TH1I.h" + +#include "Buffering/BeSlinkSim.hh" + + +class BeSlinkAna { +public: + BeSlinkAna() { + } + + void boj(const BeSlinkSim &b, unsigned nHistory=100000) { + fBeSlinkSim=&b; + + std::ostringstream sout; + sout << "BeSlinkAna" << std::setw(2) << std::setfill('0') + << fBeSlinkSim->fSlink; + + 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(), + ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5); + + hTotalChannels=new TH1D((sout.str()+"TotalChannels").c_str(), + ";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); + } + + 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); + hWords[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Words").c_str(), + ";Number of words per HGCROC packet",60,0,60); + 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) { + /* + unsigned nChannels(0),nWords(0); + for(unsigned h(0);h<18;h++) { + hChannels[h]->Fill(fEconSim->numberOfChannels(h)); + hWords[h]->Fill(fEconSim->numberOfWords(h)); + hWordsVsChannels[h]->Fill(fEconSim->numberOfChannels(h),fEconSim->numberOfWords(h)); + nChannels+=fEconSim->numberOfChannels(h); + nWords+=fEconSim->numberOfWords(h); + } + + hTotalChannels->Fill(nChannels); + hTotalWords->Fill(nWords); + + for(unsigned block(0);blockfEconArch.fNumberOfBlocks;block++) { + unsigned nBlockChannels(0),nBlockWords(0); + for(unsigned i(0);ifEconArch.fHgcrocNumber[block].size();i++) { + unsigned h(fEconSim->fEconArch.fHgcrocNumber[block][i]); + nBlockChannels+=fEconSim->numberOfChannels(h); + nBlockWords+=fEconSim->numberOfWords(h); + } + hBlockTotalChannels[block]->Fill(nBlockChannels); + hBlockTotalWords[block]->Fill(nBlockWords); + } + */ + } + + void analyseBx(uint64_t bx) { + /* + for(unsigned block(0);blockfEconArch.fNumberOfBlocks;block++) { + hEventBufferUsed[block]->Fill(fEconSim->fEventBuffer[block].used()); + hEventBufferUsedHistory[block]->Fill(bx,fEconSim->fEventBuffer[block].used()); + } + */ + } + + void eoj() { + } + +private: + const BeSlinkSim *fBeSlinkSim; + + TH1I *hBitmapWordsVsChannels; + TH1I *hLabelsWordsVsChannels; + + TH1D *hMeans; + + TH1D *hChannels[18]; + TH1D *hWords[18]; + TH2D *hWordsVsChannels[18]; + + TH1D *hTotalChannels; + TH1D *hTotalWords; + TH1D *hBlockTotalChannels[7]; + TH1D *hBlockTotalWords[7]; + TH1D *hEventBufferUsed[7]; + TH1I *hEventBufferUsedHistory[7]; +}; + +#endif diff --git a/interface/Buffering/BeSlinkSim.hh b/interface/Buffering/BeSlinkSim.hh new file mode 100644 index 0000000000000000000000000000000000000000..9c89e316f24f34d55a811dabab8bef2155da1127 --- /dev/null +++ b/interface/Buffering/BeSlinkSim.hh @@ -0,0 +1,504 @@ +#ifndef BeSlinkSim_HH +#define BeSlinkSim_HH + +#include +#include +#include + +#include "Buffering/SlinkBoe.hh" +#include "Buffering/SlinkEoe.hh" +#include "Buffering/SlinkArch.hh" + +class BeSlinkSim { + friend class BeSlinkAna; + +public: + enum { + NumberOfParallelBuffers=2 + }; + + enum DataRandomMethod { + NotRandom, + Binomial, + Flat, + Mixed + }; + + enum DataFormatMethod { + FixedChannelBitmap, + FixedChannelLabels, + FixedMixture, + VariableMixture + }; + + enum DataFlowMethod { + FixedHgcrocMap, + VariableHgcrocMap, + EventBuild + }; + + //BeSlinkSim(unsigned e, unsigned h=18, unsigned m=0) : fEcon(e) { + BeSlinkSim() { + } + + void boj(unsigned s, const SlinkArch &a) { + fSlink=a.slinkNumber(); + fSlinkArch=&a; + + if(fPrintLevel>0) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::ctor() " + << "Entered" << std::endl; + } + + fEventActive=false; + fActiveInputBuffer=0; + fWriteElink=0; + + fArrayWrite=0; + for(unsigned i(0);i<4;i++) fArrayWord[i]=0; + + for(unsigned e(0);enumberOfEcons();e++) { + const EconArch &econArch(fSlinkArch->econArch(e)); + for(unsigned b(0);bslinkNumber(),e,b,econArch.hgcrocNumber(b)); + } + } + + + /* + if(false) { + + 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); + } + + } else { + + fNumberOfBlocks=7; + + for(unsigned h(0);h<18;h++) { + fHgcrocNumber[h%7].push_back(h); + } + + for(unsigned e(0);e<7;e++) { + fElinkNumber[e].push_back(e); + } + + } + + if(fPrintLevel>1) { + std::cout << "BeSlinkSim::ctor() " + << "Number of blocks = " << fNumberOfBlocks << std::endl; + + for(unsigned block(0);block4) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processL1Accept(" << bx << "," << l1a << ") " + << "Writing Slink BOE" << std::endl; + sboe.print(); + } + } + + void processBx(const SlinkElinkData &d) { + for(unsigned e(0);enumberOfEcons();e++) processEconBx(e,d.fData[e]); + + bool done(false); + uint128_t w; + fNumberOfSlinkWords=0; + + for(fNumberOfSlinkWords=0;fNumberOfSlinkWords<3 && !done;) { + if(fPrintLevel>5) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() " + << "Number of Slink words written = " << fNumberOfSlinkWords + << ", event active = " << (fEventActive?"true":"false") + << ", done = " << (done?"true":"false") + << std::endl; + } + + if(!fEventActive) { + if(!cbBoe.empty()) { + assert(cbBoe.readAndIncrementPtr(w.first)); + assert(cbBoe.readAndIncrementPtr(w.second)); + fSlinkWord[fNumberOfSlinkWords]=std::pair(w,true); + fNumberOfSlinkWords++; + + if(fPrintLevel>3) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() " + << "Writing Slink BOE = 0x" << std::hex << w.second << " " << w.first + << std::dec << std::endl; + } + + fEconRead=0; + fBlockRead=0; + fNumberOfEventWords=0; + fEventActive=true; + } else { + done=true; + } + + } else { + if(fEconRead==fSlinkArch->numberOfEcons()) { + SlinkEoe seoe(0xce00,0x77,0xff,fNumberOfEventWords); + seoe.word(w); + fSlinkWord[fNumberOfSlinkWords]=std::pair(w,true); + fNumberOfSlinkWords++; + + if(fPrintLevel>3) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() " + << "Writing Slink EOE = 0x" << std::hex << w.second << " " << w.first + << std::dec << std::endl; + } + + fEventActive=false; + + } else { + + for(unsigned i(0);i<4 && fEconReadnumberOfEcons() && 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; + } + + if(fBlockCheck[fEconRead][fBlockRead].processBx(fArrayWord[fArrayWrite-1])) fBlockRead++; + + if(fBlockRead==fSlinkArch->econArch(fEconRead).numberOfBlocks()) { + fBlockRead=0; + fEconRead++; + } + + if(fEconRead==fSlinkArch->numberOfEcons()) fArrayWrite=4; + + } else { + done=true; + } + } + + if(fArrayWrite==4) { + w.first=fArrayWord[1]; + w.first=(w.first<<32)+fArrayWord[0]; + w.second=fArrayWord[3]; + w.second=(w.second<<32)+fArrayWord[2]; + fSlinkWord[fNumberOfSlinkWords]=std::pair(w,false); + fNumberOfSlinkWords++; + fNumberOfEventWords++; + + if(fPrintLevel>3) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "]::processBx() " + << "Writing Slink data word = 0x" << std::hex << w.second << " " << w.first + << std::dec << std::endl; + } + + fArrayWrite=0; + for(unsigned i(0);i<4;i++) fArrayWord[i]=0; + } + } + } + } + } + + void processEconBx(unsigned ec, const uint32_t *d) { + + // Switch for different dataflow methods + + for(unsigned w(0);weconArch(ec).numberOfBlocks()==1?0:w].writeAndIncrementPtr(d[w])); + } + + return; + + uint32_t a[7]; + + // Switch for different dataflow methods + + if(fDataFlowMethod==FixedHgcrocMap) { + +#ifdef NOT_YET + + // 4 words per BX for 7 eLinks + unsigned nWords(4); + + if(fPrintLevel>3) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Data flow method = fixed HGCROC map, reading " + << nWords << " words per BX" << std::endl; + } + + for(unsigned b(0);b4) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Copying BX word " << w << " from first buffer " << b + << ", HGCROC " << fReadHgcroc[b] << ", word " << fReadWord[b] + << " of " << fFirstBuffer[b][fReadHgcroc[b]].size() << " = " + << std::hex << fFirstBuffer[b][fReadHgcroc[b]][fReadWord[b]] + << std::dec << std::endl; + } + assert(fElink[fHgcrocToElink[h]].writeAndIncrementPtr(fFirstBuffer[b][fReadHgcrocNumber[b]][fReadWord[b]])); + } + } + } + } + } + + // Add zero padding word if odd + //if((nWords%2)==1) assert(fElink[fHgcrocToElink[h]].writeAndIncrementPtr(0)); + + uint64_t d; + for(unsigned e(0);e<7;e++) { + if(fElink[e].readAndIncrementPtr(d)) a[e]=(d&0xffffffff); + else a[e]=0; + + if(fPrintLevel>4) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Sending eLink " << e << " = " + << std::hex << a[e] + << std::dec << std::endl; + } + } + +#endif + + } else if(fDataFlowMethod==VariableHgcrocMap) { + + unsigned nWords(0); + + if(fPrintLevel>3) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Data flow method = variable HGCROC map, reading " + << nWords << " words per BX" << std::endl; + } + + assert(false); + + + } else if(fDataFlowMethod==EventBuild) { + + // 24 words per BX for 2 parallel buffers = 960 MHz + // 12 words per BX for 3 parallel buffers = 480 MHz + // 8 words per BX for 4 parallel buffers = 320 MHz + //unsigned nWords(24/(NumberOfParallelBuffers-1)); + + + // For one block, must be > 55 words x 18 HGCROCs/44 BX = 22.5; also more than output = 7 words/BX + // OR + // For one block, must be > 39 words x 18 HGCROCs/44 BX = 15.95; also more than output = 7 words/BX + // For seven blocks, must be > 55 words x 3 HGCROCs/44 BX = 3.75; also more than output = 1 word/BX + // OR + // For seven blocks, must be > 39 words x 3 HGCROCs/44 BX = 2.66; also more than output = 1 word/BX + + unsigned nWords(fEconArch.fNumberOfBlocks==1?24:4); + //unsigned nWords(fEconArch.fNumberOfBlocks==1?16:3); + + if(fPrintLevel>3) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Data flow method = event build, reading " + << nWords << " words per BX" << std::endl; + } + + for(unsigned block(0);block4) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Reading HGCROC number " << fReadHgcrocNumber[b][block] + << " < " << fEconArch.fHgcrocNumber[block].size() + << ", word number " << fReadWord[b][block] << std::endl; + } + + //if(fReadHgcrocNumber[b] &readBuffer(fFirstBuffer[b][readHgcroc]); // Convenient + assert(fReadWord[b][block]4) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Copying BX word " << w << " from block " << block << ", first buffer " << b + << ", HGCROC " << readHgcroc << ", word " << fReadWord[b][block] + << " of " << readBuffer.size() << " = " + << std::hex << readBuffer[fReadWord[b][block]] + << std::dec << std::endl; + } + + // Write word to FIFO + + assert(fEventBuffer[0][block].writeAndIncrementPtr(readBuffer[fReadWord[b][block]])); + + // Check if completed all words of this HGCROC + + fReadWord[b][block]++; + if(fReadWord[b][block]==readBuffer.size()) { + fReadWord[b][block]=0; + fReadHgcrocNumber[b][block]++; + + // Check if completed all HGCROCs + + if(fReadHgcrocNumber[b][block]==fEconArch.fHgcrocNumber[block].size()) w=nWords; + } + } + } + } + } + + uint64_t d; + for(unsigned e(0);e4) { + for(unsigned e(0);e<7;e++) { + std::cout << "BeSlinkSim[" << fSlinkArch->slinkNumber() << "][" << fEcon << "]::processBx() " + << "Sending eLink " << e << " = " + << std::hex << a[e] + << std::dec << std::endl; + } + } + + } else { + assert(false); + } + } + + unsigned numberOfSlinkWords() const { + return fNumberOfSlinkWords; + } + + const std::pair& slinkWord(unsigned n) const { + assert(n fElink[7]; + CircularBuffer<16> fEventBuffer[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon]; + //PartitionedBuffer<7,16> fPartitionedBuffer[5]; + + unsigned fNumberOfChannels[18]; + unsigned fNumberOfWords[18]; + + bool fEventActive; + unsigned fEconRead; + unsigned fBlockRead; + unsigned fArrayWrite; + uint32_t fArrayWord[4]; + unsigned fNumberOfEventWords; + + BlockCheck fBlockCheck[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon]; + + + //unsigned fReadHgcroc[NumberOfParallelBuffers]; + //unsigned fReadWord[NumberOfParallelBuffers]; + unsigned fReadHgcrocNumber[NumberOfParallelBuffers][20]; + unsigned fReadWord[NumberOfParallelBuffers][20]; + unsigned fWriteElink; + + //unsigned fNumberOfBlocks; + std::vector fHgcrocNumber[7]; + std::vector fElinkNumber[7]; + + unsigned fActiveInputBuffer; + std::vector fFirstBuffer[NumberOfParallelBuffers][18]; + + CircularBuffer<1> cbBoe; + unsigned fNumberOfSlinkWords; + std::pair 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 diff --git a/interface/Buffering/BlockCheck.hh b/interface/Buffering/BlockCheck.hh new file mode 100644 index 0000000000000000000000000000000000000000..64bea49b7f1313d83c2884f9adbbeecd65fd9149 --- /dev/null +++ b/interface/Buffering/BlockCheck.hh @@ -0,0 +1,178 @@ +#ifndef BlockCheck_HH +#define BlockCheck_HH + +#include +#include +#include + +class BlockCheck { +public: + BlockCheck() { + } + + BlockCheck(unsigned s, unsigned e, unsigned b, const std::vector &h) { + initialise(s,e,b,h); + } + + void initialise(unsigned s, unsigned e, unsigned b, const std::vector &h) { + fSlink=s; + fEcon=e; + fBlock=b; + fHgcrocNumber=&h; + + if(fPrintLevel>1) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::initialise() " + << "Number of HGCROCs = " << h.size() + << ", numbers ="; + for(unsigned n(0);n4) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::processBx(" << std::hex << a << std::dec << ") " + << "Entered" << std::endl; + } + + if(!fActivePacket) { + if(a!=0) { + fActivePacket=true; + fActiveHgcroc=true; + + //for(unsigned h(0);h4) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::processBx() " + << "New packet found" << std::endl; + + std::cout << "New HGCROC found" << std::endl; + fHgcrocBoe.print(); + } + + if(fHgcrocBoe.numberOfWords()==1) { + fActiveHgcroc=false; + fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + + if(fPrintLevel>4) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::processBx() " + << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) + << " completed" << std::endl; + } + } + } + + } else { + assert(a!=0); + + if(!fActiveHgcroc) { + fActiveHgcroc=true; + + fHgcroc=(*fHgcrocNumber)[fNumberSeen]; + fNumberSeen++; + checkHeader(a,false); + fWords=1; + + if(fPrintLevel>4) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::processBx() " + << "New HGCROC found" << std::endl; + fHgcrocBoe.print(); + } + + if(fHgcrocBoe.numberOfWords()==1) { + fActiveHgcroc=false; + fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + + if(fPrintLevel>4) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::processBx() " + << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) + << " completed" << std::endl; + } + } + + } else { + assert((a>>24)==fL1Accept); + assert((a&0xffffff)==fWords); + fWords++; + + if(fWords==fHgcrocBoe.numberOfWords()) { + fActiveHgcroc=false; + fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + + if(fPrintLevel>4) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::processBx() " + << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) + << " completed" << std::endl; + } + + if(fNumberSeen==(*fHgcrocNumber).size()) { + fActivePacket=false; + if(fPrintLevel>4) { + std::cout << "BlockCheck[" << fSlink << "][" << fEcon + << "][" << fBlock << "]::processBx() " + << "Packet ended" << std::endl; + } + fL1Accept++; + return true; + } + } + } + } + + return false; + } + + void checkHeader(uint32_t a, bool first) { + fHgcrocBoe.word(a); + if(first) fBx=fHgcrocBoe.bx(); + + //assert(!fHgcrocSeen[fHgcrocBoe.hgcroc()]); + //fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + + assert(fHgcrocBoe.econ()==fEcon); + assert(fHgcrocBoe.hgcroc()==fHgcroc); + assert(fHgcrocBoe.bx()==fBx); + assert(fHgcrocBoe.l1a()==fL1Accept); + } + + static unsigned fPrintLevel; + +private: + unsigned fSlink; + unsigned fEcon; + unsigned fBlock; + unsigned fHgcroc; + + unsigned fNumberSeen; + const std::vector *fHgcrocNumber; + + bool fActivePacket; + bool fActiveHgcroc; + + uint8_t fL1Accept; + uint8_t fBx; + HgcrocBoe fHgcrocBoe; + unsigned fWords; + bool fHgcrocSeen[18]; +}; + +unsigned BlockCheck::fPrintLevel(1); + +#endif diff --git a/interface/Buffering/Dimensions.hh b/interface/Buffering/Dimensions.hh new file mode 100644 index 0000000000000000000000000000000000000000..3e9423cea462de81afc15910e124fc389af50324 --- /dev/null +++ b/interface/Buffering/Dimensions.hh @@ -0,0 +1,16 @@ +#ifndef Dimensions_HH +#define Dimensions_HH + +class Dimensions { +public: + enum { + MaxNumberOfSlinks=12, + MaxNumberOfEconsPerSlink=5, + MaxNumberOfElinksPerEcon=7, + MaxNumberOfBlocksPerEcon=MaxNumberOfElinksPerEcon, + MaxNumberOfHgcrocsPerEcon=18, + MaxNumberOfHgcrocsPerElink=3 + }; +}; + +#endif diff --git a/interface/Buffering/EconAna.hh b/interface/Buffering/EconAna.hh index edc5edc0d525e048c2113e3d4770adabd67d4423..ff9a7c9eab9a3ac9f9ed502c55ae76e1af2aef70 100644 --- a/interface/Buffering/EconAna.hh +++ b/interface/Buffering/EconAna.hh @@ -14,33 +14,51 @@ class EconAna { public: - EconAna(const EconSim &e, unsigned nHistory=100000) : - fEconSim(e) { + EconAna() { + } + + void boj(const EconSim &e, unsigned nHistory=100000) { + fEconSim=&e; std::ostringstream sout; sout << "EconAna" << std::setw(2) << std::setfill('0') - << fEconSim.econNumber(); + << fEconSim->econNumber(); std::string sHgcroc[18]={"00","01","02","03","04","05","06","07","08", "09","10","11","12","13","14","15","16","17"}; - hMapWordsVsChannels=new TH1I((sout.str()+"MapWordsVsChannels").c_str(), - ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,0,73); - hLabelWordsVsChannels=new TH1I((sout.str()+"LabelWordsVsChannels").c_str(), - ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,0,73); + 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(), + ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5); + hTotalChannels=new TH1D((sout.str()+"TotalChannels").c_str(), + ";ECON total number of channels",1300,0,1300); hTotalWords=new TH1D((sout.str()+"TotalWords").c_str(), - ";Total number of words",1000,0,1000); - hEventBufferUsed=new TH1D((sout.str()+"EventBufferUsed").c_str(), - ";Number of event buffer words used",10000,0,10000); - hEventBufferUsedHistory=new TH1I((sout.str()+"EventBufferUsedHistory").c_str(), - ";BX;Number of event buffer words used",nHistory,0,nHistory); + ";ECON total number of words",1000,0,1000); + + for(unsigned block(0);blockeconArch().numberOfBlocks();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); + } for(unsigned c(0);c<=72;c++) { - hMapWordsVsChannels->Fill(c,fEconSim.channelsToWords(c,true)); - hLabelWordsVsChannels->Fill(c,fEconSim.channelsToWords(c,false)); + hBitmapWordsVsChannels->Fill(c,fEconSim->channelsToWords(c,true)); + hLabelsWordsVsChannels->Fill(c,fEconSim->channelsToWords(c,false)); } + + hMeans=new TH1D((sout.str()+"Means").c_str(), + ";HGCROC;Mean number of channels",18,0,18); + for(unsigned h(0);heconFile().numberOfHgcrocs();h++) { + hMeans->SetBinContent(h+1,fEconSim->econFile().mean(h)); + } for(unsigned h(0);h<18;h++) { hChannels[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Channels").c_str(), @@ -48,39 +66,64 @@ public: hWords[h]=new TH1D((sout.str()+"Hgcroc"+sHgcroc[h]+"Words").c_str(), ";Number of words per HGCROC packet",60,0,60); 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,73,60,0,60); + ";Number of channels per HGCROC packet;Number of words per HGCROC packet",73,-0.5,72.5,60,-0.5,59.5); } } void analyseZs(uint64_t bx) { - unsigned nWords(0); + unsigned nChannels(0),nWords(0); + for(unsigned h(0);h<18;h++) { - hChannels[h]->Fill(fEconSim.numberOfChannels(h)); - hWords[h]->Fill(fEconSim.numberOfWords(h)); - hWordsVsChannels[h]->Fill(fEconSim.numberOfChannels(h),fEconSim.numberOfWords(h)); - nWords+=fEconSim.numberOfWords(h); + hChannels[h]->Fill(fEconSim->numberOfChannels(h)); + hWords[h]->Fill(fEconSim->numberOfWords(h)); + hWordsVsChannels[h]->Fill(fEconSim->numberOfChannels(h),fEconSim->numberOfWords(h)); + nChannels+=fEconSim->numberOfChannels(h); + nWords+=fEconSim->numberOfWords(h); } + + hTotalChannels->Fill(nChannels); hTotalWords->Fill(nWords); + + for(unsigned block(0);blockeconArch().numberOfBlocks();block++) { + unsigned nBlockChannels(0),nBlockWords(0); + for(unsigned i(0);ieconArch().fHgcrocNumber[block].size();i++) { + unsigned h(fEconSim->econArch().fHgcrocNumber[block][i]); + nBlockChannels+=fEconSim->numberOfChannels(h); + nBlockWords+=fEconSim->numberOfWords(h); + } + hBlockTotalChannels[block]->Fill(nBlockChannels); + hBlockTotalWords[block]->Fill(nBlockWords); + } } void analyseBx(uint64_t bx) { - hEventBufferUsed->Fill(fEconSim.fEventBuffer.used()); - hEventBufferUsedHistory->Fill(bx,fEconSim.fEventBuffer.used()); + for(unsigned block(0);blockeconArch().fNumberOfBlocks;block++) { + hEventBufferUsed[block]->Fill(fEconSim->fEventBuffer[block].used()); + hEventBufferUsedHistory[block]->Fill(bx,fEconSim->fEventBuffer[block].used()); + } } - + + void eoj() { + } + private: - const EconSim &fEconSim; + const EconSim *fEconSim; - TH1I *hMapWordsVsChannels; - TH1I *hLabelWordsVsChannels; + TH1I *hBitmapWordsVsChannels; + TH1I *hLabelsWordsVsChannels; + TH1D *hMeans; + TH1D *hChannels[18]; TH1D *hWords[18]; TH2D *hWordsVsChannels[18]; + TH1D *hTotalChannels; TH1D *hTotalWords; - TH1D *hEventBufferUsed; - TH1I *hEventBufferUsedHistory; + TH1D *hBlockTotalChannels[7]; + TH1D *hBlockTotalWords[7]; + TH1D *hEventBufferUsed[7]; + TH1I *hEventBufferUsedHistory[7]; }; #endif diff --git a/interface/Buffering/EconArch.hh b/interface/Buffering/EconArch.hh new file mode 100644 index 0000000000000000000000000000000000000000..7c4e663bfc2cfb54c071e1fb9a452ec5effa68f3 --- /dev/null +++ b/interface/Buffering/EconArch.hh @@ -0,0 +1,91 @@ +#ifndef EconArch_HH +#define EconArch_HH + +#include + +#include "EconFile.hh" + +class EconArch { +public: + EconArch() { + }; + + void initialise(bool b, const EconFile &econFile) { + unsigned nh=econFile.numberOfHgcrocs(); + assert(nh<=Dimensions::MaxNumberOfHgcrocsPerEcon); + + for(unsigned b(0);b& hgcrocNumber(unsigned b) const { + assert(b& elinkNumber(unsigned b) const { + assert(b fHgcrocNumber[Dimensions::MaxNumberOfElinksPerEcon]; + std::vector fElinkNumber[Dimensions::MaxNumberOfElinksPerEcon]; +}; + +#endif diff --git a/interface/Buffering/EconFile.hh b/interface/Buffering/EconFile.hh new file mode 100644 index 0000000000000000000000000000000000000000..a458df9df80d3a16e51ea705175c70573e73a2ec --- /dev/null +++ b/interface/Buffering/EconFile.hh @@ -0,0 +1,61 @@ +#ifndef EconFile_HH +#define EconFile_HH + +#include + +class EconFile { + friend class EconSim; + +public: + enum { + MaxNumberOfHgcrocs=18 + }; + + EconFile () : fNumberOfHgcrocs(-1) { + } + + bool read(std::istream &fin) { + if(!fin) return false; + + char lead; + fin >> lead >> fNumberOfHgcrocs; + if(lead!='E') return false; + if(fNumberOfHgcrocs>MaxNumberOfHgcrocs) return false; + + for(unsigned h(0);h> fHgcrocMean[h]; + if(fHgcrocMean[h]< 0) return false; + if(fHgcrocMean[h]>72) return false; + } + + if(!fin) return false; + return true; + } + + unsigned numberOfHgcrocs() const { + return fNumberOfHgcrocs; + } + + double mean(unsigned h) const { + assert(h #include #include #include "Buffering/HgcrocBoe.hh" +#include "Buffering/EconArch.hh" +#include "Buffering/EconFile.hh" class EconSim { friend class EconAna; + public: + enum { + NumberOfParallelBuffers=2 + }; + + enum DataRandomMethod { + NotRandom, + Binomial, + Flat, + Mixed + }; + enum DataFormatMethod { - FixedChannelMap, + FixedChannelBitmap, FixedChannelLabels, FixedMixture, VariableMixture @@ -26,23 +37,108 @@ public: EventBuild }; - EconSim(unsigned e, unsigned h=18, unsigned m=0) : fEcon(e), fHgcroc(h) { - if(fPrintLevel>0) { - std::cout << "EconSim::ctor(" << e << "," << h << "," << m << ") " + //EconSim(unsigned e, unsigned h=18, unsigned m=0) : fEcon(e) { + EconSim() { + fSlink=0; + + if(fPrintLevel>0) { + std::cout << "EconSim::ctor() " << "Entered" << std::endl; } - assert(fHgcroc<=18); setFormatBreakEven(); - fActiveBuffer=0; - fReadHgcroc=18; - fReadWord=0xffffffff; + fActiveInputBuffer=0; + fWriteElink=0; + + /* + if(false) { + + 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); + } + + } else { + + fNumberOfBlocks=7; + + for(unsigned h(0);h<18;h++) { + fHgcrocNumber[h%7].push_back(h); + } + + for(unsigned e(0);e<7;e++) { + fElinkNumber[e].push_back(e); + } + + } + + if(fPrintLevel>1) { + std::cout << "EconSim::ctor() " + << "Number of blocks = " << fNumberOfBlocks << std::endl; + + for(unsigned block(0);block2) { + std::cout << "EconSim::ctor() " + << "First buffer " << b << ", block " << block + << ", zeroing HGCROC number " << fReadHgcrocNumber[b][block] + << ", word number " << fReadWord[b][block] << std::endl; + } + } + for(unsigned h(0);hfNumberOfHgcrocs<=18); + + setFormatBreakEven(); + fActiveInputBuffer=0; fWriteElink=0; // Random values for now /* - for(unsigned h(0);hfHgcrocMean[h]=0.5*h+1; fHgcrocToElink[h]=(h%7); } */ @@ -51,55 +147,56 @@ public: fFirstBuffer[0][h].resize(channelsToWords(72,false)); fFirstBuffer[1][h].resize(channelsToWords(72,false)); - fMean[h]=0.0; + fEconFile->fHgcrocMean[h]=0.0; } - for(unsigned h(0);hfNumberOfHgcrocs;h++) { if(m==0) { - fMean[h]=10; - if(h<14) fMean[h]=20; - if(h< 7) fMean[h]=35; + fEconFile->fHgcrocMean[h]=10; + if(h<14) fEconFile->fHgcrocMean[h]=20; + if(h< 7) fEconFile->fHgcrocMean[h]=35; + if(h==6) fEconFile->fHgcrocMean[h]=40; } if(m==1) { - fMean[h]=5; - if(h<14) fMean[h]=10; - if(h< 7) fMean[h]=15; + fEconFile->fHgcrocMean[h]=5; + if(h<14) fEconFile->fHgcrocMean[h]=10; + if(h< 7) fEconFile->fHgcrocMean[h]=15; } if(m==2) { - fMean[h]=3; - if(h<14) fMean[h]=7; - if(h< 7) fMean[h]=10; + fEconFile->fHgcrocMean[h]=3; + if(h<14) fEconFile->fHgcrocMean[h]=7; + if(h< 7) fEconFile->fHgcrocMean[h]=10; } if(m==3) { - fMean[h]=2; - if(h<14) fMean[h]=4; - if(h< 7) fMean[h]=5; + fEconFile->fHgcrocMean[h]=2; + if(h<14) fEconFile->fHgcrocMean[h]=4; + if(h< 7) fEconFile->fHgcrocMean[h]=5; } if(m>=4) { - fMean[h]=1; - if(h<14) fMean[h]=2; - if(h< 7) fMean[h]=3; + fEconFile->fHgcrocMean[h]=1; + if(h<14) fEconFile->fHgcrocMean[h]=2; + if(h< 7) fEconFile->fHgcrocMean[h]=3; } fHgcrocToElink[h]=(h%7); } std::cout << std::endl << "Econ::ctor() number of HGCROCs = " - << fHgcroc << std::endl; + << fEconFile->fNumberOfHgcrocs << std::endl; double elinkNum[7]={0,0,0,0,0,0,0}; double elinkMean[7]={0,0,0,0,0,0,0}; - for(unsigned h(0);hfNumberOfHgcrocs;h++) { std::cout << " HGCROC " << std::setw(2) << h - << ", average number of channels = " << fMean[h] + << ", average number of channels = " << fEconFile->fHgcrocMean[h] << ", assigned to Elink = " << fHgcrocToElink[h] << std::endl; elinkNum[fHgcrocToElink[h]]++; - elinkMean[fHgcrocToElink[h]]+=fMean[h]; + elinkMean[fHgcrocToElink[h]]+=fEconFile->fHgcrocMean[h]; } - + /* fTotalNum=0; fTotalMean=0; @@ -119,35 +216,86 @@ public: << fTotalMean << ", average number of 32-bit words = " << fTotalWords << std::endl; + */ + } +#endif + + void slinkNumber(unsigned s) { + fSlink=s; + } + + void econNumber(unsigned e) { + fEcon=e; + } + + void econFile(const EconFile *e) { + fEconFile=e; + } + + const EconFile& econFile() const { + return *fEconFile; } double mean(unsigned h) { assert(h<18); - return fMean[h]; + return fEconFile->fHgcrocMean[h]; } - - void processZs(uint8_t bx, uint8_t l1a, bool randomChannels=true) { + + void processZs(uint8_t bx, uint8_t l1a) { if(fPrintLevel>3) { - std::cout << "EconSim" << fEcon << "::processZs(" << unsigned(bx) - << "," << unsigned(l1a) << "," - << (randomChannels?"true":"false") << ") " + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << unsigned(bx) + << "," << unsigned(l1a) << ") " << "Entered" << std::endl; } TRandom &random(Random::random()); + bool binomialOrFlat; + + for(unsigned h(0);hfNumberOfHgcrocs;h++) { - for(unsigned h(0);hfHgcrocMean[h]+0.5); + + } else if(fDataRandomMethod==Binomial) { + fNumberOfChannels[h]=random.Binomial(72,fEconFile->fHgcrocMean[h]/72.0); + + } else if(fDataRandomMethod==Flat) { + int im(fEconFile->fHgcrocMean[h]+0.5); + if(im>36) { + fNumberOfChannels[h]=2*im-72+random.Integer(145-2*im); + } else { + fNumberOfChannels[h]=random.Integer(2*im+1); + } + + } else if(fDataRandomMethod==Mixed) { + binomialOrFlat=(random.Integer(2)==0); + if(binomialOrFlat) { + fNumberOfChannels[h]=random.Binomial(72,fEconFile->fHgcrocMean[h]/72.0); + } else { + int im(fEconFile->fHgcrocMean[h]+0.5); + if(im>36) { + fNumberOfChannels[h]=2*im-72+random.Integer(145-2*im); + } else { + fNumberOfChannels[h]=random.Integer(2*im+1); + } + } - if(fDataFormatMethod==FixedChannelMap) { + } else { + assert(false); + } + + // Switch for different format methods + + if(fDataFormatMethod==FixedChannelBitmap) { fNumberOfWords[h]=channelsToWords(fNumberOfChannels[h],true); } else if(fDataFormatMethod==FixedChannelLabels) { fNumberOfWords[h]=channelsToWords(fNumberOfChannels[h],false); } else if(fDataFormatMethod==FixedMixture) { - fNumberOfWords[h]=channelsToWords(fNumberOfChannels[h],fMean[h]>fFormatBreakEven); + fNumberOfWords[h]=channelsToWords(fNumberOfChannels[h],fEconFile->fHgcrocMean[h]>fFormatBreakEven); } else if(fDataFormatMethod==VariableMixture) { fNumberOfWords[h]=channelsToWords(fNumberOfChannels[h],fNumberOfChannels[h]>fFormatBreakEven); @@ -157,124 +305,216 @@ public: } if(fPrintLevel>4) { - std::cout << "EconSim" << fEcon << "::processZs(" << unsigned(bx) - << "," << unsigned(l1a) << "," - << (randomChannels?"true":"false") << ") " + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << unsigned(bx) + << "," << unsigned(l1a) << ") " << "Hgcroc " << h << ", number of channels = " << fNumberOfChannels[h] << ", words = " << fNumberOfWords[h] << std::endl; } - HgcrocBoe hboe(fEcon,h,bx,l1a,fNumberOfWords[h]); + // Create HGCROC header - assert((fActiveBuffer&0xff)==l1a); - - fFirstBuffer[0][h][0]=hboe.word(); - - //assert(fElink[fHgcrocToElink[h]].writeAndIncrementPtr(hboe.word())); + HgcrocBoe hboe(fEcon,h,bx,l1a,fNumberOfWords[h]); if(fPrintLevel>4) { - std::cout << "EconSim" << fEcon << "::processZs(" << unsigned(bx) - << "," << unsigned(l1a) << "," - << (randomChannels?"true":"false") << ") " - << "Hgcroc " << h << " BOE written" << std::endl; + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processZs(" << unsigned(bx) + << "," << unsigned(l1a) << ") " + << "Hgcroc " << h << " BOE" << std::endl; hboe.print(); } + // Write data into selected buffer + + assert((fActiveInputBuffer&0xff)==l1a); + fFirstBuffer[fActiveInputBuffer%NumberOfParallelBuffers][h].resize(fNumberOfWords[h]); + fFirstBuffer[fActiveInputBuffer%NumberOfParallelBuffers][h][0]=hboe.word(); + for(unsigned i(1);ifNumberOfBlocks;block++) { + fReadHgcrocNumber[fActiveInputBuffer%NumberOfParallelBuffers][block]=0; + fReadWord[fActiveInputBuffer%NumberOfParallelBuffers][block]=0; + } - fActiveBuffer++; + fActiveInputBuffer++; } void processBx(uint32_t *a) { - // SWITCH DEPENDING ON DATAFLOWMETHOD + // Switch for different dataflow methods + if(fDataFlowMethod==FixedHgcrocMap) { - - } else if(fDataFlowMethod==VariableHgcrocMap) { +#ifdef NOT_YET - - } else if(fDataFlowMethod==EventBuild) { + // 4 words per BX for 7 eLinks + unsigned nWords(4); if(fPrintLevel>3) { - std::cout << "EconSim" << fEcon << "::processBx() " - << "Data flow method = event build, reading HGCROC " - << fReadHgcroc << ", word " << fReadWord << std::endl; + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Data flow method = fixed HGCROC map, reading " + << nWords << " words per BX" << std::endl; } - - for(unsigned w(0);w<24 && fReadHgcroc4) { - std::cout << "EconSim" << fEcon << "::processBx() " - << "Writing word " << w << " from HGCROC " << fReadHgcroc - << ", word " << fReadWord - << " of " << fNumberOfWords[fReadHgcroc] << " = " - << std::hex << fFirstBuffer[0][fReadHgcroc][fReadWord] - << std::dec << std::endl; + for(unsigned e(0);e<7;e++) { + if(fReadHgcroc[b]fNumberOfHgcrocs) { + + for(unsigned w(0);wfNumberOfHgcrocs); + assert(fReadWord[b]4) { + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Copying BX word " << w << " from first buffer " << b + << ", HGCROC " << fReadHgcroc[b] << ", word " << fReadWord[b] + << " of " << fFirstBuffer[b][fReadHgcroc[b]].size() << " = " + << std::hex << fFirstBuffer[b][fReadHgcroc[b]][fReadWord[b]] + << std::dec << std::endl; + } + assert(fElink[fHgcrocToElink[h]].writeAndIncrementPtr(fFirstBuffer[b][fReadHgcrocNumber[b]][fReadWord[b]])); + } + } } - - assert(fEventBuffer.writeAndIncrementPtr(fFirstBuffer[0][fReadHgcroc][fReadWord])); - w++; - } - - if(fReadWord==fNumberOfWords[fReadHgcroc]) { - fReadWord=0; - fReadHgcroc++; } } + + // Add zero padding word if odd + //if((nWords%2)==1) assert(fElink[fHgcrocToElink[h]].writeAndIncrementPtr(0)); uint64_t d; for(unsigned e(0);e<7;e++) { - if(fEventBuffer.readAndIncrementPtr(d)) a[e]=(d&0xffffffff); + if(fElink[e].readAndIncrementPtr(d)) a[e]=(d&0xffffffff); else a[e]=0; if(fPrintLevel>4) { - std::cout << "EconSim" << fEcon << "::processBx() " - << "Reading eLink " << e << " = " + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Sending eLink " << e << " = " << std::hex << a[e] << std::dec << std::endl; } } + +#endif - } else { + } else if(fDataFlowMethod==VariableHgcrocMap) { + + unsigned nWords(0); + + if(fPrintLevel>3) { + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Data flow method = variable HGCROC map, reading " + << nWords << " words per BX" << std::endl; + } + assert(false); - } - /* - if(nReadHgcroc<18) { - //for(unsigned n - assert(fElink[fWriteElink].writeAndIncrementPtr(fFirstBuffer[fActiveBuffer%2][fReadHgcroc][fReadWord])); + + } else if(fDataFlowMethod==EventBuild) { + + // 24 words per BX for 2 parallel buffers = 960 MHz + // 12 words per BX for 3 parallel buffers = 480 MHz + // 8 words per BX for 4 parallel buffers = 320 MHz + //unsigned nWords(24/(NumberOfParallelBuffers-1)); + + + // For one block, must be > 55 words x 18 HGCROCs/44 BX = 22.5; also more than output = 7 words/BX + // OR + // For one block, must be > 39 words x 18 HGCROCs/44 BX = 15.95; also more than output = 7 words/BX + // For seven blocks, must be > 55 words x 3 HGCROCs/44 BX = 3.75; also more than output = 1 word/BX + // OR + // For seven blocks, must be > 39 words x 3 HGCROCs/44 BX = 2.66; also more than output = 1 word/BX + + unsigned nWords(fEconArch->fNumberOfBlocks==1?24:4); + //unsigned nWords(fEconArch->fNumberOfBlocks==1?16:3); + + if(fPrintLevel>3) { + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Data flow method = event build, reading " + << nWords << " words per BX" << std::endl; } - } - // Copy data from first buffers to FIFO - + for(unsigned block(0);blockfNumberOfBlocks;block++) { - // assert(fElink[fHgcrocToElink[h]].writeAndIncrementPtr(fFirstBuffer[fActiveBuffer%2][h][n])); - */ - /* - uint64_t d; - for(unsigned e(0);e<7;e++) { - if(fElink[e].readAndIncrementPtr(d)) a[e]=(d&0xffffffff); - else a[e]=0; + for(unsigned b(0);b4) { + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Reading HGCROC number " << fReadHgcrocNumber[b][block] + << " < " << fEconArch->fHgcrocNumber[block].size() + << ", word number " << fReadWord[b][block] << std::endl; + } + + //if(fReadHgcrocNumber[b]fNumberOfHgcrocs) { + if(fReadHgcrocNumber[b][block]fHgcrocNumber[block].size()) { + + for(unsigned w(0);wfNumberOfHgcrocs); + + unsigned readHgcroc(fEconArch->fHgcrocNumber[block][fReadHgcrocNumber[b][block]]); + std::vector &readBuffer(fFirstBuffer[b][readHgcroc]); // Convenient + assert(fReadWord[b][block]4) { + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Copying BX word " << w << " from block " << block << ", first buffer " << b + << ", HGCROC " << readHgcroc << ", word " << fReadWord[b][block] + << " of " << readBuffer.size() << " = " + << std::hex << readBuffer[fReadWord[b][block]] + << std::dec << std::endl; + } + + // Write word to FIFO + + assert(fEventBuffer[block].writeAndIncrementPtr(readBuffer[fReadWord[b][block]])); + + // Check if completed all words of this HGCROC + + fReadWord[b][block]++; + if(fReadWord[b][block]==readBuffer.size()) { + fReadWord[b][block]=0; + fReadHgcrocNumber[b][block]++; + + // Check if completed all HGCROCs + + if(fReadHgcrocNumber[b][block]==fEconArch->fHgcrocNumber[block].size()) w=nWords; + } + } + } + } + } + + uint64_t d; + for(unsigned e(0);efElinkNumber[block].size();e++) { + if(fEventBuffer[block].readAndIncrementPtr(d)) a[fEconArch->fElinkNumber[block][e]]=(d&0xffffffff); + else a[fEconArch->fElinkNumber[block][e]]=0; + } + } + + if(fPrintLevel>4) { + for(unsigned e(0);e<7;e++) { + std::cout << "EconSim[" << fSlink << "][" << fEcon << "]::processBx() " + << "Sending eLink " << e << " = " + << std::hex << a[e] + << std::dec << std::endl; + } + } + + } else { + assert(false); } - */ } - unsigned nHgcroc() const { - return fHgcroc; + unsigned numberOfHgcrocs() const { + return fEconFile->fNumberOfHgcrocs; } unsigned space(unsigned elink) { @@ -308,24 +548,24 @@ public: else return 1+3*(c+1)/4; } /* - unsigned channelsToWords(unsigned c, double m) const { - if(fDataFormatMethod==FixedChannelMap) { - return channelsToWords(c,true); + unsigned channelsToWords(unsigned c, double m) const { + if(fDataFormatMethod==FixedChannelBitmap) { + return channelsToWords(c,true); } else if(fDataFormatMethod==FixedChannelLabels) { - return channelsToWords(c,false); + return channelsToWords(c,false); } else if(fDataFormatMethod==FixedMixture) { - return channelsToWords(c,m>fFormatBreakEven); + return channelsToWords(c,m>fFormatBreakEven); } else if(fDataFormatMethod==VariableMixture) { - return channelsToWords(c,c>fFormatBreakEven); + return channelsToWords(c,c>fFormatBreakEven); } else { - assert(false); + assert(false); } return -1; - } + } */ static void setFormatBreakEven() { @@ -352,7 +592,7 @@ public: } if(fPrintLevel>0) { - std::cout << "EconSim::setFormatBreakEvent() " + std::cout << "EconSim::setFormatBreakEven() " << "Break-even channel number = " << fFormatBreakEven << std::endl; } @@ -362,41 +602,63 @@ public: unsigned econNumber() const { return fEcon; } + + unsigned econSlink() const { + return fSlink; + } + const EconArch& econArch() const { + return *fEconArch; + } + public: static unsigned fPrintLevel; + + static DataRandomMethod fDataRandomMethod; static DataFormatMethod fDataFormatMethod; static DataFlowMethod fDataFlowMethod; static unsigned fFormatBreakEven; - + /* double fTotalNum; double fTotalMean; double fTotalWords; - + */ + protected: private: - const unsigned fEcon; - const unsigned fHgcroc; - double fMean[18]; + unsigned fSlink; + unsigned fEcon; + const EconFile *fEconFile; + const EconArch *fEconArch; + + //unsigned fNumberOfHgcrocs; + //double fHgcrocMean[18]; + unsigned fHgcrocToElink[18]; CircularBuffer<1> fElink[7]; - CircularBuffer<16> fEventBuffer; + CircularBuffer<16> fEventBuffer[7]; unsigned fNumberOfChannels[18]; unsigned fNumberOfWords[18]; - unsigned fReadHgcroc; - unsigned fReadWord; + //unsigned fReadHgcroc[NumberOfParallelBuffers]; + //unsigned fReadWord[NumberOfParallelBuffers]; + unsigned fReadHgcrocNumber[NumberOfParallelBuffers][20]; + unsigned fReadWord[NumberOfParallelBuffers][20]; unsigned fWriteElink; + + //unsigned fNumberOfBlocks; + std::vector fHgcrocNumber[7]; + std::vector fElinkNumber[7]; - unsigned fActiveBuffer; - std::vector fFirstBuffer[2][18]; + unsigned fActiveInputBuffer; + std::vector fFirstBuffer[NumberOfParallelBuffers][18]; }; unsigned EconSim::fPrintLevel(1); -EconSim::DataFormatMethod EconSim::fDataFormatMethod(EconSim::FixedChannelMap); -EconSim::DataFlowMethod EconSim::fDataFlowMethod(EconSim::FixedHgcrocMap); -unsigned EconSim::fFormatBreakEven(0); +EconSim::DataRandomMethod EconSim::fDataRandomMethod(EconSim::Binomial); +EconSim::DataFormatMethod EconSim::fDataFormatMethod(EconSim::FixedChannelBitmap); +EconSim::DataFlowMethod EconSim::fDataFlowMethod(EconSim::FixedHgcrocMap);unsigned EconSim::fFormatBreakEven(0); #endif diff --git a/interface/Buffering/HgcrocAna.hh b/interface/Buffering/HgcrocAna.hh index 049d3e4ade6ff3419720ff24cd3ca7484c13346e..ad0e56b78a07ba12d1e5c141ff7fc57f73fbab9a 100644 --- a/interface/Buffering/HgcrocAna.hh +++ b/interface/Buffering/HgcrocAna.hh @@ -13,17 +13,33 @@ class HgcrocAna { public: - HgcrocAna(const HgcrocSim &h, unsigned nHistory=100000) : - fHgcrocSim(h), fBusyLength(0) { - - unsigned bd(fHgcrocSim.bufferDepth()); + HgcrocAna() : + fNumberOfBx(0), fNumberOfDeadtimeBx(0), + fBxPreviousL1Accept(-1), fBxPreviousEventComplete(-1), + fBusyLength(0) { + } + + void boj(const HgcrocSim &h, unsigned nHistory=100000) { + fHgcrocSim=&h; + + unsigned bd(fHgcrocSim->bufferDepth()); + bd=100; 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); + ";Number of events in buffer;BXs", + bd,0,bd); hL1AEvents=new TH1D((sName+"L1AEvents").c_str(), - ";Number of events in buffer;L1Accepts",bd,0,bd); + ";Number of events in buffer;L1Accepts", + bd,0,bd); + + hL1AcceptSeparation=new TH1D((sName+"L1AcceptSeparation").c_str(), + ";Time between sequential L1Accepts (BX);Number",1000,0,1000); + hEventCompleteSeparation=new TH1D((sName+"EventCompleteSeparation").c_str(), + ";Time between sequential event completes (BX);Number",1000,0,1000); hBusyLength=new TH1D((sName+"BusyLength").c_str(), ";Length of continuous output (Events);Number",1000,0,1000); @@ -38,34 +54,59 @@ public: } void analyseBx(uint64_t bx) { - hEvents->Fill(fHgcrocSim.numberOfEvents()); + fNumberOfBx++; + if(!fHgcrocSim->allowL1Accept()) fNumberOfDeadtimeBx++; - if(fHgcrocSim.l1Accept()) { - hL1AEvents->Fill(fHgcrocSim.numberOfEvents()); + hEvents->Fill(fHgcrocSim->numberOfEvents()); + + if(fHgcrocSim->l1Accept()) { + hL1AEvents->Fill(fHgcrocSim->numberOfEvents()); hL1AcceptHistory->Fill(bx,3); + + hL1AcceptSeparation->Fill(bx-fBxPreviousL1Accept); + fBxPreviousL1Accept=bx; } - if(fHgcrocSim.eventComplete()) hEventCompleteHistory->Fill(bx,2); - hEventsHistory->Fill(bx,fHgcrocSim.numberOfEvents()); - hWordsHistory->Fill(bx,fHgcrocSim.numberOfWords()); + if(fHgcrocSim->eventComplete()) { + hEventCompleteHistory->Fill(bx,2); - if(fHgcrocSim.numberOfEvents()>0) fBusyLength++; + hEventCompleteSeparation->Fill(bx-fBxPreviousEventComplete); + fBxPreviousEventComplete=bx; + } + + hEventsHistory->Fill(bx,fHgcrocSim->numberOfEvents()); + hWordsHistory->Fill(bx,fHgcrocSim->numberOfWords()); + + if(fHgcrocSim->numberOfEvents()>0) fBusyLength++; else { if(fBusyLength!=0) { - hBusyLength->Fill((fBusyLength+1)/fHgcrocSim.eventLength()); + hBusyLength->Fill((fBusyLength+1)/fHgcrocSim->eventLength()); fBusyLength=0; } } } + void processEoj() { + hCounts->SetBinContent(1,fNumberOfBx); + hCounts->SetBinContent(2,fNumberOfDeadtimeBx); + } + private: - const HgcrocSim &fHgcrocSim; + const HgcrocSim *fHgcrocSim; + + uint64_t fNumberOfBx; + uint64_t fNumberOfDeadtimeBx; + uint64_t fBxPreviousL1Accept; + uint64_t fBxPreviousEventComplete; unsigned fBusyLength; + TH1D *hCounts; TH1D *hEvents; TH1D *hL1AEvents; + TH1D *hL1AcceptSeparation; + TH1D *hEventCompleteSeparation; TH1D *hBusyLength; TH1I *hL1AcceptHistory; diff --git a/interface/Buffering/HgcrocBoe.hh b/interface/Buffering/HgcrocBoe.hh index 3b695cc7a198e3ad0dfb406e825e4a9be21e3bf1..070ab6f0d83963667a5a6bc0cc738c40979e94d2 100644 --- a/interface/Buffering/HgcrocBoe.hh +++ b/interface/Buffering/HgcrocBoe.hh @@ -15,8 +15,9 @@ public: fWord=w; } - HgcrocBoe(uint8_t e, uint8_t h, uint8_t b, uint8_t l, uint8_t n) { - fWord=(b<<24)+((18*e+h)<<16)+(l<<8)+n; + HgcrocBoe(uint8_t e, uint8_t h, uint8_t b, uint8_t l, uint8_t n, bool s=false) { + assert(n<64); + fWord=(b<<24)+((18*e+h)<<16)+(l<<8)+(n&0x3f)+(s?0x40:0); } uint8_t bx() const { @@ -34,11 +35,15 @@ public: uint8_t l1a() const { return (fWord>>8)&0xff; } - - uint16_t numberOfWords() const { - return fWord&0xff; + + bool startOfEvent() const { + return (fWord&0x40)!=0; } + uint8_t numberOfWords() const { + return fWord&0x3f; + } + uint32_t word() const { return fWord; } @@ -52,6 +57,7 @@ public: std::cout << " BX = " << unsigned(bx()) << std::endl; std::cout << " ECON, HGCROC = " << unsigned(econ()) << ", " << unsigned(hgcroc()) << std::endl; std::cout << " L1Accept = " << unsigned(l1a()) << std::endl; + std::cout << " Start of event = " << (startOfEvent()?"true":"false") << std::endl; std::cout << " Number of words = " << unsigned(numberOfWords()) << std::endl; } diff --git a/interface/Buffering/HgcrocSim.hh b/interface/Buffering/HgcrocSim.hh index 078211a46166450d228352a7c3b83125e818f9d6..ebf9998045300abee432781f71a516c48442be39 100644 --- a/interface/Buffering/HgcrocSim.hh +++ b/interface/Buffering/HgcrocSim.hh @@ -7,9 +7,16 @@ class HgcrocSim { public: - HgcrocSim(unsigned e=7, unsigned w=44) : fBufferDepth(1<1) { - std::cout << "HgcrocSim::ctor(" << e << "," << w << ")" << std::endl; + HgcrocSim(){ + } + + void boj(unsigned e=7, unsigned w=44) { + fBufferDepth=(1<0) { + std::cout << "HgcrocSim::ctor(" << e << "," << w << ") " + <<"Entered, buffer depth = " << fBufferDepth << std::endl; } } @@ -105,8 +112,8 @@ public: static unsigned fPrintLevel; private: - const unsigned fBufferDepth; - const unsigned fEventLength; + unsigned fBufferDepth; + unsigned fEventLength; bool fL1Accept; bool fEventComplete; diff --git a/interface/Buffering/LpGbtCheck.hh b/interface/Buffering/LpGbtCheck.hh index 176bb40c959dd5e15d51b4af23e8d8340499cae3..66ade3c8f025bfc192aad9ebe1aabe2f92103edf 100644 --- a/interface/Buffering/LpGbtCheck.hh +++ b/interface/Buffering/LpGbtCheck.hh @@ -5,20 +5,34 @@ #include #include +#include "BlockCheck.hh" + class LpGbtCheck { public: - LpGbtCheck() : fActivePacket(false), fActiveHgcroc(false) { - initialise(-1,-1,0); + LpGbtCheck() { + for(unsigned block(0);block<7;block++) { + fActivePacket[block]=false; + fActiveHgcroc[block]=false; + } } - LpGbtCheck(unsigned s, unsigned e, unsigned h) : fActivePacket(false), fActiveHgcroc(false) { - initialise(s,e,h); + LpGbtCheck(unsigned s, unsigned e, const EconArch &a) { + initialise(s,e,a); + + for(unsigned block(0);block<7;block++) { + fActivePacket[block]=false; + fActiveHgcroc[block]=false; + } } - void initialise(unsigned s, unsigned e, unsigned h) { + void initialise(unsigned s, unsigned e, const EconArch &a) { fSlink=s; fEcon=e; - fNumberOfHgcrocs=h; + fEconArch=&a; + + for(unsigned b(0);bfNumberOfBlocks;b++) { + fBlockCheck[b].initialise(s,e,b,fEconArch->fHgcrocNumber[b]); + } } bool processBx(uint32_t *a) { @@ -27,120 +41,129 @@ public: std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon << "]::processBx() " << "Entered" << std::endl; - } - - for(unsigned e(0);e<7;e++) { - if(fPrintLevel>4) { - std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon - << "]::processBx() " - << "Elink " << e << " word = " - << std::hex << a[e] << std::dec << std::endl; + for(unsigned e(0);e<7;e++) { + std::cout << " Word " << e << " = " << std::hex + << a[e] << std::dec << std::endl; } - - if(!fActivePacket) { - if(a[e]!=0) { - fActivePacket=true; - fActiveHgcroc=true; - - for(unsigned h(0);h4) { - std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon - << "]::processBx() " - << "New packet found" << std::endl; - fHgcrocBoe.print(); - } - - if(fHgcrocBoe.numberOfWords()==1) { - fActiveHgcroc=false; - fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + } - if(fPrintLevel>4) { - std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon - << "]::processBx() " - << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) - << " completed" << std::endl; - } - } + for(unsigned block(0);blockfNumberOfBlocks;block++) { + for(unsigned ee(0);eefElinkNumber[block].size();ee++) { + unsigned e(fEconArch->fElinkNumber[block][ee]); + + if(fPrintLevel>4) { + std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon + << "]::processBx() " + << "L1Accept = " << unsigned(fL1Accept) + << ", block " << block << " of " << fEconArch->fNumberOfBlocks + << ", elink " << ee << " of " << fEconArch->fElinkNumber[block].size() + << ", elink number = " << e << ", word = " + << std::hex << a[e] << std::dec << std::endl; } - } else { - assert(a[e]!=0); - /* - if(a[e]==0) { - fActivePacket=false; - if(fPrintLevel>4) { - std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon - << "]::processBx() " - << "Packet ended" << std::endl; - } - fL1Accept++; - } else { - */ - if(!fActiveHgcroc) { - fHgcroc++; - checkHeader(a[e],false); - fActiveHgcroc=true; - fWords=1; - - if(fPrintLevel>4) { - std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon - << "]::processBx() " - << "New HGCROC found" << std::endl; - fHgcrocBoe.print(); - } - - if(fHgcrocBoe.numberOfWords()==1) { - fActiveHgcroc=false; - fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + fBlockCheck[block].processBx(a[e]); + } + } + /* + if(!fActivePacket[block]) { + if(a[e]!=0) { + fActivePacket[block]=true; + fActiveHgcroc[block]=true; + + for(unsigned h(0);hfHgcrocNumber[block].size();h++) fHgcrocSeen[fEconArch->fHgcrocNumber[block][h]]=false; + fHgcroc=fEconArch->fHgcrocNumber[block][0]; + checkHeader(a[e],true); + fBx=fHgcrocBoe.bx(); + fWords[block]=1; + if(fPrintLevel>4) { std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon << "]::processBx() " - << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) - << " completed" << std::endl; + << "New packet found, seen bits = "; + for(unsigned h(0);h<18;h++) std::cout << (fHgcrocSeen[h]?1:0); + std::cout << std::endl; + std::cout << "New HGCROC found" << std::endl; + fHgcrocBoe.print(); + } + + if(fHgcrocBoe.numberOfWords()==1) { + fActiveHgcroc[block]=false; + fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + + if(fPrintLevel>4) { + std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon + << "]::processBx() " + << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) + << " completed" << std::endl; + } } } } else { - assert((a[e]>>24)==fL1Accept); - assert((a[e]&0xffffff)==fWords); - fWords++; - - if(fWords==fHgcrocBoe.numberOfWords()) { - fActiveHgcroc=false; - fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; - + assert(a[e]!=0); + + if(!fActiveHgcroc[block]) { + fHgcroc++; + checkHeader(a[e],false); + fActiveHgcroc[block]=true; + fWords[block]=1; + if(fPrintLevel>4) { std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon << "]::processBx() " - << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) - << " completed" << std::endl; + << "New HGCROC found" << std::endl; + fHgcrocBoe.print(); + } + + if(fHgcrocBoe.numberOfWords()==1) { + fActiveHgcroc[block]=false; + fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + + if(fPrintLevel>4) { + std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon + << "]::processBx() " + << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) + << " completed" << std::endl; + } + } + + } else { + assert((a[e]>>24)==fL1Accept); + assert((a[e]&0xffffff)==fWords[block]); + fWords[block]++; + + if(fWords[block]==fHgcrocBoe.numberOfWords()) { + fActiveHgcroc[block]=false; + fHgcrocSeen[fHgcrocBoe.hgcroc()]=true; + + if(fPrintLevel>4) { + std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon + << "]::processBx() " + << "HGCROC " << unsigned(fHgcrocBoe.hgcroc()) + << " completed" << std::endl; + } } } - } - bool allSeen(true); - for(unsigned h(0);h4) { - std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon - << "]::processBx() " - << "Packet ended" << std::endl; + if(allSeen) { + fActivePacket[block]=false; + if(fPrintLevel>4) { + std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon + << "]::processBx() " + << "Packet ended" << std::endl; + } + fL1Accept++; } - fL1Accept++; } } } - + */ return true; } @@ -162,16 +185,21 @@ public: private: unsigned fSlink; unsigned fEcon; + BlockCheck fBlockCheck[7]; + + unsigned fNumberOfHgcrocs; unsigned fHgcroc; + + const EconArch *fEconArch; - bool fActivePacket; - bool fActiveHgcroc; + bool fActivePacket[7]; + bool fActiveHgcroc[7]; uint8_t fL1Accept; uint8_t fBx; HgcrocBoe fHgcrocBoe; - unsigned fWords; + unsigned fWords[7]; bool fHgcrocSeen[18]; }; diff --git a/interface/Buffering/SlinkArch.hh b/interface/Buffering/SlinkArch.hh new file mode 100644 index 0000000000000000000000000000000000000000..b1bee6c5f204d2357f1ea3bd3c7f467d704d1b97 --- /dev/null +++ b/interface/Buffering/SlinkArch.hh @@ -0,0 +1,47 @@ +#ifndef SlinkArch_HH +#define SlinkArch_HH + +#include + +#include "SlinkFile.hh" +#include "EconArch.hh" + +class SlinkArch { +public: + SlinkArch() { + }; + + void initialise(const SlinkFile *s, bool b) { + fSlinkFile=s; + + for(unsigned e(0);enumberOfEcons();e++) { + const EconFile &econFile(fSlinkFile->econFile(e)); + fEconArch[e].initialise(b,econFile); //.numberOfHgcrocs()); + } + } + + unsigned slinkNumber() const { + return fSlinkFile->slinkNumber(); + } + + unsigned numberOfEcons() const { + return fSlinkFile->numberOfEcons(); + } + + const EconArch& econArch(unsigned e) const { + assert(enumberOfEcons()); + return fEconArch[e]; + } + + void print() const { + std::cout << "SlinkArch::print() "; + fSlinkFile->print(); + for(unsigned e(0);enumberOfEcons();e++) fEconArch[e].print(); + } + +private: + const SlinkFile *fSlinkFile; + EconArch fEconArch[Dimensions::MaxNumberOfEconsPerSlink]; +}; + +#endif diff --git a/interface/Buffering/SlinkCheck.hh b/interface/Buffering/SlinkCheck.hh new file mode 100644 index 0000000000000000000000000000000000000000..83deb35624bfe249492d3a897efa2396f867e5c6 --- /dev/null +++ b/interface/Buffering/SlinkCheck.hh @@ -0,0 +1,235 @@ +#ifndef SlinkCheck_HH +#define SlinkCheck_HH + +#include "SlinkArch.hh" + + +class SlinkCheck { +public: + SlinkCheck() : fEventActive(false) { + + if(fPrintLevel>0) { + std::cout << "SlinkCheck::ctor() " + << "Entered" << std::endl; + } + } + + void boj(const SlinkArch &a) { + fSlinkArch=&a; + fEventActive=false; + nCalls=0; + fL1Accept=-1; + nHgcrocWords=0; + + for(unsigned e(0);enumberOfEcons();e++) { + const EconArch &econArch(fSlinkArch->econArch(e)); + for(unsigned b(0);bslinkNumber(),e,b,econArch.hgcrocNumber(b)); + } + } + } + + //void processWords(uint64_t *d, bool be=false) { + //void processWord(const std::pair &w) { + void processWord(uint128_t w, bool be) { + + if(fPrintLevel>3) { + std::cout << "SlinkCheck::processWord() " + << "Call " << nCalls << " words = 0x" << std::hex + << w.second << " " << w.first << std::dec + << ", begin/end flag = " << (be?"true":"false") + << std::endl; + } + + uint64_t d[2]={w.first,w.second}; + + nCalls++; + + // FIX ME!!! + //assert(be); + + if(!fEventActive) { + assert(be); + fBoe.setWords(d); + + if(fPrintLevel>4) { + std::cout << "SlinkCheck::processWord() " + << ", new BOE found" << std::endl; + fBoe.print(); + } + + assert(fBoe.valid()); + fL1Accept=(fL1Accept+1)&0xffffffff; + assert(fBoe.eventId()==fL1Accept); + + fEventActive=true; + fEconRead=0; + fBlockRead=0; + + for(unsigned e(0);e<5;e++) { + for(unsigned h(0);h<18;h++) { + if(e==0) completedHgcroc[e][h]=false; + if(e==1) completedHgcroc[e][h]=(h>=12); + if(e>=2) completedHgcroc[e][h]=(h>=9); + } + } + + return; + } + + if(be) { + fEoe.setWords(d); + + if(fPrintLevel>4) { + std::cout << "SlinkCheck::processWord() " + << "New EOE found" << std::endl; + fEoe.print(); + } + + assert(fEoe.valid()); + assert(w.second); + assert(fEoe.fedUserId()==fBoe.sourceId()); + assert(fEoe.status()==0x77); + assert(fEoe.crc()==0xff); + assert(fEoe.eventLength()==nWords); + + if(nWords==0) { + if(fPrintLevel>4) { + std::cout << "SlinkCheck::processWord() " + << "Empty event found" << std::endl; + fBoe.print(); + fEoe.print(); + } + } + + fEventActive=false; + nWords=0; + return; + } + + assert(fEconReadnumberOfEcons()); + + nWords++; + + fData[0]=d[0]&0xffffffff; + fData[1]=d[0]>>32; + fData[2]=d[1]&0xffffffff; + fData[3]=d[1]>>32; + + for(unsigned i(0);i<4;i++) { + if(fEconReadnumberOfEcons()) { + + if(fPrintLevel>5) { + std::cout << "SlinkCheck::processWord() " + << "ECON read " << fEconRead + << ", block read " << fBlockRead + << ", checking word " << i << " = " + << std::hex << fData[i] << std::dec + << std::endl; + } + + if(fBlockCheck[fEconRead][fBlockRead].processBx(fData[i])) fBlockRead++; + + if(fBlockRead==fSlinkArch->econArch(fEconRead).numberOfBlocks()) { + fBlockRead=0; + fEconRead++; + } + + } else { + if(fPrintLevel>5) { + std::cout << "SlinkCheck::processWord() " + << "ECON read " << fEconRead + << ", block read " << fBlockRead + << ", checking word " << i << " = " + << std::hex << fData[i] << std::dec + << std::endl; + } + + assert(fData[i]==0); + } + } + + // REPLACE WITH BLOCKCHECK + //for(unsigned i(0);i<4;i++) processHgcrocWord(fData[i]); + } + + bool allComplete() const { + for(unsigned e(0);e<5;e++) { + for(unsigned h(0);h<18;h++) { + if(!completedHgcroc[e][h]) return false; + } + } + return true; + } + + void processHgcrocWord(uint32_t w) { + if(nHgcrocWords==0) { + std::cout << "All completed ="; + for(unsigned e(0);e<5;e++) { + std::cout << " "; + for(unsigned h(0);h<18;h++) { + std::cout << (completedHgcroc[e][h]?1:0); + } + } + std::cout << std::endl; + + if(allComplete()) { + assert(w==0); + return; + } + + fHgcrocBoe.word(w); + + DEBUG_PRINT << " processHgcrocWord, fL1Accept = " << fL1Accept << " &0xff = " << (fL1Accept&0xff) << std::endl; + fHgcrocBoe.print(); + + assert(fHgcrocBoe.l1a()==(fL1Accept&0xff)); + + } else { + DEBUG_PRINT << " processHgcrocWord, nHgcrocWords = " << nHgcrocWords << ", word = " << w << std::endl; + + assert(w==nHgcrocWords); + } + + nHgcrocWords++; + if(nHgcrocWords==fHgcrocBoe.numberOfWords()) { + completedHgcroc[fHgcrocBoe.econ()][fHgcrocBoe.hgcroc()]=true; + nHgcrocWords=0; + } + } + + + uint64_t numberOfCalls() const { + return nCalls; + } + + static unsigned fPrintLevel; + + +private: + const SlinkArch *fSlinkArch; + + unsigned fEconRead; + unsigned fBlockRead; + BlockCheck fBlockCheck[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon]; + + uint64_t nCalls; + + bool fEventActive; + uint32_t fL1Accept; + + SlinkBoe fBoe; + SlinkEoe fEoe; + uint16_t nWords; + + uint32_t fData[4]; + + HgcrocBoe fHgcrocBoe; + unsigned nHgcrocWords; + + bool completedHgcroc[5][18]; +}; + +unsigned SlinkCheck::fPrintLevel(1); + +#endif diff --git a/interface/Buffering/SlinkEoe.hh b/interface/Buffering/SlinkEoe.hh index a0ada3f7cee46cf1227c7f10d5bdbb3edba9c70e..98226f677842b1ba8308f50bfa63458d8833e594 100644 --- a/interface/Buffering/SlinkEoe.hh +++ b/interface/Buffering/SlinkEoe.hh @@ -35,6 +35,15 @@ public: fEoe=(d[1]>>32); } + void word(uint128_t &w) const { + w.first=fCrc; + w.first=(w.first<<16)+fStatus; + w.first=(w.first<<32)+fFedUserId; + + w.second=fEoe; + w.second=(w.second<<32)+fEventLength; + } + void words(uint64_t *d) const { d[0]=fCrc; d[0]=(d[0]<<16)+fStatus; diff --git a/interface/Buffering/SlinkFile.hh b/interface/Buffering/SlinkFile.hh new file mode 100644 index 0000000000000000000000000000000000000000..98340c21435e2fa544b8c83d40959e95ab35734e --- /dev/null +++ b/interface/Buffering/SlinkFile.hh @@ -0,0 +1,90 @@ +#ifndef SlinkFile_HH +#define SlinkFile_HH + +#include + +#include "EconFile.hh" + +class SlinkFile { +public: + SlinkFile () : fSlink(-1), fNumberOfEcons(-1) { + } + + void slinkNumber(unsigned s) { + fSlink=s; + } + + unsigned slinkNumber() const { + return fSlink; + } + + unsigned numberOfEcons() const { + return fNumberOfEcons; + } + + const EconFile& econFile(unsigned e) const { + assert(e> lead >> fNumberOfEcons; + if(lead!='S') return false; + if(fNumberOfEcons>Dimensions::MaxNumberOfEconsPerSlink) return false; + + for(unsigned e(0);e> lead >> fNumberOfHgcrocs[e]; + if(lead!='E') return false; + if(fNumberOfHgcrocs[e]>MaxNumberOfHgcrocs) return false; + + for(unsigned h(0);h> fHgcrocMean[e][h]; + if(fHgcrocMean[e][h]< 0) return false; + if(fHgcrocMean[e][h]>72) return false; + } + */ + } + + if(!fin) return false; + return true; + } + + void print() const { + std::cout << "SlinkFile::print() Slink " + << std::setw(2) << fSlink + << ", number of ECONs = " << fNumberOfEcons << std::endl; + + for(unsigned e(0);e uint128_t; +#include "Buffering/Dimensions.hh" + +class SlinkElinkData { +public: + SlinkElinkData() { + } + + uint32_t fData[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfElinksPerEcon]; +}; + + #include "Buffering/CircularBuffer.hh" #include "Buffering/PartitionedBuffer.hh" #include "Buffering/HgcrocSim.hh" @@ -20,17 +31,20 @@ typedef std::pair uint128_t; #include "Buffering/EconSim.hh" #include "Buffering/EconAna.hh" #include "Buffering/LpGbtCheck.hh" +#include "Buffering/BeSlinkSim.hh" +#include "Buffering/BeSlinkAna.hh" +#include "Buffering/SlinkArch.hh" +#include "Buffering/SlinkFile.hh" #include "Buffering/SlinkBoe.hh" #include "Buffering/SlinkEoe.hh" - #define DEBUG_PRINT if(false) std::cout << "Line " << __LINE__ << ": " +#include "Buffering/SlinkCheck.hh" + #ifndef TriggerRule_PrintLevel #define TriggerRule_PrintLevel 10 #endif -const unsigned NumberOfSlinks(1); - class TriggerRule { public: @@ -287,6 +301,7 @@ private: uint32_t fWord; }; */ +/* class SlinkCheck { public: SlinkCheck() : fEventActive(false) { @@ -428,155 +443,8 @@ private: bool completedHgcroc[5][18]; }; - -/* -class Econ { -public: - Econ(unsigned e, unsigned h=18, unsigned m=0) : fEcon(e), fHgcroc(h) { - assert(fHgcroc<=18); - - // Random values for now - //for(unsigned h(0);h=4) { - fMean[h]=1; - if(h<14) fMean[h]=2; - if(h< 7) fMean[h]=3; - } - - fHgcrocToElink[h]=(h%7); - } - - std::cout << std::endl << "Econ::ctor() number of HGCROCs = " - << fHgcroc << std::endl; - - double elinkNum[7]={0,0,0,0,0,0,0}; - double elinkMean[7]={0,0,0,0,0,0,0}; - - for(unsigned h(0);h fElink[7]; - -public: - double fTotalNum; - double fTotalMean; - double fTotalWords; -}; */ + /* class Noce { public: @@ -743,79 +611,110 @@ private: int main(int argc, char* argv[]) { - /* - if(argc<3) { - std::cerr << "Usage: " << argv[0] << " " << std::endl; - return 1; - } - */ - bool randomL1Accept(true); - bool randomChannels(true); + unsigned l1AcceptAverageRate(750); + unsigned printLevel(1); + unsigned seconds(1); + unsigned hgcrocLimit(4); + unsigned slinkNumber[Dimensions::MaxNumberOfSlinks]; + unsigned block(1); + unsigned long rSeed(0); + unsigned econRandom(EconSim::Mixed); + unsigned econFormat(EconSim::FixedChannelBitmap); + unsigned econFlow(EconSim::FixedHgcrocMap); + + for(unsigned n(0);n " << std::endl; + return 1; + } + for(int i(1);i> rSeed; + if(sarg1=="--seconds") sarg2 >> seconds; + if(sarg1=="--l1AcceptAverageRate") sarg2 >> l1AcceptAverageRate; + if(sarg1=="--hgcrocLimit") sarg2 >> hgcrocLimit; + if(sarg1=="--printLevel") sarg2 >> printLevel; + + if(sarg1=="--slinkFile") sarg2 >> slinkNumber[0]; + if(sarg1=="--slinkNumber") sarg2 >> slinkNumber[0]; + if(sarg1=="--block") sarg2 >> block; + if(sarg1=="--econRandom") sarg2 >> econRandom; + if(sarg1=="--econFormat") sarg2 >> econFormat; + //if(sarg1=="--econFlow") sarg2 >> econFlow; + } + bool doingEcon(true); - bool doingBe(false); + bool doingBe(true); - EconSim::fDataFormatMethod=EconSim::FixedChannelLabels; - EconSim::fDataFlowMethod=EconSim::EventBuild; + std::ostringstream sout; + sout << "_L1AcceptAverageRate" << l1AcceptAverageRate; + sout << "_HgcrocLimit" << hgcrocLimit; + + if(doingEcon) { + sout << "_SlinkNumber" << std::setw(2) << std::setfill('0') << slinkNumber[0]; + sout << "_EconRandom" << econRandom; + sout << "_EconFormat" << econFormat; + sout << "_Block" << block; + assert(block==1 || block==7); + } + + if(doingBe) { + } + + sout << "_Seconds" << seconds; - unsigned pl(1); - HgcrocSim::fPrintLevel=pl; - EconSim::fPrintLevel=pl; - LpGbtCheck::fPrintLevel=pl; + std::string sName("DaqDaqBuffer/DaqDaqBuffer"); + + if(!doingEcon) sName+="_HgcrocOnly"; + else if(!doingBe) sName+="_HgcrocAndEcon"; + else sName+="_FullChain"; + + sName+=sout.str(); + + bool randomL1Accept(true); + + //EconSim::fDataRandomMethod=EconSim::Flat; + EconSim::fDataRandomMethod=EconSim::DataRandomMethod(econRandom); + + //EconSim::fDataFormatMethod=EconSim::FixedChannelBitmap; + //EconSim::fDataFormatMethod=EconSim::FixedChannelLabels; + //EconSim::fDataFormatMethod=EconSim::FixedMixture; + //EconSim::fDataFormatMethod=EconSim::VariableMixture; + EconSim::fDataFormatMethod=EconSim::DataFormatMethod(econFormat); + EconSim::fDataFlowMethod=EconSim::EventBuild; + + HgcrocSim::fPrintLevel=printLevel; + EconSim::fPrintLevel=printLevel; + BlockCheck::fPrintLevel=printLevel; + LpGbtCheck::fPrintLevel=printLevel; + BeSlinkSim::fPrintLevel=printLevel; + SlinkCheck::fPrintLevel=printLevel; + const unsigned NumberOfSlinks(1); + assert(NumberOfSlinks<=Dimensions::MaxNumberOfSlinks); + assert(sizeof(SlinkBoe)==16); assert(sizeof(SlinkEoe)==16); + assert(sizeof(uint128_t)==16); - SlinkBoe sboe(0xce00,999,123,7); - sboe.print(); - std::cout << std::endl; - SlinkEoe seoe(0xce00,0x77,0xff,10); - seoe.print(); - Random random; + random.random().SetSeed(rSeed); + CircularBuffer<1> cbBoe; CircularBuffer<1> cb; CircularBuffer<1> cbFinal; PartitionedBuffer<18,4> pb[5]; - SlinkCheck slinkCheck; BeReadState brs; uint64_t d; - unsigned cw(0),cr(0),fw(0),fr(0); - unsigned i(0); - for(;i<2048;i++) { - assert(cb.writeAndIncrementPtr(cw)); - cw++; - } - - for(;i<10000000;i++) { - if(random.random().Integer(10000)<5000) { - if(cb.writeAndIncrementPtr(cw)) { - cw++; - } else { - fw++; - } - } else { - if(cb.readAndIncrementPtr(d)) { - assert(d==cr); - cr++; - } else { - fr++; - } - } - } - std::cout << "Writes, fails = " << cw << ", " << fw << std::endl; - std::cout << " Reads, fails = " << cr << ", " << fr << std::endl; - std::cout << "Total = " << cw+cr+fw+fr << std::endl; - - //EconSim econTest; - //for(unsigned l(0);l<3;l++) { - //econTest.processL1A(l&0xff); - //} unsigned nHWords(0); @@ -928,56 +827,91 @@ int main(int argc, char* argv[]) { econTest.reset(); //return 0; */ - TFileHandler tfh("DaqDaqBuffer"); + TFileHandler tfh(sName); + + unsigned nHistory(10000); - HgcrocSim hgcrocSim(7); - HgcrocAna hgcrocAna(hgcrocSim,nHistory); + HgcrocSim hgcrocSim; + HgcrocAna hgcrocAna; + + SlinkFile slinkFile[NumberOfSlinks]; + SlinkArch slinkArch[NumberOfSlinks]; + SlinkElinkData slinkElinkData[NumberOfSlinks]; - EconSim *econ[NumberOfSlinks][5]={{0,0,0,0,0}}; - EconAna *econAna[NumberOfSlinks][5]={{0,0,0,0,0}}; - LpGbtCheck lpGbtCheck[NumberOfSlinks][5]; + EconSim econSim[NumberOfSlinks][Dimensions::MaxNumberOfEconsPerSlink]; + EconAna econAna[NumberOfSlinks][Dimensions::MaxNumberOfEconsPerSlink]; + LpGbtCheck lpGbtCheck[NumberOfSlinks][Dimensions::MaxNumberOfEconsPerSlink]; + BeSlinkSim beSlinkSim[NumberOfSlinks]; + BeSlinkAna beSlinkAna[NumberOfSlinks]; + SlinkCheck slinkCheck[NumberOfSlinks]; + + + + + + + double totalLinkWords(0.0); unsigned nEventWords(0); std::string sNum[7]={"0","1","2","3","4","5","6"}; - TH1F *hEconMean[5]; + + + // Initialisation + + hgcrocSim.boj(hgcrocLimit); + hgcrocAna.boj(hgcrocSim,nHistory); + if(doingEcon) { for(unsigned sl(0);slfTotalWords; - - lpGbtCheck[sl][ec].initialise(sl,ec,econ[sl][ec]->nHgcroc()); + lpGbtCheck[sl][ec].initialise(sl,ec,econSim[sl][ec].econArch()); + } + + if(doingBe) { + beSlinkSim[sl].boj(sl,slinkArch[sl]); + beSlinkAna[sl].boj(beSlinkSim[sl],nHistory); - for(unsigned h(0);h<18;h++) { - hEconMean[ec]->Fill(h,econ[sl][ec]->mean(h)); - } - econAna[sl][ec]=new EconAna(*(econ[sl][ec])); + slinkCheck[sl].boj(slinkArch[sl]); } } } - + std::cout << std::endl << "lpGBT total average 32-bit words per event = " << totalLinkWords << std::endl; TH1F *hWorst=new TH1F("Worst",";Log10(secs);Worst",35,-5.5,29.5); - TH1D *hEconSpace[5][7]; - TH1F *hEconSpaceHistory[5][7]; + TH1D *hCounts=new TH1D("MainCounts",";Counts", + 10,0,10); + + + + + //TH1D *hEconSpace[5][7]; + //TH1F *hEconSpaceHistory[5][7]; TH1D *hSboeSpace; TH1F *hSboeSpaceHistory; TH1D *hSpace[5][18]; @@ -987,10 +921,10 @@ int main(int argc, char* argv[]) { for(unsigned ec(0);ec<5;ec++) { for(unsigned e(0);e<7;e++) { - hEconSpace[ec][e]=new TH1D((std::string("Econ")+sNum[ec]+"Elink"+sNum[e]+"Space").c_str(), - ";Circular buffer space",4096,0,4096); - hEconSpaceHistory[ec][e]=new TH1F((std::string("Econ")+sNum[ec]+"Elink"+sNum[e]+"SpaceHistory").c_str(), - ";BX;Circular buffer space",nHistory,0,nHistory); + //hEconSpace[ec][e]=new TH1D((std::string("Econ")+sNum[ec]+"Elink"+sNum[e]+"Space").c_str(), + // ";Circular buffer space",4096,0,4096); + //hEconSpaceHistory[ec][e]=new TH1F((std::string("Econ")+sNum[ec]+"Elink"+sNum[e]+"SpaceHistory").c_str(), + // ";BX;Circular buffer space",nHistory,0,nHistory); } for(unsigned h(0);h<18;h++) { hSpace[ec][h]=new TH1D((std::string("BeEcon")+sNum[ec]+"Hgcroc"+sHgcroc[h]+"Space").c_str(), @@ -1005,13 +939,14 @@ int main(int argc, char* argv[]) { hSboeSpaceHistory=new TH1F((std::string("Sboe")+"SpaceHistory").c_str(), ";BX;BOE buffer space",nHistory,0,nHistory); + int64_t runSec(seconds); //int64_t runSec(-10000); // for 0.0001 run secs - //int64_t runSec(-1000); // for 0.001 run secs + //runSec=-1000; // for 0.001 run secs //int64_t runSec(-100); // for 0.01 run secs - //int64_t runSec(-10); // for 0.1 run secs + //runSec=-10; // for 0.1 run secs //int64_t runSec(1); // for 1 run secs //int64_t runSec(10); // for 10 run secs - int64_t runSec(100); // ~4 mins for 100 run secs + //int64_t runSec(100); // ~4 mins for 100 run secs //int64_t runSec(1000); // ~40 mins for 1000 run secs //int64_t runSec(10000); // ~6 hours for 10000 run secs @@ -1020,7 +955,6 @@ int main(int argc, char* argv[]) { uint64_t maxBx(runSec>=0?bxPerSec*runSec:bxPerSec/(-runSec)); std::cout << "Max BX = " << maxBx << ", run time = " << (runSec>=0?runSec:-1.0/runSec) << " sec" << std::endl; - unsigned nL1A(0); unsigned nOut(0); @@ -1036,6 +970,11 @@ int main(int argc, char* argv[]) { for(uint64_t bx(0);bx100000) { + //BeSlinkSim::fPrintLevel=6; + //SlinkCheck::fPrintLevel=6; + //} + //////////////////////////////////////////////////////////// // // L1A and HGCROC @@ -1048,7 +987,7 @@ int main(int argc, char* argv[]) { if(!hgcrocSim.allowL1Accept()) { nHgcrocDeadtime++; } else { - if(randomL1Accept) newL1AIn=(random.random().Uniform()<(0.750/40.0)); + if(randomL1Accept) newL1AIn=(random.random().Uniform()<(l1AcceptAverageRate/40000.0)); else newL1AIn=((bx%53)==0); } @@ -1079,28 +1018,18 @@ int main(int argc, char* argv[]) { for(unsigned sl(0);slprocessZs(bx&0xff,numberL1AOut&0xff,randomChannels); - econAna[sl][ec]->analyseZs(bx); + econSim[sl][ec].processZs(bx&0xff,numberL1AOut&0xff); + econAna[sl][ec].analyseZs(bx); } - econ[sl][ec]->processBx(array[ec][bx%2]); - econAna[sl][ec]->analyseBx(bx); + //econSim[sl][ec].processBx(array[ec][bx%2]); + econSim[sl][ec].processBx(slinkElinkData[sl].fData[ec]); + econAna[sl][ec].analyseBx(bx); if(!doingBe) { - lpGbtCheck[sl][ec].processBx(array[ec][bx%2]); - } - } - - - - - for(unsigned ec(0);ec<5;ec++) { - for(unsigned e(0);e<7;e++) { - hEconSpace[ec][e]->Fill(econ[sl][ec]->used(e)); - hEconSpaceHistory[ec][e]->Fill(bx,econ[sl][ec]->used(e)); + //lpGbtCheck[sl][ec].processBx(array[ec][bx%2]); + lpGbtCheck[sl][ec].processBx(slinkElinkData[sl].fData[ec]); } } - - } //////////////////////////////////////////////////////////// @@ -1111,6 +1040,23 @@ int main(int argc, char* argv[]) { if(doingBe) { + for(unsigned sl(0);slSetBinContent(1,maxBx); + hCounts->SetBinContent(2,numberL1AIn); + hCounts->SetBinContent(3,numberL1AOut); + hCounts->SetBinContent(4,nHgcrocDeadtime); + std::cout << "Number of L1As = " << numberL1AIn << ", " << numberL1AOut << ", rate = " << numberL1AIn/runSecs << " kHz" << std::endl; + + std::cout << "Number of HGCROC deadtime BXs = " << nHgcrocDeadtime + << ", fraction = " << 1.0*nHgcrocDeadtime/maxBx << std::endl; + + hgcrocAna.processEoj(); + + for(unsigned sl(0);sl