00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string>
00014
00015
00016 #include "midas.h"
00017
00018
00019 #include <TROOT.h>
00020 #include <TPluginManager.h>
00021 #include <TFile.h>
00022 #include <TTree.h>
00023 #include <TBranch.h>
00024
00025
00026 #include "TGlobalData.h"
00027 #include "TSetupData.h"
00028 #include "TVacuumData.h"
00029
00030
00031
00032 INT MTreeOutput_init(void);
00033 INT MTreeOutput_exit(void);
00034 INT MTreeOutput(EVENT_HEADER*, void*);
00035
00036 extern HNDLE hDB;
00037 extern TGlobalData* gData;
00038 extern TSetupData* gSetup;
00039 extern TVacuumData* gVacuum;
00040 extern char *gMiasTreeOutputFileName;
00041
00042 static TFile *fTreeFile = NULL;
00043 static TTree *fEventTree = NULL;
00044 static TBranch *fEventBranch = NULL;
00045 static TTree *fSetupTree = NULL;
00046 static TBranch *fSetupBranch = NULL;
00047 static TTree *fVacuumTree = NULL;
00048 static TBranch *fVacuumBranch = NULL;
00049
00050 ANA_MODULE MTreeOutput_module =
00051 {
00052 "MTreeOutput",
00053 "Peter Winter",
00054 MTreeOutput,
00055 NULL,
00056 NULL,
00057 MTreeOutput_init,
00058 MTreeOutput_exit,
00059 NULL,
00060 0,
00061 NULL,
00062 };
00063
00064 extern TROOT* gROOT;
00065 static bool PLUGIN_LOADED = false;
00066
00069 INT MTreeOutput_init()
00070 {
00071 if (!PLUGIN_LOADED) {
00072 if(gROOT->GetPluginManager()->FindHandler("TVirtualStreamerInfo") == NULL)
00073 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo","*","TStreamerInfo","RIO","TStreamerInfo()");
00074 PLUGIN_LOADED = true;
00075 }
00076
00077 if(gMiasTreeOutputFileName){
00078 fTreeFile = TFile::Open(gMiasTreeOutputFileName, "recreate");
00079 if(!fTreeFile || fTreeFile->IsZombie()){
00080 printf("Could not open tree file %s!\n", gMiasTreeOutputFileName);
00081 return ANA_SKIP;
00082 }
00083 }
00084 fTreeFile->cd();
00085
00086 fEventTree = new TTree("EventTree","All readout channels");
00087 fEventTree->SetAutoSave(300000000);
00088 fEventTree->SetMaxVirtualSize(300000000);
00089 int split = 1;
00090 int bufsize = 64000;
00091 Int_t branchstyle = 1;
00092
00093 if (split < 0) {branchstyle = 0; split = -1-split;}
00094 TTree::SetBranchStyle(branchstyle);
00095
00096 fEventBranch = fEventTree->Branch("Event", "TGlobalData", &gData, bufsize, split);
00097 fEventBranch->SetAutoDelete(kFALSE);
00098
00099
00100 fSetupTree = new TTree("SetupTree","All setup information");
00101 fSetupTree->SetAutoSave(300000000);
00102 fSetupTree->SetMaxVirtualSize(300000000);
00103
00104 fSetupBranch = fSetupTree->Branch("Setup", "TSetupData", &gSetup, bufsize, split);
00105 fSetupBranch->SetAutoDelete(kFALSE);
00106
00107 fSetupTree->Fill();
00108
00109
00110 fVacuumTree = new TTree("VacuumTree","All setup information");
00111 fVacuumTree->SetAutoSave(300000000);
00112 fVacuumTree->SetMaxVirtualSize(300000000);
00113
00114 fVacuumBranch = fVacuumTree->Branch("Vacuum", "TVacuumData", &gVacuum, bufsize, split);
00115 fVacuumBranch->SetAutoDelete(kFALSE);
00116
00117 return SUCCESS;
00118 }
00119
00121 INT MTreeOutput(EVENT_HEADER *pheader, void *pevent)
00122 {
00123 fEventTree->Fill();
00124 fVacuumTree->Fill();
00125 return SUCCESS;
00126 }
00127
00129 INT MTreeOutput_exit()
00130 {
00131 if(fTreeFile){
00132 fTreeFile->Write();
00133 fTreeFile->Close();
00134 }
00135
00136 return SUCCESS;
00137 }
00138