(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 saw   1.2 // Revision 1.1  2002/07/31 20:07:48  saw
  7           // Add files for ROOT Trees
  8           //
  9 saw   1.1 // Revision 1.1  1999/08/25 13:16:07  saw
 10           // *** empty log message ***
 11           //
 12           #include <stdio.h>
 13           #include <stdlib.h>
 14           
 15           #include <TROOT.h>
 16           #include <TFile.h>
 17           #include <TH1.h>
 18           #include <TH2.h>
 19           #include <TProfile.h>
 20           #include <TRandom.h>
 21           #include <TTree.h>
 22           
 23           TROOT CTP("CTP","CTP Histograms and trees");
 24           
 25           TTree *tree;
 26           TFile *hfile;
 27           
 28           struct thRootFileList {
 29             char *filename;
 30 saw   1.1   TFile *tfile;
 31             int count;
 32             struct thRootFileList *next;
 33           };
 34           typedef struct thRootFileList thRootFileList;
 35           
 36           thRootFileList *rootfilelistp=0;
 37             
 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           }
111 saw   1.2 

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