]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/alimdc.cxx
Protection if trigger TClonesArray is empty (Ch.F.)
[u/mrichter/AliRoot.git] / RAW / alimdc.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
26#ifdef USE_SMI
27extern "C" {
28 #include <smirtl.h>
29}
30#endif
31
32#include "AliRawEvent.h"
33
24df3da7 34//______________________________________________________________________________
35static void AliMDCErrorHandler(int level, Bool_t abort, const char *location,
36 const char *msg)
37{
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
41 // of each message.
42
43 if (level < gErrorIgnoreLevel)
44 return;
45
46 const char *type = 0;
47
48 if (level >= kInfo)
49 type = "Info";
50 if (level >= kWarning)
51 type = "Warning";
52 if (level >= kError)
53 type = "Error";
54 if (level >= kBreak)
55 type = "\n *** Break ***";
56 if (level >= kSysError)
57 type = "SysError";
58 if (level >= kFatal)
59 type = "Fatal";
60
61 TDatime dt;
62
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);
67 else
68 fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location,
69 msg);
70
71 fflush(stderr);
72 if (abort) {
73 fprintf(stderr, "aborting\n");
74 fflush(stderr);
75 if (gSystem) {
76 gSystem->StackTrace();
77 gSystem->Abort();
78 } else
79 ::abort();
80 }
81}
5ea08be4 82
83#ifdef USE_SMI
24df3da7 84static void SMI_handle_command()
5ea08be4 85{
86 // Handle SMI commands
87
88 char action[64], param[64];
89 int n_params;
90
91 smi_get_action(action, &n_params);
92 if (n_params >= 1) {
93 smi_get_par_value("PARAM", param);
94 } else {
95 strcpy(param, "");
96 }
97 if (strcmp(action, "STOP") == 0) {
4933e568 98 if (gAliMDC) gAliMDC->SetStopLoop();
5ea08be4 99 }
100 smi_set_state("RUNNING");
101}
102#endif
103
104//______________________________________________________________________________
105static void Usage(const char *prognam)
106{
107#ifdef USE_SMI
108 fprintf(stderr, "Usage: %s <sminame> <dbsize> <filter> <compmode> [date_file]\n",
109 prognam);
110 fprintf(stderr, " <sminame> = name used by SMI\n");
111#else
112 fprintf(stderr, "Usage: %s <dbsize> <filter> <compmode> [date_file]\n",
113 prognam);
114#endif
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");
9174317d 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");
5ea08be4 122 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
123#ifdef USE_EB
124 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
125#else
126 fprintf(stderr, " [date_file] = optional input file (default reads from pipe /tmp/alimdc.fifo)\n");
127#endif
128 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
129}
130
131//______________________________________________________________________________
132int main(int argc, char **argv)
133{
134 // Convert a DATE data stream to a ROOT DB.
135
136 // Set ROOT in batch mode
137 gROOT->SetBatch();
138
24df3da7 139 // Set custom error handler
140 SetErrorHandler(AliMDCErrorHandler);
141
5ea08be4 142#ifdef USE_SMI
143 // Handle command line arguments
144 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
145 argc > 6 || argc < 5) {
146 Usage(argv[0]);
147 return 1;
148 }
149
150 char smiobj[128];
151 strcpy(smiobj, argv[1]);
152 smi_attach(smiobj, SMI_handle_command);
153 smi_volatile();
154 smi_set_state("RUNNING");
155
156 for (int i = 1; i < argc-1; i++)
157 argv[i] = argv[i+1];
158 argc--;
159
160#else
161 // Handle command line arguments
162 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
163 argc > 5 || argc < 4) {
164 Usage(argv[0]);
165 return 1;
166 }
167#endif
168
9174317d 169 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
5ea08be4 170 Bool_t useFilter = kFALSE, useLoop = kFALSE;
171 Bool_t delFiles = kFALSE;
172 Int_t fd = -1, compress;
173 Double_t maxFileSize;
174
175 // no special arg checking so don't make errors
176 if (argv[1][0] == '-') {
177 delFiles = kTRUE;
178 maxFileSize = atoi(argv[1]+1);
179 } else
180 maxFileSize = atoi(argv[1]);
181 if (maxFileSize < 1000 || maxFileSize > 2.e9) {
182 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
183 return 1;
184 }
185
186 int filter = atoi(argv[2]);
187 if (filter != 0)
188 useFilter = kTRUE;
189
190 if (argv[3][0] == '-') {
9174317d 191 wmode = AliMDC::kRFIO;
5ea08be4 192 compress = atoi(argv[3]+1);
193 } else if (argv[3][0] == '+') {
9174317d 194 wmode = AliMDC::kROOTD;
195 compress = atoi(argv[3]+1);
196 } else if (argv[3][0] == '%') {
197 wmode = AliMDC::kCASTOR;
5ea08be4 198 compress = atoi(argv[3]+1);
199 } else if (argv[3][0] == '@') {
9174317d 200 wmode = AliMDC::kDEVNULL;
5ea08be4 201 compress = atoi(argv[3]+1);
202 } else
203 compress = atoi(argv[3]);
204 if (compress > 9) {
205 Error(argv[0], "unreasonable compression mode %d\n", compress);
206 return 1;
207 }
208
209 if (argc == 5) {
210 char *file = argv[4];
211 if (argv[4][0] == '-') {
212 useLoop = kTRUE;
213 file = argv[4]+1;
214 }
215 if ((fd = open(file, O_RDONLY)) == -1) {
216 Error(argv[0], "cannot open input file %s", argv[4]);
217 return 1;
218 }
219 }
220
221 // Create MDC processor object and process input stream
9174317d 222 AliMDC mdcproc(fd, compress, maxFileSize, useFilter, wmode, useLoop, delFiles);
5ea08be4 223
224#ifdef USE_DEBUG
225 mdcproc.SetDebugLevel(3);
226#endif
227
13d0d987 228 Int_t result = 0;
d67af9b1 229
13d0d987 230 result = mdcproc.Run();
d67af9b1 231
232 if (result == 0)
233 Info(argv[0], "normal termination of run");
234 else
235 Error(argv[0], "error termination of run, status: %d", result);
13d0d987 236 return result;
5ea08be4 237}