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>
37 // avoid loading pythia and pdf
42 //______________________________________________________________________________
43 static void AliMDCErrorHandler(int level, Bool_t abort, const char *location,
46 // The default error handler function. It prints the message on stderr and
47 // if abort is set it aborts the application. Comapared to the default
48 // ROOT error handler this one also prints the date and time in front
51 if (level < gErrorIgnoreLevel)
58 if (level >= kWarning)
63 type = "\n *** Break ***";
64 if (level >= kSysError)
71 if (level >= kBreak && level < kSysError)
72 fprintf(stderr, "%s: %s %s\n", dt.AsSQLString(), type, msg);
73 else if (!location || strlen(location) == 0)
74 fprintf(stderr, "%s: %s: %s\n", dt.AsSQLString(), type, msg);
76 fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location,
81 fprintf(stderr, "aborting\n");
84 gSystem->StackTrace();
92 static void SMI_handle_command()
94 // Handle SMI commands
96 char action[64], param[64];
99 smi_get_action(action, &n_params);
101 smi_get_par_value("PARAM", param);
105 if (strcmp(action, "STOP") == 0) {
106 if (AliMDC::Instance()) AliMDC::Instance()->SetStopLoop();
108 smi_set_state("RUNNING");
112 //______________________________________________________________________________
113 static void Usage(const char *prognam)
116 fprintf(stderr, "Usage: %s <sminame> <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
118 fprintf(stderr, " <sminame> = name used by SMI\n");
120 fprintf(stderr, "Usage: %s <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
123 fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n");
124 fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n");
125 fprintf(stderr, " <tagdbsize> = maximum tag DB size (in bytes, 0 for no tag DB)\n");
126 fprintf(stderr, " (precede by - to switch off the run DB)\n");
127 fprintf(stderr, " (precede by + to fill only the local run DB)\n");
128 fprintf(stderr, " <filter> = state of 3rd level filter (0: off, 1: transparent, 2: on)\n");
129 fprintf(stderr, " <compmode> = compression level (see TFile)\n");
130 fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
131 fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n");
132 fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
133 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
134 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
135 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
138 //______________________________________________________________________________
139 int main(int argc, char **argv)
141 // Convert a DATE data stream to a ROOT DB.
143 // Set ROOT in batch mode
146 // Set custom error handler
147 AliLog::SetHandleRootMessages(kFALSE);
148 SetErrorHandler(AliMDCErrorHandler);
150 // Default file system locations
152 const char* rawDBFS[2] = { "/data1/mdc", "/data2/mdc" };
153 const char* tagDBFS = "/data1/mdc/tags";
154 const char* runDBFS = "/data1/mdc/meta";
155 const char* rfioFS = "rfio:/castor/cern.ch/lcg/dc5";
156 const char* castorFS = "castor:/castor/cern.ch/lcg/dc5";
158 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
159 const char* tagDBFS = "/tmp/mdc1/tags";
160 const char* runDBFS = "/tmp/mdc1/meta";
161 TString user(gSystem->Getenv("USER")[0] + TString("/") +
162 gSystem->Getenv("USER"));
163 TString rfioStr("rfio:/castor/cern.ch/user/" + user);
164 const char* rfioFS = rfioStr.Data();
165 TString castorStr("castor:/castor/cern.ch/user/" + user);
166 const char* castorFS = castorStr.Data();
168 const char* rootdFS = "root://localhost//tmp/mdc1";
169 // const char* alienHost = "alien://aliens7.cern.ch:15000/?direct";
170 const char* alienHost = NULL;
171 const char* alienDir = "/alice_mdc/DC";
173 // User defined file system locations
174 if (gSystem->Getenv("ALIMDC_RAWDB1"))
175 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
176 if (gSystem->Getenv("ALIMDC_RAWDB2"))
177 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
178 if (gSystem->Getenv("ALIMDC_TAGDB"))
179 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
180 if (gSystem->Getenv("ALIMDC_RUNDB"))
181 runDBFS = gSystem->Getenv("ALIMDC_RUNDB");
182 if (gSystem->Getenv("ALIMDC_RFIO"))
183 rfioFS = gSystem->Getenv("ALIMDC_RFIO");
184 if (gSystem->Getenv("ALIMDC_CASTOR"))
185 castorFS = gSystem->Getenv("ALIMDC_CASTOR");
186 if (gSystem->Getenv("ALIMDC_ROOTD"))
187 rootdFS = gSystem->Getenv("ALIMDC_ROOTD");
188 if (gSystem->Getenv("ALIMDC_ALIENHOST"))
189 alienHost = gSystem->Getenv("ALIMDC_ALIENHOST");
190 if (gSystem->Getenv("ALIMDC_ALIENDIR"))
191 alienDir = gSystem->Getenv("ALIMDC_ALIENDIR");
193 // Handle command line arguments
194 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
196 argc > 7 || argc < 6) {
198 argc > 6 || argc < 5) {
207 strcpy(smiobj, argv[iarg]);
208 smi_attach(smiobj, SMI_handle_command);
210 smi_set_state("RUNNING");
214 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
215 Int_t filterMode = 0;
216 Bool_t useLoop = kFALSE;
217 Bool_t delFiles = kFALSE;
218 Bool_t rdbmsRunDB = kTRUE;
220 Double_t maxFileSize;
222 const char* fs1 = NULL;
223 const char* fs2 = NULL;
225 // no special arg checking so don't make errors
226 if (argv[iarg][0] == '-') {
228 maxFileSize = atoi(argv[iarg]+1);
230 maxFileSize = atoi(argv[iarg]);
231 if (maxFileSize < 1000 || maxFileSize > 2.e9) {
232 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
237 if (argv[iarg][0] == '-') {
240 alienHost = alienDir = NULL;
241 maxTagSize = atoi(argv[iarg]+1);
242 } else if (argv[iarg][0] == '+') {
244 alienHost = alienDir = NULL;
245 maxTagSize = atoi(argv[iarg]+1);
247 maxTagSize = atoi(argv[iarg]);
248 if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 2.e9)) {
249 Error(argv[0], "unreasonable tag file size %f\n", maxTagSize);
252 if (maxTagSize == 0) tagDBFS = NULL;
255 filterMode = atoi(argv[iarg]);
256 if (filterMode < 0 || filterMode > 2) {
257 Error(argv[0], "unreasonable filter mode %d\n", filterMode);
262 if (argv[iarg][0] == '-') {
263 wmode = AliMDC::kRFIO;
264 compress = atoi(argv[iarg]+1);
266 } else if (argv[iarg][0] == '+') {
267 wmode = AliMDC::kROOTD;
268 compress = atoi(argv[iarg]+1);
270 } else if (argv[iarg][0] == '%') {
271 wmode = AliMDC::kCASTOR;
272 compress = atoi(argv[iarg]+1);
274 } else if (argv[iarg][0] == '@') {
275 wmode = AliMDC::kDEVNULL;
276 compress = atoi(argv[iarg]+1);
278 compress = atoi(argv[iarg]);
283 Error(argv[0], "unreasonable compression mode %d\n", compress);
291 if (argv[iarg][0] == '-') {
297 // Create MDC processor object and process input stream
298 AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode),
299 runDBFS, rdbmsRunDB, alienHost, alienDir,
300 maxTagSize, tagDBFS);
302 Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2);
305 Info(argv[0], "normal termination of run");
307 Error(argv[0], "error termination of run, status: %d", result);