DaqDaqBuffer.cpp 26.7 KB
Newer Older
dauncey's avatar
dauncey committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#include "Hack.hh"

#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>

#include "TH1F.h"

#include "TFileHandler.hh"
#include "Random.hh"

dauncey's avatar
dauncey committed
14 15
typedef std::pair<uint64_t,uint64_t> uint128_t;

dauncey's avatar
dauncey committed
16 17 18 19 20 21 22 23 24 25 26
#include "Buffering/Dimensions.hh"

class SlinkElinkData {
public:
  SlinkElinkData() {
  }

  uint32_t fData[Dimensions::MaxNumberOfEconsPerSlink][Dimensions::MaxNumberOfElinksPerEcon];
};


dauncey's avatar
dauncey committed
27
#include "Buffering/CircularBufferUR.hh"
28
#include "Buffering/PartitionedBuffer.hh"
dauncey's avatar
dauncey committed
29 30 31 32 33
#include "Buffering/HgcrocSim.hh"
#include "Buffering/HgcrocAna.hh"
#include "Buffering/EconSim.hh"
#include "Buffering/EconAna.hh"
#include "Buffering/LpGbtCheck.hh"
dauncey's avatar
dauncey committed
34 35 36 37
#include "Buffering/BeSlinkSim.hh"
#include "Buffering/BeSlinkAna.hh"
#include "Buffering/SlinkArch.hh"
#include "Buffering/SlinkFile.hh"
dauncey's avatar
dauncey committed
38 39 40
#include "Buffering/SlinkBoe.hh"
#include "Buffering/SlinkEoe.hh"
#define DEBUG_PRINT if(false) std::cout << "Line " << __LINE__ << ": "
dauncey's avatar
dauncey committed
41
#include "Buffering/SlinkCheck.hh"
dauncey's avatar
dauncey committed
42
#include "Buffering/Throttle.hh"
dauncey's avatar
dauncey committed
43

dauncey's avatar
dauncey committed
44
#include "Buffering/interrupts.cc"
dauncey's avatar
dauncey committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

#ifndef TriggerRule_PrintLevel
#define TriggerRule_PrintLevel 10
#endif


class TriggerRule {
public:
  enum {
    TriggerLimit=8
  };

  TriggerRule(uint64_t n=43) : fNumberOfBx(n), fTriggers(0) {
    if(TriggerRule_PrintLevel>0) std::cout << "TriggerRule::ctor()  Initialised with trigger limit "
					   << TriggerLimit << " within " << fNumberOfBx << " BX"
					   << std::endl;
  }

  bool allowTrigger(uint64_t bx) {
    if(TriggerRule_PrintLevel>9) std::cout << std::endl
					   << "TriggerRule::allowTriggers()  fTriggers = " << fTriggers
					   << ", called with bx = " << bx << std::endl;

    if(fTriggers<TriggerLimit) {
      fTriggerBx[fTriggers]=bx;
      fTriggers++;

      if(TriggerRule_PrintLevel>9) std::cout << "TriggerRule::allowTriggers()  new fTriggers = " << fTriggers
					     << ", trigger allowed" << std::endl;
      return true;
    }

    if((bx-fTriggerBx[0])<fNumberOfBx) {
      if(TriggerRule_PrintLevel>9) std::cout << "TriggerRule::allowTriggers()  oldest BX = " << fTriggerBx[0]
					     << ", difference = " << bx-fTriggerBx[0]
					     << ", trigger not allowed" << std::endl;
      return false;
    }

    bool reject(true);
    unsigned nReject(0);
    for(;nReject<TriggerLimit && reject;) {
      reject=(bx-fTriggerBx[nReject])>=fNumberOfBx;
      if(reject) {
	if(TriggerRule_PrintLevel>9) std::cout << "TriggerRule::allowTriggers()  Trigger " << nReject << " BX = " << fTriggerBx[nReject]
					       << ", difference = " << bx-fTriggerBx[nReject]
					       << ", rejected" << std::endl;
	nReject++;
      }
    }

    if(TriggerRule_PrintLevel>9) std::cout << "TriggerRule::allowTriggers()  Number of triggers rejected = " << nReject << std::endl;
    
    fTriggers=TriggerLimit-nReject;
    for(unsigned i(0);i<fTriggers;i++) {
      if(TriggerRule_PrintLevel>9) std::cout << "TriggerRule::allowTriggers()  Trigger " << i+nReject << " BX = " << fTriggerBx[i+nReject]
					     << " moved to trigger " << i << std::endl;
      fTriggerBx[i]=fTriggerBx[i+nReject];
    }
    
    if(TriggerRule_PrintLevel>9) std::cout << "TriggerRule::allowTriggers()  new fTriggers = " << fTriggers
					   << ", trigger allowed" << std::endl;
    return true;
  }
  
private:
  const uint64_t fNumberOfBx;
  unsigned fTriggers;
  uint64_t fTriggerBx[TriggerLimit];
};
dauncey's avatar
dauncey committed
115 116


dauncey's avatar
dauncey committed
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
class BeReadState {
  enum {
    maxEcon=5,
    maxHgcroc=18
  };

public:
  BeReadState() {
    reset();
  }

  void reset() {
    fEcon=maxEcon;
    fHgcroc=0;
    fWord=0;
    fSentEoe=true;
    
    fNHgcroc[0]=18;
    fNHgcroc[1]=12;
    fNHgcroc[2]=9;
    fNHgcroc[3]=9;
    fNHgcroc[4]=9;
  }

  bool isActive() const {
    return fEcon<maxEcon;
  }
  
  void setActive() {
    fEcon=0;
    fHgcroc=0;
    fWord=0;
    fSentEoe=false;
  }
  
  unsigned econ() const {
    return fEcon;
  }
  
  unsigned hgcroc() const {
    return fHgcroc;
  }
  
  bool sentEoe() const {
    return fSentEoe;
  }
  
  void stepEoe() {
    fSentEoe=true;
  }
  
