File indexing completed on 2025-08-06 08:14:30
0001 #ifndef READSPINDB_C
0002 #define READSPINDB_C
0003
0004 #include <string>
0005 #include <iostream>
0006 #include <fstream>
0007
0008 #include <uspin/SpinDBContent.h>
0009 #include <uspin/SpinDBOutput.h>
0010
0011
0012 R__LOAD_LIBRARY(libuspin.so)
0013
0014 int ReadSpinDB(int runnumber, TH1D* h_spinQA, unsigned int qa_level = 0xffff);
0015
0016 void CheckRunsForSpin(std::string infilename)
0017 {
0018 std::ifstream infile;
0019 infile.open(infilename.c_str());
0020
0021
0022 std::string outfilename = "validspinruns.txt";
0023 std::ofstream outfile;
0024 std::cout << "outfilename = " << outfilename << std::endl;
0025 outfile.open(outfilename.c_str());
0026 if (outfile.is_open()) std::cout << "outfile is open!";
0027 else return -1;
0028
0029
0030 std::string rootfilename = "spinQAlog.root";
0031 TFile* rootfile = new TFile(rootfilename.c_str(), "RECREATE");
0032 rootfile->cd();
0033 TH1D* h_spinQA = new TH1D("h_spinQA", "Reason for Run Failing Spin QA;Reason;# Runs", 4, -0.5, 3.5);
0034 h_spinQA->GetXaxis()->SetBinLabel(1, "All Runs");
0035 h_spinQA->GetXaxis()->SetBinLabel(2, "Good Runs");
0036 h_spinQA->GetXaxis()->SetBinLabel(3, "BadRunFlag");
0037 h_spinQA->GetXaxis()->SetBinLabel(4, "GL1P Empty");
0038
0039
0040 int run;
0041 while (infile >> run) {
0042 bool has_spin = ReadSpinDB(run, h_spinQA);
0043
0044 if (has_spin) outfile << run << std::endl;
0045 }
0046
0047 rootfile->Write();
0048 TCanvas* c1 = new TCanvas("c1", "c1", 1600, 900);
0049 h_spinQA->Draw();
0050 c1->SaveAs("spinQAlog.pdf");
0051 rootfile->Close();
0052 delete c1;
0053
0054 infile.close();
0055 outfile.close();
0056 }
0057
0058
0059
0060
0061 int ReadSpinDB(int runnumber, TH1D* h_spinQA, unsigned int qa_level)
0062 {
0063 h_spinQA->Fill(0);
0064
0065 SpinDBContent spin_cont;
0066 SpinDBOutput spin_out("phnxrc");
0067
0068 spin_out.StoreDBContent(runnumber,runnumber,qa_level);
0069 spin_out.GetDBContentStore(spin_cont,runnumber);
0070
0071
0072
0073
0074 int badrun = spin_cont.GetBadRunFlag();
0075
0076
0077
0078 int bluespin[120] = {0};
0079 int yellspin[120] = {0};
0080
0081 for (int i = 0; i < 120; i++)
0082 {
0083 bluespin[i] = spin_cont.GetSpinPatternBlue(i);
0084
0085
0086 }
0087
0088
0089
0090 for (int i = 0; i < 120; i++)
0091 {
0092 yellspin[i] = spin_cont.GetSpinPatternYellow(i);
0093
0094
0095 }
0096
0097
0098
0099
0100
0101 long int gl1pScalers[120] = {0};
0102 long int gl1pSum = 0;
0103
0104 for (int i = 0; i < 120; i++)
0105 {
0106 gl1pScalers[i] = spin_cont.GetScalerMbdNoCut(i);
0107 gl1pSum += gl1pScalers[i];
0108
0109
0110 }
0111
0112
0113
0114 if (badrun) {
0115 h_spinQA->Fill(2);
0116 return false;
0117 }
0118 if (gl1pSum == 0) {
0119 h_spinQA->Fill(3);
0120 return false;
0121 }
0122 h_spinQA->Fill(1);
0123 return true;
0124
0125 }
0126
0127 #endif