rundmc.cc File Reference

#include <algorithm>
#include <iostream>
#include <fstream>
#include <libgen.h>
#include <iosfwd>
#include <vector>
#include <map>
#include <unistd.h>
#include <getopt.h>
#include "TError.h"
#include "TFile.h"
#include "TIterator.h"
#include "TList.h"
#include "TObject.h"
#include "TObjectTable.h"
#include "TROOT.h"
#include "TString.h"
#include "TSystem.h"
#include "TTimeStamp.h"
#include "TTree.h"
#include "Conventions/Detector.h"
#include "JobControl/JobC.h"
#include "JobControl/JobCEnv.h"
#include "MessageService/MsgService.h"
#include "MessageService/Msg.h"
#include "OnlineUtil/mdRunTypeCodes.h"
#include "OnlineUtil/mdTriggerCodes.h"
#include "Util/UtilString.h"
#include "RSM.h"
#include "UtilRSM.h"

Go to the source code of this file.

Typedefs

typedef map< string, bool > MSB
typedef MSB::value_type MSBVT
typedef MSB::iterator MSBItr
typedef MSB::const_iterator MSBCItr
typedef multimap< string, string > MMSS
typedef MMSS::value_type MMSSVT
typedef MMSS::iterator MMSSItr
typedef MMSS::const_iterator MMSSCItr

Functions

 CVSID ("$Id: rundmc.cc,v 2.4 2006/02/01 20:04:12 rhatcher Exp $")
void usage ()
int main (int argc, char **argv)

Variables

Int_t loud = 0
Bool_t DryRun = false
Bool_t BatchMode = false
string RootDataDir = "./"
vector< string > RootDataList
Bool_t PathCompare = true
Bool_t SuffCompare = true
Bool_t ReadRunFiles = true
Bool_t MakeListFiles = true

Typedef Documentation

typedef multimap<string,string> MMSS

Definition at line 60 of file rundmc.cc.

typedef MMSS::const_iterator MMSSCItr

Definition at line 63 of file rundmc.cc.

typedef MMSS::iterator MMSSItr

Definition at line 62 of file rundmc.cc.

typedef MMSS::value_type MMSSVT

Definition at line 61 of file rundmc.cc.

typedef map<string,bool> MSB

Definition at line 56 of file rundmc.cc.

typedef MSB::const_iterator MSBCItr

Definition at line 59 of file rundmc.cc.

typedef MSB::iterator MSBItr

Definition at line 58 of file rundmc.cc.

typedef MSB::value_type MSBVT

Definition at line 57 of file rundmc.cc.


Function Documentation

CVSID ( "$Id: rundmc.  cc,
v 2.4 2006/02/01 20:04:12 rhatcher Exp $"   
)
int main ( int  argc,
char **  argv 
)

Definition at line 80 of file rundmc.cc.

References BatchMode, UtilRSM::CheckFile(), UtilRSM::DirFileList(), DryRun, exit(), UtilRSM::FileFileList(), UtilRSM::FileListOut(), find(), fname, MsgService::GetStream(), gSystem(), JobCEnv::Instance(), MsgService::Instance(), Msg::kDebug, Msg::kError, Msg::kFatal, Msg::kInfo, Msg::kSynopsis, Msg::kVerbose, Msg::kWarning, loud, MakeListFiles, PathCompare, ReadRunFiles, RootDataDir, RSMErr, RSMInf, RSMSyn, RSMWar, UtilRSM::RTFail, UtilRSM::RTMask, UtilRSM::RunType(), UtilRSM::RunTypeName(), RunTypeName(), MsgStream::SetLogLevel(), SuffCompare, UtilString::ToString(), usage(), and JobCEnv::Cleaner::~Cleaner().

