LpGbtCheck.hh 4.98 KB
Newer Older
dauncey's avatar
dauncey committed
1 2 3 4 5 6 7
#ifndef LpGbtCheck_HH
#define LpGbtCheck_HH

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

dauncey's avatar
dauncey committed
8 9
#include "BlockCheck.hh"

dauncey's avatar
dauncey committed
10 11
class LpGbtCheck {
public:
dauncey's avatar
dauncey committed
12 13 14 15 16
  LpGbtCheck() {
    for(unsigned block(0);block<7;block++) {
      fActivePacket[block]=false;
      fActiveHgcroc[block]=false;
    }
dauncey's avatar
dauncey committed
17 18
  }
  
dauncey's avatar
dauncey committed
19 20 21 22 23 24 25
  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;
    }
dauncey's avatar
dauncey committed
26 27
  }

dauncey's avatar
dauncey committed
28
  void initialise(unsigned s, unsigned e, const EconArch &a) {
dauncey's avatar
dauncey committed
29 30
    fSlink=s;
    fEcon=e;
dauncey's avatar
dauncey committed
31 32 33 34 35
    fEconArch=&a;

    for(unsigned b(0);b<fEconArch->fNumberOfBlocks;b++) {
      fBlockCheck[b].initialise(s,e,b,fEconArch->fHgcrocNumber[b]);
    }
dauncey's avatar
dauncey committed
36 37 38 39 40 41 42 43
  }
  
  bool processBx(uint32_t *a) {

    if(fPrintLevel>4) {
      std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon
		<< "]::processBx() "
		<< "Entered" << std::endl;
dauncey's avatar
dauncey committed
44 45 46
      for(unsigned e(0);e<7;e++) {
	std::cout << " Word " << e << " = " << std::hex
		  << a[e] << std::dec << std::endl;
dauncey's avatar
dauncey committed
47
      }
dauncey's avatar
dauncey committed
48
    }
dauncey's avatar
dauncey committed
49

dauncey's avatar
dauncey committed
50 51 52 53 54 55 56 57 58 59 60 61
    for(unsigned block(0);block<fEconArch->fNumberOfBlocks;block++) {
      for(unsigned ee(0);ee<fEconArch->fElinkNumber[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;
dauncey's avatar
dauncey committed
62 63
	}

dauncey's avatar
dauncey committed
64 65 66
	fBlockCheck[block].processBx(a[e]);
      }
    }
dauncey's avatar
dauncey committed
67

dauncey's avatar
dauncey committed
68 69 70 71 72 73 74 75 76 77 78 79
	  /*    
	if(!fActivePacket[block]) {
	  if(a[e]!=0) {
	    fActivePacket[block]=true;
	    fActiveHgcroc[block]=true;

	    for(unsigned h(0);h<fEconArch->fHgcrocNumber[block].size();h++) fHgcrocSeen[fEconArch->fHgcrocNumber[block][h]]=false;
	    fHgcroc=fEconArch->fHgcrocNumber[block][0];
	    checkHeader(a[e],true);
	    fBx=fHgcrocBoe.bx();
	    fWords[block]=1;
	    
dauncey's avatar
dauncey committed
80 81 82
	    if(fPrintLevel>4) {
	      std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon
			<< "]::processBx() "
dauncey's avatar
dauncey committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
			<< "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;
	      }
dauncey's avatar
dauncey committed
100 101 102 103
	    }
	  }
	  
	} else {
dauncey's avatar
dauncey committed
104 105 106 107 108 109 110 111
	  assert(a[e]!=0);

	  if(!fActiveHgcroc[block]) {
	    fHgcroc++;
	    checkHeader(a[e],false);
	    fActiveHgcroc[block]=true;
	    fWords[block]=1;
	    
dauncey's avatar
dauncey committed
112 113 114
	    if(fPrintLevel>4) {
	      std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon
			<< "]::processBx() "
dauncey's avatar
dauncey committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
			<< "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;
	      }
dauncey's avatar
dauncey committed
146 147 148
	    }
	  }
	  
dauncey's avatar
dauncey committed
149 150 151 152
	  bool allSeen(true);
	  for(unsigned h(0);h<fNumberOfHgcrocs && allSeen;h++) {
	    allSeen=fHgcrocSeen[h];
	  }
dauncey's avatar
dauncey committed
153

dauncey's avatar
dauncey committed
154 155 156 157 158 159 160 161
	  if(allSeen) {
	    fActivePacket[block]=false;
	    if(fPrintLevel>4) {
	      std::cout << "LpGbtCheck[" << fSlink << "][" << fEcon
			<< "]::processBx() "
			<< "Packet ended" << std::endl;
	    }
	    fL1Accept++;
dauncey's avatar
dauncey committed
162 163 164 165
	  }
	}
      }
    }
dauncey's avatar
dauncey committed
166
	  */    
dauncey's avatar
dauncey committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    return true;
  }

  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;
dauncey's avatar
dauncey committed
188 189 190
  BlockCheck fBlockCheck[7];


dauncey's avatar
dauncey committed
191
  //unsigned fNumberOfHgcrocs;
dauncey's avatar
dauncey committed
192
  unsigned fHgcroc;
dauncey's avatar
dauncey committed
193 194

  const EconArch *fEconArch;
dauncey's avatar
dauncey committed
195
  
dauncey's avatar
dauncey committed
196 197
  bool fActivePacket[7];
  bool fActiveHgcroc[7];
dauncey's avatar
dauncey committed
198 199 200 201

  uint8_t fL1Accept;
  uint8_t fBx;
  HgcrocBoe fHgcrocBoe;
dauncey's avatar
dauncey committed
202
  //unsigned fWords[7];
dauncey's avatar
dauncey committed
203 204 205 206 207 208
  bool fHgcrocSeen[18];
};

unsigned LpGbtCheck::fPrintLevel(1);

#endif