source: trunk/MagicSoft/Cosy/cosy.cc@ 8862

Last change on this file since 8862 was 8862, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 7.3 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4
5#include <TSystem.h>
6#include <TApplication.h>
7#include <TObjectTable.h>
8
9#include "ethernet.h"
10#include "vmodican.h"
11
12#include "MEnv.h"
13#include "MArgs.h"
14#include "MCosy.h"
15#include "MTime.h"
16
17#include "MLogManip.h"
18
19#include "MStarguider.h"
20
21using namespace std;
22
23#define EXPERT
24
25static void StartUpMessage()
26{
27 gLog << all << endl;
28
29 // 1 2 3 4 5 6
30 // 123456789012345678901234567890123456789012345678901234567890
31 gLog << "========================================================" << endl;
32 gLog << " COSY " << endl;
33 gLog << " Magic Drive Control System Software " << endl;
34 gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
35 gLog << "========================================================" << endl;
36 gLog << endl;
37}
38
39static void Usage()
40{
41 // 1 2 3 4 5 6 7 8
42 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
43 gLog << all << endl;
44 gLog << "Sorry the usage is:" << endl;
45 gLog << " cosy [options]" << endl << endl;
46 gLog << " Arguments:" << endl;
47 gLog << " n/a" << endl;
48 gLog << endl;
49 gLog << " Root Options:" << endl;
50 gLog << " -b Batch mode (no graphical output to screen)" << endl<<endl;
51 gLog << " Options:" << endl;
52 gLog.Usage();
53 gLog << " --debug-env=0 Disable debugging setting resources <default>" << endl;
54 gLog << " --debug-env[=1] Display untouched resources after program execution" << endl;
55 gLog << " --debug-env=2 Display untouched resources after eventloop setup" << endl;
56 gLog << " --debug-env=3 Debug setting resources from resource file and command line" << endl;
57 gLog << " --debug-mem Debug memory usage" << endl << endl;
58 gLog << " --debug-threads Debug threads" << endl << endl;
59 gLog << " --rc=Name:option Set or overwrite a resource of the resource file." << endl << endl;
60 gLog << " --version, -V Show startup message with version number" << endl;
61 gLog << " -?, -h, --help This help" << endl << endl;
62}
63
64/* ---------------------------------------------------------------------- */
65int main(int argc, char **argv)
66{
67 if (!MARS::CheckRootVer())
68 return 0xff;
69
70 MLog::RedirectErrorHandler(MLog::kColor);
71
72 //
73 // Evaluate arguments
74 //
75 MArgs arg(argc, argv, kTRUE);
76 gLog.Setup(arg);
77
78 StartUpMessage();
79
80 if (arg.HasOnly("-V") || arg.HasOnly("--version"))
81 return 0;
82
83 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
84 {
85 Usage();
86 return 2;
87 }
88
89 const Int_t channel = arg.GetIntAndRemove("--channel=", 0);
90 const Bool_t kDebugMem = arg.HasOnlyAndRemove("--debug-mem");
91 const Bool_t kDebugThreads = arg.HasOnlyAndRemove("--debug-threads");
92 const TString sps = arg.GetStringAndRemove("--sps=", "127.0.0.1");
93 const TString ceco = arg.GetStringAndRemove("--cc=", "ceco"); // ceco
94 const TString pointing = arg.GetStringAndRemove("--pointing-model=", "bending2.txt"); // ceco
95 const TString kConfig = arg.GetStringAndRemove("--config=", ".cosyrc"); // ceco
96 Int_t kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
97 kDebugEnv = arg.GetIntAndRemove("--debug-env=", kDebugEnv);
98
99 //
100 // check for the right usage of the program (number of arguments)
101 //
102 if (arg.GetNumArguments()>0)
103 {
104 gLog << warn << "WARNING - Wrong number of arguments..." << endl;
105 Usage();
106 return 2;
107 }
108
109 //
110 // Now we access/read the resource file. This will remove all
111 // --rc= from the list of arguments.
112 //
113 MEnv env(kConfig);
114 if (!env.IsValid())
115 {
116 gLog << err << "ERROR - Reading resource file " << kConfig << "." << endl;
117 return 0xfe;
118 }
119
120 // And move the resource options from the command line to the MEnv
121 if (!env.TakeEnv(arg, kDebugEnv>2))
122 return 0xfd;
123
124 //
125 // check for the right usage of the program (number of options)
126 //
127 if (arg.GetNumOptions()>0)
128 {
129 gLog << warn << "WARNING - Unknown commandline options..." << endl;
130 arg.Print("options");
131 gLog << endl;
132 return 2;
133 }
134
135 if (!gLog.IsOutputDeviceEnabled(MLog::eFile))
136 {
137 const TString name = MCosy::GetFileName("log", "cosy", "log");
138 gLog << inf << "Open automatic logfile: " << name << endl;
139 gLog.SetOutputFile(name);
140 }
141
142 gLog << all << "Starting Cosy at " << MTime(-1) << " in thread " << TThread::SelfId() << "..." << endl;
143
144 //
145 // start the main window
146 //
147 gLog << all << "- Initialising Root environment." << endl;
148
149 //
150 // Initialize root
151 //
152 //MArray::Class()->IgnoreTObjectStreamer();
153 //MParContainer::Class()->IgnoreTObjectStreamer();
154
155 TApplication app("cosy", &argc, argv);
156 if (gROOT->IsBatch())
157 {
158 gLog << err << "ERROR - Cannot run in Batch mode!" << endl;
159 return 0;
160 }
161 if (!gClient)
162 {
163 gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
164 return 1;
165 }
166
167 if (kDebugMem)
168 TObject::SetObjectStat(kTRUE);
169
170 //
171 // Create the Network. Device: /dev/dpm_00, Rate: 500kbps
172 //
173 gLog << all <<"- Constructing MCosy." << endl;
174/*
175 //
176 // check for the right usage of the program
177 //
178 int mode = 0;
179 if (argc==2 && (argv[1][0]=='-' || argv[1][1]=='m'))
180 switch (argv[1][2])
181 {
182 case '0': // standard
183 mode = 0;
184 break;
185 case '1': // SE mode
186 mode = 1;
187 break;
188 case '2': // GUI demo mode
189 mode = 2;
190 break;
191 }
192*/
193 MCosy *cosy = new MCosy(env, ceco, pointing);
194
195 Interface *interface = new Ethernet(sps, 5357, 5358, cosy);
196 // Interface *interface = new VmodIcan(cosy, "/dev/dpm_00", 125);
197
198 gLog << all << "- Starting MCosy." << endl;
199
200 cosy->Start(env);
201
202 // FIXME: Is this the right position?
203 if (kDebugEnv>0)
204 env.PrintUntouched();
205
206
207 MStarguider *client=0;
208 if (channel>=0)
209 {
210 gLog << all << "- Starting Camera." << endl;
211 client=new MStarguider(MObservatory::kMagic1, channel);
212 cosy->SetStarguider(client);
213 client->SetCosy(cosy);
214 }
215
216 gLog << all << "- Starting mainloop." << endl;
217
218 app.Run(kTRUE);
219
220 if (kDebugThreads)
221 TThread::Ps();
222
223 if (channel>=0)
224 {
225 client->SetCosy(NULL);
226 cosy->SetStarguider(NULL);
227 gLog << all << "- Stopping starg." << endl;
228 delete client;
229 }
230
231 gLog << all << "- Stopping cosy." << endl;
232 cosy->Stop();
233
234 gLog << all << MTime(-1) << ": MCosy stopped." << endl;
235
236 delete interface;
237
238 gLog << all << "Deleting cosy at " << MTime(-1) << endl;
239
240 delete cosy;
241
242 if (kDebugThreads)
243 TThread::Ps();
244
245 //delete app;
246
247 if (TObject::GetObjectStat())
248 {
249 TObject::SetObjectStat(kFALSE);
250 gObjectTable->Print();
251 }
252
253 gLog << all << "The End." << endl;
254}
Note: See TracBrowser for help on using the repository browser.