///////////////////////////////////////////////////////////////////////
//
// Summarises the event data into the SOC format and places it into the
// run tree.
//
// Author:  Phil Jones <p.g.jones@qmul.ac.uk>
// Author: Rob Stainforth <R.Stainforth@liverpool.ac.uk> -- contact person
//
// REVISION HISTORY:
//     02/10/2012 : P. Jones - First Revision, new file.
//     2014-01-17 : G. Prior - added Source pos. from manipulator and Laser wavelength.
//                           - suppressed calculation of integral of PMT hits (moved in SOCPeakProc).
//     2014-05-25 : P. Jones - Refactored in line with dsreview.
///    2017-11-14 : A. Inacio - Updated the code to work with non-integer laserball
///               orientations, which is the case of external LB runs.
//
///////////////////////////////////////////////////////////////////////

#ifndef __RAT_SOCDataProc__
#define __RAT_SOCDataProc__

#include <RAT/Processor.hh>
#include <RAT/DS/SOC.hh>

#include <string>
#include <vector>
using namespace std;

namespace RAT
{

class SOCDataProc : public Processor
{
public:
  // Constructor, initialize cut variable
  SOCDataProc();
  // empty virtual destructor
  virtual ~SOCDataProc() {};
  // Applies set integer commands
  virtual void SetI( const std::string& param, const int value );
  // New run must wipe old data ready for new data
  virtual void BeginOfRun( DS::Run& run );
  // Called per event
  virtual Processor::Result DSEvent( DS::Run& run,DS::Entry& ds );
  // Called at the end of the run, fills the run tree with the SOC data
  virtual void EndOfRun( DS::Run&  run );
  // Loads manip info from ratdb (data only)
  void LoadCalibCommon(std::string fCalInfo);
  // Loads N2 laser info from ratdb (data only)
  void LoadN2DyeLaser();
  // Loads smellie run info from ratdb (data only)
  void LoadSMELLIERun( DS::Run& run );
  // Loads tellie run info from ratdb (data only)
  void LoadTELLIERun( DS::Run& run );



protected:
    std::map<std::string, DS::SOC> fSummaryData; // Data indexed by source id
    vector<string> fSubrunFibreIDsVector; ///< vector of fibre IDs used, with one entry for each subrun
    vector<double> fSubRunNumbers; ///< Vector containing the subrun numbers
    // flag to allow some initialization within DSEvent
    bool firstEvent;
    // string to distiguish bewtween LB, T/SM/AMELLIE, and subrun (SMELLIE)
    std::string fSourceID;
    std::string fSourceType;
    //
    bool is_this_mc;
    bool isSource;
    bool isTELLIE;
    bool isSMELLIE;
    bool isAMELLIE;
    TVector3 fPosition;
    TVector3 fOrientationVector;
    int fOrientationCode;
    float fWavelengthAvg;

    DU::PMTCalStatus fPMTStatus;
    int iSkipPMTCuts;

    };

} // ::RAT

#endif