00080                                 {
00081 
00082   MSB UseModes;
00083   UseModes["Physics"] = true;//just the physics runs by default
00084   const char short_opt[] = "hvqnFNAD:L:rRmM";
00085   int c;
00086   while ((c = getopt(argc,argv,short_opt)) != -1)
00087     switch (c) {
00088     case 'h':
00089       usage();
00090       exit(0);
00091       break;
00092     case 'v':
00093       loud++;
00094       break;
00095     case 'q':
00096       loud--;
00097       break;
00098     case 'n':
00099       if(loud>=0) cout << "DryRun (no running done)\n";
00100       DryRun = true;
00101       break;
00102     case 'F':
00103       if(loud>=0) cout << "Far Setup\n";
00104       BatchMode = true;
00105       UseModes["Physics"] = true;
00106       UseModes["CheckOut"] = true;
00107       UseModes["VACalibrate"] = true;
00108       UseModes["VAPedestal"] = true;
00109       ReadRunFiles = true;
00110       MakeListFiles = false;
00111       RootDataDir="/data/root_files";
00112       break;
00113     case 'N':
00114       if(loud>=0) cout << "Near Setup\n";
00115       BatchMode = true;
00116       UseModes["Physics"] = true;
00117       UseModes["CheckOut"] = true;
00118       UseModes["QieCalibrate"] = true;
00119       UseModes["QieMonitor"] = true;
00120       ReadRunFiles = true;
00121       MakeListFiles = false;
00122       break;
00123     case 'A':
00124       if(loud>=0) cout << "All Setup\n";
00125       //BatchMode = true;
00126       UseModes["Physics"] = true;
00127       UseModes["CheckOut"] = true;
00128       UseModes["VACalibrate"] = true;
00129       UseModes["VAPedestal"] = true;
00130       UseModes["QieCalibrate"] = true;
00131       UseModes["QieMonitor"] = true;
00132       ReadRunFiles = true;
00133       MakeListFiles = true;
00134       break;
00135     case 'D':
00136       if(loud>=0) cout << "Use root data directory " << optarg << endl;
00137       RootDataDir = optarg;
00138       break;
00139     case 'L':
00140       if(loud>=0) cout << "Add root data list " << optarg << endl;
00141       RootDataList.push_back(optarg);
00142       break;
00143     case 'r':
00144       ReadRunFiles = false;
00145       break;
00146     case 'R':
00147       ReadRunFiles = true;
00148       break;
00149     case 'm':
00150       MakeListFiles = false;
00151       break;
00152     case 'M':
00153       MakeListFiles = true;
00154       break;
00155     default:
00156       cerr << "unknown command line option:" << optopt << endl;
00157       usage();
00158       exit(1);
00159       break;
00160     }
00161   if(loud>=1) printf("Verbose output level %d\n",loud);
00162   if(loud<=0) gErrorIgnoreLevel = kFatal;
00163   MsgStream *s = MsgService::Instance()->GetStream("RSM");
00164 
00165   if(loud>= 4) s->SetLogLevel(Msg::kVerbose);
00166   if(loud== 3) s->SetLogLevel(Msg::kDebug);
00167   if(loud== 2) s->SetLogLevel(Msg::kSynopsis);
00168   if(loud== 1) s->SetLogLevel(Msg::kInfo);
00169   if(loud== 0) s->SetLogLevel(Msg::kWarning);
00170   if(loud==-1) s->SetLogLevel(Msg::kError);
00171   if(loud<=-2) s->SetLogLevel(Msg::kFatal);
00172 
00173   //Make sure nothing is building for batch mode
00174   if (BatchMode) {
00175     gROOT->SetBatch();
00176     if (UtilRSM::CheckFile("./.building_rundmc",false)) {
00177       cout << "Already building in this directory" << endl;
00178       cout << "Remove .building_rundmc to proceed" << endl;
00179       exit(0);
00180     }
00181 
00182     UtilRSM::FileListOut(".building_rundmc",
00183                          UtilString::ToString<int>(getpid()),
00184                          false);
00185     //ofstream bfile;
00186     //bfile.open(".building_rundmc", ios_base::out);
00187     //bfile << getpid() << endl;
00188     //bfile.close();
00189   }
00190 
00191   string fname;
00192   string mdaq_str = ".mdaq.root";
00193   vector<string> mdaq_ind;
00194 
00195   //Compile list if files are specified on command line
00196   for (int i=optind; i<argc; i++) {
00197     if(PathCompare) fname = argv[i];
00198     else fname = basename(argv[i]);
00199 
00200     if(fname.length()<=mdaq_str.length()) continue;
00201     if(fname.find(mdaq_str)!=fname.length()-mdaq_str.length()) continue;
00202 
00203     if(!SuffCompare) fname = fname.substr(0,fname.find(mdaq_str));
00204 
00205     mdaq_ind.push_back(fname);
00206     ReadRunFiles = false;
00207   }
00208 
00209   //If no mdaq files on command line, first look in RootDataList
00210   for (unsigned int i=0;i<RootDataList.size();i++) {
00211     mdaq_ind = UtilRSM::FileFileList(RootDataList[i],mdaq_str,
00212                                      PathCompare,SuffCompare);
00213   }
00214 
00215   //If no mdaq files yet, try RootDataDir
00216   if (mdaq_ind.size()==0) {
00217     PathCompare = false;
00218     mdaq_ind = UtilRSM::DirFileList(RootDataDir,mdaq_str,
00219                                     PathCompare,SuffCompare);
00220   }
00221 
00222   //Sort the mdaq lists
00223   sort(mdaq_ind.begin(),mdaq_ind.end());
00224 
00225   RSMSyn << mdaq_ind.size() << " " << mdaq_str << " files" << endl;
00226   //Build the list of the files that have been run into frun_ind
00227   vector<string> frun_ind;
00228   if (ReadRunFiles) {
00229     for (MSBCItr MItr=UseModes.begin();MItr!=UseModes.end();++MItr) {
00230       if (! (*MItr).second ) continue;
00231       string ThisMode = (*MItr).first;
00232       RSMInf << "Reading run file for " << ThisMode << " mode" << endl;
00233       frun_ind = UtilRSM::FileFileList(ThisMode+".run",mdaq_str,
00234                                        PathCompare,SuffCompare,
00235                                        frun_ind);
00236     }
00237 
00238     //Also check the Failure and Unknown run files
00239     frun_ind = UtilRSM::FileFileList("Failure.run",mdaq_str,
00240                                      PathCompare,SuffCompare,
00241                                      frun_ind);
00242     frun_ind = UtilRSM::FileFileList("Unknown.run",mdaq_str,
00243                                      PathCompare,SuffCompare,
00244                                      frun_ind);
00245 
00246     sort(frun_ind.begin(),frun_ind.end());
00247   }
00248   RSMSyn << frun_ind.size() << " run files" << endl;
00249 
00250   UInt_t NFailure = 0;
00251   UInt_t NUnknown = 0;
00252 
00253   MMSS ListModes;
00254   //Test files to determine runtype and build lists.
00255   for (unsigned int i=0;i<mdaq_ind.size();i++) {
00256     //Skip the run if it is in the frun_ind list
00257     if(find(frun_ind.begin(),frun_ind.end(),mdaq_ind[i])
00258        != frun_ind.end()) continue;
00259 
00260     string FullFName = mdaq_ind[i];
00261     if(!PathCompare) FullFName = RootDataDir + "/" + mdaq_ind[i];
00262     RSMSyn << "Looking at " << FullFName << endl;
00263     short RunType = UtilRSM::RunType(FullFName);
00264     short BaseRunType = RunType&UtilRSM::RTMask;
00265     string RunTypeName = UtilRSM::RunTypeName(BaseRunType);
00266     RSMSyn << "Get RunType " << RunType << endl;
00267     RSMSyn << "BaseRunType " << BaseRunType << endl;
00268     RSMSyn << "RunTypeName " << RunTypeName << endl;
00269 
00270     //Look for runs that failed UtilRSM::RunType
00271     if (RunType&UtilRSM::RTFail) {
00272       UtilRSM::FileListOut("Failure.run",FullFName,true);
00273       NFailure++;
00274       continue;
00275     }
00276 
00277     //Now check test and modified bit set
00278     if (BaseRunType==0) {
00279       UtilRSM::FileListOut("Unknown.run",FullFName,true);
00280       NUnknown++;
00281       continue;
00282     }
00283 
00284     ListModes.insert(MMSSVT(RunTypeName,FullFName));
00285     if(BatchMode) UtilRSM::FileListOut(".building_rundmc",FullFName,true);
00286   }
00287 
00288   if(NFailure>0) RSMErr << NFailure << " Failure runs\n";
00289   if(NUnknown>0) RSMWar << NUnknown << " Unknown runs\n";
00290 
00291   for (MSBCItr MItr=UseModes.begin();MItr!=UseModes.end();++MItr) {
00292     if(!(*MItr).second) continue;
00293     string ThisMode = (*MItr).first;
00294     RSMInf << ListModes.count(ThisMode) << " " << ThisMode << endl;
00295   }
00296 
00297   int NProcessed = 0;
00298 
00299   for (MSBCItr MItr=UseModes.begin();MItr!=UseModes.end();++MItr) {
00300     if(!(*MItr).second) continue;
00301     string ThisMode = (*MItr).first;
00302     RSMInf << "Building run list for " << ThisMode << " mode" << endl;
00303     MMSSCItr Lower = ListModes.lower_bound(ThisMode);
00304     MMSSCItr Upper = ListModes.upper_bound(ThisMode);
00305 
00306     vector<string> ThisList;
00307     for(MMSSCItr MMItr=Lower;MMItr!=Upper;++MMItr) {
00308       ThisList.push_back((*MMItr).second);
00309     }
00310     if(ThisList.size()==0) continue;
00311 
00312     if(MakeListFiles) UtilRSM::FileListOut(ThisMode+".lst",ThisList);
00313     if(DryRun) continue;
00314     if (!UtilRSM::CheckFile(ThisMode+".C")) {
00315       RSMWar << "No " << ThisMode+".C" << " found" << endl;
00316       continue;
00317     }
00318 
00319     JobCEnv::Cleaner jcecl;//Cleaner to purge JobCEnv
00320     //Start it up once and clean it, just to tempt fate, and have it
00321     //crash before running in case JobCEnv::Cleaner is privatized
00322     jcecl.~Cleaner();
00323 
00324     int Argc=2;
00325     char **Argv = new char*[Argc];
00326     Argv[0] = argv[0];
00327     Int_t ErrorStat;
00328     string MacroStr = ThisMode + ".C";
00329     MacroStr += "(" + UtilString::ToString(loud) + ")";
00330     for (unsigned int i=0;i<ThisList.size();i++) {
00331       Argv[1]=(char *)((ThisList[i]).c_str());
00332       //JobCEnv &jce = JobCEnv::Instance(Argc,Argv);
00333       JobCEnv::Instance(Argc,Argv);
00334 
00335       gROOT->Macro(MacroStr.c_str(),&ErrorStat);
00336 
00337       if(ErrorStat == 0) NProcessed++;
00338       else RSMWar << ThisMode << ".C returned " << ErrorStat << endl;
00339       jcecl.~Cleaner();
00340     }
00341   }
00342   RSMInf << NProcessed << " runs processed" << endl;
00343 
00344   if(BatchMode) gSystem->Unlink("./.building_rundmc");
00345   //gObjectTable->Print();
00346   return NProcessed;
00347 }

