]>
Commit | Line | Data |
---|---|---|
65fb704d | 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 | ||
acd84897 | 16 | /* $Id$ */ |
65fb704d | 17 | |
18 | /////////////////////////////////////////////////////////////////////////////// | |
af7ba10c | 19 | // Random number class for AliRoot |
20 | // This class allows to have different | |
21 | // random number generator for different | |
22 | // elements of AliRoot // | |
23 | // It also allows saving and retrieving of the random number seeds | |
65fb704d | 24 | /////////////////////////////////////////////////////////////////////////////// |
25 | ||
65fb704d | 26 | #include "TFile.h" |
e2afb3b6 | 27 | #include "TError.h" |
28 | #include "TRandom3.h" | |
29 | #include "TSystem.h" | |
65fb704d | 30 | |
31 | #include "AliRndm.h" | |
21bf7095 | 32 | #include "AliLog.h" |
65fb704d | 33 | |
34 | ClassImp(AliRndm) | |
35 | ||
e2afb3b6 | 36 | //_______________________________________________________________________ |
37 | AliRndm::AliRndm(): | |
7cdba479 | 38 | fRandom(gRandom) |
e2afb3b6 | 39 | { |
40 | // | |
41 | // Default ctor | |
42 | // | |
e2afb3b6 | 43 | } |
44 | ||
45 | //_______________________________________________________________________ | |
46 | AliRndm::AliRndm(const AliRndm& rn): | |
7cdba479 | 47 | fRandom(gRandom) |
e2afb3b6 | 48 | { |
49 | // | |
50 | // Copy constructor | |
51 | // | |
52 | rn.Copy(*this); | |
53 | } | |
54 | ||
55 | //_______________________________________________________________________ | |
56 | void AliRndm::Copy(AliRndm&) const | |
57 | { | |
21bf7095 | 58 | AliFatalClass("Not implemented"); |
e2afb3b6 | 59 | } |
60 | ||
65fb704d | 61 | |
62 | //_____________________________________________________________________________ | |
fea8896f | 63 | void AliRndm::Rndm(Float_t* array, Int_t size) const |
65fb704d | 64 | { |
65 | // | |
66 | // Return an array of n random numbers uniformly distributed | |
67 | // between 0 and 1 not included | |
68 | // | |
69 | for(Int_t i=0; i<size; i++) | |
70 | #ifdef CKNONE | |
71 | array[i]=fRandom->Rndm(); | |
72 | #else | |
73 | do array[i]=fRandom->Rndm(); while(0>=array[i] || array[i]>=1); | |
74 | #endif | |
75 | } | |
76 | ||
65fb704d | 77 | //_____________________________________________________________________________ |
78 | void AliRndm::ReadRandom(const char *filename) | |
79 | { | |
b23a502f | 80 | // |
81 | // Reads saved random generator status from filename | |
82 | // | |
65fb704d | 83 | char *fntmp = gSystem->ExpandPathName(filename); |
88cb7938 | 84 | TFile *file = new TFile(fntmp,"r"); |
65fb704d | 85 | delete [] fntmp; |
86 | if(!file) { | |
21bf7095 | 87 | AliErrorClass(Form("Could not open file %s",filename)); |
65fb704d | 88 | } else { |
89 | if(!fRandom) fRandom = new TRandom(); | |
88cb7938 | 90 | fRandom->Read("Random"); |
65fb704d | 91 | file->Close(); |
92 | delete file; | |
93 | } | |
94 | } | |
95 | ||
96 | //_____________________________________________________________________________ | |
97 | void AliRndm::WriteRandom(const char *filename) const | |
98 | { | |
b23a502f | 99 | // |
100 | // Writes random generator status to filename | |
101 | // | |
65fb704d | 102 | char *fntmp = gSystem->ExpandPathName(filename); |
88cb7938 | 103 | TFile *file = new TFile(fntmp,"new"); |
65fb704d | 104 | delete [] fntmp; |
105 | if(!file) { | |
21bf7095 | 106 | AliErrorClass(Form("Could not open file %s",filename)); |
65fb704d | 107 | } else { |
108 | fRandom->Write(); | |
109 | file->Close(); | |
110 | delete file; | |
111 | } | |
112 | } |