/* ======================================================================== *\
!
! *
! * This file is part of MARS, the MAGIC Analysis and Reconstruction
! * Software. It is distributed to you in the hope that it can be a useful
! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
! * It is distributed WITHOUT ANY WARRANTY.
! *
! * Permission to use, copy, modify and distribute this software and its
! * documentation for any purpose is hereby granted without fee,
! * provided that the above copyright notice appear in all copies and
! * that both that copyright notice and this permission notice appear
! * in supporting documentation. It is provided "as is" without express
! * or implied warranty.
! *
!
!
!   Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
!
!   Copyright: MAGIC Software Development, 2000-2003
!
!
\* ======================================================================== */

//////////////////////////////////////////////////////////////////////////////
//
//  MReportTrigger
//
//////////////////////////////////////////////////////////////////////////////
#include "MReportTrigger.h"

#include "MLogManip.h"

ClassImp(MReportTrigger);

using namespace std;

MReportTrigger::MReportTrigger() : MReport("TRIGGER-REPORT")
{
    fName = "MReportTrigger";
}

Bool_t MReportTrigger::InterpreteBody(TString &str)
{
    str = str.Strip(TString::kLeading);
    Int_t pos = str.First(' ');
    if (pos<=0)
    {
        *fLog << err << "ERROR - Cannot determin name of trigger table." << endl;
        return kFALSE;
    }

    TString tablename = str(0, pos);
    str.Remove(0, pos);

    Int_t len, n;

    pos = 0;
    for (int i=0; i<19; i++)
    {
        n = sscanf(str.Data()+pos, " %f %n", &fScalerRate[i], &len);
        if (n!=1)
        {
            *fLog << err << "ERROR - Scaler Value #" << i << " missing." << endl;
            return kFALSE;
        }
        pos += len;
    }
    n = sscanf(str.Data()+pos, " %f %f %n", &fL1TriggerRate,
               &fL2TriggerRate, &len);
    if (n!=2)
    {
        *fLog << err << "ERROR - Couldn't read Trigger rates." << endl;
        return kFALSE;
    }
    pos += len;
    for (int i=0; i<11; i++)
    {
        n = sscanf(str.Data()+pos, " %f %n", &fRates[i], &len);
        if (n!=1)
        {
            *fLog << err << "ERROR - Rate #" << i << " missing." << endl;
            return kFALSE;
        }
        pos += len;
    }
    str.Remove(0, pos);
    str.Strip(TString::kBoth);

    *fLog << "T" << flush;

    return str==(TString)"OVER";
}
