Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ana.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include <list>
00012 #include <string>
00013 #include <csignal>
00014 #include <fstream>
00015 #include "TROOT.h"
00016 #include "TApplication.h"
00017 #include "TRint.h"
00018 #include "JobControl/jobc.h"
00019 #include "XMLInterface/xmli.h"
00020 #include "Config/Table.h"
00021 
00022 static TROOT troot("ana","ana");
00023 
00024 TFile* gsHistoFile = 0;
00025 
00026 static void gsSIGHUPhandler(int s) 
00027 {
00028   switch (s) {
00029   case SIGINT: case SIGQUIT: case SIGTERM: case SIGHUP:
00030     jobc::CmdLine::Instance().SetSIGHUP();
00031     break;
00032 
00033   case SIGUSR1:
00034     jobc::Sequence::PrintCurrentNode();
00035     break;
00036 
00037   default:
00038     break;
00039   }
00040 }
00041 
00042 //......................................................................
00043 
00044 int main(int argc, char** argv) 
00045 {
00046   /* TRint* theApp = */ new TRint("ana",0,0);
00047 
00048   jobc::CmdLine::Instance().Parse(argc, argv);
00049   jobc::HistoFile::SetFileName(jobc::CmdLine::Instance().HistoFileName());
00050 
00051   // Start the XML parser and load files and directories specified on
00052   // the command line
00053   xmli::Initialize();
00054 
00055   std::list<std::string>::const_iterator itr;
00056   std::list<std::string>::const_iterator itrEnd;
00057 
00058   itr    = jobc::CmdLine::Instance().XMLFileList().begin();
00059   itrEnd = jobc::CmdLine::Instance().XMLFileList().end();
00060   for (; itr!=itrEnd; ++itr) xmli::ReadFile((*itr).c_str());
00061 
00062   itr    = jobc::CmdLine::Instance().XMLDirList().begin();
00063   itrEnd = jobc::CmdLine::Instance().XMLDirList().end();
00064   for (; itr!=itrEnd; ++itr) xmli::ReadDirectory((*itr).c_str());
00065   
00066   // Set the handler for the SIGHUP signal. Signal ends the job
00067   // gracefully at end of event currently being processed
00068   signal(SIGINT, gsSIGHUPhandler);
00069   signal(SIGQUIT,gsSIGHUPhandler);
00070   signal(SIGTERM,gsSIGHUPhandler);
00071   signal(SIGHUP, gsSIGHUPhandler);
00072   signal(SIGUSR1,gsSIGHUPhandler);
00073 
00074   // Dump the configuration before we start
00075   if ( strcmp(jobc::CmdLine::Instance().XMLDumpFile(),"") != 0 ) {
00076     std::ofstream file;
00077     file.open(jobc::CmdLine::Instance().XMLDumpFile());
00078     file << jobc::XMLConfiguration() << std::endl;
00079     file.close();
00080   }
00081 
00082   // Run all the jobs in the stack
00083   jobc::Stack::Instance().Run();
00084   jobc::Stack::Instance().CleanUp();
00085 
00086   // Clean up the histogram file
00087   if (jobc::HistoFile::File()) {
00088     jobc::HistoFile::File()->Write();
00089     jobc::HistoFile::File()->Close();
00090     if (! jobc::HistoFile::SaveHistos()) {  // JMP: this is a total hack;
00091       // if someone else knows how to nicely avoid writing out the histograms
00092       // and ntuples owned by the modules, please make the change to the code.
00093       std::string cmd("rm -f ");
00094       cmd += std::string(jobc::HistoFile::FileName());
00095       system(cmd.c_str());
00096     }
00097   }
00098   
00099   return 0;
00100 }

Generated on Mon Nov 23 04:45:24 2009 for NOvA Offline by  doxygen 1.3.9.1