21 #include "TDictAttributeMap.h"
37 anyProductProduced_(
false),
38 productLookups_{{std::make_unique<ProductResolverIndexHelper>(),
39 std::make_unique<ProductResolverIndexHelper>(),
40 std::make_unique<ProductResolverIndexHelper>(),
41 std::make_unique<ProductResolverIndexHelper>()}},
44 for (
bool& isProduced : productProduced_)
50 for (
bool& isProduced : productProduced_)
52 anyProductProduced_ =
false;
55 for (
auto& iterProductLookup : productLookups_) {
56 iterProductLookup = std::make_unique<ProductResolverIndexHelper>();
71 std::pair<ProductList::iterator, bool>
ret =
78 <<
"\nThe Framework requires a unique branch name for each product\n"
79 <<
"which consists of four parts: a friendly class name, module label,\n"
80 <<
"product instance name, and process name. A product has been\n"
81 <<
"registered with a duplicate branch name. The most common way\n"
82 <<
"to fix this error is to modify the product instance name in\n"
83 <<
"one of the offending 'produces' function calls. Another fix\n"
84 <<
"would be to delete one of them if they are for the same product.\n\n"
85 <<
" friendly class name = " <<
previous.second.friendlyClassName() <<
"\n"
86 <<
" module label = " <<
previous.second.moduleLabel() <<
"\n"
87 <<
" product instance name = " <<
previous.second.productInstanceName() <<
"\n"
88 <<
" process name = " <<
previous.second.processName() <<
"\n\n"
89 <<
"The following additional information is not used as part of\n"
90 <<
"the unique branch identifier.\n\n"
91 <<
" branch types = " <<
previous.second.branchType() <<
" " << productDesc.
branchType() <<
"\n"
92 <<
" class name = " <<
previous.second.fullClassName() <<
"\n\n"
93 <<
"Note that if the four parts of the branch name are the same,\n"
94 <<
"then this error will occur even if the branch types differ!\n\n";
98 <<
"The process name " << productDesc.
processName() <<
" was previously used for products in the input.\n"
99 <<
"This has caused branch name conflicts between input products and new products.\n"
100 <<
"Please modify the configuration file to use a distinct process name.\n"
101 <<
"Alternately, drop all input products using that process name and the\n"
102 <<
"descendants of those products.\n";
131 iter->second.merge(productDesc);
138 if (it->second.branchType() == brType) {
157 if (initializeLookupInfo) {
164 std::set<TypeID>
const& elementTypesConsumed,
176 <<
"cannot modify the ProductRegistry because it is frozen\n";
183 <<
"cannot read the ProductRegistry because it is not yet frozen\n";
190 std::vector<std::string>
result;
194 result.push_back(product.second.branchName());
200 std::vector<BranchDescription const*>
result;
204 result.push_back(&product.second);
210 for (
auto const& product : other) {
224 bool hasAliases =
false;
225 std::vector<BranchID> onDemandIDs;
227 if (prod.second.produced() && prod.second.branchType() ==
InEvent &&
228 unscheduledLabels.end() != unscheduledLabels.find(prod.second.moduleLabel())) {
229 prod.second.setOnDemand(
true);
230 onDemandIDs.push_back(prod.second.branchID());
232 if (prod.second.produced() && prod.second.isAlias()) {
239 std::sort(onDemandIDs.begin(), onDemandIDs.end());
240 for (
auto& prod : productList_) {
241 if (prod.second.isAlias()) {
242 if (std::binary_search(onDemandIDs.begin(), onDemandIDs.end(), prod.second.aliasForBranchID())) {
243 prod.second.setOnDemand(
true);
253 std::ostringstream differences;
255 ProductRegistry::ProductList::iterator
j =
productList_.begin();
256 ProductRegistry::ProductList::iterator
s =
productList_.end();
257 ProductRegistry::ProductList::const_iterator
i = other.
productList().begin();
258 ProductRegistry::ProductList::const_iterator
e = other.
productList().end();
261 while (j != s || i != e) {
262 if (j != s && j->second.produced()) {
265 }
else if (j == s || (i != e && i->first < j->first)) {
266 if (i->second.present()) {
267 differences <<
"Branch '" << i->second.branchName() <<
"' is in file '" << fileName <<
"'\n";
268 differences <<
" but not in previous files.\n";
275 }
else if (i == e || (j != s && j->first < i->first)) {
276 if (j->second.present() &&
278 differences <<
"Branch '" << j->second.branchName() <<
"' is in previous files\n";
279 differences <<
" but not in file '" << fileName <<
"'.\n";
285 j->second.merge(i->second);
293 return differences.str();
297 std::set<TypeID>
const* elementTypesConsumed,
299 std::map<TypeID, TypeID> containedTypeMap;
300 std::map<TypeID, std::vector<TypeWithDict>> containedTypeToBaseTypesMap;
302 std::vector<std::string> missingDictionaries;
303 std::vector<std::string> branchNamesForMissing;
304 std::vector<std::string> producedTypes;
309 auto const&
desc = product.second;
313 if (
desc.produced() && !
desc.transient()) {
318 if (
desc.present()) {
323 if (!
desc.produced()) {
326 branchNamesForMissing.emplace_back(
desc.branchName());
327 producedTypes.emplace_back(
desc.className() +
std::string(
" (read from input)"));
331 TypeID typeID(
desc.unwrappedType().typeInfo());
333 auto iterContainedType = containedTypeMap.find(typeID);
334 bool alreadySawThisType = (iterContainedType != containedTypeMap.end());
336 if (!
desc.produced() && !alreadySawThisType) {
338 branchNamesForMissing.emplace_back(
desc.branchName());
339 producedTypes.emplace_back(
desc.className() +
std::string(
" (read from input)"));
344 TypeID wrappedTypeID(
desc.wrappedType().typeInfo());
347 if (alreadySawThisType) {
348 containedTypeID = iterContainedType->second;
352 bool hasContainedType = (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID());
354 std::vector<TypeWithDict>* baseTypesOfContainedType =
nullptr;
356 if (!alreadySawThisType) {
357 bool alreadyCheckedConstituents =
desc.produced() && !
desc.transient();
358 if (!alreadyCheckedConstituents && !
desc.transient()) {
361 branchNamesForMissing.emplace_back(
desc.branchName());
362 producedTypes.emplace_back(
desc.className() +
std::string(
" (read from input)"));
367 if (hasContainedType) {
368 auto iterBaseTypes = containedTypeToBaseTypesMap.find(containedTypeID);
369 if (iterBaseTypes == containedTypeToBaseTypesMap.end()) {
370 std::vector<TypeWithDict> baseTypes;
372 branchNamesForMissing.emplace_back(
desc.branchName());
373 if (
desc.produced()) {
374 producedTypes.emplace_back(
desc.className() +
std::string(
" (produced in current process)"));
376 producedTypes.emplace_back(
desc.className() +
std::string(
" (read from input)"));
380 iterBaseTypes = containedTypeToBaseTypesMap.insert(std::make_pair(containedTypeID, baseTypes)).first;
382 baseTypesOfContainedType = &iterBaseTypes->second;
387 containedTypeMap.emplace(typeID, containedTypeID);
389 if (hasContainedType) {
390 auto iterBaseTypes = containedTypeToBaseTypesMap.find(containedTypeID);
391 if (iterBaseTypes != containedTypeToBaseTypesMap.end()) {
392 baseTypesOfContainedType = &iterBaseTypes->second;
397 if (productTypesConsumed !=
nullptr && !
desc.produced()) {
398 bool mainTypeConsumed = (productTypesConsumed->find(typeID) != productTypesConsumed->end());
399 bool containedTypeConsumed =
400 hasContainedType && (elementTypesConsumed->find(containedTypeID) != elementTypesConsumed->end());
401 if (hasContainedType && !containedTypeConsumed && baseTypesOfContainedType !=
nullptr) {
402 for (
TypeWithDict const& baseType : *baseTypesOfContainedType) {
403 if (elementTypesConsumed->find(
TypeID(baseType.typeInfo())) != elementTypesConsumed->end()) {
404 containedTypeConsumed =
true;
409 if (!containedTypeConsumed) {
410 if (mainTypeConsumed) {
415 if (hasContainedType) {
416 containedTypeID =
TypeID(
typeid(
void));
429 desc.moduleLabel().c_str(),
430 desc.productInstanceName().c_str(),
431 desc.processName().c_str(),
433 baseTypesOfContainedType);
438 if (!missingDictionaries.empty()) {
444 iterProductLookup->setFrozen();
447 unsigned int indexIntoNextIndexValue = 0;
450 ++indexIntoNextIndexValue;
453 for (
auto const& product : productList_) {
454 auto const&
desc = product.second;
461 productTypesConsumed, elementTypesConsumed, containedTypeMap, containedTypeToBaseTypesMap);
467 std::set<TypeID>
const* elementTypesConsumed,
468 std::map<TypeID, TypeID>
const& containedTypeMap,
469 std::map<
TypeID, std::vector<TypeWithDict>>
const& containedTypeToBaseTypesMap) {
472 auto iterContainedType = containedTypeMap.find(std::get<Transients::kType>(
item));
473 if (iterContainedType == containedTypeMap.end()) {
475 ex <<
"containedTypeMap did not contain " << std::get<Transients::kType>(
item).
className()
476 <<
" that is used in EDAlias " << std::get<Transients::kModuleLabel>(
item)
477 <<
".\nThis should not happen, contact framework developers";
478 ex.
addContext(
"Calling ProductRegistry::initializeLookupTables()");
481 auto const& containedTypeID = iterContainedType->second;
482 bool const hasContainedType = (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID());
483 if (not hasContainedType) {
487 if (elementTypesConsumed->find(containedTypeID) != elementTypesConsumed->end()) {
490 std::get<Transients::kModuleLabel>(
item),
491 std::get<Transients::kProductInstanceName>(
item),
492 std::get<Transients::kAliasForModuleLabel>(
item));
495 auto iterBaseTypes = containedTypeToBaseTypesMap.find(containedTypeID);
496 if (iterBaseTypes == containedTypeToBaseTypesMap.end()) {
499 for (
TypeWithDict const& baseType : iterBaseTypes->second) {
501 if (elementTypesConsumed->find(baseTypeID) != elementTypesConsumed->end()) {
504 std::get<Transients::kModuleLabel>(
item),
505 std::get<Transients::kProductInstanceName>(
item),
506 std::get<Transients::kAliasForModuleLabel>(
item));
511 std::make_move_iterator(elementAliases.begin()),
512 std::make_move_iterator(elementAliases.end()));
516 std::set<TypeID>
const* productTypesConsumed,
517 std::set<TypeID>
const* elementTypesConsumed,
518 std::map<TypeID, TypeID>
const& containedTypeMap,
519 std::map<
TypeID, std::vector<TypeWithDict>>& containedTypeToBaseTypesMap) {
520 std::vector<std::string> missingDictionaries;
521 std::set<std::string> consumedTypesWithMissingDictionaries;
523 if (productTypesConsumed) {
525 for (
auto const& consumedTypeID : *productTypesConsumed) {
529 if (containedTypeMap.find(consumedTypeID) == containedTypeMap.end()) {
534 consumedTypesWithMissingDictionaries.emplace(consumedTypeID.className());
537 bool transient =
false;
538 TDictAttributeMap* wp = wrappedType.getClass()->GetAttributeMap();
539 if (wp && wp->HasKey(
"persistent") && !strcmp(wp->GetPropertyAsString(
"persistent"),
"false")) {
544 consumedTypesWithMissingDictionaries.emplace(consumedTypeID.className());
549 bool hasContainedType = (containedTypeID !=
TypeID(
typeid(
void)) && containedTypeID !=
TypeID());
550 if (hasContainedType) {
551 if (containedTypeToBaseTypesMap.find(containedTypeID) == containedTypeToBaseTypesMap.end()) {
552 std::vector<TypeWithDict> bases;
555 consumedTypesWithMissingDictionaries.emplace(consumedTypeID.className());
557 containedTypeToBaseTypesMap.insert(std::make_pair(containedTypeID, bases));
562 consumedTypesWithMissingDictionaries.emplace(consumedTypeID.className());
567 if (!missingDictionaries.empty()) {
569 "Calling ProductRegistry::initializeLookupTables, checking dictionaries for consumed products");
574 if (elementTypesConsumed) {
575 missingDictionaries.clear();
576 consumedTypesWithMissingDictionaries.clear();
577 for (
auto const& consumedTypeID : *elementTypesConsumed) {
578 if (containedTypeToBaseTypesMap.find(consumedTypeID) == containedTypeToBaseTypesMap.end()) {
579 std::vector<TypeWithDict> bases;
582 consumedTypesWithMissingDictionaries.emplace(consumedTypeID.className());
586 if (!missingDictionaries.empty()) {
588 "Calling ProductRegistry::initializeLookupTables, checking dictionaries for elements of products consumed "
599 <<
"The process name " << *processName <<
" was previously used for products in the input.\n"
600 <<
"Please modify the configuration file to use a distinct process name.\n"
601 <<
"Alternately, drop all input products using that process name and the\n"
602 <<
"descendants of those products.\n";
611 return itFind->second;
616 std::string_view moduleLabel,
617 std::string_view productInstanceName)
const {
618 auto aliasFields = [](
auto const&
item) {
619 return std::tie(std::get<Transients::kKind>(
item),
620 std::get<Transients::kType>(
item),
621 std::get<Transients::kModuleLabel>(
item),
622 std::get<Transients::kProductInstanceName>(
item));
624 auto const target = std::tuple(kindOfType, type, moduleLabel, productInstanceName);
629 [aliasFields](
auto const&
item,
auto const&
target) {
return aliasFields(item) <
target; });
630 std::vector<std::string>
ret;
632 ret.emplace_back(std::get<Transients::kAliasForModuleLabel>(*
found));
639 os << product.second <<
"\n-----\n";
tuple ret
prodAgent to be discontinued
void setProductProduced(BranchType branchType)
BranchType const & branchType() const
void throwMissingDictionariesException(std::vector< std::string > &missingDictionaries, std::string const &context)
unsigned int ProductResolverIndex
std::vector< std::tuple< KindOfType, TypeID, std::string, std::string, std::string >> AliasToOriginalVector
void throwIfNotFrozen() const
TypeID getContainedTypeFromWrapper(TypeID const &wrappedtypeID, std::string const &className)
std::vector< std::string > allBranchNames() const
std::map< BranchKey, BranchDescription > ProductList
bool public_base_classes(std::vector< std::string > &missingDictionaries, TypeID const &typeID, std::vector< TypeWithDict > &baseTypes)
bool anyProducts(BranchType const brType) const
void addElementTypesForAliases(std::set< TypeID > const *elementTypesConsumed, std::map< TypeID, TypeID > const &containedTypeMap, std::map< TypeID, std::vector< TypeWithDict >> const &containedTypeToBaseTypesMap)
std::string const & processName() const
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
ProductList::size_type size() const
void addLabelAlias(BranchDescription const &productdesc, std::string const &labelAlias, std::string const &instanceAlias)
AliasToOriginalVector aliasToOriginal_
virtual void addCalled(BranchDescription const &, bool iFromListener)
static TypeWithDict byName(std::string const &name)
ProductList const & productList() const
deep_tau::DeepTauBase::BasicDiscriminator bd
void initializeLookupTables(std::set< TypeID > const *productTypesConsumed, std::set< TypeID > const *elementTypesConsumed, std::string const *processName)
std::string const & moduleLabel() const
bool combinable(BranchDescription const &a, BranchDescription const &b)
bool checkDictionary(std::vector< std::string > &missingDictionaries, TypeID const &typeID)
void setUnscheduledProducts(std::set< std::string > const &unscheduledLabels)
TypeID unwrappedTypeID() const
void checkForDuplicateProcessName(BranchDescription const &desc, std::string const *processName) const
ProductResolverIndex & nextIndexValue(BranchType branchType)
bool checkClassDictionaries(std::vector< std::string > &missingDictionaries, TypeID const &typeID)
std::vector< BranchDescription const * > allBranchDescriptions() const
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
BranchID const & branchID() const
std::type_info const & typeInfo() const
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
void setFrozen(bool initializeLookupInfo=true)
void freezeIt(bool frozen=true)
void print(std::ostream &os) const
void checkDictionariesOfConsumedTypes(std::set< TypeID > const *productTypesConsumed, std::set< TypeID > const *elementTypesConsumed, std::map< TypeID, TypeID > const &containedTypeMap, std::map< TypeID, std::vector< TypeWithDict >> &containedTypeToBaseTypesMap)
std::array< ProductResolverIndex, NumBranchTypes > nextIndexValues_
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
std::array< edm::propagate_const< std::shared_ptr< ProductResolverIndexHelper > >, NumBranchTypes > productLookups_
std::string wrappedClassName(std::string const &iFullName)
void addContext(std::string const &context)
std::shared_ptr< ProductResolverIndexHelper const > productLookup(BranchType branchType) const
ProductResolverIndex const & getNextIndexValue(BranchType branchType) const
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
void throwIfFrozen() const
std::string const & className() const
void updateFromInput(ProductList const &other)
bool checkDictionaryOfWrappedType(std::vector< std::string > &missingDictionaries, TypeID const &unwrappedTypeID)
std::vector< std::string > aliasToModules(KindOfType kindOfType, TypeID const &type, std::string_view moduleLabel, std::string_view productInstanceName) const
ProductResolverIndex indexFrom(BranchID const &iID) const
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
std::map< BranchID, ProductResolverIndex > branchIDToIndex_
std::string className(const T &t)
void copyProduct(BranchDescription const &productdesc)
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)