38 saw 1.2 extern "C" void *thRoot_TFile(char *filename);
39
40 extern "C" void *thRoot_TTree(char *treename);
41
42 extern "C" void thRoot_Branch(TTree *tree, char *branchname, void *structp, char *brancharg);
43
44 extern "C" void thRoot_Fill(TTree *tree);
45
46 extern "C" void thRoot_Write(thRootFileList *file);
47
48 extern "C" void thRoot_Close(thRootFileList *file);
49
|
50 saw 1.1 void *thRoot_TFile(char *filename)
51 {
52 thRootFileList *thisfile,**lastp;
53 thisfile = rootfilelistp;
54 lastp = &rootfilelistp;
55 while(thisfile) {
56 if(strcmp(thisfile->filename,filename)==0) {
57 thisfile->count++;
58 return((void *) thisfile);
59 }
60 lastp = &(thisfile->next);
61 thisfile = thisfile->next;
62 }
63 /* Need to check if file has been opened */
64 printf("Tfile(\"%s\",\"RECREATE\",\"CTP ROOT file with trees\")\n",filename);
65 *lastp = (thRootFileList *) malloc(sizeof(thRootFileList));
66 thisfile = *lastp;
67 thisfile->tfile = new TFile(filename,"RECREATE","CTP ROOT file with trees");
68 thisfile->count = 1;
69 thisfile->filename = (char *)malloc(strlen(filename)+1);
70 strcpy(thisfile->filename,filename);
71 saw 1.1 return((void *) thisfile);
72 }
73
74 void *thRoot_TTree(char *treename)
75 {
76 TTree *tree;
77
78 /* Perhaps Check if a tree exists by this name?? */
79 printf("new TTree(\"%s\",\"CTP ROOT tree\")\n",treename);
80 tree = new TTree(treename,"CTP ROOT tree");
81 return((void *)tree);
82 }
83
84 void thRoot_Branch(TTree *tree, char *branchname, void *structp, char *brancharg)
85 {
86 tree->Branch(branchname,structp,brancharg);
87 }
88
89 void thRoot_Fill(TTree *tree)
90 {
91 tree->Fill();
92 saw 1.1 }
93
94 void thRoot_Write(thRootFileList *file)
95 {
96 (file->tfile)->Flush();
97 }
98
99 void thRoot_Close(thRootFileList *file)
100 {
101 TFile *hfile;
102 if(--file->count <= 0){
103 printf("Closing\n");
104 hfile = file->tfile;
105 hfile->Write();
106 hfile->Close();
107 } else {
108 printf("Not Closing\n");
109 }
110 }
|