PrintProducts

From Mu2eWiki
Jump to navigation Jump to search

Introduction

This page describes an Offline utility that can be used to print standard mu2e art products and other useful information. An overview of art products and naming is also available.

Print art products

To print the list of products in a file

mu2e -c Print/fcl/dumpDataProducts.fcl

To print the mu2e art products in a file, in a briefer form. Note that this supresses low-momentum particles. example output

mu2e -c Print/fcl/print.fcl

To print the mu2e art products in a file, in a longer form. Everything possible is printed. example output

mu2e -c Print/fcl/printLong.fcl

These fcl can be modfied to only print certain products, certain instances of products, and to supress low-momentum particles. See the printLong.fcl file to see all options.

The print module can be put in a path with other modules. This is particularly useful to see the KalRep contents, which are not persistent.

Each product has a utility class which can be used anywhere in the code. As an example:

#include "Print/inc/CaloClusterPrinter.hh"
CaloClusterPrinter _ccprinter;
...
      auto ih = event.getValidHandle<CaloClusterCollection>(tag);
      _ccprinter.Print(ih);

To print to a separate file

#include "Print/inc/CaloClusterPrinter.hh"
CaloClusterPrinter _ccprinter;

...
  ofstream ofs("file.log");
...
  auto ih = event.getValidHandle<CaloClusterCollection>(tag);
  if(interesting) _ccprinter.Print(ih,ofs);

There are several interfaces:

void Print(art::Event const& event, std::ostream& os = std::cout) override;
void Print(const art::Handle<CaloClusterCollection>& handle, std::ostream& os = std::cout);
void Print(const art::ValidHandle<CaloClusterCollection>& handle, std::ostream& os = std::cout);
void Print(const CaloClusterCollection& coll, std::ostream& os = std::cout);
void Print(const art::Ptr<CaloCluster>& ptr, int ind = -1, std::ostream& os = std::cout);
void Print(const mu2e::CaloCluster& obj, int ind = -1, std::ostream& os = std::cout);

We plan to make sure all products have a simple << operator too.


Print event numbers

To print the run, event and subrun numbers of the file contents

mu2e -c Print/fcl/events.fcl

Or using the native art tool:

file_info_dumper --file-index <file>

To count the runs, events and subruns in the file

mu2e -c Print/fcl/count.fcl

Or using the native art tool:

count_events <file>

To print the piece of the SAM record which is derived from the file

mu2e -c Print/fcl/printSam.fcl

This module fcl can be modified to also print the begin run and subrun numbers. See events.fcl for options.

Other print utilities

This print is very similar dumpDataProducts.fcl, but does not print SubRun products and adds a count of dropped products. It uses the art product (not mu2e) module FileDumperOutput. example output

mu2e -c Print/fcl/fileDumper.fcl

This print will compute the average size of the products in the file. example output

artProductSizes file

Details of fileDumper

The recommended way to get a list of all data products in a Mu2e event-data file is:

 mu2e -c Print/fcl/fileDumper.fcl -s <inputfile> -n <N>

Here is example output. It was created with a command like

mu2e -c Print/fcl/fileDumper.fcl -s data_03.root -n 5

where data_03.root is the output file created by Mu2eG4/test/g4test_03.fcl.

In the example output there is a block of printout for each of the first 5 events. For each data product, the first 4 columns contain the elements of the data product identifier. The fifth column contains the number of entries in each data product, provided that information is available; for most data products this will change from event to event. If the number of entries in the data product is not available, the fifth column will contain a dash or a question mark. The rules are:

  • If the data product class has a member function named size(), the fifth column contains the value returned by calling size().
  • If the data product class does not have a member function named size(), the fifth column contains a dash.
  • The circumstances under which a question mark may appear are discussed below.

Many of the StepPointMC data products have a size of 0; this is normal since g4test_03.fcl creates only a few particles, all of which originate in the stopping target. Therefore the example does not produce particles that cover the full Mu2e apparatus.

Following the printout for the 5 events, there is similar printout describing the data products found in the SubRun record and the Run record.

You can change the behavior of the fourth column, which contains the data type of the data product. The example illustrated shows the full class name. Instead you can choose to display the art "Friendly Classname"; to do so, edit fileDumper.fcl and change the value of the wantProductFullClassName parameter:

dumper : {
      module_type              : FileDumperOutput
      wantProductFullClassName : false
}

You may even ask that both names be printed, which will add an extra column to the output:

dumper : {
      module_type                  : FileDumperOutput
      wantProductFullClassName     : true
      wantProductFriendlyClassName : true
}


You may notice that the file dumper is implemented as an output module, not as an analyzer module. This is due to technical constaints inside art: the code that knows if a data product has a size function, is part of the art::Wrapper<T> class template. The Wrapper of a data product is not accessible to analyzer or producer modules but it is accessible to input and output modules. The code for the FileDumperOutput_module.cc is part of art, not part of Mu2e.


There is subtlety that was missed above concerning data product provenance. The behavior of the file dumper module is that it loops over all provenances found in the provenance registry (not over all of the data products found in the file!). Products may be dropped but their provenance is still in the registry. If a provenance is present in the registry but the corresponding data product is not present in the file, then the last column contains a question mark.

In the example above, there are no provenances without a data product present in the file - so there are no lines that end in a question mark.

An example that contains provenance entries with no corresponding data product can be seen by:

mu2e -c Print/fcl/fileDumper.fcl -n 5 -s \
 /pnfs/mu2e/phy-sim/sim/mu2e/cd3-beam-g4s1-dsregion/0506a/001/307/sim.mu2e.cd3-beam-g4s1-dsregion.0506a.001002_00000005.art

You can look at the output of this command; many of the data products produced by the module labeled g4run were filtered by the g4filter module to produce compressed data products. Most of the products produced by g4run were not written to the output file. More details about how this file was produced are available in Mu2e Doc 3774 .

There are several other optional parameters for the file dumper module:

  • resolveProducts, which has a default value of true. If this is false then the file dumper module will only tell you the size of a data product that has already been loaded into memory by a previously executed module. If this is true, then file dumper module will read all data products into memory and, if they have a size member function, print their size. Setting this flag to true causes slower execution; setting it to false causes the size information to disappear.
  • onlyIfPresent, which has a default value of false. If this is true then file dumper module will only print information about data products that are found in the file; it will skip provenances for which the corresponding data product is not present.
  • onDemandProduction, which has a default value of false. If this is true, and if the data product is not found in the file but the data product can be produced using on-demand reconstruction, then the on-demand reconstruction system will be used to create the data product.