#include "AliMC.h"
#include "AliHLTSimulation.h"
#include "AliQADataMakerSteer.h"
+#include "AliSysInfo.h"
ClassImp(AliSimulation)
fWriteRawData(""),
fRawDataFileName(""),
fDeleteIntermediateFiles(kFALSE),
+ fWriteSelRawData(kFALSE),
fStopOnError(kFALSE),
fNEvents(1),
fInitRunNumberCalled(kFALSE),
fSetRunNumberFromDataCalled(kFALSE),
fEmbeddingFlag(kFALSE),
+ fQADetectors("ALL"),
+ fQATasks("ALL"),
fRunQA(kTRUE),
fRunHLT("default")
{
fWriteRawData(sim.fWriteRawData),
fRawDataFileName(""),
fDeleteIntermediateFiles(kFALSE),
+ fWriteSelRawData(kFALSE),
fStopOnError(sim.fStopOnError),
fNEvents(sim.fNEvents),
fInitRunNumberCalled(sim.fInitRunNumberCalled),
fSetRunNumberFromDataCalled(sim.fSetRunNumberFromDataCalled),
fEmbeddingFlag(sim.fEmbeddingFlag),
- fRunQA(kTRUE),
+ fQADetectors(sim.fQADetectors),
+ fQATasks(sim.fQATasks),
+ fRunQA(sim.fRunQA),
fRunHLT(sim.fRunHLT)
{
// copy constructor
if (!AliGeomManager::GetGeometry()) {
// Initialize the geometry manager
AliGeomManager::LoadGeometry("geometry.root");
+
+// // Check that the consistency of symbolic names for the activated subdetectors
+// // in the geometry loaded by AliGeomManager
+// AliRunLoader* runLoader = LoadRun("READ");
+// if (!runLoader) return kFALSE;
+//
+// TString detsToBeChecked = "";
+// 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;
+// detsToBeChecked += det->GetName();
+// detsToBeChecked += " ";
+// } // end loop over detectors
+// if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
+ if(!AliGeomManager::CheckSymNamesLUT("ALL"))
+ AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
+
if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
// Misalign geometry
if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
}
+
// hits -> summable digits
+ AliSysInfo::AddStamp("Start_sdigitization");
if (!fMakeSDigits.IsNull()) {
if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
}
+ AliSysInfo::AddStamp("Stop_sdigitization");
-
-
+ AliSysInfo::AddStamp("Start_digitization");
// summable digits -> digits
if (!fMakeDigits.IsNull()) {
if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
if (fStopOnError) return kFALSE;
}
}
+ AliSysInfo::AddStamp("Stop_digitization");
// digits -> raw data
if (!fWriteRawData.IsNull()) {
if (!WriteRawData(fWriteRawData, fRawDataFileName,
- fDeleteIntermediateFiles)) {
+ fDeleteIntermediateFiles,fWriteSelRawData)) {
if (fStopOnError) return kFALSE;
}
}
// Misalign geometry
#if ROOT_VERSION_CODE < 331527
AliGeomManager::SetGeometry(gGeoManager);
+
+ // Check that the consistency of symbolic names for the activated subdetectors
+ // in the geometry loaded by AliGeomManager
+ TString detsToBeChecked = "";
+ 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;
+ detsToBeChecked += det->GetName();
+ detsToBeChecked += " ";
+ } // end loop over detectors
+ if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
+ AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
MisalignGeometry(runLoader);
#endif
}
AliInfo("running gAlice");
+ AliSysInfo::AddStamp("Start_simulation");
StdoutToAliInfo(StderrToAliError(
gAlice->Run(nEvents);
););
-
+ AliSysInfo::AddStamp("Stop_simulation");
delete runLoader;
return kTRUE;
Bool_t AliSimulation::RunSDigitization(const char* detectors)
{
// run the digitization and produce summable digits
-
+ static Int_t eventNr=0;
AliCodeTimerAuto("")
// initialize CDB storage, run number, set CDB lock
if (IsSelected(det->GetName(), detStr)) {
AliInfo(Form("creating summable digits for %s", det->GetName()));
AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
-
det->Hits2SDigits();
+ AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
}
}
detStr.Data()));
if (fStopOnError) return kFALSE;
}
-
+ eventNr++;
delete runLoader;
return kTRUE;
//_____________________________________________________________________________
Bool_t AliSimulation::WriteRawData(const char* detectors,
const char* fileName,
- Bool_t deleteIntermediateFiles)
+ Bool_t deleteIntermediateFiles,
+ Bool_t selrawdata)
{
// convert the digits to raw data
// First DDL raw data files for the given detectors are created.
// If the file name has the extension ".root", the DATE file is converted
// to a root file.
// If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
+// 'selrawdata' flag can be used to enable writing of detectors raw data
+// accoring to the trigger cluster.
AliCodeTimerAuto("")
+
+ TString detStr = detectors;
+ if (IsSelected("HLT", detStr))
+ {
+ // Do nothing. "HLT" will be removed from detStr because the HLT raw
+ // data files are generated in RunHLT.
+ }
- if (!WriteRawFiles(detectors)) {
+ if (!WriteRawFiles(detStr.Data())) {
if (fStopOnError) return kFALSE;
}
if (!dateFileName.IsNull()) {
Bool_t rootOutput = dateFileName.EndsWith(".root");
if (rootOutput) dateFileName += ".date";
- if (!ConvertRawFilesToDate(dateFileName)) {
+ TString selDateFileName;
+ if (selrawdata) {
+ selDateFileName = "selected.";
+ selDateFileName+= dateFileName;
+ }
+ if (!ConvertRawFilesToDate(dateFileName,selDateFileName)) {
if (fStopOnError) return kFALSE;
}
if (deleteIntermediateFiles) {
if (deleteIntermediateFiles) {
gSystem->Unlink(dateFileName);
}
+ if (selrawdata) {
+ TString selFileName = "selected.";
+ selFileName += fileName;
+ if (!ConvertDateToRoot(selDateFileName, selFileName)) {
+ if (fStopOnError) return kFALSE;
+ }
+ if (deleteIntermediateFiles) {
+ gSystem->Unlink(selDateFileName);
+ }
+ }
}
}
}
//_____________________________________________________________________________
-Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName)
+Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
+ const char* selDateFileName)
{
// convert raw data DDL files to a DATE file with the program "dateStream"
+// The second argument is not empty when the user decides to write
+// the detectors raw data according to the trigger cluster.
AliCodeTimerAuto("")
if (!runLoader) return kFALSE;
AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
+ Bool_t selrawdata = kFALSE;
+ if (strcmp(selDateFileName,"") != 0) selrawdata = kTRUE;
+
char command[256];
// Note the option -s. It is used in order to avoid
// the generation of SOR/EOR events.
dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
FILE* pipe = gSystem->OpenPipe(command, "w");
+ Int_t selEvents = 0;
for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
fprintf(pipe, "GDC\n");
Float_t ldc = 0;
Int_t prevLDC = -1;
+ if (selrawdata) {
+ // Check if the event was triggered by CTP
+ runLoader->GetEvent(iEvent);
+ if (!runLoader->LoadTrigger()) {
+ AliCentralTrigger *aCTP = runLoader->GetTrigger();
+ if (aCTP->GetClassMask()) selEvents++;
+ }
+ else {
+ AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
+ selrawdata = kFALSE;
+ }
+ }
+
// loop over detectors and DDLs
for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
Int_t result = gSystem->ClosePipe(pipe);
+ if (!(selrawdata && selEvents > 0)) {
+ delete runLoader;
+ return (result == 0);
+ }
+
+ AliInfo(Form("converting selected by trigger cluster raw data DDL files to DATE file %s", selDateFileName));
+
+ sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
+ selDateFileName,selEvents,runLoader->GetHeader()->GetRun());
+ FILE* pipe2 = gSystem->OpenPipe(command, "w");
+
+ for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
+
+ // Get the trigger decision and cluster
+ TString detClust;
+ runLoader->GetEvent(iEvent);
+ if (!runLoader->LoadTrigger()) {
+ AliCentralTrigger *aCTP = runLoader->GetTrigger();
+ if (aCTP->GetClassMask() == 0) continue;
+ detClust = AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask());
+ AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
+ }
+
+ fprintf(pipe2, "GDC\n");
+ Float_t ldc = 0;
+ Int_t prevLDC = -1;
+
+ // loop over detectors and DDLs
+ for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
+ // Write only raw data from detectors that
+ // are contained in the trigger cluster(s)
+ if (!IsSelected(AliDAQ::DetectorName(iDet),detClust)) continue;
+
+ for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
+
+ Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
+ Int_t ldcID = Int_t(ldc + 0.0001);
+ ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
+
+ char rawFileName[256];
+ sprintf(rawFileName, "raw%d/%s",
+ iEvent, AliDAQ::DdlFileName(iDet,iDDL));
+
+ // check existence and size of raw data file
+ FILE* file = fopen(rawFileName, "rb");
+ if (!file) continue;
+ fseek(file, 0, SEEK_END);
+ unsigned long size = ftell(file);
+ fclose(file);
+ if (!size) continue;
+
+ if (ldcID != prevLDC) {
+ fprintf(pipe2, " LDC Id %d\n", ldcID);
+ prevLDC = ldcID;
+ }
+ fprintf(pipe2, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
+ }
+ }
+ }
+
+ Int_t result2 = gSystem->ClosePipe(pipe2);
+
delete runLoader;
- return (result == 0);
+ return ((result == 0) && (result2 == 0));
}
//_____________________________________________________________________________
rawReader = new AliRawReaderRoot(fileName);
} else if (!fileName.IsNull()) {
rawReader = new AliRawReaderDate(fileName);
- rawReader->SelectEvents(7);
}
// if (!fEquipIdMap.IsNull() && fRawReader)
// fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
}
// init the HLT simulation
- if (fRunHLT.CompareTo("default")==0) fRunHLT="";
+ TString options;
+ if (fRunHLT.CompareTo("default")!=0) options=fRunHLT;
+ if (!IsSelected("HLT", fWriteRawData)) {
+ options+=" writerawfiles=";
+ } else {
+ options+=" writerawfiles=HLT";
+ }
AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
- if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, fRunHLT.Data())))<0) {
+ if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, options.Data())))<0) {
AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
} else {
// run the HLT simulation
{
// run the QA on summable hits, digits or digits
- AliQADataMakerSteer qas ;
+ AliQADataMakerSteer qas("sim") ;
qas.SetRunLoader(gAlice->GetRunLoader()) ;
- Bool_t rv = qas.Run("ALL", AliQA::kHITS) ;
-// qas.Reset() ;
- rv *= qas.Run(fMakeSDigits.Data(), AliQA::kSDIGITS) ;
+ TString detectorsw("") ;
+ Bool_t rv = kTRUE ;
+ if (fQATasks.Contains(Form("%d", AliQA::kHITS)))
+ detectorsw = qas.Run(fQADetectors.Data(), AliQA::kHITS) ;
// qas.Reset() ;
- rv *= qas.Run(fMakeDigits.Data(), AliQA::kDIGITS) ;
+ if (fQATasks.Contains(Form("%d", AliQA::kSDIGITS)))
+ detectorsw += qas.Run(fQADetectors.Data(), AliQA::kSDIGITS) ;
// qas.Reset() ;
- rv *= qas.Run(fMakeDigitsFromHits.Data(), AliQA::kDIGITS) ;
+ if (fQATasks.Contains(Form("%d", AliQA::kDIGITS)))
+ detectorsw += qas.Run(fQADetectors.Data(), AliQA::kDIGITS) ;
+ if ( detectorsw.IsNull() )
+ rv = kFALSE ;
return rv ;
}
+//_____________________________________________________________________________
+Bool_t AliSimulation::SetRunQA(TString detAndAction)
+{
+ // Allows to run QA for a selected set of detectors
+ // and a selected set of tasks among HITS, SDIGITS and DIGITS
+ // all selected detectors run the same selected tasks
+
+ if (!detAndAction.Contains(":")) {
+ AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
+ fRunQA = kFALSE ;
+ return kFALSE ;
+ }
+ Int_t colon = detAndAction.Index(":") ;
+ fQADetectors = detAndAction(0, colon) ;
+ if (fQADetectors.Contains("ALL") )
+ fQADetectors = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ;
+ fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
+ if (fQATasks.Contains("ALL") ) {
+ fQATasks = Form("%d %d %d", AliQA::kHITS, AliQA::kSDIGITS, AliQA::kDIGITS) ;
+ } else {
+ fQATasks.ToUpper() ;
+ TString tempo("") ;
+ if ( fQATasks.Contains("HIT") )
+ tempo = Form("%d ", AliQA::kHITS) ;
+ if ( fQATasks.Contains("SDIGIT") )
+ tempo += Form("%d ", AliQA::kSDIGITS) ;
+ if ( fQATasks.Contains("DIGIT") )
+ tempo += Form("%d ", AliQA::kDIGITS) ;
+ fQATasks = tempo ;
+ if (fQATasks.IsNull()) {
+ AliInfo("No QA requested\n") ;
+ fRunQA = kFALSE ;
+ return kTRUE ;
+ }
+ }
+ TString tempo(fQATasks) ;
+ tempo.ReplaceAll(Form("%d", AliQA::kHITS), AliQA::GetTaskName(AliQA::kHITS)) ;
+ tempo.ReplaceAll(Form("%d", AliQA::kSDIGITS), AliQA::GetTaskName(AliQA::kSDIGITS)) ;
+ tempo.ReplaceAll(Form("%d", AliQA::kDIGITS), AliQA::GetTaskName(AliQA::kDIGITS)) ;
+ AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
+ fRunQA = kTRUE ;
+ return kTRUE;
+}
+
//_____________________________________________________________________________
void AliSimulation::ProcessEnvironmentVars()
{
AliInfo(Form("Run number = %d", fRun));
}
+
+