Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:20

0001 #include "DataFormats/HGCalDigi/interface/HGCalElectronicsId.h"
0002 #include <iostream>
0003 #include <cassert>
0004 #include <string>
0005 #include <chrono>
0006 #include <random>
0007 
0008 // run for instance with:
0009 //
0010 //                         time HGCalElectronicsId 10000000000 => 8 sec
0011 // for a measureble amount of time taken
0012 // acceptas an additional argument for verbosity level
0013 
0014 int main(int argc, char** argv) {
0015   std::cout << "Basic check of HGCalElectronicsId class" << std::endl;
0016 
0017   // first command line argument is the number of trials
0018   unsigned long int repetitions = 100;
0019   if (argc > 1)
0020     repetitions = std::stoul(argv[1], nullptr, 0);
0021   std::cout << "\t + repetitions [int]: " << repetitions << std::endl;
0022 
0023   unsigned long int verbosity = 0;
0024   if (argc > 2)
0025     verbosity = std::stoul(argv[2], nullptr, 0);
0026 
0027   // init static values
0028   uint16_t fedid(0);
0029   uint8_t captureblock(0), econdidx(0), econderx(0), halfrocch(0);
0030 
0031   // http://www.cplusplus.com/reference/random/linear_congruential_engine/
0032   unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
0033   std::minstd_rand0 myrand(seed1);
0034 
0035   // do the trials: time/performance test and exploit randomisation to check
0036   unsigned long int u = 0;
0037   for (; u < repetitions; u++) {
0038     fedid = myrand() % 576;
0039     captureblock = myrand() % 10;
0040     econdidx = myrand() % 12;
0041     econderx = myrand() % 12;
0042     halfrocch = myrand() % 39;
0043 
0044     HGCalElectronicsId eid(fedid, captureblock, econdidx, econderx, halfrocch);
0045     assert(fedid == eid.fedId());
0046     assert(captureblock == eid.captureBlock());
0047     assert(econdidx == eid.econdIdx());
0048     assert(econderx == eid.econdeRx());
0049     assert(halfrocch == eid.halfrocChannel());
0050 
0051     if (verbosity > 0)
0052       eid.print(std::cout);
0053   }
0054 
0055   std::cout << "\nDone " << repetitions << "\t" << u << std::endl;
0056 
0057   return 0;
0058 }