APPLICATIONS/geb2hdt.cxx

00001 // @(#)fROOT/APPLICATIONS:$Name:  $:$Id: geb2hdt.cxx,v 1.24 2007/09/07 14:05:24 Diego_Faso Exp $
00002 // Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2006/07/25
00003 // Author of the first version (macro): Piergiorgio Cerello <mailto:cerello@to.infn.it>, year 2001
00004 
00005 // The structure of the Run processing process has been 
00006 // completely changed from fROOT-8 to fROOT-9 (June/December 2006). D. Faso
00007 
00008 // the HDT tree is define in this executable only
00009 // TFndRun class handles the event/run processing
00010 // TFndGeb2hdtMan handles monitoring program processing
00011 // TFndGeb2hdtGui handles GUI for TFndGeb2hdtMan
00012 //
00013 // The inter-communication between TFndGeb2hdtMan and TFndGeb2hdtGui
00014 // is realized by means of RQ_OBJECT signals
00015 
00016 #include "TRint.h"
00017 #include "TFndGeb2hdtGUI.h"
00018 #include "TFndGeb2hdtMan.h"
00019 
00020 TRint *theApp = 0;
00021 
00022 TFndGeometry *fingeo;
00023 
00024 TFndGeb2hdtMan *geb_run = 0;
00025 TThread *ProdThread = 0;
00026 TThread *GUIThread = 0;
00027 
00028 static TCondition *CondProdReady;
00029 static TCondition *CondGuiReady;
00030 
00031 TFndGeb2hdtGUI *gebgui = 0;
00032 
00033 static Bool_t USING_GEB2HDT_GUI;
00034 
00035 //________________________
00036 void *HandleGUI(void *ptr){
00037 
00038   gebgui = new TFndGeb2hdtGUI((TFndGeb2hdtMan *)ptr);
00039   CondProdReady->Wait();
00040   gebgui->BuildGUI();
00041   cout << "GUI built" << endl;
00042   CondGuiReady->Signal();
00043   cout << ".................signal emitted" << endl;
00044   TThread::Join(TThread::GetThread("geb2hdt_prod_thread")->GetId());
00045   gSystem->Sleep(500);
00046   delete gebgui;
00047   return 0;
00048 
00049 }
00050 
00051 //________________________
00052 void *HandleProducer(void *ptr){
00053   
00054   TFndGeb2hdtMan *geb_run = (TFndGeb2hdtMan *)(ptr);
00055   Int_t TimeLimit = -1; // seconds ("-1" means "unlimited")
00056   geb_run->SetTimeLimit(TimeLimit);
00057 
00058   geb_run->InitRun(); // debug flags taken from RunConfig.C
00059   
00060   if(USING_GEB2HDT_GUI){
00061     CondProdReady->Signal();
00062     CondGuiReady->Wait();
00063   }
00064   
00065   cout << "starting event loop......." << endl;
00066   geb_run->EventLoop();
00067   geb_run->FinishRun(); // post-processing operations
00068   
00069   if(geb_run->GetOnlFlag()) geb_run->HandleConsumerActions(1);  // allow consumer(s)  
00070   delete geb_run;   
00071   gROOT->Info("geb2hdt.C (Producer)","All processes completed");
00072 
00073   delete fingeo;
00074   gApplication->Terminate();
00075   return 0;
00076 }
00077 
00078 //___________________________________________________
00079 //___________________________________________________
00080 //___________________________________________________
00081 //void geb2hdt(TString msqlhost="$MSQL_DB_HOST", TString fpth="$RDT", TString fnam="ONLM00000", Int_t nevts = 100,Int_t gebip=0) {
00082 void geb2hdt(const TString &msqlhost, const TString &fpth, const TString &run_type, const Int_t &run_num,const Int_t &nevts,Int_t gebip) {
00083   // Online monitor main-macro management:
00084   //            - GUI support (start/stop/pause/reset) (check if the USE_GEB2HDT_GUI symbol is defined)
00085   //            - producer->consumer(s) communication support (shared hidden text file)
00086   //
00087   // Montecarlo and analysis not supported
00088   
00089   CondProdReady = new TCondition(0);
00090   CondGuiReady = new TCondition(0);
00091  
00092   fingeo = new TFndGeometry();
00093   fingeo->LoadGeometry("$FROOTSYS/geom/fin_spec_geom_2006.root");
00094 
00095   if(!gebip) gebip = FROOT::Ip2Int(gSystem->Getenv("FND_GEBIP"));
00096   geb_run = new TFndGeb2hdtMan(msqlhost,fpth,run_type,run_num,nevts,gebip);
00097   ProdThread = new TThread("geb2hdt_prod_thread",HandleProducer,(void *)geb_run);
00098   
00099   geb_run->ReadConfFile(); // --- needed for getting GUI-mode and debug flags
00100   USING_GEB2HDT_GUI = geb_run->UsingGUI();
00101   gROOT->Info("geb2hdt","USING_GEB2HDT_GUI = %d",USING_GEB2HDT_GUI);
00102 
00103   ProdThread->Run();
00104   
00105   if(USING_GEB2HDT_GUI){
00106     GUIThread = new TThread("gui_thread",HandleGUI,(void *)geb_run);
00107     GUIThread->Run();
00108   }
00109 }
00110 
00111 // -----------------------------------------
00112 void PrintUsage(){
00113   cout << endl << " -----------------------------------" << endl;
00114   cout << " --- geb2hdt usage:" << endl;
00115   cout << " - argument 1: database-host." << endl;
00116   cout << " - argument 2: path to raw-data." << endl;
00117   cout << " - argument 3: requested run type." << endl;
00118   cout << " - argument 4: requested run number." << endl;
00119   cout << " - argument 5: requested number of events." << endl;
00120   cout << " - argument 6: requested Geb-IP (may use defaults)." << endl << endl;
00121   cout << " EXAMPLE: geb2hdt $MSQL_DB_HOST $RDT FINU 4372 10000000" << endl; 
00122   cout << " -----------------------------------" << endl;
00123 }
00124 
00125 //_____________________________
00126 int main(int argc, char **argv)
00127 {
00128   
00129   cout << "geb2hdt executable started: number of arguments: " << argc << endl;
00130 
00131   if(argc < 2){
00132     PrintUsage();
00133     return 0;
00134   }
00135   
00136   TString str1 = "$MSQL_DB_HOST";
00137   if(argc > 1) str1 = TString(argv[1]);
00138 
00139   TString str2 = "$RDT";
00140   if(argc > 2) str2 = TString(argv[2]);
00141 
00142   TString str3 = "ONLM";
00143   if(argc > 3) str3 = TString(argv[3]);
00144 
00145   Int_t arg_4 = 0;
00146   if(argc > 4) arg_4 = atoi(argv[4]);
00147 
00148   Int_t nevts = std::numeric_limits<Int_t>::max();
00149   if(argc > 5) nevts = atoi(argv[5]);
00150 
00151   Int_t gebip = 0;
00152   if(argc > 6) gebip = atoi(argv[6]);
00153   
00154   cout << "str1: \"" << str1
00155        << "\"; str2: \"" << str2 
00156        << "\"; str3: \"" << str3
00157        << "\"; arg_4: \"" << arg_4
00158        << "\"," << nevts << "; " << gebip << endl;
00159   
00160   argc = 0;
00161   for(Int_t ar=0;ar<argc;ar++)argv[ar] = '\0';
00162 
00163   for(Int_t ar=0;ar<argc;ar++) cout << "arg[" << ar << "]: \"" << argv[ar] << "\"." << endl;
00164   cout << endl;
00165   
00166   cout << " -------------> \"" << *(argv+2) << "\"" << endl;
00167   theApp = new TRint("geb2hdt run application", &argc,argv,NULL,0,1);
00168 
00169   theApp->ProcessFile("$FROOTSYS/mcr_called/frootlogon.C");
00170   theApp->SetPrompt("# froot > ");
00171   
00172   geb2hdt(str1,str2,str3,arg_4,nevts,gebip);
00173 
00174   theApp->Run();
00175   theApp->Terminate(0);
00176   delete theApp;
00177   return 0;
00178 }
00179 
00180 // Old workaround to skip directory arguments
00181 // TRint takes the first 2 arguments as work-directory:
00182 // then "msqlhost" and "fpth" will be skipped
00183 //  TRint *theApp = new TRint("geb2hdt run",&argc-2,argv+2,NULL,0,1);

Generated on Tue Oct 16 15:40:46 2007 by  doxygen 1.5.2