  void step(uint32_t w) {
    assert(isActive());

    if(fWord==0) {
      HgcrocBoe hboe(w);
      fNWord=hboe.numberOfWords();
    }

    fWord++;
    if(fWord==fNWord) {
      fWord=0;
      fHgcroc++;
      if(fHgcroc==fNHgcroc[fEcon]) {
	fHgcroc=0;
	fEcon++;
      }
    }
  }
  
  
private:
  unsigned fNHgcroc[maxEcon];
  unsigned fNWord;

  unsigned fEcon;
  unsigned fHgcroc;
  unsigned fWord;
  bool fSentEoe;
};



dauncey's avatar
dauncey committed
200 201
int main(int argc, char* argv[]) {

202
  // General
dauncey's avatar
dauncey committed
203 204 205
  unsigned printLevel(1);
  unsigned seconds(1);
  unsigned long rSeed(0);
206 207 208
  unsigned l1AcceptRate(750);
  unsigned l1AcceptRandom(1);

dauncey's avatar
dauncey committed
209 210
  bool doingEcon(true);
  bool doingBe(doingEcon && true);
211 212 213 214 215 216 217

  // HGCROC
  unsigned hgcrocLimit(7);
  unsigned hgcrocTransmission(44);

  // ECON
  unsigned block(1);
dauncey's avatar
dauncey committed
218 219 220
  unsigned econRandom(EconSim::Mixed);
  unsigned econFormat(EconSim::FixedChannelBitmap);
  unsigned econFlow(EconSim::FixedHgcrocMap);
221
  unsigned slinkNumber[Dimensions::MaxNumberOfSlinks];
dauncey's avatar
dauncey committed
222 223
  for(unsigned n(0);n<Dimensions::MaxNumberOfSlinks;n++) slinkNumber[n]=n;
  
224 225
  // BE

dauncey's avatar
dauncey committed
226 227
  unsigned beLimit(block==1?4000:1000);
  
dauncey's avatar
dauncey committed
228 229
  //if(argc>2 && (argc%2)!=1) {
  if(argc==1) {
dauncey's avatar
dauncey committed
230
    std::cerr << "Usage: " << argv[0] << " --<parameter> <value>  or  <parameter number>" << std::endl;
dauncey's avatar
dauncey committed
231 232
    return 1;
  }
dauncey's avatar
dauncey committed
233

dauncey's avatar
dauncey committed
234 235 236 237
  int initial(1);
  if((argc%2)==0) {
    initial=2;
    
dauncey's avatar
dauncey committed
238 239 240 241 242
    unsigned nArg(0);
    std::istringstream sArg(argv[1]);
    sArg >> nArg;
    //    nArg--;

dauncey's avatar
dauncey committed
243 244
    std::cout << nArg << std::endl;
    
dauncey's avatar
dauncey committed
245
    l1AcceptRate=550+50*(nArg%10);
dauncey's avatar
dauncey committed
246

dauncey's avatar
dauncey committed
247 248 249 250
    nArg/=10;
    hgcrocLimit=(nArg%10);
    nArg/=10;
    hgcrocTransmission=40+2*(nArg%10);
dauncey's avatar
dauncey committed
251 252 253 254 255 256 257 258

    nArg/=10;
    block=(nArg%10);
    nArg/=10;
    econRandom=(nArg%10);

    nArg/=10;
    beLimit=500*(nArg%10);
dauncey's avatar
dauncey committed
259 260 261 262 263
  }
  
  for(int i(initial);i<argc;i+=2) {
    std::string sarg1(argv[i]);
    std::istringstream sarg2(argv[i+1]);
dauncey's avatar
dauncey committed
264
    
dauncey's avatar
dauncey committed
265 266 267 268 269
    if(sarg1=="--printLevel") sarg2 >> printLevel;
    if(sarg1=="--seed") sarg2 >> rSeed;
    if(sarg1=="--seconds") sarg2 >> seconds;
    if(sarg1=="--l1AcceptRate") sarg2 >> l1AcceptRate;
    if(sarg1=="--l1AcceptRandom") sarg2 >> l1AcceptRandom;
dauncey's avatar
dauncey committed
270
    
dauncey's avatar
dauncey committed
271 272 273 274 275 276 277 278 279
    if(sarg1=="--hgcrocLimit") sarg2 >> hgcrocLimit;
    if(sarg1=="--hgcrocTransmission") sarg2 >> hgcrocTransmission;
    
    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;
dauncey's avatar
dauncey committed
280 281 282

    if(sarg1=="--beLimit") sarg2 >> beLimit;
}
dauncey's avatar
dauncey committed
283 284
  
  std::ostringstream sout;
285 286 287
  sout << "_L1AcceptRate" << l1AcceptRate;
  sout << "_L1AcceptRandom" << l1AcceptRandom;

dauncey's avatar
dauncey committed
288
  sout << "_HgcrocLimit" << hgcrocLimit;
289
  sout << "_HgcrocTransmission" << hgcrocTransmission;
dauncey's avatar
dauncey committed
290 291 292 293 294 295 296 297

  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);

298
    if(doingBe) {
dauncey's avatar
dauncey committed
299
      sout << "_BeLimit" << beLimit;
300
    }
dauncey's avatar
dauncey committed
301 302 303
  }

  sout << "_Seconds" << seconds;
dauncey's avatar
dauncey committed
304

dauncey's avatar
dauncey committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
  std::string sName("DaqDaqBuffer/DaqDaqBuffer");

  if(!doingEcon) sName+="_HgcrocOnly";
  else if(!doingBe) sName+="_HgcrocAndEcon";
  else sName+="_FullChain";

  sName+=sout.str();

  //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);
dauncey's avatar
dauncey committed
321
  
dauncey's avatar
dauncey committed
322 323 324 325 326 327 328 329
  EconSim::fDataFlowMethod=EconSim::EventBuild;

  HgcrocSim::fPrintLevel=printLevel;
  EconSim::fPrintLevel=printLevel;
  BlockCheck::fPrintLevel=printLevel;
  LpGbtCheck::fPrintLevel=printLevel;
  BeSlinkSim::fPrintLevel=printLevel;
  SlinkCheck::fPrintLevel=printLevel;
