11 #include <framework/modules/core/PrintCollectionsModule.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/dataobjects/EventMetaData.h>
17 #include <TClonesArray.h>
19 #include <boost/format.hpp>
35 setDescription(
"Prints the contents of the DataStore in an event, listing all objects and arrays (including size).");
37 addParam(
"printForEvent", m_printForEvent,
38 "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.",
42 PrintCollectionsModule::~PrintCollectionsModule() =
default;
44 void PrintCollectionsModule::initialize()
49 void PrintCollectionsModule::event()
54 if (m_printForEvent < 0) {
61 else if ((m_printForEvent > 0) && ((
unsigned int)m_printForEvent != eventMetaDataPtr->getEvent()))
64 B2INFO(
"============================================================================");
65 B2INFO(
"DataStore collections in event " << eventMetaDataPtr->getEvent());
66 B2INFO(
"============================================================================");
67 B2INFO(boost::format(
"Type %|20t| Name %|47t| #Entries <Event>"));
68 printCollections(DataStore::c_Event);
69 B2INFO(
"----------------------------------------------------------------------------");
70 B2INFO(boost::format(
"Type %|20t| Name %|47t| #Entries <Persistent>"));
71 printCollections(DataStore::c_Persistent);
72 B2INFO(
"============================================================================");
77 std::string shorten(std::string className)
79 if (className.compare(0, 8,
"Belle2::") == 0) {
81 return className.substr(8);
97 for (
auto iter = map.begin(); iter != map.end(); ++iter) {
98 if (iter->second.isArray)
100 const TObject* currCol = iter->second.ptr;
102 if (currCol !=
nullptr) {
103 B2INFO(boost::format(
"%1% %|20t| %2%") % shorten(currCol->ClassName()) % iter->first);
111 for (
auto iter = map.begin(); iter != map.end(); ++iter) {
112 if (!iter->second.isArray)
114 const TClonesArray* currCol =
dynamic_cast<TClonesArray*
>(iter->second.ptr);
117 if (currCol !=
nullptr)
118 entries = currCol->GetEntriesFast();
120 std::string type = shorten(iter->second.objClass->GetName());
122 B2INFO(boost::format(
"%1%[] %|20t| %2% %|47t| %3%") % type % iter->first % entries);