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