@@ -8,35 +8,38 @@ HepMC3DataSource::HepMC3DataSource(const SourceConfig& config, size_t source_ind
88 total_entries_ = 0 ;
99 current_entry_index_ = 0 ;
1010 entries_needed_ = 0 ;
11- openInputFiles ();
11+ m_still_to_skip = config_->skip ;
12+ m_current_file = 0 ;
13+ m_total_files = config_->input_files .size ();
14+ openNextFile ();
1215}
1316
1417HepMC3DataSource::~HepMC3DataSource () {
1518 cleanup ();
1619}
1720
18- void HepMC3DataSource::openInputFiles () {
19- if (config_->input_files .empty ()) {
20- throw std::runtime_error ( " No input files specified for source: " + config_->name );
21- }
22-
23- // For now, support only single file (could be extended to support multiple files)
24- if (config_-> input_files . size () > 1 ) {
25- std::cout << " Warning: HepMC3DataSource currently supports only the first input file. "
26- << " Using: " << config_-> input_files [ 0 ] << std::endl;
21+ void HepMC3DataSource::openNextFile () {
22+ if (m_current_file >= config_->input_files .size ()) {
23+ if (! config_->repeat_on_eof ) {
24+ throw std::runtime_error ( " No more input files to process for source: " + config_-> name );
25+ } else {
26+ std::cout << " Reached end of input files for source: " << config_-> name
27+ << " . Repeating from the first file. " << std::endl;
28+ m_current_file = 0 ; // Loop back to the first file if repeat_on_eof is true
29+ }
2730 }
28-
29- const std::string& input_file = config_->input_files [0 ];
30-
31+
32+ const std::string& input_file = config_->input_files [m_current_file ];
33+
3134 // Validate file extension
3235 if (input_file.find (" .hepmc3.tree.root" ) == std::string::npos) {
3336 throw std::runtime_error (
3437 " HepMC3DataSource only supports .hepmc3.tree.root format. Got: " + input_file
3538 );
3639 }
37-
40+
3841 std::cout << " Opening HepMC3 file: " << input_file << std::endl;
39-
42+
4043 // Create ReaderRootTree explicitly for ROOT tree format
4144 reader_ = std::make_shared<HepMC3::ReaderRootTree>(input_file);
4245 if (!reader_) {
@@ -45,27 +48,26 @@ void HepMC3DataSource::openInputFiles() {
4548
4649 // Get entry count directly from TTree
4750 total_entries_ = reader_->m_tree ->GetEntries ();
48-
51+
4952 std::cout << " Found " << total_entries_ << " events in HepMC3 file" << std::endl;
50-
53+
5154 current_entry_index_ = 0 ;
5255
5356 // Skip initial events if specified
54- long long skipN = config_->skip ;
55- if (skipN > 0 ) {
56- std::cout << " Skipping first " << skipN << " events for source " << config_->name << " as per configuration" << std::endl;
57- if (config_->skip >= total_entries_) {
58- if (!config_->repeat_on_eof ) {
59- throw std::runtime_error (" Skip value exceeds total entries in source: " + config_->name );
60- } else {
61- std::cout << " Warning: Skip value exceeds total entries, but repeat_on_eof is true. Will loop back to start after reaching EOF." << std::endl;
62- skipN = skipN % total_entries_; // Wrap around if repeat_on_eof is true
63- }
57+ if (m_still_to_skip > 0 ) {
58+ std::cout << " Skipping first " << m_still_to_skip << " events for source " << config_->name << " as per configuration" << std::endl;
59+ if (m_still_to_skip >= total_entries_) {
60+ std::cout << " Warning: Skip value exceeds total entries, moving to next file." << std::endl;
61+ m_still_to_skip = m_still_to_skip - total_entries_; // Wrap around if repeat_on_eof is true
62+ m_current_file++;
63+ openNextFile (); // Open next file if available
64+ return ;
65+ } else {
66+ reader_->skip (m_still_to_skip);
67+ current_entry_index_ += m_still_to_skip;
68+ m_still_to_skip = 0 ; // Reset skip counter after skipping
6469 }
65- reader_->skip (skipN);
66- current_entry_index_ += skipN;
6770 }
68-
6971}
7072
7173bool HepMC3DataSource::hasMoreEntries () const {
0 commit comments