Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:14

0001 
0002 #include "FWCore/Utilities/interface/InputTag.h"
0003 #include "FWCore/Utilities/interface/TypeID.h"
0004 
0005 #include "oneapi/tbb/parallel_for.h"
0006 #include "oneapi/tbb/blocked_range.h"
0007 
0008 #include <cstdlib>
0009 #include <iostream>
0010 #include <string>
0011 
0012 namespace edm {
0013   class ProductRegistry;
0014 }
0015 
0016 // This is just for the test. Do not dereference the pointers.
0017 // They points to nothing legal.
0018 edm::ProductRegistry* reg1 = reinterpret_cast<edm::ProductRegistry*>(1);
0019 edm::ProductRegistry* reg2 = reinterpret_cast<edm::ProductRegistry*>(2);
0020 
0021 class TypeToTestInputTag1 {};
0022 class TypeToTestInputTag2 {};
0023 TypeToTestInputTag1 typeToTestInputTag1;
0024 TypeToTestInputTag2 typeToTestInputTag2;
0025 
0026 edm::TypeID testTypeID1(typeToTestInputTag1);
0027 edm::TypeID testTypeID2(typeToTestInputTag2);
0028 
0029 class InputTagModifier {
0030   edm::InputTag* inputTag;
0031 
0032 public:
0033   InputTagModifier(edm::InputTag* i) : inputTag(i) {}
0034 
0035   void operator()(oneapi::tbb::blocked_range<int> const& r) const {
0036     for (int i = r.begin(); i != r.end(); i++) {
0037       for (unsigned int j = 0; j < 10000; ++j) {
0038         unsigned int index = inputTag->indexFor(testTypeID1, edm::InRun, reg1);
0039         if (index != 5 && index != edm::ProductResolverIndexInvalid)
0040           abort();
0041         // std::cout << "a\n";
0042       }
0043       for (unsigned int j = 0; j < 100; ++j) {
0044         inputTag->tryToCacheIndex(5, testTypeID1, edm::InRun, reg1);
0045         // std::cout << "b\n";
0046       }
0047       for (unsigned int j = 0; j < 1000; ++j) {
0048         unsigned int index = inputTag->indexFor(testTypeID1, edm::InRun, reg1);
0049         // if (index != 5) abort(); // This can fail!
0050         // std::cout << index << " c\n";
0051         if (index != 5 && index != edm::ProductResolverIndexInvalid)
0052           abort();
0053       }
0054     }
0055   }
0056 };
0057 
0058 int main() {
0059   for (unsigned int k = 0; k < 500; ++k) {
0060     edm::InputTag tag21("a:b:c");
0061     InputTagModifier inputTagModifier(&tag21);
0062     oneapi::tbb::parallel_for(oneapi::tbb::blocked_range<int>(0, 20, 1), inputTagModifier);
0063   }
0064   return 0;
0065 }