@@ -206,6 +206,8 @@ class CAFMaker : public art::EDProducer {
206206
207207 std::string fSourceFile ;
208208 std::uint32_t fSourceFileHash ;
209+
210+ bool fNewInputFile ;
209211
210212 bool fOverrideRealData ;
211213 bool fFirstInSubRun ;
@@ -223,6 +225,7 @@ class CAFMaker : public art::EDProducer {
223225 double fTotalEvents ;
224226 double fBlindEvents ;
225227 double fPrescaleEvents ;
228+ double fTotalGenEvents ;
226229 std::vector<caf::SRBNBInfo> fBNBInfo ; // /< Store detailed BNB info to save into the first StandardRecord of the output file
227230 std::vector<caf::SRNuMIInfo> fNuMIInfo ; // /< Store detailed NuMI info to save into the first StandardRecord of the output file
228231 std::map<unsigned int ,sbn::BNBSpillInfo> fBNBInfoEventMap ; // /< Store detailed BNB info to save for the particular spills of events
@@ -782,6 +785,7 @@ void CAFMaker::respondToOpenInputFile(const art::FileBlock& fb) {
782785 // so should be less than or equal to 32-bit
783786 fSourceFileHash = static_cast <std::uint32_t >(fSourceFileHashFull );
784787
788+ fNewInputFile = true ;
785789}
786790
787791// ......................................................................
@@ -857,6 +861,18 @@ void CAFMaker::beginRun(art::Run& run) {
857861 fDet = override ;
858862 }
859863
864+ if (std::exchange (fNewInputFile , false )){
865+ for (const art::ProcessConfiguration &process: run.processHistory ()) {
866+ std::optional<fhicl::ParameterSet> gen_config = run.getProcessParameterSet (process.processName ());
867+ if (gen_config && gen_config->has_key (" source" ) && gen_config->has_key (" source.maxEvents" ) && gen_config->has_key (" source.module_type" ) ) {
868+ int max_events = gen_config->get <int >(" source.maxEvents" );
869+ std::string module_type = gen_config->get <std::string>(" source.module_type" );
870+ if (module_type == " EmptyEvent" ) {
871+ fTotalGenEvents += max_events;
872+ }
873+ }
874+ }
875+ }
860876
861877 if (fParams .SystWeightLabels ().empty ()) return ; // no need for globalTree
862878
@@ -1211,6 +1227,7 @@ void CAFMaker::InitializeOutfiles()
12111227 fTotalEvents = 0 ;
12121228 fBlindEvents = 0 ;
12131229 fPrescaleEvents = 0 ;
1230+ fTotalGenEvents = 0 ;
12141231 fIndexInFile = SRHeader::NoSourceIndex;
12151232 fFirstInSubRun = false ;
12161233 fFirstBlindInSubRun = false ;
@@ -2704,11 +2721,11 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27042721// ......................................................................
27052722 void CAFMaker::AddHistogramsToFile (TFile* outfile,bool isBlindPOT = false , bool isPrescalePOT = false ) const
27062723{
2707-
27082724 outfile->cd ();
27092725
27102726 TH1* hPOT = new TH1D (" TotalPOT" , " TotalPOT;; POT" , 1 , 0 , 1 );
27112727 TH1* hEvents = new TH1D (" TotalEvents" , " TotalEvents;; Events" , 1 , 0 , 1 );
2728+ TH1* hGen = new TH1D (" TotalGenEvents" , " TotalGenEvents;; Events" , 1 , 0 , 1 );
27122729
27132730 if (isBlindPOT) {
27142731 hPOT->Fill (0.5 ,fTotalPOT *(1 -(1 /fParams .PrescaleFactor ()))*GetBlindPOTScale ());
@@ -2720,13 +2737,15 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27202737 hPOT->Fill (0.5 ,fTotalPOT );
27212738 }
27222739 hEvents->Fill (0.5 ,fTotalEvents );
2740+ hGen->Fill (0.5 ,fTotalGenEvents );
27232741
27242742 hPOT->Write ();
27252743 hEvents->Write ();
2744+ hGen->Write ();
27262745
27272746 if (fParams .CreateBlindedCAF ()) {
27282747 TH1*hBlindEvents = new TH1D (" BlindEvents" , " BlindEvents;; Events" , 1 , 0 , 1 );
2729- TH1* hPrescaleEvents = new TH1D (" PrescaleEvents" , " PrescaleEvents;; Events" , 1 , 0 , 1 );
2748+ TH1*hPrescaleEvents = new TH1D (" PrescaleEvents" , " PrescaleEvents;; Events" , 1 , 0 , 1 );
27302749 hBlindEvents->Fill (0.5 , fBlindEvents );
27312750 hPrescaleEvents->Fill (0.5 , fPrescaleEvents );
27322751 hBlindEvents->Write ();
@@ -2736,29 +2755,26 @@ void CAFMaker::endSubRun(art::SubRun& sr) {
27362755
27372756// ......................................................................
27382757void CAFMaker::endJob () {
2739- if (fTotalEvents == 0 ) {
27402758
2741- std::cerr << " No events processed in this file. Aborting rather than "
2742- " produce an empty CAF."
2759+ // Only produce empty recTree/GenieTree since it relies on non-zero art events.
2760+ // Still want to keep POT histograms.
2761+ if (fTotalEvents == 0 ) {
2762+ std::cerr << " No events processed in this file. Producing empty recTree/GenieTree."
27432763 << std::endl;
2744- // n.b. changed abort() to return so that eny exceptions thrown during startup
2745- // still get printed to the user by art
2746- return ;
27472764 }
27482765
2749-
2750-
27512766 if (fFile ){
2752-
27532767 AddHistogramsToFile (fFile );
2754- fRecTree ->SetDirectory (fFile );
2755- if (fGenieTree ){
2756- fGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2757- fGenieTree ->SetDirectory (fFile );
2758- }
2759- if (fParams .CreateBlindedCAF ()) {
2760- fRecTreeb ->SetDirectory (fFileb );
2761- fRecTreep ->SetDirectory (fFilep );
2768+ if (fTotalEvents > 0 ) {
2769+ if (fGenieTree ){
2770+ fGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2771+ fGenieTree ->SetDirectory (fFile );
2772+ }
2773+ fRecTree ->SetDirectory (fFile );
2774+ if (fParams .CreateBlindedCAF ()) {
2775+ fRecTreeb ->SetDirectory (fFileb );
2776+ fRecTreep ->SetDirectory (fFilep );
2777+ }
27622778 }
27632779 fFile ->cd ();
27642780 fFile ->Write ();
@@ -2774,17 +2790,19 @@ void CAFMaker::endJob() {
27742790 }
27752791
27762792 if (fFlatFile ){
2777-
27782793 AddHistogramsToFile (fFlatFile );
2779- fFlatTree ->SetDirectory (fFlatFile );
2780- if (fFlatGenieTree ){
2781- fFlatGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2782- fFlatGenieTree ->SetDirectory (fFlatFile );
2783- }
2784- if (fParams .CreateBlindedCAF () && fFlatFileb ) {
2785- fFlatTreeb ->SetDirectory (fFlatFileb );
2786- fFlatTreep ->SetDirectory (fFlatFilep );
2794+ if (fTotalEvents > 0 ) {
2795+ if (fFlatGenieTree ){
2796+ fFlatGenieTree ->BuildIndex (" SourceFileHash" , " GENIEEntry" );
2797+ fFlatGenieTree ->SetDirectory (fFlatFile );
2798+ }
2799+ fFlatTree ->SetDirectory (fFlatFile );
2800+ if (fParams .CreateBlindedCAF () && fFlatFileb ) {
2801+ fFlatTreeb ->SetDirectory (fFlatFileb );
2802+ fFlatTreep ->SetDirectory (fFlatFilep );
2803+ }
27872804 }
2805+
27882806 fFlatFile ->cd ();
27892807 fFlatFile ->Write ();
27902808 if (fParams .CreateBlindedCAF ()) {
0 commit comments