@@ -369,6 +369,70 @@ namespace larcv {
369369 LARCV_DEBUG () << " Current input tree index: " << _in_tree_index << std::endl;
370370 return true ;
371371 }
372+
373+
374+ bool IOManager::save_entry (const std::string& type, const std::string& producer)
375+ {
376+ LARCV_DEBUG () << " start" << std::endl;
377+
378+ if (!_prepared) {
379+ LARCV_CRITICAL () << " Cannot be called before initialize()!" << std::endl;
380+ throw larbys ();
381+ }
382+
383+ if (_io_mode == kREAD ) {
384+ LARCV_ERROR () << " Cannot save in READ mode..." << std::endl;
385+ return false ;
386+ }
387+
388+ TTree* current_tree = nullptr ;
389+ EventBase* current_product = nullptr ;
390+
391+ auto prod_name = ProducerName_t (type, producer);
392+ std::string tree_name = prod_name.first + " _" + prod_name.second + " _tree" ;
393+ // Find the tree by name
394+ for (size_t i = 0 ; i < _out_tree_v.size (); ++i) {
395+ if (!_out_tree_v[i]) break ;
396+ if (std::string (_out_tree_v[i]->GetName ()) == tree_name) {
397+ current_tree = _out_tree_v[i];
398+ current_product = _product_ptr_v[i];
399+ break ;
400+ }
401+ }
402+
403+ if (!current_tree) {
404+ LARCV_ERROR () << " Tree with name \" " << tree_name << " \" not found!" << std::endl;
405+ return false ;
406+ }
407+
408+ LARCV_INFO () << " Saving new entry in current tree " << current_tree->GetName () << std::endl;
409+
410+ set_id ();
411+
412+ // Update event ID if not set externally
413+ if (!_set_event_id.valid ()) {
414+ current_product->_run = _event_id.run ();
415+ current_product->_subrun = _event_id.subrun ();
416+ current_product->_event = _event_id.event ();
417+ }
418+
419+ // Fill the current tree
420+ current_tree->Fill ();
421+
422+ // Clear the product data
423+ current_product->clear ();
424+
425+ // Clear event ID
426+ _event_id.clear ();
427+ _set_event_id.clear ();
428+
429+ _out_tree_entries += 1 ;
430+ _out_tree_index += 1 ;
431+
432+ return true ;
433+ }
434+
435+
372436
373437 bool IOManager::save_entry ()
374438 {
@@ -441,15 +505,14 @@ namespace larcv {
441505 p->clear ();
442506 }
443507 }
444-
445508 clear_entry ();
446509
447510 _out_tree_entries += 1 ;
448511 _out_tree_index += 1 ;
449512
450513 return true ;
451514 }
452-
515+
453516 void IOManager::clear_entry ()
454517 {
455518 for (auto & p : _product_ptr_v) {
@@ -553,7 +616,7 @@ namespace larcv {
553616 __ioman_mtx.unlock ();
554617 return _product_ptr_v[id];
555618 }
556-
619+
557620 void IOManager::set_id (const size_t run, const size_t subrun, const size_t event) {
558621
559622 if (_io_mode == kREAD ) {
@@ -574,7 +637,7 @@ namespace larcv {
574637 _set_event_id = tmp;
575638
576639 }
577-
640+
578641 void IOManager::set_id () {
579642 LARCV_DEBUG () << " start" << std::endl;
580643
@@ -605,7 +668,7 @@ namespace larcv {
605668
606669 }
607670 }
608-
671+
609672 void IOManager::finalize ()
610673 {
611674 LARCV_DEBUG () << " start" << std::endl;
@@ -630,7 +693,7 @@ namespace larcv {
630693 LARCV_NORMAL () << " Writing " << t->GetName () << " with " << t->GetEntries () << " entries" << std::endl;
631694 t->Write ();
632695 }
633- }
696+ }
634697 LARCV_NORMAL () << " Closing output file" << std::endl;
635698 _out_file->Close ();
636699 _out_file = nullptr ;
0 commit comments