NuOutputWriter Class Reference

#include <NuOutputWriter.h>

List of all members.

Public Member Functions

 NuOutputWriter ()
 ~NuOutputWriter ()
TDirectory * GetDirectory () const
void FillNuEventTree ()
void FillNuMCEventTree ()
void Finish ()
NuEventGetNuEventToFill ()
NuMCEventGetNuMCEventToFill ()
void SetupFile (Int_t run, Int_t subrun)
void SetupFile (const NuConfig &config, std::string prefix)

Private Member Functions

TFile * OpenFile (Int_t run, Int_t subrun, std::string prefix) const
TFile * OpenFile (const NuConfig &config, std::string prefix) const
void SetupNuEventTree ()
void SetupNuMCEventTree ()

Private Attributes

TFile * fFile
NuEventfNuEvent
NuMCEventfNuMCEvent
TTree * fNuEventTree
TTree * fNuMCEventTree
TDirectory * fDirectory

Detailed Description

Definition at line 18 of file NuOutputWriter.h.


Constructor & Destructor Documentation

NuOutputWriter::NuOutputWriter (  ) 

Definition at line 33 of file NuOutputWriter.cxx.

References fDirectory, fFile, fNuEvent, fNuEventTree, fNuMCEvent, fNuMCEventTree, Msg::kDebug, and MSG.

00034 {
00035   MSG("NuOutputWriter",Msg::kDebug)
00036       <<"Running NuOutputWriter Constructor..."<<endl;
00037 
00038   //initialise data members
00039   fFile=0;
00040   fNuEvent=0;
00041   fNuMCEvent=0;
00042   fNuEventTree=0;
00043   fNuMCEventTree=0;
00044   fDirectory=0;
00045   
00046   MSG("NuOutputWriter",Msg::kDebug)
00047       <<"Finished NuOutputWriter Constructor"<<endl;
00048 }

NuOutputWriter::~NuOutputWriter (  ) 

Definition at line 52 of file NuOutputWriter.cxx.

References Msg::kDebug, and MSG.

00053 {
00054   MSG("NuOutputWriter",Msg::kDebug)
00055       <<"Running NuOutputWriter Destructor..."<<endl;
00056   
00057 
00058   MSG("NuOutputWriter",Msg::kDebug)
00059       <<"Finished NuOutputWriter Destructor"<<endl;
00060 }


Member Function Documentation

void NuOutputWriter::FillNuEventTree (  ) 

Definition at line 363 of file NuOutputWriter.cxx.

References fNuEvent, fNuEventTree, NuEvent::index, Msg::kDebug, Msg::kError, and MSG.

