Back to home page

sPhenix code displayed by LXR

 
 

    


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 <map>
0007 
0008 struct Packet {
0009     std::string name;
0010     int eventNumber;
0011 };
0012 
0013 bool checkRunSEB(const std::vector<Packet>& packets, std::ofstream& errorFile) {
0014   bool isgood = true;
0015 
0016   if (packets[0].name != "gl1daq") {
0017     errorFile << "  Run has no gl1daq packets." << std::endl;
0018     isgood = false;
0019   }
0020   for (int i = 0; i <= 17; ++i) {
0021     std::string sebName = std::string("seb") + (i < 10 ? "0" : "") + std::to_string(i);
0022     bool found = false;
0023     for (const auto& packet : packets) {
0024       if (packet.name == sebName) {
0025         found = true;
0026         break;
0027       }
0028     }
0029     if (!found) {
0030       errorFile << "  Run has no " << sebName << " packets." << std::endl;
0031       isgood = false;
0032     }
0033   }
0034 
0035   return isgood;
0036 }
0037 
0038 bool chekRunEvent(const std::vector<Packet>& packets, std::ofstream& errorFile) {
0039   bool isgood = true;
0040 
0041   int gl1daqEvents = packets[0].eventNumber;
0042   if (gl1daqEvents < 500000) {
0043     errorFile << "  Run has gl1daq event number " << gl1daqEvents << " which is too small." << std::endl;
0044     isgood = false;
0045   }
0046 
0047   return isgood;
0048 }
0049 
0050 bool checkRunGL1(const std::vector<Packet>& packets, std::ofstream& errorFile) {
0051   bool isgood = true;
0052 
0053   int gl1daqEvents = packets[0].eventNumber;
0054   int failedpackets = 0;
0055   for (size_t i = 1; i < packets.size(); ++i) {
0056     if (packets[i].eventNumber != gl1daqEvents - 1) {
0057       int diff = packets[i].eventNumber - gl1daqEvents + 1;
0058       if (diff < -500) {
0059         errorFile << "  Packet " << packets[i].name << " has event number " << packets[i].eventNumber << " while big difference in gl1daq with " << gl1daqEvents << std::endl;
0060         isgood = false;
0061       } else {
0062         errorFile << "  Packet " << packets[i].name << " has event number " << packets[i].eventNumber << " while gl1daq has " << gl1daqEvents << std::endl;
0063         failedpackets++;
0064       }
0065     }
0066   }
0067   if (failedpackets > 2) {
0068     errorFile << "  Run has " << failedpackets << " packets with wrong event numbers." << std::endl;
0069     isgood = false;
0070   }
0071 
0072   return isgood;
0073 }
0074 
0075 void analyzeRuns(const std::string& inputFileName, const std::string& outputFileName1) {
0076   std::ifstream inputFile(inputFileName);
0077   std::ofstream outputFile1(outputFileName1);
0078   std::ofstream errorFile("list_eventnumber_errorlog.txt");
0079 
0080   if (!inputFile.is_open() || !outputFile1.is_open() || !errorFile.is_open()) {
0081     std::cerr << "Error opening file(s)." << std::endl;
0082     return;
0083   }
0084 
0085   std::map<int, std::vector<Packet>> runPackets;
0086   std::string line;
0087 
0088   while (std::getline(inputFile, line)) {
0089     std::istringstream iss(line);
0090     int runNumber, eventNumber;
0091     std::string packetName;
0092 
0093     if (!(iss >> runNumber >> packetName >> eventNumber)) {
0094       std::cerr << "Error reading line: " << line << std::endl;
0095       continue;
0096     }
0097 
0098     runPackets[runNumber].push_back({packetName, eventNumber});
0099   }
0100 
0101   int passedRunCount = 0;
0102   for (const auto& run : runPackets) {
0103     errorFile << run.first << std::endl;
0104     if (checkRunSEB(run.second, errorFile) && chekRunEvent(run.second, errorFile) && checkRunGL1(run.second, errorFile)) {
0105       outputFile1 << run.first << std::endl;
0106       passedRunCount++;
0107     }
0108   }
0109   std::cout << "Number of GL1 GOLDEN runs saved to " << outputFileName1 << ": " << passedRunCount << std::endl;
0110 
0111   inputFile.close();
0112   outputFile1.close();
0113   errorFile.close();
0114 }
0115 
0116 void GoldenGL1RunListGenerator() {
0117   analyzeRuns("EventNumberList_GoldenEmcalRuns.txt", "GoldenGL1RunList.txt");
0118 }
0119 
0120