]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
Support for automatic pedestal estimation per pad (Marian and Matevz).
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index a0261812a04d1e26e32a11ab18a3dfa1f54aa27e..3f1427952538ba8928466588d07a52e81fb65b9f 100644 (file)
 #include <TObjString.h>
 #include <TStopwatch.h>
 #include <TSystem.h>
+#include <TFile.h>
 
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "AliSimulation.h"
 #include "AliVertexGenFile.h"
 #include "AliCentralTrigger.h"
+#include "AliCTPRawData.h"
 
 ClassImp(AliSimulation)
 
 
 //_____________________________________________________________________________
-AliSimulation::AliSimulation(const char* configFileName,
+AliSimulation::AliSimulation(const char* configFileName, const char* cdbUri,
                             const char* name, const char* title) :
   TNamed(name, title),
 
   fRunGeneration(kTRUE),
   fRunSimulation(kTRUE),
+  fLoadAlignFromCDB(kTRUE),
+  fLoadAlignData("ALL"),
   fMakeSDigits("ALL"),
   fMakeDigits("ALL"),
   fMakeTrigger(""),
@@ -153,7 +157,8 @@ AliSimulation::AliSimulation(const char* configFileName,
   fBkgrdFileNames(NULL),
   fAlignObjArray(NULL),
   fUseBkgrdVertex(kTRUE),
-  fRegionOfInterest(kFALSE)
+  fRegionOfInterest(kFALSE),
+  fCDBUri(cdbUri)
 {
 // create simulation object with default parameters
 
@@ -166,6 +171,8 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
 
   fRunGeneration(sim.fRunGeneration),
   fRunSimulation(sim.fRunSimulation),
+  fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
+  fLoadAlignData(sim.fLoadAlignData),
   fMakeSDigits(sim.fMakeSDigits),
   fMakeDigits(sim.fMakeDigits),
   fMakeTrigger(sim.fMakeTrigger),
@@ -182,7 +189,8 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fBkgrdFileNames(NULL),
   fAlignObjArray(NULL),
   fUseBkgrdVertex(sim.fUseBkgrdVertex),
-  fRegionOfInterest(sim.fRegionOfInterest)
+  fRegionOfInterest(sim.fRegionOfInterest),
+  fCDBUri(sim.fCDBUri)
 {
 // copy constructor
 
@@ -214,6 +222,8 @@ AliSimulation::~AliSimulation()
 // clean up
 
   fEventsPerFile.Delete();
+//  if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
+//  delete fAlignObjArray; fAlignObjArray=0;
 
   if (fBkgrdFileNames) {
     fBkgrdFileNames->Delete();
@@ -230,6 +240,41 @@ void AliSimulation::SetNumberOfEvents(Int_t nEvents)
   fNEvents = nEvents;
 }
 
+//_____________________________________________________________________________
+void AliSimulation::InitCDBStorage(const char* uri)
+{
+// activate a default CDB storage
+// First check if we have any CDB storage set, because it is used 
+// to retrieve the calibration and alignment constants
+
+  AliCDBManager* man = AliCDBManager::Instance();
+  if (!man->IsDefaultStorageSet())
+  {
+    AliWarningClass("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    AliWarningClass("Default CDB storage not yet set");
+    AliWarningClass(Form("Using default storage declared in AliSimulation: %s",uri));
+    AliWarningClass("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+    SetDefaultStorage(uri);
+  }  
+  
+}
+
+//_____________________________________________________________________________
+void AliSimulation::SetDefaultStorage(const char* uri) {
+// activate a default CDB storage 
+
+   AliCDBManager::Instance()->SetDefaultStorage(uri);
+
+}
+
+//_____________________________________________________________________________
+void AliSimulation::SetSpecificStorage(const char* detName, const char* uri) {
+// activate a detector-specific CDB storage 
+
+   AliCDBManager::Instance()->SetSpecificStorage(detName, uri);
+
+}
+
 //_____________________________________________________________________________
 void AliSimulation::SetConfigFile(const char* fileName)
 {
@@ -268,7 +313,37 @@ void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::ApplyDisplacements(const char* fileName, const char* clArrayName)
+Bool_t AliSimulation::ApplyAlignObjsToGeom(TObjArray* alObjArray)
+{
+  // Read collection of alignment objects (AliAlignObj derived) saved
+  // in the TClonesArray ClArrayName and apply them to the geometry
+  // manager singleton.
+  //
+  alObjArray->Sort();
+  Int_t nvols = alObjArray->GetEntriesFast();
+
+  Bool_t flag = kTRUE;
+
+  for(Int_t j=0; j<nvols; j++)
+    {
+      AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
+      if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
+    }
+
+  if (AliDebugLevelClass() >= 1) {
+    gGeoManager->CheckOverlaps(20);
+    TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
+    if(ovexlist->GetEntriesFast()){  
+      AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
+   }
+  }
+
+  return flag;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* fileName, const char* clArrayName)
 {
   // read collection of alignment objects (AliAlignObj derived) saved
   // in the TClonesArray ClArrayName in the file fileName and apply
@@ -288,12 +363,12 @@ Bool_t AliSimulation::ApplyDisplacements(const char* fileName, const char* clArr
     return kFALSE;
   }
 
-  return gAlice->ApplyDisplacements(alObjArray);
+  return ApplyAlignObjsToGeom(alObjArray);
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::ApplyDisplacements(AliCDBParam* param, AliCDBId& Id)
+Bool_t AliSimulation::ApplyAlignObjsToGeom(AliCDBParam* param, AliCDBId& Id)
 {
   // read collection of alignment objects (AliAlignObj derived) saved
   // in the TClonesArray ClArrayName in the AliCDBEntry identified by
@@ -305,12 +380,12 @@ Bool_t AliSimulation::ApplyDisplacements(AliCDBParam* param, AliCDBId& Id)
   AliCDBEntry* entry = storage->Get(Id);
   TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
 
-  return gAlice->ApplyDisplacements(AlObjArray);
+  return ApplyAlignObjsToGeom(AlObjArray);
 
 }
 
 //_____________________________________________________________________________
-Bool_t AliSimulation::ApplyDisplacements(const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion)
+Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion)
 {
   // read collection of alignment objects (AliAlignObj derived) saved
   // in the TClonesArray ClArrayName in the AliCDBEntry identified by
@@ -321,8 +396,159 @@ Bool_t AliSimulation::ApplyDisplacements(const char* uri, const char* path, Int_
   AliCDBParam* param = AliCDBManager::Instance()->CreateParameter(uri);
   AliCDBId id(path, runnum, runnum, version, sversion);
 
-  return ApplyDisplacements(param, id);
+  return ApplyAlignObjsToGeom(param, id);
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::ApplyAlignObjsToGeom(const char* detName, Int_t runnum, Int_t version, Int_t sversion)
+{
+  // read collection of alignment objects (AliAlignObj derived) saved
+  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
+  // param (to get the AliCDBStorage) and Id; apply the alignment objects
+  // to the TGeo geometry passed as argument
+  //
+
+  InitCDBStorage("local://$ALICE_ROOT");
+  AliCDBPath path(detName,"Align","Data");
+  AliCDBEntry* entry = AliCDBManager::Instance()->Get(path.GetPath(),runnum,version,sversion);
+
+  if(!entry) return kFALSE;
+  TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
+
+  return ApplyAlignObjsToGeom(AlObjArray);
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::SetAlignObjArraySingleDet(const char* detName)
+{
+  // Fills array of single detector's alignable objects from CDB
+  
+  AliDebug(2, Form("Loading alignment data for detector: %s",detName));
+  
+  AliCDBEntry *entry;
+       
+  AliCDBPath path(detName,"Align","Data");
+       
+  entry=AliCDBManager::Instance()->Get(path.GetPath());
+  if(!entry){ 
+       AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
+       return kFALSE;
+  }
+  entry->SetOwner(1);
+  TClonesArray *alignArray = (TClonesArray*) entry->GetObject();       
+  alignArray->SetOwner(0);
+  AliDebug(2,Form("Found %d alignment objects for %s",
+                       alignArray->GetEntries(),detName));
+
+  AliAlignObj *alignObj=0;
+  TIter iter(alignArray);
+       
+  // loop over align objects in detector
+  while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
+       fAlignObjArray->Add(alignObj);
+  }
+  // delete entry --- Don't delete, it is cached!
+       
+  AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
+{
+  // Read the alignment objects from CDB.
+  // Each detector is supposed to have the
+  // alignment objects in DET/Align/Data CDB path.
+  // All the detector objects are then collected,
+  // sorted by geometry level (starting from ALIC) and
+  // then applied to the TGeo geometry.
+  // Finally an overlaps check is performed.
+
+  Bool_t delRunLoader = kFALSE;
+  if (!runLoader) {
+    runLoader = LoadRun("READ");
+    if (!runLoader) return kFALSE;
+    delRunLoader = kTRUE;
+  }
+
+  // Load alignment data from CDB and fill fAlignObjArray 
+  if(fLoadAlignFromCDB){
+       if(!fAlignObjArray) fAlignObjArray = new TObjArray();
+       
+       //fAlignObjArray->RemoveAll(); 
+       fAlignObjArray->Clear();        
+       fAlignObjArray->SetOwner(0);
+       TString detStr = fLoadAlignData;
+       TString dataNotLoaded="";
+       TString dataLoaded="";
+  
+       TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+       for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
+               AliModule* det = (AliModule*) detArray->At(iDet);
+               if (!det || !det->IsActive()) continue;
+               if (IsSelected(det->GetName(), detStr)) {
+                       if(!SetAlignObjArraySingleDet(det->GetName())){
+                               dataNotLoaded += det->GetName();
+                               dataNotLoaded += " ";
+                       } else {
+                               dataLoaded += det->GetName();
+                               dataLoaded += " ";
+                       }
+               }
+       } // end loop over detectors
+  
+       if ((detStr.CompareTo("ALL") == 0)) detStr = "";
+       dataNotLoaded += detStr;
+       AliInfo(Form("Alignment data loaded for: %s",
+                         dataLoaded.Data()));
+       AliInfo(Form("Didn't/couldn't load alignment data for: %s",
+                         dataNotLoaded.Data()));
+  } // fLoadAlignFromCDB flag
+  // Check if the array with alignment objects was
+  // provided by the user. If yes, apply the objects
+  // to the present TGeo geometry
+  if (fAlignObjArray) {
+    if (gGeoManager && gGeoManager->IsClosed()) {
+      if (ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
+       AliError("The misalignment of one or more volumes failed!"
+                "Compare the list of simulated detectors and the list of detector alignment data!");
+       if (delRunLoader) delete runLoader;
+       return kFALSE;
+      }
+    }
+    else {
+      AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
+      if (delRunLoader) delete runLoader;
+      return kFALSE;
+    }
+  }
+
+  if (delRunLoader) delete runLoader;
+
+  return kTRUE;
+}
+
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::SetRunNumber()
+{
+  // Set the CDB manager run number
+  // The run number is retrieved from gAlice
 
+  if(AliCDBManager::Instance()->GetRun() < 0) {
+    AliRunLoader* runLoader = LoadRun("READ");
+    if (!runLoader) return kFALSE;
+    else {
+      AliCDBManager::Instance()->SetRun(runLoader->GetAliRun()->GetRunNumber());
+      AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
+      delete runLoader;
+    }
+  }
+  return kTRUE;
 }
 
 //_____________________________________________________________________________
@@ -342,6 +568,8 @@ Bool_t AliSimulation::Run(Int_t nEvents)
 {
 // run the generation, simulation and digitization
 
+  InitCDBStorage(fCDBUri);
+
   if (nEvents > 0) fNEvents = nEvents;
 
   // generation and simulation -> hits
@@ -349,6 +577,16 @@ Bool_t AliSimulation::Run(Int_t nEvents)
     if (!RunSimulation()) if (fStopOnError) return kFALSE;
   }
 
+  // Set run number in CDBManager (if it is not already set in RunSimulation)
+  if (!SetRunNumber()) if (fStopOnError) return kFALSE;
+
+  // Load and misalign the geometry
+  if (!gGeoManager) {
+    TGeoManager::Import("geometry.root");
+    if (!gGeoManager) if (fStopOnError) return kFALSE;
+    if (!MisalignGeometry()) if (fStopOnError) return kFALSE;
+  }
+
   // hits -> summable digits
   if (!fMakeSDigits.IsNull()) {
     if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
@@ -375,10 +613,8 @@ Bool_t AliSimulation::Run(Int_t nEvents)
   }
 
   // digits -> trigger
-  if (!fMakeTrigger.IsNull()) {
-    if (!RunTrigger(fMakeTrigger)) {
-      if (fStopOnError) return kFALSE;
-    }
+  if (!RunTrigger(fMakeTrigger)) {
+    if (fStopOnError) return kFALSE;
   }
 
   // digits -> raw data
@@ -397,79 +633,56 @@ Bool_t AliSimulation::RunTrigger(const char* descriptors)
 {
   // run the trigger
 
-  TStopwatch stopwatch;
-  stopwatch.Start();
-
-  AliRunLoader* runLoader = LoadRun("READ");
-  if (!runLoader) return kFALSE;
-  TString des = descriptors;
+   TStopwatch stopwatch;
+   stopwatch.Start();
+
+   AliRunLoader* runLoader = LoadRun("READ");
+   if (!runLoader) return kFALSE;
+   TString des = descriptors;
+
+   if (des.IsNull()) {
+     if (gAlice->GetTriggerDescriptor() != "") {
+       des = gAlice->GetTriggerDescriptor();
+     }
+     else {
+       AliWarning("No trigger descriptor is specified. Skipping the trigger simulation...");
+       return kTRUE;
+     }
+   }
+
+   runLoader->MakeTree( "CT" );
+   AliCentralTrigger* aCTP = runLoader->GetTrigger();
   // Load Descriptors
-  AliCentralTrigger* aCTP = new AliCentralTrigger( des );
+   aCTP->LoadDescriptor( des );
 
   // digits -> trigger
-  if( !aCTP->RunTrigger( runLoader ) ) {
-    if (fStopOnError) {
-      delete aCTP;
-      return kFALSE;
-    }
-  }
-
-/*
-  // Process each event
-  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
-    AliInfo(Form("processing event %d", iEvent));
-    runLoader->GetEvent(iEvent);
-
-    TObjArray* detArray = runLoader->GetAliRun()->Detectors();
-    for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
-      AliModule* det = (AliModule*) detArray->At(iDet);
-      if (!det || !det->IsActive()) continue;
-      if (IsSelected(det->GetName(), detStr)) {
-        AliInfo(Form("triggering from digits for %s", det->GetName()));
-
-     //   AliLoader* loader = fLoader[iDet];
-     //   loader->LoadDigits("read");
-     //   TTree* digitsTree = loader->TreeD();
-     //   det->Trigger( digitsTree );
-     // or
-        AliTriggerDetector* tdet = det->CreateTriggerDetector();
-        TObjArray* detInp = dtrg->GetTriggerInputs();
-        for( Int_t i=0; i<detInp->GetEntriesFast(); i++ )
-               fInputs.AddLast( detInp->At(i) );
-
-        AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
-                det->GetName(),stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
-      }
-    }
-
-    if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
-      AliError(Form("the following detectors were not found: %s",
-                    detStr.Data()));
+   if( !aCTP->RunTrigger( runLoader ) ) {
       if (fStopOnError) {
-         delete centralTP;
+    //  delete aCTP;
          return kFALSE;
       }
-    }
+   }
 
-    // Check trigger conditions
-    centralTP->TriggerConditions();
+   AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+           stopwatch.RealTime(),stopwatch.CpuTime()));
 
-    // Write trigger ????
-    centralTP->Write();
+   delete runLoader;
 
-  } */
-
-  AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
-               stopwatch.RealTime(),stopwatch.CpuTime()));
+   return kTRUE;
+}
 
-  delete aCTP;
-  delete runLoader;
+//_____________________________________________________________________________
+Bool_t AliSimulation::WriteTriggerRawData()
+{
+  // Writes the CTP (trigger) DDL raw data
+  // Details of the format are given in the
+  // trigger TDR - pages 134 and 135.
+  AliCTPRawData writer;
+  writer.RawData();
 
   return kTRUE;
 }
 
-
-
 //_____________________________________________________________________________
 Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 {
@@ -493,32 +706,63 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
     gAlice->Init(fConfigFileName.Data());
   ););
 
-  // Check if the array with alignment objects was
-  // provided by the user. If yes, apply the objects
-  // to the present TGeo geometry
-  if (fAlignObjArray) {
-    if (gGeoManager && gGeoManager->IsClosed()) {
-      if (gAlice->ApplyDisplacements(fAlignObjArray) == kFALSE) {
-       AliError("The application of misalignment failed! Restart aliroot and try again. ");
-       return kFALSE;
-      }
-    }
-    else {
-      AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
-      return kFALSE;
-    }
+  // Get the trigger descriptor string
+  // Either from AliSimulation or from
+  // gAlice
+  if (fMakeTrigger.IsNull()) {
+    if (gAlice->GetTriggerDescriptor() != "")
+      fMakeTrigger = gAlice->GetTriggerDescriptor();
   }
+  else
+    gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
 
-  // Export TGeo geometry
-  if (gGeoManager) gGeoManager->Export("geometry.root");
+  // Set run number in CDBManager
+  AliCDBManager::Instance()->SetRun(gAlice->GetRunNumber());
+  AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
 
   AliRunLoader* runLoader = gAlice->GetRunLoader();
   if (!runLoader) {
-    AliError(Form("gAlice has no run loader object. "
-                  "Check your config file: %s", fConfigFileName.Data()));
-    return kFALSE;
+             AliError(Form("gAlice has no run loader object. "
+                            "Check your config file: %s", fConfigFileName.Data()));
+             return kFALSE;
   }
   SetGAliceFile(runLoader->GetFileName());
+  // Export ideal geometry 
+  if (gGeoManager) gGeoManager->Export("geometry.root");
+
+  // Misalign geometry
+//   if (!MisalignGeometry(runLoader)) {
+//     delete runLoader;
+//     return kFALSE;
+//   }
+  MisalignGeometry(runLoader);
+
+  // Temporary fix by A.Gheata
+  // Could be removed with the next Root version (>5.11)
+  if (gGeoManager) {
+    TIter next(gGeoManager->GetListOfVolumes());
+    TGeoVolume *vol;
+    while ((vol = (TGeoVolume *)next())) {
+      if (vol->GetVoxels()) {
+       if (vol->GetVoxels()->NeedRebuild()) {
+         vol->GetVoxels()->Voxelize();
+         vol->FindOverlaps();
+       }
+      }
+    }
+  }
+
+  // Export (mis)aligned geometry 
+  if (gGeoManager) gGeoManager->Export("misaligned_geometry.root");
+
+//   AliRunLoader* runLoader = gAlice->GetRunLoader();
+//   if (!runLoader) {
+//     AliError(Form("gAlice has no run loader object. "
+//                   "Check your config file: %s", fConfigFileName.Data()));
+//     return kFALSE;
+//   }
+//   SetGAliceFile(runLoader->GetFileName());
 
   if (!gAlice->Generator()) {
     AliError(Form("gAlice has no generator object. "
@@ -813,6 +1057,9 @@ Bool_t AliSimulation::WriteRawFiles(const char* detectors)
       }
     }
 
+    if (!WriteTriggerRawData())
+      if (fStopOnError) return kFALSE;
+
     gSystem->ChangeDirectory(baseDir);
     if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
       AliError(Form("the following detectors were not found: %s", 
@@ -843,7 +1090,7 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName)
 
   AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
   char command[256];
-  sprintf(command, "dateStream -o %s -# %d -C", 
+  sprintf(command, "dateStream -D -o %s -# %d -C", 
          dateFileName, runLoader->GetNumberOfEvents());
   FILE* pipe = gSystem->OpenPipe(command, "w");
 
@@ -910,20 +1157,38 @@ Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
   AliInfo(Form("converting DATE file %s to root file %s", 
                dateFileName, rootFileName));
 
-  gSystem->Exec("rm -rf /tmp/mdc1");
-  gSystem->Exec("rm -rf /tmp/mdc2");
-
-  gSystem->Exec("mkdir /tmp/mdc1");
-  gSystem->Exec("mkdir /tmp/mdc2");
-
-  char command[256];
-  sprintf(command, "alimdc %d %d %d %d %s", 
-         kDBSize, kTagDBSize, kFilter, kCompression, dateFileName);
-  Int_t result = gSystem->Exec(command);
-  sprintf(command, "mv /tmp/mdc1/*.root %s", rootFileName);
-  gSystem->Exec(command);
-  gSystem->Exec("rm -rf /tmp/mdc1");
-  gSystem->Exec("rm -rf /tmp/mdc2");
+  const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
+  const char* tagDBFS    = "/tmp/mdc1/tags";
+  const char* runDBFS    = "/tmp/mdc1/meta";
+
+  // User defined file system locations
+  if (gSystem->Getenv("ALIMDC_RAWDB1")) 
+    rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
+  if (gSystem->Getenv("ALIMDC_RAWDB2")) 
+    rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
+  if (gSystem->Getenv("ALIMDC_TAGDB")) 
+    tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
+  if (gSystem->Getenv("ALIMDC_RUNDB")) 
+    runDBFS = gSystem->Getenv("ALIMDC_RUNDB");
+
+  gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
+  gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
+  gSystem->Exec(Form("rm -rf %s",tagDBFS));
+  gSystem->Exec(Form("rm -rf %s",runDBFS));
+
+  gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
+  gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
+  gSystem->Exec(Form("mkdir %s",tagDBFS));
+  gSystem->Exec(Form("mkdir %s",runDBFS));
+
+  Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s", 
+                                   kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
+  gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
+
+  gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
+  gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
+  gSystem->Exec(Form("rm -rf %s",tagDBFS));
+  gSystem->Exec(Form("rm -rf %s",runDBFS));
 
   return (result == 0);
 }