-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Support for std::array event products #30493
Comments
assign core |
New categories assigned: core @Dr15Jones,@smuzaffar,@makortel you have been requested to review this Pull request/Issue and eventually sign? Thanks |
A new Issue was created by @makortel Matti Kortelainen. @Dr15Jones, @silviodonato, @dpiparo, @smuzaffar, @makortel can you please review it and eventually sign/assign? Thanks. cms-bot commands are listed here |
@pcanal suggested to look into |
This issue is related to investigations done as part of #27277. |
Mostly to document for myself. I replaced cmssw/FWCore/Reflection/src/TypeWithDict.cc Lines 808 to 815 in cea1d1b
with // A related free function
bool hasDictionary(std::type_info const& ti) {
return TDictionary::GetDictionary(ti) != nullptr;
} after which my test failed with
That exception is thrown from cmssw/FWCore/Framework/src/one/OutputModuleBase.cc Lines 147 to 150 in cea1d1b
where the checkDictionary() overload is this onecmssw/FWCore/Reflection/src/DictionaryTools.cc Lines 92 to 100 in cea1d1b
The branch is fired because typeWithDict.invalidTypeInfo() == true , which translates tocmssw/FWCore/Reflection/src/TypeWithDict.cc Line 355 in cea1d1b
The isPointer() and isArray() both return false , so *ti_ == typeid(dummyType) must hold.
The cmssw/FWCore/Reflection/src/TypeWithDict.cc Lines 318 to 328 in cea1d1b
when TClass::GetTypeInfo() == nullptr , which is the case with std::array<T, N> (confirmed with a printout there, and in ROOT prompt).
I need to think a bit more how to proceed from here. |
I just wanted to check on the status |
Shouldn't isArray() return true here? (I.e. should it be expanded to also return true for std::array)? |
Good question. I need to understand if we use On the other hand cmssw/FWCore/Reflection/src/DictionaryTools.cc Lines 92 to 100 in cea1d1b
would add the type to missingDictionaries . This makes me wonder if that check, or the call from OutputModuleBase::keepThisBranch() are fully appropriate (for std::array ). Of course it could be that changing isArray() == true would lead to another code branch to be taken elsewhere.
|
It "should" since a C-style would not have a TClass and would not have a typeinfo stored by ROOT.
Indeed, since the dictionary for the std::array is not generate we do not acquire the type_info for it (we 'could' but it would require header parsing at run-time which we are trying to avoid). |
Fortunately all calls to
The consequences of
I didn't continue further, but based on this I'm not sure if treating |
(the definition of There are also two overloads for cmssw/FWCore/Reflection/interface/DictionaryTools.h Lines 25 to 27 in b062071
that both call the overload 2 of checkDictionary() .
The
|
The two overloads of
I'm currently trying to understand why the overload 2 of |
Overload 1 does (explicitly but somewhat obscurely):
while Overload 2 assumes that the dictionary library library is already loaded (and that the answer is already compiled in TypeWithDict object). |
I tried to just call the
I'm not really sure why the (unwrapped)
and that TypeWithDict is initialized from std::type_info herecmssw/FWCore/Framework/src/ProductRegistryHelper.cc Lines 77 to 78 in b05f18a
(still need to investigate where that std::type_info originates from)
Another attempt I did was to replace the bool checkDictionary(std::vector<std::string>& missingDictionaries,
std::string const& name,
TypeWithDict const& typeWithDict) {
if ((!bool(typeWithDict) || typeWithDict.invalidTypeInfo()) and not hasDictionary(typeWithDict.name())) {
missingDictionaries.emplace_back(name);
return false;
}
return true;
bool hasDictionary(std::string const& typeName) {
return hasDictionary(typeName.c_str());
}
bool hasDictionary(char const* typeName) {
return TDictionary::GetDictionary(typeName) != nullptr;
} This allowed me to pass the cmssw/FWCore/Framework/src/one/OutputModuleBase.cc Lines 159 to 160 in b05f18a
which leads to a call to TypeWithDict::typeInfo() , which then throws an exception because the held type_info is dummy. That raises an additional question if we really need a valid std::type_info there (based on quick look I'd say "yes").
|
On the other hand the cmssw/FWCore/Reflection/src/TypeWithDict.cc Lines 173 to 212 in b05f18a
|
That seems wrong. Overload 2 knows it does not need overload 1. What is the goal trying this? |
I wanted to see what happens if I skip the "answer already compiled in |
On the other hand it would certainly be inconsistent if |
Matti asked me to look into this. Below are some comments First Question - How hard is it to make CMSSW work with std::array This is the major problem. TClass::GetClass("std::array<int,4>") The type_info is used by the output module when it declares Independent of the type_info, we use the dictionary in There could be other issues. Things like cutParser and My first thought is that the best thing is simply to I tried to think of some alternatives: For produced products, we can get the type_info from I do not see any easy alternate way to get the type_info.
If we wanted to support Views into std::array, we would also Second question - What do we use dictionaries for in the Framework?
One unrelated other thing that I noticed while doing this. |
(still digesting but a quick note):
nesting of std::array is not yet supported by the I/O |
For 1 (and somewhat 2) (TClass returns a typeinfo or getTypeInfo special case std::array), the major question/trade-off is that we need to either: |
@wddgit Thanks for the detailed information. I am reviewing if there is a good practical solution. |
#43076 provides a workaround for storing std::array directly |
Current
std::array<T, N>
products can not be put into the event because framework complains from missing dictionary.std::array
is one of those types that ROOT handles internally without an explicit dictionary. Our current check (or one of them)cmssw/FWCore/Reflection/src/TypeWithDict.cc
Lines 808 to 815 in b0ddd4e
handles built-in types as a special case, and then asks from
TClassTable
if the type has a dictionary. Forstd::array
theTClassTable::GetDict()
returns anullptr
, and therefore the framework code thinks thestd::array
to not have a dictionary.We should look for a better way to ask from ROOT if its parser system can interact with a type
T
.The text was updated successfully, but these errors were encountered: