//=======================================================
//
// File: VertexInfo.hpp
//
// Purpose: functions to access VertexCollChunk's content
//
// Created: 11-NOV-1998   Meenakshi Narain
//          12-FEB-1999: Moved to vertex_evt package
//          08-JUN-1999: New signatures + methods
//          25-JUN-1999: Deep modifications to avoid copying
//          28-JUN-1999: New version using pointers only
//           1-OCT-1999: use LinkIndex (Serban Protopopescu)
//===================================================
#ifndef VERTEXINFO_HPP
#define VERTEXINFO_HPP

#include <string>
#include <vector>
#include "edm/Event.hpp"
#include "identifiers/ChunkID.hpp"
#include "edm/LinkIndex.hpp"

#include "vertexutil/Vertex.hpp"
#include "vertexutil/VertexColl.hpp"
#include "vertexutil/VertexType.hpp"

/** Primary Vertex namespace
   Functions to access the vertices stored in {\bf VertexCollChunk} objects. */

namespace vertex {
  
  typedef edm::LinkIndex<Vertex> VertexIndex;
  typedef edm::LinkIndex<Vertex> VtxIndex;

  /// Given an event, return pointer to the first vertex stored in chunk vtype
  bool get_Vertex(const edm::Event& event,
                  VertexType& vtype,const Vertex*& pv);
  bool get_Vertex(const edm::Event& event,
                  VertexType& vtype,const Vertex*& pv, edm::ChunkID& cid);

  /// Given an event, return pointer to first vertex and its {\bf Index}
  bool get_Vertex(const edm::Event& e, VertexType& vtype, 
                  VertexIndex& vID, const Vertex*& pv);
  bool get_Vertex(const edm::Event& e, VertexType& vtype, 
                  VertexIndex& vID, const Vertex*& pv, edm::ChunkID& cid);

  /// Given an event, return pointer to the best primary vertex
  bool get_PrimaryVertex(const edm::Event& event, const Vertex*& pv);
  bool get_PrimaryVertex(const edm::Event& event, const Vertex*& pv, 
			 edm::ChunkID& cid);

  /// Given an event, return the best primary vertex and its {\bf D0Index}
  bool get_PrimaryVertex(const edm::Event& event, VertexIndex& vID,
                         const Vertex*& pv);
  bool get_PrimaryVertex(const edm::Event& event, VertexIndex& vID,
                         const Vertex*& pv, edm::ChunkID& cid);

  /// Given an event, return pointer to the collection of vertices
  bool get_AllVertices(const edm::Event& event,VertexType& vtype, 
		       const std::vector<Vertex>*& pv);
  bool get_AllVertices(const edm::Event& event,VertexType& vtype, 
		       const std::vector<Vertex>*& pv, edm::ChunkID& cid);

  /// Given an event, return pointer to the vertices and their ID's
  bool get_AllVertices(const edm::Event& event, VertexType& vtype, 
                   std::vector<VertexIndex>& vID, 
                   const std::vector<Vertex>*& pv);
  bool get_AllVertices(const edm::Event& event, VertexType& vtype, 
                   std::vector<VertexIndex>& vID, 
                   const std::vector<Vertex>*& pv, edm::ChunkID& cid);

  /// function to extract the VertexColl from a chunk based on its type
  //            returns best vertex
  const VertexColl* extractFromPVChunk(const edm::Event& event, 
				       VertexType& vtype, 
				       VertexIndex& vID, edm::ChunkID& cid);
  const VertexColl* extractFromPVChunk(const edm::Event& event,
				    VertexType& vertexType,
				    std::vector<VertexIndex>& vIDs, 
				       edm::ChunkID& cid);

  /// function to extract the VertexColl from a chunk based on its type
  //            returns ChunkID
  const VertexColl* extractFromPVChunk(const edm::Event& event, 
				       VertexType& vtype, 
				       edm::ChunkID& cid);

  /// function to extract the VertexColl from a chunk based on its ID
  const VertexColl* extractFromPVChunk(const edm::Event& event, 
				       const edm::ChunkID& id);
}

#endif //VERTEXINFO_HPP