Index: /trunk/CHANGELOG
===================================================================
--- /trunk/CHANGELOG	(revision 465)
+++ /trunk/CHANGELOG	(revision 466)
@@ -6,4 +6,5 @@
      (input event files, detector card, trigger card, beam files, particle table)
    - it is now possible to read "delphes root files" as an input for Delphes (GEN tree)
+   - bug fix: number of events to process is correct event if multiple files in the inputlist
 
  /-----------------------------------------\
Index: /trunk/src/HEPEVTConverter.cc
===================================================================
--- /trunk/src/HEPEVTConverter.cc	(revision 465)
+++ /trunk/src/HEPEVTConverter.cc	(revision 466)
@@ -57,6 +57,4 @@
 //------------------------------------------------------------------------------
 
-//Nevents not yet implemented! 08.03.2009
-
 HEPTreeReader::HEPTreeReader(TTree *tree, HEPEvent *event) : fChain(tree), fCurrentTree(-1), fEvent(event)
 {
@@ -174,4 +172,5 @@
 {
   string buffer;
+  int nevt_already_processed=0;
 
   gROOT->SetBatch(); 
@@ -190,5 +189,5 @@
   while(1)
     {
-      
+      if (Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed 
       TChain *chain = new TChain("h101");
       infile >> buffer;
@@ -203,5 +202,5 @@
         else checking_the_file.close();
 
-      if(!infile.good()) break;
+      if(!infile.good()) break;  // end of the list
       chain->Add(buffer.c_str());
       
@@ -214,8 +213,9 @@
       
       TRootC::GenParticle *element;
-      allEntries = (Nevt<0)?allEntries:min((int)allEntries,Nevt); // do not miss the "+1"  
+      allEntries = (Nevt<0)?allEntries:min((int)allEntries,Nevt);
       // Loop over all events
       for(entry = 0; entry < allEntries; ++entry)
 	{
+          if (Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed
 	  // Load selected branches with data from specified event
 	  treeReader->ReadEntry(entry);
@@ -253,4 +253,5 @@
 	    }
 	  treeWriter->Fill();
+	  ++nevt_already_processed;
 	}
       delete chain;
Index: /trunk/src/HepMCConverter.cc
===================================================================
--- /trunk/src/HepMCConverter.cc	(revision 465)
+++ /trunk/src/HepMCConverter.cc	(revision 466)
@@ -270,5 +270,7 @@
   // generated particles from HEPEVT
   ExRootTreeBranch *branchGenParticle = treeWriter->NewBranch("Particle", TRootC::GenParticle::Class());
-  
+ 
+  int nevt_already_processed=0;
+ 
   // Open a stream connected to an event file:
   ifstream infile(inputFileList.c_str());
@@ -285,5 +287,7 @@
     {
       infile >> filename;
-      if(!infile.good()) break;
+      if(!infile.good()) break; // end of listfile reached
+      if (Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed   
+
       ifstream checking_the_file(filename.c_str());
       if(!checking_the_file.good()) 
@@ -305,4 +309,5 @@
 	{
           if(Nevt>0 && entry>=Nevt) break;
+	  if(Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed
 
 	  treeWriter->Clear();
@@ -314,4 +319,5 @@
 	  treeWriter->Fill();
 	  ++entry;
+          ++nevt_already_processed;
         }
     }
@@ -322,5 +328,2 @@
 }
 
-
-
-
Index: /trunk/src/LHEFConverter.cc
===================================================================
--- /trunk/src/LHEFConverter.cc	(revision 465)
+++ /trunk/src/LHEFConverter.cc	(revision 466)
@@ -171,4 +171,6 @@
   ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootLHEFParticle::Class());
   //ExRootTreeBranch *branchParticle = treeWriter->NewBranch("Particle", TRootC::GenParticle::Class());
+
+  int nevt_already_processed=0;
   
   // Open a stream connected to an event file:
@@ -186,4 +188,6 @@
       infile >> filename;
       if(!infile.good()) break;
+      if (Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed
+
         ifstream checking_the_file(filename.c_str());
         if(!checking_the_file.good()) 
@@ -206,4 +210,5 @@
 	  Long64_t entry = 0;
 	  while(inputReader->readEvent()) {
+	      if (Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed
 	      treeWriter->Clear();
 	      AnalyseEvent(inputReader, branchEvent, entry + 1);
@@ -211,4 +216,5 @@
 	      treeWriter->Fill();
 	      ++entry;
+              ++nevt_already_processed;
               if(allEntries<entry+1) break;
 	  }
Index: /trunk/src/STDHEPConverter.cc
===================================================================
--- /trunk/src/STDHEPConverter.cc	(revision 465)
+++ /trunk/src/STDHEPConverter.cc	(revision 466)
@@ -60,10 +60,6 @@
 //---------------------------------------------------------------------------
 
-void STDHEPConverter::AnalyseParticles(ExRootTreeBranch *branch)
-{
-  int Nmax = -1;  // useless for the moment -- should be changed in order
-  if(Nmax>0) Nmax = min(Nmax,myhepevt.nhep); // to use Nevt in DataConverter
-  else Nmax = myhepevt.nhep;
-
+void STDHEPConverter::AnalyseParticles(ExRootTreeBranch *branch) 
+{
   TRootC::GenParticle *element;
 
@@ -72,5 +68,5 @@
   Int_t number;
 
-  for(number = 0; number < Nmax; ++number)
+  for(number = 0; number < myhepevt.nhep; ++number)
   {
     element = static_cast<TRootC::GenParticle*>(branch->NewEntry());
@@ -119,5 +115,5 @@
   int ierr, entryType;
   int istr = 0;
-  int nevt = 0;
+  int nevt = 0, nevt_already_processed=0;
 
   ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputFileName, "GEN");
@@ -136,28 +132,29 @@
                     << left  << setw(20) << inputFileList                    <<""
                     << right << setw(19) <<"for input **"<<""<<endl;
-
       exit(1);
     }
+
+  // Parsing the input list
   while(1)
     {
       infile >> filename;
-      if(!infile.good()) break;
-        ifstream checking_the_file(filename.c_str());
-        if(!checking_the_file.good()) 
-           { 
+      if(!infile.good()) break; // end of the list
+      if (Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed
+
+      ifstream checking_the_file(filename.c_str());
+      if(!checking_the_file.good()) { 
              cerr << left  << setw(30) <<"**   ERROR: Can't find file  "<<""
                   << left  << setw(20) << filename                      <<""
                   << right << setw(19) <<"for input **"<<""<<endl;
              continue;
-           }
-        else checking_the_file.close();
+       } else checking_the_file.close();
       
       ierr = StdHepXdrReadInit(const_cast<char*>(filename.c_str()), &nevt, istr);
-      
-      if(ierr != 0)
-	{
+
+      if(ierr != 0) {
           cerr <<"**                ERROR: Can't open file for input                 **"<<endl;
 	  break;
-	}
+      }
+
 
       Long64_t allEntries = (Nevt<0)?nevt:min(nevt,Nevt+1); // do not miss the "+1"
@@ -170,39 +167,35 @@
 	    {
 	      ierr = StdHepXdrRead(&entryType, istr);
+              if (Nevt>0 && nevt_already_processed >=Nevt) break; // enough events already processed
 	      
-	      if(ierr != 0)
-		{
+	      if(ierr != 0) {
                   cerr << left  << setw(49) <<"**   ERROR: Unexpected end of file after"<<""
                        << left  << setw(10) << entry                                    <<""
                        << right << setw(10) <<"entries **"<<""<<endl;
 		  break;
-		}
+	      } // if error
 	      
 	      // analyse only entries with standard HEPEVT common block
-	      if(entryType == 1)
-		{
+	      if(entryType == 1) {
 		  // add empty events for missing event numbers
-		  while(recordNumber < myhepevt.nevhep)
-		    {
+		  while(recordNumber < myhepevt.nevhep) {
 		      treeWriter->Clear();
 		      AnalyseEvent(branchGenEvent, recordNumber);
 		      treeWriter->Fill();
 		      ++recordNumber;
-		    }
+	      	      ++nevt_already_processed;
+		  } // while
 		  
 		  treeWriter->Clear();
-		  
 		  AnalyseEvent(branchGenEvent, myhepevt.nevhep);
 		  AnalyseParticles(branchGenParticle);
-		  
 		  treeWriter->Fill();
-		  
 		  ++recordNumber;
-		  
-		}
-	    }
-	}
+	      	  ++nevt_already_processed;
+		} // if
+	    } // for
+	} // if allEntries >0
       StdHepXdrEnd(istr);
-    }
+    } // while inputlist not empty
   treeWriter->Write();
   
