AliRoot Core  3dc7879 (3dc7879)
AliSimulation.cxx
Go to the documentation of this file.
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: AliSimulation.cxx 64623 2013-10-21 13:38:58Z rgrosso $ */
17 
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 // //
33 // The name of the configuration file can be passed as argument to the //
34 // AliSimulation constructor or can be specified by //
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 // //
64 // Background events can be merged by calling //
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. //
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. //
74 // //
75 // The output of raw data can be switched on by calling //
76 // //
77 // sim.SetWriteRawData("MUON"); // write raw data for MUON //
78 // //
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 // //
88 // The methods RunSimulation, RunSDigitization, RunDigitization, //
89 // RunHitsDigitization and WriteRawData can be used to run only parts of //
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. //
93 // //
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 // //
106 // The trigger configuration is set by the method SetTriggerConfig(X) //
107 // X can take three kinds of values //
108 // //
109 // - The exact string "none" - case insensitive. In this case, not trigger //
110 // information is generated from the digits. //
111 // - The empty string or "ocdb" - case insensitive. In this case the //
112 // trigger configuration is read from OCDB //
113 // - Some string - say "p-p" - in which case the configuration is read from //
114 // fixed files in $ALICE_ROOT/GRP/CTP/ - say $ALICE_ROOT/GRP/CTP/p-p.cfg //
115 // //
116 // Default is to read from OCDB. //
117 // //
119 
120 #include <TFile.h>
121 #include <TGeoGlobalMagField.h>
122 #include <TGeoManager.h>
123 #include <TObjString.h>
124 #include <TROOT.h>
125 #include <TSystem.h>
126 #include <TVirtualMC.h>
127 #include <TVirtualMCApplication.h>
128 #include <TDatime.h>
129 #include <TInterpreter.h>
130 
131 #include "AliAlignObj.h"
132 #include "AliCDBEntry.h"
133 #include "AliCDBManager.h"
134 #include "AliGRPManager.h"
135 #include "AliCDBStorage.h"
136 #include "AliCTPRawData.h"
137 #include "AliCentralTrigger.h"
138 #include "AliCentralTrigger.h"
139 #include "AliCodeTimer.h"
140 #include "AliDAQ.h"
141 #include "AliDigitizer.h"
142 #include "AliESDEvent.h"
143 #include "AliFileUtilities.h"
144 #include "AliGRPObject.h"
145 #include "AliGenEventHeader.h"
146 #include "AliGenerator.h"
147 #include "AliGeomManager.h"
148 #include "AliHLTSimulation.h"
149 #include "AliHeader.h"
150 #include "AliLego.h"
151 #include "AliLegoGenerator.h"
152 #include "AliLog.h"
153 #include "AliMC.h"
154 #include "AliMagF.h"
155 #include "AliModule.h"
156 #include "AliPDG.h"
157 #include "AliRawReaderDate.h"
158 #include "AliRawReaderFile.h"
159 #include "AliRawReaderRoot.h"
160 #include "AliRun.h"
161 #include "AliDigitizationInput.h"
162 #include "AliRunLoader.h"
163 #include "AliStack.h"
164 #include "AliSimulation.h"
165 #include "AliSysInfo.h"
166 #include "AliVertexGenFile.h"
167 #include "AliLumiTools.h"
168 #include <TGraph.h>
169 #include <fstream>
170 
171 using std::ofstream;
172 ClassImp(AliSimulation)
173 
174 AliSimulation *AliSimulation::fgInstance = 0;
175  const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD",
176  "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE","AD",
177  "FIT","MFT","HLT"};
178 
179 const Char_t* AliSimulation::fgkRunHLTAuto = "auto";
180 const Char_t* AliSimulation::fgkHLTDefConf = "default";
181 //_____________________________________________________________________________
182 AliSimulation::AliSimulation(const char* configFileName,
183  const char* name, const char* title) :
184  TNamed(name, title),
185 
186  fRunGeneratorOnly(kFALSE),
187  fRunGeneration(kTRUE),
188  fRunSimulation(kTRUE),
189  fLoadAlignFromCDB(kTRUE),
190  fLoadAlObjsListOfDets("ALL"),
191  fMakeSDigits("ALL"),
192  fMakeDigits("ALL"),
193  fTriggerConfig(""),
194  fMakeDigitsFromHits(""),
195  fWriteRawData(""),
196  fRawDataFileName(""),
197  fDeleteIntermediateFiles(kFALSE),
198  fWriteSelRawData(kFALSE),
199  fStopOnError(kFALSE),
200  fUseMonitoring(kFALSE),
201  fNEvents(1),
202  fConfigFileName(configFileName),
203  fGAliceFileName("galice.root"),
204  fEventsPerFile(),
205  fBkgrdFileNames(NULL),
206  fAlignObjArray(NULL),
207  fUseBkgrdVertex(kTRUE),
208  fRegionOfInterest(kFALSE),
209  fCDBUri(""),
210  fQARefUri(""),
211  fSpecCDBUri(),
212  fRun(-1),
213  fSeed(0),
214  fInitCDBCalled(kFALSE),
215  fInitRunNumberCalled(kFALSE),
216  fSetRunNumberFromDataCalled(kFALSE),
217  fEmbeddingFlag(kFALSE),
218  fLego(NULL),
219  fKey(0),
220  fUseVertexFromCDB(0),
221  fUseMagFieldFromGRP(0),
222  fGRPWriteLocation(Form("local://%s", gSystem->pwd())),
223  fUseDetectorsFromGRP(kTRUE),
224  fUseTimeStampFromCDB(0),
225  fTimeStart(0),
226  fTimeEnd(0),
227  fLumiDecayH(-1.), // by default, use lumi from CTP
228  fOrderedTimeStamps(),
229  fQADetectors("ALL"),
230  fQATasks("ALL"),
231  fRunQA(kTRUE),
232  fEventSpecie(AliRecoParam::kDefault),
233  fWriteQAExpertData(kTRUE),
234  fGeometryFile(),
235  fRunHLT(fgkRunHLTAuto),
236  fpHLT(NULL),
237  fWriteGRPEntry(kTRUE)
238 {
239 // create simulation object with default parameters
240  fgInstance = this;
241  SetGAliceFile("galice.root");
242 
243 // for QA
247  qam->SetTasks(fQATasks) ;
248 }
249 
250 //_____________________________________________________________________________
252 {
253 // clean up
254 
255  fEventsPerFile.Delete();
256 // if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
257 // delete fAlignObjArray; fAlignObjArray=0;
258 
259  if (fBkgrdFileNames) {
260  fBkgrdFileNames->Delete();
261  delete fBkgrdFileNames;
262  }
263 
264  fSpecCDBUri.Delete();
265  if (fgInstance==this) fgInstance = 0;
266 
270 }
271 
272 
273 //_____________________________________________________________________________
275 {
276 // set the number of events for one run
277 
278  fNEvents = nEvents;
279 }
280 
281 //_____________________________________________________________________________
283 {
284  // activate a default CDB storage
285  // First check if we have any CDB storage set, because it is used
286  // to retrieve the calibration and alignment constants
287 
288  if (fInitCDBCalled) return;
289  fInitCDBCalled = kTRUE;
290 
294  qam->SetTasks(fQATasks) ;
295  if (fWriteQAExpertData)
296  qam->SetWriteExpert() ;
297 
298  if (qam->IsDefaultStorageSet()) {
299  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
300  AliWarning("Default QA reference storage has been already set !");
301  AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fQARefUri.Data()));
302  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
303  fQARefUri = qam->GetDefaultStorage()->GetURI();
304  } else {
305  if (fQARefUri.Length() > 0) {
306  AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
307  AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
308  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
309  } else {
310  fQARefUri="local://$ALICE_ROOT/QARef";
311  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
312  AliWarning("Default QA reference storage not yet set !!!!");
313  AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
314  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
315  }
317  }
318 }
319 
320 //_____________________________________________________________________________
322 {
323 // activate a default CDB storage
324 // First check if we have any CDB storage set, because it is used
325 // to retrieve the calibration and alignment constants
326 
327  if (fInitCDBCalled) return;
328  fInitCDBCalled = kTRUE;
329 
331  if (man->IsDefaultStorageSet())
332  {
333  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
334  AliWarning("Default CDB storage has been already set !");
335  AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
336  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
337  fCDBUri = man->GetDefaultStorage()->GetURI();
338  }
339  else {
340  if (fCDBUri.Length() > 0)
341  {
342  AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
343  AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
344  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
345  } else {
346  fCDBUri="local://$ALICE_ROOT/OCDB";
347  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
348  AliWarning("Default CDB storage not yet set !!!!");
349  AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
350  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
351 
352  }
354  }
355 
356  // Now activate the detector specific CDB storage locations
357  for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
358  TObject* obj = fSpecCDBUri[i];
359  if (!obj) continue;
360  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
361  AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
362  AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
363  man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
364  }
365 
366 }
367 
368 //_____________________________________________________________________________
370 // check run number. If not set, set it to 0 !!!!
371 
372  if (fInitRunNumberCalled) return;
373  fInitRunNumberCalled = kTRUE;
374 
375  if(fRun >= 0) {
376  AliDebug(2, Form("Setting CDB run number to: %d",fRun));
377  } else {
378  fRun=0;
379  AliWarning(Form("Run number not yet set !!!! Setting it now to: %d",
380  fRun));
381  }
382 
384  if (man->GetRun() != fRun) {
385  man->SetRun(fRun);
386  }
387 
388  man->Print();
389 
390 }
391 
392 //_____________________________________________________________________________
394  // Set CDB lock: from now on it is forbidden to reset the run number
395  // or the default storage or to activate any further storage!
396 
397  ULong64_t key = AliCDBManager::Instance()->SetLock(1);
398  if (key) fKey = key;
399 }
400 
401 //_____________________________________________________________________________
402 void AliSimulation::SetDefaultStorage(const char* uri) {
403  // Store the desired default CDB storage location
404  // Activate it later within the Run() method
405 
406  fCDBUri = uri;
407 
408 }
409 
410 //_____________________________________________________________________________
412  // Store the desired default CDB storage location
413  // Activate it later within the Run() method
414 
415  fQARefUri = uri;
417 }
418 
419 //_____________________________________________________________________________
420 void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
421 // Store a detector-specific CDB storage location
422 // Activate it later within the Run() method
423 
424  AliCDBPath aPath(calibType);
425  if(!aPath.IsValid()){
426  AliError(Form("Not a valid path: %s", calibType));
427  return;
428  }
429 
430  TObject* obj = fSpecCDBUri.FindObject(calibType);
431  if (obj) fSpecCDBUri.Remove(obj);
432  fSpecCDBUri.Add(new TNamed(calibType, uri));
433 
434 }
435 
436 //_____________________________________________________________________________
438 {
439 // sets run number
440 // Activate it later within the Run() method
441 
442  fRun = run;
443 }
444 
445 //_____________________________________________________________________________
447 {
448 // sets seed number
449 // Activate it later within the Run() method
450 
451  fSeed = seed;
452 }
453 
454 //_____________________________________________________________________________
456 {
457  // Set the CDB manager run number
458  // The run number is retrieved from gAlice
459 
460  if (fSetRunNumberFromDataCalled) return kTRUE;
462 
464  Int_t runData = -1, runCDB = -1;
465 
466  AliRunLoader* runLoader = LoadRun("READ");
467  if (!runLoader) return kFALSE;
468  else {
469  runData = runLoader->GetHeader()->GetRun();
470  delete runLoader;
471  }
472 
473  runCDB = man->GetRun();
474  if(runCDB >= 0) {
475  if (runCDB != runData) {
476  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
477  AliWarning(Form("A run number was previously set in AliCDBManager: %d !", runCDB));
478  AliWarning(Form("It will be replaced with the run number got from run header: %d !", runData));
479  AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
480  }
481 
482  }
483 
484  man->SetRun(runData);
485  fRun = runData;
486 
487  if(man->GetRun() < 0) {
488  AliError("Run number not properly initalized!");
489  return kFALSE;
490  }
491 
492  man->Print();
493 
494  return kTRUE;
495 }
496 
497 //_____________________________________________________________________________
499 {
500 // set the name of the config file
501 
503 }
504 
505 //_____________________________________________________________________________
507 {
508 // set the name of the galice file
509 // the path is converted to an absolute one if it is relative
510 
512  if (!gSystem->IsAbsoluteFileName(fGAliceFileName)) {
513  char* absFileName = gSystem->ConcatFileName(gSystem->WorkingDirectory(),
515  fGAliceFileName = absFileName;
516  delete[] absFileName;
517  }
518 
519  AliDebug(2, Form("galice file name set to %s", fileName));
520 }
521 
522 //_____________________________________________________________________________
523 void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
524  Int_t nEvents)
525 {
526 // set the number of events per file for the given detector and data type
527 // ("Hits", "Summable Digits", "Digits", "Reconstructed Points" or "Tracks")
528 
529  TNamed* obj = new TNamed(detector, type);
530  obj->SetUniqueID(nEvents);
531  fEventsPerFile.Add(obj);
532 }
533 
534 //_____________________________________________________________________________
536 {
537  // Read the alignment objects from CDB.
538  // Each detector is supposed to have the
539  // alignment objects in DET/Align/Data CDB path.
540  // All the detector objects are then collected,
541  // sorted by geometry level (starting from ALIC) and
542  // then applied to the TGeo geometry.
543  // Finally an overlaps check is performed.
544 
545  if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
546  AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
547  return kFALSE;
548  }
549 
550  // initialize CDB storage, run number, set CDB lock
551  InitCDB();
552 // if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
553  SetCDBLock();
554 
555  Bool_t delRunLoader = kFALSE;
556  if (!runLoader) {
557  runLoader = LoadRun("READ");
558  if (!runLoader) return kFALSE;
559  delRunLoader = kTRUE;
560  }
561 
562  // Export ideal geometry
563  if(!IsGeometryFromFile()) AliGeomManager::GetGeometry()->Export("geometry.root");
564 
565  // Load alignment data from CDB and apply to geometry through AliGeomManager
566  if(fLoadAlignFromCDB){
567 
568  TString detStr = fLoadAlObjsListOfDets;
569  TString loadAlObjsListOfDets = "";
570 
571  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
572  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
573  AliModule* det = (AliModule*) detArray->At(iDet);
574  if (!det || !det->IsActive()) continue;
575  if (IsSelected(det->GetName(), detStr)) {
576  //add det to list of dets to be aligned from CDB
577  loadAlObjsListOfDets += det->GetName();
578  loadAlObjsListOfDets += " ";
579  }
580  } // end loop over detectors
581  loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
582  AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
583  }else{
584  // Check if the array with alignment objects was
585  // provided by the user. If yes, apply the objects
586  // to the present TGeo geometry
587  if (fAlignObjArray) {
589  AliError("The misalignment of one or more volumes failed!"
590  "Compare the list of simulated detectors and the list of detector alignment data!");
591  if (delRunLoader) delete runLoader;
592  return kFALSE;
593  }
594  }
595  }
596 
597  // Update the internal geometry of modules (ITS needs it)
598  TString detStr = fLoadAlObjsListOfDets;
599  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
600  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
601 
602  AliModule* det = (AliModule*) detArray->At(iDet);
603  if (!det || !det->IsActive()) continue;
604  if (IsSelected(det->GetName(), detStr)) {
605  det->UpdateInternalGeometry();
606  }
607  } // end loop over detectors
608 
609 
610  if (delRunLoader) delete runLoader;
611 
612  return kTRUE;
613 }
614 
615 //_____________________________________________________________________________
616 void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
617 {
618 // add a file with background events for merging
619 
620  TObjString* fileNameStr = new TObjString(fileName);
621  fileNameStr->SetUniqueID(nSignalPerBkgrd);
623  fBkgrdFileNames->Add(fileNameStr);
624 }
625 
626 void AliSimulation::EmbedInto(const char* fileName, Int_t nSignalPerBkgrd)
627 {
628 // add a file with background events for embedding
629  MergeWith(fileName, nSignalPerBkgrd);
630  fEmbeddingFlag = kTRUE;
631 }
632 
633 //_____________________________________________________________________________
634 Bool_t AliSimulation::Run(Int_t nEvents)
635 {
636 // run the generation, simulation and digitization
637 
638 
639  AliCodeTimerAuto("",0)
640  AliSysInfo::AddStamp("Start_Run");
641 
642  // Load run number and seed from environmental vars
644  AliSysInfo::AddStamp("ProcessEnvironmentVars");
645 
646  gRandom->SetSeed(fSeed);
647 
648  if (nEvents > 0) fNEvents = nEvents;
649 
650  // Run generator-only code on demand
651  if (fRunGeneratorOnly)
652  {
653  if(!RunGeneratorOnly())
654  {
655  if (fStopOnError) return kFALSE;
656  }
657  else
658  return kTRUE;
659  }
660 
661  if (fRunHLT.Contains(fgkRunHLTAuto)) {
662  InitCDB();
663  InitRunNumber();
664  AliGRPManager grpM;
665  grpM.ReadGRPEntry();
666  const AliGRPObject* grp = grpM.GetGRPData();
667  int hmode = grp->GetHLTMode();
668  TString hmodS;
669  switch(hmode) {
670  case AliGRPObject::kModeA : hmodS = "A"; break;
671  case AliGRPObject::kModeB : hmodS = "B"; break;
672  case AliGRPObject::kModeC : hmodS = "C"; break;
673  default: hmodS = "Unknown";
674  }
675  AliInfoF("HLT Trigger Mode %s detected from GRP",hmodS.Data());
676  Int_t activeDetectors = grp->GetDetectorMask();
677  TString detStr = AliDAQ::ListOfTriggeredDetectors(activeDetectors);
678  Bool_t tpcIN = detStr.Contains("TPC");
679  if (!tpcIN) {
680  AliInfo("TPC is not in the run, disabling HLT");
681  }
682  if (hmode==AliGRPObject::kModeC && tpcIN) {
683  fRunHLT.ReplaceAll(fgkRunHLTAuto,fgkHLTDefConf);
684  AliInfoF("HLT simulation set to %s",fRunHLT.Data());
685  }
686  else {
687  fRunHLT.ReplaceAll(fgkRunHLTAuto,"");
688  AliInfoF("HLT simulation set to \"%s\"",fRunHLT.Data());
689  }
690  }
691  else {
692  AliInfoF("fRunHLT is set to \"%s\", no attempt to extract HLT mode from GRP will be done",fRunHLT.Data());
693  }
694 
695  // create and setup the HLT instance
696  if (!fRunHLT.IsNull() && !CreateHLT()) {
697  if (fStopOnError) return kFALSE;
698  // disable HLT
699  fRunHLT="";
700  }
701 
702  // generation and simulation -> hits
703  if (fRunGeneration) {
704  if (!RunSimulation()) if (fStopOnError) return kFALSE;
705  }
706  AliSysInfo::AddStamp("RunSimulation");
707 
708  // initialize CDB storage from external environment
709  // (either CDB manager or AliSimulation setters),
710  // if not already done in RunSimulation()
711  InitCDB();
712  AliSysInfo::AddStamp("InitCDB");
713 
714  // Set run number in CDBManager from data
715  // From this point on the run number must be always loaded from data!
716  if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
717 
718  // Set CDB lock: from now on it is forbidden to reset the run number
719  // or the default storage or to activate any further storage!
720  SetCDBLock();
721 
722  // If RunSimulation was not called, load the geometry and misalign it
724  // Initialize the geometry manager
725  AliGeomManager::LoadGeometry("geometry.root");
726  AliSysInfo::AddStamp("GetGeometry");
727 // // Check that the consistency of symbolic names for the activated subdetectors
728 // // in the geometry loaded by AliGeomManager
729 // AliRunLoader* runLoader = LoadRun("READ");
730 // if (!runLoader) return kFALSE;
731 //
732 // TString detsToBeChecked = "";
733 // TObjArray* detArray = runLoader->GetAliRun()->Detectors();
734 // for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
735 // AliModule* det = (AliModule*) detArray->At(iDet);
736 // if (!det || !det->IsActive()) continue;
737 // detsToBeChecked += det->GetName();
738 // detsToBeChecked += " ";
739 // } // end loop over detectors
740 // if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
742  AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
743 
744  if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
745  // Misalign geometry
746  if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
747  }
748  AliSysInfo::AddStamp("MissalignGeometry");
749 
750 
751  // hits -> summable digits
752  AliSysInfo::AddStamp("Start_sdigitization");
753  if (!fMakeSDigits.IsNull()) {
754  if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
755 
756  }
757  AliSysInfo::AddStamp("Stop_sdigitization");
758 
759  AliSysInfo::AddStamp("Start_digitization");
760  // summable digits -> digits
761  if (!fMakeDigits.IsNull()) {
763  if (fStopOnError) return kFALSE;
764  }
765  }
766  AliSysInfo::AddStamp("Stop_digitization");
767 
768 
769 
770  // hits -> digits
771  if (!fMakeDigitsFromHits.IsNull()) {
772  if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
773  AliWarning(Form("Merging and direct creation of digits from hits "
774  "was selected for some detectors. "
775  "No merging will be done for the following detectors: %s",
776  fMakeDigitsFromHits.Data()));
777  }
779  if (fStopOnError) return kFALSE;
780  }
781  }
782 
783  AliSysInfo::AddStamp("Hits2Digits");
784 
785 
786  // digits -> trigger. Set trigger configuration to "none" - any
787  // case - to not generate the trigger information. Set the trigger
788  // configuration to some string X to read from file at
789  // $ALICE_ROOT/GRP/CTP/X. Set the trigger configuration to the
790  // empty string or "ocdb" - any case - to read from OCDB.
791  if (!fTriggerConfig.EqualTo("none",TString::kIgnoreCase) &&
793  if (fStopOnError) return kFALSE;
794  }
795 
796  AliSysInfo::AddStamp("RunTrigger");
797 
798 
799  // digits -> raw data
800  if (!fWriteRawData.IsNull()) {
803  if (fStopOnError) return kFALSE;
804  }
805  }
806 
807  AliSysInfo::AddStamp("WriteRaw");
808 
809  // run HLT simulation on simulated digit data if raw data is not
810  // simulated, otherwise its called as part of WriteRawData
811  if (!fRunHLT.IsNull() && fWriteRawData.IsNull()) {
812  if (!RunHLT()) {
813  if (fStopOnError) return kFALSE;
814  }
815  }
816 
817  AliSysInfo::AddStamp("RunHLT");
818 
819  //QA
820  if (fRunQA) {
821  Bool_t rv = RunQA() ;
822  if (!rv)
823  if (fStopOnError)
824  return kFALSE ;
825  }
826 
827  AliSysInfo::AddStamp("RunQA");
828  //
830  //
831  TString snapshotFileOut("");
832  if(TString(gSystem->Getenv("OCDB_SNAPSHOT_CREATE")) == TString("kTRUE")){
833  AliInfo(" ******** Creating the snapshot! *********");
834  TString snapshotFile(gSystem->Getenv("OCDB_SNAPSHOT_FILENAME"));
835  if(!(snapshotFile.IsNull() || snapshotFile.IsWhitespace()))
836  snapshotFileOut = snapshotFile;
837  else
838  snapshotFileOut="OCDB.root";
839  AliCDBManager::Instance()->DumpToSnapshotFile(snapshotFileOut.Data(),kFALSE);
840  }
841 
842  // Cleanup of CDB manager: cache and active storages!
844 
845  return kTRUE;
846 }
847 
848 //_______________________________________________________________________
849 Bool_t AliSimulation::RunLego(const char *setup, Int_t nc1, Float_t c1min,
850  Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
851  Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev)
852 {
853  //
854  // Generates lego plots of:
855  // - radiation length map phi vs theta
856  // - radiation length map phi vs eta
857  // - interaction length map
858  // - g/cm2 length map
859  //
860  // ntheta bins in theta, eta
861  // themin minimum angle in theta (degrees)
862  // themax maximum angle in theta (degrees)
863  // nphi bins in phi
864  // phimin minimum angle in phi (degrees)
865  // phimax maximum angle in phi (degrees)
866  // rmin minimum radius
867  // rmax maximum radius
868  //
869  //
870  // The number of events generated = ntheta*nphi
871  // run input parameters in macro setup (default="Config.C")
872  //
873  // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
874  //Begin_Html
875  /*
876  <img src="picts/AliRunLego1.gif">
877  */
878  //End_Html
879  //Begin_Html
880  /*
881  <img src="picts/AliRunLego2.gif">
882  */
883  //End_Html
884  //Begin_Html
885  /*
886  <img src="picts/AliRunLego3.gif">
887  */
888  //End_Html
889  //
890 
891 // run the generation and simulation
892 
893  AliCodeTimerAuto("",0)
894 
895  // initialize CDB storage and run number from external environment
896  // (either CDB manager or AliSimulation setters)
897  InitCDB();
898  InitRunNumber();
899  SetCDBLock();
900 
901  if (!gAlice) {
902  AliError("no gAlice object. Restart aliroot and try again.");
903  return kFALSE;
904  }
905  if (gAlice->Modules()->GetEntries() > 0) {
906  AliError("gAlice was already run. Restart aliroot and try again.");
907  return kFALSE;
908  }
909  AliInfo(Form("initializing gAlice with config file %s",
910  fConfigFileName.Data()));
911 
912  // Number of events
913  if (nev == -1) nev = nc1 * nc2;
914 
915  // check if initialisation has been done
916  // If runloader has been initialized, set the number of events per file to nc1 * nc2
917 
918  // Set new generator
919  if (!gener) gener = new AliLegoGenerator();
920  //
921  // Configure Generator
922 
923  gener->SetRadiusRange(rmin, rmax);
924  gener->SetZMax(zmax);
925  gener->SetCoor1Range(nc1, c1min, c1max);
926  gener->SetCoor2Range(nc2, c2min, c2max);
927 
928 
929  //Create Lego object
930  fLego = new AliLego("lego",gener);
931 
932  //__________________________________________________________________________
933 
934  gAlice->Announce();
935 
936  // - cholm - Add this here for consitency
937  // If requested set the mag. field from the GRP entry.
938  // After this the field is loccked and cannot be changed by Config.C
939  if (fUseMagFieldFromGRP) {
940  AliGRPManager grpM;
941  grpM.ReadGRPEntry();
942  grpM.SetMagField();
943  AliInfo("Field is locked now. It cannot be changed in Config.C");
944 
945  }
946 
947  gROOT->LoadMacro(setup);
948  gInterpreter->ProcessLine(gAlice->GetConfigFunction());
949 
950  if(AliCDBManager::Instance()->GetRun() >= 0) {
952  } else {
953  AliWarning("Run number not initialized!!");
954  }
955 
957 
959 
960  TVirtualMC::GetMC()->SetMagField(TGeoGlobalMagField::Instance()->GetField());
961 
962  gAlice->GetMCApp()->Init();
963 
964 
965  //Must be here because some MCs (G4) adds detectors here and not in Config.C
966  gAlice->InitLoaders();
968 
969  //
970  // Save stuff at the beginning of the file to avoid file corruption
972  gAlice->Write();
973 
974  //Save current generator
976  gAlice->GetMCApp()->ResetGenerator(gener);
977  //Prepare MC for Lego Run
978  TVirtualMC::GetMC()->InitLego();
979 
980  //Run Lego Object
981 
982 
984  TVirtualMC::GetMC()->ProcessRun(nev);
985 
986  // End of this run, close files
987  FinishRun();
988  // Restore current generator
989  gAlice->GetMCApp()->ResetGenerator(gen);
990  // Delete Lego Object
991  delete fLego;
992 
993  return kTRUE;
994 }
995 
996 //_____________________________________________________________________________
997 Bool_t AliSimulation::RunTrigger(const char* config, const char* detectors)
998 {
999  // run the trigger
1000 
1001  AliCodeTimerAuto("",0)
1002 
1003  // initialize CDB storage from external environment
1004  // (either CDB manager or AliSimulation setters),
1005  // if not already done in RunSimulation()
1006  InitCDB();
1007 
1008  // Set run number in CDBManager from data
1009  // From this point on the run number must be always loaded from data!
1010  if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1011 
1012  // Set CDB lock: from now on it is forbidden to reset the run number
1013  // or the default storage or to activate any further storage!
1014  SetCDBLock();
1015 
1016  AliRunLoader* runLoader = LoadRun("READ");
1017  if (!runLoader) return kFALSE;
1018  TString trconfiguration = config;
1019 
1020  if (trconfiguration.IsNull()) {
1021  if(!fTriggerConfig.IsNull()) {
1022  trconfiguration = fTriggerConfig;
1023  }
1024  else
1025  AliWarning("No trigger descriptor is specified. Loading the one that is in the CDB.");
1026  }
1027 
1028  runLoader->MakeTree( "GG" );
1029  AliCentralTrigger* aCTP = runLoader->GetTrigger();
1030  // Load Configuration
1031  if (!aCTP->LoadConfiguration( trconfiguration ))
1032  return kFALSE;
1033 
1034  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1035  if (fUseDetectorsFromGRP) {
1036  AliInfo("Will run only for detectors seen in the GRP");
1038  }
1039 
1040  // digits -> trigger
1041  if( !aCTP->RunTrigger( runLoader , detectors ) ) {
1042  if (fStopOnError) {
1043  // delete aCTP;
1044  return kFALSE;
1045  }
1046  }
1047 
1048  delete runLoader;
1049 
1050  return kTRUE;
1051 }
1052 
1053 //_____________________________________________________________________________
1055 {
1056  // Writes the CTP (trigger) DDL raw data
1057  // Details of the format are given in the
1058  // trigger TDR - pages 134 and 135.
1059  AliCTPRawData writer;
1060  //writer.RawData();
1061  writer.RawDataRun2();
1062 
1063  return kTRUE;
1064 }
1065 
1066 //_____________________________________________________________________________
1067 Bool_t AliSimulation::RunSimulation(Int_t nEvents)
1068 {
1069 // run the generation and simulation
1070 
1071  AliCodeTimerAuto("",0)
1072 
1073  // initialize CDB storage and run number from external environment
1074  // (either CDB manager or AliSimulation setters)
1075  AliSysInfo::AddStamp("RunSimulation_Begin");
1076  InitCDB();
1077  AliSysInfo::AddStamp("RunSimulation_InitCDB");
1078  InitRunNumber();
1079 
1080  SetCDBLock();
1081  AliSysInfo::AddStamp("RunSimulation_SetCDBLock");
1082 
1083  if (!gAlice) {
1084  AliError("no gAlice object. Restart aliroot and try again.");
1085  return kFALSE;
1086  }
1087  if (gAlice->Modules()->GetEntries() > 0) {
1088  AliError("gAlice was already run. Restart aliroot and try again.");
1089  return kFALSE;
1090  }
1091 
1092  // Setup monitoring if requested
1094 
1095  AliInfo(Form("initializing gAlice with config file %s",
1096  fConfigFileName.Data()));
1097 
1098  //
1099  // Initialize ALICE Simulation run
1100  //
1101  gAlice->Announce();
1102 
1103  //
1104  // If requested set the mag. field from the GRP entry.
1105  // After this the field is loccked and cannot be changed by Config.C
1106  if (fUseMagFieldFromGRP) {
1107  AliGRPManager grpM;
1108  grpM.ReadGRPEntry();
1109  grpM.SetMagField();
1110  AliInfo("Field is locked now. It cannot be changed in Config.C");
1111  }
1112 //
1113 // Execute Config.C
1114  TInterpreter::EErrorCode interpreterError=TInterpreter::kNoError;
1115  gROOT->LoadMacro(fConfigFileName.Data());
1116  Long_t interpreterResult=gInterpreter->ProcessLine(gAlice->GetConfigFunction(), &interpreterError);
1117  if (interpreterResult!=0 || interpreterError!=TInterpreter::kNoError) {
1118  AliFatal(Form("execution of config file \"%s\" failed with error %d", fConfigFileName.Data(), (int)interpreterError));
1119  }
1120  AliSysInfo::AddStamp("RunSimulation_Config");
1121 
1122  //
1123  // If requested obtain the vertex position and vertex sigma_z from the CDB
1124  // This overwrites the settings from the Config.C
1125  if (fUseVertexFromCDB) {
1126  Double_t vtxPos[3] = {0., 0., 0.};
1127  Double_t vtxSig[3] = {0., 0., 0.};
1128  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1129  if (entry) {
1130  AliESDVertex* vertex = dynamic_cast<AliESDVertex*> (entry->GetObject());
1131  Bool_t useSigmaxy=kTRUE;
1132  if (vertex) {
1133  if(vertex->GetXRes()>2.8) { // > pipe radius --> it's a dummy object, don't use it
1134  useSigmaxy=kFALSE;
1135  entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1136  if (entry) vertex = dynamic_cast<AliESDVertex*> (entry->GetObject());
1137  }
1138  }
1139  if (vertex) {
1140  vertex->GetXYZ(vtxPos);
1141  vertex->GetSigmaXYZ(vtxSig);
1142  AliInfo("Overwriting Config.C vertex settings !");
1143  TString usedCDBobj=(entry->GetId()).GetPath();
1144  AliInfo(Form("Vertex mean position from OCDB entry (%s): x = %13.3f, y = %13.3f, z = %13.3f", usedCDBobj.Data(), vtxPos[0], vtxPos[1], vtxPos[2]));
1146  gen->SetOrigin(vtxPos[0], vtxPos[1], vtxPos[2]); // vertex position
1147  if(useSigmaxy){
1148  vtxSig[0]*=0.9; // remove 10% tolerance
1149  vtxSig[1]*=0.9; // remove 10% tolerance
1150  AliInfo(Form("Vertex spread from OCDB entry: sigmax = %13.6f, sigmay = %13.6f, sigmaz = %13.3f",vtxSig[0], vtxSig[1], vtxSig[2]));
1151  gen->SetSigma(vtxSig[0], vtxSig[1], vtxSig[2]);
1152  }else{
1153  AliInfo(Form("Vertex spread from OCDB entry only for z: sigmaz = %13.3f", vtxSig[2]));
1154  gen->SetSigmaZ(vtxSig[2]);
1155  }
1156  }
1157  }
1158  }
1159 
1160  // If requested we take the SOR and EOR time-stamps from the GRP and use them
1161  // in order to generate the event time-stamps
1162  if (fUseTimeStampFromCDB>0) {
1163  AliGRPManager grpM;
1164  grpM.ReadGRPEntry();
1165  const AliGRPObject *grpObj = grpM.GetGRPData();
1166  if (!grpObj || (grpObj->GetTimeEnd() <= grpObj->GetTimeStart())) {
1167  AliFatal("Missing GRP or bad SOR/EOR time-stamps! Switching off the time-stamp generation from GRP!");
1168  fTimeStart = fTimeEnd = 0;
1170  }
1171  else {
1172  fTimeStart = grpObj->GetTimeStart();
1173  fTimeEnd = grpObj->GetTimeEnd();
1174  }
1175  time_t deltaT = fTimeEnd - fTimeStart;
1176  if (deltaT>0) {
1177  fOrderedTimeStamps.resize(fNEvents);
1178  if (fLumiDecayH>0) {
1179  double tau = fLumiDecayH*3600.;
1180  double wt = 1.-TMath::Exp(-double(deltaT)/tau);
1181  for (int i=0;i<fNEvents;i++) {
1182  double w = wt*gRandom->Rndm();
1183  time_t t = fTimeStart - tau*TMath::Log(1-w);
1184  fOrderedTimeStamps[i] = t;
1185  }
1186  AliInfoF("Ordered %d TimeStamps will be generated between %ld:%ld with decay tau=%.2f h",
1187  fNEvents,fTimeStart,fTimeEnd,fLumiDecayH);
1188  }
1189  else { // generate according to real lumi
1190  TGraph* lumi = AliLumiTools::GetLumiFromCTP();
1191  if (!lumi) AliFatal("Failed to get lumi graph");
1192  // redefine time stamps according to real luminosity start - end
1193  int nbl = lumi->GetN();
1194  if (nbl) {
1195  fTimeStart = lumi->GetX()[0];
1196  fTimeEnd = lumi->GetX()[nbl-1];
1197  deltaT = fTimeEnd - fTimeStart;
1198  }
1199  int nb = 1+deltaT/60.;
1200  TH1F hlumi("hlumi","",nb,fTimeStart,fTimeEnd);
1201  for (int ib=1;ib<=nb;ib++) hlumi.SetBinContent(ib,TMath::Max(0.,lumi->Eval(hlumi.GetBinCenter(ib))));
1202  delete lumi;
1203  for (int i=0;i<fNEvents;i++) fOrderedTimeStamps[i] = time_t(hlumi.GetRandom());
1204  AliInfoF("Ordered %d TimeStamps will be generated between %ld:%ld according to CTP Lumi profile",
1205  fNEvents,fTimeStart,fTimeEnd);
1206  }
1207  std::sort(fOrderedTimeStamps.begin(), fOrderedTimeStamps.end());
1208  //
1209  }
1210  else AliInfoF("Random TimeStamps will be generated between %ld:%ld",fTimeStart,fTimeEnd);
1211  }
1212  else AliInfo("Generated events TimeStamps will be set to 0");
1213 
1214  if(AliCDBManager::Instance()->GetRun() >= 0) {
1217  } else {
1218  AliWarning("Run number not initialized!!");
1219  }
1220 
1222 
1223 
1225 
1226  TVirtualMC::GetMC()->SetMagField(TGeoGlobalMagField::Instance()->GetField());
1227  AliSysInfo::AddStamp("RunSimulation_GetField");
1228  gAlice->GetMCApp()->Init();
1229  AliSysInfo::AddStamp("RunSimulation_InitMCApp");
1230 
1231  //Must be here because some MCs (G4) adds detectors here and not in Config.C
1232  gAlice->InitLoaders();
1234  AliRunLoader::Instance()->LoadKinematics("RECREATE");
1235  AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
1236  AliRunLoader::Instance()->LoadHits("all","RECREATE");
1237  //
1238  // Save stuff at the beginning of the file to avoid file corruption
1240  gAlice->Write();
1241  gAlice->SetEventNrInRun(-1); //important - we start Begin event from increasing current number in run
1242  AliSysInfo::AddStamp("RunSimulation_InitLoaders");
1243  //___________________________________________________________________________________________
1244 
1245  AliSysInfo::AddStamp("RunSimulation_TriggerDescriptor");
1246 
1247  // Set run number in CDBManager
1248  AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
1249 
1250  AliRunLoader* runLoader = AliRunLoader::Instance();
1251  if (!runLoader) {
1252  AliError(Form("gAlice has no run loader object. "
1253  "Check your config file: %s", fConfigFileName.Data()));
1254  return kFALSE;
1255  }
1256  SetGAliceFile(runLoader->GetFileName());
1257 
1258  // Misalign geometry
1259 #if ROOT_VERSION_CODE < 331527
1261 
1262  // Check that the consistency of symbolic names for the activated subdetectors
1263  // in the geometry loaded by AliGeomManager
1264  TString detsToBeChecked = "";
1265  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1266  //
1267  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1268  AliModule* det = (AliModule*) detArray->At(iDet);
1269  if (!det || !det->IsActive()) continue;
1270  detsToBeChecked += det->GetName();
1271  detsToBeChecked += " ";
1272  } // end loop over detectors
1273  if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
1274  AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
1275  MisalignGeometry(runLoader);
1276  AliSysInfo::AddStamp("RunSimulation_MisalignGeometry");
1277 #endif
1278 
1279 // AliRunLoader* runLoader = AliRunLoader::Instance();
1280 // if (!runLoader) {
1281 // AliError(Form("gAlice has no run loader object. "
1282 // "Check your config file: %s", fConfigFileName.Data()));
1283 // return kFALSE;
1284 // }
1285 // SetGAliceFile(runLoader->GetFileName());
1286 
1287 
1288  if (!gAlice->GetMCApp()->Generator()) {
1289  AliError(Form("gAlice has no generator object. "
1290  "Check your config file: %s", fConfigFileName.Data()));
1291  return kFALSE;
1292  }
1293 
1294  // Write GRP entry corresponding to the setting found in Cofig.C
1295  if (fWriteGRPEntry)
1296  WriteGRPEntry();
1297  AliSysInfo::AddStamp("RunSimulation_WriteGRP");
1298 
1299  if (nEvents <= 0) nEvents = fNEvents;
1300 
1301  // get vertex from background file in case of merging
1302  if (fUseBkgrdVertex &&
1303  fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
1304  Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
1305  const char* fileName = ((TObjString*)
1306  (fBkgrdFileNames->At(0)))->GetName();
1307  AliInfo(Form("The vertex will be taken from the background "
1308  "file %s with nSignalPerBackground = %d",
1309  fileName, signalPerBkgrd));
1310  AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
1312  fUseTimeStampFromCDB = -1;
1313  AliInfo("TimeStamp generation is overriden: will be taken from background event");
1314  gAlice->SetSgPerBgEmbedded(signalPerBkgrd);
1315  }
1316 
1317  if (!fRunSimulation) {
1319  }
1320 
1321  // set the number of events per file for given detectors and data types
1322  for (Int_t i = 0; i < fEventsPerFile.GetEntriesFast(); i++) {
1323  if (!fEventsPerFile[i]) continue;
1324  const char* detName = fEventsPerFile[i]->GetName();
1325  const char* typeName = fEventsPerFile[i]->GetTitle();
1326  TString loaderName(detName);
1327  loaderName += "Loader";
1328  AliLoader* loader = runLoader->GetLoader(loaderName);
1329  if (!loader) {
1330  AliError(Form("RunSimulation no loader for %s found\n Number of events per file not set for %s %s",
1331  detName, typeName, detName));
1332  continue;
1333  }
1334  AliDataLoader* dataLoader =
1335  loader->GetDataLoader(typeName);
1336  if (!dataLoader) {
1337  AliError(Form("no data loader for %s found\n"
1338  "Number of events per file not set for %s %s",
1339  typeName, detName, typeName));
1340  continue;
1341  }
1342  dataLoader->SetNumberOfEventsPerFile(fEventsPerFile[i]->GetUniqueID());
1343  AliDebug(1, Form("number of events per file set to %d for %s %s",
1344  fEventsPerFile[i]->GetUniqueID(), detName, typeName));
1345  }
1346 
1347  AliInfo("running gAlice");
1348  AliSysInfo::AddStamp("Start_ProcessRun");
1349 
1350 
1351 
1352  if (fUseDetectorsFromGRP) {
1353  TObjArray* detArr = runLoader->GetAliRun()->Detectors();
1354  AliInfo("Will run only for detectors seen in the GRP");
1356  }
1357  //
1358 
1359 
1360  // Create the Root Tree with one branch per detector
1361  //Hits moved to begin event -> now we are crating separate tree for each event
1362  TVirtualMC::GetMC()->ProcessRun(nEvents);
1363 
1364  // End of this run, close files
1365  if(nEvents>0) FinishRun();
1366 
1367  AliSysInfo::AddStamp("Stop_ProcessRun");
1368  delete runLoader;
1369 
1370  return kTRUE;
1371 }
1372 
1373 //_____________________________________________________________________________
1375 {
1376  // Execute Config.C
1377  InitCDB();
1378  InitRunNumber();
1379  if (fUseMagFieldFromGRP) {
1380  AliGRPManager grpM;
1381  grpM.ReadGRPEntry();
1382  grpM.SetMagField();
1383  AliInfo("Field is locked now. It cannot be changed in Config.C");
1384  }
1385 
1386  TInterpreter::EErrorCode interpreterError=TInterpreter::kNoError;
1387  gROOT->LoadMacro(fConfigFileName.Data());
1388  Long_t interpreterResult=gInterpreter->ProcessLine(gAlice->GetConfigFunction(), &interpreterError);
1389  if (interpreterResult!=0 || interpreterError!=TInterpreter::kNoError) {
1390  AliFatal(Form("execution of config file \"%s\" failed with error %d", fConfigFileName.Data(), (int)interpreterError));
1391  }
1392 
1393  // Setup the runloader and generator, check if everything is OK
1394  AliRunLoader* runLoader = AliRunLoader::Instance();
1395  AliGenerator* generator = gAlice->GetMCApp()->Generator();
1396  if (!runLoader) {
1397  AliError(Form("gAlice has no run loader object. "
1398  "Check your config file: %s", fConfigFileName.Data()));
1399  return kFALSE;
1400  }
1401  if (!generator) {
1402  AliError(Form("gAlice has no generator object. "
1403  "Check your config file: %s", fConfigFileName.Data()));
1404  return kFALSE;
1405  }
1406 
1407  runLoader->LoadKinematics("RECREATE");
1408  runLoader->MakeTree("E");
1409 
1410  // Create stack and header
1411  runLoader->MakeStack();
1412  AliStack* stack = runLoader->Stack();
1413  AliHeader* header = runLoader->GetHeader();
1414 
1415  // Intialize generator
1416  generator->Init();
1417  generator->SetStack(stack);
1418 
1419  // Run main generator loop
1420 
1421  for (Int_t iev=0; iev<fNEvents; iev++)
1422  {
1423  // Initialize event
1424  header->Reset(0,iev);
1425  runLoader->SetEventNumber(iev);
1426  stack->Reset();
1427  runLoader->MakeTree("K");
1428 
1429  // Generate event
1430  generator->Generate();
1431 
1432  // Finish event
1433  header->SetNprimary(stack->GetNprimary());
1434  header->SetNtrack(stack->GetNtrack());
1435  stack->FinishEvent();
1436  header->SetStack(stack);
1437  runLoader->TreeE()->Fill();
1438  runLoader->WriteKinematics("OVERWRITE");
1439  }
1440 
1441  // Finalize
1442  generator->FinishRun();
1443  // Write file
1444  runLoader->WriteHeader("OVERWRITE");
1445  generator->Write();
1446  runLoader->Write();
1447 
1448  return kTRUE;
1449 }
1450 
1451 //_____________________________________________________________________________
1452 Bool_t AliSimulation::RunSDigitization(const char* detectors)
1453 {
1454 // run the digitization and produce summable digits
1455  static Int_t eventNr=0;
1456  AliCodeTimerAuto("",0) ;
1457 
1458  // initialize CDB storage, run number, set CDB lock
1459  InitCDB();
1460  if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1461  SetCDBLock();
1462 
1463  AliRunLoader* runLoader = LoadRun();
1464  if (!runLoader) return kFALSE;
1465  //
1466  TString detStr = detectors;
1467  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1468  //
1469  if (fUseDetectorsFromGRP) {
1470  AliInfo("Will run only for detectors seen in the GRP");
1471  DeactivateDetectorsAbsentInGRP(detArray);
1472  }
1473  //
1474  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1475  AliModule* det = (AliModule*) detArray->At(iDet);
1476  if (!det || !det->IsActive()) continue;
1477  if (IsSelected(det->GetName(), detStr)) {
1478  AliInfo(Form("creating summable digits for %s", det->GetName()));
1479  AliCodeTimerStart(Form("creating summable digits for %s", det->GetName()));
1480  det->Hits2SDigits();
1481  AliCodeTimerStop(Form("creating summable digits for %s", det->GetName()));
1482  AliSysInfo::AddStamp(Form("SDigit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
1483  }
1484  }
1485 
1486  if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1487  AliError(Form("the following detectors were not found: %s",
1488  detStr.Data()));
1489  if (fStopOnError) return kFALSE;
1490  }
1491  eventNr++;
1492  delete runLoader;
1493 
1494  return kTRUE;
1495 }
1496 
1497 
1498 //_____________________________________________________________________________
1499 Bool_t AliSimulation::RunDigitization(const char* detectors,
1500  const char* excludeDetectors)
1501 {
1502 // run the digitization and produce digits from sdigits
1503  AliCodeTimerAuto("",0)
1504 
1505  // initialize CDB storage, run number, set CDB lock
1506  InitCDB();
1507  if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1508  SetCDBLock();
1509 
1510  delete AliRunLoader::Instance();
1511  delete gAlice;
1512  gAlice = NULL;
1513 
1514  Int_t nStreams = 1;
1515  if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
1516  Int_t signalPerBkgrd = GetNSignalPerBkgrd();
1517  AliDigitizationInput digInp(nStreams, signalPerBkgrd);
1518  // digInp.SetEmbeddingFlag(fEmbeddingFlag);
1520  digInp.SetInputStream(0, fGAliceFileName.Data());
1521  for (Int_t iStream = 1; iStream < nStreams; iStream++) {
1522  const char* fileName = ((TObjString*)(fBkgrdFileNames->At(iStream-1)))->GetName();
1523  digInp.SetInputStream(iStream, fileName);
1524  }
1525  TObjArray detArr;
1526  detArr.SetOwner(kTRUE);
1527  TString detStr = detectors;
1528  TString detExcl = excludeDetectors;
1529  if (!static_cast<AliStream*>(digInp.GetInputStream(0))->ImportgAlice()) {
1530  AliError("Error occured while getting gAlice from Input 0");
1531  return kFALSE;
1532  }
1534  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1535  //
1536  if (fUseDetectorsFromGRP) {
1537  AliInfo("Will run only for detectors seen in the GRP");
1538  DeactivateDetectorsAbsentInGRP(detArray);
1539  }
1540  //
1541  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1542  AliModule* det = (AliModule*) detArray->At(iDet);
1543  if (!det || !det->IsActive()) continue;
1544  if (!IsSelected(det->GetName(), detStr) || IsSelected(det->GetName(), detExcl)) continue;
1545  AliDigitizer* digitizer = det->CreateDigitizer(&digInp);
1546  if (!digitizer || !digitizer->Init()) {
1547  AliError(Form("no digitizer for %s", det->GetName()));
1548  if (fStopOnError) return kFALSE;
1549  else continue;
1550  }
1551  detArr.AddLast(digitizer);
1552  AliInfo(Form("Created digitizer from SDigits -> Digits for %s", det->GetName()));
1553 
1554  }
1555  //
1556  if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1557  AliError(Form("the following detectors were not found: %s", detStr.Data()));
1558  if (fStopOnError) return kFALSE;
1559  }
1560  //
1561  Int_t ndigs = detArr.GetEntriesFast();
1562  Int_t eventsCreated = 0;
1563  AliRunLoader* outRl = digInp.GetOutRunLoader();
1564  while ((eventsCreated++ < fNEvents) || (fNEvents < 0)) {
1565  if (!digInp.ConnectInputTrees()) break;
1566  digInp.InitEvent(); //this must be after call of Connect Input tress.
1567  if (outRl) outRl->SetEventNumber(eventsCreated-1);
1568  static_cast<AliStream*>(digInp.GetInputStream(0))->ImportgAlice(); // use gAlice of the first input stream
1569  for (int id=0;id<ndigs;id++) {
1570  ((AliDigitizer*)detArr[id])->Digitize("");
1571  AliSysInfo::AddStamp(Form("Digit_%s_%d",detArr[id]->GetName(),eventsCreated), 0,2, eventsCreated);
1572  }
1573  digInp.FinishEvent();
1574  };
1575  digInp.FinishGlobal();
1576  //
1577  return kTRUE;
1578 }
1579 
1580 //_____________________________________________________________________________
1581 Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
1582 {
1583 // run the digitization and produce digits from hits
1584 
1585  AliCodeTimerAuto("",0)
1586 
1587  // initialize CDB storage, run number, set CDB lock
1588  InitCDB();
1589  if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1590  SetCDBLock();
1591 
1592  AliRunLoader* runLoader = LoadRun("READ");
1593  if (!runLoader) return kFALSE;
1594 
1595  TString detStr = detectors;
1596  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1597  //
1598  if (fUseDetectorsFromGRP) {
1599  AliInfo("Will run only for detectors seen in the GRP");
1600  DeactivateDetectorsAbsentInGRP(detArray);
1601  }
1602  //
1603  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1604  AliModule* det = (AliModule*) detArray->At(iDet);
1605  if (!det || !det->IsActive()) continue;
1606  if (IsSelected(det->GetName(), detStr)) {
1607  AliInfo(Form("creating digits from hits for %s", det->GetName()));
1608  det->Hits2Digits();
1609  }
1610  }
1611 
1612  if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1613  AliError(Form("the following detectors were not found: %s",
1614  detStr.Data()));
1615  if (fStopOnError) return kFALSE;
1616  }
1617 
1618  return kTRUE;
1619 }
1620 
1621 //_____________________________________________________________________________
1622 Bool_t AliSimulation::WriteRawData(const char* detectors,
1623  const char* fileName,
1624  Bool_t deleteIntermediateFiles,
1625  Bool_t selrawdata)
1626 {
1627 // convert the digits to raw data
1628 // First DDL raw data files for the given detectors are created.
1629 // If a file name is given, the DDL files are then converted to a DATE file.
1630 // If deleteIntermediateFiles is true, the DDL raw files are deleted
1631 // afterwards.
1632 // If the file name has the extension ".root", the DATE file is converted
1633 // to a root file.
1634 // If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
1635 // 'selrawdata' flag can be used to enable writing of detectors raw data
1636 // accoring to the trigger cluster.
1637 
1638  AliCodeTimerAuto("",0)
1639  AliSysInfo::AddStamp("WriteRawData_Start");
1640 
1641  TString detStr = detectors;
1642  if (!WriteRawFiles(detStr.Data())) {
1643  if (fStopOnError) return kFALSE;
1644  }
1645  AliSysInfo::AddStamp("WriteRawFiles");
1646 
1647  // run HLT simulation on simulated DDL raw files
1648  // and produce HLT ddl raw files to be included in date/root file
1649  // bugfix 2009-06-26: the decision whether to write HLT raw data
1650  // is taken in RunHLT. Here HLT always needs to be run in order to
1651  // create HLT digits, unless its switched off. This is due to the
1652  // special placement of the HLT between the generation of DDL files
1653  // and conversion to DATE/Root file.
1654  detStr.ReplaceAll("HLT", "");
1655  if (!fRunHLT.IsNull()) {
1656  if (!RunHLT()) {
1657  if (fStopOnError) return kFALSE;
1658  }
1659  }
1660  AliSysInfo::AddStamp("WriteRawData_RunHLT");
1661 
1662  TString dateFileName(fileName);
1663  if (!dateFileName.IsNull()) {
1664  Bool_t rootOutput = dateFileName.EndsWith(".root");
1665  if (rootOutput) dateFileName += ".date";
1666  TString selDateFileName;
1667  if (selrawdata) {
1668  selDateFileName = "selected.";
1669  selDateFileName+= dateFileName;
1670  }
1671  if (!ConvertRawFilesToDate(dateFileName,selDateFileName)) {
1672  if (fStopOnError) return kFALSE;
1673  }
1674  AliSysInfo::AddStamp("ConvertRawFilesToDate");
1675  if (deleteIntermediateFiles) {
1676  AliRunLoader *runLoader = LoadRun("READ");
1677  if (runLoader)
1678  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents();
1679  iEvent++) {
1680  char dir[256];
1681  snprintf(dir, 256, "raw%d", iEvent);
1682  //gSystem->Exec(command);
1684  }
1685  delete runLoader;
1686  }
1687 
1688  if (rootOutput) {
1689  if (!ConvertDateToRoot(dateFileName, fileName)) {
1690  if (fStopOnError) return kFALSE;
1691  }
1692  AliSysInfo::AddStamp("ConvertDateToRoot");
1693  if (deleteIntermediateFiles) {
1694  gSystem->Unlink(dateFileName);
1695  }
1696  if (selrawdata) {
1697  TString selFileName = "selected.";
1698  selFileName += fileName;
1699  if (!ConvertDateToRoot(selDateFileName, selFileName)) {
1700  if (fStopOnError) return kFALSE;
1701  }
1702  if (deleteIntermediateFiles) {
1703  gSystem->Unlink(selDateFileName);
1704  }
1705  }
1706  }
1707  }
1708 
1709  return kTRUE;
1710 }
1711 
1712 //_____________________________________________________________________________
1713 Bool_t AliSimulation::WriteRawFiles(const char* detectors)
1714 {
1715 // convert the digits to raw data DDL files
1716 
1717  AliCodeTimerAuto("",0)
1718 
1719  AliRunLoader* runLoader = LoadRun("READ");
1720  if (!runLoader) return kFALSE;
1721 
1722  // write raw data to DDL files
1723  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1724  AliInfo(Form("processing event %d", iEvent));
1725  runLoader->GetEvent(iEvent);
1726  TString baseDir = gSystem->WorkingDirectory();
1727  char dirName[256];
1728  snprintf(dirName, 256, "raw%d", iEvent);
1729  gSystem->MakeDirectory(dirName);
1730  if (!gSystem->ChangeDirectory(dirName)) {
1731  AliError(Form("couldn't change to directory %s", dirName));
1732  if (fStopOnError) return kFALSE; else continue;
1733  }
1734 
1735  ofstream runNbFile(Form("run%u",runLoader->GetHeader()->GetRun()));
1736  runNbFile.close();
1737 
1738  TString detStr = detectors;
1739  if (IsSelected("HLT", detStr)) {
1740  // Do nothing. "HLT" will be removed from detStr and HLT raw
1741  // data files are generated in RunHLT.
1742  }
1743 
1744  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1745  //
1746  if (fUseDetectorsFromGRP) {
1747  AliInfo("Will run only for detectors seen in the GRP");
1748  DeactivateDetectorsAbsentInGRP(detArray);
1749  }
1750  //
1751  for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1752  AliModule* det = (AliModule*) detArray->At(iDet);
1753  if (!det || !det->IsActive()) continue;
1754  if (IsSelected(det->GetName(), detStr)) {
1755  AliInfo(Form("creating raw data from digits for %s", det->GetName()));
1756  det->Digits2Raw();
1757  }
1758  }
1759 
1760  if (!WriteTriggerRawData())
1761  if (fStopOnError) return kFALSE;
1762 
1763  gSystem->ChangeDirectory(baseDir);
1764  if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1765  AliError(Form("the following detectors were not found: %s",
1766  detStr.Data()));
1767  if (fStopOnError) return kFALSE;
1768  }
1769  }
1770 
1771  delete runLoader;
1772 
1773  return kTRUE;
1774 }
1775 
1776 //_____________________________________________________________________________
1777 Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
1778  const char* selDateFileName)
1779 {
1780 // convert raw data DDL files to a DATE file with the program "dateStream"
1781 // The second argument is not empty when the user decides to write
1782 // the detectors raw data according to the trigger cluster.
1783 
1784  AliCodeTimerAuto("",0)
1785 
1786  char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
1787  if (!path) {
1788  AliError("the program dateStream was not found");
1789  if (fStopOnError) return kFALSE;
1790  } else {
1791  delete[] path;
1792  }
1793 
1794  AliRunLoader* runLoader = LoadRun("READ");
1795  if (!runLoader) return kFALSE;
1796 
1797  AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
1798  Bool_t selrawdata = kFALSE;
1799  if (strcmp(selDateFileName,"") != 0) selrawdata = kTRUE;
1800 
1801  char command[256];
1802  // Note the option -s. It is used in order to avoid
1803  // the generation of SOR/EOR events.
1804  snprintf(command, 256, "dateStream -c -s -D -o %s -# %d -C -run %d",
1805  dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
1806  FILE* pipe = gSystem->OpenPipe(command, "w");
1807 
1808  if (!pipe) {
1809  AliError(Form("Cannot execute command: %s",command));
1810  return kFALSE;
1811  }
1812 
1813  Int_t selEvents = 0;
1814  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1815 
1816  UInt_t detectorPattern = 0;
1817  runLoader->GetEvent(iEvent);
1818  if (!runLoader->LoadTrigger()) {
1819  AliCentralTrigger *aCTP = runLoader->GetTrigger();
1820  detectorPattern = aCTP->GetClusterMask();
1821  // Check if the event was triggered by CTP
1822  if (selrawdata) {
1823  if (aCTP->GetClassMask()) selEvents++;
1824  }
1825  }
1826  else {
1827  AliWarning("No trigger can be loaded! Some fields in the event header will be empty !");
1828  if (selrawdata) {
1829  AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
1830  selrawdata = kFALSE;
1831  }
1832  }
1833 
1834  fprintf(pipe, "GDC DetectorPattern %u Timestamp %ld\n", detectorPattern, runLoader->GetHeader()->GetTimeStamp());
1835  Float_t ldc = 0;
1836  Int_t prevLDC = -1;
1837 
1838  // loop over detectors and DDLs
1839  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1840  for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1841 
1842  Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1843  Int_t ldcID = Int_t(ldc + 0.0001);
1844  ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1845 
1846  char rawFileName[256];
1847  snprintf(rawFileName, 256, "raw%d/%s",
1848  iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1849 
1850  // check existence and size of raw data file
1851  FILE* file = fopen(rawFileName, "rb");
1852  if (!file) continue;
1853  fseek(file, 0, SEEK_END);
1854  unsigned long size = ftell(file);
1855  fclose(file);
1856  if (!size) continue;
1857 
1858  if (ldcID != prevLDC) {
1859  fprintf(pipe, " LDC Id %d\n", ldcID);
1860  prevLDC = ldcID;
1861  }
1862  fprintf(pipe, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1863  }
1864  }
1865  }
1866 
1867  Int_t result = gSystem->ClosePipe(pipe);
1868 
1869  if (!(selrawdata && selEvents > 0)) {
1870  delete runLoader;
1871  return (result == 0);
1872  }
1873 
1874  AliInfo(Form("converting selected by trigger cluster raw data DDL files to DATE file %s", selDateFileName));
1875 
1876  snprintf(command, 256, "dateStream -c -s -D -o %s -# %d -C -run %d",
1877  selDateFileName,selEvents,runLoader->GetHeader()->GetRun());
1878  FILE* pipe2 = gSystem->OpenPipe(command, "w");
1879 
1880  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1881 
1882  // Get the trigger decision and cluster
1883  UInt_t detectorPattern = 0;
1884  TString detClust;
1885  runLoader->GetEvent(iEvent);
1886  if (!runLoader->LoadTrigger()) {
1887  AliCentralTrigger *aCTP = runLoader->GetTrigger();
1888  if (aCTP->GetClassMask() == 0) continue;
1889  detectorPattern = aCTP->GetClusterMask();
1890  detClust = AliDAQ::ListOfTriggeredDetectors(detectorPattern);
1891  AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
1892  }
1893 
1894  fprintf(pipe2, "GDC DetectorPattern %u Timestamp %ld\n", detectorPattern, runLoader->GetHeader()->GetTimeStamp());
1895  Float_t ldc = 0;
1896  Int_t prevLDC = -1;
1897 
1898  // loop over detectors and DDLs
1899  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1900  // Write only raw data from detectors that
1901  // are contained in the trigger cluster(s)
1902  if (!IsSelected(AliDAQ::DetectorName(iDet),detClust)) continue;
1903 
1904  for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1905 
1906  Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1907  Int_t ldcID = Int_t(ldc + 0.0001);
1908  ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1909 
1910  char rawFileName[256];
1911  snprintf(rawFileName, 256, "raw%d/%s",
1912  iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1913 
1914  // check existence and size of raw data file
1915  FILE* file = fopen(rawFileName, "rb");
1916  if (!file) continue;
1917  fseek(file, 0, SEEK_END);
1918  unsigned long size = ftell(file);
1919  fclose(file);
1920  if (!size) continue;
1921 
1922  if (ldcID != prevLDC) {
1923  fprintf(pipe2, " LDC Id %d\n", ldcID);
1924  prevLDC = ldcID;
1925  }
1926  fprintf(pipe2, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1927  }
1928  }
1929  }
1930 
1931  Int_t result2 = gSystem->ClosePipe(pipe2);
1932 
1933  delete runLoader;
1934  return ((result == 0) && (result2 == 0));
1935 }
1936 
1937 //_____________________________________________________________________________
1938 Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
1939  const char* rootFileName)
1940 {
1941 // convert a DATE file to a root file with the program "alimdc"
1942 
1943  // ALIMDC setup
1944  const Int_t kDBSize = 2000000000;
1945  const Int_t kTagDBSize = 1000000000;
1946  const Bool_t kFilter = kFALSE;
1947  const Int_t kCompression = 1;
1948 
1949  char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
1950  if (!path) {
1951  AliError("the program alimdc was not found");
1952  if (fStopOnError) return kFALSE;
1953  } else {
1954  delete[] path;
1955  }
1956 
1957  AliInfo(Form("converting DATE file %s to root file %s",
1958  dateFileName, rootFileName));
1959 
1960  const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
1961  const char* tagDBFS = "/tmp/mdc1/tags";
1962 
1963  // User defined file system locations
1964  if (gSystem->Getenv("ALIMDC_RAWDB1"))
1965  rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
1966  if (gSystem->Getenv("ALIMDC_RAWDB2"))
1967  rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
1968  if (gSystem->Getenv("ALIMDC_TAGDB"))
1969  tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
1970 
1971 
1972  //gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1973  //gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1974  //gSystem->Exec(Form("rm -rf %s",tagDBFS));
1975  AliFileUtilities::Remove_All(rawDBFS[0]);
1976  AliFileUtilities::Remove_All(rawDBFS[1]);
1978 
1979  //gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
1980  //gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
1981  //gSystem->Exec(Form("mkdir %s",tagDBFS));
1982  gSystem->MakeDirectory(rawDBFS[0]);
1983  gSystem->MakeDirectory(rawDBFS[1]);
1984  gSystem->MakeDirectory(tagDBFS);
1985 
1986  Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s",
1987  kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
1988  gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
1989 
1990 // gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1991 // gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1992 // gSystem->Exec(Form("rm -rf %s",tagDBFS));
1993  AliFileUtilities::Remove_All(rawDBFS[0]);
1994  AliFileUtilities::Remove_All(rawDBFS[1]);
1996 
1997  return (result == 0);
1998 }
1999 
2000 
2001 //_____________________________________________________________________________
2002 AliRunLoader* AliSimulation::LoadRun(const char* mode) const
2003 {
2004 // delete existing run loaders, open a new one and load gAlice
2005 
2006  delete AliRunLoader::Instance();
2007  AliRunLoader* runLoader =
2010  if (!runLoader) {
2011  AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2012  return NULL;
2013  }
2014  runLoader->LoadgAlice();
2015  runLoader->LoadHeader();
2016  gAlice = runLoader->GetAliRun();
2017  if (!gAlice) {
2018  AliError(Form("no gAlice object found in file %s",
2019  fGAliceFileName.Data()));
2020  return NULL;
2021  }
2022  return runLoader;
2023 }
2024 
2025 //_____________________________________________________________________________
2026 Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
2027 {
2028 // get or calculate the number of signal events per background event
2029 
2030  if (!fBkgrdFileNames) return 1;
2031  Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
2032  if (nBkgrdFiles == 0) return 1;
2033 
2034  // get the number of signal events
2035  if (nEvents <= 0) {
2036  AliRunLoader* runLoader =
2037  AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
2038  if (!runLoader) return 1;
2039 
2040  nEvents = runLoader->GetNumberOfEvents();
2041  delete runLoader;
2042  }
2043 
2044  Int_t result = 0;
2045  for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
2046  // get the number of background events
2047  const char* fileName = ((TObjString*)
2048  (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
2049  AliRunLoader* runLoader =
2050  AliRunLoader::Open(fileName, "BKGRD");
2051  if (!runLoader) continue;
2052  Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
2053  delete runLoader;
2054 
2055  // get or calculate the number of signal per background events
2056  Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
2057  if (nSignalPerBkgrd <= 0) {
2058  nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
2059  } else if (result && (result != nSignalPerBkgrd)) {
2060  AliInfo(Form("the number of signal events per background event "
2061  "will be changed from %d to %d for stream %d",
2062  nSignalPerBkgrd, result, iBkgrdFile+1));
2063  nSignalPerBkgrd = result;
2064  }
2065 
2066  if (!result) result = nSignalPerBkgrd;
2067  if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
2068  AliWarning(Form("not enough background events (%d) for %d signal events "
2069  "using %d signal per background events for stream %d",
2070  nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1));
2071  }
2072  }
2073 
2074  return result;
2075 }
2076 
2077 //_____________________________________________________________________________
2078 Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
2079 {
2080 // check whether detName is contained in detectors
2081 // if yes, it is removed from detectors
2082 
2083  // check if all detectors are selected
2084  if ((detectors.CompareTo("ALL") == 0) ||
2085  detectors.BeginsWith("ALL ") ||
2086  detectors.EndsWith(" ALL") ||
2087  detectors.Contains(" ALL ")) {
2088  detectors = "ALL";
2089  return kTRUE;
2090  }
2091 
2092  // search for the given detector
2093  Bool_t result = kFALSE;
2094  if ((detectors.CompareTo(detName) == 0) ||
2095  detectors.BeginsWith(detName+" ") ||
2096  detectors.EndsWith(" "+detName) ||
2097  detectors.Contains(" "+detName+" ")) {
2098  detectors.ReplaceAll(detName, "");
2099  result = kTRUE;
2100  }
2101 
2102  // clean up the detectors string
2103  while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2104  while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2105  while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2106 
2107  return result;
2108 }
2109 
2110 //_____________________________________________________________________________
2111 Int_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName, Int_t N, Int_t nSkip)
2112 {
2113 //
2114 // Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
2115 // These can be used for embedding of MC tracks into RAW data using the standard
2116 // merging procedure.
2117 //
2118 // If an ESD file is given the reconstructed vertex is taken from it and stored in the event header.
2119 //
2120  if (!gAlice) {
2121  AliError("no gAlice object. Restart aliroot and try again.");
2122  return kFALSE;
2123  }
2124  if (gAlice->Modules()->GetEntries() > 0) {
2125  AliError("gAlice was already run. Restart aliroot and try again.");
2126  return kFALSE;
2127  }
2128 
2129  AliInfo(Form("initializing gAlice with config file %s",fConfigFileName.Data()));
2130 
2131  gAlice->Announce();
2132 
2133  gROOT->LoadMacro(fConfigFileName.Data());
2134  gInterpreter->ProcessLine(gAlice->GetConfigFunction());
2135 
2136  if(AliCDBManager::Instance()->GetRun() >= 0) {
2138  } else {
2139  AliWarning("Run number not initialized!!");
2140  }
2141 
2143 
2145 
2146  TVirtualMC::GetMC()->SetMagField(TGeoGlobalMagField::Instance()->GetField());
2147 
2148  gAlice->GetMCApp()->Init();
2149 
2150  //Must be here because some MCs (G4) adds detectors here and not in Config.C
2151  gAlice->InitLoaders();
2153  AliRunLoader::Instance()->LoadKinematics("RECREATE");
2154  AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
2155  AliRunLoader::Instance()->LoadHits("all","RECREATE");
2156 
2157  //
2158  // Save stuff at the beginning of the file to avoid file corruption
2160  gAlice->Write();
2161 //
2162 // Initialize CDB
2163  InitCDB();
2164  //AliCDBManager* man = AliCDBManager::Instance();
2165  //man->SetRun(0); // Should this come from rawdata header ?
2166 
2167  Int_t iDet;
2168  //
2169  // Get the runloader
2170  AliRunLoader* runLoader = AliRunLoader::Instance();
2171  //
2172  // Open esd file if available
2173  TFile* esdFile = 0;
2174  TTree* treeESD = 0;
2175  AliESDEvent* esd = 0;
2176  if (esdFileName && (strlen(esdFileName)>0)) {
2177  esdFile = TFile::Open(esdFileName);
2178  if (esdFile) {
2179  esd = new AliESDEvent();
2180  esdFile->GetObject("esdTree", treeESD);
2181  if (treeESD) {
2182  esd->ReadFromTree(treeESD);
2183  if (nSkip>0) {
2184  AliInfo(Form("Asking to skip first %d ESDs events",nSkip));
2185  } else {
2186  nSkip=0;
2187  }
2188  }
2189  }
2190  }
2191 
2192  //
2193  // Create the RawReader
2194  TString fileName(rawDirectory);
2195  AliRawReader* rawReader = AliRawReader::Create(fileName.Data());
2196  if (!rawReader) return (kFALSE);
2197 
2198 // if (!fEquipIdMap.IsNull() && fRawReader)
2199 // fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
2200  //
2201  // Get list of detectors
2202  TObjArray* detArray = runLoader->GetAliRun()->Detectors();
2203  if (fUseDetectorsFromGRP) {
2204  AliInfo("Will run only for detectors seen in the GRP");
2205  DeactivateDetectorsAbsentInGRP(detArray);
2206  }
2207  //
2208  // Get Header
2209  AliHeader* header = runLoader->GetHeader();
2210  // Event loop
2211  Int_t nev = 0;
2212  Int_t prevEsdID = nSkip-1;
2213  while(kTRUE) {
2214  if (!(rawReader->NextEvent())) break;
2215  runLoader->SetEventNumber(nev);
2216  runLoader->GetHeader()->Reset(rawReader->GetRunNumber(),
2217  nev, nev);
2218  runLoader->GetEvent(nev);
2219  AliInfo(Form("We are at event %d",nev));
2220  //
2221  // Detector loop
2222  TString detStr = fMakeSDigits;
2223  for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
2224  AliModule* det = (AliModule*) detArray->At(iDet);
2225  if (!det || !det->IsActive()) continue;
2226  if (IsSelected(det->GetName(), detStr)) {
2227  AliInfo(Form("Calling Raw2SDigits for %s", det->GetName()));
2228  det->Raw2SDigits(rawReader);
2229  rawReader->Reset();
2230  }
2231  } // detectors
2232 
2233 
2234  //
2235  // If ESD information available obtain reconstructed vertex and store in header.
2236  if (treeESD) {
2237  Int_t rawID = rawReader->GetEventIndex();
2238  ULong64_t rawGID = rawReader->GetEventIdAsLong();
2239 
2240  Int_t esdID = nSkip+rawID;
2241  if (esdID > treeESD->GetEntriesFast()) esdID = treeESD->GetEntriesFast();
2242  Bool_t bFound = kFALSE;
2243  while (esdID>prevEsdID) {
2244  treeESD->GetEvent(esdID);
2245  if (ULong64_t(esd->GetHeader()->GetEventIdAsLong()) == rawGID) {
2246  bFound = kTRUE;
2247  prevEsdID = esdID;
2248  break; // found!
2249  }
2250  esdID--;
2251  }
2252  if (!bFound) {
2253  AliInfo("Failed to find event ... skipping");
2254  continue;
2255  }
2256 
2257  AliInfo(Form("Selected event %d correspond to event %d in raw and to %d in esd",nev,rawReader->GetEventIndex(),prevEsdID));
2258  const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
2259  Double_t position[3];
2260  esdVertex->GetXYZ(position);
2261  AliGenEventHeader* mcHeader = new AliGenEventHeader("ESD");
2262  TArrayF mcV;
2263  mcV.Set(3);
2264  for (Int_t i = 0; i < 3; i++) mcV[i] = position[i];
2265  mcHeader->SetPrimaryVertex(mcV);
2266  header->Reset(0,nev);
2267  header->SetGenEventHeader(mcHeader);
2268  AliInfo(Form("***** Saved vertex %f %f %f \n", position[0], position[1], position[2]));
2269  }
2270 //
2271 // Finish the event
2272  runLoader->TreeE()->Fill();
2273  AliInfo(Form("Finished event %d",nev));
2274  nev++;
2275  if (N>0&&nev>=N)
2276  break;
2277  } // events
2278 
2279  delete rawReader;
2280 //
2281 // Finish the run
2282  runLoader->CdGAFile();
2283  runLoader->WriteHeader("OVERWRITE");
2284  runLoader->WriteRunLoader();
2285 
2286  return nev;
2287 }
2288 
2289 //_____________________________________________________________________________
2291 {
2292  //
2293  // Called at the end of the run.
2294  //
2295 
2296  if(IsLegoRun())
2297  {
2298  AliDebug(1, "Finish Lego");
2300  fLego->FinishRun();
2301  }
2302 
2303  // Clean detector information
2304  TIter next(gAlice->Modules());
2305  AliModule *detector;
2306  while((detector = dynamic_cast<AliModule*>(next()))) {
2307  AliDebug(2, Form("%s->FinishRun()", detector->GetName()));
2308  detector->FinishRun();
2309  }
2310 
2311  AliDebug(1, "AliRunLoader::Instance()->WriteHeader(OVERWRITE)");
2312  AliRunLoader::Instance()->WriteHeader("OVERWRITE");
2313 
2314  // Write AliRun info and all detectors parameters
2316  gAlice->Write(0,TObject::kOverwrite);//write AliRun
2317  AliRunLoader::Instance()->Write(0,TObject::kOverwrite);//write RunLoader itself
2318  //
2319  if(gAlice->GetMCApp()) gAlice->GetMCApp()->FinishRun();
2321 }
2322 
2323 //_____________________________________________________________________________
2324 Int_t AliSimulation::GetDetIndex(const char* detector)
2325 {
2326  // return the detector index corresponding to detector
2327  Int_t index = -1 ;
2328  for (index = 0; index < fgkNDetectors ; index++) {
2329  if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2330  break ;
2331  }
2332  return index ;
2333 }
2334 
2335 //_____________________________________________________________________________
2337 {
2338  // Init the HLT simulation.
2339  // The function loads the library and creates the instance of AliHLTSimulation.
2340  // the main reason for the decoupled creation is to set the transient OCDB
2341  // objects before the OCDB is locked
2342 
2343  // load the library dynamically
2344  gSystem->Load(ALIHLTSIMULATION_LIBRARY);
2345 
2346  // check for the library version
2347  // AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
2348  // if (!fctVersion) {
2349  // AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
2350  // return kFALSE;
2351  // }
2352  // if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
2353  // AliWarning(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
2354  // }
2355 
2356  /*
2357  // print compile info
2358  {
2359  const char* date="";
2360  const char* time="";
2361  CompileInfo(date, time);
2362  if (!date) date="unknown";
2363  if (!time) time="unknown";
2364  AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
2365  }
2366  */
2367  /*
2368  // print compile info
2369  typedef void (*CompileInfo)( const char*& date, const char*& time);
2370  CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
2371  if (fctInfo) {
2372  const char* date="";
2373  const char* time="";
2374  (*fctInfo)(date, time);
2375  if (!date) date="unknown";
2376  if (!time) time="unknown";
2377  AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
2378  } else {
2379  AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
2380  }
2381  */
2382 
2383  // create instance of the HLT simulation
2384  if ( (fpHLT=AliHLTSimulationCreateInstance())==NULL) {
2385  AliError("can not create instance of HLT simulation");
2386  return kFALSE;
2387  }
2388  /*
2389  // create instance of the HLT simulation
2390  AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
2391  if (fctCreate==NULL || (fpHLT=(fctCreate()))==NULL) {
2392  AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
2393  return kFALSE;
2394  }
2395  */
2396 
2397  TString specObjects;
2398  for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
2399  if (specObjects.Length()>0) specObjects+=" ";
2400  specObjects+=fSpecCDBUri[i]->GetName();
2401  }
2402 
2403  if (AliHLTSimulationSetup(fpHLT, this, specObjects.Data())<0) {
2404  AliWarning("failed to setup HLT simulation");
2405  }
2406  /*
2407  AliHLTSimulationSetup_t fctSetup=(AliHLTSimulationSetup_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_SETUP));
2408  if (fctSetup==NULL || fctSetup(fpHLT, this, specObjects.Data())<0) {
2409  AliWarning(Form("failed to setup HLT simulation (function %p)", fctSetup));
2410  }
2411  */
2412  return kTRUE;
2413 }
2414 
2415 //_____________________________________________________________________________
2417 {
2418  // Run the HLT simulation
2419  // HLT simulation is implemented in HLT/sim/AliHLTSimulation
2420  // Disabled if fRunHLT is empty, default vaule is "default".
2421  // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
2422  // The default simulation depends on the HLT component libraries and their
2423  // corresponding agents which define components and chains to run. See
2424  // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/
2425  // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/classAliHLTModuleAgent.html
2426  //
2427  // The libraries to be loaded can be specified as an option.
2428  // <pre>
2429  // AliSimulation sim;
2430  // sim.SetRunHLT("libAliHLTSample.so");
2431  // </pre>
2432  // will only load <tt>libAliHLTSample.so</tt>
2433 
2434  // Other available options:
2435  // \li loglevel=<i>level</i> <br>
2436  // logging level for this processing
2437  // \li alilog=off
2438  // disable redirection of log messages to AliLog class
2439  // \li config=<i>macro</i>
2440  // configuration macro
2441  // \li chains=<i>configuration</i>
2442  // comma separated list of configurations to be run during simulation
2443  // \li rawfile=<i>file</i>
2444  // source for the RawReader to be created, the default is <i>./</i> if
2445  // raw data is simulated
2446 
2447  int iResult=0;
2448 
2449  if (!fpHLT && !CreateHLT()) {
2450  return kFALSE;
2451  }
2452  AliHLTSimulation* pHLT=fpHLT;
2453 
2454  AliRunLoader* pRunLoader = LoadRun("READ");
2455  if (!pRunLoader) return kFALSE;
2456 
2457  // initialize CDB storage, run number, set CDB lock
2458  // thats for the case of running HLT simulation without all the other steps
2459  // multiple calls are handled by the function, so we can just call
2460  InitCDB();
2461  if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
2462  SetCDBLock();
2463 
2464  // init the HLT simulation
2465  TString options;
2466  if (fRunHLT.CompareTo("default")!=0) options=fRunHLT;
2467  TString detStr = fWriteRawData;
2468  if (!IsSelected("HLT", detStr)) {
2469  options+=" writerawfiles=";
2470  } else {
2471  options+=" writerawfiles=HLT";
2472  }
2473 
2474  if (!detStr.IsNull() && !options.Contains("rawfile=")) {
2475  // as a matter of fact, HLT will run reconstruction and needs the RawReader
2476  // in order to get detector data. By default, RawReaderFile is used to read
2477  // the already simulated ddl files. Date and Root files from the raw data
2478  // are generated after the HLT simulation.
2479  options+=" rawfile=./";
2480  }
2481 
2482  if ( (iResult=AliHLTSimulationInit(pHLT, pRunLoader, options.Data()))<0) {
2483  AliError(Form("can not init HLT simulation: error %d", iResult));
2484  } else {
2485  // run the HLT simulation
2486  if ((iResult=AliHLTSimulationRun(pHLT, pRunLoader))<0) {
2487  AliError(Form("can not run HLT simulation: error %d", iResult));
2488  }
2489  }
2490 
2491  /*
2492  AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
2493  if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, options.Data())))<0) {
2494  AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
2495  } else {
2496  // run the HLT simulation
2497  AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
2498  if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
2499  AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
2500  }
2501  }
2502  */
2503 
2504  // delete the instance
2505  if (AliHLTSimulationDeleteInstance(pHLT)<0) {
2506  AliError("can not delete instance of HLT simulation");
2507  }
2508  /*
2509  AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
2510  if (fctDelete==NULL || fctDelete(pHLT)<0) {
2511  AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
2512  }
2513  */
2514  pHLT=NULL;
2515 
2516  return iResult>=0?kTRUE:kFALSE;
2517 }
2518 
2519 //_____________________________________________________________________________
2521 {
2522  // run the QA on summable hits, digits or digits
2523 
2524  //if(!gAlice) return kFALSE;
2526 
2527  TString detectorsw("") ;
2528  Bool_t rv = kTRUE ;
2530  detectorsw = AliQAManager::QAManager()->Run(fQADetectors.Data()) ;
2531  if ( detectorsw.IsNull() )
2532  rv = kFALSE ;
2533  return rv ;
2534 }
2535 
2536 //_____________________________________________________________________________
2537 Bool_t AliSimulation::SetRunQA(TString detAndAction)
2538 {
2539  // Allows to run QA for a selected set of detectors
2540  // and a selected set of tasks among HITS, SDIGITS and DIGITS
2541  // all selected detectors run the same selected tasks
2542 
2543  if (!detAndAction.Contains(":")) {
2544  AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2545  fRunQA = kFALSE ;
2546  return kFALSE ;
2547  }
2548  Int_t colon = detAndAction.Index(":") ;
2549  fQADetectors = detAndAction(0, colon) ;
2550  if (fQADetectors.Contains("ALL") ){
2551  TString tmp = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ;
2552  Int_t minus = fQADetectors.Last('-') ;
2553  TString toKeep = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ;
2554  TString toRemove("") ;
2555  while (minus >= 0) {
2556  toRemove = fQADetectors(minus+1, fQADetectors.Length()) ;
2557  toRemove = toRemove.Strip() ;
2558  toKeep.ReplaceAll(toRemove, "") ;
2559  fQADetectors.ReplaceAll(Form("-%s", toRemove.Data()), "") ;
2560  minus = fQADetectors.Last('-') ;
2561  }
2562  fQADetectors = toKeep ;
2563  }
2564  fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
2565  if (fQATasks.Contains("ALL") ) {
2567  } else {
2568  fQATasks.ToUpper() ;
2569  TString tempo("") ;
2570  if ( fQATasks.Contains("HIT") )
2571  tempo = Form("%d ", AliQAv1::kHITS) ;
2572  if ( fQATasks.Contains("SDIGIT") )
2573  tempo += Form("%d ", AliQAv1::kSDIGITS) ;
2574  if ( fQATasks.Contains("DIGIT") )
2575  tempo += Form("%d ", AliQAv1::kDIGITS) ;
2576  fQATasks = tempo ;
2577  if (fQATasks.IsNull()) {
2578  AliInfo("No QA requested\n") ;
2579  fRunQA = kFALSE ;
2580  return kTRUE ;
2581  }
2582  }
2583  TString tempo(fQATasks) ;
2584  tempo.ReplaceAll(Form("%d", AliQAv1::kHITS), AliQAv1::GetTaskName(AliQAv1::kHITS)) ;
2585  tempo.ReplaceAll(Form("%d", AliQAv1::kSDIGITS), AliQAv1::GetTaskName(AliQAv1::kSDIGITS)) ;
2586  tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITS), AliQAv1::GetTaskName(AliQAv1::kDIGITS)) ;
2587  AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2588  fRunQA = kTRUE ;
2591  for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
2593 
2594  return kTRUE;
2595 }
2596 
2597 //_____________________________________________________________________________
2599 {
2600 // Extract run number and random generator seed from env variables
2601 
2602  AliInfo("Processing environment variables");
2603 
2604  // Random Number seed
2605 
2606  // first check that seed is not already set
2607  if (fSeed == 0) {
2608  if (gSystem->Getenv("CONFIG_SEED")) {
2609  fSeed = atoi(gSystem->Getenv("CONFIG_SEED"));
2610  }
2611  } else {
2612  if (gSystem->Getenv("CONFIG_SEED")) {
2613  AliInfo(Form("Seed for random number generation already set (%d)"
2614  ": CONFIG_SEED variable ignored!", fSeed));
2615  }
2616  }
2617 
2618  AliInfo(Form("Seed for random number generation = %d ", fSeed));
2619 
2620  // Run Number
2621 
2622  // first check that run number is not already set
2623  if(fRun < 0) {
2624  if (gSystem->Getenv("DC_RUN")) {
2625  fRun = atoi(gSystem->Getenv("DC_RUN"));
2626  }
2627  } else {
2628  if (gSystem->Getenv("DC_RUN")) {
2629  AliInfo(Form("Run number already set (%d): DC_RUN variable ignored!", fRun));
2630  }
2631  }
2632 
2633  AliInfo(Form("Run number = %d", fRun));
2634 }
2635 
2636 //---------------------------------------------------------------------
2638 {
2639  // Get the necessary information from galice (generator, trigger etc) and
2640  // write a GRP entry corresponding to the settings in the Config.C used
2641  // note that Hall probes and Cavern and Surface Atmos pressures are not simulated.
2642 
2643 
2644  AliInfo("Writing global run parameters entry into the OCDB");
2645 
2646  AliGRPObject* grpObj = new AliGRPObject();
2647 
2648  grpObj->SetRunType("PHYSICS");
2649  grpObj->SetTimeStart(fTimeStart);
2650  grpObj->SetTimeEnd(fTimeEnd);
2651  grpObj->SetBeamEnergyIsSqrtSHalfGeV(); // new format of GRP: store sqrt(s)/2 in GeV
2652 
2653  const AliGenerator *gen = gAlice->GetMCApp()->Generator();
2654  Int_t a = 0;
2655  Int_t z = 0;
2656 
2657  if (gen) {
2658  TString projectile;
2659  gen->GetProjectile(projectile,a,z);
2660  TString target;
2661  gen->GetTarget(target,a,z);
2662  TString beamType = projectile + "-" + target;
2663  beamType.ReplaceAll(" ","");
2664  if (!beamType.CompareTo("-")) {
2665  grpObj->SetBeamType("UNKNOWN");
2666  grpObj->SetBeamEnergy(gen->GetEnergyCMS()/2);
2667  }
2668  else {
2669  grpObj->SetBeamType(beamType);
2670  if (z != 0) {
2671  grpObj->SetBeamEnergy(gen->GetEnergyCMS()/2 * a / z);
2672  } else {
2673  grpObj->SetBeamEnergy(gen->GetEnergyCMS()/2 );
2674  }
2675  // Heavy ion run, the event specie is set to kHighMult
2677  if ((strcmp(beamType,"p-p") == 0) ||
2678  (strcmp(beamType,"p-") == 0) ||
2679  (strcmp(beamType,"-p") == 0) ||
2680  (strcmp(beamType,"P-P") == 0) ||
2681  (strcmp(beamType,"P-") == 0) ||
2682  (strcmp(beamType,"-P") == 0)) {
2683  // Proton run, the event specie is set to kLowMult
2685  }
2686  }
2687  } else {
2688  AliWarning("Unknown beam type and energy! Setting energy to 0");
2689  grpObj->SetBeamEnergy(0);
2690  grpObj->SetBeamType("UNKNOWN");
2691  }
2692 
2693  UInt_t detectorPattern = 0;
2694  Int_t nDets = 0;
2695  TObjArray *detArray = gAlice->Detectors();
2696  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors-1; iDet++) {
2697  if (detArray->FindObject(AliDAQ::OfflineModuleName(iDet))) {
2698  AliDebug(1, Form("Detector #%d found: %s", iDet, AliDAQ::OfflineModuleName(iDet)));
2699  detectorPattern |= (1 << iDet);
2700  nDets++;
2701  }
2702  }
2703  // CTP
2704  if (!fTriggerConfig.IsNull())
2705  detectorPattern |= (1 << AliDAQ::DetectorID("TRG"));
2706 
2707  // HLT
2708  if (!fRunHLT.IsNull())
2709  detectorPattern |= (1 << AliDAQ::kHLTId);
2710 
2711  grpObj->SetNumberOfDetectors((Char_t)nDets);
2712  grpObj->SetDetectorMask((Int_t)detectorPattern);
2713  grpObj->SetLHCPeriod("LHC08c");
2714  grpObj->SetLHCState("STABLE_BEAMS");
2715  //
2716  AliMagF *field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
2717  Float_t solenoidField = field ? TMath::Abs(field->SolenoidField()) : 0;
2718 
2719  Float_t factorSol = field ? field->GetFactorSol() : 0;
2720  Float_t currentSol = TMath::Abs(factorSol)>1E-6 ?
2721  TMath::Nint(TMath::Abs(solenoidField/factorSol))/5.*30000.*TMath::Abs(factorSol) : 0;
2722  //
2723  Float_t factorDip = field ? field->GetFactorDip() : 0;
2724  Float_t currentDip = 6000.*TMath::Abs(factorDip);
2725  //
2726  grpObj->SetL3Current(currentSol,(AliGRPObject::Stats)0);
2727  grpObj->SetDipoleCurrent(currentDip,(AliGRPObject::Stats)0);
2728  grpObj->SetL3Polarity(factorSol>0 ? 0:1);
2729  grpObj->SetDipolePolarity(factorDip>0 ? 0:1);
2730  if (field) grpObj->SetUniformBMap(field->IsUniform()); // for special MC with k5kGUniform map
2731  grpObj->SetPolarityConventionLHC(); // LHC convention +/+ current -> -/- field main components
2732  //
2734 
2735  //grpMap->Add(new TObjString("fCavernPressure"),new TObjString("0")); ---> not inserted in simulation with the new object, since it is now an AliDCSSensor
2736 
2737  // Now store the entry in OCDB
2739 
2740  man->SetLock(0, fKey);
2741 
2742  AliCDBStorage* sto = man->GetStorage(fGRPWriteLocation.Data());
2743 
2744 
2745  AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun(), 1, 1);
2746  AliCDBMetaData *metadata= new AliCDBMetaData();
2747 
2748  metadata->SetResponsible("alice-off@cern.ch");
2749  metadata->SetComment("Automatically produced GRP entry for Monte Carlo");
2750 
2751  sto->Put(grpObj,id,metadata);
2752  man->SetLock(1, fKey);
2753 }
2754 
2755 //_____________________________________________________________________________
2757 {
2758  // Generate event time-stamp according to
2759  // 1) SOR/EOR time from GRP if fUseTimeStampFromCDB>0
2760  // 2) set it to 0 if fUseTimeStampFromCDB = 0
2761  // 3) in special mode of embedding take it from underlaying event fUseTimeStampFromCDB<0
2762 
2763  static int counter=0;
2764  if (fUseTimeStampFromCDB==0) return 0;
2765  //
2766  if (fUseTimeStampFromCDB>0)
2767  if (fOrderedTimeStamps.size()) {
2768  if (counter>=fOrderedTimeStamps.size()) counter = 0; // in case of overflow, restart
2769  return fOrderedTimeStamps[counter++];
2770  }
2771  else return fTimeStart + gRandom->Integer(fTimeEnd-fTimeStart);
2772  else { // special mode of embedded event, take if from the AliVertexGenFile header
2774  if (!vtxGen) AliFatal("Failed to fetch AliVertexGenFile generator for timeStamp extraction");
2775  return vtxGen->GetHeaderTimeStamp();
2776  }
2777 }
2778 
2779 //_____________________________________________________________________________
2781 {
2782  // write in galice.root maps with used CDB paths
2783  //
2784  //
2785  AliRunLoader* runLoader = LoadRun();
2786  if (!runLoader) {
2787  AliError("Failed to open gAlice.root in write mode");
2788  return;
2789  }
2790  //
2791  TMap *cdbMapCopy = new TMap();
2792  cdbMapCopy->SetName("cdbMap");
2793  TList *cdbListCopy = new TList();
2794  cdbListCopy->SetName("cdbList");
2795  // create map/list accounting for eventual snapshot
2796  AliCDBManager::Instance()->CreateMapListCopy(*cdbMapCopy,*cdbListCopy);
2797  //
2799  gDirectory->WriteObject(cdbMapCopy,"cdbMap","kSingleKey");
2800  gDirectory->WriteObject(cdbListCopy,"cdbList","kSingleKey");
2801 
2802  // store embedding info
2803  if (fBkgrdFileNames) {
2804  TString str(gSystem->Getenv("OVERRIDE_BKG_PATH_RECORD"));
2805  if (!str.IsNull()) {
2806  TObjArray arrTmp;
2807  arrTmp.AddLast( new TObjString(str.Data()) );
2808  arrTmp.SetOwner(kTRUE);
2809  AliInfoF("Overriding background path to: %s",str.Data());
2810  gDirectory->WriteObject(&arrTmp,AliStack::GetEmbeddingBKGPathsKey(),"kSingleKey");
2811  }
2812  else {
2813  gDirectory->WriteObject(fBkgrdFileNames,AliStack::GetEmbeddingBKGPathsKey(),"kSingleKey");
2814  }
2815  }
2816 
2817  delete runLoader;
2818  //
2819  AliInfo(Form("Stored used OCDB entries as TMap %s and TList %s in %s",
2820  cdbMapCopy->GetName(),
2821  cdbListCopy->GetName(),
2822  fGAliceFileName.Data()));
2823  //
2824 }
2825 
2826 //_____________________________________________________________________________
2828 {
2829  // avoid simulating detectors not fount in GRP
2830  AliGRPManager grpm;
2831  grpm.ReadGRPEntry();
2832  const AliGRPObject* grpData = grpm.GetGRPData();
2833  Int_t activeDetectors = grpData->GetDetectorMask();
2834  TString detStrGRP = AliDAQ::ListOfTriggeredDetectors(activeDetectors);
2835  for (int idt=detArr->GetEntriesFast();idt--;) {
2836  AliModule* det = (AliModule*)detArr->At(idt);
2837  if (!det || !det->IsActive()) continue;
2838  if (!detStrGRP.Contains(det->GetName())) {
2839  AliInfoF("Detector %s is not in GRP, disabling",det->GetName());
2840  det->SetActive(kFALSE);
2841  }
2842  }
2843 }
2844 
2845 //_____________________________________________________________________________
2846 void AliSimulation::UseTimeStampFromCDB(Double_t decayTimeHours)
2847 {
2848  // Request event time stamp generated within GRP start/end
2849  // If decayTimeHours>0, then exponential decay is generated, otherwhise, generated according to lumi from CTP
2851  fLumiDecayH = decayTimeHours;
2852 }
void SetStack(AliStack *stack)
Definition: AliGenerator.h:93
int AliHLTSimulationSetup(AliHLTSimulation *, AliSimulation *pSim, const char *specificObjects)
static const char * DdlFileName(const char *detectorName, Int_t ddlIndex)
Definition: AliDAQ.cxx:329
const TString & GetURI() const
Definition: AliCDBStorage.h:34
static AliRunLoader * Instance()
Definition: AliRunLoader.h:176
Int_t LoadgAlice()
void SetCavernTemperature(const Float_t *cavernTemperature)
Definition: AliGRPObject.h:124
Bool_t fEmbeddingFlag
flag to check if run number is already loaded from run loader
ULong64_t GetEventIdAsLong() const
Definition: AliVHeader.cxx:46
void UseTimeStampFromCDB(Double_t decayTimeHours=-1)
virtual Bool_t WriteRawFiles(const char *detectors="ALL")
AliRunLoader * LoadRun(const char *mode="UPDATE") const
static const TString & GetDefaultEventFolderName()
Definition: AliConfig.h:58
TFile * Open(const char *filename, Long64_t &nevents)
AliCentralTrigger * GetTrigger() const
static const Char_t * fgkRunHLTAuto
void SetDipolePolarity(Char_t dipolePolarity)
Definition: AliGRPObject.h:115
static const char * OfflineModuleName(const char *detectorName)
Definition: AliDAQ.cxx:512
TString fMakeDigitsFromHits
UInt_t GetDetectorMask() const
Definition: AliGRPObject.h:60
virtual void UpdateInternalGeometry()
Definition: AliModule.h:114
time_t GetHeaderTimeStamp() const
void Print(Option_t *opt="") const
Print the list of timers we manage.
static AliQAManager * QAManager(AliQAv1::MODE_t=AliQAv1::kNULLMODE, TMap *entryCache=NULL, Int_t run=-1)
UInt_t GetClusterMask() const
virtual ~AliSimulation()
time_t GetTimeStart() const
Definition: AliGRPObject.h:55
virtual void GetTarget(TString &tar, Int_t &a, Int_t &z) const
Definition: AliGenerator.h:105
Bool_t Put(TObject *object, AliCDBId &id, AliCDBMetaData *metaData, const char *mirrors="", AliCDBManager::DataType type=AliCDBManager::kPrivate)
void SetNumberOfEvents(Int_t nEvents)
Int_t GetRun() const
void SetDipoleCurrent(const Float_t *dipoleCurrent)
Definition: AliGRPObject.h:120
Int_t WriteRunLoader(Option_t *opt="")
Bool_t MisalignGeometry(AliRunLoader *runLoader=NULL)
TString fQATasks
Int_t fUseTimeStampFromCDB
virtual Int_t GetRun() const
Definition: AliHeader.h:35
void SetRegionOfInterest(Bool_t flag)
void CreateMapListCopy(TMap &mapCopy, TList &listCopy) const
#define TObjArray
virtual void GetXYZ(Double_t position[3]) const
Definition: AliVertex.cxx:119
void SetSpecificStorage(const char *calibType, const char *uri)
Int_t GetNSignalPerBkgrd(Int_t nEvents=0) const
void SetGAliceFile(const char *fileName)
void SetRunNumber(Int_t run)
const char * path
Bool_t IsUniform() const
Definition: AliMagF.h:57
virtual Float_t GetEnergyCMS() const
Definition: AliGenerator.h:101
TString fMakeSDigits
void SetEventSpecie(AliRecoParam::EventSpecie_t es)
static Bool_t ApplyAlignObjsFromCDB(const char *AlDetsList)
TString fConfigFileName
virtual void FinishRun()
virtual Bool_t ConvertDateToRoot(const char *dateFileName="raw.date", const char *rootFileName="raw.root")
void SetUniformBMap(Bool_t v=kTRUE)
Definition: AliGRPObject.h:101
void DumpToSnapshotFile(const char *snapshotFileName, Bool_t singleKeys) const
Bool_t ReadGRPEntry()
virtual void FinishRun()
Definition: AliLego.cxx:281
virtual void InitLoaders()
Definition: AliRun.cxx:150
TString fMakeDigits
Bool_t fInitRunNumberCalled
flag to check if CDB storages are already initialized
void SetTimeEnd(time_t timeEnd)
Definition: AliGRPObject.h:103
virtual Bool_t Run(Int_t nEvents=0)
TROOT * gROOT
void SetLHCState(TString lhcState)
Definition: AliGRPObject.h:110
ULong64_t fKey
Pointer to aliLego object if it exists.
TString fQARefUri
Uri of the default CDB storage.
virtual void Announce() const
Definition: AliRun.cxx:170
void SetL3Current(const Float_t *l3Current)
Definition: AliGRPObject.h:116
void SetWriteExpert(const AliQAv1::DETECTORINDEX_t det)
Definition: AliQAManager.h:73
AliLoader * GetLoader(const char *detname) const
TString fLoadAlObjsListOfDets
void SetDefaultStorage(const char *uri)
static void Destroy()
static const Int_t fgkNDetectors
optional ordered time stamps
Int_t GetHLTMode() const
Definition: AliGRPObject.h:83
int AliHLTSimulationRun(AliHLTSimulation *pSim, AliRunLoader *pRunLoader)
static Int_t DetectorID(const char *detectorName)
Definition: AliDAQ.cxx:204
TString fGRPWriteLocation
Bool_t SetRunNumberFromData()
static void AddParticlesToPdgDataBase()
Definition: AliPDG.cxx:31
TString fQADetectors
AliDataLoader * GetDataLoader(const char *name)
Definition: AliLoader.cxx:142
#define AliInfoF(message,...)
Definition: AliLog.h:499
AliHLTSimulation * fpHLT
HLT options, HLT is disabled if empty, default=&#39;default&#39;.
virtual Bool_t RunGeneratorOnly()
TString fWriteRawData
virtual void SetZMax(Float_t zmax)
Binding class for HLT simulation in AliRoot.
Bool_t IsSelected(TString detName, TString &detectors) const
Double_t SolenoidField() const
Definition: AliMagF.h:67
TObjArray * fAlignObjArray
#define AliFatalClass(message)
Definition: AliLog.h:645
void SetBeamEnergyIsSqrtSHalfGeV(Bool_t v=kTRUE)
Definition: AliGRPObject.h:99
TString fRawDataFileName
static void SetQARefStorage(const char *name)
Definition: AliQAv1.cxx:771
void SetTasks(TString tasks)
Definition: AliQAManager.h:84
virtual Bool_t Init()
Definition: AliDigitizer.h:35
TString fileName(const char *dir, int runNumber, const char *da, int i, const char *type)
static const char * ListOfTriggeredDetectors(UInt_t detectorPattern)
Definition: AliDAQ.cxx:438
void SetTimeStart(time_t timeStart)
Definition: AliGRPObject.h:102
#define AliWarning(message)
Definition: AliLog.h:541
Bool_t ImportgAlice(TFile *file)
Definition: AliTPCCmpNG.C:212
TObjArray * fBkgrdFileNames
static AliSimulation * fgInstance
Bool_t fUseBkgrdVertex
static const char * GetEmbeddingBKGPathsKey()
Definition: AliStack.h:93
virtual void FinishRun()
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
virtual void GetProjectile(TString &tar, Int_t &a, Int_t &z) const
Definition: AliGenerator.h:103
static AliRunLoader * Open(const char *filename="galice.root", const char *eventfoldername=AliConfig::GetDefaultEventFolderName(), Option_t *option="READ")
virtual void SetCoor1Range(Int_t nbin, Float_t c1min, Float_t c1max)
Int_t SetEventNumber(Int_t evno)
void SetSeed(Int_t seed)
virtual void SetStack(AliStack *stack)
Definition: AliHeader.cxx:187
Bool_t fRunGeneratorOnly
Double_t GetFactorDip() const
Definition: AliMagF.cxx:539
Bool_t fInitCDBCalled
Seed for random number generator.
static const char * DetectorName(Int_t detectorID)
Definition: AliDAQ.cxx:226
TString GetFileName() const
static TGraph * GetLumiFromCTP(Int_t run=-1, const char *ocdbPathDef="raw://", TString refClassName="", Double_t refSigma=-1)
time_t GenerateTimeStamp() const
Int_t GetNprimary() const
Definition: AliStack.h:137
TObject * GetObject()
Definition: AliCDBEntry.h:56
virtual Int_t GetNtrack() const
Definition: AliStack.h:134
AliCDBStorage * GetStorage(const char *dbString)
static Float_t NumberOfLdcs(const char *detectorName)
Definition: AliDAQ.cxx:394
void SetQARefDefaultStorage(const char *uri)
virtual Bool_t RunSDigitization(const char *detectors="ALL")
Int_t fRun
Array with detector specific CDB storages.
void SetSpecificStorage(const char *calibType, const char *dbString, Int_t version=-1, Int_t subVersion=-1)
Double_t GetFactorSol() const
Definition: AliMagF.cxx:528
void MakeTree(Option_t *option)
virtual Bool_t RunLego(const char *setup="Config.C", Int_t nc1=60, Float_t c1min=2, Float_t c1max=178, Int_t nc2=60, Float_t c2min=0, Float_t c2max=360, Float_t rmin=0, Float_t rmax=430, Float_t zmax=10000, AliLegoGenerator *gener=NULL, Int_t nev=-1)
Bool_t fRegionOfInterest
virtual void SetNprimary(Int_t nprimary)
Definition: AliHeader.h:37
AliHeader * GetHeader() const
#define AliInfo(message)
Definition: AliLog.h:484
Bool_t fRunSimulation
int AliHLTSimulationDeleteInstance(AliHLTSimulation *pSim)
void gen(Int_t nev=1, const char *genConfig="$ALICE_ROOT/MUON/macros/genTestConfig.C")
Definition: gen.C:45
virtual void Init()
Definition: AliMC.cxx:1624
virtual Bool_t ConvertRawFilesToDate(const char *dateFileName="raw.date", const char *rootFileName="")
void SetUseMonitoring(Bool_t flag=kTRUE)
Definition: AliMC.h:117
#define AliCodeTimerStart(message)
Definition: AliCodeTimer.h:135
Bool_t fWriteQAExpertData
void SetActiveDetectors(TString aDet)
Definition: AliQAManager.h:69
#define AliCodeTimerAuto(message, counter)
Definition: AliCodeTimer.h:137
TGeoManager * gGeoManager
virtual void SetOrigin(Float_t ox, Float_t oy, Float_t oz)
virtual void Digits2Raw()
Definition: AliModule.cxx:402
Int_t WriteHeader(Option_t *opt="")
void SetConfigFile(const char *fileName)
ULong64_t GetClassMask() const
virtual AliGenerator * Generator() const
Definition: AliMC.h:58
void DeactivateDetectorsAbsentInGRP(TObjArray *detArr)
Int_t LoadHeader()
Bool_t fUseVertexFromCDB
current CDB key
static void SetGeometry(TGeoManager *const geom)
AliStream * GetInputStream(Int_t index) const
virtual void Hits2SDigits()
Definition: AliModule.h:90
AliRun * gAlice
Definition: AliRun.cxx:62
AliRunLoader * GetOutRunLoader()
Int_t GetNumberOfEvents()
void SetLHCPeriod(TString lhcPeriod)
Definition: AliGRPObject.h:108
Bool_t SetMagField()
virtual time_t GetTimeStamp() const
Definition: AliHeader.h:63
const TString & GetFolderName() const
Definition: AliStream.h:41
void SetInputStream(Int_t stream, const char *inputName, TString foldername="")
TString baseDir
Definition: UnitTest.C:38
virtual void SetPrimaryVertex(const TArrayF &o)
virtual void Reset(Int_t run, Int_t event)
Definition: AliHeader.cxx:130
static AliCodeTimer * Instance()
Unique instance of this class, which is a singleton.
TString Run(const Char_t *detectors, const AliQAv1::TASKINDEX_t taskIndex=AliQAv1::kNULLTASKINDEX, Bool_t const sameCycle=kFALSE, const Char_t *fileName=NULL)
void SetRun(Int_t run)
Bool_t fUseDetectorsFromGRP
#define ALIHLTSIMULATION_LIBRARY
time_t GetTimeEnd() const
Definition: AliGRPObject.h:56
virtual Bool_t WriteRawData(const char *detectors="ALL", const char *fileName=NULL, Bool_t deleteIntermediateFiles=kFALSE, Bool_t selrawdata=kFALSE)
Bool_t SetRunQA(TString detAndAction="ALL:ALL")
Definition: AliCDBEntry.h:18
#define AliFatal(message)
Definition: AliLog.h:640
Int_t LoadTrigger(Option_t *option="READ")
virtual Bool_t RunHLT()
TTree * TreeE() const
void SetVertexGenerator(AliVertexGenerator *vertexGenerator)
Definition: AliGenerator.h:66
static UInt_t seed
Definition: pdc06_config.C:131
void GetSigmaXYZ(Double_t sigma[3]) const
void SetDefaultStorage(const char *dbString)
void Print(Option_t *option="") const
void SetSgPerBgEmbedded(int i)
Definition: AliRun.h:69
virtual Bool_t RunDigitization(const char *detectors="ALL", const char *excludeDetectors="")
void SetBeamEnergy(Float_t beamEnergy)
Definition: AliGRPObject.h:104
Int_t GetEvent(Int_t evno)
Int_t GetDetIndex(const char *detector)
TString fTriggerConfig
virtual void Generate()=0
static const char * fgkDetectorName[fgkNDetectors]
Bool_t fRunGeneration
Bool_t fUseMonitoring
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
TObjArray fSpecCDBUri
Uri of the default QA reference storage.
std::vector< time_t > fOrderedTimeStamps
AliHLTSimulation * AliHLTSimulationCreateInstance()
virtual Bool_t RunSimulation(Int_t nEvents=0)
virtual void SetTrackingFlag(Int_t flag=1)
Definition: AliGenerator.h:75
void ReadFromTree(TTree *tree, Option_t *opt="")
const AliGRPObject * GetGRPData() const
Definition: AliGRPManager.h:28
AliSimulation(const char *configFileName="Config.C", const char *name="AliSimulation", const char *title="generation, simulation and digitization")
virtual Bool_t RunHitsDigitization(const char *detectors="ALL")
virtual void SetNtrack(Int_t ntrack)
Definition: AliHeader.h:44
Int_t LoadHits(Option_t *detectors="all", Option_t *opt="READ")
DETECTORINDEX_t
Definition: AliQAv1.h:23
void SetNumberOfDetectors(Char_t numberOfDetectors)
Definition: AliGRPObject.h:106
Float_t fLumiDecayH
void SetBeamType(TString beamType)
Definition: AliGRPObject.h:105
void Reset(Int_t size=0)
Definition: AliStack.cxx:653
virtual Bool_t RunTrigger(const char *descriptors="", const char *detectors="ALL")
Int_t grp(UInt_t run, TString &gdc)
Definition: onlineReco.C:70
virtual void SetCoor2Range(Int_t nbin, Float_t c2min, Float_t c2max)
static Bool_t CheckSymNamesLUT(const char *detsToBeChecked)
Int_t LoadTrackRefs(Option_t *option="READ")
const AliESDVertex * GetPrimaryVertex() const
void SetNumberOfEventsPerFile(Int_t nevpf)
Definition: AliRunLoader.h:153
virtual void FinishRun()
Definition: AliMC.cxx:1151
void SetEventNrInRun(Int_t event)
Definition: AliRun.h:39
void SetEventsPerFile(const char *detector, const char *type, Int_t nEvents)
Bool_t LoadConfiguration(TString &config)
virtual const char * GetConfigFunction() const
Definition: AliRun.h:50
void ProcessEnvironmentVars()
AliCDBStorage * GetDefaultStorage() const
Definition: AliCDBManager.h:61
virtual Bool_t IsLegoRun() const
void SetDetectorMask(UInt_t detectorMask)
Definition: AliGRPObject.h:107
void SetRunLoader(AliRunLoader *rl)
Definition: AliQAManager.h:82
int AliHLTSimulationInit(AliHLTSimulation *pSim, AliRunLoader *pRunLoader, const char *options)
static Bool_t ApplyAlignObjsToGeom(TObjArray &alObjArray, Bool_t ovlpcheck=kFALSE)
void FinishEvent()
Definition: AliStack.cxx:555
ULong64_t SetLock(Bool_t lockFlag=kTRUE, ULong64_t key=0)
AliLego * fLego
virtual AliDigitizer * CreateDigitizer(AliDigitizationInput *) const
Definition: AliModule.h:91
virtual void Init()
Bool_t fDeleteIntermediateFiles
TObjArray fEventsPerFile
virtual Bool_t Raw2SDigits(AliRawReader *)
Definition: AliModule.h:100
static void AddStamp(const char *sname, Int_t id0=-1, Int_t id1=-1, Int_t id2=-1, Int_t id3=-1)
Definition: AliSysInfo.cxx:179
virtual Bool_t CreateHLT()
AliVertexGenerator * GetVertexGenerator() const
Definition: AliGenerator.h:68
virtual void SetSigma(Float_t sx, Float_t sy, Float_t sz)
Bool_t fSetRunNumberFromDataCalled
flag to check if run number is already initialized
AliESDHeader * GetHeader() const
Definition: AliESDEvent.h:193
void SetNumberOfEventsPerFile(Int_t nevpf)
Definition: AliDataLoader.h:77
#define AliError(message)
Definition: AliLog.h:591
Bool_t fStopOnError
virtual Int_t ConvertRaw2SDigits(const char *rawDirectory, const char *esdFile="", Int_t N=-1, Int_t nSkip=0)
AliCDBId & GetId()
Definition: AliCDBEntry.h:51
AliRecoParam::EventSpecie_t fEventSpecie
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
static Int_t NumberOfDdls(const char *detectorName)
Definition: AliDAQ.cxx:368
virtual void Hits2Digits()
Definition: AliModule.h:96
Bool_t IsValid() const
Definition: AliCDBPath.h:43
static AliRunLoader * GetRunLoader(const char *eventfoldername)
size_t Remove_All(const char *name)
void SetRunType(TString runType)
Definition: AliGRPObject.h:109
virtual Bool_t IsActive() const
Definition: AliModule.h:53
Bool_t fLoadAlignFromCDB
Bool_t IsDefaultStorageSet() const
Definition: AliCDBManager.h:60
Bool_t RunTrigger(AliRunLoader *runloader, const char *detectors)
void StoreUsedCDBMapsAndEmbPaths() const
Double_t GetXRes() const
Definition: AliESDVertex.h:61
virtual void SetGenEventHeader(AliGenEventHeader *header)
Definition: AliHeader.cxx:194
static TGeoManager * GetGeometry()
Bool_t fWriteGRPEntry
The instance of HLT simulation.
virtual void SetSigmaZ(Float_t sz)
Definition: AliGenerator.h:45
static void LoadGeometry(const char *geomFileName=NULL)
void MergeWith(const char *fileName, Int_t nSignalPerBkgrd=0)
static TString GetTaskName(UInt_t tsk)
Definition: AliQAv1.h:90
AliMC * GetMCApp() const
Definition: AliRun.h:53
TObjArray * Modules() const
Definition: AliRun.h:36
virtual Bool_t IsGeometryFromFile() const
virtual void SetActive(Bool_t v=kTRUE)
Definition: AliModule.h:54
void SetRunNumber(Int_t run)
Definition: AliRunLoader.h:102
void SetPolarityConventionLHC(Bool_t v=kTRUE)
Definition: AliGRPObject.h:100
virtual void SetRadiusRange(Float_t rmin, Float_t rmax)
void SetNumberOfEventsPerRun(Int_t nevpr)
Definition: AliRunLoader.h:154
static Int_t DdlID(const char *detectorName, Int_t ddlIndex)
Definition: AliDAQ.cxx:298
void SetL3Polarity(Char_t l3Polarity)
Definition: AliGRPObject.h:114
Bool_t fUseMagFieldFromGRP
Int_t LoadKinematics(Option_t *option="READ")
static const Char_t * fgkHLTDefConf
AliRun * GetAliRun() const
#define AliCodeTimerStop(message)
Definition: AliCodeTimer.h:136
TString fGAliceFileName
Int_t fSeed
Run number, will be passed to CDB and gAlice!!
virtual void ResetGenerator(AliGenerator *generator)
Definition: AliMC.cxx:1132
Bool_t fWriteSelRawData
void EmbedInto(const char *fileName, Int_t nSignalPerBkgrd=0)
virtual Bool_t WriteTriggerRawData()
TObjArray * Detectors() const
Definition: AliRun.h:35