Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-04 04:04:19

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   bool zside(false);
0029   uint16_t localfedid(0);
0030   uint8_t captureblock(0), econdidx(0), econderx(0), halfrocch(0);
0031 
0032   // http://www.cplusplus.com/reference/random/linear_congruential_engine/
0033   unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
0034   std::minstd_rand0 myrand(seed1);
0035 
0036   // do the trials: time/performance test and exploit randomisation to check
0037   unsigned long int u = 0;
0038   for (; u < repetitions; u++) {
0039     zside = (bool)myrand() % 2;
0040     localfedid = myrand() % 576;
0041     captureblock = myrand() % 10;
0042     econdidx = myrand() % 12;
0043     econderx = myrand() % 12;
0044     halfrocch = myrand() % 39;
0045     bool cmflag = ((halfrocch == 37) || (halfrocch == 38));
0046 
0047     HGCalElectronicsId eid(zside, localfedid, captureblock, econdidx, econderx, halfrocch);
0048     assert(zside == eid.zSide());
0049     assert(cmflag == eid.isCM());
0050     assert(localfedid == eid.localFEDId());
0051     assert(captureblock == eid.captureBlock());
0052     assert(econdidx == eid.econdIdx());
0053     assert(econderx == eid.econdeRx());
0054     assert(halfrocch == eid.halfrocChannel());
0055 
0056     if (verbosity > 0)
0057       eid.print(std::cout);
0058   }
0059 
0060   std::cout << "\nDone " << repetitions << "\t" << u << std::endl;
0061 
0062   return 0;
0063 }