Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-05 02:47:27

0001 #include "DataFormats/Provenance/interface/ProductResolverIndexHelper.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/Utilities/interface/TypeID.h"
0004 #include "FWCore/Utilities/interface/CPUTimer.h"
0005 #include "DataFormats/Provenance/interface/EventID.h"
0006 #include "FWCore/Utilities/interface/EDMException.h"
0007 #include "FWCore/Utilities/interface/ProductKindOfType.h"
0008 
0009 #include "TClass.h"
0010 
0011 #include <iostream>
0012 #include <iomanip>
0013 #include <string>
0014 #include <fstream>
0015 #include <istream>
0016 #include <vector>
0017 
0018 // This program will run and time the ProductResolverIndexHelper class.
0019 // Before running it one needs to create a text file named
0020 // "log3" which contains a list of products. I generated
0021 // this file as follows:
0022 
0023 // I started using CMSSW_6_1_0_pre7 with this command:
0024 // runTheMatrix.py -l 24.0
0025 // Then I reran step3 with the the last line of the following code
0026 // fragment added in ProductRegistry.cc to print out the products
0027 // as they are added to the lookup table.
0028 /*
0029   void ProductRegistry::initializeLookupTables() const {
0030 
0031     ...
0032 
0033           fillLookup(type, index, pBD, tempProductLookupMap);
0034           std::cout << "initializeLookups: " << desc.className() << "\n"
0035                     << "initializeLookups: " << desc.moduleLabel() << "\n" 
0036                     << "initializeLookups: " << desc.productInstanceName() << "\n"
0037                     << "initializeLookups: " << desc.processName() << "\n"; 
0038 */
0039 
0040 // Then run  it with this command
0041 //   cmsRun step3_RAW2DIGI_L1Reco_RECO_VALIDATION_DQM.py > & log2
0042 // Then grep out the interesting lines with this command
0043 //   grep initializeLook log2 > log3
0044 
0045 // Just running the test will print the important timing info
0046 // to std::cout. In addition if you want to run the program
0047 // under igprof, use the following commands:
0048 // igprof -d -pp -o igprof.pp.gz ../tmp/slc5_amd64_gcc472/src/DataFormats/Provenance/test/productResolverIndexHelperTest/productResolverIndexHelperTest > & logfile &
0049 // igprof-analyse -d -v -g igprof.pp.gz > & igreport_perfres
0050 // more igreport_perfres
0051 
0052 using namespace edm;
0053 
0054 namespace edmtestlookup {
0055 
0056   class Names {
0057   public:
0058     std::string className;
0059     std::string label;
0060     std::string instance;
0061     std::string process;
0062     TypeID typeID;
0063   };
0064 }  // namespace edmtestlookup
0065 
0066 using namespace edmtestlookup;
0067 
0068 int main() {
0069   //Read the file listing all the products
0070   std::string line1;
0071   std::string line2;
0072   std::string line3;
0073   std::string line4;
0074 
0075   Names names;
0076   std::vector<Names> vNames;
0077 
0078   std::ifstream myfile("log3");
0079   if (myfile.is_open()) {
0080     while (myfile.good()) {
0081       getline(myfile, line1);
0082       if (!myfile.good())
0083         break;
0084       getline(myfile, line2);
0085       if (!myfile.good())
0086         break;
0087       getline(myfile, line3);
0088       if (!myfile.good())
0089         break;
0090       getline(myfile, line4);
0091       if (!myfile.good())
0092         break;
0093 
0094       std::istringstream ss1(line1);
0095       std::istringstream ss2(line2);
0096       std::istringstream ss3(line3);
0097       std::istringstream ss4(line4);
0098 
0099       std::string word;
0100 
0101       word = ss1.str();
0102       names.className = word.substr(19);
0103       ss2 >> word >> names.label;
0104       ss3 >> word >> names.instance;
0105       ss4 >> word >> names.process;
0106 
0107       // if (names.className == "trigger::TriggerFilterObjectWithRefs") continue;
0108       // if (vNames.size() > 99) continue;
0109 
0110       // std::cout << names.className << " " << names.label << " " << names.instance << " " << names.process << std::endl;
0111 
0112       vNames.push_back(names);
0113     }
0114     myfile.close();
0115   } else {
0116     std::cout << "ERROR: could not open file log3\n";
0117   }
0118 
0119   std::cout << "vNames.size = " << vNames.size() << "\n";
0120 
0121   edm::CPUTimer timer;
0122 
0123   timer.start();
0124   edm::ProductResolverIndexHelper phih;
0125   timer.stop();
0126 
0127   std::vector<unsigned int> savedIndexes;
0128 
0129   for (auto& n : vNames) {
0130     // Most of the initialization time in this test is
0131     // in this line as the dictionaries are loaded. Depending
0132     // on the number of loops and types, this also may be
0133     // most of the total time as well.
0134     TClass* clss = TClass::GetClass(n.className.c_str());
0135 
0136     if (n.className == "bool") {
0137       n.typeID = TypeID(typeid(bool));
0138     } else if (n.className == "double") {
0139       n.typeID = TypeID(typeid(double));
0140     } else {
0141       n.typeID = TypeID(*clss->GetTypeInfo());
0142     }
0143 
0144     timer.start();
0145     phih.insert(n.typeID, n.label.c_str(), n.instance.c_str(), n.process.c_str());
0146     timer.stop();
0147   }
0148   std::cout << "Filling Time: real " << timer.realTime() << " cpu " << timer.cpuTime() << std::endl;
0149   timer.reset();
0150 
0151   timer.start();
0152   phih.setFrozen();
0153   timer.stop();
0154   std::cout << "Freezing Time: real " << timer.realTime() << " cpu " << timer.cpuTime() << std::endl;
0155   timer.reset();
0156 
0157   // phih.print(std::cout);
0158 
0159   timer.start();
0160 
0161   unsigned sum = 0;
0162 
0163   for (unsigned j = 0; j < 100; ++j) {
0164     for (auto& n : vNames) {
0165       unsigned temp = 1;
0166       // if (n.className == "trigger::TriggerFilterObjectWithRefs") continue;
0167       temp = phih.index(PRODUCT_TYPE, n.typeID, n.label.c_str(), n.instance.c_str(), n.process.c_str());
0168 
0169       sum += temp;
0170     }
0171   }
0172   timer.stop();
0173 
0174   std::cout << "index loop time = real " << timer.realTime() << " cpu " << timer.cpuTime() << std::endl;
0175   return sum;
0176 }