File indexing completed on 2024-04-06 11:58:01
0001 #include <string>
0002 #include <fstream>
0003 #include <sstream>
0004 #include <iostream>
0005 #include <cstdlib>
0006
0007 int main (int argc, char* argv[])
0008 {
0009 if (argc != 3) {
0010 std::cout << "Usage:" << std::endl;
0011 std::cout << " " << argv[0] << " <input TPG.txt filename> <threshold in ADC count> " << std::endl;
0012 exit(-1);
0013 }
0014
0015 std::string filename = argv[1] ;
0016 std::string s_threshold = argv[2] ;
0017 int threshold = atoi(s_threshold.c_str()) ;
0018
0019 if (threshold<0 || threshold>1023) {
0020 std::cerr << "your threshold "<<std::dec<<threshold<< " must be in the range [0,1024]" << std::endl ;
0021 }
0022
0023 std::cout << "Producing TPG_threshold_" << threshold << ".txt with LUT threshold = " << threshold << std::endl ;
0024
0025 std::string dataCard ;
0026 std::ifstream infile ;
0027
0028 int data;
0029 std::stringstream oufilename ;
0030 oufilename << "TPG_threshold_" << threshold << ".txt" ;
0031 std::ofstream oufile(oufilename.str().c_str()) ;
0032 std::string str ;
0033
0034 infile.open(filename.c_str()) ;
0035
0036 if (infile.is_open()) {
0037 while (!infile.eof()) {
0038
0039 getline (infile,str) ;
0040
0041 int pos = int(str.find("LUT")) ;
0042 if (pos == 0) {
0043 oufile << str << std::endl ;
0044 for (int i=0 ; i <1024 ; i++) {
0045 infile >> std::hex >> data ;
0046 if (i <= threshold) data = 0 ;
0047 if (i < 1023) oufile << "0x" << std::hex << data << " " ;
0048 else oufile << "0x" << std::hex << data ;
0049 }
0050 }
0051 else oufile << str << std::endl ;
0052
0053 }
0054 }
0055
0056 return 0;
0057 }