LCOV - code coverage report
Current view: top level - RAW/alimdc - alimdc_main.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 57 108 52.8 %
Date: 2016-06-14 17:26:59 Functions: 2 3 66.7 %

          Line data    Source code
       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             : #include <AliLog.h>
      27             : 
      28             : #ifdef USE_SMI
      29             : extern "C" {
      30             :    #include <smirtl.h>
      31             : }
      32             : #endif
      33             : 
      34             : #include "AliMDC.h"
      35             : 
      36             : #ifdef __APPLE__
      37             : // avoid loading pythia and pdf
      38             : #include <Hepevt.h>
      39             : #endif
      40             : 
      41             : //______________________________________________________________________________
      42             : static void AliMDCErrorHandler(int level, Bool_t abort, const char *location,
      43             :                                const char *msg)
      44             : {
      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
      48             :    // of each message.
      49             : 
      50           3 :    if (level < gErrorIgnoreLevel)
      51             :       return;
      52             : 
      53             :    const char *type = 0;
      54             : 
      55           3 :    if (level >= kInfo)
      56             :       type = "Info";
      57           3 :    if (level >= kWarning)
      58             :       type = "Warning";
      59           3 :    if (level >= kError)
      60             :       type = "Error";
      61           3 :    if (level >= kBreak)
      62             :       type = "\n *** Break ***";
      63           3 :    if (level >= kSysError)
      64             :       type = "SysError";
      65           3 :    if (level >= kFatal)
      66             :       type = "Fatal";
      67             : 
      68           3 :    TDatime dt;
      69             : 
      70           3 :    if (level >= kBreak && level < kSysError)
      71           0 :       fprintf(stderr, "%s: %s %s\n", dt.AsSQLString(), type, msg);
      72           9 :    else if (!location || strlen(location) == 0)
      73           0 :       fprintf(stderr, "%s: %s: %s\n", dt.AsSQLString(), type, msg);
      74             :    else
      75           6 :       fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location,
      76             :               msg);
      77             : 
      78           3 :    fflush(stderr);
      79           3 :    if (abort) {
      80           0 :       fprintf(stderr, "aborting\n");
      81           0 :       fflush(stderr);
      82           0 :       if (gSystem) {
      83           0 :          gSystem->StackTrace();
      84           0 :          gSystem->Abort();
      85             :       } else
      86           0 :          ::abort();
      87             :    }
      88           6 : }
      89             : 
      90             : #ifdef USE_SMI
      91             : static void SMI_handle_command()
      92             : {
      93             :    // Handle SMI commands
      94             : 
      95             :    char action[64], param[64];
      96             :    int n_params;
      97             : 
      98             :    smi_get_action(action, &n_params);
      99             :    if (n_params >= 1) {
     100             :       smi_get_par_value("PARAM", param);
     101             :    } else {
     102             :       strcpy(param, "");
     103             :    }
     104             :    if (strcmp(action, "STOP") == 0) {
     105             :       if (AliMDC::Instance()) AliMDC::Instance()->SetStopLoop();
     106             :    }
     107             :    smi_set_state("RUNNING");
     108             : }
     109             : #endif
     110             : 
     111             : //______________________________________________________________________________
     112             : static void Usage(const char *prognam)
     113             : {
     114             : #ifdef USE_SMI
     115             :       fprintf(stderr, "Usage: %s <sminame> <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
     116             :               prognam);
     117             :       fprintf(stderr, " <sminame> = name used by SMI\n");
     118             : #else
     119           0 :       fprintf(stderr, "Usage: %s <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n",
     120             :               prognam);
     121             : #endif
     122           0 :       fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n");
     123           0 :       fprintf(stderr, "    (precede by - to delete raw and tag databases on close)\n");
     124           0 :       fprintf(stderr, " <tagdbsize> = maximum tag DB size (in bytes, 0 for no tag DB)\n");
     125           0 :       fprintf(stderr, " <filter> = state of 3rd level filter (0: off, 1: transparent, 2: on)\n");
     126           0 :       fprintf(stderr, " <compmode> = compression level (see TFile)\n");
     127           0 :       fprintf(stderr, "    (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
     128           0 :       fprintf(stderr, "    (precede by + to use rootd, +0 is rootd and 0 compression)\n");
     129           0 :       fprintf(stderr, "    (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
     130           0 :       fprintf(stderr, "    (precede by @ to use /dev/null as sink)\n");
     131           0 :       fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
     132           0 :       fprintf(stderr, "    (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
     133           0 : }
     134             : 
     135             : //______________________________________________________________________________
     136             : int main(int argc, char **argv)
     137             : {
     138             :    // Convert a DATE data stream to a ROOT DB.
     139             : 
     140             :    // Set ROOT in batch mode
     141           2 :    gROOT->SetBatch();
     142             : 
     143             :    // Set custom error handler
     144           1 :    AliLog::SetHandleRootMessages(kFALSE);
     145           1 :    SetErrorHandler(AliMDCErrorHandler);
     146             : 
     147             :    // Default file system locations
     148             : #ifdef USE_EB
     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";
     153             : #else
     154             :    const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
     155             :    const char* tagDBFS    = "/tmp/mdc1/tags";
     156           3 :    TString user(gSystem->Getenv("USER")[0] + TString("/") + 
     157           1 :                 gSystem->Getenv("USER"));
     158           1 :    TString rfioStr("rfio:/castor/cern.ch/user/" + user);
     159           1 :    const char* rfioFS     = rfioStr.Data();
     160           1 :    TString castorStr("castor:/castor/cern.ch/user/" + user);
     161           1 :    const char* castorFS   = castorStr.Data();
     162             : #endif
     163             :    const char* rootdFS    = "root://localhost//tmp/mdc1";
     164             :    
     165             :    Int_t basketSize = 16000;
     166             :    Long64_t autoflush = -5000000LL;
     167             : 
     168             :    // User defined file system locations
     169           2 :    if (gSystem->Getenv("ALIMDC_RAWDB1")) 
     170           0 :      rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
     171           2 :    if (gSystem->Getenv("ALIMDC_RAWDB2")) 
     172           0 :      rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
     173           2 :    if (gSystem->Getenv("ALIMDC_TAGDB")) 
     174           0 :      tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
     175           2 :    if (gSystem->Getenv("ALIMDC_RFIO")) 
     176           0 :      rfioFS = gSystem->Getenv("ALIMDC_RFIO");
     177           2 :    if (gSystem->Getenv("ALIMDC_CASTOR")) 
     178           0 :      castorFS = gSystem->Getenv("ALIMDC_CASTOR");
     179           2 :    if (gSystem->Getenv("ALIMDC_ROOTD")) 
     180           0 :      rootdFS = gSystem->Getenv("ALIMDC_ROOTD");
     181             : 
     182             :    // User defined basket and autoflush settings
     183           2 :    TString autoflushS = gSystem->Getenv("ALIMDC_AUTOFLUSH");
     184           2 :    if (!autoflushS.IsNull()) {
     185           0 :      autoflush = autoflushS.Atoll();
     186           0 :      Info(argv[0],"Set autoflush to %lld",autoflush);
     187             :    }
     188           2 :    TString bsksizeS = gSystem->Getenv("ALIMDC_BASKETSIZE");
     189           2 :    if (!bsksizeS.IsNull()) {
     190           0 :      basketSize = bsksizeS.Atoi();
     191           0 :      Info(argv[0],"Set basket size to %d",basketSize);
     192             :    }
     193             : 
     194             :    // Handle command line arguments
     195           1 :    if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
     196             : #ifdef USE_SMI
     197             :        argc > 7 || argc < 6) {
     198             : #else
     199           1 :        argc > 6 || argc < 5) {
     200             : #endif
     201           0 :       Usage(argv[0]);
     202           0 :       return 1;
     203             :    }
     204             : 
     205             :    Int_t iarg = 1;
     206             : #ifdef USE_SMI
     207             :    char smiobj[128];
     208             :    strcpy(smiobj, argv[iarg]);
     209             :    smi_attach(smiobj, SMI_handle_command);
     210             :    smi_volatile();
     211             :    smi_set_state("RUNNING");
     212             :    iarg++;
     213             : #endif
     214             : 
     215             :    AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
     216             :    Int_t    filterMode = 0;
     217             :    Bool_t   useLoop = kFALSE;
     218             :    Bool_t   delFiles = kFALSE;
     219             :    Int_t    compress;
     220             :    Double_t maxFileSize;
     221             :    Double_t maxTagSize;
     222             :    const char* fs1 = NULL;
     223             :    const char* fs2 = NULL;
     224             : 
     225             :    // no special arg checking so don't make errors
     226           1 :    if (argv[iarg][0] == '-') {
     227             :       delFiles = kTRUE;
     228           0 :       maxFileSize = atoll(argv[iarg]+1);
     229           0 :    } else
     230           2 :       maxFileSize = atoll(argv[iarg]);
     231           1 :    if (maxFileSize < 1000 || maxFileSize > 20.e9) {
     232           0 :       Error(argv[0], "unreasonable file size %f\n", maxFileSize);
     233           0 :       return 1;
     234             :    }
     235             :    iarg++;
     236             : 
     237           2 :    maxTagSize = atoi(argv[iarg]);
     238           2 :    if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 20.e9)) {
     239           0 :       Error(argv[0], "unreasonable tag file size %f\n", maxTagSize);
     240           0 :       return 1;
     241             :    }
     242           1 :    if (maxTagSize == 0) tagDBFS = NULL;
     243             :    iarg++;
     244             : 
     245           1 :    filterMode = atoi(argv[iarg]);
     246           1 :    if (filterMode < 0 || filterMode > 2) {
     247           0 :       Error(argv[0], "unreasonable filter mode %d\n", filterMode);
     248           0 :       return 1;
     249             :    }
     250             :    iarg++;
     251             : 
     252           1 :    if (argv[iarg][0] == '-') {
     253             :       wmode = AliMDC::kRFIO;
     254           0 :       compress = atoi(argv[iarg]+1);
     255             :       fs1 = rfioFS;
     256           1 :    } else if (argv[iarg][0] == '+') {
     257             :       wmode = AliMDC::kROOTD;
     258           0 :       compress = atoi(argv[iarg]+1);
     259             :       fs1 = rootdFS;
     260           1 :    } else if (argv[iarg][0] == '%') {
     261             :       wmode = AliMDC::kCASTOR;
     262           0 :       compress = atoi(argv[iarg]+1);
     263             :       fs1 = castorFS;
     264           1 :    } else if (argv[iarg][0] == '@') {
     265             :       wmode = AliMDC::kDEVNULL;
     266           0 :       compress = atoi(argv[iarg]+1);
     267           0 :    } else {
     268           1 :       compress = atoi(argv[iarg]);
     269             :       fs1 = rawDBFS[0];
     270             :       fs2 = rawDBFS[1];
     271             :    }
     272           1 :    if (compress > 9) {
     273           0 :       Error(argv[0], "unreasonable compression mode %d\n", compress);
     274           0 :       return 1;
     275             :    }
     276             :    iarg++;
     277             : 
     278             :    char* file = NULL;
     279           1 :    if (iarg < argc) {
     280           1 :       file = argv[iarg];
     281           1 :       if (argv[iarg][0] == '-') {
     282             :          useLoop = kTRUE;
     283           0 :          file = argv[iarg]+1;
     284           0 :       }
     285             :    }
     286             : 
     287             :    // Create MDC processor object and process input stream
     288           1 :    AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode), 
     289             :                   maxTagSize, tagDBFS,NULL,basketSize,autoflush);
     290             : 
     291           1 :    Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2);
     292             : 
     293           2 :    if (result == 0)
     294           2 :       Info(argv[0], "normal termination of run");
     295             :    else
     296           0 :       Error(argv[0], "error termination of run, status: %d", result);
     297             :    return result;
     298           2 : }

Generated by: LCOV version 1.11