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>
36 //______________________________________________________________________________
37 static void AliMDCErrorHandler(int level, Bool_t abort, const char *location,
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
45 if (level < gErrorIgnoreLevel)
52 if (level >= kWarning)
57 type = "\n *** Break ***";
58 if (level >= kSysError)
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);
70 fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location,
75 fprintf(stderr, "aborting\n");
78 gSystem->StackTrace();
86 static void SMI_handle_command()
88 // Handle SMI commands
90 char action[64], param[64];
93 smi_get_action(action, &n_params);
95 smi_get_par_value("PARAM", param);
99 if (strcmp(action, "STOP") == 0) {
100 if (AliMDC::Instance()) AliMDC::Instance()->SetStopLoop();
102 smi_set_state("RUNNING");
106 //______________________________________________________________________________
107 static void Usage(const char *prognam)
110 fprintf(stderr, "Usage: %s <sminame> <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
112 fprintf(stderr, " <sminame> = name used by SMI\n");
114 fprintf(stderr, "Usage: %s <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
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");
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");
123 fprintf(stderr, " <compmode> = compression level (see TFile)\n");
124 fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
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");
127 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
128 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
129 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
132 //______________________________________________________________________________
133 int main(int argc, char **argv)
135 // Convert a DATE data stream to a ROOT DB.
137 // Set ROOT in batch mode
140 // Set custom error handler
141 AliLog::SetHandleRootMessages(kFALSE);
142 SetErrorHandler(AliMDCErrorHandler);
144 // Default file system locations
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";
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();
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";
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");
186 // Handle command line arguments
187 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
189 argc > 7 || argc < 6) {
191 argc > 6 || argc < 5) {
200 strcpy(smiobj, argv[iarg]);
201 smi_attach(smiobj, SMI_handle_command);
203 smi_set_state("RUNNING");
207 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
208 Int_t filterMode = 0;
209 Bool_t useLoop = kFALSE;
210 Bool_t delFiles = kFALSE;
211 Bool_t rdbmsRunDB = kTRUE;
213 Double_t maxFileSize;
215 const char* fs1 = NULL;
216 const char* fs2 = NULL;
218 // no special arg checking so don't make errors
219 if (argv[iarg][0] == '-') {
221 maxFileSize = atoi(argv[iarg]+1);
223 maxFileSize = atoi(argv[iarg]);
224 if (maxFileSize < 1000 || maxFileSize > 2.e9) {
225 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
230 if (argv[iarg][0] == '-') {
233 alienHost = alienDir = NULL;
234 maxTagSize = atoi(argv[iarg]+1);
235 } else if (argv[iarg][0] == '+') {
237 alienHost = alienDir = NULL;
238 maxTagSize = atoi(argv[iarg]+1);
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);
245 if (maxTagSize == 0) tagDBFS = NULL;
248 filterMode = atoi(argv[iarg]);
249 if (filterMode < 0 || filterMode > 2) {
250 Error(argv[0], "unreasonable filter mode %d\n", filterMode);
255 if (argv[iarg][0] == '-') {
256 wmode = AliMDC::kRFIO;
257 compress = atoi(argv[iarg]+1);
259 } else if (argv[iarg][0] == '+') {
260 wmode = AliMDC::kROOTD;
261 compress = atoi(argv[iarg]+1);
263 } else if (argv[iarg][0] == '%') {
264 wmode = AliMDC::kCASTOR;
265 compress = atoi(argv[iarg]+1);
267 } else if (argv[iarg][0] == '@') {
268 wmode = AliMDC::kDEVNULL;
269 compress = atoi(argv[iarg]+1);
271 compress = atoi(argv[iarg]);
276 Error(argv[0], "unreasonable compression mode %d\n", compress);
284 if (argv[iarg][0] == '-') {
290 // Create MDC processor object and process input stream
291 AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode),
292 runDBFS, rdbmsRunDB, alienHost, alienDir,
293 maxTagSize, tagDBFS);
295 Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2);
298 Info(argv[0], "normal termination of run");
300 Error(argv[0], "error termination of run, status: %d", result);