// -*- c++ -*- // ish

// A protocol buffer descriptin of Wire-Cell Toolkit IData classes.

// conventions:
// - use same name as interface class minus the "I".
// - all message classes in this one .proto
// - 

syntax = "proto3";
package wctzpb;

import "google/protobuf/any.proto";


// What is sent/recv'ed
message Payload {
  // One of the messages below.
  repeated google.protobuf.Any objects = 1;
}

message Point {
  float x = 1;
  float y = 2;
  float z = 3;
}

message Depo {
  /// Uniquely identify this depo in some context.  If in a depo set
  /// this is the index.
  uint64 ident = 1;

  /// The location of the deposition.
  Point pos = 2;

  /// The number of seconds from some absolute start time to when the
  /// deposition occurred.
  double time = 3;

  /// The number charge (in units of number of electrons) deposited.
  double charge = 4;

  /// The energy (in units of MeV) deposited.
  double energy = 5;

  /// Track ID eg from Geant4 which produced this depo directly or indirectly
  uint32 trackid = 6;

  /// PDG code of that track ID
  uint32 pdg = 7;
        
  /// If the deposition is drifted, this may allow access to the
  /// original and refers to an ident.
  uint64 prior = 8;

  /// Any (half width) extent in the longitudinal (drift)
  /// direction (distance).  The distribution is implicit but
  /// typically it is taken that this is a Gaussian sigma.
  double extent_long = 9;

  /// Any (half width) extent in the transverse (pitch)
  /// direction (distance).  The distribution is implicit but
  /// typically it is taken that this is a Gaussian sigma.
  double extent_tran = 10;
  
}


message DepoSet {
  // A unique identifier for this set.
  uint32 ident = 1;

  // The depos in the set.
  repeated Depo depos = 2;
}

message FloatArray {
    repeated float elements = 1;
}
message IntArray {
    repeated int32 elements = 1;
}

message Trace {
    // Identifier for the channel on which this trace was recorded
    int32 channel = 1;

    // The time bin relative to some absolute time at which the first
    // ADC/charge in the trace was digitized (leading bin edge).
    int32 tbin = 2;

    // Contiguous ADC/charge measurement on the channel starting at
    // tbin.
    FloatArray samples = 3;
}

message BinRangeList {
    // Array of begin sample indices of some range
    repeated int32 beg = 1;
    // Array of end sample indices (non-inclusive) of some range
    repeated int32 end = 2;    
}

message ChannelMasks {
    // Map a channel ID to a bin range list
    map<int32, BinRangeList> bin_range_lists = 1;
}

message Frame {

    // An identifying number for this frame.
    int32 ident = 1;

    // A reference time for this frame w.r.t. some global time origin.
    // Each trace tbin counts samples w.r.t. this time
    double time = 2;

    // The digitization sample period assumed for the traces.
    double tick = 3;

    // The list of all traces in the frame.
    repeated Trace traces = 4;

    // List of tags applied to this frame as a whole
    repeated string frame_tags = 5;

    // Map of a trace tag to an array of integer indices into the
    // traces array.
    map<string, IntArray> tagged_traces = 6;

    // Map of a trace tag to an array of values with each
    // corresponding to a tagged trace index in the tagged traces map.
    // Every key in trace_summaries should exist in tagged_traces (but
    // not necessarily vice versa)
    map<string, FloatArray> trace_summaries = 7;

    // Map a channel mask tag to a set of channel masks.
    map<string, ChannelMasks> channel_masks = 8;
}
