11// This macro must be v5/v6 executable!
22
3- void writecomplex (const std ::string base ){
4-
3+ void writecomplex (const std ::string base )
4+ {
55 const int nentries = 1000 ;
66
77 const double theMax = 1000. ;
88 const double theMin = - theMax ;
99
1010 // The two formats
1111 std ::string rVersion = "ROOT6" ;
12- if (gROOT -> GetVersionInt ()< 60000 )
12+ if (gROOT -> GetVersionInt () < 60000 )
1313 rVersion = "ROOT5" ;
1414
1515 std ::vector < string > ofileNames ;
16- ofileNames .push_back (base + rVersion + ".xml" );
17- ofileNames .push_back (base + rVersion + ".root" );
16+ ofileNames .push_back (base + rVersion + ".xml" );
17+ ofileNames .push_back (base + rVersion + ".root" );
1818
19- for (int iFile = 0 ; iFile < ofileNames .size ();++ iFile ){
19+ for (int iFile = 0 ; iFile < ofileNames .size (); ++ iFile ) {
2020
2121 const char * ofileName = ofileNames [iFile ].c_str ();
2222
@@ -27,36 +27,47 @@ void writecomplex(const std::string base){
2727 TRandom3 rndm (1 );
2828
2929 // Write nentries random complex per type
30- for (int j = 0 ;j < nentries ;++ j ){
31- std ::complex < float > cFloatrw (rndm .Uniform (theMin ,theMax ),rndm .Uniform (theMin ,theMax ));
32- std ::complex < double > cDoublerw (rndm .Uniform (theMin ,theMax ),rndm .Uniform (theMin ,theMax ));
30+ for (int j = 0 ; j < nentries ; ++ j ) {
31+ // Since the order of execution of function arguments are not guarantees by the standard,
32+ // don't pass TRandom3 methods as function arguments, to avoid potential cross-platform differences
33+ auto rnd1 = rndm .Uniform (theMin , theMax );
34+ auto rnd2 = rndm .Uniform (theMin , theMax );
35+ auto rnd3 = rndm .Uniform (theMin , theMax );
36+ auto rnd4 = rndm .Uniform (theMin , theMax );
37+ std ::complex < float > cFloatrw (rnd1 , rnd2 );
38+ std ::complex < double > cDoublerw (rnd3 , rnd4 );
3339
34- ofile -> WriteObjectAny (& cFloatrw ,"complex<float>" ,TString ::Format ("cFloat_%i" ,j ));
35- ofile -> WriteObjectAny (& cDoublerw ,"complex<double>" ,TString ::Format ("cDouble_%i" ,j ));
40+ ofile -> WriteObjectAny (& cFloatrw , "complex<float>" , TString ::Format ("cFloat_%i" , j ));
41+ ofile -> WriteObjectAny (& cDoublerw , "complex<double>" , TString ::Format ("cDouble_%i" , j ));
3642 }
3743
3844 if (iFile != 0 ) { // tree not supported on xml
3945
4046 // Now write a tree with nentries events with one branch per type, split and unsplit
41- std ::complex < float > * cFloat = new std ::complex < float > (0.f ,0.f );
42- std ::complex < double > * cDouble = new std ::complex < double > (0. ,0. );
43- TTree t ("t" ,"Test Tree" );
44- t .Branch ("cFloat_split" , & cFloat ,16000 ,99 );
45- t .Branch ("cFloat" , & cFloat ,16000 ,0 );
46- t .Branch ("cDouble_split" , & cDouble ,16000 ,99 );
47- t .Branch ("cDouble" , & cDouble ,16000 ,0 );
48- for (int j = 0 ;j < nentries ;++ j ){
49- std ::complex < float > cFloatVol (rndm .Uniform (theMin ,theMax ),rndm .Uniform (theMin ,theMax ));
50- std ::complex < double > cDoubleVol (rndm .Uniform (theMin ,theMax ),rndm .Uniform (theMin ,theMax ));
51- * cFloat = cFloatVol ;
52- * cDouble = cDoubleVol ;
47+ std ::complex < float > * cFloat = new std ::complex < float > (0.f , 0.f );
48+ std ::complex < double > * cDouble = new std ::complex < double > (0. , 0. );
49+ TTree t ("t" , "Test Tree" );
50+ t .Branch ("cFloat_split" , & cFloat , 16000 , 99 );
51+ t .Branch ("cFloat" , & cFloat , 16000 , 0 );
52+ t .Branch ("cDouble_split" , & cDouble , 16000 , 99 );
53+ t .Branch ("cDouble" , & cDouble , 16000 , 0 );
54+ for (int j = 0 ; j < nentries ; ++ j ) {
55+ auto rnd11 = rndm .Uniform (theMin , theMax );
56+ auto rnd12 = rndm .Uniform (theMin , theMax );
57+ auto rnd13 = rndm .Uniform (theMin , theMax );
58+ auto rnd14 = rndm .Uniform (theMin , theMax );
59+ std ::complex < float > cFloatVol (rnd11 , rnd12 );
60+ std ::complex < double > cDoubleVol (rnd13 , rnd14 );
61+ * cFloat = cFloatVol ;
62+ * cDouble = cDoubleVol ;
5363 t .Fill ();
5464 }
5565 t .Write ();
5666 }
5767 }
5868}
5969
60- void execwritecomplex (){
70+ void execwritecomplex ()
71+ {
6172 writecomplex ("complexOfile" );
6273}
0 commit comments