]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/alimdc.cxx
add support for TCastorFile (use CASTOR over rootd) and use
[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
34
35#ifdef USE_SMI
36void SMI_handle_command()
37{
38 // Handle SMI commands
39
40 char action[64], param[64];
41 int n_params;
42
43 smi_get_action(action, &n_params);
44 if (n_params >= 1) {
45 smi_get_par_value("PARAM", param);
46 } else {
47 strcpy(param, "");
48 }
49 if (strcmp(action, "STOP") == 0) {
50 gAliMDC->StopLoop();
51 }
52 smi_set_state("RUNNING");
53}
54#endif
55
56//______________________________________________________________________________
57static void Usage(const char *prognam)
58{
59#ifdef USE_SMI
60 fprintf(stderr, "Usage: %s <sminame> <dbsize> <filter> <compmode> [date_file]\n",
61 prognam);
62 fprintf(stderr, " <sminame> = name used by SMI\n");
63#else
64 fprintf(stderr, "Usage: %s <dbsize> <filter> <compmode> [date_file]\n",
65 prognam);
66#endif
67 fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n");
68 fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n");
69 fprintf(stderr, " <filter> = state of 3rd level filter (0 or 1)\n");
70 fprintf(stderr, " <compmode> = compression level (see TFile)\n");
71 fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
9174317d 72 fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n");
73 fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
5ea08be4 74 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
75#ifdef USE_EB
76 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
77#else
78 fprintf(stderr, " [date_file] = optional input file (default reads from pipe /tmp/alimdc.fifo)\n");
79#endif
80 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
81}
82
83//______________________________________________________________________________
84int main(int argc, char **argv)
85{
86 // Convert a DATE data stream to a ROOT DB.
87
88 // Set ROOT in batch mode
89 gROOT->SetBatch();
90
91#ifdef USE_SMI
92 // Handle command line arguments
93 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
94 argc > 6 || argc < 5) {
95 Usage(argv[0]);
96 return 1;
97 }
98
99 char smiobj[128];
100 strcpy(smiobj, argv[1]);
101 smi_attach(smiobj, SMI_handle_command);
102 smi_volatile();
103 smi_set_state("RUNNING");
104
105 for (int i = 1; i < argc-1; i++)
106 argv[i] = argv[i+1];
107 argc--;
108
109#else
110 // Handle command line arguments
111 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
112 argc > 5 || argc < 4) {
113 Usage(argv[0]);
114 return 1;
115 }
116#endif
117
9174317d 118 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
5ea08be4 119 Bool_t useFilter = kFALSE, useLoop = kFALSE;
120 Bool_t delFiles = kFALSE;
121 Int_t fd = -1, compress;
122 Double_t maxFileSize;
123
124 // no special arg checking so don't make errors
125 if (argv[1][0] == '-') {
126 delFiles = kTRUE;
127 maxFileSize = atoi(argv[1]+1);
128 } else
129 maxFileSize = atoi(argv[1]);
130 if (maxFileSize < 1000 || maxFileSize > 2.e9) {
131 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
132 return 1;
133 }
134
135 int filter = atoi(argv[2]);
136 if (filter != 0)
137 useFilter = kTRUE;
138
139 if (argv[3][0] == '-') {
9174317d 140 wmode = AliMDC::kRFIO;
5ea08be4 141 compress = atoi(argv[3]+1);
142 } else if (argv[3][0] == '+') {
9174317d 143 wmode = AliMDC::kROOTD;
144 compress = atoi(argv[3]+1);
145 } else if (argv[3][0] == '%') {
146 wmode = AliMDC::kCASTOR;
5ea08be4 147 compress = atoi(argv[3]+1);
148 } else if (argv[3][0] == '@') {
9174317d 149 wmode = AliMDC::kDEVNULL;
5ea08be4 150 compress = atoi(argv[3]+1);
151 } else
152 compress = atoi(argv[3]);
153 if (compress > 9) {
154 Error(argv[0], "unreasonable compression mode %d\n", compress);
155 return 1;
156 }
157
158 if (argc == 5) {
159 char *file = argv[4];
160 if (argv[4][0] == '-') {
161 useLoop = kTRUE;
162 file = argv[4]+1;
163 }
164 if ((fd = open(file, O_RDONLY)) == -1) {
165 Error(argv[0], "cannot open input file %s", argv[4]);
166 return 1;
167 }
168 }
169
170 // Create MDC processor object and process input stream
9174317d 171 AliMDC mdcproc(fd, compress, maxFileSize, useFilter, wmode, useLoop, delFiles);
5ea08be4 172
173#ifdef USE_DEBUG
174 mdcproc.SetDebugLevel(3);
175#endif
176
177 return mdcproc.Run();
178}