From a110ff5d6109307015fb46bc3920cfcf76badcd1 Mon Sep 17 00:00:00 2001
From: Greg <gchristian@tamu.edu>
Date: Thu, 26 Oct 2017 11:16:50 -0500
Subject: [PATCH] Added option to specify the first entry to analyze for
 npanalysis, not just the total number.

Also fixed minor bug - in the event loops the loop variable was unsigned int.
Really it should be unsigned long.
---
 NPLib/Core/NPOptionManager.cxx |  6 +++++-
 NPLib/Core/NPOptionManager.h   |  2 ++
 NPLib/Utility/npanalysis.cxx   | 13 ++++++++-----
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/NPLib/Core/NPOptionManager.cxx b/NPLib/Core/NPOptionManager.cxx
index c78716c93..eb522e198 100644
--- a/NPLib/Core/NPOptionManager.cxx
+++ b/NPLib/Core/NPOptionManager.cxx
@@ -67,6 +67,7 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){
   fLastAnyFile = false;
   fVerboseLevel               = 1;
   fNumberOfEntryToAnalyse     = -1;
+	fFirstEntryToAnalyse        = 0;
   fDisableAllBranchOption = false;
   fInputPhysicalTreeOption = false;
   fGenerateHistoOption = false ;
@@ -140,6 +141,8 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){
 
     else if (argument == "-L")                                    fNumberOfEntryToAnalyse = atoi(argv[++i]) ;
 
+		else if (argument == "-F")                                    fFirstEntryToAnalyse = atoi(argv[++i]);
+
     else if (argument == "--last-sim")                            fLastSimFile = true ;
 
     else if (argument == "--last-phy")                            fLastPhyFile = true ;
@@ -366,7 +369,7 @@ void NPOptionManager::DisplayHelp(){
   cout << "\t--output -O <arg>\t\tSet arg as the Output File Name (output tree)" << endl ;
   cout << "\t--tree-name <arg>\t\tSet arg as the Output Tree Name " << endl ;
   cout << "\t--verbose -V <arg>\t\tSet the verbose level, 0 for nothing, 1 for normal printout."<<endl;
- cout  << "\t\t\t\t\tError and warning are not affected" << endl ;
+	cout  << "\t\t\t\t\tError and warning are not affected" << endl ;
   cout << endl << "NPAnalysis only:"<<endl;
   cout << "\t--run -R <arg>\t\t\tSet arg as the run to read file list" << endl  ;
   cout << "\t--cal -C <arg>\t\t\tSet arg as the calibration file list" << endl ;
@@ -375,6 +378,7 @@ void NPOptionManager::DisplayHelp(){
   cout << "\t--check-histo -CH\t\tCheck if the Histogram looks ok and change there color if not" << endl ;
   cout << "\t--input-physical -IP\t\tConsider the Input file is containing Physics Class." << endl  ;
   cout << "\t-L <arg>\t\t\tLimit the number of events to be analysed to arg" << endl ;
+  cout << "\t-F <arg>\t\t\tSet the first event to analyse to arg (analysis goes from F -> L+F)" << endl ;
   cout << "\t--last-sim\t\t\tIgnore the list of Run to treat if any and analysed the last simulated file" << endl ;
   cout << "\t--last-phy\t\t\tIgnore the list of Run to treat if any and analysed the last Physics file" << endl ;
   cout << "\t--last-res\t\t\tIgnore the list of Run to treat if any and analysed the last Result file" << endl ;
diff --git a/NPLib/Core/NPOptionManager.h b/NPLib/Core/NPOptionManager.h
index dc9941ceb..eaece873a 100644
--- a/NPLib/Core/NPOptionManager.h
+++ b/NPLib/Core/NPOptionManager.h
@@ -105,6 +105,7 @@ class NPOptionManager{
       bool   GetG4BatchMode()              {return fG4BatchMode;}
       int    GetVerboseLevel()             {return fVerboseLevel;}
       int    GetNumberOfEntryToAnalyse()   {return fNumberOfEntryToAnalyse;} 
+      int    GetFirstEntryToAnalyse()      {return fFirstEntryToAnalyse;} 
       string GetSharedLibExtension()       {return fSharedLibExtension;}     
       string GetLastFile();                 
       
@@ -143,6 +144,7 @@ class NPOptionManager{
       bool   fLastAnyFile;
       int    fVerboseLevel; // 0 for not talk, 1 for talking
       int    fNumberOfEntryToAnalyse; // use to limit the number of analysed in NPA
+      int    fFirstEntryToAnalyse; // use to set the first event analysed in NPA (total: fFirstEntryToAnalyse -> fFirstEntryToAnalyse + fNumberOfEntryToAnalyse)
       string fSharedLibExtension; // lib extension is platform dependent
       string fG4MacroPath; // Path to a geant4 macro to execute at start of nps
       bool fG4BatchMode; // Execute geant4 in batch mode, running the given macro
diff --git a/NPLib/Utility/npanalysis.cxx b/NPLib/Utility/npanalysis.cxx
index 061bfbb41..3863a46d5 100644
--- a/NPLib/Utility/npanalysis.cxx
+++ b/NPLib/Utility/npanalysis.cxx
@@ -102,10 +102,13 @@ int main(int argc , char** argv){
   std::cout << std::endl << "///////// Starting Analysis ///////// "<< std::endl;
   TChain* Chain = RootInput:: getInstance()->GetChain();
   myOptionManager->GetNumberOfEntryToAnalyse();
- 
+
+	unsigned long first_entry = myOptionManager->GetFirstEntryToAnalyse(); // defaults to zero
   unsigned long nentries = Chain->GetEntries();
   if(nentries> myOptionManager->GetNumberOfEntryToAnalyse() && myOptionManager->GetNumberOfEntryToAnalyse()>0)
-    nentries = myOptionManager->GetNumberOfEntryToAnalyse() ; 
+    nentries = myOptionManager->GetNumberOfEntryToAnalyse() ;
+	if(nentries + first_entry > Chain->GetEntries()) {nentries = first_entry+Chain->GetEntries();}
+	
 
   TString ChainName = Chain->GetName();
   std::cout << " Number of Event to be treated : " << nentries << " on chain " << ChainName << std::endl;
@@ -124,7 +127,7 @@ int main(int argc , char** argv){
 
   if(UserAnalysis==NULL){ 
     if(!IsPhysics){
-      for (unsigned int i = 0 ; i < nentries; i++) { 
+      for (unsigned long i = first_entry ; i < nentries + first_entry; i++) { 
         // Get the raw Data
         Chain -> GetEntry(i);
         // Build the current event
@@ -166,7 +169,7 @@ int main(int argc , char** argv){
 
   else{
     if(!IsPhysics){ 
-      for (unsigned int i = 0 ; i < nentries; i++) { 
+      for (unsigned long i = first_entry ; i < nentries + first_entry; i++) { 
         // Get the raw Data
 	//cout << "!" << endl;
         Chain -> GetEntry(i);
@@ -207,7 +210,7 @@ int main(int argc , char** argv){
     }
 
     else{
-      for (unsigned int i = 0 ; i < nentries; i++) { 
+			for (unsigned long i = first_entry ; i < nentries + first_entry; i++) { 
         // Get the Physics Data
         Chain -> GetEntry(i);
         // User Analysis
-- 
GitLab