dauncey's avatar
dauncey committed
330

dauncey's avatar
dauncey committed
331 332 333
  const unsigned NumberOfSlinks(1);
  assert(NumberOfSlinks<=Dimensions::MaxNumberOfSlinks);
  
dauncey's avatar
dauncey committed
334 335
  assert(sizeof(SlinkBoe)==16);
  assert(sizeof(SlinkEoe)==16);
dauncey's avatar
dauncey committed
336
  assert(sizeof(uint128_t)==16);
dauncey's avatar
dauncey committed
337 338

  Random random;
dauncey's avatar
dauncey committed
339 340
  random.random().SetSeed(rSeed);

dauncey's avatar
dauncey committed
341 342 343
  CircularBufferUR<1> cbBoe;
  CircularBufferUR<1> cb;
  CircularBufferUR<1> cbFinal;
dauncey's avatar
dauncey committed
344 345
  PartitionedBuffer<18,4> pb[5];

dauncey's avatar
dauncey committed
346
  BeReadState brs;
dauncey's avatar
dauncey committed
347 348 349 350
  
  uint64_t d;


dauncey's avatar
dauncey committed
351 352 353
  unsigned nHWords(0);


dauncey's avatar
dauncey committed
354 355
  uint32_t array[5][2][7];
  unsigned nArray[5][7];
dauncey's avatar
dauncey committed
356 357
  //uint32_t hArray[5][7];
  HgcrocBoe hArray[5][7];
dauncey's avatar
dauncey committed
358 359 360
  UltraRam ur[7];
  unsigned hActive[5][18];
  bool completeEvent[5][18][256];
dauncey's avatar
dauncey committed
361 362
  bool doneEvent[5][18][256];
  unsigned nHgcrocWords=-1;
dauncey's avatar
dauncey committed
363 364 365 366
  
  unsigned readL1A=0;
  unsigned readEcon=0;
  unsigned readHgcroc=0;
dauncey's avatar
dauncey committed
367
  unsigned readState=5*18;
dauncey's avatar
dauncey committed
368 369 370 371 372 373 374 375 376 377 378
  
  for(unsigned ec(0);ec<5;ec++) {
    for(unsigned e(0);e<7;e++) {
      array[ec][0][e]=-1;
      array[ec][1][e]=-1;
      nArray[ec][e]=-1;
    }
    for(unsigned h(0);h<18;h++) {
      hActive[ec][h]=-1;
      for(unsigned i(0);i<256;i++) {
	completeEvent[ec][h][i]=false;
dauncey's avatar
dauncey committed
379
	doneEvent[ec][h][i]=true;
dauncey's avatar
dauncey committed
380 381 382 383
      }
    }
  }
  
dauncey's avatar
dauncey committed
384

dauncey's avatar
dauncey committed
385 386 387
  TFileHandler tfh(sName);

  
dauncey's avatar
dauncey committed
388
  unsigned nHistory(10000);
dauncey's avatar
dauncey committed
389
  
dauncey's avatar
dauncey committed
390 391 392 393 394
  HgcrocSim hgcrocSim;
  HgcrocAna hgcrocAna;
  
  SlinkFile slinkFile[NumberOfSlinks];
  SlinkArch slinkArch[NumberOfSlinks];
dauncey's avatar
dauncey committed
395

dauncey's avatar
dauncey committed
396
  SlinkElinkData slinkElinkData[NumberOfSlinks];
dauncey's avatar
dauncey committed
397
  
dauncey's avatar
dauncey committed
398 399 400
  EconSim econSim[NumberOfSlinks][Dimensions::MaxNumberOfEconsPerSlink];
  EconAna econAna[NumberOfSlinks][Dimensions::MaxNumberOfEconsPerSlink];
  LpGbtCheck lpGbtCheck[NumberOfSlinks][Dimensions::MaxNumberOfEconsPerSlink];
dauncey's avatar
dauncey committed
401
  
dauncey's avatar
dauncey committed
402 403 404 405 406 407 408 409 410 411
  BeSlinkSim beSlinkSim[NumberOfSlinks];
  BeSlinkAna beSlinkAna[NumberOfSlinks];
  SlinkCheck slinkCheck[NumberOfSlinks];







dauncey's avatar
dauncey committed
412 413 414 415 416 417
  double totalLinkWords(0.0);

  unsigned nEventWords(0);

  std::string sNum[7]={"0","1","2","3","4","5","6"};

dauncey's avatar
dauncey committed
418

dauncey's avatar
dauncey committed
419 420 421 422


  // Initialisation
  
423
  hgcrocSim.boj(hgcrocLimit,hgcrocTransmission);
dauncey's avatar
dauncey committed
424 425
  hgcrocAna.boj(hgcrocSim,nHistory);
  
dauncey's avatar
dauncey committed
426 427
  if(doingEcon) {
    for(unsigned sl(0);sl<NumberOfSlinks;sl++) {
dauncey's avatar
dauncey committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
      slinkFile[sl].slinkNumber(sl);
      
      std::ostringstream soutFile;
      soutFile << "Slink" << std::setw(2) << std::setfill('0') << slinkNumber[sl] << ".txt";
      assert(slinkFile[sl].read(soutFile.str()));
      
      slinkArch[sl].initialise(&(slinkFile[sl]),block==1);
      slinkArch[sl].print();
      
      for(unsigned ec(0);ec<slinkArch[sl].numberOfEcons();ec++) {
	//econSim[sl][ec].slinkNumber(sl);
	//econSim[sl][ec].econNumber(ec);
	//econSim[sl][ec].econFile(&(slinkFile[sl].econFile(ec)));
	econSim[sl][ec].boj(sl,ec,slinkFile[sl].econFile(ec),slinkArch[sl].econArch(ec));
	econAna[sl][ec].boj(econSim[sl][ec],nHistory);
dauncey's avatar
dauncey committed
443
	
dauncey's avatar
dauncey committed
444 445 446 447
	lpGbtCheck[sl][ec].initialise(sl,ec,econSim[sl][ec].econArch());
      }
  
      if(doingBe) {
dauncey's avatar
dauncey committed
448
	beSlinkSim[sl].boj(slinkArch[sl],beLimit);
dauncey's avatar
dauncey committed
449
	beSlinkAna[sl].boj(beSlinkSim[sl],nHistory);
dauncey's avatar
dauncey committed
450
	
dauncey's avatar
dauncey committed
451
	slinkCheck[sl].boj(slinkArch[sl]);
dauncey's avatar
dauncey committed
452 453
      }
    }
dauncey's avatar
dauncey committed
454
  }
