Adding the AliAnalysisGUI class which is the main class that controls the GUI.
[u/mrichter/AliRoot.git] / RAW / alimdc_main.cxx
CommitLineData
5ea08be4 1// @(#)alimdc:$Name$:$Id$
2// Author: Fons Rademakers 26/11/99
3
4//////////////////////////////////////////////////////////////////////////
5// //
6// alimdc //
7// //
8// Main program used to create application that reads a data stream //
9// from the DATE DAQ system and that creates a ROOT database. //
10// //
11// Written by: Fons Rademakers, 1/4/99. //
12// //
13//////////////////////////////////////////////////////////////////////////
14
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <unistd.h>
18#include <stdlib.h>
19#include <fcntl.h>
20#include <errno.h>
21
22#include <TROOT.h>
23#include <TSystem.h>
24#include <TError.h>
25
e10815f1 26#include <AliLog.h>
27
5ea08be4 28#ifdef USE_SMI
29extern "C" {
30 #include <smirtl.h>
31}
32#endif
33
a197a4ce 34#include "AliMDC.h"
5ea08be4 35
bf4fbefe 36#ifdef __APPLE__
37// avoid loading pythia and pdf
38#include <Hepevt.h>
bf4fbefe 39#endif
40
24df3da7 41//______________________________________________________________________________
42static void AliMDCErrorHandler(int level, Bool_t abort, const char *location,
43 const char *msg)
44{
45 // The default error handler function. It prints the message on stderr and
46 // if abort is set it aborts the application. Comapared to the default
47 // ROOT error handler this one also prints the date and time in front
48 // of each message.
49
50 if (level < gErrorIgnoreLevel)
51 return;
52
53 const char *type = 0;
54
55 if (level >= kInfo)
56 type = "Info";
57 if (level >= kWarning)
58 type = "Warning";
59 if (level >= kError)
60 type = "Error";
61 if (level >= kBreak)
62 type = "\n *** Break ***";
63 if (level >= kSysError)
64 type = "SysError";
65 if (level >= kFatal)
66 type = "Fatal";
67
68 TDatime dt;
69
70 if (level >= kBreak && level < kSysError)
71 fprintf(stderr, "%s: %s %s\n", dt.AsSQLString(), type, msg);
72 else if (!location || strlen(location) == 0)
73 fprintf(stderr, "%s: %s: %s\n", dt.AsSQLString(), type, msg);
74 else
75 fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location,
76 msg);
77
78 fflush(stderr);
79 if (abort) {
80 fprintf(stderr, "aborting\n");
81 fflush(stderr);
82 if (gSystem) {
83 gSystem->StackTrace();
84 gSystem->Abort();
85 } else
86 ::abort();
87 }
88}
5ea08be4 89
90#ifdef USE_SMI
24df3da7 91static void SMI_handle_command()
5ea08be4 92{
93 // Handle SMI commands
94
95 char action[64], param[64];
96 int n_params;
97
98 smi_get_action(action, &n_params);
99 if (n_params >= 1) {
100 smi_get_par_value("PARAM", param);
101 } else {
102 strcpy(param, "");
103 }
104 if (strcmp(action, "STOP") == 0) {
a197a4ce 105 if (AliMDC::Instance()) AliMDC::Instance()->SetStopLoop();
5ea08be4 106 }
107 smi_set_state("RUNNING");
108}
109#endif
110
111//______________________________________________________________________________
112static void Usage(const char *prognam)
113{
114#ifdef USE_SMI
e10815f1 115 fprintf(stderr, "Usage: %s <sminame> <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
5ea08be4 116 prognam);
117 fprintf(stderr, " <sminame> = name used by SMI\n");
118#else
e10815f1 119 fprintf(stderr, "Usage: %s <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
5ea08be4 120 prognam);
121#endif
122 fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n");
123 fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n");
e10815f1 124 fprintf(stderr, " <tagdbsize> = maximum tag DB size (in bytes, 0 for no tag DB)\n");
125 fprintf(stderr, " (precede by - to switch off the run DB)\n");
126 fprintf(stderr, " (precede by + to fill only the local run DB)\n");
127 fprintf(stderr, " <filter> = state of 3rd level filter (0: off, 1: transparent, 2: on)\n");
5ea08be4 128 fprintf(stderr, " <compmode> = compression level (see TFile)\n");
129 fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
9174317d 130 fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n");
131 fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
5ea08be4 132 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
5ea08be4 133 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
5ea08be4 134 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
135}
136
137//______________________________________________________________________________
138int main(int argc, char **argv)
139{
140 // Convert a DATE data stream to a ROOT DB.
141
142 // Set ROOT in batch mode
143 gROOT->SetBatch();
144
24df3da7 145 // Set custom error handler
e10815f1 146 AliLog::SetHandleRootMessages(kFALSE);
24df3da7 147 SetErrorHandler(AliMDCErrorHandler);
148
e10815f1 149 // Default file system locations
150#ifdef USE_EB
151 const char* rawDBFS[2] = { "/data1/mdc", "/data2/mdc" };
152 const char* tagDBFS = "/data1/mdc/tags";
153 const char* runDBFS = "/data1/mdc/meta";
154 const char* rfioFS = "rfio:/castor/cern.ch/lcg/dc5";
155 const char* castorFS = "castor:/castor/cern.ch/lcg/dc5";
156#else
157 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
158 const char* tagDBFS = "/tmp/mdc1/tags";
159 const char* runDBFS = "/tmp/mdc1/meta";
160 TString user(gSystem->Getenv("USER")[0] + TString("/") +
161 gSystem->Getenv("USER"));
162 TString rfioStr("rfio:/castor/cern.ch/user/" + user);
163 const char* rfioFS = rfioStr.Data();
164 TString castorStr("castor:/castor/cern.ch/user/" + user);
165 const char* castorFS = castorStr.Data();
166#endif
167 const char* rootdFS = "root://localhost//tmp/mdc1";
f07ec911 168 // const char* alienHost = "alien://aliens7.cern.ch:15000/?direct";
169 const char* alienHost = NULL;
e10815f1 170 const char* alienDir = "/alice_mdc/DC";
171
172 // User defined file system locations
173 if (gSystem->Getenv("ALIMDC_RAWDB1"))
174 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
175 if (gSystem->Getenv("ALIMDC_RAWDB2"))
176 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
177 if (gSystem->Getenv("ALIMDC_TAGDB"))
178 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
179 if (gSystem->Getenv("ALIMDC_RUNDB"))
180 runDBFS = gSystem->Getenv("ALIMDC_RUNDB");
181 if (gSystem->Getenv("ALIMDC_RFIO"))
182 rfioFS = gSystem->Getenv("ALIMDC_RFIO");
183 if (gSystem->Getenv("ALIMDC_CASTOR"))
184 castorFS = gSystem->Getenv("ALIMDC_CASTOR");
185 if (gSystem->Getenv("ALIMDC_ROOTD"))
186 rootdFS = gSystem->Getenv("ALIMDC_ROOTD");
187 if (gSystem->Getenv("ALIMDC_ALIENHOST"))
188 alienHost = gSystem->Getenv("ALIMDC_ALIENHOST");
189 if (gSystem->Getenv("ALIMDC_ALIENDIR"))
190 alienDir = gSystem->Getenv("ALIMDC_ALIENDIR");
191
192 // Handle command line arguments
5ea08be4 193 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
e10815f1 194#ifdef USE_SMI
195 argc > 7 || argc < 6) {
196#else
5ea08be4 197 argc > 6 || argc < 5) {
e10815f1 198#endif
5ea08be4 199 Usage(argv[0]);
200 return 1;
201 }
202
e10815f1 203 Int_t iarg = 1;
204#ifdef USE_SMI
5ea08be4 205 char smiobj[128];
e10815f1 206 strcpy(smiobj, argv[iarg]);
5ea08be4 207 smi_attach(smiobj, SMI_handle_command);
208 smi_volatile();
209 smi_set_state("RUNNING");
e10815f1 210 iarg++;
5ea08be4 211#endif
212
9174317d 213 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
e10815f1 214 Int_t filterMode = 0;
215 Bool_t useLoop = kFALSE;
5ea08be4 216 Bool_t delFiles = kFALSE;
e10815f1 217 Bool_t rdbmsRunDB = kTRUE;
218 Int_t compress;
5ea08be4 219 Double_t maxFileSize;
e10815f1 220 Double_t maxTagSize;
221 const char* fs1 = NULL;
222 const char* fs2 = NULL;
5ea08be4 223
224 // no special arg checking so don't make errors
e10815f1 225 if (argv[iarg][0] == '-') {
5ea08be4 226 delFiles = kTRUE;
e10815f1 227 maxFileSize = atoi(argv[iarg]+1);
5ea08be4 228 } else
e10815f1 229 maxFileSize = atoi(argv[iarg]);
5ea08be4 230 if (maxFileSize < 1000 || maxFileSize > 2.e9) {
231 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
232 return 1;
233 }
e10815f1 234 iarg++;
235
236 if (argv[iarg][0] == '-') {
237 runDBFS = NULL;
238 rdbmsRunDB = kFALSE;
239 alienHost = alienDir = NULL;
240 maxTagSize = atoi(argv[iarg]+1);
241 } else if (argv[iarg][0] == '+') {
242 rdbmsRunDB = kFALSE;
243 alienHost = alienDir = NULL;
244 maxTagSize = atoi(argv[iarg]+1);
245 } else
246 maxTagSize = atoi(argv[iarg]);
247 if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 2.e9)) {
248 Error(argv[0], "unreasonable tag file size %f\n", maxTagSize);
249 return 1;
250 }
251 if (maxTagSize == 0) tagDBFS = NULL;
252 iarg++;
5ea08be4 253
e10815f1 254 filterMode = atoi(argv[iarg]);
255 if (filterMode < 0 || filterMode > 2) {
256 Error(argv[0], "unreasonable filter mode %d\n", filterMode);
257 return 1;
258 }
259 iarg++;
5ea08be4 260
e10815f1 261 if (argv[iarg][0] == '-') {
9174317d 262 wmode = AliMDC::kRFIO;
e10815f1 263 compress = atoi(argv[iarg]+1);
264 fs1 = rfioFS;
265 } else if (argv[iarg][0] == '+') {
9174317d 266 wmode = AliMDC::kROOTD;
e10815f1 267 compress = atoi(argv[iarg]+1);
268 fs1 = rootdFS;
269 } else if (argv[iarg][0] == '%') {
9174317d 270 wmode = AliMDC::kCASTOR;
e10815f1 271 compress = atoi(argv[iarg]+1);
272 fs1 = castorFS;
273 } else if (argv[iarg][0] == '@') {
9174317d 274 wmode = AliMDC::kDEVNULL;
e10815f1 275 compress = atoi(argv[iarg]+1);
276 } else {
277 compress = atoi(argv[iarg]);
278 fs1 = rawDBFS[0];
279 fs2 = rawDBFS[1];
280 }
5ea08be4 281 if (compress > 9) {
282 Error(argv[0], "unreasonable compression mode %d\n", compress);
283 return 1;
284 }
e10815f1 285 iarg++;
5ea08be4 286
e10815f1 287 char* file = NULL;
288 if (iarg < argc) {
289 file = argv[iarg];
290 if (argv[iarg][0] == '-') {
5ea08be4 291 useLoop = kTRUE;
e10815f1 292 file = argv[iarg]+1;
5ea08be4 293 }
294 }
295
296 // Create MDC processor object and process input stream
e10815f1 297 AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode),
298 runDBFS, rdbmsRunDB, alienHost, alienDir,
299 maxTagSize, tagDBFS);
d67af9b1 300
e10815f1 301 Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2);
d67af9b1 302
303 if (result == 0)
304 Info(argv[0], "normal termination of run");
305 else
306 Error(argv[0], "error termination of run, status: %d", result);
13d0d987 307 return result;
5ea08be4 308}