Juggler
Juggling algorithms and event processing using gaudi framework
PodioOutput.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 // Copyright (C) 2022 Whitney Armstrong, Wouter Deconinck
3 
4 #ifndef JUGBASE_PODIOOUTPUT_H
5 #define JUGBASE_PODIOOUTPUT_H
6 
8 #include "GaudiAlg/GaudiAlgorithm.h"
9 #include "podio/CollectionBase.h"
10 
11 #include "TTree.h"
12 
13 #include <vector>
14 #include <gsl/gsl>
15 
16 // forward declarations
17 class TFile;
18 class PodioDataSvc;
19 
20 class PodioOutput : public GaudiAlgorithm {
21 
22 public:
23  /// Constructor.
24  PodioOutput(const std::string& name, ISvcLocator* svcLoc);
25 
26  /// Initialization of PodioOutput. Acquires the data service, creates trees and root file.
27  virtual StatusCode initialize();
28  /// Execute. For the first event creates branches for all collections known to PodioDataSvc and prepares them for
29  /// writing. For the following events it reconnects the branches with collections and prepares them for write.
30  virtual StatusCode execute();
31  /// Finalize. Writes the meta data tree; writes file and cleans up all ROOT-pointers.
32  virtual StatusCode finalize();
33 
34 private:
35  void resetBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections);
36  void createBranches(const std::vector<std::pair<std::string, podio::CollectionBase*>>& collections);
37  /// First event or not
38  bool m_firstEvent;
39  /// Root file name the output is written to
40  Gaudi::Property<std::string> m_filename{this, "filename", "output.root", "Name of the file to create"};
41  /// Commands which output is to be kept
42  Gaudi::Property<std::vector<std::string>> m_outputCommands{
43  this, "outputCommands", {"keep *"}, "A set of commands to declare which collections to keep or drop."};
44  Gaudi::Property<std::string> m_filenameRemote{
45  this, "filenameRemote", "", "An optional file path to copy the outputfile to."};
46  /// Switch for keeping or dropping outputs
47  KeepDropSwitch m_switch;
48  /// Needed for collection ID table
49  PodioDataSvc* m_podioDataSvc;
50  /// The actual ROOT file
51  std::unique_ptr<TFile> m_file;
52  /// The tree to be filled with collections
53  gsl::owner<TTree*> m_datatree;
54  /// The tree to be filled with meta data
55  gsl::owner<TTree*> m_metadatatree;
56  gsl::owner<TTree*> m_runMDtree;
57  gsl::owner<TTree*> m_evtMDtree;
58  gsl::owner<TTree*> m_colMDtree;
59  /// The stored collections
60  std::vector<podio::CollectionBase*> m_storedCollections;
61 };
62 
63 #endif
PodioDataSvc
Definition: PodioDataSvc.h:26
PodioOutput::PodioOutput
PodioOutput(const std::string &name, ISvcLocator *svcLoc)
Constructor.
Definition: PodioOutput.cpp:14
KeepDropSwitch.h
KeepDropSwitch
Definition: KeepDropSwitch.h:19
PodioOutput
Definition: PodioOutput.h:20
PodioOutput::initialize
virtual StatusCode initialize()
Initialization of PodioOutput. Acquires the data service, creates trees and root file.
Definition: PodioOutput.cpp:19
PodioOutput::finalize
virtual StatusCode finalize()
Finalize. Writes the meta data tree; writes file and cleans up all ROOT-pointers.
Definition: PodioOutput.cpp:154
PodioOutput::execute
virtual StatusCode execute()
Definition: PodioOutput.cpp:129