Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-18 09:22:11

0001 #include "getCaloTemp.C"
0002 
0003 #include <format>
0004 #include <fstream>
0005 #include <set>
0006 
0007 //how to run example:root -l -q 'loopCaloTemp.C("runList_pp_2024.txt","HCALOUT")'
0008 
0009 void loopCaloTemp(const char* runListFile = "runList.txt",
0010                   const char* detector    = "HCALIN",
0011                   int max_retries         = 5,
0012                   int backoff_ms          = 500,
0013                   bool skip_if_exists     = true,
0014                   int passes              = 1)   // set >1 to automatically re-try failed runs
0015 {
0016 
0017   TString outdir;
0018 
0019   if (TString(detector) == "HCALOUT") {
0020     outdir = "temp_ohcal";
0021   }
0022   else if (TString(detector) == "HCALIN") {
0023     outdir = "temp_ihcal";
0024   }
0025   else if (TString(detector) == "CEMC") {
0026     outdir = "temp_emcal";
0027   }
0028   else {
0029     outdir = "temp_other";
0030   }
0031 
0032   gSystem->mkdir(outdir, kTRUE);
0033 
0034   std::ifstream fin(runListFile);
0035   if (!fin.is_open()) {
0036     std::cerr << "Error: Could not open " << runListFile << std::endl;
0037     return;
0038   }
0039 
0040   std::vector<int> runs;
0041   for (int r; fin >> r;) runs.push_back(r);
0042   fin.close();
0043 
0044   std::cout << "Found " << runs.size() << " runs in " << runListFile << std::endl;
0045 
0046   std::set<int> pending(runs.begin(), runs.end());
0047 
0048   for (int pass = 1; pass <= std::max(1, passes) && !pending.empty(); ++pass) {
0049     std::cout << "\n=== Pass " << pass << " (" << pending.size() << " runs) ===\n";
0050     std::set<int> failures;
0051 
0052   for (int r : pending) {
0053   // Expected output file
0054   
0055     TString outname = std::format("{}/{}_temp_{}.root",
0056                              outdir.Data(),
0057                              TString(detector).Data(),
0058                              r);
0059 
0060   // Skip if already exists in outdir
0061   if (skip_if_exists && !gSystem->AccessPathName(outname.Data())) {
0062      std::cout << "[skip] " << outname << " already exists for run " << r << "\n";
0063      continue;
0064     }
0065 
0066   std::cout << "Processing run " << r << " ..." << std::endl;
0067   Long64_t before = gSystem->Now();
0068   getCaloTemp(r, detector, max_retries, backoff_ms);
0069   Long64_t after  = gSystem->Now();
0070 
0071   // ---- simple existence check ----
0072   if (!gSystem->AccessPathName(outname.Data())) {
0073     std::cout << "  -> OK (" << (after - before) << " ms)\n";
0074   } else {
0075     std::cerr << "  -> FAILED for run " << r << "\n";
0076     failures.insert(r);
0077   }
0078 }
0079 
0080 
0081   // Write failure list for this pass
0082   std::ofstream flog(std::format("failed_runs_pass{}_{}.txt", pass, detector));
0083   for (int r : failures) flog << r << "\n";
0084   flog.close();
0085   std::cout << "Pass " << pass << " failures written to failed_runs_pass"
0086         << pass << "_" << detector << ".txt" << std::endl;
0087 
0088   // Prepare for next pass
0089   pending = failures;
0090   }
0091 
0092   std::cout << "\nAll passes done." << std::endl;
0093 }
0094