1 // @(#)alimdc:$Name$:$Id$
2 // Author: Fons Rademakers 26/11/99
4 //////////////////////////////////////////////////////////////////////////
8 // Main program used to create application that reads a data stream //
9 // from the DATE DAQ system and that creates a ROOT database. //
11 // Written by: Fons Rademakers, 1/4/99. //
13 //////////////////////////////////////////////////////////////////////////
15 #include <sys/types.h>
32 #include "AliRawEvent.h"
34 //______________________________________________________________________________
35 static void AliMDCErrorHandler(int level, Bool_t abort, const char *location,
38 // The default error handler function. It prints the message on stderr and
39 // if abort is set it aborts the application. Comapared to the default
40 // ROOT error handler this one also prints the date and time in front
43 if (level < gErrorIgnoreLevel)
50 if (level >= kWarning)
55 type = "\n *** Break ***";
56 if (level >= kSysError)
63 if (level >= kBreak && level < kSysError)
64 fprintf(stderr, "%s: %s %s\n", dt.AsSQLString(), type, msg);
65 else if (!location || strlen(location) == 0)
66 fprintf(stderr, "%s: %s: %s\n", dt.AsSQLString(), type, msg);
68 fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location,
73 fprintf(stderr, "aborting\n");
76 gSystem->StackTrace();
84 static void SMI_handle_command()
86 // Handle SMI commands
88 char action[64], param[64];
91 smi_get_action(action, &n_params);
93 smi_get_par_value("PARAM", param);
97 if (strcmp(action, "STOP") == 0) {
98 if (gAliMDC) gAliMDC->SetStopLoop();
100 smi_set_state("RUNNING");
104 //______________________________________________________________________________
105 static void Usage(const char *prognam)
108 fprintf(stderr, "Usage: %s <sminame> <dbsize> <filter> <compmode> [date_file]\n",
110 fprintf(stderr, " <sminame> = name used by SMI\n");
112 fprintf(stderr, "Usage: %s <dbsize> <filter> <compmode> [date_file]\n",
115 fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n");
116 fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n");
117 fprintf(stderr, " <filter> = state of 3rd level filter (0 or 1)\n");
118 fprintf(stderr, " <compmode> = compression level (see TFile)\n");
119 fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
120 fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n");
121 fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
122 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
124 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
126 fprintf(stderr, " [date_file] = optional input file (default reads from pipe /tmp/alimdc.fifo)\n");
128 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
131 //______________________________________________________________________________
132 int main(int argc, char **argv)
134 // Convert a DATE data stream to a ROOT DB.
136 // Set ROOT in batch mode
139 // Set custom error handler
140 SetErrorHandler(AliMDCErrorHandler);
143 // Handle command line arguments
144 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
145 argc > 6 || argc < 5) {
151 strcpy(smiobj, argv[1]);
152 smi_attach(smiobj, SMI_handle_command);
154 smi_set_state("RUNNING");
156 for (int i = 1; i < argc-1; i++)
161 // Handle command line arguments
162 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
163 argc > 5 || argc < 4) {
169 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
170 Bool_t useFilter = kFALSE, useLoop = kFALSE;
171 Bool_t delFiles = kFALSE;
172 Int_t fd = -1, compress;
173 Double_t maxFileSize;
175 // no special arg checking so don't make errors
176 if (argv[1][0] == '-') {
178 maxFileSize = atoi(argv[1]+1);
180 maxFileSize = atoi(argv[1]);
181 if (maxFileSize < 1000 || maxFileSize > 2.e9) {
182 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
186 int filter = atoi(argv[2]);
190 if (argv[3][0] == '-') {
191 wmode = AliMDC::kRFIO;
192 compress = atoi(argv[3]+1);
193 } else if (argv[3][0] == '+') {
194 wmode = AliMDC::kROOTD;
195 compress = atoi(argv[3]+1);
196 } else if (argv[3][0] == '%') {
197 wmode = AliMDC::kCASTOR;
198 compress = atoi(argv[3]+1);
199 } else if (argv[3][0] == '@') {
200 wmode = AliMDC::kDEVNULL;
201 compress = atoi(argv[3]+1);
203 compress = atoi(argv[3]);
205 Error(argv[0], "unreasonable compression mode %d\n", compress);
210 char *file = argv[4];
211 if (argv[4][0] == '-') {
215 if ((fd = open(file, O_RDONLY)) == -1) {
216 Error(argv[0], "cannot open input file %s", argv[4]);
221 // Create MDC processor object and process input stream
222 AliMDC mdcproc(fd, compress, maxFileSize, useFilter, wmode, useLoop, delFiles);
225 mdcproc.SetDebugLevel(3);
230 result = mdcproc.Run();
233 Info(argv[0], "normal termination of run");
235 Error(argv[0], "error termination of run, status: %d", result);