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");
75 typedef std::map<std::string, FunctionType> TypeToPrintMap;
78 void addToMap(TypeToPrintMap& iMap) {
79 iMap[
typeid(
T).
name()] = doPrint<T>;
83 ObjectWithDict
const& iObject,
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 std::string printName = iName;
122 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() == 0) {
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 sizeObj = ObjectWithDict(TypeWithDict(
typeid(
size_t)), &temp);
180 iObject.typeOf().functionMemberByName(
"size").invoke(iObject, &sizeObj);
181 assert(iObject.typeOf().functionMemberByName(
"size").returnType().typeInfo() ==
typeid(size_t));
183 assert(sizeObj.typeOf().typeInfo() ==
typeid(size_t));
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.returnType());
202 bool const isRef = atReturnType.isReference();
203 void* refMemoryBuffer = 0;
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 atReturnType.destruct(contained.address(),
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 virtual 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_.size()>0),
294 getModuleLabels_(iConfig.getUntrackedParameter(
"getDataForModuleLabels", std::vector<std::
string>())),
295 getData_(iConfig.getUntrackedParameter(
"getData",
false) || getModuleLabels_.size()>0),
297 listContent_(iConfig.getUntrackedParameter(
"listContent",
true))
336 typedef std::vector<Provenance const*> Provenances;
337 Provenances provenances;
343 << provenances.size() <<
" product" << (provenances.size() == 1 ?
"" :
"s")
344 <<
" with friendlyClassName, moduleLabel, productInstanceName and processName:"
349 for(Provenances::iterator itProv = provenances.begin(), itProvEnd = provenances.end();
352 std::string
const&
className = (*itProv)->className();
354 std::string
const&
friendlyName = (*itProv)->friendlyClassName();
357 std::string
const& modLabel = (*itProv)->moduleLabel();
360 std::string
const& instanceName = (*itProv)->productInstanceName();
363 std::string
const& processName = (*itProv)->processName();
371 <<
"\" \"" << instanceName <<
"\" \""
372 << processName <<
"\""
373 <<
" (productId = " << (*itProv)->productID() <<
")"
377 std::string
key = friendlyName
379 +
std::string(
"\" + \"") + instanceName +
"\" \"" + processName +
"\"";
390 verboseIndentation_);
394 std::string class_and_label = friendlyName +
"_" + modLabel;
401 LogAbsolute(
"EventContent") << startIndent <<
" \"" << className <<
"\"" <<
" is an unknown type" << std::endl;
419 typedef std::map<std::string, int> nameMap;
421 LogAbsolute(
"EventContent") <<
"\nSummary for key being the concatenation of friendlyClassName, moduleLabel, productInstanceName and processName" << std::endl;
425 LogAbsolute(
"EventContent") << std::setw(6) << it->second <<
" occurrences of key " << it->first << std::endl;
437 descriptions.
setComment(
"This plugin will print a list of all products in the event "
438 "provenance. It also has options to print and/or get each product.");
444 std::string defaultString(
"++");
446 np->
setComment(
"This string is printed at the beginning of every line printed during event processing.");
449 np->
setComment(
"If true, the contents of products are printed.");
453 np->
setComment(
"This string is used to further indent lines when printing the contents of products in verbose mode.");
455 std::vector<std::string> defaultVString;
457 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"verboseForModuleLabels", defaultVString);
458 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are printed.");
461 np->
setComment(
"If true the products will be retrieved using getByLabel.");
463 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"getDataForModuleLabels", defaultVString);
464 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are retrieved by getByLabel.");
467 np->
setComment(
"If true then print a list of all the event content.");
470 descriptions.
add(
"printContent", desc);
std::vector< std::string > getModuleLabels_
void setComment(std::string const &value)
void getAllProvenance(std::vector< Provenance const * > &provenances) const
static TypeWithDict byName(std::string const &className)
#define DEFINE_FWK_MODULE(type)
std::string verboseIndentation_
std::string const & processName() const
std::map< std::string, int > cumulates_
virtual void endJob() override
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void analyze(Event const &, EventSetup const &) override
std::string friendlyName(std::string const &iFullName)
std::string const & moduleLabel() const
std::string const & productInstanceName() const
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)
volatile std::atomic< bool > shutdown_flag false
T mod(const T &a, const T &b)
static const bool doPrint
EventContentAnalyzer(ParameterSet const &)
tuple size
Write out results.
std::string className(const T &t)