Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:10

0001 // -- c++ includes --
0002 #include <filesystem>
0003 #include <fstream>
0004 #include <iomanip>
0005 #include <iostream>
0006 #include <string>
0007 
0008 // -- root includes --
0009 #include <TFile.h>
0010 #include <TChain.h>
0011 
0012 #include <calobase/TowerInfoDefs.h>
0013 
0014 using std::cerr;
0015 using std::cout;
0016 using std::endl;
0017 using std::max;
0018 using std::min;
0019 using std::ofstream;
0020 using std::pair;
0021 using std::string;
0022 using std::stringstream;
0023 using std::to_string;
0024 using std::vector;
0025 
0026 namespace fs = std::filesystem;
0027 
0028 namespace myAnalysis
0029 {
0030     void analyze();
0031     Int_t readFiles(const string &input);
0032     vector<string> files;
0033 }  // namespace myAnalysis
0034 
0035 Int_t myAnalysis::readFiles(const string &input)
0036 {
0037   // Create an input stream
0038   std::ifstream file(input);
0039 
0040   // Check if the file was successfully opened
0041   if (!file.is_open())
0042   {
0043     cerr << "Failed to open file list: " << input << endl;
0044     return 1;
0045   }
0046 
0047   cout << "Reading Files" << endl;
0048   cout << "======================================" << endl;
0049 
0050   string line;
0051   while (std::getline(file, line))
0052   {
0053     cout << "Reading File: " << line << endl;
0054     files.push_back(line);
0055   }
0056 
0057   // Close the file
0058   file.close();
0059 
0060   return 0;
0061 }
0062 
0063 void myAnalysis::analyze()
0064 {
0065     Int_t badFiles = 0;
0066     for(UInt_t i = 0; i < files.size(); ++i) {
0067         string file = files[i];
0068         cout << "Processing: " << fs::path(file).filename() << ", " << i*100./static_cast<Double_t>(files.size()) << " %" << endl;
0069         TChain* chain = new TChain("Multiple");
0070         chain->Add(file.c_str());
0071 
0072         Int_t id;
0073         Float_t time;
0074 
0075         chain->SetBranchAddress("IID", &id);
0076         chain->SetBranchAddress("Ftime", &time);
0077 
0078         Int_t ctr = 0;
0079 
0080         for(UInt_t j = 0; j < chain->GetEntries(); ++j) {
0081             chain->GetEntry(j);
0082             if(std::isfinite(time)) ++ctr;
0083             // cout << "id: " << id << ", time: " << time << endl;
0084         }
0085 
0086         if(ctr != chain->GetEntries()) ++badFiles;
0087 
0088         delete chain;
0089     }
0090     cout << "Bad Files: " << badFiles << endl;
0091 }
0092 
0093 void printStats(const string &input)
0094 {
0095   cout << "#############################" << endl;
0096   cout << "Run Parameters" << endl;
0097   cout << "input: " << input << endl;
0098   cout << "#############################" << endl;
0099 
0100   myAnalysis::readFiles(input);
0101   myAnalysis::analyze();
0102 }
0103 
0104 #ifndef __CINT__
0105 Int_t main(Int_t argc, const char* const argv[])
0106 {
0107   if (argc < 2 || argc > 2)
0108   {
0109     cout << "usage: ./genStatus input" << endl;
0110     cout << "input: input list" << endl;
0111     return 1;
0112   }
0113 
0114   printStats(argv[1]);
0115 
0116   cout << "======================================" << endl;
0117   cout << "done" << endl;
0118   return 0;
0119 }
0120 #endif