ROOT logo
#ifndef ALISIMULATION_H
#define ALISIMULATION_H
/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

/* $Id: AliSimulation.h 63170 2013-06-24 14:20:10Z morsch $ */

//
// class for running generation, simulation and digitization
// Hits, sdigits and digits are created for all detectors by typing:
//   AliSimulation sim;
//   sim.Run();
//

#include <TNamed.h>
#include <TString.h>
#include <TObjArray.h>
#include "AliQAv1.h"
#include "AliQAManager.h"
#include <time.h>

class AliCDBId;
class AliCDBParam;
class AliRunLoader;
class AliLegoGenerator;
class AliLego;
class AliMagF;
class AliHLTSimulation;

class AliSimulation: public TNamed {
public:
  AliSimulation(const char* configFileName = "Config.C",
		const char* name = "AliSimulation", 
		const char* title = "generation, simulation and digitization");
  virtual ~AliSimulation();

  static AliSimulation *Instance() {if(!fgInstance) fgInstance=new AliSimulation(); return fgInstance;}

  void           SetNumberOfEvents(Int_t nEvents);
  void           SetConfigFile(const char* fileName);
  void           SetGAliceFile(const char* fileName);
  void           SetEventsPerFile(const char* detector, const char* type, 
				  Int_t nEvents);

  void           SetRunGeneratorOnly(Bool_t val) {fRunGeneratorOnly = val;};
  void           SetRunGeneration(Bool_t run) {fRunGeneration = run;};
  void           SetRunSimulation(Bool_t run) {fRunSimulation = run;};
  void           SetLoadAlignFromCDB(Bool_t load)  {fLoadAlignFromCDB = load;};
  void           SetLoadAlignData(const char* detectors) 
                   {fLoadAlObjsListOfDets = detectors;};
  void           SetMakeSDigits(const char* detectors) 
                   {fMakeSDigits = detectors;};
  void           MergeWith(const char* fileName, Int_t nSignalPerBkgrd = 0);
  void           EmbedInto(const char* fileName, Int_t nSignalPerBkgrd = 0);
  void           SetUseBkgrdVertex(Bool_t useBkgrdVertex)
                   {fUseBkgrdVertex = useBkgrdVertex;};
  void           SetRegionOfInterest(Bool_t flag) {fRegionOfInterest = flag;};
  void           SetMakeDigits(const char* detectors)
                   {fMakeDigits = detectors;};
  void           SetMakeDigitsFromHits(const char* detectors)
                   {fMakeDigitsFromHits = detectors;};
  void           SetWriteRawData(const char* detectors, 
				 const char* fileName = NULL,
				 Bool_t deleteIntermediateFiles = kFALSE)
                   {fWriteRawData = detectors; fRawDataFileName = fileName;
		   fDeleteIntermediateFiles = deleteIntermediateFiles;};
  void           SetWriteSelRawData(Bool_t sel = kTRUE)
                   {fWriteSelRawData = sel;}
  void           SetTriggerConfig(TString conf) {fTriggerConfig=conf;}
  const Char_t*  GetTriggerConfig() const {return fTriggerConfig.Data();}
  void           SetAlignObjArray(TObjArray *array)
                   {fAlignObjArray = array;
		   fLoadAlignFromCDB = kFALSE;}
  void           SetUseMonitoring(Bool_t flag=kTRUE) {fUseMonitoring = flag;}

  Bool_t         MisalignGeometry(AliRunLoader *runLoader = NULL);

  void           SetRunNumber(Int_t run);
  void           SetSeed(Int_t seed);
    
  void 		 ProcessEnvironmentVars();
		   
  // CDB storage activation
  void SetDefaultStorage(const char* uri);
  void SetSpecificStorage(const char* calibType, const char* uri);
  void SetCDBSnapshotMode(const char* snapshotFileName) {AliCDBManager::Instance()->SetSnapshotMode(snapshotFileName);}