void usage (  ) 

Definition at line 349 of file rundmc.cc.

References MakeListFiles, ReadRunFiles, and RootDataDir.

00349              {
00350   cout << "Usage: rundmc -hvqn -FN -D <Dir> -L <File> -rR -tT -mM\n";
00351 
00352   cout << " -v: Verbose output up one level\n";
00353   cout << " -q: Quiet output down one level\n";
00354   cout << " -h: output this statement\n";
00355   cout << " -n: Dry Run, count runs, generate lists, don't process\n";
00356   cout << " -F: Far, far processing run types\n";
00357   cout << " -N: Near, near processing run types\n";
00358   cout << " -A: All, all processing run types\n";
00359 
00360   cout << " -D <RootDataDir>: Location of the mdaq root files ("
00361        << RootDataDir << ")" << endl;
00362   cout << " -L <RootDataList>: A list of the mdaq root files" << endl;
00363 
00364   cout << " -r: Turn off reading of .run files";
00365   if(!ReadRunFiles) cout << "(default)";
00366   cout << endl;
00367   cout << " -R: Turn on reading of .run files";
00368   if(ReadRunFiles) cout << "(default)";
00369   cout << endl;
00370   cout << "     Reading of .run files is turned off if mdaq" << endl;
00371   cout << "     files are specified on the command line" << endl;
00372   cout << " -m: Turn off making of .lst files";
00373   if(!MakeListFiles) cout << "(default)";
00374   cout << endl;
00375   cout << " -M: Turn on making of .lst files";
00376   if(MakeListFiles) cout << "(default)";
00377   cout << endl;
00378 }


Variable Documentation

Bool_t BatchMode = false

Definition at line 67 of file rundmc.cc.

Referenced by main().

Bool_t DryRun = false

Definition at line 65 of file rundmc.cc.

Int_t loud = 0

Definition at line 54 of file rundmc.cc.

Bool_t MakeListFiles = true

Definition at line 76 of file rundmc.cc.

Referenced by main(), and usage().

Bool_t PathCompare = true

Definition at line 72 of file rundmc.cc.

Referenced by main().

Bool_t ReadRunFiles = true

Definition at line 75 of file rundmc.cc.

Referenced by main(), and usage().

string RootDataDir = "./"

Definition at line 69 of file rundmc.cc.

Referenced by main(), and usage().

Definition at line 70 of file rundmc.cc.

Bool_t SuffCompare = true

Definition at line 73 of file rundmc.cc.

Referenced by main().


Generated on 8 Jul 2019 for loon by  doxygen 1.6.1