(file) Return to thRootStuff.cpp CVS log (file) (dir) Up to [HallC] / Analyzer / CTP

 1 saw   1.1 //
 2           // thRootStuff.cpp
 3           //    C++ wrapper routines to interface between CTP and Root libraries
 4           //
 5           // $Log: thRootStuff.cpp,v $
 6           // Revision 1.1  1999/08/25 13:16:07  saw
 7           // *** empty log message ***
 8           //
 9           #include <stdio.h>
10           #include <stdlib.h>
11           
12           #include <TROOT.h>
13           #include <TFile.h>
14           #include <TH1.h>
15           #include <TH2.h>
16           #include <TProfile.h>
17           #include <TRandom.h>
18           #include <TTree.h>
19           
20           TROOT CTP("CTP","CTP Histograms and trees");
21           
22 saw   1.1 TTree *tree;
23           TFile *hfile;
24           
25           struct thRootFileList {
26             char *filename;
27             TFile *tfile;
28             int count;
29             struct thRootFileList *next;
30           };
31           typedef struct thRootFileList thRootFileList;
32           
33           thRootFileList *rootfilelistp=0;
34             
35           void *thRoot_TFile(char *filename)
36           {
37             thRootFileList *thisfile,**lastp;
38             thisfile = rootfilelistp;
39             lastp = &rootfilelistp;
40             while(thisfile) {
41               if(strcmp(thisfile->filename,filename)==0) {
42                 thisfile->count++;
43 saw   1.1       return((void *) thisfile);
44               }
45               lastp = &(thisfile->next);
46               thisfile = thisfile->next;
47             }
48             /* Need to check if file has been opened */
49             printf("Tfile(\"%s\",\"RECREATE\",\"CTP ROOT file with trees\")\n",filename);
50             *lastp = (thRootFileList *) malloc(sizeof(thRootFileList));
51             thisfile = *lastp;
52             thisfile->tfile = new TFile(filename,"RECREATE","CTP ROOT file with trees");
53             thisfile->count = 1;
54             thisfile->filename = (char *)malloc(strlen(filename)+1);
55             strcpy(thisfile->filename,filename);
56             return((void *) thisfile);
57           }
58           
59           void *thRoot_TTree(char *treename)
60           {
61             TTree *tree;
62           
63             /* Perhaps Check if a tree exists by this name?? */
64 saw   1.1   printf("new TTree(\"%s\",\"CTP ROOT tree\")\n",treename);
65             tree = new TTree(treename,"CTP ROOT tree");
66             return((void *)tree);
67           }
68           
69           void thRoot_Branch(TTree *tree, char *branchname, void *structp, char *brancharg)
70           {
71             tree->Branch(branchname,structp,brancharg);
72           }
73           
74           void thRoot_Fill(TTree *tree)
75           {
76             tree->Fill();
77           }
78           
79           void thRoot_Write(thRootFileList *file)
80           {
81             (file->tfile)->Flush();
82           }
83           
84           void thRoot_Close(thRootFileList *file)
85 saw   1.1 {
86             TFile *hfile;
87             if(--file->count <= 0){
88               printf("Closing\n");
89               hfile = file->tfile;
90               hfile->Write();
91               hfile->Close();
92             } else {
93               printf("Not Closing\n");
94             }
95           }

Analyzer/Replay: Mark Jones, Documents: Stephen Wood
Powered by
ViewCVS 0.9.2-cvsgraph-1.4.0