  virtual Bool_t Run(Int_t nEvents = 0);
  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);

  virtual Bool_t RunSimulation(Int_t nEvents = 0);
  virtual Bool_t RunGeneratorOnly();
  virtual Bool_t RunSDigitization(const char* detectors = "ALL");
  virtual Bool_t RunTrigger(const char* descriptors ="", const char* detectors = "ALL");
  virtual Bool_t WriteTriggerRawData();
  virtual Bool_t RunDigitization(const char* detectors = "ALL",
				 const char* excludeDetectors = "");
  virtual Bool_t RunHitsDigitization(const char* detectors = "ALL");
  virtual Bool_t WriteRawData(const char* detectors = "ALL",
			      const char* fileName = NULL,
			      Bool_t deleteIntermediateFiles = kFALSE,
			      Bool_t selrawdata = kFALSE);
  virtual Bool_t WriteRawFiles(const char* detectors = "ALL");
  virtual Bool_t ConvertRawFilesToDate(const char* dateFileName = "raw.date",
				       const char* rootFileName = "");
  virtual Bool_t ConvertDateToRoot(const char* dateFileName = "raw.date",
				   const char* rootFileName = "raw.root");
  virtual Int_t ConvertRaw2SDigits(const char* rawDirectory, const char* esdFile = "", Int_t N=-1, Int_t nSkip=0);

  // Sets the name of the file from which the geometry is loaded
  virtual void SetGeometryFile(const Char_t* filename) {fGeometryFile=filename;}
  virtual const Char_t* GetGeometryFile() const {return fGeometryFile.Data();}
  virtual Bool_t IsGeometryFromFile() const {return !fGeometryFile.IsNull();}


  // HLT
  void SetRunHLT(const char* options) {fRunHLT=options;}
  virtual Bool_t CreateHLT();
  virtual Bool_t RunHLT();
  virtual  Bool_t IsLegoRun() const {return (fLego!=0);}
  AliLego* Lego() const {return fLego;}
  virtual  void  FinishRun();
  //
  void StoreUsedCDBMaps() const; 

  //Quality Assurance
  Int_t       GetDetIndex(const char * detector);
  void        SetQACycles(AliQAv1::DETECTORINDEX_t det, const Int_t cycles) {  AliQAManager::QAManager()->SetCycleLength(det, cycles) ; }
  Bool_t      RunQA() ;
  Bool_t      SetRunQA(TString detAndAction="ALL:ALL") ; 
  void        SetQAWriteExpert(AliQAv1::DETECTORINDEX_t det) { AliQAManager::QAManager()->SetWriteExpert(det) ; }  
  void        SetQARefDefaultStorage(const char* uri);
  void        InitQA();
  void        SetEventSpecie(AliRecoParam::EventSpecie_t es) { fEventSpecie = es ; }
  void        SetWriteQAExpert() { fWriteQAExpertData = kTRUE ; }

  void SetWriteGRPEntry(Bool_t flag = kTRUE) { fWriteGRPEntry = flag; }
  void WriteGRPEntry();
  void UseVertexFromCDB()   {fUseVertexFromCDB   = kTRUE;}
  void UseMagFieldFromGRP() {fUseMagFieldFromGRP = kTRUE;} 
  void SetGRPWriteLocation(char* loc) {fGRPWriteLocation = loc;}

  void UseTimeStampFromCDB()   {fUseTimeStampFromCDB   = kTRUE;}
  time_t GenerateTimeStamp() const;

