// //
///////////////////////////////////////////////////////////////////////////////
+#include <TGeoManager.h>
#include <TObjString.h>
#include <TStopwatch.h>
#include <TSystem.h>
-
-#include "AliLog.h"
+#include <TFile.h>
+
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliAlignObj.h"
+#include "AliCentralTrigger.h"
+#include "AliDAQConfig.h"
#include "AliDigitizer.h"
#include "AliGenerator.h"
+#include "AliLog.h"
#include "AliModule.h"
#include "AliRun.h"
#include "AliRunDigitizer.h"
#include "AliRunLoader.h"
#include "AliSimulation.h"
#include "AliVertexGenFile.h"
+#include "AliCentralTrigger.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(""),
fMakeDigitsFromHits(""),
fWriteRawData(""),
fRawDataFileName(""),
fGAliceFileName("galice.root"),
fEventsPerFile(),
fBkgrdFileNames(NULL),
+ fAlignObjArray(NULL),
fUseBkgrdVertex(kTRUE),
- fRegionOfInterest(kFALSE)
+ fRegionOfInterest(kFALSE),
+ fCDBUri(cdbUri)
{
// create simulation object with default parameters
fRunGeneration(sim.fRunGeneration),
fRunSimulation(sim.fRunSimulation),
+ fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
+ fLoadAlignData(sim.fLoadAlignData),
fMakeSDigits(sim.fMakeSDigits),
fMakeDigits(sim.fMakeDigits),
+ fMakeTrigger(sim.fMakeTrigger),
fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
fWriteRawData(sim.fWriteRawData),
fRawDataFileName(""),
fGAliceFileName(sim.fGAliceFileName),
fEventsPerFile(),
fBkgrdFileNames(NULL),
+ fAlignObjArray(NULL),
fUseBkgrdVertex(sim.fUseBkgrdVertex),
- fRegionOfInterest(sim.fRegionOfInterest)
+ fRegionOfInterest(sim.fRegionOfInterest),
+ fCDBUri(sim.fCDBUri)
{
// copy constructor
// clean up
fEventsPerFile.Delete();
+// if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
+// delete fAlignObjArray; fAlignObjArray=0;
if (fBkgrdFileNames) {
fBkgrdFileNames->Delete();
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)
{
fEventsPerFile.Add(obj);
}
+//_____________________________________________________________________________
+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
+ // them to the TGeo geometry passed as argument
+ //
+
+ TFile* inFile = TFile::Open(fileName,"READ");
+ if (!inFile || !inFile->IsOpen()) {
+ AliErrorClass(Form("Could not open file %s !",fileName));
+ return kFALSE;
+ }
+
+ TClonesArray* alObjArray = ((TClonesArray*) inFile->Get(clArrayName));
+ inFile->Close();
+ if (!alObjArray) {
+ AliErrorClass(Form("Could not get array (%s) from file (%s) !",clArrayName,fileName));
+ return kFALSE;
+ }
+
+ return gAlice->ApplyAlignObjsToGeom(alObjArray);
+
+}
+
+//_____________________________________________________________________________
+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
+ // param (to get the AliCDBStorage) and Id; apply the alignment objects
+ // to the TGeo geometry passed as argument
+ //
+
+ AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage(param);
+ AliCDBEntry* entry = storage->Get(Id);
+ TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
+
+ return gAlice->ApplyAlignObjsToGeom(AlObjArray);
+
+}
+
+//_____________________________________________________________________________
+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
+ // param (to get the AliCDBStorage) and Id; apply the alignment objects
+ // to the TGeo geometry passed as argument
+ //
+
+ AliCDBParam* param = AliCDBManager::Instance()->CreateParameter(uri);
+ AliCDBId id(path, runnum, runnum, version, sversion);
+
+ 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 gAlice->ApplyAlignObjsToGeom(AlObjArray);
+}
+
+
+//_____________________________________________________________________________
+void AliSimulation::SetAlignObjArray(const char* detectors)
+{
+ // Fills array of detectors' alignable objects from CDB
+ // detectors can be "ALL" or "ITS TPC ..."
+
+ AliRunLoader* runLoader = LoadRun();
+ if (!runLoader) return;
+
+ InitCDBStorage(fCDBUri);
+
+ if(!fAlignObjArray) fAlignObjArray = new TObjArray();
+ fAlignObjArray->SetOwner(0); // AliCDBEntry is owner of the align objects!
+ fAlignObjArray->Clear();
+
+ TString detStr = detectors;
+ TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+ TString dataNotLoaded="";
+ TString dataLoaded="";
+
+ 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 all 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()));
+
+ AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
+ delete detArray;
+
+}
+
+//_____________________________________________________________________________
+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;
+
+}
+
//_____________________________________________________________________________
void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
{
{
// run the generation, simulation and digitization
+ InitCDBStorage(fCDBUri);
+
if (nEvents > 0) fNEvents = nEvents;
// generation and simulation -> hits
}
}
+ // digits -> trigger
+ if (!fMakeTrigger.IsNull()) {
+ if (!RunTrigger(fMakeTrigger)) {
+ if (fStopOnError) return kFALSE;
+ }
+ }
+
// digits -> raw data
if (!fWriteRawData.IsNull()) {
if (!WriteRawData(fWriteRawData, fRawDataFileName,
return kTRUE;
}
+//_____________________________________________________________________________
+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;
+
+ runLoader->MakeTree( "CT" );
+ AliCentralTrigger* aCTP = runLoader->GetTrigger();
+ // Load Descriptors
+ aCTP->LoadDescriptor( des );
+
+ // digits -> trigger
+ if( !aCTP->RunTrigger( runLoader ) ) {
+ if (fStopOnError) {
+ // delete aCTP;
+ return kFALSE;
+ }
+ }
+
+ AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+ stopwatch.RealTime(),stopwatch.CpuTime()));
+
+ delete runLoader;
+
+ return kTRUE;
+}
+
+
+
//_____________________________________________________________________________
Bool_t AliSimulation::RunSimulation(Int_t nEvents)
{
StdoutToAliInfo(StderrToAliError(
gAlice->Init(fConfigFileName.Data());
););
+
+ // Set run number in CDBManager (here????)
+ 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");
+
+ // 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 (gAlice->ApplyAlignObjsToGeom(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;
+ }
+ }
+
+ // 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. "
delete runLoader;
- AliInfo("execution time:");
- StdoutToAliInfo(stopwatch.Print(););
+ AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+ stopwatch.RealTime(),stopwatch.CpuTime()));
return kTRUE;
}
TStopwatch stopwatchDet;
stopwatchDet.Start();
det->Hits2SDigits();
- AliInfo(Form("execution time for %s:", det->GetName()));
- StdoutToAliInfo(stopwatchDet.Print(););
+ AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
+ det->GetName(),stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
}
}
delete runLoader;
- AliInfo("execution time:");
- StdoutToAliInfo(stopwatch.Print(););
+ AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+ stopwatch.RealTime(),stopwatch.CpuTime()));
return kTRUE;
}
delete manager;
- AliInfo("execution time:");
- StdoutToAliInfo(stopwatch.Print(););
-
+ AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+ stopwatch.RealTime(),stopwatch.CpuTime()));
+
return kTRUE;
}
if (fStopOnError) return kFALSE;
}
- //PH delete runLoader;
+ delete runLoader;
//PH Temporary fix to avoid interference with the PHOS loder/getter
//PH The problem has to be solved in more general way 09/06/05
- AliInfo("execution time:");
- StdoutToAliInfo(stopwatch.Print(););
+ AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+ stopwatch.RealTime(),stopwatch.CpuTime()));
return kTRUE;
}
}
}
- AliInfo("execution time:");
- StdoutToAliInfo(stopwatch.Print(););
+ AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
+ stopwatch.RealTime(),stopwatch.CpuTime()));
return kTRUE;
}
{
// convert raw data DDL files to a DATE file with the program "dateStream"
- // DATE setup
- const Int_t kNDetectors = 17;
- const char* kDetectors[kNDetectors] = {"TPC", "ITSSPD", "ITSSDD", "ITSSSD",
- "TRD", "TOF", "PHOS", "RICH",
- "EMCAL", "MUON", "MUTR", "ZDC",
- "PMD", "START", "VZERO", "CRT",
- "FMD"};
- const Int_t kDetectorDDLs[kNDetectors] = {216, 20, 12, 16,
- 18, 72, 20, 20,
- 22, 20, 2, 1,
- 6, 1, 1, 1,
- 3};
- const Float_t kDetectorLDCs[kNDetectors] = {46, 2, 2, 1,
- 4, 2, 1, 2,
- 1, 2, 1, 1,
- 1, 0.5, 0.5, 1,
- 1};
-
char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
if (!path) {
AliError("the program dateStream was not found");
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);
}