Go to the documentation of this file.00001 #include <Riostream.h>
00002 #include <TDirectory.h>
00003 #include <TFile.h>
00004 #include <TROOT.h>
00005 #include <TStyle.h>
00006 #include <TKey.h>
00007 #include <TH1.h>
00008 #include <TH2.h>
00009 #include <TH2D.h>
00010 #include <TCanvas.h>
00011 #include <TGraph.h>
00012 #include <TPaveStats.h>
00013 #include <TText.h>
00014 #include <TLegend.h>
00015 #include <string>
00016 #include <utility>
00017 #include <vector>
00018 #include <sstream>
00019 #include <algorithm>
00020 #include <TString.h>
00021 #include <TColor.h>
00022 #include <dirent.h>
00023
00024 #include "check_runcomplete.h"
00025
00026
00027
00028 int main(int argc , char *argv[]) {
00029
00030 if(argc==3) {
00031 char* crun = argv[1];
00032 char* repro_type = argv[2];
00033
00034 int run = 0;
00035 sscanf(crun,"%d",&run);
00036
00037 std::cout << "ready to check run " << run << " repro type " << repro_type << std::endl;
00038
00039 check_runcomplete(run,repro_type);
00040
00041 }
00042 else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
00043 return 0;
00044
00045 }
00046
00047 void check_runcomplete ( int run , std::string repro_type )
00048 {
00049 int runflag = read_runflag ( run , repro_type );
00050 if ( runflag == 0 )
00051 {
00052 printf("************************************\n");
00053 printf("**\n");
00054 printf("** W A R N I N G: the DQM file with run %i (%s) is not fully archived yet on /afs,\n" , run , repro_type.c_str() );
00055 printf("** it is strongly recommended that you analyze it later.\n" );
00056 printf("**\n");
00057 printf("************************************\n");
00058 }
00059 }
00060
00061 int read_runflag ( int run , std::string repro_type )
00062 {
00063 std::string filename;
00064 int flag = get_filename ( run , repro_type , filename );
00065
00066 if ( flag < 0 )
00067 {
00068
00069 return -1;
00070 }
00071
00072 std::string nrun = filename.substr ( filename.find( "_R000" ) + 5 , 6 );
00073
00074 TFile *dqmfile = TFile::Open ( filename.c_str() , "READ" );
00075 std::string infodir = "DQMData/Run " + nrun + "/Info/Run summary/ProvInfo";
00076 gDirectory->cd(infodir.c_str());
00077
00078 TIter next ( gDirectory->GetListOfKeys() );
00079 TKey *key;
00080
00081 int isruncomplete = -1;
00082
00083 while ( ( key = dynamic_cast<TKey*> ( next() ) ) )
00084 {
00085 std::string svar = key->GetName();
00086 if ( svar.size() == 0 ) continue;
00087
00088 if ( svar.find( "runIsComplete" ) != std::string::npos )
00089 {
00090 std::string statusflag = svar.substr ( svar.rfind ( "<" ) -1 , 1 );
00091 isruncomplete = atoi ( statusflag.c_str() );
00092 }
00093 }
00094
00095 dqmfile->Close();
00096 return isruncomplete;
00097 }
00098
00099
00100 int get_filename ( int run , std::string repro_type , std::string& filename )
00101 {
00102 std::stringstream runstr;
00103 runstr << run;
00104
00105 std::stringstream rundirprefix;
00106 rundirprefix << "000" << run / 100 << "xx/";
00107
00108 std::stringstream thisdir;
00109 thisdir << "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/data/OfflineData/Run2011/" << repro_type.c_str() << "/" << rundirprefix.str();
00110
00111 std::string thisdir2 = thisdir.str();
00112 DIR *dp;
00113
00114 if ( ( dp = opendir( thisdir2.c_str() ) ) == NULL )
00115 {
00116
00117 return -1;
00118 }
00119
00120 struct dirent *dirp;
00121
00122 std::string dqmfile;
00123
00124 while ( ( dirp = readdir ( dp ) ) != NULL )
00125 {
00126 std::string dirfile = std::string ( dirp->d_name );
00127 if (
00128 dirfile.find ( "__DQM" ) != std::string::npos &&
00129 dirfile.find ( runstr.str() ) != std::string::npos
00130 )
00131 {
00132 dqmfile = dirfile;
00133 break;
00134 }
00135 }
00136
00137 closedir( dp );
00138
00139 if ( dqmfile.size() < 10 )
00140 {
00141
00142 return -1;
00143 }
00144
00145 filename = thisdir.str() + dqmfile;
00146
00147 return 0;
00148 }
00149
00150