private:

  AliSimulation(const AliSimulation&); // Not implemented
  AliSimulation& operator = (const AliSimulation&); // Not implemented

  void 		 InitCDB();
  void 		 InitRunNumber();
  void 		 SetCDBLock();
  Bool_t         SetRunNumberFromData();
  AliRunLoader*  LoadRun(const char* mode = "UPDATE") const;
  Int_t          GetNSignalPerBkgrd(Int_t nEvents = 0) const;
  Bool_t         IsSelected(TString detName, TString& detectors) const;

  static AliSimulation *fgInstance;    // Static pointer to object

  Bool_t         fRunGeneratorOnly;   // run code for a generator only production
  Bool_t         fRunGeneration;      // generate prim. particles or not
  Bool_t         fRunSimulation;      // simulate detectors (hits) or not
  Bool_t         fLoadAlignFromCDB;   // Load alignment data from CDB and apply it to geometry or not
  TString        fLoadAlObjsListOfDets;   // Load alignment data from CDB for these detectors
  TString        fMakeSDigits;        // create sdigits for these detectors
  TString        fMakeDigits;         // create digits for these detectors
  TString        fTriggerConfig;      // run trigger for these descriptors
  TString        fMakeDigitsFromHits; // create digits from hits for these detectors
  TString        fWriteRawData;       // write raw data for these detectors
  TString        fRawDataFileName;    // file name for the raw data file
  Bool_t         fDeleteIntermediateFiles; // delete intermediate raw data files
  Bool_t         fWriteSelRawData;    // write detectors raw data in a separate file accoring to the trigger cluster
  Bool_t         fStopOnError;        // stop or continue on errors
  Bool_t         fUseMonitoring;      // monitor simulation timing per volume

  Int_t          fNEvents;            // number of events
  TString        fConfigFileName;     // name of the config file
  TString        fGAliceFileName;     // name of the galice file
  TObjArray      fEventsPerFile;      // number of events per file for given detectors and data types

  TObjArray*     fBkgrdFileNames;     // names of background files for merging
  TObjArray*     fAlignObjArray;      // array with the alignment objects to be applied to the geometry
  Bool_t         fUseBkgrdVertex;     // use vertex from background in case of merging
  Bool_t         fRegionOfInterest;   // digitization in region of interest

  TString 	 fCDBUri;	                     //! Uri of the default CDB storage
  TString 	 fQARefUri;	                     //! Uri of the default QA reference storage
  TObjArray      fSpecCDBUri;                        //! Array with detector specific CDB storages
  Int_t 	   fRun; 		                     //! Run number, will be passed to CDB and gAlice!!
  Int_t 	   fSeed;                        //! Seed for random number generator 
  Bool_t 	   fInitCDBCalled;               //! flag to check if CDB storages are already initialized
  Bool_t 	   fInitRunNumberCalled;         //! flag to check if run number is already initialized
  Bool_t 	   fSetRunNumberFromDataCalled;  //! flag to check if run number is already loaded from run loader
  
  Bool_t         fEmbeddingFlag;       // Flag for embedding
  AliLego       *fLego;                //! Pointer to aliLego object if it exists
  // OCDB
  ULong64_t       fKey;                //! current CDB key
  Bool_t          fUseVertexFromCDB;   // Flag to use Vertex from CDB
  Bool_t          fUseMagFieldFromGRP; // Use magnetic field settings from GRP
  TString         fGRPWriteLocation;   // Location to write the GRP entry from simulation

  Bool_t          fUseTimeStampFromCDB;// Flag to generate event time-stamps according to SOR/EOR from GRP
  time_t          fTimeStart;          // SOR time-stamp
  time_t          fTimeEnd;            // EOR time-stamp
  
  //QA stuff
  static const Int_t   fgkNDetectors = 18 ;             // number of detectors   +FIT // alla
  static const char *  fgkDetectorName[fgkNDetectors] ; // names of detectors
  TString              fQADetectors ;                   // list of detectors to be QA'ed 	
  TString              fQATasks ;                       // list of QA tasks to be performed	
  Bool_t               fRunQA ;                         // Runs the QA at the end of simulation
  AliRecoParam::EventSpecie_t fEventSpecie ;            // type of event (see AliRecoParam::EventSpecie_t)
  Bool_t               fWriteQAExpertData ;             //! decides wheter or not to write experts QA data; true by default

  TString              fGeometryFile;                   // Geometry file

  //HLT
  TString              fRunHLT;       //! HLT options, HLT is disabled if empty, default='default'
  AliHLTSimulation*    fpHLT;         //! The instance of HLT simulation

  Bool_t         fWriteGRPEntry;      // Write or not GRP entry corresponding to the settings in Config.C

  ClassDef(AliSimulation, 13)  // class for running generation, simulation and digitization
};