dauncey's avatar
dauncey committed
455

dauncey's avatar
dauncey committed
456 457 458 459 460
  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);

dauncey's avatar
dauncey committed
461 462 463 464 465 466 467 468
  TH1D *hCounts=new TH1D("MainCounts",";Counts",
			 10,0,10);




  //TH1D *hEconSpace[5][7];
  //TH1F *hEconSpaceHistory[5][7];
dauncey's avatar
dauncey committed
469 470 471
  TH1D *hSboeSpace;
  TH1F *hSboeSpaceHistory;
  TH1D *hSpace[5][18];
dauncey's avatar
dauncey committed
472 473 474 475
  TH1F *hSpaceHistory[5][18];
  std::string sHgcroc[18]={"00","01","02","03","04","05","06","07","08","09",
			   "10","11","12","13","14","15","16","17"};

476
  /*
dauncey's avatar
dauncey committed
477 478
  for(unsigned ec(0);ec<5;ec++) {
    for(unsigned e(0);e<7;e++) {
dauncey's avatar
dauncey committed
479 480 481 482
      //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);
dauncey's avatar
dauncey committed
483 484
    }
    for(unsigned h(0);h<18;h++) {
dauncey's avatar
dauncey committed
485 486
      hSpace[ec][h]=new TH1D((std::string("BeEcon")+sNum[ec]+"Hgcroc"+sHgcroc[h]+"Space").c_str(),
			     ";Partitioned buffer space",1000,0,1000);
dauncey's avatar
dauncey committed
487
      hSpaceHistory[ec][h]=new TH1F((std::string("BeEcon")+sNum[ec]+"Hgcroc"+sHgcroc[h]+"SpaceHistory").c_str(),
dauncey's avatar
dauncey committed
488
				    ";BX;Partitioned buffer space",nHistory,0,nHistory);
dauncey's avatar
dauncey committed
489 490 491
    }
  }

dauncey's avatar
dauncey committed
492 493 494 495
  hSboeSpace=new TH1D((std::string("Sboe")+"Space").c_str(),
		      ";BOE buffer space",4096,0,4096);
  hSboeSpaceHistory=new TH1F((std::string("Sboe")+"SpaceHistory").c_str(),
			     ";BX;BOE buffer space",nHistory,0,nHistory);
496
  */
dauncey's avatar
dauncey committed
497
  
dauncey's avatar
dauncey committed
498
  int64_t runSec(seconds);
dauncey's avatar
dauncey committed
499
  //int64_t runSec(-10000); // for 0.0001 run secs
dauncey's avatar
dauncey committed
500
  //runSec=-1000; // for 0.001 run secs
dauncey's avatar
dauncey committed
501
  //int64_t runSec(-100); // for 0.01 run secs
dauncey's avatar
dauncey committed
502
  //runSec=-10; // for 0.1 run secs
dauncey's avatar
dauncey committed
503 504
  //int64_t runSec(1); // for 1 run secs
  //int64_t runSec(10); // for 10 run secs
dauncey's avatar
dauncey committed
505
  //int64_t runSec(100); // ~4 mins for 100 run secs
dauncey's avatar
dauncey committed
506 507 508 509
  //int64_t runSec(1000); // ~40 mins for 1000 run secs
  //int64_t runSec(10000); // ~6 hours for 10000 run secs

  uint64_t bxPerSec(40000000);
dauncey's avatar
dauncey committed
510
  double runSecs(runSec>=0?runSec:-1.0/runSec);
dauncey's avatar
dauncey committed
511 512 513 514 515 516 517 518
  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);
  unsigned worstL1A(0);
  unsigned worstPower(1);
dauncey's avatar
dauncey committed
519
  uint64_t numberL1AIn(0);
dauncey's avatar
dauncey committed
520
  uint64_t numberL1AOut(0);
dauncey's avatar
dauncey committed
521 522

  uint64_t nHgcrocDeadtime(0);
dauncey's avatar
dauncey committed
523 524 525 526
  uint64_t nEconThrottleDeadtime(0);
  uint64_t nEconExceeded(0);
  uint64_t nBeThrottleDeadtime(0);
  uint64_t nBeExceeded(0);
dauncey's avatar
dauncey committed
527 528

  //TriggerRule tr(50);
dauncey's avatar
dauncey committed
529

dauncey's avatar
dauncey committed
530 531
  std::vector<Throttle> vEconThrottle;
  std::vector<Throttle> vBeThrottle;
dauncey's avatar
dauncey committed
532
  catchSignals();
dauncey's avatar
dauncey committed
533
  
