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