51 char const* kNameValueSep =
"=";
55 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << *reinterpret_cast<T*>(iObject.address());
60 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << static_cast<int>(*
reinterpret_cast<char*
>(iObject.address()));
64 void doPrint<unsigned char>(
std::string const& iName, ObjectWithDict
const& iObject,
std::string const& iIndent) {
65 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << static_cast<unsigned int>(*
reinterpret_cast<unsigned char*
>(iObject.address()));
70 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << ((*reinterpret_cast<bool*>(iObject.address()))?
"true":
"false");
74 typedef std::map<std::string, FunctionType> TypeToPrintMap;
77 void addToMap(TypeToPrintMap& iMap) {
78 iMap[
typeid(
T).
name()] = doPrint<T>;
82 ObjectWithDict
const& iObject,
84 typedef void(*FunctionType)(
std::string const&, ObjectWithDict
const&, std::string
const&);
85 typedef std::map<std::string, FunctionType> TypeToPrintMap;
86 static TypeToPrintMap s_map;
89 addToMap<bool>(s_map);
90 addToMap<char>(s_map);
91 addToMap<short>(s_map);
93 addToMap<long>(s_map);
94 addToMap<unsigned char>(s_map);
95 addToMap<unsigned short>(s_map);
96 addToMap<unsigned int>(s_map);
97 addToMap<unsigned long>(s_map);
98 addToMap<float>(s_map);
99 addToMap<double>(s_map);
102 TypeToPrintMap::iterator itFound = s_map.find(iObject.typeOf().name());
103 if(itFound == s_map.end()) {
107 itFound->second(iName, iObject, iIndent);
111 bool printAsContainer(std::string
const& iName,
112 ObjectWithDict
const& iObject,
113 std::string
const& iIndent,
114 std::string
const& iIndentDelta);
116 void printObject(std::string
const& iName,
117 ObjectWithDict
const& iObject,
118 std::string
const& iIndent,
119 std::string
const& iIndentDelta) {
120 std::string printName = iName;
121 ObjectWithDict objectToPrint = iObject;
122 std::string
indent(iIndent);
123 if(iObject.typeOf().isPointer()) {
124 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << formatClassName(iObject.typeOf().name()) << std::hex << iObject.address() << std::dec;
125 TypeWithDict pointedType = iObject.typeOf().toType();
128 iObject.address() == 0) {
141 std::string typeName(objectToPrint.typeOf().name());
142 if(typeName.empty()) {
143 typeName =
"<unknown>";
146 if(printAsBuiltin(printName, objectToPrint,
indent)) {
149 if(printAsContainer(printName, objectToPrint,
indent, iIndentDelta)) {
153 LogAbsolute(
"EventContent") <<
indent << printName <<
" " << formatClassName(typeName);
156 TypeDataMembers dataMembers(objectToPrint.typeOf());
157 for(
auto const& dataMember : dataMembers) {
158 MemberWithDict
const member(dataMember);
161 printObject(member.name(),
162 member.get(objectToPrint),
166 LogAbsolute(
"EventContent") <<
indent << member.name() <<
" <exception caught(" << iEx.what() <<
")>\n";
171 bool printAsContainer(std::string
const& iName,
172 ObjectWithDict
const& iObject,
173 std::string
const& iIndent,
174 std::string
const& iIndentDelta) {
175 ObjectWithDict sizeObj;
178 sizeObj = ObjectWithDict(TypeWithDict(
typeid(
size_t)), &temp);
179 iObject.typeOf().functionMemberByName(
"size").invoke(iObject, &sizeObj);
180 assert(iObject.typeOf().functionMemberByName(
"size").returnType().typeInfo() ==
typeid(size_t));
182 assert(sizeObj.typeOf().typeInfo() ==
typeid(size_t));
183 size_t size = *
reinterpret_cast<size_t*
>(sizeObj.address());
184 FunctionWithDict atMember;
186 atMember = iObject.typeOf().functionMemberByName(
"at");
191 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep <<
"[size=" << size <<
"]";
192 ObjectWithDict contained;
193 std::string indexIndent = iIndent + iIndentDelta;
194 TypeWithDict atReturnType(atMember.returnType());
201 bool const isRef = atReturnType.isReference();
202 void* refMemoryBuffer = 0;
207 std::vector<void*>
args;
208 args.push_back(&index);
210 std::ostringstream sizeS;
211 sizeS <<
"[" << index <<
"]";
213 ObjectWithDict refObject(atReturnType, &refMemoryBuffer);
214 atMember.invoke(iObject, &refObject, args);
217 contained = ObjectWithDict(atReturnType, refMemoryBuffer);
219 contained = atReturnType.construct();
220 atMember.invoke(iObject, &contained, args);
224 printObject(sizeS.str(), contained, indexIndent, iIndentDelta);
226 LogAbsolute(
"EventContent") << indexIndent << iName <<
" <exception caught("
227 << iEx.what() <<
")>\n";
230 atReturnType.destruct(contained.address(),
true);
242 std::string
const& iClassName,
243 std::string
const& iModuleLabel,
244 std::string
const& iInstanceLabel,
245 std::string
const& iProcessName,
246 std::string
const& iIndent,
247 std::string
const& iIndentDelta) {
251 LogAbsolute(
"EventContent") << iIndent <<
" \"" << iClassName <<
"\"" <<
" is an unknown type" << std::endl;
255 iEvent.getByLabel(InputTag(iModuleLabel, iInstanceLabel, iProcessName),
handle);
256 std::string
className = formatClassName(iClassName);
257 printObject(className, *
handle, iIndent, iIndentDelta);
289 indentation_(iConfig.getUntrackedParameter(
"indentation", std::
string(
"++"))),
290 verboseIndentation_(iConfig.getUntrackedParameter(
"verboseIndentation", std::
string(
" "))),
291 moduleLabels_(iConfig.getUntrackedParameter(
"verboseForModuleLabels", std::vector<std::
string>())),
292 verbose_(iConfig.getUntrackedParameter(
"verbose",
false) || moduleLabels_.size()>0),
293 getModuleLabels_(iConfig.getUntrackedParameter(
"getDataForModuleLabels", std::vector<std::
string>())),
294 getData_(iConfig.getUntrackedParameter(
"getData",
false) || getModuleLabels_.size()>0),
296 listContent_(iConfig.getUntrackedParameter(
"listContent",
true)){
316 typedef std::vector<Provenance const*> Provenances;
317 Provenances provenances;
323 << provenances.size() <<
" product" << (provenances.size() == 1 ?
"" :
"s")
324 <<
" with friendlyClassName, moduleLabel, productInstanceName and processName:"
329 for(Provenances::iterator itProv = provenances.begin(), itProvEnd = provenances.end();
332 std::string
const&
className = (*itProv)->className();
334 std::string
const&
friendlyName = (*itProv)->friendlyClassName();
337 std::string
const& modLabel = (*itProv)->moduleLabel();
340 std::string
const& instanceName = (*itProv)->productInstanceName();
343 std::string
const& processName = (*itProv)->processName();
351 <<
"\" \"" << instanceName <<
"\" \""
352 << processName <<
"\""
353 <<
" (productId = " << (*itProv)->productID() <<
")"
357 std::string
key = friendlyName
359 +
std::string(
"\" + \"") + instanceName +
"\" \"" + processName +
"\"";
370 verboseIndentation_);
374 std::string class_and_label = friendlyName +
"_" + modLabel;
381 LogAbsolute(
"EventContent") << startIndent <<
" \"" << className <<
"\"" <<
" is an unknown type" << std::endl;
399 typedef std::map<std::string, int> nameMap;
401 LogAbsolute(
"EventContent") <<
"\nSummary for key being the concatenation of friendlyClassName, moduleLabel, productInstanceName and processName" << std::endl;
405 LogAbsolute(
"EventContent") << std::setw(6) << it->second <<
" occurrences of key " << it->first << std::endl;
417 descriptions.
setComment(
"This plugin will print a list of all products in the event "
418 "provenance. It also has options to print and/or get each product.");
424 std::string defaultString(
"++");
426 np->
setComment(
"This string is printed at the beginning of every line printed during event processing.");
429 np->
setComment(
"If true, the contents of products are printed.");
433 np->
setComment(
"This string is used to further indent lines when printing the contents of products in verbose mode.");
435 std::vector<std::string> defaultVString;
437 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"verboseForModuleLabels", defaultVString);
438 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are printed.");
441 np->
setComment(
"If true the products will be retrieved using getByLabel.");
443 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"getDataForModuleLabels", defaultVString);
444 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are retrieved by getByLabel.");
447 np->
setComment(
"If true then print a list of all the event content.");
450 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::map< std::string, int > cumulates_
std::string friendlyName(std::string const &iFullName)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void analyze(Event const &, EventSetup const &)
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)
bool binary_search_all(ForwardSequence const &s, Datum const &d)
wrappers for std::binary_search
ParameterDescriptionBase * addOptionalUntracked(U const &iLabel, T const &value)
EventContentAnalyzer(ParameterSet const &)
tuple size
Write out results.
std::string className(const T &t)