31 #include "Reflex/Member.h"
45 std::string formatClassName(std::string
const& iName) {
46 return std::string(
"(")+iName+
")";
49 char const* kNameValueSep =
"=";
52 void doPrint(std::string
const& iName, Reflex::Object
const& iObject, std::string
const& iIndent) {
53 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << *reinterpret_cast<T*>(iObject.Address());
57 void doPrint<char>(std::string
const& iName, Reflex::Object
const& iObject, std::string
const& iIndent) {
58 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << static_cast<int>(*
reinterpret_cast<char*
>(iObject.Address()));
62 void doPrint<unsigned char>(std::string
const& iName, Reflex::Object
const& iObject, std::string
const& iIndent) {
63 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << static_cast<unsigned int>(*
reinterpret_cast<unsigned char*
>(iObject.Address()));
67 void doPrint<bool>(std::string
const& iName, Reflex::Object
const& iObject, std::string
const& iIndent) {
68 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << ((*reinterpret_cast<bool*>(iObject.Address()))?
"true":
"false");
71 typedef void(*FunctionType)(std::string
const&, Reflex::Object
const&, std::string
const&);
72 typedef std::map<std::string, FunctionType> TypeToPrintMap;
75 void addToMap(TypeToPrintMap& iMap) {
76 iMap[
typeid(
T).
name()] = doPrint<T>;
79 bool printAsBuiltin(std::string
const& iName,
80 Reflex::Object
const& iObject,
81 std::string
const& iIndent) {
82 typedef void(*FunctionType)(std::string
const&, Reflex::Object
const&, std::string
const&);
83 typedef std::map<std::string, FunctionType> TypeToPrintMap;
84 static TypeToPrintMap s_map;
87 addToMap<bool>(s_map);
88 addToMap<char>(s_map);
89 addToMap<short>(s_map);
91 addToMap<long>(s_map);
92 addToMap<unsigned char>(s_map);
93 addToMap<unsigned short>(s_map);
94 addToMap<unsigned int>(s_map);
95 addToMap<unsigned long>(s_map);
96 addToMap<float>(s_map);
97 addToMap<double>(s_map);
100 TypeToPrintMap::iterator itFound = s_map.find(iObject.TypeOf().TypeInfo().name());
101 if(itFound == s_map.end()) {
105 itFound->second(iName, iObject, iIndent);
109 bool printAsContainer(std::string
const& iName,
110 Reflex::Object
const& iObject,
111 std::string
const& iIndent,
112 std::string
const& iIndentDelta);
114 void printObject(std::string
const& iName,
115 Reflex::Object
const& iObject,
116 std::string
const& iIndent,
117 std::string
const& iIndentDelta) {
118 std::string printName = iName;
119 Reflex::Object objectToPrint = iObject;
120 std::string
indent(iIndent);
121 if(iObject.TypeOf().IsPointer()) {
122 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep << formatClassName(iObject.TypeOf().Name()) << std::hex << iObject.Address() << std::dec;
124 if(Reflex::Type::ByName(
"void") == pointedType ||
125 pointedType.IsPointer() ||
126 iObject.Address() == 0) {
139 std::string typeName(objectToPrint.TypeOf().Name());
140 if(typeName.empty()) {
141 typeName =
"<unknown>";
145 if(objectToPrint.TypeOf().IsTypedef()) {
146 objectToPrint = Reflex::Object(objectToPrint.TypeOf().ToType(), objectToPrint.Address());
148 if(printAsBuiltin(printName, objectToPrint,
indent)) {
151 if(printAsContainer(printName, objectToPrint,
indent, iIndentDelta)) {
155 LogAbsolute(
"EventContent") <<
indent << printName <<
" " << formatClassName(typeName);
158 for(Reflex::Member_Iterator itMember = objectToPrint.TypeOf().DataMember_Begin();
159 itMember != objectToPrint.TypeOf().DataMember_End();
163 printObject(itMember->Name(),
164 itMember->Get(objectToPrint),
168 LogAbsolute(
"EventContent") <<
indent << itMember->Name() <<
" <exception caught(" << iEx.what() <<
")>\n";
173 bool printAsContainer(std::string
const& iName,
174 Reflex::Object
const& iObject,
175 std::string
const& iIndent,
176 std::string
const& iIndentDelta) {
177 Reflex::Object sizeObj;
180 sizeObj = Reflex::Object(Reflex::Type::ByTypeInfo(
typeid(
size_t)), &temp);
181 iObject.Invoke(
"size", &sizeObj);
182 assert(iObject.TypeOf().FunctionMemberByName(
"size").TypeOf().ReturnType().TypeInfo() ==
typeid(size_t));
184 assert(sizeObj.TypeOf().FinalType().TypeInfo() ==
typeid(size_t));
185 size_t size = *
reinterpret_cast<size_t*
>(sizeObj.Address());
186 Reflex::Member atMember;
188 atMember = iObject.TypeOf().MemberByName(
"at");
193 LogAbsolute(
"EventContent") << iIndent << iName << kNameValueSep <<
"[size=" << size <<
"]";
194 Reflex::Object contained;
195 std::string indexIndent = iIndent + iIndentDelta;
196 Reflex::Type atReturnType = atMember.TypeOf().ReturnType();
203 bool const isRef = atReturnType.IsReference();
204 void* refMemoryBuffer = 0;
209 std::vector<void*>
args;
210 args.push_back(&index);
212 std::ostringstream sizeS;
213 sizeS <<
"[" << index <<
"]";
215 Reflex::Object refObject(atReturnType, &refMemoryBuffer);
216 atMember.Invoke(iObject, &refObject, args);
219 contained = Reflex::Object(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();
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);
291 indentation_(iConfig.getUntrackedParameter(
"indentation", std::string(
"++"))),
292 verboseIndentation_(iConfig.getUntrackedParameter(
"verboseIndentation", std::string(
" "))),
293 moduleLabels_(iConfig.getUntrackedParameter(
"verboseForModuleLabels", std::vector<std::string>())),
294 verbose_(iConfig.getUntrackedParameter(
"verbose",
false) || moduleLabels_.size()>0),
295 getModuleLabels_(iConfig.getUntrackedParameter(
"getDataForModuleLabels", std::vector<std::string>())),
296 getData_(iConfig.getUntrackedParameter(
"getData",
false) || getModuleLabels_.size()>0),
298 listContent_(iConfig.getUntrackedParameter(
"listContent",
true)){
318 typedef std::vector<Provenance const*> Provenances;
319 Provenances provenances;
325 << provenances.size() <<
" product" << (provenances.size() == 1 ?
"" :
"s")
326 <<
" with friendlyClassName, moduleLabel, productInstanceName and processName:"
331 for(Provenances::iterator itProv = provenances.begin(), itProvEnd = provenances.end();
334 std::string
const&
className = (*itProv)->className();
336 std::string
const&
friendlyName = (*itProv)->friendlyClassName();
339 std::string
const& modLabel = (*itProv)->moduleLabel();
342 std::string
const& instanceName = (*itProv)->productInstanceName();
345 std::string
const& processName = (*itProv)->processName();
353 <<
"\" \"" << instanceName <<
"\" \""
354 << processName <<
"\""
355 <<
" (productId = " << (*itProv)->productID() <<
")"
359 std::string
key = friendlyName
360 + std::string(
" + \"") + modLabel
361 + std::string(
"\" + \"") + instanceName +
"\" \"" + processName +
"\"";
372 verboseIndentation_);
376 std::string class_and_label = friendlyName +
"_" + modLabel;
383 LogAbsolute(
"EventContent") << startIndent <<
" \"" << className <<
"\"" <<
" is an unknown type" << std::endl;
401 typedef std::map<std::string, int> nameMap;
403 LogAbsolute(
"EventContent") <<
"\nSummary for key being the concatenation of friendlyClassName, moduleLabel, productInstanceName and processName" << std::endl;
407 LogAbsolute(
"EventContent") << std::setw(6) << it->second <<
" occurrences of key " << it->first << std::endl;
419 descriptions.
setComment(
"This plugin will print a list of all products in the event "
420 "provenance. It also has options to print and/or get each product.");
426 std::string defaultString(
"++");
428 np->
setComment(
"This string is printed at the beginning of every line printed during event processing.");
431 np->
setComment(
"If true, the contents of products are printed using Reflex.");
435 np->
setComment(
"This string is used to further indent lines when printing the contents of products in verbose mode.");
437 std::vector<std::string> defaultVString;
439 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"verboseForModuleLabels", defaultVString);
440 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are printed using Reflex.");
443 np->
setComment(
"If true the products will be retrieved using getByLabel.");
445 np = desc.
addOptionalUntracked<std::vector<std::string> >(
"getDataForModuleLabels", defaultVString);
446 np->
setComment(
"If this vector is not empty, then only products with module labels on this list are retrieved by getByLabel.");
449 np->
setComment(
"If true then print a list of all the event content.");
452 descriptions.
add(
"printContent", desc);
std::vector< std::string > getModuleLabels_
void setComment(std::string const &value)
void getAllProvenance(std::vector< Provenance const * > &provenances) const
bool isFirst(HepMC::GenParticle *x)
#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)