source: Sophya/trunk/SophyaPI/ProgPI/piapp.cc@ 2189

Last change on this file since 2189 was 2189, checked in by ansari, 23 years ago

Modif pour execution du script .pic du debut ds la boucle d'evts - Reza 9/9/2002

File size: 8.4 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <iostream.h>
5
6#include "pistdimgapp.h"
7#include "piacmd.h"
8#include "piversion.h"
9#include "piaversion.h"
10
11#include "timing.h"
12#include "skyinit.h"
13
14#include "xntuple.h" // Pour faire le SetTmpDir()
15
16
17// ---- Pour charger automatiquement le module sopiamodule
18extern "C" {
19void sopiamodule_init();
20void sopiamodule_end();
21void skymapmodule_init();
22void skymapmodule_end();
23void fitsbtadapter_init();
24void fitsbtadapter_end();
25void W2PSModule_init();
26void W2PSModule_end();
27}
28
29/*!
30 \defgroup ProgPI ProgPI module
31 This module contains programs for interactive data analysis and
32 visualisation, based on SOPHYA class libray and PI (GUI framework)
33 and PIext (Interactive data analysis framework).
34*/
35
36/*!
37 \ingroup ProgPI
38 \file piapp.cc
39 \brief \b (s)piapp: Starts the piapp interactive data analysis program.
40
41 The current version of the program has a single execution thread. This
42 creates few limitations (GUI can not be used when computing is being
43 done, ...). Also the command file executed during start-up (-exec)
44 cannot contain display (graphic) commands.
45
46 \verbatim
47 csh> spiapp -h
48 SOPHYA Version 1.3 Revision 70 (V_Jun2002) -- Jul 16 2002 15:45:53 cxx
49
50 piapp: Interactive data analysis and visualisation program
51 Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin]
52 [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
53 -nored : NoRedirect StdOut/StdErr
54 -nosig : Don't catch SigFPE, SigSEGV
55 -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
56 -hidezswin : Hide Zoom/Stat/ColMap window
57 -tmpdir TmpDirectory: defines TMDIR for temporary files
58 -help2tex: Create a LaTeX help file (piahelp.tex)
59 -exec file [args] : Execute command file
60
61 \endverbatim
62
63*/
64
65void Usage(bool fgerr)
66{
67 if (fgerr) {
68 cout << " piapp : Argument Error ! piapp -h for Usage" << endl;
69 exit(1);
70 }
71 else {
72 cout << "\n piapp: Interactive data analysis and visualisation program \n"
73 << " Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-hidezswin] \n"
74 << " [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]] \n"
75 << " -nored : NoRedirect StdOut/StdErr \n"
76 << " -nosig : Don't catch SigFPE, SigSEGV \n"
77 << " -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV \n"
78 << " -hidezswin : Hide Zoom/Stat/ColMap window \n"
79 << " -tmpdir TmpDirectory: defines TMDIR for temporary files \n"
80 << " -help2tex: Create a LaTeX help file (piahelp.tex)\n"
81 << " -exec file [args] : Execute command file \n"
82 << endl;
83 exit(0);
84 }
85}
86
87/* ================================ MAIN() ================================= */
88
89int main(int narg, char *arg[])
90{
91int ofa;
92bool fgfpe, fgsegv, fgred, fghidezsw, fgexec;
93
94SkyTInitiator skyinit;
95
96InitTim();
97
98
99if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
100
101ofa = 1;
102fgred = fgfpe = fgsegv = true;
103fghidezsw = false;
104fgexec = false;
105bool fgtmp = false;
106string tmpdir;
107string exfc;
108// Pour fabriquer le help
109bool fgtexh = false;
110int ka;
111for(ka=1; ka<narg; ka++) {
112 if (strcmp(arg[ka],"-nored") == 0) fgred=false;
113 else if (strcmp(arg[ka],"-nosig") == 0) fgfpe=fgsegv=false;
114 else if (strcmp(arg[ka],"-nosigfpe") == 0) fgfpe=false;
115 else if (strcmp(arg[ka],"-nosigsegv") == 0) fgsegv=false;
116 else if (strcmp(arg[ka],"-hidezswin") == 0) fghidezsw=true;
117 else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
118 else if (strcmp(arg[ka],"-tmpdir") == 0) {
119 if (ka == narg-1) Usage(true);
120 fgtmp = true; ka++;
121 tmpdir = arg[ka];
122 }
123 else if (strcmp(arg[ka],"-exec") == 0) {
124 if (ka < narg-1) {
125 fgexec = true;
126 exfc = "exec";
127 for(int kaa=ka+1; kaa<narg; kaa++) { exfc += ' '; exfc += arg[kaa]; }
128 }
129 break;
130 }
131 }
132
133
134if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
135else printf(">>>>> Starting piapp <<<<< \n");
136printf("Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
137 (double)PI_VERSIONNUMBER, (double)skyinit.Version());
138
139char* vcmds=NULL;
140string vcmd;
141if (fgtmp) {
142 if (tmpdir[tmpdir.length()-1] != '/') tmpdir += '/'; // Necessaire pour SetSwapPath
143 vcmd = "TMPDIR=" + tmpdir;
144 vcmds = new char[vcmd.length()+1];
145 strcpy(vcmds, vcmd.c_str());
146 putenv(vcmds);
147}
148
149char* tmpde = getenv("TMPDIR");
150char tmpdname[32];
151if (tmpde == NULL) tmpde = "./";
152if (tmpde[strlen(tmpde)-1] != '/')
153 strcpy(tmpdname, "/PIATmp_XXXXXX");
154else
155 strcpy(tmpdname, "PIATmp_XXXXXX");
156mktemp(tmpdname);
157tmpdir = tmpde;
158tmpdir += tmpdname;
159tmpdir += '/';
160vcmd = "mkdir ";
161vcmd += tmpde;
162vcmd += tmpdname;
163cout << " --piapp: Creating Tmp Directory: " << tmpdir << endl;
164int rcc = system(vcmd.c_str());
165if (rcc != 0) {
166 cout << " --piapp: Error creating TmpDir " << vcmd << " ---> exit !" << endl;
167 return(9);
168}
169
170// On cree un repertoire temporaire
171// cout << " DBG-TMPDIR= " << getenv("TMPDIR") << endl;
172
173PIStdImgApp * app = new PIStdImgApp(narg, arg);
174// cout << " DBG-2 " << app->ObjMgr()->GetTmpDir() << endl;
175cout << " NamedObjMgr::SetTmpDir()+XNTuple::SetSwapPath() " << tmpdir << endl;
176app->ObjMgr()->SetTmpDir(tmpdir);
177XNTuple::SetSwapPath(const_cast<char *>(tmpdir.c_str()));
178
179
180
181// Gestion de redirection stdout/err et Signaux
182if (fgred) app->RedirectStdOutErr(true);
183else app->RedirectStdOutErr(false);
184app->CatchSignals(fgfpe, fgsegv);
185
186// if Hide Zoom/Stat Win
187if (fghidezsw) app->StatZoomWindowSetVisible(false);
188
189// S'il y a un fichier de commande a executer
190// if (fgexec) app->CmdInterpreter()->Interpret(exfc);
191if (fgexec) app->SubmitCommand(exfc);
192
193// On charge le module sopiamodule
194sopiamodule_init();
195// On charge le module skymapmodule
196skymapmodule_init();
197// On charge le module de lecture ligne a ligne des Fits BINARY/ASCII tables
198fitsbtadapter_init();
199// On charge le module des commandes de creation de fichier postscript
200W2PSModule_init();
201
202// S'il y a besoin de faire le fichier Help
203if (fgtexh) {
204 string thf = "piahelp.tex";
205 app->CmdInterpreter()->HelptoLaTex(thf);
206 printf("piapp : Help file piahelp.tex created --> exit(0) \n");
207 delete app;
208 exit(0);
209}
210
211int rc = 0;
212bool cont = true;
213char rep; // ans[32]
214int excnt = 0;
215while(cont) {
216 rc = 0; cont = false;
217 app->SetReady();
218 if (fgred) app->RedirectStdOutErr(true);
219 try {
220 app->Run();
221 }
222 catch(PThrowable exc) { // Catching SOPHYA exceptions
223 app->Stop();
224 app->RedirectStdOutErr(false);
225 //BUG ? fait planter OSF-cxx fflush(stdout);
226 cout << endl; cerr << endl;
227 cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl;
228 cout << ++excnt << "- continue <CR>, Close Windows, "
229 << " continue C<CR> Stop program S<CR> ? " << endl;
230 rep = getchar(); // was: gets(ans);
231 rep = toupper(rep);
232 if (rep == 'S') {
233 cout << " !!!! Stopping piapp !!!! " << endl;
234 rc = 78;
235 cont = false;
236 }
237 else {
238 if (rep == 'C') {
239 cout << "piapp/main() Closing all windows ... " << endl;
240 app->CloseAllWindows();
241 }
242 cout << " *** piapp - Continuing event loop *** " << endl;
243 cont = true;
244 }
245 }
246 catch(...) { // Catching all other exceptions
247 app->Stop();
248 app->RedirectStdOutErr(false);
249 cout << endl; cerr << endl;
250 cout << "\n piapp/main() exception catched ! " << endl;
251 cout << ++excnt << "- continue <CR>, Close Windows, "
252 << " continue C<CR> Stop program S<CR> ? " << endl;
253 rep = getchar(); // gets(ans);
254 rep = toupper(rep);
255 if (rep == 'S') {
256 cout << " !!!! Stopping piapp !!!! " << endl;
257 rc = 78;
258 cont = false;
259 }
260 else {
261 if (rep == 'C') {
262 cout << "piapp/main() Closing all windows ... " << endl;
263 app->CloseAllWindows();
264 }
265 cout << " *** piapp - Continuing event loop *** " << endl;
266 cont = true;
267 }
268 }
269}
270cout << "\n ------------------------------------------------ \n"
271 << " piapp: Cleaning up ... " << endl;
272
273app->RedirectStdOutErr(false);
274// On de-charge le module sopiamodule et fitsbtadapter
275sopiamodule_end();
276skymapmodule_end();
277fitsbtadapter_end();
278W2PSModule_end();
279
280delete app;
281if (fgtmp) delete[] vcmds;
282
283vcmd = "rm -rf ";
284vcmd += tmpdir;
285cout << " --piapp: Removing Tmp Directory: " << tmpdir << endl;
286rcc = system(vcmd.c_str());
287if (rcc != 0) {
288 cout << " --piapp: Error deleting TmpDir " << vcmd << endl;
289 return(9);
290}
291
292cout << "------------------------------------------------ \n"
293 << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
294 << "------------------------------------------------ " << endl;
295return(rc);
296}
297
Note: See TracBrowser for help on using the repository browser.