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

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