53 char const* kNameValueSep =
"=";
57 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << *reinterpret_cast<T*>(iObject.address());
62 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << 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 << static_cast<unsigned int>(*
reinterpret_cast<unsigned char*
>(iObject.address()));
72 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << ((*reinterpret_cast<bool*>(iObject.address()))?
"true":
"false");
75 typedef void(*FunctionType)(
std::string const&, ObjectWithDict
const&, std::string
const&);
76 typedef std::map<std::string, FunctionType> TypeToPrintMap;
79 void addToMap(TypeToPrintMap& iMap) {
80 iMap[
typeid(
T).
name()] = doPrint<T>;
83 bool printAsBuiltin(std::string
const& iName,
84 ObjectWithDict
const& iObject,
85 std::string
const& iIndent) {
86 typedef void(*FunctionType)(std::string
const&, ObjectWithDict
const&, std::string
const&);
87 typedef std::map<std::string, FunctionType> TypeToPrintMap;
88 static TypeToPrintMap s_map;
91 addToMap<bool>(s_map);
92 addToMap<char>(s_map);
93 addToMap<short>(s_map);
95 addToMap<long>(s_map);
96 addToMap<unsigned char>(s_map);
97 addToMap<unsigned short>(s_map);
98 addToMap<unsigned int>(s_map);
99 addToMap<unsigned long>(s_map);
100 addToMap<float>(s_map);
101 addToMap<double>(s_map);
104 TypeToPrintMap::iterator itFound = s_map.find(iObject.typeOf().name());
105 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()) << std::hex << iObject.address() <<
std::dec;
127 TypeWithDict pointedType = iObject.typeOf().toType();
130 iObject.address() ==
nullptr) {
143 std::string typeName(objectToPrint.typeOf().name());
144 if(typeName.empty()) {
145 typeName =
"<unknown>";
148 if(printAsBuiltin(printName, objectToPrint,
indent)) {
151 if(printAsContainer(printName, objectToPrint,
indent, iIndentDelta)) {
155 LogAbsolute(
"EventContent") <<
indent << printName <<
" " << formatClassName(typeName);
158 TypeDataMembers dataMembers(objectToPrint.typeOf());
159 for(
auto const& dataMember : dataMembers) {
160 MemberWithDict
const member(dataMember);
163 printObject(member.name(),
164 member.get(objectToPrint),
168 LogAbsolute(
"EventContent") <<
indent << member.name() <<
" <exception caught(" << iEx.what() <<
")>\n";
173 bool printAsContainer(std::string
const& iName,
174 ObjectWithDict
const& iObject,
175 std::string
const& iIndent,
176 std::string
const& iIndentDelta) {
177 ObjectWithDict sizeObj;
180 FunctionWithDict sizeFunc = iObject.typeOf().functionMemberByName(
"size");
181 assert(sizeFunc.finalReturnType() ==
typeid(size_t));
182 sizeObj = ObjectWithDict(TypeWithDict(
typeid(
size_t)), &temp);
183 sizeFunc.invoke(iObject, &sizeObj);
185 size_t size = *
reinterpret_cast<size_t*
>(sizeObj.address());
186 FunctionWithDict atMember;
188 atMember = iObject.typeOf().functionMemberByName(
"at");
193 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep <<
"[size=" << size <<
"]";
194 ObjectWithDict contained;
195 std::string indexIndent = iIndent + iIndentDelta;
196 TypeWithDict atReturnType(atMember.finalReturnType());
203 bool const isRef = atReturnType.isReference();
204 void* refMemoryBuffer =
nullptr;
209 std::vector<void*>
args;
210 args.push_back(&index);
212 std::ostringstream sizeS;
213 sizeS <<
"[" << index <<
"]";
215 ObjectWithDict refObject(atReturnType, &refMemoryBuffer);
216 atMember.invoke(iObject, &refObject, args);
219 contained = ObjectWithDict(atReturnType, refMemoryBuffer);
221 contained = atReturnType.construct();
222 atMember.invoke(iObject, &contained, args);
226 printObject(sizeS.str(), contained, indexIndent, iIndentDelta);
228 LogAbsolute(
"EventContent") << indexIndent << iName <<
" <exception caught(" 229 << iEx.what() <<
")>\n";
232 contained.destruct(
true);
244 std::string
const& iClassName,
245 std::string
const& iModuleLabel,
246 std::string
const& iInstanceLabel,
247 std::string
const& iProcessName,
248 std::string
const& iIndent,
249 std::string
const& iIndentDelta) {
253 LogAbsolute(
"EventContent") << iIndent <<
" \"" << iClassName <<
"\"" <<
" is an unknown type" << std::endl;
257 iEvent.getByLabel(InputTag(iModuleLabel, iInstanceLabel, iProcessName),
handle);
258 std::string
className = formatClassName(iClassName);
259 printObject(className, *
handle, iIndent, iIndentDelta);
269 void endJob()
override;
292 indentation_(iConfig.getUntrackedParameter(
"indentation",
std::
string(
"++"))),
293 verboseIndentation_(iConfig.getUntrackedParameter(
"verboseIndentation",
std::
string(
" "))),
294 moduleLabels_(iConfig.getUntrackedParameter(
"verboseForModuleLabels",
std::vector<
std::
string>())),
295 verbose_(iConfig.getUntrackedParameter(
"verbose",
false) || !moduleLabels_.
empty()),
296 getModuleLabels_(iConfig.getUntrackedParameter(
"getDataForModuleLabels",
std::vector<
std::
string>())),
297 getData_(iConfig.getUntrackedParameter(
"getData",
false) || !getModuleLabels_.
empty()),
299 listContent_(iConfig.getUntrackedParameter(
"listContent",
true)),
300 listProvenance_(iConfig.getUntrackedParameter(
"listProvenance",
false))
308 const std::string kPathStatus(
"edm::PathStatus");
309 const std::string kEndPathStatus(
"edm::EndPathStatus");
343 typedef std::vector<StableProvenance const*> Provenances;
344 Provenances provenances;
350 << provenances.size() <<
" product" << (provenances.size() == 1 ?
"" :
"s")
351 <<
" with friendlyClassName, moduleLabel, productInstanceName and processName:" 356 for(
auto const& provenance : provenances) {
357 std::string
const&
className = provenance->className();
358 const std::string kPathStatus(
"edm::PathStatus");
359 const std::string kEndPathStatus(
"edm::EndPathStatus");
360 if(className == kPathStatus || className == kEndPathStatus) {
363 std::string
const&
friendlyName = provenance->friendlyClassName();
366 std::string
const& modLabel = provenance->moduleLabel();
369 std::string
const&
instanceName = provenance->productInstanceName();
372 std::string
const&
processName = provenance->processName();
380 <<
"\" \"" << instanceName <<
"\" \"" 381 << processName <<
"\"" 382 <<
" (productId = " << provenance->productID() <<
")" 386 auto const& prov = iEvent.
getProvenance(provenance->branchID());
388 if(productProvenance) {
389 const bool isAlias = productProvenance->
branchID() != provenance->branchID();
390 std::string aliasForModLabel;
393 aliasForModLabel = iEvent.
getProvenance(productProvenance->branchID()).moduleLabel();
394 LogAbsolute(
"EventContent") <<
"Is an alias for " << aliasForModLabel;
399 if(pc.processName() == prov.processName()) {
420 std::string
key = friendlyName
422 +
std::string(
"\" + \"") + instanceName +
"\" \"" + processName +
"\"";
433 verboseIndentation_);
437 std::string class_and_label = friendlyName +
"_" + modLabel;
444 LogAbsolute(
"EventContent") << startIndent <<
" \"" << className <<
"\"" <<
" is an unknown type" << std::endl;
462 typedef std::map<std::string, int> nameMap;
464 LogAbsolute(
"EventContent") <<
"\nSummary for key being the concatenation of friendlyClassName, moduleLabel, productInstanceName and processName" << std::endl;
468 LogAbsolute(
"EventContent") << std::setw(6) << it->second <<
" occurrences of key " << it->first << std::endl;
480 descriptions.
setComment(
"This plugin will print a list of all products in the event " 481 "provenance. It also has options to print and/or get each product.");
487 std::string defaultString(
"++");
489 np->
setComment(
"This string is printed at the beginning of every line printed during event processing.");
492 np->
setComment(
"If true, the contents of products are printed.");
496 np->
setComment(
"This string is used to further indent lines when printing the contents of products in verbose mode.");
498 std::vector<std::string> defaultVString;
500 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"verboseForModuleLabels", defaultVString);
501 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are printed.");
504 np->
setComment(
"If true the products will be retrieved using getByLabel.");
506 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"getDataForModuleLabels", defaultVString);
507 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are retrieved by getByLabel.");
510 np->
setComment(
"If true then print a list of all the event content.");
513 np->
setComment(
"If true, and if listContent or verbose is true, print provenance information for each product");
515 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
#define DEFINE_FWK_MODULE(type)
~EventContentAnalyzer() override
std::string verboseIndentation_
std::string const & processName() const
std::map< std::string, int > cumulates_
ProductProvenance const * productProvenance() const
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
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 &)
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
static Registry * instance()
std::string className(const T &t)
void getAllStableProvenance(std::vector< StableProvenance const * > &provenances) const