/* ======================================================================== *\
!
! *
! * 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
!
!
\* ======================================================================== */

//////////////////////////////////////////////////////////////////////////////
//
//  MReport
//
//////////////////////////////////////////////////////////////////////////////
#include "MReport.h"

#include "MLogManip.h"

#include "MTime.h"

ClassImp(MReport);

using namespace std;

Bool_t MReport::Interprete(TString &str)
{
    if (!InterpreteHeader(str))
        return kFALSE;

    return InterpreteBody(str);
}

Bool_t MReport::InterpreteBody(TString &str)
{
    *fLog << warn << "No interpreter existing for: " << fIdentifier << endl;
    return kTRUE;
}

Bool_t MReport::InterpreteHeader(TString &str)
{
    int len, state;
    int hor, min, sec, ms;

    int n = sscanf(str.Data(),
                   " %d %*d %*d %*d %d %d %d %d "
                   "%*d %*d %*d %*d %*d %*d %*d %*d"
                   "%n",
                   &state, &hor, &min, &sec, &ms, &len);
    if (n!=5)
    {
        *fLog << err << "ERROR - Cannot interprete Body of " << fIdentifier << endl;
        return kFALSE;
    }

    fState=state;
    if (fTime)
        fTime->SetTime(hor, min, sec, ms*1000000);

    str.Remove(0, len);
    return kTRUE;
}
