From 0c898bbca075e3a6c477764d4c0640bbceae7fff Mon Sep 17 00:00:00 2001
From: zoujh <zoujh@ihep.ac.cn>
Date: Wed, 18 Sep 2019 16:56:48 +0800
Subject: [PATCH] support reading a file list in LCIODataSvc

---
 FWCore/FWCore/LCIODataSvc.h           |  2 ++
 FWCore/src/components/LCIODataSvc.cpp | 25 +++++++++++++++++--------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/FWCore/FWCore/LCIODataSvc.h b/FWCore/FWCore/LCIODataSvc.h
index 9627a8b7..180f7b8d 100644
--- a/FWCore/FWCore/LCIODataSvc.h
+++ b/FWCore/FWCore/LCIODataSvc.h
@@ -80,6 +80,8 @@ private:
   int m_eventNum{0};
   /// Number of events in the file / to process
   int m_eventMax{-1};
+  /// the current file index in the m_filenames vector
+  int m_fileIndex{0};
 
 
   SmartIF<IConversionSvc> m_cnvSvc;
diff --git a/FWCore/src/components/LCIODataSvc.cpp b/FWCore/src/components/LCIODataSvc.cpp
index f31e1361..681890e1 100644
--- a/FWCore/src/components/LCIODataSvc.cpp
+++ b/FWCore/src/components/LCIODataSvc.cpp
@@ -34,11 +34,10 @@ StatusCode LCIODataSvc::initialize() {
   }
 
   if (m_filenames.size() > 0) {
-    if (m_filenames[0] != "") {
-      m_reader->open(m_filenames);
-      m_eventMax = m_reader->getNumberOfEvents();
-    }
+    m_reader->open(m_filenames[0]);
+    m_eventMax = m_reader->getNumberOfEvents();
   }
+
   return status;
 }
 /// Service reinitialisation
@@ -48,6 +47,9 @@ StatusCode LCIODataSvc::reinitialize() {
 }
 /// Service finalization
 StatusCode LCIODataSvc::finalize() {
+  m_reader->close();
+  delete m_reader;
+  m_reader = nullptr;
   m_cnvSvc = 0;  // release
   DataSvc::finalize().ignore();
   return StatusCode::SUCCESS;
@@ -75,10 +77,17 @@ void LCIODataSvc::endOfRead() {
     // m_provider.clearCaches();
     // m_reader.endOfEvent();
     if ( ++m_eventNum >= m_eventMax ) {
-      info() << "Reached end of file with event " << m_eventMax << endmsg;
-      IEventProcessor* eventProcessor;
-      service("ApplicationMgr", eventProcessor);
-      eventProcessor->stopRun();
+      if ( ++m_fileIndex < m_filenames.size() ) {  // move to next file
+        m_reader->close();
+        m_reader->open( m_filenames[m_fileIndex] );
+        m_eventMax += m_reader->getNumberOfEvents();
+      }
+      else {  // reach to the end of the file list
+        info() << "Reached end of file with event " << m_eventMax << endmsg;
+        IEventProcessor* eventProcessor;
+        service("ApplicationMgr", eventProcessor);
+        eventProcessor->stopRun();
+      }
     }
   }
   evt = nullptr;
-- 
GitLab