iris-hep / func_adl_xAOD

Client interface to send a hierarchical SQL-like query to an xAOD backend
0 stars 5 forks source link

First scoping does not work with multiple later actions #225

Closed gordonwatts closed 4 months ago

gordonwatts commented 4 months ago

The following query generates incorrect C++ code:

pv_query = (
    ds
    .Select(lambda e: e.Vertices("PrimaryVertices"))
    .Select(lambda vtx: vtx.First())
)

track_query = (
    pv_query
    .Select(lambda v: v.trackParticleLinks().Where(lambda t: t.pt() > 500.0))
    .Select(lambda tracks: {
        "pt": tracks.Select(lambda t: t.pt()),
        "eta": tracks.Select(lambda t: t.eta()),
        "phi": tracks.Select(lambda t: t.phi()),
    })
)

tracks= track_query.AsAwkwardArray().value()

The C++ code generated:

{
  {

    const DataVector<xAOD::Vertex_v1>* vertices13;

    bool is_first15 (true);

    {

      const DataVector<xAOD::Vertex_v1>* result = 0;

      ANA_CHECK (evtStore()->retrieve(result, "PrimaryVertices"));

      vertices13 = result;

    }

    for (auto &&i_obj14 : *vertices13)

    {

      if (is_first15)

      {

        is_first15 = false;

        for (auto &&i_obj16 : i_obj14->trackParticleLinks())

        {

          if (((*i_obj16)->pt()>500.0))

          {

            _pt19.push_back((*i_obj16)->pt());

          }

        }

      }

    }

    for (auto &&i_obj17 : i_obj14->trackParticleLinks())

    {

      if (((*i_obj17)->pt()>500.0))

      {

        _eta20.push_back((*i_obj17)->eta());

      }

    }

    for (auto &&i_obj18 : i_obj14->trackParticleLinks())

    {

      if (((*i_obj18)->pt()>500.0))

      {

        _phi21.push_back((*i_obj18)->phi());

      }

    }

    tree("atlas_xaod_tree")->Fill();

    _pt19.clear();

    _eta20.clear();

    _phi21.clear();

  }

  return StatusCode::SUCCESS;
}

Note the second (and further) i_obj14->trackParticleLinks() are outside the generated First C++ - and so i_obj14 is no longer valid.