dauncey's avatar
dauncey committed
534 535
  uint64_t bx;
  for(bx=0;bx<maxBx && continueJob;bx++) {
dauncey's avatar
dauncey committed
536 537
    if(((100*bx)%maxBx)==0) std::cout << "BX " << bx << " = " << 100*bx/maxBx << " %" << std::endl;

dauncey's avatar
dauncey committed
538 539 540 541 542
    //if(bx>100000) {
    //BeSlinkSim::fPrintLevel=6;
    //SlinkCheck::fPrintLevel=6;
    //}
    
dauncey's avatar
dauncey committed
543 544 545 546 547 548 549
    ////////////////////////////////////////////////////////////
    //
    // L1A and HGCROC
    //
    ////////////////////////////////////////////////////////////

    bool newL1AIn(false);
dauncey's avatar
dauncey committed
550 551
    bool newL1AOut(false);

dauncey's avatar
dauncey committed
552 553 554 555 556 557 558 559
    bool econAllowL1a(true);
    for(unsigned t(0);t<vEconThrottle.size() && econAllowL1a;t++) {
      econAllowL1a=vEconThrottle[t].allowL1Accept(bx);
    }

    bool beAllowL1a(true);
    for(unsigned t(0);t<vBeThrottle.size() && beAllowL1a;t++) {
      beAllowL1a=vBeThrottle[t].allowL1Accept(bx);
dauncey's avatar
dauncey committed
560 561
    }
    
dauncey's avatar
dauncey committed
562 563
    if(!hgcrocSim.allowL1Accept()) {
      nHgcrocDeadtime++;
564

dauncey's avatar
dauncey committed
565 566 567 568 569
    } else if(!econAllowL1a) {
      nEconThrottleDeadtime++;      

    } else if(!beAllowL1a) {
      nBeThrottleDeadtime++;
dauncey's avatar
dauncey committed
570
      
dauncey's avatar
dauncey committed
571
    } else {
572
      if(l1AcceptRandom!=0) newL1AIn=(random.random().Uniform()<(l1AcceptRate/40000.0));
dauncey's avatar
dauncey committed
573
      else newL1AIn=((bx%53)==0);
dauncey's avatar
dauncey committed
574
    }
dauncey's avatar
dauncey committed
575 576 577
    
    /*
      if(worstL1A<nL1A) {
dauncey's avatar
dauncey committed
578 579 580 581
      worstL1A=nL1A;
      std::cout << "New worst case = " << worstL1A << std::endl;
      }
    */
dauncey's avatar
dauncey committed
582 583
    /*
      if(bx==worstPower*(bxPerSec/100000)-1) {
dauncey's avatar
dauncey committed
584 585 586
      std::cout << "Worst plotting for BX = " << bx << std::endl;
      hWorst->Fill(log10(worstPower)-5.0,worstL1A);
      worstPower*=10;
dauncey's avatar
dauncey committed
587
      }
dauncey's avatar
dauncey committed
588
    */
dauncey's avatar
dauncey committed
589 590 591 592 593 594 595 596 597

    newL1AOut=hgcrocSim.processBx(newL1AIn);
    hgcrocAna.analyseBx(bx);

    ////////////////////////////////////////////////////////////
    //
    // ECON
    //
    ////////////////////////////////////////////////////////////
dauncey's avatar
dauncey committed
598
    
dauncey's avatar
dauncey committed
599
    if(doingEcon) {
dauncey's avatar
dauncey committed
600 601
      bool anyExceeded(false);

dauncey's avatar
dauncey committed
602 603 604
      for(unsigned sl(0);sl<NumberOfSlinks;sl++) {
	for(unsigned ec(0);ec<5;ec++) {
	  if(newL1AOut) {
dauncey's avatar
dauncey committed
605
	    econSim[sl][ec].processZs(bx,numberL1AOut);
dauncey's avatar
dauncey committed
606
	    econAna[sl][ec].analyseZs(bx);
dauncey's avatar
dauncey committed
607
	  }
dauncey's avatar
dauncey committed
608

dauncey's avatar
dauncey committed
609
	  econSim[sl][ec].processBx(slinkElinkData[sl].fData[ec]);
dauncey's avatar
dauncey committed
610 611
	  if(econSim[sl][ec].exceededBuffer()) anyExceeded=true;

dauncey's avatar
dauncey committed
612
	  econAna[sl][ec].analyseBx(bx);
dauncey's avatar
dauncey committed
613 614

	  if(!doingBe) {
dauncey's avatar
dauncey committed
615
	    lpGbtCheck[sl][ec].processBx(slinkElinkData[sl].fData[ec]);
dauncey's avatar
dauncey committed
616
	  }
dauncey's avatar
dauncey committed
617
	}	
dauncey's avatar
dauncey committed
618
      }
dauncey's avatar
dauncey committed
619
      
dauncey's avatar
dauncey committed
620 621
      if(anyExceeded) nEconExceeded++;
      
dauncey's avatar
dauncey committed
622 623 624 625 626 627 628
      ////////////////////////////////////////////////////////////
      //
      // BE
      //
      ////////////////////////////////////////////////////////////

      if(doingBe) {
dauncey's avatar
dauncey committed
629 630
	bool anyExceeded(false);
	
dauncey's avatar
dauncey committed
631 632 633 634 635 636
	for(unsigned sl(0);sl<NumberOfSlinks;sl++) {
	  if(newL1AIn) {
	    beSlinkSim[sl].processL1Accept(bx,numberL1AIn);
	    beSlinkAna[sl].analyseL1Accept(bx);
	  }
	    
dauncey's avatar
dauncey committed
637
	  beSlinkSim[sl].processBx(bx,slinkElinkData[sl]);
dauncey's avatar
dauncey committed
638

dauncey's avatar
dauncey committed
639 640 641 642 643
	  if(beSlinkSim[sl].throttle()) vBeThrottle.push_back(Throttle(bx));
	  if(beSlinkSim[sl].unThrottle()) {
	    assert(vBeThrottle.size()>0);
	    vBeThrottle[vBeThrottle.size()-1].endThrottle(bx);
	    //vBeThrottle[vBeThrottle.size()-1].print();
dauncey's avatar
dauncey committed
644 645
	  }

dauncey's avatar
dauncey committed
646 647
	  if(beSlinkSim[sl].exceededBuffer()) anyExceeded=true;
	  
dauncey's avatar
dauncey committed
648 649 650 651 652 653 654 655
	  beSlinkAna[sl].analyseBx(bx);

	  for(unsigned w(0);w<beSlinkSim[sl].numberOfSlinkWords();w++) {
	    slinkCheck[sl].processWord(beSlinkSim[sl].slinkWord(w).first,
				       beSlinkSim[sl].slinkWord(w).second);
	  }
	}
      
dauncey's avatar
dauncey committed
656 657
	if(anyExceeded) nBeExceeded++;

dauncey's avatar
dauncey committed
658 659
#ifdef NOT_YET
      
dauncey's avatar
dauncey committed
660 661 662 663 664 665 666 667 668 669 670 671 672
	if(newL1AIn) {
	  uint64_t d[2];
	  SlinkBoe sboe(0xce00,bx&0xffffffff,numberL1AIn&0xffffffff,0xab);
	  sboe.words(d);
	  assert(cbBoe.writeAndIncrementPtr(d[0]));
	  assert(cbBoe.writeAndIncrementPtr(d[1]));

	  hSboeSpace->Fill(cbBoe.space());
	  hSboeSpaceHistory->Fill(bx,cbBoe.space());

	  DEBUG_PRINT << " L1A = " << numberL1AIn << ", write Slink BOE 0x" << std::hex << d[1] << " " << d[0] << std::dec << std::endl;
	  //sboe.print();
	}
dauncey's avatar
dauncey committed
673

dauncey's avatar
dauncey committed
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695


	for(unsigned ec(0);ec<5;ec++) {
	  /*
	    std::cout << "Array "
	    << array[ec][bx%2][0] << ", "
	    << array[ec][bx%2][1] << ", "
	    << array[ec][bx%2][2] << ", "
	    << array[ec][bx%2][3] << ", "
	    << array[ec][bx%2][4] << ", "
	    << array[ec][bx%2][5] << ", "
	    << array[ec][bx%2][6] << std::endl;
	  */
	  for(unsigned e(0);e<7;e++) {
	    if(nArray[ec][e]==0xffffffff) {
	      if(array[ec][bx%2][e]!=0) {
		hArray[ec][e].word(array[ec][bx%2][e]);
		//unsigned hgcroc((hArray[ec][e]&0xff0000)>>16);
		unsigned hgcroc(hArray[ec][e].hgcroc());
		assert(hgcroc<18);
		assert((hgcroc%7)==e);
		hActive[ec][hgcroc]=e;
dauncey's avatar
dauncey committed
696
	    
dauncey's avatar
dauncey committed
697 698 699
		//ur[e].write(0,array[ec][bx%2][e]);
		nArray[ec][e]=1;
	      }
dauncey's avatar
dauncey committed
700
	  
dauncey's avatar
dauncey committed
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
	    } else {
	      //if(nArray[ec][e]<(hArray[ec][e]&0xff)) {
	      if(nArray[ec][e]<(hArray[ec][e].numberOfWords())) {
		//ur[e].write(nArray[ec][e],array[ec][bx%2][e]);
		nArray[ec][e]++;
		if((nArray[ec][e]%2)==0) {
		  //unsigned hgcroc((hArray[ec][e]&0xff0000)>>16);
		  unsigned hgcroc(hArray[ec][e].hgcroc());
		  //uint64_t d(array[ec][hActive[hgcroc]][bx%2]);
		  uint64_t d(array[ec][bx%2][e]);
		  d=d<<32;
		  //d+=array[ec][hActive[hgcroc]][(bx+1)%2];
		  d+=array[ec][(bx+1)%2][e];
		  //uint64_t d((((unsigned long)array[ec][hActive[hgcroc]][bx%2])<<32)+array[ec][hActive[hgcroc]][(l+1)%2]);
		  //std::cout << "Writing to HGCROC " << hgcroc << " = " << std::hex << d << std::dec << std::endl;

		  //HgcrocBoe hBoe(readL1A&0xff,hgcroc&0xff,(numberL1AOut-1)&0xff,0);

		  assert(pb[ec].writeAndIncrementPtr(hgcroc,d));
		  //pb[ec].writeAndIncrementPtr(hgcroc,d);
		}
dauncey's avatar
dauncey committed
722
	    
dauncey's avatar
dauncey committed
723 724 725 726 727 728 729 730 731 732
		//if(nArray[ec][e]==(hArray[ec][e]&0xff)) {
		if(nArray[ec][e]==(hArray[ec][e].numberOfWords())) {
		  /*
		    std::cout << std::endl << "Elink " << e << ", print event for BX "
		    << ((hArray[ec][e]&0xff000000)>>24) << ", HGCROC "
		    << ((hArray[ec][e]&0xff0000)>>16) << ", length " << (hArray[ec][e]&0xffff) << std::endl;
		    for(unsigned i(0);i<(hArray[ec][e]&0xffff);i++) {
		    std::cout << "Word " << i << " = " << ur[e].read(i)
		    << " = 0x" << std::hex << ur[e].read(i) << std::dec
		    << std::endl;
dauncey's avatar
dauncey committed
733
		
dauncey's avatar
dauncey committed
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
		    if(i==0) assert(hArray[ec][e]==ur[e].read(i));
		    else     assert(i        ==ur[e].read(i));
		    }
		  */

		  if((nArray[ec][e]%2)==1) {
		    //unsigned hgcroc((hArray[ec][e]&0xff0000)>>16);
		    unsigned hgcroc(hArray[ec][e].hgcroc());
		    uint64_t d(array[ec][bx%2][e]);
		    //std::cout << "Writing to HGCROC " << hgcroc << " = " << std::hex << d << std::dec << std::endl;

		    assert(pb[ec].writeAndIncrementPtr(hgcroc,d));
		    //pb[ec].writeAndIncrementPtr(hgcroc,d);
		  }

		  //unsigned hgcroc((hArray[ec][e]&0xff0000)>>16);
		  unsigned hgcroc(hArray[ec][e].hgcroc());
		  //completeEvent[ec][hgcroc][(hArray[ec][e]&0xff00)>>8]=true;
		  completeEvent[ec][hgcroc][hArray[ec][e].l1a()]=true;
		  //doneEvent[ec][hgcroc][(hArray[ec][e]&0xff00)>>8]=false;
		  doneEvent[ec][hgcroc][hArray[ec][e].l1a()]=false;

		  nArray[ec][e]=0xffffffff;
		  hActive[ec][hgcroc]=0xffffffff;
		}
	      }
	    }
	  }
	}

	unsigned ecMin,hMin,spaceMin(0xffffffff);
    
	for(unsigned ec(0);ec<5;ec++) {
	  for(unsigned h(0);h<18;h++) {
	    hSpace[ec][h]->Fill(pb[ec].space(h));
	    hSpaceHistory[ec][h]->Fill(bx,pb[ec].space(h));

	    if(spaceMin>pb[ec].space(h)) {
	      spaceMin=pb[ec].space(h);
	      ecMin=ec;
	      hMin=h;
	    }
	  }
	}
    
	// Readout 
	uint64_t d[2];
	uint32_t dh[10];
	/*
	  std::cout << "Complete event list";
	  for(unsigned ec(0);ec<5;ec++) {
	  std::cout << " ";
	  for(unsigned h(0);h<18;h++) {
	  std::cout << (completeEvent[ec][h][readL1A&0xff]?1:0);
	  }
	  }
	  std::cout << std::endl;
	*/

dauncey's avatar
dauncey committed
793 794 795
#endif
	
#ifdef NOT_YET
dauncey's avatar
dauncey committed
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832





	unsigned nBxWords(0);
	bool completeAllEvent(true);

	//std::cout << "Line " << __LINE__ << ", BX " << bx << ": starting BE readout, readEcon = "
	DEBUG_PRINT << " BX " << bx << ": starting BE readout, readEcon = "
		    << brs.econ() << " readHgcroc = " << brs.hgcroc() << " nHgcrocWords = "
		    << nHgcrocWords << " completeEvent = "
		    << (completeEvent[brs.econ()][brs.hgcroc()][readL1A&0xff]?"true":"false") << std::endl;

	while(nBxWords<6) {
    
	  // Check if inactive
	  if(!brs.isActive()) {

	    // Check for sent EOE
	    DEBUG_PRINT << " inactive, checking for EOE" << std::endl;

	    if(!brs.sentEoe()) {
	      if(nHWords>0) {
		d[0]=dh[1];
		d[0]=(d[0]<<32)+dh[0];
		d[1]=dh[3];
		d[1]=(d[1]<<32)+dh[2];
		slinkCheck.processWords(d);
		nEventWords++;
		nBxWords+=2;
	      
		nHWords=0;
		dh[0]=0;
		dh[1]=0;
		dh[2]=0;
		dh[3]=0;
dauncey's avatar
dauncey committed
833
	      }
dauncey's avatar
dauncey committed
834 835 836 837 838 839 840 841 842
	    
	      SlinkEoe seoe(0xce00,0x77,0xff,nEventWords);
	    
	      seoe.words(d);
	    
	      DEBUG_PRINT << " make Slink EOE 0x" << std::hex << d[1] << " " << d[0] << std::dec << std::endl;
	    
	      slinkCheck.processWords(d);
	      nBxWords+=2;
dauncey's avatar
dauncey committed
843

dauncey's avatar
dauncey committed
844 845 846 847 848 849 850 851 852 853 854
	      brs.stepEoe();
	  
	    } else {
	  
	      // Check if L1A to be processed
	      DEBUG_PRINT << " inactive, checking for L1A" << std::endl;
	  
	      if(cbBoe.readAndIncrementPtr(d[0])) {
		assert(cbBoe.readAndIncrementPtr(d[1]));
	    
		DEBUG_PRINT << " read Slink BOE 0x" << std::hex << d[1] << " " << d[0] << std::dec << std::endl;
dauncey's avatar
dauncey committed
855

dauncey's avatar
dauncey committed
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
		readL1A++;
		nEventWords=0;
	    
		slinkCheck.processWords(d);
		nBxWords+=2;
		brs.setActive();
	    
		DEBUG_PRINT << " nBxWords = " << nBxWords << std::endl;
	  
	      } else {
		// No L1A so skip rest of BX
		nBxWords=999;
	    
		DEBUG_PRINT << " no Slink BOE read, nBxWords = " << nBxWords << std::endl;
	      }
	    }
	  }
      
	  // Check if active
	  if(brs.isActive() && nBxWords<6) {
	    unsigned e(brs.econ());
	    unsigned h(brs.hgcroc());
	    DEBUG_PRINT << " active, readState e, h = " << e << "," << h << std::endl;

	    // Check if waiting for HGCROC data
	    if(!completeEvent[e][h][readL1A&0xff]) {
	      DEBUG_PRINT << " HGCROC event data not complete" << std::endl;
	      nBxWords=999;

	    } else {
	      // Data to read
	      uint64_t dw;
	      assert(pb[e].readAndIncrementPtr(h,dw));

	      DEBUG_PRINT << " read buffer, word = 0x" << std::hex << dw << " = " << std::dec << dw << std::endl;

	      dh[nHWords]=dw&0xffffffff;
	      brs.step(dh[nHWords]);
	      DEBUG_PRINT << " nHWords = " << nHWords << ", saved HGCROC word = 0x" << std::hex << dh[nHWords] << " = " << std::dec << dh[nHWords] << std::endl;

	      nHWords++;
	      if(nHWords==4) {
		d[0]=dh[1];
		d[0]=(d[0]<<32)+dh[0];
		d[1]=dh[3];
		d[1]=(d[1]<<32)+dh[2];
		slinkCheck.processWords(d);
		nEventWords++;
		nBxWords+=2;

		nHWords=0;
		dh[0]=0;
		dh[1]=0;
		dh[2]=0;
		dh[3]=0;
	      }
	  
	      // If target unchanged 
	      if(brs.econ()==e && brs.hgcroc()==h) {
		dh[nHWords]=dw>>32;
		brs.step(dh[nHWords]);
		DEBUG_PRINT << " nHWords = " << nHWords << ", saved HGCROC word = 0x" << std::hex << dh[nHWords] << " = " << std::dec << dh[nHWords] << std::endl;

		nHWords++;
		if(nHWords==4) {
		  d[0]=dh[1];
		  d[0]=(d[0]<<32)+dh[0];
		  d[1]=dh[3];
		  d[1]=(d[1]<<32)+dh[2];
		  slinkCheck.processWords(d);
		  nEventWords++;
		  nBxWords+=2;

		  nHWords=0;
		  dh[0]=0;
		  dh[1]=0;
		  dh[2]=0;
		  dh[3]=0;
		}
dauncey's avatar
dauncey committed
935 936
	      }

dauncey's avatar
dauncey committed
937
	      DEBUG_PRINT << " checking for event finished, isActive = " << (brs.isActive()?"true":"false") << ", nBxWords = " << nBxWords << std::endl;
dauncey's avatar
dauncey committed
938

dauncey's avatar
dauncey committed
939 940
	      if(!brs.isActive() && nBxWords<6) {
	      }
dauncey's avatar
dauncey committed
941 942 943 944 945
	    }
	  }
	}


dauncey's avatar
dauncey committed
946 947 948 949 950 951 952 953 954









dauncey's avatar
dauncey committed
955 956

    
dauncey's avatar
dauncey committed
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
	for(;readEcon<5 && nBxWords<6;) {
	  for(;readHgcroc<18 && nBxWords<6;) {
	    if(completeEvent[readEcon][readHgcroc][readL1A&0xff]) {
	      if(nHgcrocWords==-1) {
		if(cbBoe.readAndIncrementPtr(d[0])) {
		  assert(cbBoe.readAndIncrementPtr(d[1]));
		  slinkCheck.processWords(d);
		  nBxWords+=2;
		} else nBxWords=6;
	      }

	      if(nBxWords<6) {
		pb[readEcon].readAndIncrementPtr(readHgcroc,d[nBxWords%2]);
		if(nHgcrocWords==-1) {
		  nHgcrocWords=(d[nBxWords%2]&0xffff);
		}
		nBxWords++;
		nHgcrocWord++;
dauncey's avatar
dauncey committed
975
	    
dauncey's avatar
dauncey committed
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
		if(nHgcrocWord==nHgcrocWords) {
		  completeEvent[readEcon][readHgcroc][readL1A&0xff]=false;
		  doneEvent[readEcon][readHgcroc][readL1A&0xff]=true;
		  nHgcrocWords=-1;

		  readHgcroc++;
		  if(readHgcroc>=18) {
		    readHgcroc=0;
		    readEcon++;
		  }
		  if(readEcon>=5) {
		    readL1A++;
		    readEcon=0;
		  }

		  if((nBxWords%2)==1) {
		    d[1]=0;
		    nBxWords++;
		  }
		}
dauncey's avatar
dauncey committed
996
	    
dauncey's avatar
dauncey committed
997 998 999 1000 1001
		if((nBxWords%2)==0) 	      slinkCheck.processWords(d);
	    
	      }
	    } else {
	      nBxWords=6;
dauncey's avatar
dauncey committed
1002 1003 1004 1005 1006
	    }
	  }
	}
    
#endif
dauncey's avatar
dauncey committed
1007 1008 1009 1010 1011
    
      } // End of doingBe   
    } // End of doingEcon

    // Increment some counters
dauncey's avatar
dauncey committed
1012

dauncey's avatar
dauncey committed
1013 1014
    if(newL1AIn) numberL1AIn++;
    if(newL1AOut) numberL1AOut++;
dauncey's avatar
dauncey committed
1015 1016 1017

  } // End of BX loop

