////////////////////////////////////////////////////////////////////
//
// Process only events in an event ID list.
//
// This is a conditional processor, and so should be used in conjunction
// with a ConditionalProcBlock, i.e. an if statement. For an example,
// see rat/example/macros/analysis/eventlist.mac.
//
// This processor allows you to specify a list of event IDs (GTIDs) to
// process in a text file. Events with IDs not in the list are aborted,
// i.e. no subsequent processors are run. The typical use case is
// reading in events from disk, in which case this processor should be
// called first in the event loop.
//
// Note that, since the processing chain is aborted for an event if the
// ID is not in the list, skipped events will not be written to disk.
//
// The format of the text file is flexible. The IDs in the list may be
// separated by any combination of whitespace, newlines, and commas.
// Comments following a "#" character are allowed. An ID may be in
// decimal format (indicated by a bare number), hexadecimal (preceded by
// a "0x"), or octal (preceded by a "0").
//
// Author: A. Mastbaum <mastbaum@hep.upenn.edu> - contact person
//
// REVISION HISTORY:
//     25 Sep 2013 : A. Mastbaum - new file
//     2013-11-14 : P G Jones - Added conditional results
//     2020-08-11 : A. Patton - Added instructions & example
//     2022-02-06 : M. Anderson - Implement a few minor improvements
//
////////////////////////////////////////////////////////////////////

#ifndef __RAT_EventListProc___
#define __RAT_EventListProc___

#include <RAT/Processor.hh>
#include <vector>
#include <string>

namespace RAT {

namespace DS {
  class Entry;
  class EV;
}

class EventListProc : public Processor {
public:
  EventListProc() : Processor("EventListProc"), fFileSet(false) {}
  virtual ~EventListProc() {}

  // Handle string 'procset' arguments.
  //
  // file - string, name of the file from which to load the event ID list
  virtual void SetS(const std::string& param, const std::string& value);

  // Process one event.
  //
  // If the event's ID is in the list, continue processing by returning OK;
  // otherwise, abort further processing by returning ABORT.
  virtual Processor::Result DSEvent(DS::Run& run, DS::Entry& ds);

protected:
  // Read GTIDs from a file into fGTIDList
  bool LoadFile(const std::string& filename);

  std::vector<unsigned> fEventIDList;  // Sorted list of IDs to process
  bool fFileSet;  // true after the ID list file has been loaded
};

}  // namespace RAT

#endif  // __RAT_EventListProc__