#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Provenance/interface/Provenance.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Modules/src/EventContentAnalyzer.h"
#include "FWCore/Framework/interface/GenericHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Algorithms.h"
Go to the source code of this file.
Typedefs | |
typedef void(* | FunctionType )(const std::string &, const ROOT::Reflex::Object &, const std::string &) |
typedef std::map< std::string, FunctionType > | TypeToPrintMap |
Functions | |
template<typename T> | |
static void | addToMap (TypeToPrintMap &iMap) |
template<typename T> | |
static void | doPrint (const std::string &iName, const ROOT::Reflex::Object &iObject, const std::string &iIndent) |
convert the object information to the correct type and print it | |
template<> | |
static void | doPrint< bool > (const std::string &iName, const ROOT::Reflex::Object &iObject, const std::string &iIndent) |
template<> | |
static void | doPrint< char > (const std::string &iName, const ROOT::Reflex::Object &iObject, const std::string &iIndent) |
template<> | |
static void | doPrint< unsigned char > (const std::string &iName, const ROOT::Reflex::Object &iObject, const std::string &iIndent) |
static std::string | formatClassName (const std::string &iName) |
Description: <one line="" class="" summary>="">. | |
static bool | printAsBuiltin (const std::string &iName, const ROOT::Reflex::Object iObject, const std::string &iIndent) |
static bool | printAsContainer (const std::string &iName, const ROOT::Reflex::Object &iObject, const std::string &iIndent, const std::string &iIndentDelta) |
static void | printObject (const edm::Event &iEvent, const std::string &iClassName, const std::string &iModuleLabel, const std::string &iInstanceLabel, const std::string &iProcessName, const std::string &iIndent, const std::string &iIndentDelta) |
static void | printObject (const std::string &iName, const ROOT::Reflex::Object &iObject, const std::string &iIndent, const std::string &iIndentDelta) |
Variables | |
static const char * | kNameValueSep = "=" |
typedef void(* FunctionType)(const std::string &, const ROOT::Reflex::Object &, const std::string &) |
Definition at line 82 of file EventContentAnalyzer.cc.
typedef std::map<std::string, FunctionType> TypeToPrintMap |
Definition at line 83 of file EventContentAnalyzer.cc.
static void addToMap | ( | TypeToPrintMap & | iMap | ) | [inline, static] |
Definition at line 86 of file EventContentAnalyzer.cc.
References name.
00086 { 00087 iMap[typeid(T).name()]=doPrint<T>; 00088 }
static void doPrint | ( | const std::string & | iName, | |
const ROOT::Reflex::Object & | iObject, | |||
const std::string & | iIndent | |||
) | [inline, static] |
convert the object information to the correct type and print it
Definition at line 63 of file EventContentAnalyzer.cc.
00063 { 00064 edm::LogAbsolute("EventContent") << iIndent<< iName <<kNameValueSep<<*reinterpret_cast<T*>(iObject.Address());//<<"\n"; 00065 }
static void doPrint< bool > | ( | const std::string & | iName, | |
const ROOT::Reflex::Object & | iObject, | |||
const std::string & | iIndent | |||
) | [inline, static] |
static void doPrint< char > | ( | const std::string & | iName, | |
const ROOT::Reflex::Object & | iObject, | |||
const std::string & | iIndent | |||
) | [inline, static] |
static void doPrint< unsigned char > | ( | const std::string & | iName, | |
const ROOT::Reflex::Object & | iObject, | |||
const std::string & | iIndent | |||
) | [inline, static] |
static std::string formatClassName | ( | const std::string & | iName | ) | [static] |
Description: <one line="" class="" summary>="">.
Implementation: <Notes on="" implementation>="">consistently format class names
Definition at line 56 of file EventContentAnalyzer.cc.
Referenced by printObject().
static bool printAsBuiltin | ( | const std::string & | iName, | |
const ROOT::Reflex::Object | iObject, | |||
const std::string & | iIndent | |||
) | [static] |
Definition at line 90 of file EventContentAnalyzer.cc.
References cmsDriverOptions::isFirst, and void.
Referenced by printObject().
00092 { 00093 typedef void(*FunctionType)(const std::string&,const ROOT::Reflex::Object&, const std::string&); 00094 typedef std::map<std::string, FunctionType> TypeToPrintMap; 00095 static TypeToPrintMap s_map; 00096 static bool isFirst = true; 00097 if(isFirst) { 00098 addToMap<bool>(s_map); 00099 addToMap<char>(s_map); 00100 addToMap<short>(s_map); 00101 addToMap<int>(s_map); 00102 addToMap<long>(s_map); 00103 addToMap<unsigned char>(s_map); 00104 addToMap<unsigned short>(s_map); 00105 addToMap<unsigned int>(s_map); 00106 addToMap<unsigned long>(s_map); 00107 addToMap<float>(s_map); 00108 addToMap<double>(s_map); 00109 isFirst=false; 00110 } 00111 TypeToPrintMap::iterator itFound =s_map.find(iObject.TypeOf().TypeInfo().name()); 00112 if(itFound == s_map.end()) { 00113 00114 return false; 00115 } 00116 itFound->second(iName,iObject,iIndent); 00117 return true; 00118 }
static bool printAsContainer | ( | const std::string & | iName, | |
const ROOT::Reflex::Object & | iObject, | |||
const std::string & | iIndent, | |||
const std::string & | iIndentDelta | |||
) | [static] |
Definition at line 185 of file EventContentAnalyzer.cc.
References exception, index, kNameValueSep, printObject(), size, and x.
Referenced by printObject().
00188 { 00189 using namespace ROOT::Reflex; 00190 Object sizeObj; 00191 try { 00192 sizeObj = iObject.Invoke("size"); 00193 assert(sizeObj.TypeOf().TypeInfo() == typeid(size_t)); 00194 size_t size = *reinterpret_cast<size_t*>(sizeObj.Address()); 00195 Member atMember; 00196 try { 00197 atMember = iObject.TypeOf().MemberByName("at"); 00198 } catch(const std::exception& x) { 00199 //std::cerr <<"could not get 'at' member because "<< x.what()<<std::endl; 00200 return false; 00201 } 00202 edm::LogAbsolute("EventContent") <<iIndent<<iName<<kNameValueSep<<"[size="<<size<<"]";//"\n"; 00203 Object contained; 00204 std::string indexIndent=iIndent+iIndentDelta; 00205 for(size_t index = 0; index != size; ++index) { 00206 std::ostringstream sizeS; 00207 sizeS << "["<<index<<"]"; 00208 contained = atMember.Invoke(iObject, Tools::MakeVector(static_cast<void*>(&index))); 00209 //edm::LogAbsolute("EventContent") <<"invoked 'at'"<<std::endl; 00210 try { 00211 printObject(sizeS.str(),contained,indexIndent,iIndentDelta); 00212 }catch(std::exception& iEx) { 00213 edm::LogAbsolute("EventContent") <<indexIndent<<iName<<" <exception caught(" 00214 <<iEx.what()<<")>\n"; 00215 } 00216 } 00217 return true; 00218 } catch(const std::exception& x) { 00219 //std::cerr <<"failed to invoke 'at' because "<<x.what()<<std::endl; 00220 return false; 00221 } 00222 return false; 00223 }
static void printObject | ( | const edm::Event & | iEvent, | |
const std::string & | iClassName, | |||
const std::string & | iModuleLabel, | |||
const std::string & | iInstanceLabel, | |||
const std::string & | iProcessName, | |||
const std::string & | iIndent, | |||
const std::string & | iIndentDelta | |||
) | [static] |
Definition at line 225 of file EventContentAnalyzer.cc.
References className(), lat::endl(), formatClassName(), edm::Event::getByLabel(), and printObject().
00231 { 00232 using namespace edm; 00233 try { 00234 GenericHandle handle(iClassName); 00235 }catch(const edm::Exception&) { 00236 edm::LogAbsolute("EventContent") <<iIndent<<" \""<<iClassName<<"\""<<" is an unknown type"<<std::endl; 00237 return; 00238 } 00239 GenericHandle handle(iClassName); 00240 iEvent.getByLabel(edm::InputTag(iModuleLabel,iInstanceLabel,iProcessName),handle); 00241 std::string className = formatClassName(iClassName); 00242 printObject(className,*handle,iIndent,iIndentDelta); 00243 }
static void printObject | ( | const std::string & | iName, | |
const ROOT::Reflex::Object & | iObject, | |||
const std::string & | iIndent, | |||
const std::string & | iIndentDelta | |||
) | [static] |
Definition at line 125 of file EventContentAnalyzer.cc.
References exception, formatClassName(), lat::indent(), kNameValueSep, printAsBuiltin(), and printAsContainer().
Referenced by EventContentAnalyzer::analyze(), printAsContainer(), printContentsOfStdContainer(), printDataMembers(), printObject(), and edm::XMLOutputModule::write().
00128 { 00129 using namespace ROOT::Reflex; 00130 std::string printName = iName; 00131 Object objectToPrint = iObject; 00132 std::string indent(iIndent); 00133 if(iObject.TypeOf().IsPointer()) { 00134 edm::LogAbsolute("EventContent")<<iIndent<<iName<<kNameValueSep<<formatClassName(iObject.TypeOf().Name())<<std::hex<<iObject.Address()<<std::dec;//<<"\n"; 00135 Type pointedType = iObject.TypeOf().ToType(); 00136 if(ROOT::Reflex::Type::ByName("void") == pointedType || 00137 pointedType.IsPointer() || 00138 iObject.Address() == 0) { 00139 return; 00140 } 00141 return; 00142 00143 //have the code that follows print the contents of the data to which the pointer points 00144 objectToPrint = ROOT::Reflex::Object(pointedType, iObject.Address()); 00145 //try to convert it to its actual type (assuming the original type was a base class) 00146 objectToPrint = ROOT::Reflex::Object(objectToPrint.CastObject(objectToPrint.DynamicType())); 00147 printName = std::string("*")+iName; 00148 indent +=iIndentDelta; 00149 } 00150 std::string typeName(objectToPrint.TypeOf().Name()); 00151 if(typeName.empty()) { 00152 typeName="<unknown>"; 00153 } 00154 00155 //see if we are dealing with a typedef 00156 if(objectToPrint.TypeOf().IsTypedef()) { 00157 objectToPrint = Object(objectToPrint.TypeOf().ToType(),objectToPrint.Address()); 00158 } 00159 if(printAsBuiltin(printName,objectToPrint,indent)) { 00160 return; 00161 } 00162 if(printAsContainer(printName,objectToPrint,indent,iIndentDelta)) { 00163 return; 00164 } 00165 00166 edm::LogAbsolute("EventContent")<<indent<<printName<<" "<<formatClassName(typeName);//<<"\n"; 00167 indent+=iIndentDelta; 00168 //print all the data members 00169 for(ROOT::Reflex::Member_Iterator itMember = objectToPrint.TypeOf().DataMember_Begin(); 00170 itMember != objectToPrint.TypeOf().DataMember_End(); 00171 ++itMember) { 00172 //edm::LogAbsolute("EventContent") <<" debug "<<itMember->Name()<<" "<<itMember->TypeOf().Name()<<"\n"; 00173 try { 00174 printObject(itMember->Name(), 00175 itMember->Get(objectToPrint), 00176 indent, 00177 iIndentDelta); 00178 }catch(std::exception& iEx) { 00179 edm::LogAbsolute("EventContent") <<indent<<itMember->Name()<<" <exception caught(" 00180 <<iEx.what()<<")>\n"; 00181 } 00182 } 00183 }
const char* kNameValueSep = "=" [static] |
Definition at line 60 of file EventContentAnalyzer.cc.
Referenced by printAsContainer(), and printObject().