BeSlinkAna.hh 3.69 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 27
    
    std::ostringstream sout;
    sout << "BeSlinkAna" << std::setw(2) << std::setfill('0')
dauncey's avatar
dauncey committed
28
	 << fBeSlinkSim->slinkNumber();
dauncey's avatar
dauncey committed
29 30 31
    
    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
32

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

    hThrottleActiveHistory=new TH1I((sout.str()+"ThrottleActiveHistory").c_str(),
				    ";BX;Throttle active",nHistory,0,nHistory);
    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
55 56 57
  }
  
  void analyseL1Accept(uint64_t bx) {
dauncey's avatar
dauncey committed
58 59
    if(fRaisedThrottleBx!=-1) hRaisedThrottleToL1Accept->Fill(bx-fRaisedThrottleBx);
    if(fEndedThrottleBx!=-1) hEndedThrottleToL1Accept->Fill(bx-fEndedThrottleBx);
dauncey's avatar
dauncey committed
60 61 62
  }
  
  void analyseBx(uint64_t bx) {
dauncey's avatar
dauncey committed
63 64 65 66 67 68
    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());
dauncey's avatar
dauncey committed
69
	if(fBeSlinkSim->exceededBuffer()) hEventBufferExceeded[e][b]->Fill(fBeSlinkSim->fEventBuffer[e][b].used());
dauncey's avatar
dauncey committed
70
      }
dauncey's avatar
dauncey committed
71
    }
72 73 74 75

    if(fBeSlinkSim->fL1AcceptEoe) {
      hTotalEventWords->Fill(16*fBeSlinkSim->fTotalNumberOfEventWords);
    }
dauncey's avatar
dauncey committed
76 77 78 79 80 81 82 83 84

    if(fBeSlinkSim->fThrottleActive) {
      if(!fPreviousThrottleActive) fRaisedThrottleBx=bx;
      hThrottleActiveHistory->Fill(bx);
    } else {
      if(fPreviousThrottleActive) fEndedThrottleBx=bx;
    }

    fPreviousThrottleActive=fBeSlinkSim->fThrottleActive;
dauncey's avatar
dauncey committed
85 86 87 88 89 90 91 92
  }
  
  void eoj() {
  }
  
private:
  const BeSlinkSim *fBeSlinkSim;

dauncey's avatar
dauncey committed
93 94 95
  bool fPreviousThrottleActive;
  uint64_t fRaisedThrottleBx;
  uint64_t fEndedThrottleBx;
dauncey's avatar
dauncey committed
96
  
97
  TH1D *hTotalEventWords;
dauncey's avatar
dauncey committed
98 99 100 101
  TH1I *hThrottleActiveHistory;
  TH1D *hRaisedThrottleToL1Accept;
  TH1D *hEndedThrottleToL1Accept;
  
dauncey's avatar
dauncey committed
102 103
  TH1D *hEventBufferUsed[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
  TH1I *hEventBufferUsedHistory[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
dauncey's avatar
dauncey committed
104
  TH1D *hEventBufferExceeded[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfBlocksPerEcon];
dauncey's avatar
dauncey committed
105 106 107
};

#endif