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