dauncey's avatar
dauncey committed
1018
  hCounts->SetBinContent(1,bx);
dauncey's avatar
dauncey committed
1019 1020 1021
  hCounts->SetBinContent(2,numberL1AIn);
  hCounts->SetBinContent(3,numberL1AOut);
  hCounts->SetBinContent(4,nHgcrocDeadtime);
dauncey's avatar
dauncey committed
1022 1023 1024 1025
  hCounts->SetBinContent(5,nEconThrottleDeadtime);
  hCounts->SetBinContent(6,nEconExceeded);
  hCounts->SetBinContent(7,nBeThrottleDeadtime);
  hCounts->SetBinContent(8,nBeExceeded);
dauncey's avatar
dauncey committed
1026

dauncey's avatar
dauncey committed
1027 1028 1029 1030
  std::cout << "Number of BXs = " << bx
	    << ", number of L1As = " << numberL1AIn << ", " << numberL1AOut
	    << ", rate = " << numberL1AIn*double(bxPerSec)/bx << " kHz"
	    << std::endl;
dauncey's avatar
dauncey committed
1031 1032

  std::cout << "Number of HGCROC deadtime BXs = " << nHgcrocDeadtime
dauncey's avatar
dauncey committed
1033
	    << ", fraction = " << 1.0*nHgcrocDeadtime/bx << std::endl;
