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