Referenced by NuAnalysis::ChargeSeparationOneSnarl(), NuDSTAna::ConcatenateDSTs(), NuDSTAna::MakeCuts(), NuDSTAna::MakeDstPQ(), NuAnalysis::MakeFullDST(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDst2014(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), NuDSTAna::MakeMicroDstNC2012(), NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts(), and NuDSTAna::MakeSelMicroDST().

00364 {
00365   if (!fNuEvent) {
00366     MSG("NuOutputWriter",Msg::kError)
00367       <<"No fNuEvent object to put in tree"<<endl;
00368   }
00369   
00370   MSG("NuOutputWriter",Msg::kDebug)<<"Filling NuEvent Tree..."<<endl; 
00371   
00372   static Int_t counter=0;
00373   fNuEvent->index=counter;//a counter
00374   counter++;//count the number of entries
00375   
00376   //fill the tree
00377   fNuEventTree->Fill();
00378 }

void NuOutputWriter::FillNuMCEventTree (  ) 

Definition at line 382 of file NuOutputWriter.cxx.

References fNuMCEvent, fNuMCEventTree, NuMCEvent::index, Msg::kDebug, Msg::kError, and MSG.

Referenced by NuDSTAna::ConcatenateDSTs(), NuAnalysis::LoopOverTruthInfo(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDst2014(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), NuDSTAna::MakeMicroDstNC2012(), NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts(), and NuDSTAna::MakeSelMicroDST().

00383 {
00384   if (!fNuMCEvent) {
00385     MSG("NuOutputWriter",Msg::kError)
00386       <<"No fNuMCEvent object to put in tree"<<endl;
00387   }
00388   
00389   MSG("NuOutputWriter",Msg::kDebug)<<"Filling NuMCEvent Tree..."<<endl; 
00390   
00391   static Int_t counter=0;
00392   fNuMCEvent->index=counter;//a counter
00393   counter++;//count the number of entries
00394   
00395   //fill the tree
00396   fNuMCEventTree->Fill();
00397 }

void NuOutputWriter::Finish (  ) 

Definition at line 131 of file NuOutputWriter.cxx.

References fDirectory, fFile, Msg::kDebug, Msg::kInfo, and MSG.

Referenced by NuDSTAna::ConcatenateDSTs(), NuDSTAna::MakeCuts(), NuDSTAna::MakeDstPQ(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDst2014(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), NuDSTAna::MakeMicroDstNC2012(), NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts(), NuDSTAna::MakeSelMicroDST(), and NuAnalysis::StoreOrFinishTree().

00132 {
00133   MSG("NuOutputWriter",Msg::kInfo)
00134     <<"Running NuOutputWriter::Finish..."<<endl;
00135   
00136   //store the current gDirectory
00137   TDirectory* tmpd=gDirectory;
00138   MSG("NuOutputWriter",Msg::kDebug)
00139     <<"gDirectory is:"<<endl;
00140   //gDirectory->pwd();
00141   
00142   //set the gDirectory to be the one associated with the file
00143   //opened by this object
00144   //not sure if this is necessary but it is safe
00145   gDirectory=this->fDirectory;
00146  
00147   MSG("NuOutputWriter",Msg::kInfo)
00148     <<"Changing directory to fFile..."<<endl;
00149   fFile->cd();
00150   
00151   MSG("NuOutputWriter",Msg::kInfo)<<"Writing tree..."<<endl;
00152   fFile->Write();//this should pick up any histograms as well
00153   
00154   MSG("NuOutputWriter",Msg::kInfo)
00155     <<"Closing file "<<fFile->GetName()<<" ..."<<endl;
00156   fFile->Close();
00157   
00158   //reset the directory to it's original location
00159   gDirectory=tmpd;
00160   
00161   MSG("NuOutputWriter",Msg::kInfo)
00162     <<"Completed NuOutputWriter::Finish"<<endl;
00163 }

TDirectory* NuOutputWriter::GetDirectory (  )  const [inline]

Definition at line 26 of file NuOutputWriter.h.

References fDirectory.

Referenced by NuAnalysis::StoreOrFinishTree().

00026 {return fDirectory;};

NuEvent & NuOutputWriter::GetNuEventToFill (  ) 
NuMCEvent & NuOutputWriter::GetNuMCEventToFill (  ) 
TFile * NuOutputWriter::OpenFile ( const NuConfig config,
std::string  prefix 
) const [private]

Definition at line 185 of file NuOutputWriter.cxx.

References NuConfig::detector, Form(), ReleaseType::GetMCSubVersion(), ReleaseType::GetRecoSubVersion(), NuConfig::intensity, ReleaseType::IsDaikon(), ReleaseType::IsDogwood(), Detector::kCalDet, Detector::kFar, Msg::kInfo, SimFlag::kMC, Detector::kNear, MSG, NuConfig::releaseType, NuConfig::run, NuConfig::runPeriod, NuConfig::simFlag, and NuConfig::subRun.

00187 {
00188   //call this static function to ensure any histograms created
00189   //after the file is opened are added
00190   TH1::AddDirectory(true);
00191 
00192   //create the tfile pointer to be returned
00193   TFile* outputFile=0;
00194   
00195   //get the environmental variable
00196   char *anaDir=getenv("NUANA_DIR");
00197   
00198   //use a string to hold env instead 
00199   string sAnaDir="";
00200   
00201   if (anaDir!=NULL) {
00202     sAnaDir=anaDir;
00203   }
00204   else {
00205     MSG("NuOutputWriter",Msg::kInfo) 
00206       <<"Environmental variable $NUANA_DIR not set." 
00207       <<" Writing file(s) to current directory"<<endl;
00208     sAnaDir=".";
00209   }
00210   
00211   //convert variables to string
00212   string sRunNumber=Form("%d",config.run);
00213   string sZeros="";
00214   if (config.run>=0 && config.run<10) sZeros="00000000";
00215   else if (config.run>=10 && config.run<100) sZeros="000000";
00216   else if (config.run>=100 && config.run<1000) sZeros="00000";
00217   else if (config.run>=1000 && config.run<10000) sZeros="0000";
00218   else if (config.run>=10000 && config.run<100000) sZeros="000";
00219   else if (config.run>=100000 && config.run<1000000) sZeros="00";
00220   else if (config.run>=1000000 && config.run<10000000) sZeros="0";
00221   else if (config.run>=10000000 && config.run<100000000) sZeros="";
00222   sRunNumber=sZeros+sRunNumber;
00223 
00224   string sSubRunNumber = "s";
00225   if (config.subRun < 10) {sSubRunNumber += "0";}
00226   sSubRunNumber += Form("%d", config.subRun);
00227 
00228   string sDetector="UnknownDet";
00229   if (config.detector==Detector::kNear) {
00230     sDetector="N";
00231     if (config.simFlag==SimFlag::kMC) sDetector="n";
00232   }
00233   else if (config.detector==Detector::kFar) {
00234     sDetector="F";
00235     if (config.simFlag==SimFlag::kMC) sDetector="f";
00236   }
00237   else if (config.detector==Detector::kCalDet) {
00238     sDetector="C";
00239     if (config.simFlag==SimFlag::kMC) sDetector="c";
00240   }
00241   else cout<<"Ahhh, don't know detector="<<config.detector<<endl;
00242   
00243   string sPrefix="";//default
00244   if (prefix!="") sPrefix+=prefix;
00245   string sBase=sAnaDir+"/"+sPrefix;
00246 
00247     if (ReleaseType::IsDaikon(config.releaseType)
00248         && ReleaseType::GetMCSubVersion(config.releaseType)>=7){
00249       sBase += Form("r%d",config.runPeriod);
00250     }
00251     if (SimFlag::kMC == config.simFlag
00252         && Detector::kNear == config.detector
00253         && ReleaseType::IsDogwood(config.releaseType)
00254         && ReleaseType::GetRecoSubVersion(config.releaseType)>=1){
00255       sBase += Form("i%d",config.intensity);
00256     }
00257 
00258   sBase += sDetector;
00259   sBase += sRunNumber;
00260   sBase += sSubRunNumber;
00261   string sFileName=sBase+".root";
00262   
00263   //test if file already exists
00264   ifstream Test(sFileName.c_str());
00265   
00266   //open the appropriate file
00267   if(!Test){
00268     outputFile=new TFile(sFileName.c_str(),"RECREATE");
00269   }
00270   else {
00271     //Need new filename
00272     Int_t fred=1;
00273     while(Test) {
00274       Test.close();
00275       string sAppendage=Form("%d",fred);
00276       sFileName=sBase+"_"+sAppendage+".root";
00277       Test.open(sFileName.c_str());
00278       fred++;
00279     }
00280     outputFile=new TFile(sFileName.c_str(),"NEW");
00281     outputFile->SetCompressionLevel(9);
00282   }
00283   
00284   string sTmp="No File!";
00285   if (outputFile) sTmp=outputFile->GetName();
00286 
00287   MSG("NuOutputWriter",Msg::kInfo) 
00288     <<"Output file opened: "<<sTmp<<endl;
00289   return outputFile;
00290 }

TFile * NuOutputWriter::OpenFile ( Int_t  run,
Int_t  subrun,
std::string  prefix 
) const [private]

Definition at line 294 of file NuOutputWriter.cxx.

References Form(), Msg::kInfo, and MSG.

Referenced by SetupFile().

00296 {
00297   //call this static function to ensure any histograms created
00298   //after the file is opened are added
00299   TH1::AddDirectory(true);
00300 
00301   //create the tfile pointer to be returned
00302   TFile* outputFile=0;
00303   
00304   //get the environmental variable
00305   char *anaDir=getenv("MEUANA_DIR");
00306   
00307   //use a string to hold env instead 
00308   string sAnaDir="";
00309   
00310   if (anaDir!=NULL) {
00311     sAnaDir=anaDir;
00312   }
00313   else {
00314     MSG("NuOutputWriter",Msg::kInfo) 
00315       <<"Environmental variable $MEUANA_DIR not set." 
00316       <<" Writing file(s) to current directory"<<endl;
00317     sAnaDir=".";
00318   }
00319   
00320   //convert variables to string
00321   string sRunNumber=Form("%d",run);
00322   string sSubrunNumber=Form("%d",subrun);
00323   //string sDetector="C";
00324   string sDetector="";
00325   //string sPrefix="h";//default
00326   string sPrefix="";//default
00327   if (prefix!="") sPrefix+=prefix;
00328   string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00329   sBase+="_"+sSubrunNumber;
00330   string sFileName=sBase+".root";
00331   
00332   //test if file already exists
00333   ifstream Test(sFileName.c_str());
00334   
00335   //open the appropriate file
00336   if(!Test){
00337     outputFile=new TFile(sFileName.c_str(),"RECREATE");
00338   }
00339   else {
00340     //Need new filename
00341     Int_t fred=1;
00342     while(Test) {
00343       Test.close();
00344       string sAppendage=Form("%d",fred);
00345       sFileName=sBase+"_"+sAppendage+".root";
00346       Test.open(sFileName.c_str());
00347       fred++;
00348     }
00349     outputFile=new TFile(sFileName.c_str(),"NEW");
00350     outputFile->SetCompressionLevel(9);
00351   }
00352   
00353   string sTmp="No File!";
00354   if (outputFile) sTmp=outputFile->GetName();
00355 
00356   MSG("NuOutputWriter",Msg::kInfo) 
00357     <<"Output file opened: "<<sTmp<<endl;
00358   return outputFile;
00359 }

void NuOutputWriter::SetupFile ( const NuConfig config,
std::string  prefix 
)

Definition at line 78 of file NuOutputWriter.cxx.

References fDirectory, fFile, and OpenFile().

00080 {
00081   //sanity check that the directory is not already set
00082   if (fDirectory!=0) cout<<"Ahhhh, fDirectory already exists"<<endl;
00083 
00084   //open the file
00085   fFile=this->OpenFile(config,prefix);
00086 
00087   //store the TDirectory associated with the file just opened
00088   fDirectory=gDirectory;
00089 }

void NuOutputWriter::SetupFile ( Int_t  run,
Int_t  subrun 
)

Definition at line 64 of file NuOutputWriter.cxx.

References fDirectory, fFile, and OpenFile().

Referenced by NuAnalysis::ChargeSeparationOneSnarl(), NuDSTAna::DoIO(), and NuAnalysis::MakeFullDST().

00065 {
00066   //sanity check that the directory is not already set
00067   if (fDirectory!=0) cout<<"Ahhhh, fDirectory already exists"<<endl;
00068 
00069   //open the file
00070   fFile=this->OpenFile(run,subrun,"NuEvent");
00071   
00072   //store the TDirectory associated with the file just opened
00073   fDirectory=gDirectory;
00074 }

void NuOutputWriter::SetupNuEventTree (  )  [private]

Definition at line 93 of file NuOutputWriter.cxx.

References fDirectory, fNuEvent, fNuEventTree, Msg::kInfo, and MSG.

Referenced by GetNuEventToFill().

00094 {
00095   MSG("NuOutputWriter",Msg::kInfo)
00096     <<"gDirectory is:"<<endl;
00097   gDirectory->pwd();
00098   MSG("NuOutputWriter",Msg::kInfo)
00099     <<"Local stored fDirectory is:"<<endl;
00100   this->fDirectory->pwd();
00101   MSG("NuOutputWriter",Msg::kInfo)
00102     <<"Setting gDirectory=fDirectory"<<endl;
00103   gDirectory=fDirectory;
00104   fNuEventTree=new TTree("s","s");
00105   cout<<"Creating new NuEvent for output to tree"<<endl;
00106   fNuEvent=new NuEvent();
00107   fNuEventTree->Branch("s","NuEvent",&fNuEvent,32000,2);
00108 }

void NuOutputWriter::SetupNuMCEventTree (  )  [private]

Definition at line 112 of file NuOutputWriter.cxx.

References fDirectory, fNuMCEvent, fNuMCEventTree, Msg::kInfo, and MSG.

Referenced by GetNuMCEventToFill().

00113 {
00114   MSG("NuOutputWriter",Msg::kInfo)
00115     <<"gDirectory is:"<<endl;
00116   gDirectory->pwd();
00117   MSG("NuOutputWriter",Msg::kInfo)
00118     <<"Local stored fDirectory is:"<<endl;
00119   this->fDirectory->pwd();
00120   MSG("NuOutputWriter",Msg::kInfo)
00121     <<"Setting gDirectory=fDirectory"<<endl;
00122   gDirectory=fDirectory;
00123   fNuMCEventTree=new TTree("mc","mc");
00124   cout<<"Creating new NuMCEvent for output to tree"<<endl;
00125   fNuMCEvent=new NuMCEvent();
00126   fNuMCEventTree->Branch("mc","NuMCEvent",&fNuMCEvent,32000,2);
00127 }


Member Data Documentation

TDirectory* NuOutputWriter::fDirectory [private]
TFile* NuOutputWriter::fFile [private]

Definition at line 48 of file NuOutputWriter.h.

Referenced by Finish(), NuOutputWriter(), and SetupFile().

TTree* NuOutputWriter::fNuEventTree [private]

Definition at line 51 of file NuOutputWriter.h.

Referenced by FillNuEventTree(), NuOutputWriter(), and SetupNuEventTree().

Definition at line 52 of file NuOutputWriter.h.

Referenced by FillNuMCEventTree(), NuOutputWriter(), and SetupNuMCEventTree().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1