Belle II Software development
PrintCollectionsModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/modules/core/PrintCollectionsModule.h>
10
11#include <framework/datastore/StoreObjPtr.h>
12#include <framework/dataobjects/EventMetaData.h>
13
14#include <TClass.h>
15#include <TClonesArray.h>
16
17#include <boost/format.hpp>
18
19using namespace std;
20using namespace Belle2;
21
22//-----------------------------------------------------------------
23// Register the Module
24//-----------------------------------------------------------------
25REG_MODULE(PrintCollections);
26
27//-----------------------------------------------------------------
28// Implementation
29//-----------------------------------------------------------------
30
32{
33 setDescription("Prints the contents of the DataStore in an event, listing all objects and arrays (including size).");
34
35 addParam("printForEvent", m_printForEvent,
36 "Print the collections only for a specific event number. If set to -1 (default) only the collections of the first event will be printed, if set to 0, the collections of all events will be printed, which might be a lot of output.",
38}
39
41
43{
45}
46
48{
49 StoreObjPtr<EventMetaData> eventMetaDataPtr;
50
51 // check if printing only for the first event
52 if (m_printForEvent < 0) {
53 if (m_firstEvent)
54 m_firstEvent = false;
55 else
56 return;
57 }
58 // or for a specific event
59 else if ((m_printForEvent > 0) && ((unsigned int)m_printForEvent != eventMetaDataPtr->getEvent()))
60 return;
61
62 B2INFO("============================================================================");
63 B2INFO("DataStore collections in event " << eventMetaDataPtr->getEvent());
64 B2INFO("============================================================================");
65 B2INFO(boost::format("Type %|20t| Name %|47t| #Entries <Event>"));
67 B2INFO("----------------------------------------------------------------------------");
68 B2INFO(boost::format("Type %|20t| Name %|47t| #Entries <Persistent>"));
70 B2INFO("============================================================================");
71}
72
73
75std::string shorten(std::string className)
76{
77 if (className.compare(0, 8, "Belle2::") == 0) {
78 //we know the experiment name, thanks
79 return className.substr(8);
80 }
81 return className;
82}
83
84//===============================================================
85// Protected methods
86//===============================================================
87
88
90{
91 //-----------------------------
92 //Print the object information
93 //-----------------------------
95 for (auto iter = map.begin(); iter != map.end(); ++iter) {
96 if (iter->second.isArray)
97 continue;
98 const TObject* currCol = iter->second.ptr;
99
100 if (currCol != nullptr) {
101 B2INFO(boost::format("%1% %|20t| %2%") % shorten(currCol->ClassName()) % iter->first);
102 }
103 }
104
105
106 //-----------------------------
107 //Print the array information
108 //-----------------------------
109 for (auto iter = map.begin(); iter != map.end(); ++iter) {
110 if (!iter->second.isArray)
111 continue;
112 const TClonesArray* currCol = dynamic_cast<TClonesArray*>(iter->second.ptr);
113
114 long entries = 0;
115 if (currCol != nullptr)
116 entries = currCol->GetEntriesFast();
117
118 std::string type = shorten(iter->second.objClass->GetName());
119
120 B2INFO(boost::format("%1%[] %|20t| %2% %|47t| %3%") % type % iter->first % entries);
121 }
122 B2INFO("");
123}
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
Definition: DataStore.h:325
EDurability
Durability types.
Definition: DataStore.h:58
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
Definition: DataStore.h:87
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
bool m_firstEvent
boolean to check if the current event is the first encountered
virtual void initialize() override
initialization.
virtual void event() override
Prints information for each collection in the DataStore.
virtual ~PrintCollectionsModule()
Destructor of the module.
int m_printForEvent
Parameter to set the event number for which the collections should be printed.
void printCollections(DataStore::EDurability durability)
Prints information for each collection in the DataStore using the specified durability.
PrintCollectionsModule()
Constructor of the module.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.