]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/alimdc_main.cxx
Small fix Sarah
[u/mrichter/AliRoot.git] / RAW / alimdc_main.cxx
CommitLineData
60838f24 1// @(#)alimdc:$Name: $:$Id$
5ea08be4 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");
e10815f1 125 fprintf(stderr, " <filter> = state of 3rd level filter (0: off, 1: transparent, 2: on)\n");
5ea08be4 126 fprintf(stderr, " <compmode> = compression level (see TFile)\n");
127 fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
9174317d 128 fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n");
129 fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
5ea08be4 130 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
5ea08be4 131 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
5ea08be4 132 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
133}
134
135//______________________________________________________________________________
136int main(int argc, char **argv)
137{
138 // Convert a DATE data stream to a ROOT DB.
139
140 // Set ROOT in batch mode
141 gROOT->SetBatch();
142
24df3da7 143 // Set custom error handler
e10815f1 144 AliLog::SetHandleRootMessages(kFALSE);
24df3da7 145 SetErrorHandler(AliMDCErrorHandler);
146
e10815f1 147 // Default file system locations
148#ifdef USE_EB
149 const char* rawDBFS[2] = { "/data1/mdc", "/data2/mdc" };
150 const char* tagDBFS = "/data1/mdc/tags";
e10815f1 151 const char* rfioFS = "rfio:/castor/cern.ch/lcg/dc5";
152 const char* castorFS = "castor:/castor/cern.ch/lcg/dc5";
153#else
154 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
155 const char* tagDBFS = "/tmp/mdc1/tags";
e10815f1 156 TString user(gSystem->Getenv("USER")[0] + TString("/") +
157 gSystem->Getenv("USER"));
158 TString rfioStr("rfio:/castor/cern.ch/user/" + user);
159 const char* rfioFS = rfioStr.Data();
160 TString castorStr("castor:/castor/cern.ch/user/" + user);
161 const char* castorFS = castorStr.Data();
162#endif
163 const char* rootdFS = "root://localhost//tmp/mdc1";
e10815f1 164
165 // User defined file system locations
166 if (gSystem->Getenv("ALIMDC_RAWDB1"))
167 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
168 if (gSystem->Getenv("ALIMDC_RAWDB2"))
169 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
170 if (gSystem->Getenv("ALIMDC_TAGDB"))
171 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
e10815f1 172 if (gSystem->Getenv("ALIMDC_RFIO"))
173 rfioFS = gSystem->Getenv("ALIMDC_RFIO");
174 if (gSystem->Getenv("ALIMDC_CASTOR"))
175 castorFS = gSystem->Getenv("ALIMDC_CASTOR");
176 if (gSystem->Getenv("ALIMDC_ROOTD"))
177 rootdFS = gSystem->Getenv("ALIMDC_ROOTD");
e10815f1 178
179 // Handle command line arguments
5ea08be4 180 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
e10815f1 181#ifdef USE_SMI
182 argc > 7 || argc < 6) {
183#else
5ea08be4 184 argc > 6 || argc < 5) {
e10815f1 185#endif
5ea08be4 186 Usage(argv[0]);
187 return 1;
188 }
189
e10815f1 190 Int_t iarg = 1;
191#ifdef USE_SMI
5ea08be4 192 char smiobj[128];
e10815f1 193 strcpy(smiobj, argv[iarg]);
5ea08be4 194 smi_attach(smiobj, SMI_handle_command);
195 smi_volatile();
196 smi_set_state("RUNNING");
e10815f1 197 iarg++;
5ea08be4 198#endif
199
9174317d 200 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
e10815f1 201 Int_t filterMode = 0;
202 Bool_t useLoop = kFALSE;
5ea08be4 203 Bool_t delFiles = kFALSE;
e10815f1 204 Int_t compress;
5ea08be4 205 Double_t maxFileSize;
e10815f1 206 Double_t maxTagSize;
207 const char* fs1 = NULL;
208 const char* fs2 = NULL;
5ea08be4 209
210 // no special arg checking so don't make errors
e10815f1 211 if (argv[iarg][0] == '-') {
5ea08be4 212 delFiles = kTRUE;
60838f24 213 maxFileSize = atoll(argv[iarg]+1);
5ea08be4 214 } else
60838f24 215 maxFileSize = atoll(argv[iarg]);
216 if (maxFileSize < 1000 || maxFileSize > 20.e9) {
5ea08be4 217 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
218 return 1;
219 }
e10815f1 220 iarg++;
221
30bda8ef 222 maxTagSize = atoi(argv[iarg]);
60838f24 223 if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 20.e9)) {
e10815f1 224 Error(argv[0], "unreasonable tag file size %f\n", maxTagSize);
225 return 1;
226 }
227 if (maxTagSize == 0) tagDBFS = NULL;
228 iarg++;
5ea08be4 229
e10815f1 230 filterMode = atoi(argv[iarg]);
231 if (filterMode < 0 || filterMode > 2) {
232 Error(argv[0], "unreasonable filter mode %d\n", filterMode);
233 return 1;
234 }
235 iarg++;
5ea08be4 236
e10815f1 237 if (argv[iarg][0] == '-') {
9174317d 238 wmode = AliMDC::kRFIO;
e10815f1 239 compress = atoi(argv[iarg]+1);
240 fs1 = rfioFS;
241 } else if (argv[iarg][0] == '+') {
9174317d 242 wmode = AliMDC::kROOTD;
e10815f1 243 compress = atoi(argv[iarg]+1);
244 fs1 = rootdFS;
245 } else if (argv[iarg][0] == '%') {
9174317d 246 wmode = AliMDC::kCASTOR;
e10815f1 247 compress = atoi(argv[iarg]+1);
248 fs1 = castorFS;
249 } else if (argv[iarg][0] == '@') {
9174317d 250 wmode = AliMDC::kDEVNULL;
e10815f1 251 compress = atoi(argv[iarg]+1);
252 } else {
253 compress = atoi(argv[iarg]);
254 fs1 = rawDBFS[0];
255 fs2 = rawDBFS[1];
256 }
5ea08be4 257 if (compress > 9) {
258 Error(argv[0], "unreasonable compression mode %d\n", compress);
259 return 1;
260 }
e10815f1 261 iarg++;
5ea08be4 262
e10815f1 263 char* file = NULL;
264 if (iarg < argc) {
265 file = argv[iarg];
266 if (argv[iarg][0] == '-') {
5ea08be4 267 useLoop = kTRUE;
e10815f1 268 file = argv[iarg]+1;
5ea08be4 269 }
270 }
271
a8b0468f 272 Int_t basketsize = 32000;
5ea08be4 273 // Create MDC processor object and process input stream
e10815f1 274 AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode),
a8b0468f 275 maxTagSize, tagDBFS,NULL,basketsize);
d67af9b1 276
e10815f1 277 Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2);
d67af9b1 278
279 if (result == 0)
280 Info(argv[0], "normal termination of run");
281 else
282 Error(argv[0], "error termination of run, status: %d", result);
13d0d987 283 return result;
5ea08be4 284}