Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDefineReader.cxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, CERN 08/2020
2
3/*************************************************************************
4 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
13#include <ROOT/RDF/Utils.hxx> // TypeID2TypeName
14#include <TClass.h>
15
16#include <stdexcept> // std::runtime_error
17#include <string>
18#include <typeinfo>
19
20void ROOT::Internal::RDF::CheckDefineType(RDefineBase &define, const std::type_info &tid)
21{
22 const auto &colTId = define.GetTypeId();
23
24 // Here we compare names and not typeinfos since they may come from two different contexts: a compiled
25 // and a jitted one.
26 const auto diffTypes = (0 != std::strcmp(colTId.name(), tid.name()));
27 auto inheritedType = [&]() {
28 auto colTClass = TClass::GetClass(colTId);
29 return colTClass && colTClass->InheritsFrom(TClass::GetClass(tid));
30 };
31
32 if (diffTypes && !inheritedType()) {
33 const auto tName = TypeID2TypeName(tid);
34 const auto colTypeName = TypeID2TypeName(colTId);
35 std::string errMsg = "RDefineReader: column \"" + define.GetName() + "\" is being used as ";
36 if (tName.empty()) {
37 errMsg += tid.name();
38 errMsg += " (extracted from type info)";
39 } else {
40 errMsg += tName;
41 }
42 errMsg += " but defined column has type ";
43 if (colTypeName.empty()) {
44 auto &id = colTId;
45 errMsg += id.name();
46 errMsg += " (extracted from type info)";
47 } else {
48 errMsg += colTypeName;
49 }
50 throw std::runtime_error(errMsg);
51 }
52}
std::string GetName() const
virtual const std::type_info & GetTypeId() const =0
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2957
void CheckDefineType(RDFDetail::RDefineBase &define, const std::type_info &tid)
std::string TypeID2TypeName(const std::type_info &id)
Returns the name of a type starting from its type_info An empty string is returned in case of failure...
Definition RDFUtils.cxx:99