BeSlinkAna.hh 4.7 KB
Newer Older
dauncey's avatar
dauncey committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef BeSlinkAna_HH
#define BeSlinkAna_HH

#include <iostream>
#include <iomanip>
#include <cassert>

#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;
dauncey's avatar
dauncey committed
22 23 24
    fPreviousThrottleActive=false;
    fRaisedThrottleBx=-1;
    fEndedThrottleBx=-1;
dauncey's avatar
dauncey committed
25 26

    fThrottleHistWeight=fBeSlinkSim->fBufferLimit;
dauncey's avatar
dauncey committed
27 28 29
    
    std::ostringstream sout;
    sout << "BeSlinkAna" << std::setw(2) << std::setfill('0')
dauncey's avatar
dauncey committed
30
	 << fBeSlinkSim->slinkNumber();
dauncey's avatar
dauncey committed
31 32 33
    
    std::string sHgcroc[18]={"00","01","02","03","04","05","06","07","08",
			     "09","10","11","12","13","14","15","16","17"};
dauncey's avatar
dauncey committed
34

35 36
    hTotalEventWords=new TH1D((sout.str()+"TotalEventWords").c_str(),
			      ";Total number of bytes per event",250,0,4000);
dauncey's avatar
dauncey committed
37
    
dauncey's avatar
dauncey committed
38 39 40 41 42
    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(),
dauncey's avatar
dauncey committed
43
					";Number of event buffer words used",1200,0,6000);
dauncey's avatar
dauncey committed
44 45
	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);
dauncey's avatar
dauncey committed
46
	hEventBufferExceeded[e][b]=new TH1D((sout.str()+"Econ"+sHgcroc[e]+"Block"+sHgcroc[b]+"EventBufferExceeded").c_str(),
dauncey's avatar
dauncey committed
47
					";Number of event buffer words used",1200,0,6000);
dauncey's avatar
dauncey committed
48 49
      }
    }
dauncey's avatar
dauncey committed
50 51 52 53 54
    
    hEventBufferUsedMax=new TH1D((sout.str()+"EventBufferUsedMax").c_str(),
				    ";Number of event buffer words used",1200,0,6000);
    hEventBufferUsedHistoryMax=new TH1I((sout.str()+"EventBufferUsedHistoryMax").c_str(),
					   ";BX;Number of event buffer words used",nHistory,0,nHistory);
dauncey's avatar
dauncey committed
55 56 57

    hThrottleActiveHistory=new TH1I((sout.str()+"ThrottleActiveHistory").c_str(),
				    ";BX;Throttle active",nHistory,0,nHistory);
dauncey's avatar
dauncey committed
58 59
    hDelayedThrottleActiveHistory=new TH1I((sout.str()+"DelayedThrottleActiveHistory").c_str(),
				    ";BX;Delayed throttle active",nHistory,0,nHistory);
dauncey's avatar
dauncey committed
60 61 62 63
    hRaisedThrottleToL1Accept=new TH1D((sout.str()+"RaisedThrottleToL1Accept").c_str(),
				    ";L1Accept - ended throttle (BX)",1000,0,1000);
    hEndedThrottleToL1Accept=new TH1D((sout.str()+"EndedThrottleToL1Accept").c_str(),
				    ";L1Accept - ended throttle (BX)",1000,0,1000);
dauncey's avatar
dauncey committed
64 65 66
  }
  
  void analyseL1Accept(uint64_t bx) {
dauncey's avatar
dauncey committed
67 68
    if(fRaisedThrottleBx!=-1) hRaisedThrottleToL1Accept->Fill(bx-fRaisedThrottleBx);
    if(fEndedThrottleBx!=-1) hEndedThrottleToL1Accept->Fill(bx-fEndedThrottleBx);
dauncey's avatar
dauncey committed
69 70 71
  }
  
  void analyseBx(uint64_t bx) {
dauncey's avatar
dauncey committed
72 73
    unsigned maxBufferUsed(0);

dauncey's avatar
dauncey committed
74 75 76 77
    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++) {
dauncey's avatar
dauncey committed
78 79 80 81 82 83
	const unsigned bufferUsed(fBeSlinkSim->fEventBuffer[e][b].used());
	if(maxBufferUsed<bufferUsed) maxBufferUsed=bufferUsed;

	hEventBufferUsed[e][b]->Fill(bufferUsed);
	hEventBufferUsedHistory[e][b]->Fill(bx,bufferUsed);
	if(fBeSlinkSim->exceededBuffer()) hEventBufferExceeded[e][b]->Fill(bufferUsed);
dauncey's avatar
dauncey committed
84
      }
dauncey's avatar
dauncey committed
85
    }
86

dauncey's avatar
dauncey committed
87 88 89
    hEventBufferUsedMax->Fill(maxBufferUsed);
    hEventBufferUsedHistoryMax->Fill(bx,maxBufferUsed);
    
90 91 92
    if(fBeSlinkSim->fL1AcceptEoe) {
      hTotalEventWords->Fill(16*fBeSlinkSim->fTotalNumberOfEventWords);
    }
dauncey's avatar
dauncey committed
93

dauncey's avatar
dauncey committed
94 95 96 97
    // Add +1 as throttle is applied to next BX
    if(fBeSlinkSim->throttleActive()) {
      if(!fPreviousThrottleActive) fRaisedThrottleBx=bx+1;
      hThrottleActiveHistory->Fill(bx+1,fThrottleHistWeight);
dauncey's avatar
dauncey committed
98
    } else {
dauncey's avatar
dauncey committed
99
      if(fPreviousThrottleActive) fEndedThrottleBx=bx+1;
dauncey's avatar
dauncey committed
100 101
    }

dauncey's avatar
dauncey committed
102 103 104 105
    if(fBeSlinkSim->delayedThrottleActive(bx)) {
      hDelayedThrottleActiveHistory->Fill(bx+1,fThrottleHistWeight-50);
    }
    
dauncey's avatar
dauncey committed
106
    fPreviousThrottleActive=fBeSlinkSim->fThrottleActive;
dauncey's avatar
dauncey committed
107 108 109 110 111 112 113 114
  }
  
  void eoj() {
  }
  
private:
  const BeSlinkSim *fBeSlinkSim;

dauncey's avatar
dauncey committed
115 116 117
  bool fPreviousThrottleActive;
  uint64_t fRaisedThrottleBx;
  uint64_t fEndedThrottleBx;
dauncey's avatar
dauncey committed
118
  unsigned fThrottleHistWeight;
dauncey's avatar
dauncey committed
119
  
120
  TH1D *hTotalEventWords;
dauncey's avatar
dauncey committed
121
  TH1I *hThrottleActiveHistory;
dauncey's avatar
dauncey committed
122
  TH1I *hDelayedThrottleActiveHistory;
dauncey's avatar
dauncey committed
123 124 125
  TH1D *hRaisedThrottleToL1Accept;
  TH1D *hEndedThrottleToL1Accept;
  
dauncey's avatar
dauncey committed
126 127
  TH1D *hEventBufferUsed[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
  TH1I *hEventBufferUsedHistory[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
dauncey's avatar
dauncey committed
128
  TH1D *hEventBufferExceeded[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
dauncey's avatar
dauncey committed
129 130
  TH1D *hEventBufferUsedMax;
  TH1I *hEventBufferUsedHistoryMax;
dauncey's avatar
dauncey committed
131 132 133
};

#endif