Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTreeReader fails to read T<Double_32> as T<double> #12334

Open
eguiraud opened this issue Feb 16, 2023 · 1 comment
Open

TTreeReader fails to read T<Double_32> as T<double> #12334

eguiraud opened this issue Feb 16, 2023 · 1 comment
Assignees

Comments

@eguiraud
Copy link
Member

First reported on the forum at https://root-forum.cern.ch/t/problem-with-type-conversion-for-lorentz-vector/53639 .

Minimal reproducer:

#include <Math/Vector4D.h>
#include <ROOT/RDataFrame.hxx>

float TakeMVector(ROOT::Math::PtEtaPhiMVector &) { return 4.2; }

int main() {
  ROOT::RDataFrame df("Tree", "example_file.root");

  df.Define("unused", "L"); // the failure disappears if this is commented out, even if "unused" is never used.

  auto dff4 = df.Define("x", TakeMVector, {"L"});
  dff4.Max<float>("x").GetValue();
}

with the input file at https://root-forum.cern.ch/t/problem-with-type-conversion-for-lorentz-vector/53639/3?u=eguiraud .

The program errors out with:

The branch L contains data of type ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<Double32_t> >. It cannot be accessed by a TTreeReaderValue<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double> >>

(so TTreeReaderValue cannot read a LorentzVector<PtEtaPhiM4D<Double32_t>> as a LorentzVector<PtEtaPhiM4D<double>>).

The following patch by @Axel-Naumann seems to fix the problem:

diff --git a/tree/treeplayer/src/TTreeReaderValue.cxx b/tree/treeplayer/src/TTreeReaderValue.cxx
index 2323cffee4..6d938f1b14 100644
--- a/tree/treeplayer/src/TTreeReaderValue.cxx
+++ b/tree/treeplayer/src/TTreeReaderValue.cxx
@@ -554,7 +554,8 @@ void ROOT::Internal::TTreeReaderValueBase::CreateProxy() {
       auto branchActualTypeAsClass = dynamic_cast<TClass*>(branchActualType);
       auto inheritance = dictAsClass && branchActualTypeAsClass && branchActualTypeAsClass->InheritsFrom(dictAsClass);

-      if (fDict != branchActualType && !inheritance) {
+      if (fDict != branchActualType && !inheritance
+          && dictAsClass->GetTypeInfo() != branchActualTypeAsClass->GetTypeInfo()) {
          TDataType *dictdt = dynamic_cast<TDataType*>(fDict);
          TDataType *actualdt = dynamic_cast<TDataType*>(branchActualType);
          bool complainAboutMismatch = true;
@eguiraud
Copy link
Member Author

eguiraud commented Mar 7, 2023

P.S.

adding ROOT.TClass.GetClass("ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>>") at the beginning of the program works around the issue.

Axel-Naumann added a commit to Axel-Naumann/root that referenced this issue Mar 13, 2023
As the TClass corresponding to the template parameter of TTreeReaderValue is
found through the typeid => TClass map, make sure that we ignore mismatches
of `Foo<Double32_t>` vs `Foo<double>` - they should not be relevant for reading.

This fixes reading a LorentzVector<Double32_t>.

Fixes root-project#12334
Axel-Naumann added a commit to Axel-Naumann/root that referenced this issue Mar 20, 2023
As the TClass corresponding to the template parameter of TTreeReaderValue is
found through the typeid => TClass map, make sure that we ignore mismatches
of `Foo<Double32_t>` vs `Foo<double>` - they should not be relevant for reading.

This fixes reading a LorentzVector<Double32_t>.

Fixes root-project#12334
Axel-Naumann added a commit to Axel-Naumann/root that referenced this issue Jun 22, 2023
As the TClass corresponding to the template parameter of TTreeReaderValue is
found through the typeid => TClass map, make sure that we ignore mismatches
of `Foo<Double32_t>` vs `Foo<double>` - they should not be relevant for reading.

This fixes reading a LorentzVector<Double32_t>.

Fixes root-project#12334
Axel-Naumann added a commit to Axel-Naumann/root that referenced this issue Jun 23, 2023
As the TClass corresponding to the template parameter of TTreeReaderValue is
found through the typeid => TClass map, make sure that we ignore mismatches
of `Foo<Double32_t>` vs `Foo<double>` - they should not be relevant for reading.

This fixes reading a LorentzVector<Double32_t>.

Fixes root-project#12334
Axel-Naumann added a commit to Axel-Naumann/root that referenced this issue Jun 26, 2023
As the TClass corresponding to the template parameter of TTreeReaderValue is
found through the typeid => TClass map, make sure that we ignore mismatches
of `Foo<Double32_t>` vs `Foo<double>` - they should not be relevant for reading.

This fixes reading a LorentzVector<Double32_t>.

Fixes root-project#12334
@dpiparo dpiparo assigned dpiparo and unassigned Axel-Naumann Mar 24, 2024
dpiparo pushed a commit to dpiparo/root that referenced this issue May 22, 2024
As the TClass corresponding to the template parameter of TTreeReaderValue is
found through the typeid => TClass map, make sure that we ignore mismatches
of `Foo<Double32_t>` vs `Foo<double>` - they should not be relevant for reading.

This fixes reading a LorentzVector<Double32_t>.

Fixes root-project#12334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants