]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEER/AliSimulation.h
207c4595cfe89327ba054f7e9f0b9c13193f9e52
[u/mrichter/AliRoot.git] / STEER / STEER / AliSimulation.h
1 #ifndef ALISIMULATION_H
2 #define ALISIMULATION_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 //
9 // class for running generation, simulation and digitization
10 // Hits, sdigits and digits are created for all detectors by typing:
11 //   AliSimulation sim;
12 //   sim.Run();
13 //
14
15 #include <TNamed.h>
16 #include <TString.h>
17 #include <TObjArray.h>
18 #include "AliQAv1.h"
19 #include "AliQAManager.h"
20 #include <time.h>
21
22 class AliCDBId;
23 class AliCDBParam;
24 class AliRunLoader;
25 class AliLegoGenerator;
26 class AliLego;
27 class AliMagF;
28 class AliHLTSimulation;
29
30 class AliSimulation: public TNamed {
31 public:
32   AliSimulation(const char* configFileName = "Config.C",
33                 const char* name = "AliSimulation", 
34                 const char* title = "generation, simulation and digitization");
35   virtual ~AliSimulation();
36
37   static AliSimulation *Instance() {if(!fgInstance) fgInstance=new AliSimulation(); return fgInstance;}
38
39   void           SetNumberOfEvents(Int_t nEvents);
40   void           SetConfigFile(const char* fileName);
41   void           SetGAliceFile(const char* fileName);
42   void           SetEventsPerFile(const char* detector, const char* type, 
43                                   Int_t nEvents);
44
45   void           SetRunGeneration(Bool_t run) {fRunGeneration = run;};
46   void           SetRunSimulation(Bool_t run) {fRunSimulation = run;};
47   void           SetLoadAlignFromCDB(Bool_t load)  {fLoadAlignFromCDB = load;};
48   void           SetLoadAlignData(const char* detectors) 
49                    {fLoadAlObjsListOfDets = detectors;};
50   void           SetMakeSDigits(const char* detectors) 
51                    {fMakeSDigits = detectors;};
52   void           MergeWith(const char* fileName, Int_t nSignalPerBkgrd = 0);
53   void           EmbedInto(const char* fileName, Int_t nSignalPerBkgrd = 0);
54   void           SetUseBkgrdVertex(Bool_t useBkgrdVertex)
55                    {fUseBkgrdVertex = useBkgrdVertex;};
56   void           SetRegionOfInterest(Bool_t flag) {fRegionOfInterest = flag;};
57   void           SetMakeDigits(const char* detectors)
58                    {fMakeDigits = detectors;};
59   void           SetMakeDigitsFromHits(const char* detectors)
60                    {fMakeDigitsFromHits = detectors;};
61   void           SetWriteRawData(const char* detectors, 
62                                  const char* fileName = NULL,
63                                  Bool_t deleteIntermediateFiles = kFALSE)
64                    {fWriteRawData = detectors; fRawDataFileName = fileName;
65                    fDeleteIntermediateFiles = deleteIntermediateFiles;};
66   void           SetWriteSelRawData(Bool_t sel = kTRUE)
67                    {fWriteSelRawData = sel;}
68   void           SetTriggerConfig(TString conf) {fTriggerConfig=conf;}
69   const Char_t*  GetTriggerConfig() const {return fTriggerConfig.Data();}
70   void           SetAlignObjArray(TObjArray *array)
71                    {fAlignObjArray = array;
72                    fLoadAlignFromCDB = kFALSE;}
73
74   Bool_t         MisalignGeometry(AliRunLoader *runLoader = NULL);
75
76   void           SetRunNumber(Int_t run);
77   void           SetSeed(Int_t seed);
78     
79   void           ProcessEnvironmentVars();
80                    
81   // CDB storage activation
82   void SetDefaultStorage(const char* uri);
83   void SetSpecificStorage(const char* calibType, const char* uri);
84   void SetCDBSnapshotMode(const char* snapshotFileName) {AliCDBManager::Instance()->SetSnapshotMode(snapshotFileName);}
85
86   virtual Bool_t Run(Int_t nEvents = 0);
87   virtual Bool_t RunLego(const char *setup="Config.C",Int_t nc1=60,Float_t c1min=2,Float_t c1max=178,
88                          Int_t nc2=60,Float_t c2min=0,Float_t c2max=360,Float_t rmin=0,
89                          Float_t rmax=430,Float_t zmax=10000, AliLegoGenerator* gener=NULL, Int_t nev = -1);
90
91   virtual Bool_t RunSimulation(Int_t nEvents = 0);
92   virtual Bool_t RunSDigitization(const char* detectors = "ALL");
93   virtual Bool_t RunTrigger(const char* descriptors ="", const char* detectors = "ALL");
94   virtual Bool_t WriteTriggerRawData();
95   virtual Bool_t RunDigitization(const char* detectors = "ALL",
96                                  const char* excludeDetectors = "");
97   virtual Bool_t RunHitsDigitization(const char* detectors = "ALL");
98   virtual Bool_t WriteRawData(const char* detectors = "ALL",
99                               const char* fileName = NULL,
100                               Bool_t deleteIntermediateFiles = kFALSE,
101                               Bool_t selrawdata = kFALSE);
102   virtual Bool_t WriteRawFiles(const char* detectors = "ALL");
103   virtual Bool_t ConvertRawFilesToDate(const char* dateFileName = "raw.date",
104                                        const char* rootFileName = "");
105   virtual Bool_t ConvertDateToRoot(const char* dateFileName = "raw.date",
106                                    const char* rootFileName = "raw.root");
107   virtual Int_t ConvertRaw2SDigits(const char* rawDirectory, const char* esdFile = "", Int_t N=-1);
108
109   // Sets the name of the file from which the geometry is loaded
110   virtual void SetGeometryFile(const Char_t* filename) {fGeometryFile=filename;}
111   virtual const Char_t* GetGeometryFile() const {return fGeometryFile.Data();}
112   virtual Bool_t IsGeometryFromFile() const {return !fGeometryFile.IsNull();}
113
114
115   // HLT
116   void SetRunHLT(const char* options) {fRunHLT=options;}
117   virtual Bool_t CreateHLT();
118   virtual Bool_t RunHLT();
119   virtual  Bool_t IsLegoRun() const {return (fLego!=0);}
120   AliLego* Lego() const {return fLego;}
121   virtual  void  FinishRun();
122
123   //Quality Assurance
124   Int_t       GetDetIndex(const char * detector);
125   void        SetQACycles(AliQAv1::DETECTORINDEX_t det, const Int_t cycles) {  AliQAManager::QAManager()->SetCycleLength(det, cycles) ; }
126   Bool_t      RunQA() ;
127   Bool_t      SetRunQA(TString detAndAction="ALL:ALL") ; 
128   void        SetQAWriteExpert(AliQAv1::DETECTORINDEX_t det) { AliQAManager::QAManager()->SetWriteExpert(det) ; }  
129   void        SetQARefDefaultStorage(const char* uri);
130   void        InitQA();
131   void        SetEventSpecie(AliRecoParam::EventSpecie_t es) { fEventSpecie = es ; }
132   void        SetWriteQAExpert() { fWriteQAExpertData = kTRUE ; }
133
134   void SetWriteGRPEntry(Bool_t flag = kTRUE) { fWriteGRPEntry = flag; }
135   void WriteGRPEntry();
136   void UseVertexFromCDB()   {fUseVertexFromCDB   = kTRUE;}
137   void UseMagFieldFromGRP() {fUseMagFieldFromGRP = kTRUE;} 
138   void SetGRPWriteLocation(char* loc) {fGRPWriteLocation = loc;}
139
140   void UseTimeStampFromCDB()   {fUseTimeStampFromCDB   = kTRUE;}
141   time_t GenerateTimeStamp() const;
142
143 private:
144
145   AliSimulation(const AliSimulation&); // Not implemented
146   AliSimulation& operator = (const AliSimulation&); // Not implemented
147
148   void           InitCDB();
149   void           InitRunNumber();
150   void           SetCDBLock();
151   Bool_t         SetRunNumberFromData();
152   AliRunLoader*  LoadRun(const char* mode = "UPDATE") const;
153   Int_t          GetNSignalPerBkgrd(Int_t nEvents = 0) const;
154   Bool_t         IsSelected(TString detName, TString& detectors) const;
155
156   static AliSimulation *fgInstance;    // Static pointer to object
157
158   Bool_t         fRunGeneration;      // generate prim. particles or not
159   Bool_t         fRunSimulation;      // simulate detectors (hits) or not
160   Bool_t         fLoadAlignFromCDB;   // Load alignment data from CDB and apply it to geometry or not
161   TString        fLoadAlObjsListOfDets;   // Load alignment data from CDB for these detectors
162   TString        fMakeSDigits;        // create sdigits for these detectors
163   TString        fMakeDigits;         // create digits for these detectors
164   TString        fTriggerConfig;      // run trigger for these descriptors
165   TString        fMakeDigitsFromHits; // create digits from hits for these detectors
166   TString        fWriteRawData;       // write raw data for these detectors
167   TString        fRawDataFileName;    // file name for the raw data file
168   Bool_t         fDeleteIntermediateFiles; // delete intermediate raw data files
169   Bool_t         fWriteSelRawData;    // write detectors raw data in a separate file accoring to the trigger cluster
170   Bool_t         fStopOnError;        // stop or continue on errors
171
172   Int_t          fNEvents;            // number of events
173   TString        fConfigFileName;     // name of the config file
174   TString        fGAliceFileName;     // name of the galice file
175   TObjArray      fEventsPerFile;      // number of events per file for given detectors and data types
176
177   TObjArray*     fBkgrdFileNames;     // names of background files for merging
178   TObjArray*     fAlignObjArray;      // array with the alignment objects to be applied to the geometry
179   Bool_t         fUseBkgrdVertex;     // use vertex from background in case of merging
180   Bool_t         fRegionOfInterest;   // digitization in region of interest
181
182   TString        fCDBUri;                            //! Uri of the default CDB storage
183   TString        fQARefUri;                          //! Uri of the default QA reference storage
184   TObjArray      fSpecCDBUri;                        //! Array with detector specific CDB storages
185   Int_t            fRun;                                     //! Run number, will be passed to CDB and gAlice!!
186   Int_t            fSeed;                        //! Seed for random number generator 
187   Bool_t           fInitCDBCalled;               //! flag to check if CDB storages are already initialized
188   Bool_t           fInitRunNumberCalled;         //! flag to check if run number is already initialized
189   Bool_t           fSetRunNumberFromDataCalled;  //! flag to check if run number is already loaded from run loader
190   
191   Bool_t         fEmbeddingFlag;       // Flag for embedding
192   AliLego       *fLego;                //! Pointer to aliLego object if it exists
193   // OCDB
194   ULong_t         fKey;                //! current CDB key
195   Bool_t          fUseVertexFromCDB;   // Flag to use Vertex from CDB
196   Bool_t          fUseMagFieldFromGRP; // Use magnetic field settings from GRP
197   TString         fGRPWriteLocation;   // Location to write the GRP entry from simulation
198
199   Bool_t          fUseTimeStampFromCDB;// Flag to generate event time-stamps according to SOR/EOR from GRP
200   time_t          fTimeStart;          // SOR time-stamp
201   time_t          fTimeEnd;            // EOR time-stamp
202   
203   //QA stuff
204 //   #ifdef MFT_UPGRADE
205 //   static const Int_t   fgkNDetectors = 16 ;             // number of detectors
206 //   #else
207 //   static const Int_t   fgkNDetectors = 15 ;             // number of detectors
208 //   #endif
209   static const Int_t   fgkNDetectors = 16 ;             // number of detectors    // AU
210   static const char *  fgkDetectorName[fgkNDetectors] ; // names of detectors
211   TString              fQADetectors ;                   // list of detectors to be QA'ed        
212   TString              fQATasks ;                       // list of QA tasks to be performed     
213   Bool_t               fRunQA ;                         // Runs the QA at the end of simulation
214   AliRecoParam::EventSpecie_t fEventSpecie ;            // type of event (see AliRecoParam::EventSpecie_t)
215   Bool_t               fWriteQAExpertData ;             //! decides wheter or not to write experts QA data; true by default
216
217   TString              fGeometryFile;                   // Geometry file
218
219   //HLT
220   TString              fRunHLT;       //! HLT options, HLT is disabled if empty, default='default'
221   AliHLTSimulation*    fpHLT;         //! The instance of HLT simulation
222
223   Bool_t         fWriteGRPEntry;      // Write or not GRP entry corresponding to the settings in Config.C
224
225   ClassDef(AliSimulation, 12)  // class for running generation, simulation and digitization
226 };
227
228 #endif