#endif
 AliSimulation.h:1
 AliSimulation.h:2
 AliSimulation.h:3
 AliSimulation.h:4
 AliSimulation.h:5
 AliSimulation.h:6
 AliSimulation.h:7
 AliSimulation.h:8
 AliSimulation.h:9
 AliSimulation.h:10
 AliSimulation.h:11
 AliSimulation.h:12
 AliSimulation.h:13
 AliSimulation.h:14
 AliSimulation.h:15
 AliSimulation.h:16
 AliSimulation.h:17
 AliSimulation.h:18
 AliSimulation.h:19
 AliSimulation.h:20
 AliSimulation.h:21
 AliSimulation.h:22
 AliSimulation.h:23
 AliSimulation.h:24
 AliSimulation.h:25
 AliSimulation.h:26
 AliSimulation.h:27
 AliSimulation.h:28
 AliSimulation.h:29
 AliSimulation.h:30
 AliSimulation.h:31
 AliSimulation.h:32
 AliSimulation.h:33
 AliSimulation.h:34
 AliSimulation.h:35
 AliSimulation.h:36
 AliSimulation.h:37
 AliSimulation.h:38
 AliSimulation.h:39
 AliSimulation.h:40
 AliSimulation.h:41
 AliSimulation.h:42
 AliSimulation.h:43
 AliSimulation.h:44
 AliSimulation.h:45
 AliSimulation.h:46
 AliSimulation.h:47
 AliSimulation.h:48
 AliSimulation.h:49
 AliSimulation.h:50
 AliSimulation.h:51
 AliSimulation.h:52
 AliSimulation.h:53
 AliSimulation.h:54
 AliSimulation.h:55
 AliSimulation.h:56
 AliSimulation.h:57
 AliSimulation.h:58
 AliSimulation.h:59
 AliSimulation.h:60
 AliSimulation.h:61
 AliSimulation.h:62
 AliSimulation.h:63
 AliSimulation.h:64
 AliSimulation.h:65
 AliSimulation.h:66
 AliSimulation.h:67
 AliSimulation.h:68
 AliSimulation.h:69
 AliSimulation.h:70
 AliSimulation.h:71
 AliSimulation.h:72
 AliSimulation.h:73
 AliSimulation.h:74
 AliSimulation.h:75
 AliSimulation.h:76
 AliSimulation.h:77
 AliSimulation.h:78
 AliSimulation.h:79
 AliSimulation.h:80
 AliSimulation.h:81
 AliSimulation.h:82
 AliSimulation.h:83
 AliSimulation.h:84
 AliSimulation.h:85
 AliSimulation.h:86
 AliSimulation.h:87
 AliSimulation.h:88
 AliSimulation.h:89
 AliSimulation.h:90
 AliSimulation.h:91
 AliSimulation.h:92
 AliSimulation.h:93
 AliSimulation.h:94
 AliSimulation.h:95
 AliSimulation.h:96
 AliSimulation.h:97
 AliSimulation.h:98
 AliSimulation.h:99
 AliSimulation.h:100
 AliSimulation.h:101
 AliSimulation.h:102
 AliSimulation.h:103
 AliSimulation.h:104
 AliSimulation.h:105
 AliSimulation.h:106
 AliSimulation.h:107
 AliSimulation.h:108
 AliSimulation.h:109
 AliSimulation.h:110
 AliSimulation.h:111
 AliSimulation.h:112
 AliSimulation.h:113
 AliSimulation.h:114
 AliSimulation.h:115
 AliSimulation.h:116
 AliSimulation.h:117
 AliSimulation.h:118
 AliSimulation.h:119
 AliSimulation.h:120
 AliSimulation.h:121
 AliSimulation.h:122
 AliSimulation.h:123
 AliSimulation.h:124
 AliSimulation.h:125
 AliSimulation.h:126
 AliSimulation.h:127
 AliSimulation.h:128
 AliSimulation.h:129
 AliSimulation.h:130
 AliSimulation.h:131
 AliSimulation.h:132
 AliSimulation.h:133
 AliSimulation.h:134
 AliSimulation.h:135
 AliSimulation.h:136
 AliSimulation.h:137
 AliSimulation.h:138
 AliSimulation.h:139
 AliSimulation.h:140
 AliSimulation.h:141
 AliSimulation.h:142
 AliSimulation.h:143
 AliSimulation.h:144
 AliSimulation.h:145
 AliSimulation.h:146
 AliSimulation.h:147
 AliSimulation.h:148
 AliSimulation.h:149
 AliSimulation.h:150
 AliSimulation.h:151
 AliSimulation.h:152
 AliSimulation.h:153
 AliSimulation.h:154
 AliSimulation.h:155
 AliSimulation.h:156
 AliSimulation.h:157
 AliSimulation.h:158
 AliSimulation.h:159
 AliSimulation.h:160
 AliSimulation.h:161
 AliSimulation.h:162
 AliSimulation.h:163
 AliSimulation.h:164
 AliSimulation.h:165
 AliSimulation.h:166
 AliSimulation.h:167
 AliSimulation.h:168
 AliSimulation.h:169
 AliSimulation.h:170
 AliSimulation.h:171
 AliSimulation.h:172
 AliSimulation.h:173
 AliSimulation.h:174
 AliSimulation.h:175
 AliSimulation.h:176
 AliSimulation.h:177
 AliSimulation.h:178
 AliSimulation.h:179
 AliSimulation.h:180
 AliSimulation.h:181
 AliSimulation.h:182
 AliSimulation.h:183
 AliSimulation.h:184
 AliSimulation.h:185
 AliSimulation.h:186
 AliSimulation.h:187
 AliSimulation.h:188
 AliSimulation.h:189
 AliSimulation.h:190
 AliSimulation.h:191
 AliSimulation.h:192
 AliSimulation.h:193
 AliSimulation.h:194
 AliSimulation.h:195
 AliSimulation.h:196
 AliSimulation.h:197
 AliSimulation.h:198
 AliSimulation.h:199
 AliSimulation.h:200
 AliSimulation.h:201
 AliSimulation.h:202
 AliSimulation.h:203
 AliSimulation.h:204
 AliSimulation.h:205
 AliSimulation.h:206
 AliSimulation.h:207
 AliSimulation.h:208
 AliSimulation.h:209
 AliSimulation.h:210
 AliSimulation.h:211
 AliSimulation.h:212
 AliSimulation.h:213
 AliSimulation.h:214
 AliSimulation.h:215
 AliSimulation.h:216
 AliSimulation.h:217
 AliSimulation.h:218
 AliSimulation.h:219
 AliSimulation.h:220
 AliSimulation.h:221
 AliSimulation.h:222
 AliSimulation.h:223
 AliSimulation.h:224
 AliSimulation.h:225
 AliSimulation.h:226
 AliSimulation.h:227
 AliSimulation.h:228
 AliSimulation.h:229
 AliSimulation.h:230