dauncey's avatar
dauncey committed
1034 1035 1036 1037 1038 1039 1040 1041
  std::cout << "Number of ECON throttle deadtime BXs = " << nEconThrottleDeadtime
	    << ", fraction = " << 1.0*nEconThrottleDeadtime/bx << std::endl;
  std::cout << "Number of BX with ECON buffer exceeded = " << nEconExceeded
	    << ", fraction = " << 1.0*nEconExceeded/bx << std::endl;
  std::cout << "Number of BE throttle deadtime BXs = " << nBeThrottleDeadtime
	    << ", fraction = " << 1.0*nBeThrottleDeadtime/bx << std::endl;
  std::cout << "Number of BX with BE buffer exceeded = " << nBeExceeded
	    << ", fraction = " << 1.0*nBeExceeded/bx << std::endl;
dauncey's avatar
dauncey committed
1042

dauncey's avatar
dauncey committed
1043 1044 1045
  // Finish up
  
  hgcrocAna.eoj();
dauncey's avatar
dauncey committed
1046 1047 1048 1049 1050 1051
  
  for(unsigned sl(0);sl<NumberOfSlinks;sl++) {
    for(unsigned ec(0);ec<5;ec++) {
      econAna[sl][ec].eoj();
    }
  }
dauncey's avatar
dauncey committed
1052 1053 1054
  
  return 0;
}