00001
00002
00003
00004
00005 TFile *cernbuild(Int_t get=0) {
00006
00007 Int_t Category;
00008 UInt_t Flag;
00009 Int_t Age;
00010 Int_t Service;
00011 Int_t Children;
00012 Int_t Grade;
00013 Int_t Step;
00014 Int_t Hrweek;
00015 Int_t Cost;
00016 Char_t Division[4];
00017 Char_t Nation[3];
00018
00019
00020
00021 TString filename = "cernstaff.root";
00022 TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
00023 dir.ReplaceAll("cernbuild.C","");
00024 dir.ReplaceAll("/./","/");
00025 FILE *fp = fopen(Form("%scernstaff.dat",dir.Data()),"r");
00026
00027 TFile *hfile = 0;
00028 if (get) {
00029
00030
00031 if (!gSystem->AccessPathName(dir+"cernstaff.root",kFileExists)) {
00032 hfile = TFile::Open(dir+"cernstaff.root");
00033 if (hfile) return hfile;
00034 }
00035
00036 if (!gSystem->AccessPathName("cernstaff.root",kFileExists)) {
00037 hfile = TFile::Open("cernstaff.root");
00038 if (hfile) return hfile;
00039 }
00040 }
00041
00042
00043 if (!gSystem->AccessPathName(dir,kWritePermission)) {
00044 filename = dir+"cernstaff.root";
00045 } else if (!gSystem->AccessPathName(".",kWritePermission)) {
00046
00047 } else {
00048 printf("you must run the script in a directory with write access\n");
00049 return 0;
00050 }
00051 hfile = TFile::Open(filename,"RECREATE");
00052 TTree *tree = new TTree("T","CERN 1988 staff data");
00053 tree->Branch("Category",&Category,"Category/I");
00054 tree->Branch("Flag",&Flag,"Flag/i");
00055 tree->Branch("Age",&Age,"Age/I");
00056 tree->Branch("Service",&Service,"Service/I");
00057 tree->Branch("Children",&Children,"Children/I");
00058 tree->Branch("Grade",&Grade,"Grade/I");
00059 tree->Branch("Step",&Step,"Step/I");
00060 tree->Branch("Hrweek",&Hrweek,"Hrweek/I");
00061 tree->Branch("Cost",&Cost,"Cost/I");
00062 tree->Branch("Division",Division,"Division/C");
00063 tree->Branch("Nation",Nation,"Nation/C");
00064 char line[80];
00065 while (fgets(&line,80,fp)) {
00066 sscanf(&line[0],"%d %d %d %d %d",&Category,&Flag,&Age,&Service,&Children);
00067 sscanf(&line[32],"%d %d %d %d %s %s",&Grade,&Step,&Hrweek,&Cost,Division,Nation);
00068 tree->Fill();
00069 }
00070 tree->Print();
00071 tree->Write();
00072
00073 fclose(fp);
00074 delete hfile;
00075 if (get) {
00076
00077 hfile = TFile::Open(filename);
00078 return hfile;
00079 }
00080 return 0;
00081 }