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
41 //______________________________________________________________________________
42 static void AliMDCErrorHandler(int level, Bool_t abort, const char *location,
45 // The default error handler function. It prints the message on stderr and
46 // if abort is set it aborts the application. Comapared to the default
47 // ROOT error handler this one also prints the date and time in front
50 if (level < gErrorIgnoreLevel)
57 if (level >= kWarning)
62 type = "\n *** Break ***";
63 if (level >= kSysError)
70 if (level >= kBreak && level < kSysError)
71 fprintf(stderr, "%s: %s %s\n", dt.AsSQLString(), type, msg);
72 else if (!location || strlen(location) == 0)
73 fprintf(stderr, "%s: %s: %s\n", dt.AsSQLString(), type, msg);
75 fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location,
80 fprintf(stderr, "aborting\n");
83 gSystem->StackTrace();
91 static void SMI_handle_command()
93 // Handle SMI commands
95 char action[64], param[64];
98 smi_get_action(action, &n_params);
100 smi_get_par_value("PARAM", param);
104 if (strcmp(action, "STOP") == 0) {
105 if (AliMDC::Instance()) AliMDC::Instance()->SetStopLoop();
107 smi_set_state("RUNNING");
111 //______________________________________________________________________________
112 static void Usage(const char *prognam)
115 fprintf(stderr, "Usage: %s <sminame> <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
117 fprintf(stderr, " <sminame> = name used by SMI\n");
119 fprintf(stderr, "Usage: %s <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
122 fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n");
123 fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n");
124 fprintf(stderr, " <tagdbsize> = maximum tag DB size (in bytes, 0 for no tag DB)\n");
125 fprintf(stderr, " <filter> = state of 3rd level filter (0: off, 1: transparent, 2: on)\n");
126 fprintf(stderr, " <compmode> = compression level (see TFile)\n");
127 fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
128 fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n");
129 fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
130 fprintf(stderr, " (precede by @ to use /dev/null as sink)\n");
131 fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
132 fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
135 //______________________________________________________________________________
136 int main(int argc, char **argv)
138 // Convert a DATE data stream to a ROOT DB.
140 // Set ROOT in batch mode
143 // Set custom error handler
144 AliLog::SetHandleRootMessages(kFALSE);
145 SetErrorHandler(AliMDCErrorHandler);
147 // Default file system locations
149 const char* rawDBFS[2] = { "/data1/mdc", "/data2/mdc" };
150 const char* tagDBFS = "/data1/mdc/tags";
151 const char* rfioFS = "rfio:/castor/cern.ch/lcg/dc5";
152 const char* castorFS = "castor:/castor/cern.ch/lcg/dc5";
154 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
155 const char* tagDBFS = "/tmp/mdc1/tags";
156 TString user(gSystem->Getenv("USER")[0] + TString("/") +
157 gSystem->Getenv("USER"));
158 TString rfioStr("rfio:/castor/cern.ch/user/" + user);
159 const char* rfioFS = rfioStr.Data();
160 TString castorStr("castor:/castor/cern.ch/user/" + user);
161 const char* castorFS = castorStr.Data();
163 const char* rootdFS = "root://localhost//tmp/mdc1";
165 // User defined file system locations
166 if (gSystem->Getenv("ALIMDC_RAWDB1"))
167 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
168 if (gSystem->Getenv("ALIMDC_RAWDB2"))
169 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
170 if (gSystem->Getenv("ALIMDC_TAGDB"))
171 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
172 if (gSystem->Getenv("ALIMDC_RFIO"))
173 rfioFS = gSystem->Getenv("ALIMDC_RFIO");
174 if (gSystem->Getenv("ALIMDC_CASTOR"))
175 castorFS = gSystem->Getenv("ALIMDC_CASTOR");
176 if (gSystem->Getenv("ALIMDC_ROOTD"))
177 rootdFS = gSystem->Getenv("ALIMDC_ROOTD");
179 // Handle command line arguments
180 if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
182 argc > 7 || argc < 6) {
184 argc > 6 || argc < 5) {
193 strcpy(smiobj, argv[iarg]);
194 smi_attach(smiobj, SMI_handle_command);
196 smi_set_state("RUNNING");
200 AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
201 Int_t filterMode = 0;
202 Bool_t useLoop = kFALSE;
203 Bool_t delFiles = kFALSE;
205 Double_t maxFileSize;
207 const char* fs1 = NULL;
208 const char* fs2 = NULL;
210 // no special arg checking so don't make errors
211 if (argv[iarg][0] == '-') {
213 maxFileSize = atoll(argv[iarg]+1);
215 maxFileSize = atoll(argv[iarg]);
216 if (maxFileSize < 1000 || maxFileSize > 20.e9) {
217 Error(argv[0], "unreasonable file size %f\n", maxFileSize);
222 maxTagSize = atoi(argv[iarg]);
223 if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 20.e9)) {
224 Error(argv[0], "unreasonable tag file size %f\n", maxTagSize);
227 if (maxTagSize == 0) tagDBFS = NULL;
230 filterMode = atoi(argv[iarg]);
231 if (filterMode < 0 || filterMode > 2) {
232 Error(argv[0], "unreasonable filter mode %d\n", filterMode);
237 if (argv[iarg][0] == '-') {
238 wmode = AliMDC::kRFIO;
239 compress = atoi(argv[iarg]+1);
241 } else if (argv[iarg][0] == '+') {
242 wmode = AliMDC::kROOTD;
243 compress = atoi(argv[iarg]+1);
245 } else if (argv[iarg][0] == '%') {
246 wmode = AliMDC::kCASTOR;
247 compress = atoi(argv[iarg]+1);
249 } else if (argv[iarg][0] == '@') {
250 wmode = AliMDC::kDEVNULL;
251 compress = atoi(argv[iarg]+1);
253 compress = atoi(argv[iarg]);
258 Error(argv[0], "unreasonable compression mode %d\n", compress);
266 if (argv[iarg][0] == '-') {
272 // Create MDC processor object and process input stream
273 AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode),
274 maxTagSize, tagDBFS);
276 Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2);
279 Info(argv[0], "normal termination of run");
281 Error(argv[0], "error termination of run, status: %d", result);