LUTs mapping symnames and original global matrices removed from AliGeomManager, which...
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
CommitLineData
85a5290f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for running generation, simulation and digitization //
21// //
22// Hits, sdigits and digits are created for all detectors by typing: //
23// //
24// AliSimulation sim; //
25// sim.Run(); //
26// //
27// The Run method returns kTRUE in case of successful execution. //
28// The number of events can be given as argument to the Run method or it //
29// can be set by //
30// //
31// sim.SetNumberOfEvents(n); //
32// //
95601147 33// The name of the configuration file can be passed as argument to the //
34// AliSimulation constructor or can be specified by //
85a5290f 35// //
36// sim.SetConfigFile("..."); //
37// //
38// The generation of particles and the simulation of detector hits can be //
39// switched on or off by //
40// //
41// sim.SetRunGeneration(kTRUE); // generation of primary particles //
42// sim.SetRunSimulation(kFALSE); // but no tracking //
43// //
44// For which detectors sdigits and digits will be created, can be steered //
45// by //
46// //
47// sim.SetMakeSDigits("ALL"); // make sdigits for all detectors //
48// sim.SetMakeDigits("ITS TPC"); // make digits only for ITS and TPC //
49// //
50// The argument is a (case sensitive) string with the names of the //
51// detectors separated by a space. An empty string ("") can be used to //
52// disable the creation of sdigits or digits. The special string "ALL" //
53// selects all available detectors. This is the default. //
54// //
55// The creation of digits from hits instead of from sdigits can be selected //
56// by //
57// //
58// sim.SetMakeDigitsFromHits("TRD"); //
59// //
60// The argument is again a string with the selected detectors. Be aware that //
61// this feature is not available for all detectors and that merging is not //
62// possible, when digits are created directly from hits. //
63// //
05526d44 64// Background events can be merged by calling //
85a5290f 65// //
66// sim.MergeWith("background/galice.root", 2); //
67// //
68// The first argument is the file name of the background galice file. The //
69// second argument is the number of signal events per background event. //
05526d44 70// By default this number is calculated from the number of available //
71// background events. MergeWith can be called several times to merge more //
72// than two event streams. It is assumed that the sdigits were already //
73// produced for the background events. //
85a5290f 74// //
0421c3d1 75// The output of raw data can be switched on by calling //
76// //
77// sim.SetWriteRawData("MUON"); // write raw data for MUON //
78// //
06c7e392 79// The default output format of the raw data are DDL files. They are //
80// converted to a DATE file, if a file name is given as second argument. //
81// For this conversion the program "dateStream" is required. If the file //
82// name has the extension ".root", the DATE file is converted to a root //
83// file. The program "alimdc" is used for this purpose. For the conversion //
84// to DATE and root format the two conversion programs have to be installed. //
85// Only the raw data in the final format is kept if the third argument is //
86// kTRUE. //
87// //
0421c3d1 88// The methods RunSimulation, RunSDigitization, RunDigitization, //
89// RunHitsDigitization and WriteRawData can be used to run only parts of //
06c7e392 90// the full simulation chain. The creation of raw data DDL files and their //
91// conversion to the DATE or root format can be run directly by calling //
92// the methods WriteRawFiles, ConvertRawFilesToDate and ConvertDateToRoot. //
95601147 93// //
18b43626 94// The default number of events per file, which is usually set in the //
95// config file, can be changed for individual detectors and data types //
96// by calling //
97// //
98// sim.SetEventsPerFile("PHOS", "Reconstructed Points", 3); //
99// //
100// The first argument is the detector, the second one the data type and the //
101// last one the number of events per file. Valid data types are "Hits", //
102// "Summable Digits", "Digits", "Reconstructed Points" and "Tracks". //
103// The number of events per file has to be set before the simulation of //
104// hits. Otherwise it has no effect. //
105// //
85a5290f 106///////////////////////////////////////////////////////////////////////////////
107
b856a511 108#include <TVirtualMCApplication.h>
e8d02863 109#include <TGeoManager.h>
85a5290f 110#include <TObjString.h>
af7ba10c 111#include <TSystem.h>
bfbd5665 112#include <TFile.h>
85a5290f 113
87932dab 114#include "AliCodeTimer.h"
e8d02863 115#include "AliCDBStorage.h"
116#include "AliCDBEntry.h"
117#include "AliCDBManager.h"
25be1e5c 118#include "AliGeomManager.h"
e8d02863 119#include "AliAlignObj.h"
120#include "AliCentralTrigger.h"
362c9d61 121#include "AliDAQ.h"
af7ba10c 122#include "AliDigitizer.h"
123#include "AliGenerator.h"
e8d02863 124#include "AliLog.h"
af7ba10c 125#include "AliModule.h"
126#include "AliRun.h"
127#include "AliRunDigitizer.h"
128#include "AliRunLoader.h"
129#include "AliSimulation.h"
130#include "AliVertexGenFile.h"
a5a091ce 131#include "AliCentralTrigger.h"
007155cc 132#include "AliCTPRawData.h"
ca30848f 133#include "AliRawReaderFile.h"
8b31e840 134#include "AliRawReaderRoot.h"
135#include "AliRawReaderDate.h"
ca30848f 136#include "AliESD.h"
137#include "AliHeader.h"
138#include "AliGenEventHeader.h"
b856a511 139#include "AliMC.h"
cae21299 140#include "AliHLTSimulation.h"
c65c502a 141#include "AliQADataMakerSteer.h"
27fc67fa 142#include "AliSysInfo.h"
85a5290f 143
144ClassImp(AliSimulation)
145
b856a511 146AliSimulation *AliSimulation::fgInstance = 0;
5b188f2f 147const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
85a5290f 148
149//_____________________________________________________________________________
795e4a22 150AliSimulation::AliSimulation(const char* configFileName,
95601147 151 const char* name, const char* title) :
152 TNamed(name, title),
153
154 fRunGeneration(kTRUE),
155 fRunSimulation(kTRUE),
024cf675 156 fLoadAlignFromCDB(kTRUE),
25be1e5c 157 fLoadAlObjsListOfDets("ALL"),
95601147 158 fMakeSDigits("ALL"),
159 fMakeDigits("ALL"),
a5a091ce 160 fMakeTrigger(""),
95601147 161 fMakeDigitsFromHits(""),
0421c3d1 162 fWriteRawData(""),
06c7e392 163 fRawDataFileName(""),
164 fDeleteIntermediateFiles(kFALSE),
67327b72 165 fWriteSelRawData(kFALSE),
95601147 166 fStopOnError(kFALSE),
167
168 fNEvents(1),
169 fConfigFileName(configFileName),
170 fGAliceFileName("galice.root"),
18b43626 171 fEventsPerFile(),
95601147 172 fBkgrdFileNames(NULL),
995ad051 173 fAlignObjArray(NULL),
04bae0a0 174 fUseBkgrdVertex(kTRUE),
024cf675 175 fRegionOfInterest(kFALSE),
795e4a22 176 fCDBUri(""),
ca30848f 177 fSpecCDBUri(),
795e4a22 178 fRun(-1),
179 fSeed(0),
180 fInitCDBCalled(kFALSE),
181 fInitRunNumberCalled(kFALSE),
182 fSetRunNumberFromDataCalled(kFALSE),
cae21299 183 fEmbeddingFlag(kFALSE),
759c1df1 184 fRunQA(kTRUE),
cae21299 185 fRunHLT("default")
85a5290f 186{
187// create simulation object with default parameters
b856a511 188 fgInstance = this;
0421c3d1 189 SetGAliceFile("galice.root");
5b188f2f 190
191// for QA
192 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++)
193 fQACycles[iDet] = 999999;
85a5290f 194}
195
196//_____________________________________________________________________________
197AliSimulation::AliSimulation(const AliSimulation& sim) :
95601147 198 TNamed(sim),
199
200 fRunGeneration(sim.fRunGeneration),
201 fRunSimulation(sim.fRunSimulation),
024cf675 202 fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
25be1e5c 203 fLoadAlObjsListOfDets(sim.fLoadAlObjsListOfDets),
95601147 204 fMakeSDigits(sim.fMakeSDigits),
205 fMakeDigits(sim.fMakeDigits),
a5a091ce 206 fMakeTrigger(sim.fMakeTrigger),
95601147 207 fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
0421c3d1 208 fWriteRawData(sim.fWriteRawData),
06c7e392 209 fRawDataFileName(""),
210 fDeleteIntermediateFiles(kFALSE),
67327b72 211 fWriteSelRawData(kFALSE),
95601147 212 fStopOnError(sim.fStopOnError),
213
214 fNEvents(sim.fNEvents),
215 fConfigFileName(sim.fConfigFileName),
216 fGAliceFileName(sim.fGAliceFileName),
18b43626 217 fEventsPerFile(),
95601147 218 fBkgrdFileNames(NULL),
995ad051 219 fAlignObjArray(NULL),
04bae0a0 220 fUseBkgrdVertex(sim.fUseBkgrdVertex),
024cf675 221 fRegionOfInterest(sim.fRegionOfInterest),
ec92bee0 222 fCDBUri(sim.fCDBUri),
ca30848f 223 fSpecCDBUri(),
795e4a22 224 fRun(-1),
225 fSeed(0),
226 fInitCDBCalled(sim.fInitCDBCalled),
227 fInitRunNumberCalled(sim.fInitRunNumberCalled),
228 fSetRunNumberFromDataCalled(sim.fSetRunNumberFromDataCalled),
c65c502a 229 fEmbeddingFlag(sim.fEmbeddingFlag),
759c1df1 230 fRunQA(kTRUE),
c65c502a 231 fRunHLT(sim.fRunHLT)
85a5290f 232{
233// copy constructor
234
18b43626 235 for (Int_t i = 0; i < sim.fEventsPerFile.GetEntriesFast(); i++) {
236 if (!sim.fEventsPerFile[i]) continue;
237 fEventsPerFile.Add(sim.fEventsPerFile[i]->Clone());
238 }
239
85a5290f 240 fBkgrdFileNames = new TObjArray;
241 for (Int_t i = 0; i < sim.fBkgrdFileNames->GetEntriesFast(); i++) {
242 if (!sim.fBkgrdFileNames->At(i)) continue;
243 fBkgrdFileNames->Add(sim.fBkgrdFileNames->At(i)->Clone());
244 }
ec92bee0 245
246 for (Int_t i = 0; i < sim.fSpecCDBUri.GetEntriesFast(); i++) {
247 if (sim.fSpecCDBUri[i]) fSpecCDBUri.Add(sim.fSpecCDBUri[i]->Clone());
248 }
b856a511 249 fgInstance = this;
5b188f2f 250
251// for QA
252 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++)
253 fQACycles[iDet] = sim.fQACycles[iDet];
85a5290f 254}
255
256//_____________________________________________________________________________
257AliSimulation& AliSimulation::operator = (const AliSimulation& sim)
258{
259// assignment operator
260
261 this->~AliSimulation();
262 new(this) AliSimulation(sim);
263 return *this;
264}
265
266//_____________________________________________________________________________
267AliSimulation::~AliSimulation()
268{
269// clean up
270
18b43626 271 fEventsPerFile.Delete();
024cf675 272// if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
273// delete fAlignObjArray; fAlignObjArray=0;
18b43626 274
95601147 275 if (fBkgrdFileNames) {
276 fBkgrdFileNames->Delete();
277 delete fBkgrdFileNames;
278 }
ec92bee0 279
280 fSpecCDBUri.Delete();
b856a511 281 if (fgInstance==this) fgInstance = 0;
87932dab 282
283 AliCodeTimer::Instance()->Print();
85a5290f 284}
285
286
287//_____________________________________________________________________________
288void AliSimulation::SetNumberOfEvents(Int_t nEvents)
289{
290// set the number of events for one run
291
292 fNEvents = nEvents;
293}
294
024cf675 295//_____________________________________________________________________________
795e4a22 296void AliSimulation::InitCDB()
024cf675 297{
298// activate a default CDB storage
299// First check if we have any CDB storage set, because it is used
300// to retrieve the calibration and alignment constants
301
795e4a22 302 if (fInitCDBCalled) return;
303 fInitCDBCalled = kTRUE;
304
024cf675 305 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 306 if (man->IsDefaultStorageSet())
024cf675 307 {
ec92bee0 308 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
309 AliWarning("Default CDB storage has been already set !");
ced249e6 310 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
ec92bee0 311 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 312 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 313 }
314 else {
795e4a22 315 if (fCDBUri.Length() > 0)
316 {
317 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
319 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
320 } else {
321 fCDBUri="local://$ALICE_ROOT";
322 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
323 AliWarning("Default CDB storage not yet set !!!!");
324 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
325 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
326
327 }
ec92bee0 328 man->SetDefaultStorage(fCDBUri);
329 }
330
331 // Now activate the detector specific CDB storage locations
332 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
333 TObject* obj = fSpecCDBUri[i];
334 if (!obj) continue;
b8ec52f6 335 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
336 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
337 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 338 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 339 }
795e4a22 340
024cf675 341}
342
343//_____________________________________________________________________________
795e4a22 344void AliSimulation::InitRunNumber(){
345// check run number. If not set, set it to 0 !!!!
346
347 if (fInitRunNumberCalled) return;
348 fInitRunNumberCalled = kTRUE;
349
350 AliCDBManager* man = AliCDBManager::Instance();
351 if (man->GetRun() >= 0)
352 {
8c8fbdcd 353 AliFatal(Form("Run number cannot be set in AliCDBManager before start of simulation: "
354 "Use external variable DC_RUN or AliSimulation::SetRun()!"));
795e4a22 355 }
8c8fbdcd 356
357 if(fRun >= 0) {
795e4a22 358 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
359 AliDebug(2, Form("Setting CDB run number to: %d",fRun));
360 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
8c8fbdcd 361 } else {
795e4a22 362 fRun=0;
363 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
364 AliWarning("Run number not yet set !!!!");
365 AliWarning(Form("Setting it now to: %d", fRun));
366 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
367
795e4a22 368 }
8c8fbdcd 369 man->SetRun(fRun);
024cf675 370
795e4a22 371 man->Print();
024cf675 372
373}
374
00aa02d5 375//_____________________________________________________________________________
795e4a22 376void AliSimulation::SetCDBLock() {
377 // Set CDB lock: from now on it is forbidden to reset the run number
378 // or the default storage or to activate any further storage!
379
380 AliCDBManager::Instance()->SetLock(1);
381}
382
383//_____________________________________________________________________________
384void AliSimulation::SetDefaultStorage(const char* uri) {
385// Store the desired default CDB storage location
00aa02d5 386// Activate it later within the Run() method
00aa02d5 387
795e4a22 388 fCDBUri = uri;
00aa02d5 389
390}
391
024cf675 392//_____________________________________________________________________________
c3a7b59a 393void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 394// Store a detector-specific CDB storage location
395// Activate it later within the Run() method
024cf675 396
c3a7b59a 397 AliCDBPath aPath(calibType);
398 if(!aPath.IsValid()){
399 AliError(Form("Not a valid path: %s", calibType));
400 return;
401 }
402
403 TObject* obj = fSpecCDBUri.FindObject(calibType);
ec92bee0 404 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 405 fSpecCDBUri.Add(new TNamed(calibType, uri));
024cf675 406
407}
408
795e4a22 409//_____________________________________________________________________________
410void AliSimulation::SetRunNumber(Int_t run)
411{
412// sets run number
413// Activate it later within the Run() method
414
415 fRun = run;
416}
417
418//_____________________________________________________________________________
419void AliSimulation::SetSeed(Int_t seed)
420{
421// sets seed number
422// Activate it later within the Run() method
423
424 fSeed = seed;
425}
426
427//_____________________________________________________________________________
428Bool_t AliSimulation::SetRunNumberFromData()
429{
430 // Set the CDB manager run number
431 // The run number is retrieved from gAlice
432
433 if (fSetRunNumberFromDataCalled) return kTRUE;
434 fSetRunNumberFromDataCalled = kTRUE;
435
436 AliCDBManager* man = AliCDBManager::Instance();
437 Int_t runData = -1, runCDB = -1;
438
439 AliRunLoader* runLoader = LoadRun("READ");
440 if (!runLoader) return kFALSE;
441 else {
442 runData = runLoader->GetAliRun()->GetHeader()->GetRun();
443 delete runLoader;
444 }
445
446 runCDB = man->GetRun();
447 if(runCDB >= 0) {
448 if (runCDB != runData) {
449 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
450 AliWarning(Form("A run number was previously set in AliCDBManager: %d !", runCDB));
451 AliWarning(Form("It will be replaced with the run number got from run header: %d !", runData));
452 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
453 }
454
455 }
456
457 man->SetRun(runData);
458 fRun = runData;
459
460 if(man->GetRun() < 0) {
461 AliError("Run number not properly initalized!");
462 return kFALSE;
463 }
464
465 man->Print();
466
467 return kTRUE;
468}
469
85a5290f 470//_____________________________________________________________________________
471void AliSimulation::SetConfigFile(const char* fileName)
472{
473// set the name of the config file
474
475 fConfigFileName = fileName;
476}
477
0421c3d1 478//_____________________________________________________________________________
479void AliSimulation::SetGAliceFile(const char* fileName)
480{
481// set the name of the galice file
482// the path is converted to an absolute one if it is relative
483
484 fGAliceFileName = fileName;
485 if (!gSystem->IsAbsoluteFileName(fGAliceFileName)) {
486 char* absFileName = gSystem->ConcatFileName(gSystem->WorkingDirectory(),
487 fGAliceFileName);
488 fGAliceFileName = absFileName;
489 delete[] absFileName;
490 }
ac1671c0 491
492 AliDebug(2, Form("galice file name set to %s", fileName));
0421c3d1 493}
494
18b43626 495//_____________________________________________________________________________
496void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
497 Int_t nEvents)
498{
499// set the number of events per file for the given detector and data type
500// ("Hits", "Summable Digits", "Digits", "Reconstructed Points" or "Tracks")
501
502 TNamed* obj = new TNamed(detector, type);
503 obj->SetUniqueID(nEvents);
504 fEventsPerFile.Add(obj);
505}
506
6bae477a 507//_____________________________________________________________________________
508Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
509{
510 // Read the alignment objects from CDB.
511 // Each detector is supposed to have the
512 // alignment objects in DET/Align/Data CDB path.
513 // All the detector objects are then collected,
514 // sorted by geometry level (starting from ALIC) and
515 // then applied to the TGeo geometry.
516 // Finally an overlaps check is performed.
517
74ae4297 518 if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
519 AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
0717eed2 520 return kFALSE;
521 }
795e4a22 522
523 // initialize CDB storage, run number, set CDB lock
524 InitCDB();
525// if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
526 SetCDBLock();
527
6bae477a 528 Bool_t delRunLoader = kFALSE;
529 if (!runLoader) {
530 runLoader = LoadRun("READ");
531 if (!runLoader) return kFALSE;
532 delRunLoader = kTRUE;
533 }
795e4a22 534
b856a511 535 // Export ideal geometry
ced249e6 536 if(!gAlice->IsRootGeometry()) AliGeomManager::GetGeometry()->Export("geometry.root");
b856a511 537
25be1e5c 538 // Load alignment data from CDB and apply to geometry through AliGeomManager
6bae477a 539 if(fLoadAlignFromCDB){
25be1e5c 540
541 TString detStr = fLoadAlObjsListOfDets;
542 TString loadAlObjsListOfDets = "";
543
544 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
545 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
546 AliModule* det = (AliModule*) detArray->At(iDet);
547 if (!det || !det->IsActive()) continue;
548 if (IsSelected(det->GetName(), detStr)) {
0717eed2 549 //add det to list of dets to be aligned from CDB
550 loadAlObjsListOfDets += det->GetName();
551 loadAlObjsListOfDets += " ";
25be1e5c 552 }
553 } // end loop over detectors
53dd3c3d 554 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
45daac75 555 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
25be1e5c 556 }else{
557 // Check if the array with alignment objects was
558 // provided by the user. If yes, apply the objects
559 // to the present TGeo geometry
560 if (fAlignObjArray) {
45daac75 561 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
0717eed2 562 AliError("The misalignment of one or more volumes failed!"
563 "Compare the list of simulated detectors and the list of detector alignment data!");
564 if (delRunLoader) delete runLoader;
565 return kFALSE;
6bae477a 566 }
567 }
6bae477a 568 }
569
ef7ff1f9 570 // Update the internal geometry of modules (ITS needs it)
25be1e5c 571 TString detStr = fLoadAlObjsListOfDets;
ef7ff1f9 572 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
573 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
574
575 AliModule* det = (AliModule*) detArray->At(iDet);
576 if (!det || !det->IsActive()) continue;
577 if (IsSelected(det->GetName(), detStr)) {
578 det->UpdateInternalGeometry();
579 }
580 } // end loop over detectors
581
582
6bae477a 583 if (delRunLoader) delete runLoader;
584
585 return kTRUE;
586}
587
85a5290f 588//_____________________________________________________________________________
589void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
590{
591// add a file with background events for merging
592
593 TObjString* fileNameStr = new TObjString(fileName);
594 fileNameStr->SetUniqueID(nSignalPerBkgrd);
95601147 595 if (!fBkgrdFileNames) fBkgrdFileNames = new TObjArray;
85a5290f 596 fBkgrdFileNames->Add(fileNameStr);
597}
598
ca30848f 599void AliSimulation::EmbedInto(const char* fileName, Int_t nSignalPerBkgrd)
600{
601// add a file with background events for embeddin
602 MergeWith(fileName, nSignalPerBkgrd);
603 fEmbeddingFlag = kTRUE;
604}
85a5290f 605
606//_____________________________________________________________________________
607Bool_t AliSimulation::Run(Int_t nEvents)
608{
609// run the generation, simulation and digitization
610
c65c502a 611
795e4a22 612 AliCodeTimerAuto("")
87932dab 613
795e4a22 614 // Load run number and seed from environmental vars
615 ProcessEnvironmentVars();
b0314964 616
795e4a22 617 gRandom->SetSeed(fSeed);
618
85a5290f 619 if (nEvents > 0) fNEvents = nEvents;
620
621 // generation and simulation -> hits
622 if (fRunGeneration) {
85a5290f 623 if (!RunSimulation()) if (fStopOnError) return kFALSE;
624 }
795e4a22 625
626 // initialize CDB storage from external environment
627 // (either CDB manager or AliSimulation setters),
628 // if not already done in RunSimulation()
629 InitCDB();
630
631 // Set run number in CDBManager from data
632 // From this point on the run number must be always loaded from data!
633 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
634
635 // Set CDB lock: from now on it is forbidden to reset the run number
636 // or the default storage or to activate any further storage!
637 SetCDBLock();
6bae477a 638
25be1e5c 639 // If RunSimulation was not called, load the geometry and misalign it
74ae4297 640 if (!AliGeomManager::GetGeometry()) {
641 // Initialize the geometry manager
45daac75 642 AliGeomManager::LoadGeometry("geometry.root");
0bf7aade 643 if(!AliGeomManager::CheckSymNamesLUT())
644 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
74ae4297 645 if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
646 // Misalign geometry
25be1e5c 647 if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
6bae477a 648 }
25be1e5c 649
27fc67fa 650
85a5290f 651 // hits -> summable digits
27fc67fa 652 AliSysInfo::AddStamp("Start_sdigitization");
85a5290f 653 if (!fMakeSDigits.IsNull()) {
654 if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
a1b90a73 655
85a5290f 656 }
27fc67fa 657 AliSysInfo::AddStamp("Stop_sdigitization");
c65c502a 658
27fc67fa 659 AliSysInfo::AddStamp("Start_digitization");
795e4a22 660 // summable digits -> digits
85a5290f 661 if (!fMakeDigits.IsNull()) {
662 if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
663 if (fStopOnError) return kFALSE;
664 }
a1b90a73 665 }
27fc67fa 666 AliSysInfo::AddStamp("Stop_digitization");
85a5290f 667
795e4a22 668
669
85a5290f 670 // hits -> digits
671 if (!fMakeDigitsFromHits.IsNull()) {
95601147 672 if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
ac1671c0 673 AliWarning(Form("Merging and direct creation of digits from hits "
674 "was selected for some detectors. "
675 "No merging will be done for the following detectors: %s",
676 fMakeDigitsFromHits.Data()));
85a5290f 677 }
678 if (!RunHitsDigitization(fMakeDigitsFromHits)) {
679 if (fStopOnError) return kFALSE;
680 }
681 }
682
795e4a22 683
684
a5a091ce 685 // digits -> trigger
8480396b 686 if (!RunTrigger(fMakeTrigger,fMakeDigits)) {
087426de 687 if (fStopOnError) return kFALSE;
a5a091ce 688 }
689
795e4a22 690
691
0421c3d1 692 // digits -> raw data
693 if (!fWriteRawData.IsNull()) {
06c7e392 694 if (!WriteRawData(fWriteRawData, fRawDataFileName,
67327b72 695 fDeleteIntermediateFiles,fWriteSelRawData)) {
0421c3d1 696 if (fStopOnError) return kFALSE;
697 }
698 }
699
795e4a22 700
701
cae21299 702 // run HLT simulation
703 if (!fRunHLT.IsNull()) {
704 if (!RunHLT()) {
705 if (fStopOnError) return kFALSE;
706 }
707 }
795e4a22 708
04236e67 709 //QA
710 if (fRunQA) {
711 Bool_t rv = RunQA() ;
712 if (!rv)
713 if (fStopOnError)
714 return kFALSE ;
715 }
795e4a22 716
717 // Cleanup of CDB manager: cache and active storages!
718 AliCDBManager::Instance()->ClearCache();
719
85a5290f 720 return kTRUE;
721}
722
a5a091ce 723//_____________________________________________________________________________
8480396b 724Bool_t AliSimulation::RunTrigger(const char* config, const char* detectors)
a5a091ce 725{
726 // run the trigger
727
87932dab 728 AliCodeTimerAuto("")
a5a091ce 729
795e4a22 730 // initialize CDB storage from external environment
731 // (either CDB manager or AliSimulation setters),
732 // if not already done in RunSimulation()
733 InitCDB();
734
735 // Set run number in CDBManager from data
736 // From this point on the run number must be always loaded from data!
737 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
738
739 // Set CDB lock: from now on it is forbidden to reset the run number
740 // or the default storage or to activate any further storage!
741 SetCDBLock();
742
bacbe0fd 743 AliRunLoader* runLoader = LoadRun("READ");
744 if (!runLoader) return kFALSE;
51f6d619 745 TString trconfiguration = config;
bacbe0fd 746
51f6d619 747 if (trconfiguration.IsNull()) {
087426de 748 if (gAlice->GetTriggerDescriptor() != "") {
51f6d619 749 trconfiguration = gAlice->GetTriggerDescriptor();
087426de 750 }
51f6d619 751 else
8480396b 752 AliWarning("No trigger descriptor is specified. Loading the one that is in the CDB.");
087426de 753 }
754
0f46f5fa 755 runLoader->MakeTree( "GG" );
bacbe0fd 756 AliCentralTrigger* aCTP = runLoader->GetTrigger();
51f6d619 757 // Load Configuration
758 if (!aCTP->LoadConfiguration( trconfiguration ))
759 return kFALSE;
a5a091ce 760
51f6d619 761 // digits -> trigger
8480396b 762 if( !aCTP->RunTrigger( runLoader , detectors ) ) {
a5a091ce 763 if (fStopOnError) {
51f6d619 764 // delete aCTP;
765 return kFALSE;
a5a091ce 766 }
bacbe0fd 767 }
a5a091ce 768
bacbe0fd 769 delete runLoader;
a5a091ce 770
bacbe0fd 771 return kTRUE;
a5a091ce 772}
773
007155cc 774//_____________________________________________________________________________
775Bool_t AliSimulation::WriteTriggerRawData()
776{
777 // Writes the CTP (trigger) DDL raw data
778 // Details of the format are given in the
779 // trigger TDR - pages 134 and 135.
780 AliCTPRawData writer;
781 writer.RawData();
a5a091ce 782
007155cc 783 return kTRUE;
784}
a5a091ce 785
85a5290f 786//_____________________________________________________________________________
95601147 787Bool_t AliSimulation::RunSimulation(Int_t nEvents)
85a5290f 788{
789// run the generation and simulation
790
87932dab 791 AliCodeTimerAuto("")
4df28b43 792
795e4a22 793 // initialize CDB storage and run number from external environment
794 // (either CDB manager or AliSimulation setters)
795 InitCDB();
796 InitRunNumber();
797 SetCDBLock();
798
95601147 799 if (!gAlice) {
ac1671c0 800 AliError("no gAlice object. Restart aliroot and try again.");
95601147 801 return kFALSE;
802 }
803 if (gAlice->Modules()->GetEntries() > 0) {
ac1671c0 804 AliError("gAlice was already run. Restart aliroot and try again.");
95601147 805 return kFALSE;
806 }
807
ac1671c0 808 AliInfo(Form("initializing gAlice with config file %s",
809 fConfigFileName.Data()));
815c2b38 810 StdoutToAliInfo(StderrToAliError(
811 gAlice->Init(fConfigFileName.Data());
812 ););
795e4a22 813
087426de 814 // Get the trigger descriptor string
815 // Either from AliSimulation or from
816 // gAlice
817 if (fMakeTrigger.IsNull()) {
818 if (gAlice->GetTriggerDescriptor() != "")
819 fMakeTrigger = gAlice->GetTriggerDescriptor();
820 }
821 else
822 gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
823
6bae477a 824 // Set run number in CDBManager
024cf675 825 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
826
827 AliRunLoader* runLoader = gAlice->GetRunLoader();
828 if (!runLoader) {
829 AliError(Form("gAlice has no run loader object. "
830 "Check your config file: %s", fConfigFileName.Data()));
831 return kFALSE;
832 }
833 SetGAliceFile(runLoader->GetFileName());
795e4a22 834
6bae477a 835 // Misalign geometry
caf9c464 836#if ROOT_VERSION_CODE < 331527
74ae4297 837 AliGeomManager::SetGeometry(gGeoManager);
0bf7aade 838 if(!AliGeomManager::CheckSymNamesLUT())
839 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
caf9c464 840 MisalignGeometry(runLoader);
841#endif
995ad051 842
024cf675 843// AliRunLoader* runLoader = gAlice->GetRunLoader();
844// if (!runLoader) {
845// AliError(Form("gAlice has no run loader object. "
846// "Check your config file: %s", fConfigFileName.Data()));
847// return kFALSE;
848// }
849// SetGAliceFile(runLoader->GetFileName());
85a5290f 850
04bae0a0 851 if (!gAlice->Generator()) {
ac1671c0 852 AliError(Form("gAlice has no generator object. "
853 "Check your config file: %s", fConfigFileName.Data()));
04bae0a0 854 return kFALSE;
855 }
05526d44 856 if (nEvents <= 0) nEvents = fNEvents;
04bae0a0 857
858 // get vertex from background file in case of merging
859 if (fUseBkgrdVertex &&
860 fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
05526d44 861 Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
04bae0a0 862 const char* fileName = ((TObjString*)
863 (fBkgrdFileNames->At(0)))->GetName();
ac1671c0 864 AliInfo(Form("The vertex will be taken from the background "
865 "file %s with nSignalPerBackground = %d",
866 fileName, signalPerBkgrd));
04bae0a0 867 AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
868 gAlice->Generator()->SetVertexGenerator(vtxGen);
869 }
870
85a5290f 871 if (!fRunSimulation) {
85a5290f 872 gAlice->Generator()->SetTrackingFlag(0);
873 }
874
18b43626 875 // set the number of events per file for given detectors and data types
876 for (Int_t i = 0; i < fEventsPerFile.GetEntriesFast(); i++) {
877 if (!fEventsPerFile[i]) continue;
878 const char* detName = fEventsPerFile[i]->GetName();
879 const char* typeName = fEventsPerFile[i]->GetTitle();
880 TString loaderName(detName);
881 loaderName += "Loader";
882 AliLoader* loader = runLoader->GetLoader(loaderName);
883 if (!loader) {
ac1671c0 884 AliError(Form("RunSimulation", "no loader for %s found\n"
885 "Number of events per file not set for %s %s",
886 detName, typeName, detName));
18b43626 887 continue;
888 }
889 AliDataLoader* dataLoader =
890 loader->GetDataLoader(typeName);
891 if (!dataLoader) {
ac1671c0 892 AliError(Form("no data loader for %s found\n"
893 "Number of events per file not set for %s %s",
894 typeName, detName, typeName));
18b43626 895 continue;
896 }
897 dataLoader->SetNumberOfEventsPerFile(fEventsPerFile[i]->GetUniqueID());
ac1671c0 898 AliDebug(1, Form("number of events per file set to %d for %s %s",
899 fEventsPerFile[i]->GetUniqueID(), detName, typeName));
18b43626 900 }
901
ac1671c0 902 AliInfo("running gAlice");
27fc67fa 903 AliSysInfo::AddStamp("Start_simulation");
815c2b38 904 StdoutToAliInfo(StderrToAliError(
905 gAlice->Run(nEvents);
906 ););
27fc67fa 907 AliSysInfo::AddStamp("Stop_simulation");
95601147 908 delete runLoader;
85a5290f 909
910 return kTRUE;
911}
912
913//_____________________________________________________________________________
95601147 914Bool_t AliSimulation::RunSDigitization(const char* detectors)
85a5290f 915{
916// run the digitization and produce summable digits
27fc67fa 917 static Int_t eventNr=0;
87932dab 918 AliCodeTimerAuto("")
4df28b43 919
795e4a22 920 // initialize CDB storage, run number, set CDB lock
921 InitCDB();
922 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
923 SetCDBLock();
924
95601147 925 AliRunLoader* runLoader = LoadRun();
926 if (!runLoader) return kFALSE;
927
85a5290f 928 TString detStr = detectors;
95601147 929 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
85a5290f 930 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
931 AliModule* det = (AliModule*) detArray->At(iDet);
932 if (!det || !det->IsActive()) continue;
933 if (IsSelected(det->GetName(), detStr)) {
ac1671c0 934 AliInfo(Form("creating summable digits for %s", det->GetName()));
87932dab 935 AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
85a5290f 936 det->Hits2SDigits();
27fc67fa 937 AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
85a5290f 938 }
939 }
940
941 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 942 AliError(Form("the following detectors were not found: %s",
943 detStr.Data()));
85a5290f 944 if (fStopOnError) return kFALSE;
945 }
27fc67fa 946 eventNr++;
95601147 947 delete runLoader;
948
85a5290f 949 return kTRUE;
950}
951
952
953//_____________________________________________________________________________
95601147 954Bool_t AliSimulation::RunDigitization(const char* detectors,
955 const char* excludeDetectors)
85a5290f 956{
957// run the digitization and produce digits from sdigits
958
87932dab 959 AliCodeTimerAuto("")
4df28b43 960
795e4a22 961 // initialize CDB storage, run number, set CDB lock
962 InitCDB();
963 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
964 SetCDBLock();
965
95601147 966 while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
967 if (gAlice) delete gAlice;
968 gAlice = NULL;
969
970 Int_t nStreams = 1;
05526d44 971 if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
972 Int_t signalPerBkgrd = GetNSignalPerBkgrd();
85a5290f 973 AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
ca30848f 974 // manager->SetEmbeddingFlag(fEmbeddingFlag);
85a5290f 975 manager->SetInputStream(0, fGAliceFileName.Data());
976 for (Int_t iStream = 1; iStream < nStreams; iStream++) {
977 const char* fileName = ((TObjString*)
978 (fBkgrdFileNames->At(iStream-1)))->GetName();
979 manager->SetInputStream(iStream, fileName);
980 }
981
982 TString detStr = detectors;
983 TString detExcl = excludeDetectors;
95601147 984 manager->GetInputStream(0)->ImportgAlice();
985 AliRunLoader* runLoader =
986 AliRunLoader::GetRunLoader(manager->GetInputStream(0)->GetFolderName());
987 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
85a5290f 988 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
989 AliModule* det = (AliModule*) detArray->At(iDet);
990 if (!det || !det->IsActive()) continue;
991 if (IsSelected(det->GetName(), detStr) &&
992 !IsSelected(det->GetName(), detExcl)) {
4df28b43 993 AliDigitizer* digitizer = det->CreateDigitizer(manager);
ca30848f 994
4df28b43 995 if (!digitizer) {
ac1671c0 996 AliError(Form("no digitizer for %s", det->GetName()));
85a5290f 997 if (fStopOnError) return kFALSE;
4df28b43 998 } else {
999 digitizer->SetRegionOfInterest(fRegionOfInterest);
85a5290f 1000 }
1001 }
1002 }
1003
1004 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 1005 AliError(Form("the following detectors were not found: %s",
1006 detStr.Data()));
85a5290f 1007 if (fStopOnError) return kFALSE;
1008 }
1009
1010 if (!manager->GetListOfTasks()->IsEmpty()) {
ac1671c0 1011 AliInfo("executing digitization");
85a5290f 1012 manager->Exec("");
1013 }
95601147 1014
85a5290f 1015 delete manager;
1016
1017 return kTRUE;
1018}
1019
1020//_____________________________________________________________________________
95601147 1021Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
85a5290f 1022{
1023// run the digitization and produce digits from hits
1024
87932dab 1025 AliCodeTimerAuto("")
4df28b43 1026
795e4a22 1027 // initialize CDB storage, run number, set CDB lock
1028 InitCDB();
1029 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1030 SetCDBLock();
1031
591f51bb 1032 AliRunLoader* runLoader = LoadRun("READ");
95601147 1033 if (!runLoader) return kFALSE;
1034
85a5290f 1035 TString detStr = detectors;
95601147 1036 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
85a5290f 1037 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1038 AliModule* det = (AliModule*) detArray->At(iDet);
1039 if (!det || !det->IsActive()) continue;
1040 if (IsSelected(det->GetName(), detStr)) {
ac1671c0 1041 AliInfo(Form("creating digits from hits for %s", det->GetName()));
85a5290f 1042 det->Hits2Digits();
1043 }
1044 }
1045
1046 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 1047 AliError(Form("the following detectors were not found: %s",
1048 detStr.Data()));
85a5290f 1049 if (fStopOnError) return kFALSE;
1050 }
1051
b17cac0f 1052 delete runLoader;
591f51bb 1053 //PH Temporary fix to avoid interference with the PHOS loder/getter
1054 //PH The problem has to be solved in more general way 09/06/05
95601147 1055
85a5290f 1056 return kTRUE;
1057}
1058
0421c3d1 1059//_____________________________________________________________________________
06c7e392 1060Bool_t AliSimulation::WriteRawData(const char* detectors,
1061 const char* fileName,
67327b72 1062 Bool_t deleteIntermediateFiles,
1063 Bool_t selrawdata)
0421c3d1 1064{
1065// convert the digits to raw data
06c7e392 1066// First DDL raw data files for the given detectors are created.
1067// If a file name is given, the DDL files are then converted to a DATE file.
1068// If deleteIntermediateFiles is true, the DDL raw files are deleted
1069// afterwards.
1070// If the file name has the extension ".root", the DATE file is converted
1071// to a root file.
1072// If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
67327b72 1073// 'selrawdata' flag can be used to enable writing of detectors raw data
1074// accoring to the trigger cluster.
0421c3d1 1075
87932dab 1076 AliCodeTimerAuto("")
0421c3d1 1077
06c7e392 1078 if (!WriteRawFiles(detectors)) {
1079 if (fStopOnError) return kFALSE;
1080 }
1081
1082 TString dateFileName(fileName);
1083 if (!dateFileName.IsNull()) {
1084 Bool_t rootOutput = dateFileName.EndsWith(".root");
1085 if (rootOutput) dateFileName += ".date";
67327b72 1086 TString selDateFileName;
1087 if (selrawdata) {
1088 selDateFileName = "selected.";
1089 selDateFileName+= dateFileName;
1090 }
1091 if (!ConvertRawFilesToDate(dateFileName,selDateFileName)) {
06c7e392 1092 if (fStopOnError) return kFALSE;
1093 }
1094 if (deleteIntermediateFiles) {
1095 AliRunLoader* runLoader = LoadRun("READ");
1096 if (runLoader) for (Int_t iEvent = 0;
1097 iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1098 char command[256];
1099 sprintf(command, "rm -r raw%d", iEvent);
1100 gSystem->Exec(command);
1101 }
1102 }
1103
1104 if (rootOutput) {
1105 if (!ConvertDateToRoot(dateFileName, fileName)) {
1106 if (fStopOnError) return kFALSE;
1107 }
1108 if (deleteIntermediateFiles) {
1109 gSystem->Unlink(dateFileName);
1110 }
67327b72 1111 if (selrawdata) {
1112 TString selFileName = "selected.";
1113 selFileName += fileName;
1114 if (!ConvertDateToRoot(selDateFileName, selFileName)) {
1115 if (fStopOnError) return kFALSE;
1116 }
1117 if (deleteIntermediateFiles) {
1118 gSystem->Unlink(selDateFileName);
1119 }
1120 }
06c7e392 1121 }
1122 }
1123
06c7e392 1124 return kTRUE;
1125}
1126
1127//_____________________________________________________________________________
1128Bool_t AliSimulation::WriteRawFiles(const char* detectors)
1129{
1130// convert the digits to raw data DDL files
1131
87932dab 1132 AliCodeTimerAuto("")
1133
06c7e392 1134 AliRunLoader* runLoader = LoadRun("READ");
0421c3d1 1135 if (!runLoader) return kFALSE;
1136
06c7e392 1137 // write raw data to DDL files
0421c3d1 1138 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
ac1671c0 1139 AliInfo(Form("processing event %d", iEvent));
0421c3d1 1140 runLoader->GetEvent(iEvent);
1141 TString baseDir = gSystem->WorkingDirectory();
1142 char dirName[256];
1143 sprintf(dirName, "raw%d", iEvent);
1144 gSystem->MakeDirectory(dirName);
1145 if (!gSystem->ChangeDirectory(dirName)) {
ac1671c0 1146 AliError(Form("couldn't change to directory %s", dirName));
0421c3d1 1147 if (fStopOnError) return kFALSE; else continue;
1148 }
1149
1150 TString detStr = detectors;
1151 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1152 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1153 AliModule* det = (AliModule*) detArray->At(iDet);
1154 if (!det || !det->IsActive()) continue;
1155 if (IsSelected(det->GetName(), detStr)) {
ac1671c0 1156 AliInfo(Form("creating raw data from digits for %s", det->GetName()));
0421c3d1 1157 det->Digits2Raw();
1158 }
1159 }
1160
007155cc 1161 if (!WriteTriggerRawData())
1162 if (fStopOnError) return kFALSE;
1163
0421c3d1 1164 gSystem->ChangeDirectory(baseDir);
1165 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 1166 AliError(Form("the following detectors were not found: %s",
1167 detStr.Data()));
0421c3d1 1168 if (fStopOnError) return kFALSE;
1169 }
1170 }
1171
1172 delete runLoader;
87932dab 1173
06c7e392 1174 return kTRUE;
1175}
0421c3d1 1176
06c7e392 1177//_____________________________________________________________________________
67327b72 1178Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
1179 const char* selDateFileName)
06c7e392 1180{
1181// convert raw data DDL files to a DATE file with the program "dateStream"
67327b72 1182// The second argument is not empty when the user decides to write
1183// the detectors raw data according to the trigger cluster.
06c7e392 1184
87932dab 1185 AliCodeTimerAuto("")
1186
06c7e392 1187 char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
1188 if (!path) {
ac1671c0 1189 AliError("the program dateStream was not found");
06c7e392 1190 if (fStopOnError) return kFALSE;
1191 } else {
1192 delete[] path;
1193 }
0421c3d1 1194
06c7e392 1195 AliRunLoader* runLoader = LoadRun("READ");
1196 if (!runLoader) return kFALSE;
1197
ac1671c0 1198 AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
67327b72 1199 Bool_t selrawdata = kFALSE;
1200 if (strcmp(selDateFileName,"") != 0) selrawdata = kTRUE;
1201
06c7e392 1202 char command[256];
f28a8d2d 1203 // Note the option -s. It is used in order to avoid
1204 // the generation of SOR/EOR events.
f86775a3 1205 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
5c0fd670 1206 dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
06c7e392 1207 FILE* pipe = gSystem->OpenPipe(command, "w");
1208
67327b72 1209 Int_t selEvents = 0;
06c7e392 1210 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1211 fprintf(pipe, "GDC\n");
1212 Float_t ldc = 0;
1213 Int_t prevLDC = -1;
1214
67327b72 1215 if (selrawdata) {
1216 // Check if the event was triggered by CTP
1217 runLoader->GetEvent(iEvent);
1218 if (!runLoader->LoadTrigger()) {
1219 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1220 if (aCTP->GetClassMask()) selEvents++;
1221 }
1222 else {
1223 AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
1224 selrawdata = kFALSE;
1225 }
1226 }
1227
06c7e392 1228 // loop over detectors and DDLs
362c9d61 1229 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1230 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
06c7e392 1231
362c9d61 1232 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
06c7e392 1233 Int_t ldcID = Int_t(ldc + 0.0001);
362c9d61 1234 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
06c7e392 1235
1236 char rawFileName[256];
362c9d61 1237 sprintf(rawFileName, "raw%d/%s",
1238 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
06c7e392 1239
1240 // check existence and size of raw data file
1241 FILE* file = fopen(rawFileName, "rb");
1242 if (!file) continue;
1243 fseek(file, 0, SEEK_END);
1244 unsigned long size = ftell(file);
aa04f81b 1245 fclose(file);
1246 if (!size) continue;
06c7e392 1247
1248 if (ldcID != prevLDC) {
1249 fprintf(pipe, " LDC Id %d\n", ldcID);
1250 prevLDC = ldcID;
1251 }
1252 fprintf(pipe, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1253 }
1254 }
1255 }
1256
1257 Int_t result = gSystem->ClosePipe(pipe);
1258
cf30933c 1259 if (!(selrawdata && selEvents > 0)) {
67327b72 1260 delete runLoader;
1261 return (result == 0);
1262 }
1263
1264 AliInfo(Form("converting selected by trigger cluster raw data DDL files to DATE file %s", selDateFileName));
1265
1266 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
1267 selDateFileName,selEvents,runLoader->GetHeader()->GetRun());
1268 FILE* pipe2 = gSystem->OpenPipe(command, "w");
1269
1270 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1271
1272 // Get the trigger decision and cluster
1273 TString detClust;
1274 runLoader->GetEvent(iEvent);
1275 if (!runLoader->LoadTrigger()) {
1276 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1277 if (aCTP->GetClassMask() == 0) continue;
1278 detClust = aCTP->GetTriggeredDetectors();
1279 AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
1280 }
1281
1282 fprintf(pipe2, "GDC\n");
1283 Float_t ldc = 0;
1284 Int_t prevLDC = -1;
1285
1286 // loop over detectors and DDLs
1287 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1288 // Write only raw data from detectors that
1289 // are contained in the trigger cluster(s)
1290 if (!IsSelected(AliDAQ::DetectorName(iDet),detClust)) continue;
1291
1292 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1293
1294 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1295 Int_t ldcID = Int_t(ldc + 0.0001);
1296 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1297
1298 char rawFileName[256];
1299 sprintf(rawFileName, "raw%d/%s",
1300 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1301
1302 // check existence and size of raw data file
1303 FILE* file = fopen(rawFileName, "rb");
1304 if (!file) continue;
1305 fseek(file, 0, SEEK_END);
1306 unsigned long size = ftell(file);
1307 fclose(file);
1308 if (!size) continue;
1309
1310 if (ldcID != prevLDC) {
1311 fprintf(pipe2, " LDC Id %d\n", ldcID);
1312 prevLDC = ldcID;
1313 }
1314 fprintf(pipe2, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1315 }
1316 }
1317 }
1318
1319 Int_t result2 = gSystem->ClosePipe(pipe2);
1320
06c7e392 1321 delete runLoader;
67327b72 1322 return ((result == 0) && (result2 == 0));
06c7e392 1323}
1324
1325//_____________________________________________________________________________
1326Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
1327 const char* rootFileName)
1328{
1329// convert a DATE file to a root file with the program "alimdc"
1330
1331 // ALIMDC setup
f28a8d2d 1332 const Int_t kDBSize = 2000000000;
c83eb8f4 1333 const Int_t kTagDBSize = 1000000000;
06c7e392 1334 const Bool_t kFilter = kFALSE;
8ec1d12b 1335 const Int_t kCompression = 1;
06c7e392 1336
1337 char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
1338 if (!path) {
ac1671c0 1339 AliError("the program alimdc was not found");
06c7e392 1340 if (fStopOnError) return kFALSE;
1341 } else {
1342 delete[] path;
1343 }
1344
ac1671c0 1345 AliInfo(Form("converting DATE file %s to root file %s",
1346 dateFileName, rootFileName));
06c7e392 1347
f732bd7d 1348 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
1349 const char* tagDBFS = "/tmp/mdc1/tags";
f732bd7d 1350
1351 // User defined file system locations
1352 if (gSystem->Getenv("ALIMDC_RAWDB1"))
1353 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
1354 if (gSystem->Getenv("ALIMDC_RAWDB2"))
1355 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
1356 if (gSystem->Getenv("ALIMDC_TAGDB"))
1357 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
f732bd7d 1358
1359 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1360 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1361 gSystem->Exec(Form("rm -rf %s",tagDBFS));
f732bd7d 1362
1363 gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
1364 gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
1365 gSystem->Exec(Form("mkdir %s",tagDBFS));
f732bd7d 1366
1367 Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s",
1368 kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
1369 gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
1370
1371 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1372 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1373 gSystem->Exec(Form("rm -rf %s",tagDBFS));
06c7e392 1374
1375 return (result == 0);
0421c3d1 1376}
1377
85a5290f 1378
95601147 1379//_____________________________________________________________________________
06c7e392 1380AliRunLoader* AliSimulation::LoadRun(const char* mode) const
95601147 1381{
1382// delete existing run loaders, open a new one and load gAlice
1383
1384 while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
1385 AliRunLoader* runLoader =
1386 AliRunLoader::Open(fGAliceFileName.Data(),
06c7e392 1387 AliConfig::GetDefaultEventFolderName(), mode);
95601147 1388 if (!runLoader) {
ac1671c0 1389 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
95601147 1390 return NULL;
1391 }
1392 runLoader->LoadgAlice();
795e4a22 1393 runLoader->LoadHeader();
95601147 1394 gAlice = runLoader->GetAliRun();
1395 if (!gAlice) {
ac1671c0 1396 AliError(Form("no gAlice object found in file %s",
1397 fGAliceFileName.Data()));
95601147 1398 return NULL;
1399 }
1400 return runLoader;
1401}
1402
85a5290f 1403//_____________________________________________________________________________
05526d44 1404Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
1405{
1406// get or calculate the number of signal events per background event
1407
1408 if (!fBkgrdFileNames) return 1;
1409 Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
1410 if (nBkgrdFiles == 0) return 1;
1411
1412 // get the number of signal events
1413 if (nEvents <= 0) {
1414 AliRunLoader* runLoader =
ca30848f 1415 AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
05526d44 1416 if (!runLoader) return 1;
ca30848f 1417
05526d44 1418 nEvents = runLoader->GetNumberOfEvents();
1419 delete runLoader;
1420 }
1421
1422 Int_t result = 0;
1423 for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
1424 // get the number of background events
1425 const char* fileName = ((TObjString*)
1426 (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
ca30848f 1427 AliRunLoader* runLoader =
05526d44 1428 AliRunLoader::Open(fileName, "BKGRD");
1429 if (!runLoader) continue;
1430 Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
1431 delete runLoader;
ca30848f 1432
05526d44 1433 // get or calculate the number of signal per background events
1434 Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
1435 if (nSignalPerBkgrd <= 0) {
1436 nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
1437 } else if (result && (result != nSignalPerBkgrd)) {
ac1671c0 1438 AliInfo(Form("the number of signal events per background event "
1439 "will be changed from %d to %d for stream %d",
1440 nSignalPerBkgrd, result, iBkgrdFile+1));
05526d44 1441 nSignalPerBkgrd = result;
1442 }
1443
1444 if (!result) result = nSignalPerBkgrd;
1445 if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
ac1671c0 1446 AliWarning(Form("not enough background events (%d) for %d signal events "
1447 "using %d signal per background events for stream %d",
1448 nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1));
05526d44 1449 }
1450 }
1451
1452 return result;
1453}
1454
1455//_____________________________________________________________________________
85a5290f 1456Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
1457{
1458// check whether detName is contained in detectors
1459// if yes, it is removed from detectors
1460
1461 // check if all detectors are selected
1462 if ((detectors.CompareTo("ALL") == 0) ||
1463 detectors.BeginsWith("ALL ") ||
1464 detectors.EndsWith(" ALL") ||
1465 detectors.Contains(" ALL ")) {
1466 detectors = "ALL";
1467 return kTRUE;
1468 }
1469
1470 // search for the given detector
1471 Bool_t result = kFALSE;
1472 if ((detectors.CompareTo(detName) == 0) ||
1473 detectors.BeginsWith(detName+" ") ||
1474 detectors.EndsWith(" "+detName) ||
1475 detectors.Contains(" "+detName+" ")) {
1476 detectors.ReplaceAll(detName, "");
1477 result = kTRUE;
1478 }
1479
1480 // clean up the detectors string
1481 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1482 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1483 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1484
1485 return result;
1486}
ca30848f 1487
795e4a22 1488//_____________________________________________________________________________
ca30848f 1489Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName)
1490{
1491//
1492// Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
1493// These can be used for embedding of MC tracks into RAW data using the standard
1494// merging procedure.
1495//
1496// If an ESD file is given the reconstructed vertex is taken from it and stored in the event header.
1497//
1498 if (!gAlice) {
1499 AliError("no gAlice object. Restart aliroot and try again.");
1500 return kFALSE;
1501 }
1502 if (gAlice->Modules()->GetEntries() > 0) {
1503 AliError("gAlice was already run. Restart aliroot and try again.");
1504 return kFALSE;
1505 }
1506
1507 AliInfo(Form("initializing gAlice with config file %s",fConfigFileName.Data()));
1508 StdoutToAliInfo(StderrToAliError(gAlice->Init(fConfigFileName.Data());););
1509//
1510// Initialize CDB
795e4a22 1511 InitCDB();
1512 //AliCDBManager* man = AliCDBManager::Instance();
1513 //man->SetRun(0); // Should this come from rawdata header ?
ca30848f 1514
1515 Int_t iDet;
1516 //
1517 // Get the runloader
1518 AliRunLoader* runLoader = gAlice->GetRunLoader();
1519 //
1520 // Open esd file if available
1521 TFile* esdFile = TFile::Open(esdFileName);
1522 Bool_t esdOK = (esdFile != 0);
1523 AliESD* esd = new AliESD;
1524 TTree* treeESD = 0;
1525 if (esdOK) {
1526 treeESD = (TTree*) esdFile->Get("esdTree");
1527 if (!treeESD) {
1528 AliWarning("No ESD tree found");
1529 esdOK = kFALSE;
1530 } else {
1531 treeESD->SetBranchAddress("ESD", &esd);
1532 }
1533 }
1534 //
1535 // Create the RawReader
8b31e840 1536 TString fileName(rawDirectory);
1537 AliRawReader* rawReader = 0x0;
1538 if (fileName.EndsWith("/")) {
1539 rawReader = new AliRawReaderFile(fileName);
1540 } else if (fileName.EndsWith(".root")) {
1541 rawReader = new AliRawReaderRoot(fileName);
1542 } else if (!fileName.IsNull()) {
1543 rawReader = new AliRawReaderDate(fileName);
1544 rawReader->SelectEvents(7);
1545 }
1546// if (!fEquipIdMap.IsNull() && fRawReader)
1547// fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
ca30848f 1548 //
1549 // Get list of detectors
1550 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1551 //
1552 // Get Header
1553 AliHeader* header = runLoader->GetHeader();
1554 //
8b31e840 1555 TString detStr = fMakeSDigits;
ca30848f 1556 // Event loop
1557 Int_t nev = 0;
1558 while(kTRUE) {
1559 if (!(rawReader->NextEvent())) break;
1560 //
1561 // Detector loop
1562 for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1563 AliModule* det = (AliModule*) detArray->At(iDet);
8b31e840 1564 if (!det || !det->IsActive()) continue;
1565 if (IsSelected(det->GetName(), detStr)) {
1566 AliInfo(Form("Calling Raw2SDigits for %s\n", det->GetName()));
1567 det->Raw2SDigits(rawReader);
1568 rawReader->Reset();
1569 }
ca30848f 1570 } // detectors
1571
5b188f2f 1572
ca30848f 1573 //
1574 // If ESD information available obtain reconstructed vertex and store in header.
1575 if (esdOK) {
1576 treeESD->GetEvent(nev);
1577 const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
1578 Double_t position[3];
1579 esdVertex->GetXYZ(position);
1580 AliGenEventHeader* mcHeader = new AliGenEventHeader("ESD");
1581 TArrayF mcV;
1582 mcV.Set(3);
1583 for (Int_t i = 0; i < 3; i++) mcV[i] = position[i];
1584 mcHeader->SetPrimaryVertex(mcV);
1585 header->Reset(0,nev);
1586 header->SetGenEventHeader(mcHeader);
1587 printf("***** Saved vertex %f %f %f \n", position[0], position[1], position[2]);
1588 }
1589 nev++;
1590//
1591// Finish the event
1592 runLoader->TreeE()->Fill();
1593 runLoader->SetNextEvent();
1594 } // events
1595
1596 delete rawReader;
1597//
1598// Finish the run
1599 runLoader->CdGAFile();
1600 runLoader->WriteHeader("OVERWRITE");
1601 runLoader->WriteRunLoader();
1602
1603 return kTRUE;
1604}
5b188f2f 1605
1606//_____________________________________________________________________________
1607Int_t AliSimulation::GetDetIndex(const char* detector)
1608{
1609 // return the detector index corresponding to detector
1610 Int_t index = -1 ;
1611 for (index = 0; index < fgkNDetectors ; index++) {
1612 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
1613 break ;
1614 }
1615 return index ;
1616}
cae21299 1617
1618//_____________________________________________________________________________
1619Bool_t AliSimulation::RunHLT()
1620{
1621 // Run the HLT simulation
1622 // HLT simulation is implemented in HLT/sim/AliHLTSimulation
1623 // Disabled if fRunHLT is empty, default vaule is "default".
1624 // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
1625 // The default simulation depends on the HLT component libraries and their
1626 // corresponding agents which define components and chains to run. See
1627 // http://web.ift.uib.no/~kjeks/doc/alice-hlt/
1628 // http://web.ift.uib.no/~kjeks/doc/alice-hlt/classAliHLTModuleAgent.html
1629 //
1630 // The libraries to be loaded can be specified as an option.
1631 // <pre>
1632 // AliSimulation sim;
1633 // sim.SetRunHLT("libAliHLTSample.so");
1634 // </pre>
1635 // will only load <tt>libAliHLTSample.so</tt>
1636
1637 // Other available options:
1638 // \li loglevel=<i>level</i> <br>
1639 // logging level for this processing
1640 // \li alilog=off
1641 // disable redirection of log messages to AliLog class
1642 // \li config=<i>macro</i>
1643 // configuration macro
1644 // \li localrec=<i>configuration</i>
1645 // comma separated list of configurations to be run during simulation
1646
1647 int iResult=0;
1648 AliRunLoader* pRunLoader = LoadRun("READ");
1649 if (!pRunLoader) return kFALSE;
1650
795e4a22 1651 // initialize CDB storage, run number, set CDB lock
1652 InitCDB();
1653 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1654 SetCDBLock();
1655
cae21299 1656 // load the library dynamically
1657 gSystem->Load(ALIHLTSIMULATION_LIBRARY);
1658
1659 // check for the library version
1660 AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
1661 if (!fctVersion) {
1662 AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
1663 return kFALSE;
1664 }
1665 if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
1666 AliError(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
1667 return kFALSE;
1668 }
1669
1670 // print compile info
1671 typedef void (*CompileInfo)( char*& date, char*& time);
1672 CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
1673 if (fctInfo) {
1674 char* date="";
1675 char* time="";
1676 (*fctInfo)(date, time);
1677 if (!date) date="unknown";
1678 if (!time) time="unknown";
1679 AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
1680 } else {
1681 AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
1682 }
1683
1684 // create instance of the HLT simulation
1685 AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
1686 AliHLTSimulation* pHLT=NULL;
1687 if (fctCreate==NULL || (pHLT=(fctCreate()))==NULL) {
1688 AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
1689 return kFALSE;
1690 }
1691
1692 // init the HLT simulation
a441bf51 1693 TString options;
1694 if (fRunHLT.CompareTo("default")!=0) options=fRunHLT;
1695 if (!IsSelected("HLT", fWriteRawData)) {
1696 options+=" writerawfiles=";
1697 } else {
1698 options+=" writerawfiles=HLT";
1699 }
cae21299 1700 AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
a441bf51 1701 if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, options.Data())))<0) {
cae21299 1702 AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
1703 } else {
1704 // run the HLT simulation
1705 AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
1706 if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
1707 AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
1708 }
1709 }
1710
1711 // delete the instance
1712 AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
1713 if (fctDelete==NULL || fctDelete(pHLT)<0) {
1714 AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
1715 }
1716 pHLT=NULL;
1717
1718 return iResult>=0?kTRUE:kFALSE;
1719}
cae17938 1720
1721//_____________________________________________________________________________
a1b90a73 1722Bool_t AliSimulation::RunQA()
cae17938 1723{
a1b90a73 1724 // run the QA on summable hits, digits or digits
1725
1726 AliQADataMakerSteer qas ;
1727 qas.SetRunLoader(gAlice->GetRunLoader()) ;
1728
e5dedfe2 1729 TString detectorsw("") ;
1730 Bool_t rv = kTRUE ;
1731 detectorsw = qas.Run("ALL", AliQA::kHITS) ;
a1b90a73 1732// qas.Reset() ;
e5dedfe2 1733 detectorsw += qas.Run(fMakeSDigits.Data(), AliQA::kSDIGITS) ;
a1b90a73 1734// qas.Reset() ;
e5dedfe2 1735 detectorsw += qas.Run(fMakeDigits.Data(), AliQA::kDIGITS) ;
a1b90a73 1736// qas.Reset() ;
e5dedfe2 1737 detectorsw += qas.Run(fMakeDigitsFromHits.Data(), AliQA::kDIGITS) ;
1738
1739 if ( detectorsw.IsNull() )
1740 rv = kFALSE ;
a1b90a73 1741 return rv ;
cae17938 1742}
1743
795e4a22 1744//_____________________________________________________________________________
1745void AliSimulation::ProcessEnvironmentVars()
1746{
1747// Extract run number and random generator seed from env variables
1748
1749 AliInfo("Processing environment variables");
1750
1751 // Random Number seed
1752
1753 // first check that seed is not already set
1754 if (fSeed == 0) {
1755 if (gSystem->Getenv("CONFIG_SEED")) {
1756 fSeed = atoi(gSystem->Getenv("CONFIG_SEED"));
1757 }
1758 } else {
1759 if (gSystem->Getenv("CONFIG_SEED")) {
1760 AliInfo(Form("Seed for random number generation already set (%d)"
1761 ": CONFIG_SEED variable ignored!", fSeed));
1762 }
1763 }
1764
1765 AliInfo(Form("Seed for random number generation = %d ", fSeed));
1766
1767 // Run Number
1768
1769 // first check that run number is not already set
1770 if(fRun < 0) {
1771 if (gSystem->Getenv("DC_RUN")) {
1772 fRun = atoi(gSystem->Getenv("DC_RUN"));
1773 }
1774 } else {
1775 if (gSystem->Getenv("DC_RUN")) {
1776 AliInfo(Form("Run number already set (%d): DC_RUN variable ignored!", fRun));
1777 }
1778 }
1779
1780 AliInfo(Form("Run number = %d", fRun));
1781}