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