Template forward declaration is missing in the .rootmap

Hello,

I have a problem with auto-loading (root 6.12/06) the library when the templated class it contains is instantiated, while the auto-loading works fine when instantiating other classes from the same library.

The templated class looks like

namespace o2 {namespace ITSMFT {
template <class Mapping = o2::ITSMFT::ChipMappingITS>
class RawPixelReader : public PixelReader {
 //...
 private:
  Mapping mMapping;
  ClassDefOverride(RawPixelReader, 1);
};
}}

and in the LinkDef I require two specializations (together with classes which are used as template arguments):

#pragma link C++ class o2::ITSMFT::RawPixelReader < o2::ITSMFT::ChipMappingITS > +;
#pragma link C++ class o2::ITSMFT::RawPixelReader < o2::ITSMFT::ChipMappingMFT > +;
#pragma link C++ class o2::ITSMFT::ChipMappingITS + ;
#pragma link C++ class o2::ITSMFT::ChipMappingMFT + ;

Everything works fine, the template specializations are fully functional, except that if I try to instantiate them, the interpreter does not find correct library:

root [0] o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS> vv
ROOT_prompt_0:1:13: error: no member named 'RawPixelReader' in namespace 'o2::ITSMFT'
o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS> vv
~~~~~~~~~~~~^
Warning in <TInterpreter::LoadLibraryMap>: Problems in /home/shahoian/alice/sw/ubuntu1604_x86-64/O2/dev_PixRead-1/lib/libITSMFTReconstruction.rootmap declaring '
#line 1 "Forward declarations from /home/shahoian/alice/sw/ubuntu1604_x86-64/O2/dev_PixRead-1/lib/libITSMFTReconstruction.rootmap"
namespace o2 { namespace ITSMFT {  } }namespace std {  }namespace o2 { namespace ITSMFT { class ChipMappingMFT; } }namespace o2 { namespace ITSMFT { class ChipMappingITS; } }' were encountered.

The object is created w/o problem if I load in advance the corresponding library:

root [0] gSystem->Load("libITSMFTReconstruction");
root [1] o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS> vv
(o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS> &) @0x7fcafd71c020
root [2] 

The dictionary and the rootmap generation proceeds w/o problem, with rootcint -v4 I see that the template is recognized and its arguments are added to the { decls } block:

 o o2::ITSMFT::PixelReader --> , payloadCode
 o o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS> --> , payloadCode
 o o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingMFT> --> , payloadCode
 o o2::ITSMFT::TopologyFastSimulation --> , payloadCode
Class RawPixelReader is a template specialisation. Treating its arguments.
 o Template argument successfully treated. Arg fwd decl: 
namespace o2 { namespace ITSMFT { class ChipMappingMFT; } }
Class RawPixelReader is a template specialisation. Treating its arguments.
 o Template argument successfully treated. Arg fwd decl: 
namespace o2 { namespace ITSMFT { class ChipMappingITS; } }
Info: Rootmap file name ./libITSMFTReconstruction.rootmap and lib name(s) "ITSMFTReconstruction.so"

but the template forward declaration itslef is not appearing in the rootmap, which looks like (edited to not show irrelevant classes)

{ decls }
namespace o2 { namespace ITSMFT {  } }
namespace std {  }
namespace o2 { namespace ITSMFT { class ChipMappingMFT; } }
namespace o2 { namespace ITSMFT { class ChipMappingITS; } }

[ ITSMFTReconstruction.so ]
# List of selected classes
...
class o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS>
class o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingMFT>
header ITSMFTReconstruction/ChipMappingITS.h

If I modify by hand the { decls } block of libITSMFTReconstruction.rootmap, adding the template forward declaration as

{ decls }
namespace o2 { namespace ITSMFT {  } }
namespace std {  }
namespace o2 { namespace ITSMFT { class ChipMappingMFT; } }
namespace o2 { namespace ITSMFT { class ChipMappingITS; } }
namespace o2 { namespace ITSMFT { template <class Mapping> class RawPixelReader; } }

then the auto-loading works w/o problem:

root [0] o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS> vv
(o2::ITSMFT::RawPixelReader<o2::ITSMFT::ChipMappingITS> &) @0x7f40c689f020

Any hint why the template is not forward declared in the rootmap? We have plenty of templates in other libraries, and for them the forward declaration works fine.

Best regards,
Ruben

Hi,

After some digging I am almost confident that this is a rootcling bug: I see that the template forward declaration is not added to the rootmap unless in the LinkDef there is at least one specialization with the trivial type as a template argument. I.e. if I add to the LinkDef a non-functional specialization

#pragma link C++ class o2::ITSMFT::RawPixelReader < int > +;

then the template forward declaration appears in the rootmap:

{ decls }
namespace o2 { namespace ITSMFT {  } }
namespace std {  }
namespace o2 { namespace ITSMFT { template <typename Mapping> class RawPixelReader; } }
namespace o2 { namespace ITSMFT { class ChipMappingMFT; } }
namespace o2 { namespace ITSMFT { class ChipMappingITS; } }

I think this is related to the riitcling_impl.cxx ProcessAndAppendIfNotThere method behaviour: it receives the string with \n separated template argument (if it is not a trivial type) and template declaration, then adds to the forward declarations the 1st substring before the “\n”

Thanks a lot for debugging, Ruben! I will have a look next week, unless @Danilo is overtaking me!

Do you see the same issue with v6.14?

Hi Axel,

I did not test with v6.14 since the Alice O2 currently installs 6.12/06 automatically. Will try now.

Cheers,
Ruben

Hi Ruben,

I didn’t manage to reproduce this in a reasonable time as a stand-alone example. Two options:

  • can you simplify this case into a stand-alone example that exhibits this bug?
  • if not, can you describe the steps I need to run to reproduce this?
    Thanks!

Cheers, Axel.

Hi Axel,

I’ve reproduced the problem in root v6.14 (binary downloaded from the root page ) with the simple test I put in the bug report - https://sft.its.cern.ch/jira/browse/ROOT-9505?filter=-2

Now I am building the root master from the source to test one idea on how to fix this problem, will let you know.

Cheers,
Ruben

Hi Axel,

For me the attached patch (for the root master) fixes the problem of the rootmap generation.
fix_fwdTmpl.txt (1.0 KB)

Could you please check if it can have some adverse effects?

Cheers,
Ruben

Wow, even better, thanks Ruben!

This is https://github.com/root-project/root/pull/2272

Axel.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.