File indexing completed on 2025-08-06 08:14:30
0001 #include <iostream>
0002 #include <fstream>
0003 #include <sstream>
0004 #include <string>
0005 #include <vector>
0006 #include <regex>
0007
0008 bool check_clock_file(const std::string &clock_file_path) {
0009 std::ifstream clock_file(clock_file_path);
0010
0011 std::string line;
0012 std::vector<int> section_positions(18, -1);
0013 std::vector<int> section_clock_value(18, -1);
0014 int line_number = 0;
0015
0016 std::regex section_regex(R"(^[0-9]+$)");
0017 std::regex clock_value_regex(R"(^\s+[0-9]+(\s+[0-9]+)*$)");
0018
0019 while (std::getline(clock_file, line)) {
0020 line_number++;
0021
0022 if (std::regex_match(line, section_regex)) {
0023 int section_number = std::stoi(line);
0024
0025 if (section_number < 0 || section_number > 17) {
0026 return false;
0027 }
0028 if (section_positions[section_number] != -1) {
0029 return false;
0030 }
0031
0032 section_positions[section_number] = line_number;
0033
0034 for (int i = 0; i < 8; ++i) {
0035 if (!std::getline(clock_file, line)) {
0036 return false;
0037 }
0038 line_number++;
0039 if (!std::regex_match(line, clock_value_regex)) {
0040 return false;
0041 }
0042 std::istringstream clock_line(line);
0043 int clock_value;
0044 while (clock_line >> clock_value) {
0045 if (section_clock_value[section_number] == -1) {
0046 section_clock_value[section_number] = clock_value;
0047 } else if (clock_value != section_clock_value[section_number]) {
0048 return false;
0049 }
0050 }
0051 }
0052 }
0053 }
0054
0055 for (int i = 0; i < 18; ++i) {
0056 if (section_positions[i] == -1) {
0057 return false;
0058 }
0059 }
0060
0061 return true;
0062 }
0063
0064 void GoldenFEMrunListGenerator() {
0065 std::string runnumber_file_path = "GoldenGL1RunList.txt";
0066 std::string output_file_path = "GoldenFEMrunList.txt";
0067 std::ifstream runnumber_file(runnumber_file_path);
0068 std::ofstream output_file(output_file_path);
0069
0070 int passedRunCount = 0;
0071 std::string runnumber;
0072 while (std::getline(runnumber_file, runnumber)) {
0073 std::string clock_file_path = "list_allFEM_clock/FEM_clock_" + runnumber + ".txt";
0074 if (check_clock_file(clock_file_path)) {
0075 output_file << runnumber << std::endl;
0076 passedRunCount++;
0077 }
0078 }
0079
0080 std::cout << "Number of FEM GOLDEN runs saved to " << output_file_path << ": " << passedRunCount << std::endl;
0081 runnumber_file.close();
0082 output_file.close();
0083 }
0084
0085