1 #ifndef DataFormats_Common_getThinned_implementation_h 2 #define DataFormats_Common_getThinned_implementation_h 67 template <
typename F1,
typename F2,
typename F3>
72 F2 getThinnedAssociation,
79 if (associatedBranches == iEnd) {
82 bool const slimmedAllowed = (associatedBranches + 1 == iEnd);
83 if (slimmedAllowed and associatedBranches->isSlimmed()) {
85 ThinnedAssociation const* slimmedAssociation = getThinnedAssociation(associatedBranches->association());
86 if (slimmedAssociation ==
nullptr or 93 if (slimmedIndex.has_value()) {
101 for (; associatedBranches != iEnd; ++associatedBranches) {
102 if (associatedBranches->isSlimmed()) {
106 ThinnedAssociation const* thinnedAssociation = getThinnedAssociation(associatedBranches->association());
107 if (thinnedAssociation ==
nullptr)
110 if (associatedBranches->parent() != pidToBid(thinnedAssociation->
parentCollectionID())) {
116 if (not thinnedIndex.has_value()) {
122 WrapperBase const* thinnedCollection = getByProductID(thinnedCollectionPID);
123 if (thinnedCollection !=
nullptr) {
131 thinnedAssociationsHelper,
133 getThinnedAssociation,
135 if (thinnedOrSlimmed.hasThinned()
or (slimmedAllowed and thinnedOrSlimmed.hasSlimmed())) {
136 return thinnedOrSlimmed;
144 std::vector<WrapperBase const*>
const& foundContainers,
146 unsigned const nKeys =
keys.size();
149 for (
unsigned k = 0;
k < nKeys; ++
k) {
151 if (foundContainers[
k] !=
nullptr) {
159 if (
auto thinnedIndex = thinnedAssociation->
getThinnedIndex(
keys[
k]); thinnedIndex.has_value()) {
160 thinnedIndexes[
k] = *thinnedIndex;
187 template <
typename F1,
typename F2,
typename F3>
192 F2 getThinnedAssociation,
194 std::vector<WrapperBase const*>& foundContainers,
195 std::vector<unsigned int>&
keys) {
201 if (associatedBranches == iEnd) {
204 bool const slimmedAllowed = associatedBranches + 1 == iEnd;
205 if (slimmedAllowed and associatedBranches->isSlimmed()) {
207 ThinnedAssociation const* slimmedAssociation = getThinnedAssociation(associatedBranches->association());
208 if (slimmedAssociation ==
nullptr or 223 for (; associatedBranches != iEnd; ++associatedBranches) {
224 if (associatedBranches->isSlimmed()) {
228 ThinnedAssociation const* thinnedAssociation = getThinnedAssociation(associatedBranches->association());
229 if (thinnedAssociation ==
nullptr)
232 if (associatedBranches->parent() != pidToBid(thinnedAssociation->
parentCollectionID())) {
243 WrapperBase const* thinnedCollection = getByProductID(thinnedCollectionPID);
244 unsigned const nKeys =
keys.size();
245 if (thinnedCollection ==
nullptr) {
249 thinnedAssociationsHelper,
251 getThinnedAssociation,
255 if (slimmedAllowed and slimmed.has_value()) {
258 for (
unsigned k = 0;
k < nKeys; ++
k) {
259 if (foundContainers[
k] ==
nullptr)
263 keys[
k] = thinnedIndexes[
k];
266 for (
unsigned k = 0;
k < nKeys; ++
k) {
269 keys[
k] = thinnedIndexes[
k];
270 foundContainers[
k] = thinnedCollection;
287 template <
typename F1,
typename F2,
typename F3>
293 F2 getThinnedAssociation,
296 pid,
key, thinnedAssociationsHelper, pidToBid, getThinnedAssociation, getByProductID);
298 if (thinnedOrSlimmed.hasThinned()) {
299 return thinnedOrSlimmed.thinnedProduct();
300 }
else if (thinnedOrSlimmed.hasSlimmed()) {
301 auto [slimmedAssociation, slimmedIndex] = thinnedOrSlimmed.slimmedAssociation();
302 ProductID const& slimmedCollectionPID = slimmedAssociation->thinnedCollectionID();
303 WrapperBase const* slimmedCollection = getByProductID(slimmedCollectionPID);
304 if (slimmedCollection ==
nullptr) {
309 thinnedAssociationsHelper,
311 getThinnedAssociation,
314 return std::tuple(slimmedCollection, slimmedIndex);
334 template <
typename F1,
typename F2,
typename F3>
338 F2 getThinnedAssociation,
340 std::vector<WrapperBase const*>& foundContainers,
341 std::vector<unsigned int>&
keys) {
343 pid, thinnedAssociationsHelper, pidToBid, getThinnedAssociation, getByProductID, foundContainers,
keys);
344 if (slimmed.has_value()) {
346 auto [slimmedAssociation, slimmedIndexes] =
std::move(*slimmed);
347 ProductID const& slimmedCollectionPID = slimmedAssociation->thinnedCollectionID();
348 WrapperBase const* slimmedCollection = getByProductID(slimmedCollectionPID);
349 unsigned const nKeys =
keys.size();
350 if (slimmedCollection ==
nullptr) {
352 thinnedAssociationsHelper,
354 getThinnedAssociation,
358 for (
unsigned k = 0;
k < nKeys; ++
k) {
359 if (foundContainers[
k] ==
nullptr)
363 keys[
k] = slimmedIndexes[
k];
366 for (
unsigned k = 0;
k < nKeys; ++
k) {
369 keys[
k] = slimmedIndexes[
k];
370 foundContainers[
k] = slimmedCollection;
394 template <
typename F>
402 F&& getThinnedAssociation) {
409 return [parentID]() {
411 <<
"Parent collection with ProductID " << parentID <<
" has not been thinned";
415 bool foundParent =
false;
416 std::vector<ThinnedAssociation const*> thinnedAssociationParentage;
417 while (not foundParent) {
419 auto branchesToThinned = std::find_if(
420 thinnedAssociationsHelper.
begin(), thinnedAssociationsHelper.
end(), [&thinned](
auto& associatedBranches) {
421 return associatedBranches.thinned() == thinned;
423 if (branchesToThinned == thinnedAssociationsHelper.
end()) {
424 return [parentID, thinnedID, thinnedIsThinned = not thinnedAssociationParentage.empty()]() {
426 ex <<
"Requested thinned collection with ProductID " << thinnedID
427 <<
" is not thinned from the parent collection with ProductID " << parentID
428 <<
" or from any collection thinned from it.";
429 if (not thinnedIsThinned) {
430 ex <<
" In fact, the collection " << thinnedID
431 <<
" passed in as a 'thinned' collection has not been thinned at all.";
437 ThinnedAssociation const* thinnedAssociation = getThinnedAssociation(branchesToThinned->association());
438 if (thinnedAssociation ==
nullptr) {
440 if (thinnedAssociationParentage.empty()) {
441 ex <<
"ThinnedAssociation corresponding to thinned collection with ProductID " << thinnedID
444 ex <<
"Intermediate ThinnedAssociation between the requested thinned ProductID " << thinnedID
445 <<
" and parent " << parentID <<
" not found.";
447 ex <<
" This should not happen.\nPlease contact the core framework developers.";
451 thinnedAssociationParentage.push_back(thinnedAssociation);
452 if (branchesToThinned->parent() ==
parent) {
456 thinned = branchesToThinned->parent();
462 unsigned int thinnedIndex =
key;
463 for (
auto iAssociation = thinnedAssociationParentage.rbegin(), iEnd = thinnedAssociationParentage.rend();
464 iAssociation != iEnd;
466 auto optIndex = (*iAssociation)->getThinnedIndex(thinnedIndex);
468 thinnedIndex = *optIndex;
470 return std::monostate{};
ProductID const & parentCollectionID() const
auto makeThinnedIndexes(std::vector< unsigned int > const &keys, std::vector< WrapperBase const *> const &foundContainers, ThinnedAssociation const *thinnedAssociation)
constexpr unsigned int kThinningDoNotLookForThisIndex
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &pid, unsigned int key, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID)
std::variant< unsigned int, GetThinnedKeyFromExceptionFactory, std::monostate > getThinnedKeyFrom_implementation(ProductID const &parentID, BranchID const &parent, unsigned int key, ProductID const &thinnedID, BranchID thinned, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F &&getThinnedAssociation)
void getThinnedProducts(ProductID const &pid, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID, std::vector< WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys)
ProductID const & thinnedCollectionID() const
std::optional< unsigned int > getThinnedIndex(unsigned int parentIndex) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
std::vector< ThinnedAssociationBranches >::const_iterator begin() const
std::vector< ThinnedAssociationBranches >::const_iterator end() const
WrapperBase const * thinnedProduct_
ThinnedOrSlimmedProduct getThinnedProductOnSlimmingDepth(ProductID const &pid, unsigned int key, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID)
std::tuple< ThinnedAssociation const *, unsigned int > slimmedAssociation() const
std::optional< std::tuple< ThinnedAssociation const *, std::vector< unsigned int > > > getThinnedProductsOnSlimmingDepth(ProductID const &pid, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID, std::vector< WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys)
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
ThinnedOrSlimmedProduct(ThinnedAssociation const *slimmed, unsigned int key)
std::function< edm::Exception()> GetThinnedKeyFromExceptionFactory
ThinnedOrSlimmedProduct(WrapperBase const *thinned, unsigned int key)
ThinnedOrSlimmedProduct()=default
ThinnedAssociation const * slimmedAssociation_
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
std::tuple< WrapperBase const *, unsigned int > thinnedProduct() const