Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:58

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   edm::InputTag tag1;
0060   if (tag1.label() != "" || tag1.instance() != "" || tag1.process() != "" || tag1.willSkipCurrentProcess()) {
0061     std::cout << "InputTag() failed" << std::endl;
0062     abort();
0063   }
0064 
0065   edm::InputTag tag2(std::string("a"), std::string("b"), std::string("c"));
0066   if (tag2.label() != "a" || tag2.instance() != "b" || tag2.process() != "c" || tag2.willSkipCurrentProcess()) {
0067     std::cout << "InputTag(string,string,string) failed" << std::endl;
0068     abort();
0069   }
0070 
0071   edm::InputTag tag3("d", "e", "f");
0072   if (tag3.label() != "d" || tag3.instance() != "e" || tag3.process() != "f" || tag3.willSkipCurrentProcess()) {
0073     std::cout << "InputTag(char*,char*,char*) failed" << std::endl;
0074     abort();
0075   }
0076 
0077   edm::InputTag tag4("g:h:i");
0078   if (tag4.label() != "g" || tag4.instance() != "h" || tag4.process() != "i" || tag4.willSkipCurrentProcess()) {
0079     std::cout << "InputTag(string) 1 failed" << std::endl;
0080     abort();
0081   }
0082 
0083   edm::InputTag tag5("g:h");
0084   if (tag5.label() != "g" || tag5.instance() != "h" || tag5.process() != "" || tag5.willSkipCurrentProcess()) {
0085     std::cout << "InputTag(string) 2 failed" << std::endl;
0086     abort();
0087   }
0088 
0089   edm::InputTag tag6("g");
0090   if (tag6.label() != "g" || tag6.instance() != "" || tag6.process() != "" || tag6.willSkipCurrentProcess()) {
0091     std::cout << "InputTag(string) 3 failed" << std::endl;
0092     abort();
0093   }
0094 
0095   edm::InputTag tag7(std::string("a"), std::string("b"), std::string("c"));
0096   edm::InputTag tag8(std::string("x"), std::string("b"), std::string("c"));
0097   if (!(tag2 == tag7) || tag4 == tag5 || tag5 == tag6 || tag7 == tag8) {
0098     std::cout << "InputTag::operator== failed" << std::endl;
0099     abort();
0100   }
0101 
0102   if (tag7.encode() != std::string("a:b:c") || tag5.encode() != std::string("g:h") ||
0103       tag6.encode() != std::string("g")) {
0104     std::cout << "InputTag::encode failed " << std::endl;
0105     abort();
0106   }
0107 
0108   edm::InputTag tag9(tag8);
0109   edm::InputTag tag11("a:b:c");
0110   edm::InputTag tag10(std::move(tag11));
0111   tag6 = tag10;
0112   tag5 = edm::InputTag("a:b:c");
0113   if (!(tag8 == tag9) || !(tag10 == tag7) || !(tag6 == tag10) || !(tag5 == tag10)) {
0114     std::cout << "InputTag::operator= or constructor, move or copy failed" << std::endl;
0115     abort();
0116   }
0117 
0118   edm::InputTag tag12("d", "e", "@skipCurrentProcess");
0119   if (tag12.label() != "d" || tag12.instance() != "e" || tag12.process() != "@skipCurrentProcess" ||
0120       !tag12.willSkipCurrentProcess()) {
0121     std::cout << "Test of tag12 failed" << std::endl;
0122     abort();
0123   }
0124 
0125   edm::InputTag tag12a(std::string("d"), std::string("e"), std::string("@skipCurrentProcess"));
0126   if (tag12a.label() != "d" || tag12a.instance() != "e" || tag12a.process() != "@skipCurrentProcess" ||
0127       !tag12a.willSkipCurrentProcess()) {
0128     std::cout << "Test of tag12a failed" << std::endl;
0129     abort();
0130   }
0131 
0132   edm::InputTag tag12b("d:e:@skipCurrentProcess");
0133   if (tag12b.label() != "d" || tag12b.instance() != "e" || tag12b.process() != "@skipCurrentProcess" ||
0134       !tag12b.willSkipCurrentProcess()) {
0135     std::cout << "Test of tag12b failed" << std::endl;
0136     abort();
0137   }
0138 
0139   edm::InputTag tag12c(tag12b);
0140   if (!tag12c.willSkipCurrentProcess()) {
0141     std::cout << "Test of tag12c failed" << std::endl;
0142     abort();
0143   }
0144 
0145   edm::InputTag tag12d;
0146   tag12d = tag12a;
0147   if (!tag12d.willSkipCurrentProcess()) {
0148     std::cout << "Test of tag12c failed" << std::endl;
0149     abort();
0150   }
0151 
0152   edm::InputTag tag13("d", "e", "@skipCurrentProcessx");
0153   if (tag13.willSkipCurrentProcess()) {
0154     std::cout << "Test of tag13 failed" << std::endl;
0155     abort();
0156   }
0157 
0158   edm::InputTag tag14("d", "e", "@skipCurrentProces");
0159   if (tag14.willSkipCurrentProcess()) {
0160     std::cout << "Test of tag14 failed" << std::endl;
0161     abort();
0162   }
0163 
0164   edm::InputTag tag15("d", "e", "@skipCurrentProcesx");
0165   if (tag15.willSkipCurrentProcess()) {
0166     std::cout << "Test of tag15 failed" << std::endl;
0167     abort();
0168   }
0169 
0170   unsigned int index = tag5.indexFor(testTypeID1, edm::InRun, reg1);
0171   if (index != edm::ProductResolverIndexInvalid) {
0172     std::cout << "InputTag::indexFor failed" << std::endl;
0173     abort();
0174   }
0175 
0176   tag5.tryToCacheIndex(5, testTypeID1, edm::InRun, reg1);
0177   tag5.tryToCacheIndex(6, testTypeID1, edm::InRun, reg1);
0178 
0179   index = tag5.indexFor(testTypeID1, edm::InRun, reg1);
0180   if (index != 5) {
0181     std::cout << "InputTag::indexFor call 2 failed" << std::endl;
0182     abort();
0183   }
0184 
0185   if (tag5.indexFor(testTypeID1, edm::InLumi, reg1) != edm::ProductResolverIndexInvalid ||
0186       tag5.indexFor(testTypeID1, edm::InRun, reg2) != edm::ProductResolverIndexInvalid ||
0187       tag5.indexFor(testTypeID2, edm::InRun, reg1) != edm::ProductResolverIndexInvalid) {
0188     std::cout << "InputTag::indexFor call 3 failed" << std::endl;
0189     abort();
0190   }
0191 
0192   for (unsigned int k = 0; k < 500; ++k) {
0193     edm::InputTag tag21("a:b:c");
0194     InputTagModifier inputTagModifier(&tag21);
0195     oneapi::tbb::parallel_for(oneapi::tbb::blocked_range<int>(0, 20, 1), inputTagModifier);
0196   }
0197   return 0;
0198 }