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