File indexing completed on 2024-04-06 12:04:20
0001 #include "DataFormats/HGCalDigi/interface/HGCalDigiCollections.h"
0002 #include <iostream>
0003 #include <cassert>
0004 #include <string>
0005 #include <chrono>
0006 #include <random>
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 bool totOK(uint16_t tot_orig, uint16_t tot_read) {
0018 int delta(tot_read - tot_orig);
0019 return (delta >= -4 && delta <= 4);
0020 }
0021
0022 int main(int argc, char** argv) {
0023 std::cout << "Basic performance tests for HGCROCChannelDataFrame (pseudo-random seed set according to local time)\n"
0024 << std::endl;
0025 std::cout << "num parameters entered: " << argc << std::endl;
0026
0027
0028 unsigned long int repetitions = 100;
0029 if (argc > 1)
0030 repetitions = std::stoul(argv[1], nullptr, 0);
0031 std::cout << "\t + repetitions [int]: " << repetitions << std::endl;
0032
0033
0034 bool generateRandomValues = (argc > 2 ? true : false);
0035 std::cout << "\t + generateRandomValues [true/false]: " << generateRandomValues << "\n" << std::endl;
0036
0037
0038 uint16_t adc(125), adcm1(23), tot(10), toa(8);
0039 bool tc(false), tp(false), charMode(false);
0040
0041
0042 unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
0043 std::minstd_rand0 myrand(seed1);
0044
0045
0046 unsigned long int u = 0;
0047 for (; u < repetitions; u++) {
0048
0049 if (generateRandomValues) {
0050 adc = myrand() % 1024;
0051 adcm1 = myrand() % 1024;
0052 tot = myrand() % 2048;
0053 toa = myrand() % 1024;
0054 tc = myrand() % 2;
0055 tp = myrand() % 2;
0056 charMode = myrand() % 2;
0057 }
0058
0059 HGCROCChannelDataFrameSpec aSample;
0060 aSample.fill(charMode, tc, tp, adcm1, adc, tot, toa);
0061
0062 bool tc_read = aSample.tc();
0063 bool tp_read = aSample.tp();
0064 uint16_t adc_read = aSample.adc(charMode);
0065 uint16_t adcm1_read = aSample.adcm1(charMode);
0066 uint16_t tot_read = aSample.tot(charMode);
0067 uint16_t toa_read = aSample.toa();
0068 assert(tc == tc_read);
0069 assert(tp == tp_read);
0070
0071
0072
0073
0074
0075
0076 if (charMode) {
0077 assert(adcm1_read == 0);
0078 assert(adc == adc_read);
0079 assert(totOK(tot, tot_read));
0080 assert(toa == toa_read);
0081 } else {
0082 assert(adcm1 == adcm1_read);
0083 if (tc) {
0084 assert(adc_read == 0);
0085 assert(totOK(tot, tot_read));
0086 } else {
0087 assert(tot_read == 0);
0088 assert(adc == adc_read);
0089 }
0090 }
0091 }
0092
0093 std::cout << "\nDone " << repetitions << "\t" << u << std::endl;
0094
0095 return 0;
0096 }