Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:42

0001 #include <Riostream.h>
0002 #include <TDirectory.h>
0003 #include <TFile.h>
0004 #include <TROOT.h>
0005 #include <TStyle.h>
0006 #include <TKey.h>
0007 #include <TH1.h>
0008 #include <TH2.h>
0009 #include <TH2D.h>
0010 #include <TCanvas.h>
0011 #include <TGraph.h>
0012 #include <TPaveStats.h>
0013 #include <TText.h>
0014 #include <TLegend.h>
0015 #include <string>
0016 #include <utility>
0017 #include <vector>
0018 #include <sstream>
0019 #include <algorithm>
0020 #include <TString.h>
0021 #include <TColor.h>
0022 #include <dirent.h>
0023 
0024 #include "check_runcomplete.h"
0025 
0026 //using namespace std;
0027 
0028 int main(int argc, char *argv[]) {
0029   if (argc == 2) {
0030     char *cfile = argv[1];
0031 
0032     std::cout << "ready to check file " << cfile << std::endl;
0033 
0034     int returncode = check_runcomplete(cfile);
0035     if (returncode == 0)
0036       std::cout << "DQM file is ok" << std::endl;
0037 
0038     return returncode;
0039 
0040   } else {
0041     std::cout << "Too few arguments: " << argc << std::endl;
0042     return -1;
0043   }
0044 
0045   return -9;
0046 }
0047 
0048 int check_runcomplete(std::string filename) {
0049   int runflag = read_runflag(filename);
0050   if (runflag == 1) {
0051     printf("************************************\n");
0052     printf("**\n");
0053     printf("** W A R N I N G: the DQM file %s does not exist", filename.c_str());
0054     printf("**\n");
0055     printf("************************************\n");
0056   } else if (runflag == 2) {
0057     printf("************************************\n");
0058     printf("**\n");
0059     printf("** W A R N I N G: the DQM file %s is incomplete", filename.c_str());
0060     printf("**\n");
0061     printf("************************************\n");
0062   } else if (runflag != 0) {
0063     printf("************************************\n");
0064     printf("**\n");
0065     printf("** W A R N I N G: problems found in the DQM file %s", filename.c_str());
0066     printf("**\n");
0067     printf("************************************\n");
0068   }
0069   return runflag;
0070 }
0071 
0072 int read_runflag(std::string filename) {
0073   std::string nrun = filename.substr(filename.find("_R000") + 5, 6);
0074 
0075   TFile *dqmfile = TFile::Open(filename.c_str(), "READ");
0076 
0077   if (dqmfile == nullptr)
0078     return 1;
0079 
0080   std::string infodir = "DQMData/Run " + nrun + "/Info/Run summary/ProvInfo";
0081   gDirectory->cd(infodir.c_str());
0082 
0083   TIter next(gDirectory->GetListOfKeys());
0084   TKey *key;
0085 
0086   int isruncomplete = -1;
0087 
0088   while ((key = dynamic_cast<TKey *>(next()))) {
0089     std::string svar = key->GetName();
0090     if (svar.empty())
0091       continue;
0092 
0093     if (svar.find("runIsComplete") != std::string::npos) {
0094       std::string statusflag = svar.substr(svar.rfind('<') - 1, 1);
0095       isruncomplete = atoi(statusflag.c_str());
0096     }
0097   }
0098 
0099   dqmfile->Close();
0100 
0101   if (isruncomplete == -1)
0102     return 3;
0103   if (isruncomplete == 0)
0104     return 2;
0105   if (isruncomplete == 1)
0106     return 0;
0107 
0108   return -8;
0109 }