52 char const* kNameValueSep =
"=";
56 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << *reinterpret_cast<T*>(iObject.address());
61 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << static_cast<int>(*
reinterpret_cast<char*
>(iObject.address()));
65 void doPrint<unsigned char>(
std::string const& iName, ObjectWithDict
const& iObject,
std::string const& iIndent) {
66 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << static_cast<unsigned int>(*
reinterpret_cast<unsigned char*
>(iObject.address()));
71 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << ((*reinterpret_cast<bool*>(iObject.address()))?
"true":
"false");
74 typedef void(*FunctionType)(
std::string const&, ObjectWithDict
const&, std::string
const&);
75 typedef std::map<std::string, FunctionType> TypeToPrintMap;
78 void addToMap(TypeToPrintMap& iMap) {
79 iMap[
typeid(
T).
name()] = doPrint<T>;
82 bool printAsBuiltin(std::string
const& iName,
83 ObjectWithDict
const& iObject,
84 std::string
const& iIndent) {
85 typedef void(*FunctionType)(std::string
const&, ObjectWithDict
const&, std::string
const&);
86 typedef std::map<std::string, FunctionType> TypeToPrintMap;
87 static TypeToPrintMap s_map;
90 addToMap<bool>(s_map);
91 addToMap<char>(s_map);
92 addToMap<short>(s_map);
94 addToMap<long>(s_map);
95 addToMap<unsigned char>(s_map);
96 addToMap<unsigned short>(s_map);
97 addToMap<unsigned int>(s_map);
98 addToMap<unsigned long>(s_map);
99 addToMap<float>(s_map);
100 addToMap<double>(s_map);
103 TypeToPrintMap::iterator itFound = s_map.find(iObject.typeOf().name());
104 if(itFound == s_map.end()) {
108 itFound->second(iName, iObject, iIndent);
112 bool printAsContainer(std::string
const& iName,
113 ObjectWithDict
const& iObject,
114 std::string
const& iIndent,
115 std::string
const& iIndentDelta);
117 void printObject(std::string
const& iName,
118 ObjectWithDict
const& iObject,
119 std::string
const& iIndent,
120 std::string
const& iIndentDelta) {
121 const std::string& printName = iName;
122 const ObjectWithDict& objectToPrint = iObject;
123 std::string
indent(iIndent);
124 if(iObject.typeOf().isPointer()) {
125 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << formatClassName(iObject.typeOf().name()) << std::hex << iObject.address() <<
std::dec;
126 TypeWithDict pointedType = iObject.typeOf().toType();
129 iObject.address() ==
nullptr) {
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(),
163 member.get(objectToPrint),
167 LogAbsolute(
"EventContent") <<
indent << member.name() <<
" <exception caught(" << iEx.what() <<
")>\n";
172 bool printAsContainer(std::string
const& iName,
173 ObjectWithDict
const& iObject,
174 std::string
const& iIndent,
175 std::string
const& iIndentDelta) {
176 ObjectWithDict sizeObj;
179 FunctionWithDict sizeFunc = iObject.typeOf().functionMemberByName(
"size");
180 assert(sizeFunc.finalReturnType() ==
typeid(size_t));
181 sizeObj = ObjectWithDict(TypeWithDict(
typeid(
size_t)), &temp);
182 sizeFunc.invoke(iObject, &sizeObj);
184 size_t size = *
reinterpret_cast<size_t*
>(sizeObj.address());
185 FunctionWithDict atMember;
187 atMember = iObject.typeOf().functionMemberByName(
"at");
192 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep <<
"[size=" << size <<
"]";
193 ObjectWithDict contained;
194 std::string indexIndent = iIndent + iIndentDelta;
195 TypeWithDict atReturnType(atMember.finalReturnType());
202 bool const isRef = atReturnType.isReference();
203 void* refMemoryBuffer =
nullptr;
208 std::vector<void*>
args;
209 args.push_back(&index);
211 std::ostringstream sizeS;
212 sizeS <<
"[" << index <<
"]";
214 ObjectWithDict refObject(atReturnType, &refMemoryBuffer);
215 atMember.invoke(iObject, &refObject, args);
218 contained = ObjectWithDict(atReturnType, refMemoryBuffer);
220 contained = atReturnType.construct();
221 atMember.invoke(iObject, &contained, args);
225 printObject(sizeS.str(), contained, indexIndent, iIndentDelta);
227 LogAbsolute(
"EventContent") << indexIndent << iName <<
" <exception caught(" 228 << iEx.what() <<
")>\n";
231 contained.destruct(
true);
243 std::string
const& iClassName,
244 std::string
const& iModuleLabel,
245 std::string
const& iInstanceLabel,
246 std::string
const& iProcessName,
247 std::string
const& iIndent,
248 std::string
const& iIndentDelta) {
252 LogAbsolute(
"EventContent") << iIndent <<
" \"" << iClassName <<
"\"" <<
" is an unknown type" << std::endl;
256 iEvent.getByLabel(InputTag(iModuleLabel, iInstanceLabel, iProcessName),
handle);
257 std::string
className = formatClassName(iClassName);
258 printObject(className, *
handle, iIndent, iIndentDelta);
268 void endJob()
override;
290 indentation_(iConfig.getUntrackedParameter(
"indentation",
std::
string(
"++"))),
291 verboseIndentation_(iConfig.getUntrackedParameter(
"verboseIndentation",
std::
string(
" "))),
292 moduleLabels_(iConfig.getUntrackedParameter(
"verboseForModuleLabels",
std::vector<
std::
string>())),
293 verbose_(iConfig.getUntrackedParameter(
"verbose",
false) || !moduleLabels_.
empty()),
294 getModuleLabels_(iConfig.getUntrackedParameter(
"getDataForModuleLabels",
std::vector<
std::
string>())),
295 getData_(iConfig.getUntrackedParameter(
"getData",
false) || !getModuleLabels_.
empty()),
297 listContent_(iConfig.getUntrackedParameter(
"listContent",
true))
305 const std::string kPathStatus(
"edm::PathStatus");
306 const std::string kEndPathStatus(
"edm::EndPathStatus");
340 typedef std::vector<StableProvenance const*> Provenances;
341 Provenances provenances;
347 << provenances.size() <<
" product" << (provenances.size() == 1 ?
"" :
"s")
348 <<
" with friendlyClassName, moduleLabel, productInstanceName and processName:" 353 for(
auto const& provenance : provenances) {
354 std::string
const&
className = provenance->className();
355 const std::string kPathStatus(
"edm::PathStatus");
356 const std::string kEndPathStatus(
"edm::EndPathStatus");
357 if(className == kPathStatus || className == kEndPathStatus) {
360 std::string
const&
friendlyName = provenance->friendlyClassName();
363 std::string
const& modLabel = provenance->moduleLabel();
366 std::string
const&
instanceName = provenance->productInstanceName();
369 std::string
const&
processName = provenance->processName();
377 <<
"\" \"" << instanceName <<
"\" \"" 378 << processName <<
"\"" 379 <<
" (productId = " << provenance->productID() <<
")" 383 std::string
key = friendlyName
385 +
std::string(
"\" + \"") + instanceName +
"\" \"" + processName +
"\"";
396 verboseIndentation_);
400 std::string class_and_label = friendlyName +
"_" + modLabel;
407 LogAbsolute(
"EventContent") << startIndent <<
" \"" << className <<
"\"" <<
" is an unknown type" << std::endl;
425 typedef std::map<std::string, int> nameMap;
427 LogAbsolute(
"EventContent") <<
"\nSummary for key being the concatenation of friendlyClassName, moduleLabel, productInstanceName and processName" << std::endl;
431 LogAbsolute(
"EventContent") << std::setw(6) << it->second <<
" occurrences of key " << it->first << std::endl;
443 descriptions.
setComment(
"This plugin will print a list of all products in the event " 444 "provenance. It also has options to print and/or get each product.");
450 std::string defaultString(
"++");
452 np->
setComment(
"This string is printed at the beginning of every line printed during event processing.");
455 np->
setComment(
"If true, the contents of products are printed.");
459 np->
setComment(
"This string is used to further indent lines when printing the contents of products in verbose mode.");
461 std::vector<std::string> defaultVString;
463 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"verboseForModuleLabels", defaultVString);
464 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are printed.");
467 np->
setComment(
"If true the products will be retrieved using getByLabel.");
469 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"getDataForModuleLabels", defaultVString);
470 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are retrieved by getByLabel.");
473 np->
setComment(
"If true then print a list of all the event content.");
476 descriptions.
add(
"printContent", desc);
std::vector< std::string > getModuleLabels_
void setComment(std::string const &value)
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
~EventContentAnalyzer() override
std::string verboseIndentation_
std::string const & processName() const
std::map< std::string, int > cumulates_
static TypeWithDict byName(std::string const &name)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void analyze(Event const &, EventSetup const &) override
std::string const & className() const
std::string friendlyName(std::string const &iFullName)
std::string const & moduleLabel() const
std::string const & productInstanceName() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TypeID unwrappedTypeID() const
static void fillDescriptions(ConfigurationDescriptions &descriptions)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
void setComment(std::string const &value)
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
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)
T mod(const T &a, const T &b)
static const bool doPrint
EventContentAnalyzer(ParameterSet const &)
std::string className(const T &t)
void getAllStableProvenance(std::vector< StableProvenance const * > &provenances) const