#include <farfalla.h>
#include <dash.h>
#include <kuip.h>
#include <eventNode.h>
#include <stopNode.h>
#include <fstream.h>
#include <strstream.h>
#include <String.h>
#include <BitString.h>
#include <iomanip.h>

extern eventNode *ev;
static stopNode *stopBank;
static int SM;
void stopAnaEvent()
{
  if(ev->numChildren(stopType))
    {
      F_getChild(ev,stopBank,0);
      cout << "Stop Master Node   version:" << (short) stopBank->version << endl << endl;
      cout << "===================================================================" << endl;
      cout << " Trig |   Relative Trig Time in nanoseconds (each SM is separate) |" << endl; 
      cout << "      |   SM1   |   SM2   |   SM3   |   SM4   |   SM5   |   SM6   |" << endl;
      cout << "===================================================================" << endl;
      cout << "  ERP | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->erpTime[SM] << " | ";
      cout << endl;
      cout << "  LIP | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->lipTime[SM] << " | ";
      cout << endl;
      cout << "  SMT | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->smtTime[SM] << " | ";
      cout << endl;
      cout << "  STM | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->stmTime[SM] << " | ";
      cout << endl;
      cout << "  FMT | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->fmtTime[SM] << " | ";
      cout << endl;
      cout << "  HIP | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->hipTime[SM] << " | ";
      cout << endl;
      cout << "CSPAM | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->cspamTime[SM] << " | ";
      cout << endl;
      cout << "ISTOP | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->interStopTime[SM] << " | ";
      cout << endl;
      cout << "===================================================================" << endl;
      cout << " TOHM |   Relative Trig Time in nanoseconds (each SM is separate) |" << endl; 
      cout << " FACE |   SM1   |   SM2   |   SM3   |   SM4   |   SM5   |   SM6   |" << endl;
      cout << "===================================================================" << endl;
      cout << "    B | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->bottomTime[SM] << " | ";
      cout << endl;
      cout << "    C | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->centerTime[SM] << " | ";
      cout << endl;
      cout << "    T | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->topTime[SM] << " | ";
      cout << endl;
      cout << "    W | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->westTime[SM] << " | ";
      cout << endl;
      cout << "    E | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->eastTime[SM] << " | ";
      cout << endl;
      cout << "  N/S | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->nsTime[SM] << " | ";
      cout << endl;
      cout << " SM-1 | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->smMinusTime[SM] << " | ";
      cout << endl;
      cout << " SM+1 | ";
      for(SM=0; SM<6 ; SM++)cout << setw(7) << stopBank->smPlusTime[SM] << " | ";
      cout << endl;
//      cout << endl << endl << endl << endl;
//      cout << "Stop Master Trigger Pattern" << endl << endl;
//      cout << "        C  I" << endl;
//      cout << "        S  S" << endl;
//      cout << "    SELFPSHT" << endl;
//      cout << "    MRIMATIO" << endl;
//      cout << "    TPPTMMPP" << endl;
//      cout << "    ========" << endl;
//      for(SM=0; SM<6; SM++)
//	{
//	  cout << "SM" << SM+1 << ":";
//	  stopBank->trigBits[SM].printon(cout,' ','*');
//	  cout << endl;
//	}
//      cout << endl;
//      cout << "Stop Master SMT Trigger Pattern" << endl << endl;
//     cout << "          SS" << endl;
//      cout << "         NMM" << endl;
//      cout << "    BCTWES+-" << endl;
//      cout << "    ========" << endl;
//      for(SM=0; SM<6; SM++)
//	{
//	  cout << "SM" << SM+1 << ":";
//	  stopBank->smtBits[SM].printon(cout,' ','*');
//	  cout << endl;
//	}
//     cout << endl;
      cout.width(0);
    }    
}
