51 char const* kNameValueSep =
"=";
55 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep
56 << *
reinterpret_cast<T*
>(iObject.address());
61 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep
62 <<
static_cast<int>(*
reinterpret_cast<char*
>(iObject.address()));
66 void doPrint<unsigned char>(
std::string const& iName, ObjectWithDict
const& iObject,
std::string const& iIndent) {
67 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep
68 <<
static_cast<unsigned int>(
69 *
reinterpret_cast<unsigned char*
>(iObject.address()));
74 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep
75 << ((*
reinterpret_cast<bool*
>(iObject.address())) ?
"true" :
"false");
78 typedef void (*FunctionType)(
std::string const&, ObjectWithDict
const&, std::string
const&);
79 typedef std::map<std::string, FunctionType> TypeToPrintMap;
82 void addToMap(TypeToPrintMap& iMap) {
83 iMap[
typeid(
T).
name()] = doPrint<T>;
86 bool printAsBuiltin(std::string
const& iName, ObjectWithDict
const& iObject, std::string
const& iIndent) {
87 typedef void (*FunctionType)(std::string
const&, ObjectWithDict
const&, std::string
const&);
88 typedef std::map<std::string, FunctionType> TypeToPrintMap;
89 static TypeToPrintMap s_map;
92 addToMap<bool>(s_map);
93 addToMap<char>(s_map);
94 addToMap<short>(s_map);
96 addToMap<long>(s_map);
97 addToMap<unsigned char>(s_map);
98 addToMap<unsigned short>(s_map);
99 addToMap<unsigned int>(s_map);
100 addToMap<unsigned long>(s_map);
101 addToMap<float>(s_map);
102 addToMap<double>(s_map);
105 TypeToPrintMap::iterator itFound = s_map.find(iObject.typeOf().name());
106 if (itFound == s_map.end()) {
109 itFound->second(iName, iObject, iIndent);
113 bool printAsContainer(std::string
const& iName,
114 ObjectWithDict
const& iObject,
115 std::string
const& iIndent,
116 std::string
const& iIndentDelta);
118 void printObject(std::string
const& iName,
119 ObjectWithDict
const& iObject,
120 std::string
const& iIndent,
121 std::string
const& iIndentDelta) {
122 const std::string& printName = iName;
123 const ObjectWithDict& objectToPrint = iObject;
124 std::string
indent(iIndent);
125 if (iObject.typeOf().isPointer()) {
126 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << formatClassName(iObject.typeOf().name())
127 << std::hex << iObject.address() <<
std::dec;
128 TypeWithDict pointedType = iObject.typeOf().toType();
142 std::string typeName(objectToPrint.typeOf().name());
143 if (typeName.empty()) {
144 typeName =
"<unknown>";
147 if (printAsBuiltin(printName, objectToPrint,
indent)) {
150 if (printAsContainer(printName, objectToPrint,
indent, iIndentDelta)) {
154 LogAbsolute(
"EventContent") <<
indent << printName <<
" " << formatClassName(typeName);
157 TypeDataMembers dataMembers(objectToPrint.typeOf());
158 for (
auto const& dataMember : dataMembers) {
159 MemberWithDict
const member(dataMember);
162 printObject(member.name(), member.get(objectToPrint),
indent, iIndentDelta);
164 LogAbsolute(
"EventContent") <<
indent << member.name() <<
" <exception caught(" << iEx.what() <<
")>\n";
169 bool printAsContainer(std::string
const& iName,
170 ObjectWithDict
const& iObject,
171 std::string
const& iIndent,
172 std::string
const& iIndentDelta) {
173 ObjectWithDict sizeObj;
176 FunctionWithDict sizeFunc = iObject.typeOf().functionMemberByName(
"size");
177 assert(sizeFunc.finalReturnType() ==
typeid(size_t));
178 sizeObj = ObjectWithDict(TypeWithDict(
typeid(
size_t)), &temp);
179 sizeFunc.invoke(iObject, &sizeObj);
181 size_t size = *
reinterpret_cast<size_t*
>(sizeObj.address());
182 FunctionWithDict atMember;
184 atMember = iObject.typeOf().functionMemberByName(
"at");
189 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep <<
"[size=" << size <<
"]";
190 ObjectWithDict contained;
191 std::string indexIndent = iIndent + iIndentDelta;
192 TypeWithDict atReturnType(atMember.finalReturnType());
199 bool const isRef = atReturnType.isReference();
200 void* refMemoryBuffer =
nullptr;
205 std::vector<void*>
args;
206 args.push_back(&index);
208 std::ostringstream sizeS;
209 sizeS <<
"[" << index <<
"]";
211 ObjectWithDict refObject(atReturnType, &refMemoryBuffer);
212 atMember.invoke(iObject, &refObject, args);
215 contained = ObjectWithDict(atReturnType, refMemoryBuffer);
217 contained = atReturnType.construct();
218 atMember.invoke(iObject, &contained, args);
222 printObject(sizeS.str(), contained, indexIndent, iIndentDelta);
224 LogAbsolute(
"EventContent") << indexIndent << iName <<
" <exception caught(" << iEx.what() <<
")>\n";
227 contained.destruct(
true);
239 std::string
const& iClassName,
240 std::string
const& iModuleLabel,
241 std::string
const& iInstanceLabel,
242 std::string
const& iProcessName,
243 std::string
const& iIndent,
244 std::string
const& iIndentDelta) {
248 LogAbsolute(
"EventContent") << iIndent <<
" \"" << iClassName <<
"\"" 249 <<
" is an unknown type" << std::endl;
253 iEvent.getByLabel(InputTag(iModuleLabel, iInstanceLabel, iProcessName),
handle);
254 std::string
className = formatClassName(iClassName);
255 printObject(className, *
handle, iIndent, iIndentDelta);
265 void endJob()
override;
287 : indentation_(iConfig.getUntrackedParameter(
"indentation",
std::
string(
"++"))),
288 verboseIndentation_(iConfig.getUntrackedParameter(
"verboseIndentation",
std::
string(
" "))),
289 moduleLabels_(iConfig.getUntrackedParameter(
"verboseForModuleLabels",
std::vector<
std::
string>())),
290 verbose_(iConfig.getUntrackedParameter(
"verbose",
false) || !moduleLabels_.
empty()),
291 getModuleLabels_(iConfig.getUntrackedParameter(
"getDataForModuleLabels",
std::vector<
std::
string>())),
292 getData_(iConfig.getUntrackedParameter(
"getData",
false) || !getModuleLabels_.
empty()),
294 listContent_(iConfig.getUntrackedParameter(
"listContent",
true)),
295 listProvenance_(iConfig.getUntrackedParameter(
"listProvenance",
false)) {
302 const std::string kPathStatus(
"edm::PathStatus");
303 const std::string kEndPathStatus(
"edm::EndPathStatus");
332 typedef std::vector<StableProvenance const*> Provenances;
333 Provenances provenances;
340 << provenances.size() <<
" product" << (provenances.size() == 1 ?
"" :
"s")
341 <<
" with friendlyClassName, moduleLabel, productInstanceName and processName:" 346 for (
auto const& provenance : provenances) {
347 std::string
const&
className = provenance->className();
348 const std::string kPathStatus(
"edm::PathStatus");
349 const std::string kEndPathStatus(
"edm::EndPathStatus");
350 if (className == kPathStatus || className == kEndPathStatus) {
353 std::string
const&
friendlyName = provenance->friendlyClassName();
356 std::string
const& modLabel = provenance->moduleLabel();
359 std::string
const&
instanceName = provenance->productInstanceName();
362 std::string
const&
processName = provenance->processName();
368 <<
"\" \"" << processName <<
"\"" 369 <<
" (productId = " << provenance->productID() <<
")" << std::endl;
372 auto const& prov = iEvent.
getProvenance(provenance->branchID());
374 if (productProvenance) {
375 const bool isAlias = productProvenance->
branchID() != provenance->branchID();
376 std::string aliasForModLabel;
379 aliasForModLabel = iEvent.
getProvenance(productProvenance->branchID()).moduleLabel();
380 LogAbsolute(
"EventContent") <<
"Is an alias for " << aliasForModLabel;
383 if (processHistory) {
385 if (pc.processName() == prov.processName()) {
407 "\" \"" + processName +
"\"";
412 printObject(iEvent, className, modLabel, instanceName, processName, startIndent, verboseIndentation_);
416 std::string class_and_label = friendlyName +
"_" + modLabel;
422 LogAbsolute(
"EventContent") << startIndent <<
" \"" << className <<
"\"" 423 <<
" is an unknown type" << std::endl;
437 typedef std::map<std::string, int> nameMap;
439 LogAbsolute(
"EventContent") <<
"\nSummary for key being the concatenation of friendlyClassName, moduleLabel, " 440 "productInstanceName and processName" 442 for (nameMap::const_iterator it =
cumulates_.begin(), itEnd =
cumulates_.end(); it != itEnd; ++it) {
443 LogAbsolute(
"EventContent") << std::setw(6) << it->second <<
" occurrences of key " << it->first << std::endl;
454 "This plugin will print a list of all products in the event " 455 "provenance. It also has options to print and/or get each product.");
461 std::string defaultString(
"++");
463 np->
setComment(
"This string is printed at the beginning of every line printed during event processing.");
466 np->
setComment(
"If true, the contents of products are printed.");
471 "This string is used to further indent lines when printing the contents of products in verbose mode.");
473 std::vector<std::string> defaultVString;
475 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"verboseForModuleLabels", defaultVString);
476 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are printed.");
479 np->
setComment(
"If true the products will be retrieved using getByLabel.");
481 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"getDataForModuleLabels", defaultVString);
483 "If this vector is not empty, then only products with module labels on this list are retrieved by getByLabel.");
486 np->
setComment(
"If true then print a list of all the event content.");
489 np->
setComment(
"If true, and if listContent or verbose is true, print provenance information for each product");
491 descriptions.
add(
"printContent", desc);
std::vector< std::string > getModuleLabels_
void setComment(std::string const &value)
BranchID const & branchID() const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
~EventContentAnalyzer() override
std::string verboseIndentation_
std::string const & processName() const
std::map< std::string, int > cumulates_
ProductProvenance const * productProvenance() const
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
static TypeWithDict byName(std::string const &name)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void analyze(Event const &, EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
std::string const & className() const
std::string friendlyName(std::string const &iFullName)
std::string const & moduleLabel() const
std::string const & productInstanceName() const
TypeID unwrappedTypeID() const
bool getMapped(key_type const &k, value_type &result) const
static void fillDescriptions(ConfigurationDescriptions &descriptions)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
void setComment(std::string const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
ParameterSet const & getParameterSet(std::string const &) const
std::vector< std::string > moduleLabels_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
bool binary_search_all(ForwardSequence const &s, Datum const &d)
wrappers for std::binary_search
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
Provenance getProvenance(BranchID const &theID) const
T mod(const T &a, const T &b)
static const bool doPrint
EventContentAnalyzer(ParameterSet const &)
static Registry * instance()
std::string className(const T &t)
void getAllStableProvenance(std::vector< StableProvenance const * > &provenances) const