From 057597a37a61090ea998cf8a9b363fbba07992a7 Mon Sep 17 00:00:00 2001 From: matta <matta@npt> Date: Thu, 6 Jan 2011 22:51:22 +0000 Subject: [PATCH] * Adding new functionality to RootInput Class - Now Can add Friend Tree using a RunToTreat file --- NPLib/IORoot/RootInput.cxx | 71 +++++++++++++++++++++++++++++++++++++- NPLib/IORoot/RootInput.h | 5 +++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/NPLib/IORoot/RootInput.cxx b/NPLib/IORoot/RootInput.cxx index 146c60448..4d00e61e5 100644 --- a/NPLib/IORoot/RootInput.cxx +++ b/NPLib/IORoot/RootInput.cxx @@ -20,6 +20,7 @@ *****************************************************************************/ #include <iostream> +#include <sstream> #include <fstream> #include <limits> @@ -48,10 +49,10 @@ void RootInput::Destroy() } } - // fileNameBase doit etre le nom du TChain. RootInput::RootInput(string configFileName) { + NumberOfFriend = 0; bool CheckTreeName = false; bool CheckRootFileName = false; @@ -110,7 +111,75 @@ RootInput::RootInput(string configFileName) cout << "/////////////////////////////////" << endl; } +void RootInput::AddFriendChain( string RunToAdd) +{ + NumberOfFriend++; + ostringstream suffix_buffer; + suffix_buffer << "_" << NumberOfFriend ; + string suffix = suffix_buffer.str(); + bool CheckTreeName = false; + bool CheckRootFileName = false; + + // Read configuration file Buffer + string lineBuffer, dataBuffer; + + // Open file + ifstream inputConfigFile; + inputConfigFile.open(RunToAdd.c_str()); + + TChain* localChain = new TChain(); + + cout << "/////////////////////////////////" << endl; + cout << "Adding frien to current TChain" << endl; + + if (!inputConfigFile) { + cout << "Run to Add file :" << RunToAdd << " not found " << endl; + return; + } + + else { + while (!inputConfigFile.eof()) { + getline(inputConfigFile, lineBuffer); + + // search for token giving the TTree name + if (lineBuffer.compare(0, 9, "TTreeName") == 0) { + inputConfigFile >> dataBuffer; + // adding suffix to insure uniquity of the chain name + dataBuffer+suffix; + // initialize localChain + localChain->SetName(dataBuffer.c_str()); + CheckTreeName = true ; + } + + // search for token giving the list of Root files to treat + else if (lineBuffer.compare(0, 12, "RootFileName") == 0 && localChain) { + CheckRootFileName = true ; + + while (!inputConfigFile.eof()) { + inputConfigFile >> dataBuffer; + + // ignore comment Line + if (dataBuffer.compare(0, 1, "%") == 0) { + inputConfigFile.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); + } + else if (!inputConfigFile.eof()) { + localChain->Add(dataBuffer.c_str()); + cout << "Adding file " << dataBuffer << " to TChain" << endl; + } + } + } + } + } + + if (!CheckRootFileName || !CheckTreeName) + cout << "WARNING: Token not found for InputTree Declaration : Input Tree has not be Added to the current Chain" << endl; + + else + pRootChain->AddFriend( localChain->GetName() ); + + cout << "/////////////////////////////////" << endl; +} RootInput::~RootInput() { diff --git a/NPLib/IORoot/RootInput.h b/NPLib/IORoot/RootInput.h index 776b0d3b1..c5d76d097 100644 --- a/NPLib/IORoot/RootInput.h +++ b/NPLib/IORoot/RootInput.h @@ -64,10 +64,15 @@ private: static RootInput* instance; public: + // Return the private chain TChain* GetChain() {return pRootChain;}; + + // Add a Friend chain to the input chain + void AddFriendChain( string RunToAdd); private: TChain *pRootChain; + int NumberOfFriend; }; #endif // ROOTINPUT_HH -- GitLab