#include <NuOutputWriter.h>
Public Member Functions | |
| NuOutputWriter () | |
| ~NuOutputWriter () | |
| TDirectory * | GetDirectory () const |
| void | FillNuEventTree () |
| void | FillNuMCEventTree () |
| void | Finish () |
| NuEvent & | GetNuEventToFill () |
| NuMCEvent & | GetNuMCEventToFill () |
| 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 |
| NuEvent * | fNuEvent |
| NuMCEvent * | fNuMCEvent |
| TTree * | fNuEventTree |
| TTree * | fNuMCEventTree |
| TDirectory * | fDirectory |
|
|
Definition at line 33 of file NuOutputWriter.cxx. References fDirectory, fFile, fNuEvent, fNuEventTree, fNuMCEvent, fNuMCEventTree, 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 }
|
|
|
Definition at line 52 of file NuOutputWriter.cxx. References 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 }
|
|
|
Definition at line 358 of file NuOutputWriter.cxx. References fNuEvent, fNuEventTree, NuEvent::index, and MSG. Referenced by NuAnalysis::ChargeSeparationOneSnarl(), NuDSTAna::ConcatenateDSTs(), NuDSTAna::MakeDstPQ(), NuAnalysis::MakeFullDST(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDstFakeData(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts(), and NuDSTAna::MakeSelMicroDST(). 00359 {
00360 if (!fNuEvent) {
00361 MSG("NuOutputWriter",Msg::kError)
00362 <<"No fNuEvent object to put in tree"<<endl;
00363 }
00364
00365 MSG("NuOutputWriter",Msg::kDebug)<<"Filling NuEvent Tree..."<<endl;
00366
00367 static Int_t counter=0;
00368 fNuEvent->index=counter;//a counter
00369 counter++;//count the number of entries
00370
00371 //fill the tree
00372 fNuEventTree->Fill();
00373 }
|
|
|
Definition at line 377 of file NuOutputWriter.cxx. References fNuMCEvent, fNuMCEventTree, NuMCEvent::index, and MSG. Referenced by NuDSTAna::ConcatenateDSTs(), NuAnalysis::LoopOverTruthInfo(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDstFakeData(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts(), and NuDSTAna::MakeSelMicroDST(). 00378 {
00379 if (!fNuMCEvent) {
00380 MSG("NuOutputWriter",Msg::kError)
00381 <<"No fNuMCEvent object to put in tree"<<endl;
00382 }
00383
00384 MSG("NuOutputWriter",Msg::kDebug)<<"Filling NuMCEvent Tree..."<<endl;
00385
00386 static Int_t counter=0;
00387 fNuMCEvent->index=counter;//a counter
00388 counter++;//count the number of entries
00389
00390 //fill the tree
00391 fNuMCEventTree->Fill();
00392 }
|
|
|
Definition at line 131 of file NuOutputWriter.cxx. Referenced by NuDSTAna::ConcatenateDSTs(), NuDSTAna::MakeDstPQ(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDstFakeData(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), 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 }
|
|
|
Definition at line 26 of file NuOutputWriter.h. Referenced by NuAnalysis::StoreOrFinishTree(). 00026 {return fDirectory;};
|
|
|
Definition at line 167 of file NuOutputWriter.cxx. References fNuEvent, NuEvent::Reset(), and SetupNuEventTree(). Referenced by NuAnalysis::ChargeSeparationOneSnarl(), NuDSTAna::ConcatenateDSTs(), NuDSTAna::MakeDstPQ(), NuAnalysis::MakeFullDST(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDstFakeData(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts(), and NuDSTAna::MakeSelMicroDST(). 00168 {
00169 if (!fNuEvent) this->SetupNuEventTree();
00170 fNuEvent->Reset();
00171 return *fNuEvent;
00172 }
|
|
|
Definition at line 176 of file NuOutputWriter.cxx. References fNuMCEvent, NuMCEvent::Reset(), and SetupNuMCEventTree(). Referenced by NuDSTAna::ConcatenateDSTs(), NuAnalysis::LoopOverTruthInfo(), NuDSTAna::MakeMicroDST(), NuDSTAna::MakeMicroDst2010(), NuDSTAna::MakeMicroDstFakeData(), NuDSTAna::MakeMicroDstForCSSSystematics(), NuDSTAna::MakeMicroDstHe(), NuDSTAna::MakeMicroDstJJEPresel(), NuDSTAna::MakeMicroDstWithStdCCRecoAndCuts(), and NuDSTAna::MakeSelMicroDST(). 00177 {
00178 if (!fNuMCEvent) this->SetupNuMCEventTree();
00179 fNuMCEvent->Reset();
00180 return *fNuMCEvent;
00181 }
|
|
||||||||||||
|
Definition at line 185 of file NuOutputWriter.cxx. References NuConfig::detector, Form(), ReleaseType::GetMCSubVersion(), ReleaseType::GetRecoSubVersion(), NuConfig::intensity, ReleaseType::IsDaikon(), ReleaseType::IsDogwood(), MSG, NuConfig::releaseType, NuConfig::run, NuConfig::runPeriod, and NuConfig::simFlag. 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 sDetector="UnknownDet";
00225 if (config.detector==Detector::kNear) {
00226 sDetector="N";
00227 if (config.simFlag==SimFlag::kMC) sDetector="n";
00228 }
00229 else if (config.detector==Detector::kFar) {
00230 sDetector="F";
00231 if (config.simFlag==SimFlag::kMC) sDetector="f";
00232 }
00233 else if (config.detector==Detector::kCalDet) {
00234 sDetector="C";
00235 if (config.simFlag==SimFlag::kMC) sDetector="c";
00236 }
00237 else cout<<"Ahhh, don't know detector="<<config.detector<<endl;
00238
00239 string sPrefix="";//default
00240 if (prefix!="") sPrefix+=prefix;
00241 string sBase=sAnaDir+"/"+sPrefix;
00242
00243 if (ReleaseType::IsDaikon(config.releaseType)
00244 && ReleaseType::GetMCSubVersion(config.releaseType)>=7){
00245 sBase += Form("r%d",config.runPeriod);
00246 }
00247 if (SimFlag::kMC == config.simFlag
00248 && Detector::kNear == config.detector
00249 && ReleaseType::IsDogwood(config.releaseType)
00250 && ReleaseType::GetRecoSubVersion(config.releaseType)>=1){
00251 sBase += Form("i%d",config.intensity);
00252 }
00253
00254 sBase += sDetector;
00255 sBase += sRunNumber;
00256 string sFileName=sBase+".root";
00257
00258 //test if file already exists
00259 ifstream Test(sFileName.c_str());
00260
00261 //open the appropriate file
00262 if(!Test){
00263 outputFile=new TFile(sFileName.c_str(),"RECREATE");
00264 }
00265 else {
00266 //Need new filename
00267 Int_t fred=1;
00268 while(Test) {
00269 Test.close();
00270 string sAppendage=Form("%d",fred);
00271 sFileName=sBase+"_"+sAppendage+".root";
00272 Test.open(sFileName.c_str());
00273 fred++;
00274 }
00275 outputFile=new TFile(sFileName.c_str(),"NEW");
00276 outputFile->SetCompressionLevel(9);
00277 }
00278
00279 string sTmp="No File!";
00280 if (outputFile) sTmp=outputFile->GetName();
00281
00282 MSG("NuOutputWriter",Msg::kInfo)
00283 <<"Output file opened: "<<sTmp<<endl;
00284 return outputFile;
00285 }
|
|
||||||||||||||||
|
Definition at line 289 of file NuOutputWriter.cxx. References Form(), MSG, and run(). Referenced by SetupFile(). 00291 {
00292 //call this static function to ensure any histograms created
00293 //after the file is opened are added
00294 TH1::AddDirectory(true);
00295
00296 //create the tfile pointer to be returned
00297 TFile* outputFile=0;
00298
00299 //get the environmental variable
00300 char *anaDir=getenv("MEUANA_DIR");
00301
00302 //use a string to hold env instead
00303 string sAnaDir="";
00304
00305 if (anaDir!=NULL) {
00306 sAnaDir=anaDir;
00307 }
00308 else {
00309 MSG("NuOutputWriter",Msg::kInfo)
00310 <<"Environmental variable $MEUANA_DIR not set."
00311 <<" Writing file(s) to current directory"<<endl;
00312 sAnaDir=".";
00313 }
00314
00315 //convert variables to string
00316 string sRunNumber=Form("%d",run);
00317 string sSubrunNumber=Form("%d",subrun);
00318 //string sDetector="C";
00319 string sDetector="";
00320 //string sPrefix="h";//default
00321 string sPrefix="";//default
00322 if (prefix!="") sPrefix+=prefix;
00323 string sBase=sAnaDir+"/"+sPrefix+sDetector+sRunNumber;
00324 sBase+="_"+sSubrunNumber;
00325 string sFileName=sBase+".root";
00326
00327 //test if file already exists
00328 ifstream Test(sFileName.c_str());
00329
00330 //open the appropriate file
00331 if(!Test){
00332 outputFile=new TFile(sFileName.c_str(),"RECREATE");
00333 }
00334 else {
00335 //Need new filename
00336 Int_t fred=1;
00337 while(Test) {
00338 Test.close();
00339 string sAppendage=Form("%d",fred);
00340 sFileName=sBase+"_"+sAppendage+".root";
00341 Test.open(sFileName.c_str());
00342 fred++;
00343 }
00344 outputFile=new TFile(sFileName.c_str(),"NEW");
00345 outputFile->SetCompressionLevel(9);
00346 }
00347
00348 string sTmp="No File!";
00349 if (outputFile) sTmp=outputFile->GetName();
00350
00351 MSG("NuOutputWriter",Msg::kInfo)
00352 <<"Output file opened: "<<sTmp<<endl;
00353 return outputFile;
00354 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
Definition at line 64 of file NuOutputWriter.cxx. References fDirectory, fFile, OpenFile(), and run(). 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 }
|
|
|
Definition at line 93 of file NuOutputWriter.cxx. References fDirectory, fNuEvent, fNuEventTree, 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 }
|
|
|
Definition at line 112 of file NuOutputWriter.cxx. References fDirectory, fNuMCEvent, fNuMCEventTree, 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 }
|
|
|
Definition at line 53 of file NuOutputWriter.h. Referenced by NuOutputWriter(), SetupFile(), SetupNuEventTree(), and SetupNuMCEventTree(). |
|
|
Definition at line 48 of file NuOutputWriter.h. Referenced by Finish(), NuOutputWriter(), and SetupFile(). |
|
|
Definition at line 49 of file NuOutputWriter.h. Referenced by FillNuEventTree(), GetNuEventToFill(), NuOutputWriter(), and SetupNuEventTree(). |
|
|
Definition at line 51 of file NuOutputWriter.h. Referenced by FillNuEventTree(), NuOutputWriter(), and SetupNuEventTree(). |
|
|
Definition at line 50 of file NuOutputWriter.h. Referenced by FillNuMCEventTree(), GetNuMCEventToFill(), NuOutputWriter(), and SetupNuMCEventTree(). |
|
|
Definition at line 52 of file NuOutputWriter.h. Referenced by FillNuMCEventTree(), NuOutputWriter(), and SetupNuMCEventTree(). |
1.3.9.1