#include <iomanip>
#include <map>
#include <sstream>
#include <algorithm>
#include "Reflex/Base.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Provenance/interface/BranchDescription.h"
#include "DataFormats/Provenance/interface/Selections.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/GenericHandle.h"
#include "FWCore/Modules/src/XMLOutputModule.h"
Go to the source code of this file.
Defines | |
#define | FILLNAME(_type_) s_toName[typeid(_type_).name()]= #_type_; |
convert the object information to the correct type and print it | |
Typedefs | |
typedef void(* | FunctionType )(std::ostream &, std::string const &, std::string const &, ROOT::Reflex::Object const &, std::string const &) |
typedef std::map< std::string, FunctionType > | TypeToPrintMap |
Functions | |
template<typename T> | |
static void | addToMap (TypeToPrintMap &iMap) |
template<typename T> | |
static void | doPrint (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object const &iObject, std::string const &iIndent) |
template<> | |
static void | doPrint< bool > (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object const &iObject, std::string const &iIndent) |
template<> | |
static void | doPrint< char > (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object const &iObject, std::string const &iIndent) |
template<> | |
static void | doPrint< unsigned char > (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object const &iObject, std::string const &iIndent) |
static std::string | formatXML (std::string const &iO) |
static bool | printAsBuiltin (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object const iObject, std::string const &iIndent) |
static bool | printAsContainer (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object const &iObject, std::string const &iIndent, std::string const &iIndentDelta) |
static bool | printContentsOfStdContainer (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object iBegin, ROOT::Reflex::Object const &iEnd, std::string const &iIndent, std::string const &iIndentDelta) |
static void | printDataMembers (std::ostream &oStream, ROOT::Reflex::Object const &iObject, ROOT::Reflex::Type const &iType, std::string const &iIndent, std::string const &iIndentDelta) |
static void | printObject (std::ostream &oStream, edm::Event const &iEvent, std::string const &iClassName, std::string const &iModuleLabel, std::string const &iInstanceLabel, std::string const &iIndent, std::string const &iIndentDelta) |
static void | printObject (std::ostream &oStream, std::string const &iPrefix, std::string const &iPostfix, ROOT::Reflex::Object const &iObject, std::string const &iIndent, std::string const &iIndentDelta) |
static std::string const & | typeidToName (std::type_info const &iID) |
Variables | |
static char const * | kContainerClose = "</container>" |
static char const * | kContainerOpen = "<container size=\"" |
static char const * | kNameValueSep = "\">" |
static std::string const | kObjectClose = "</object>" |
static std::string const | kObjectOpen = "<object type=\"" |
#define FILLNAME | ( | _type_ | ) | s_toName[typeid(_type_).name()]= #_type_; |
convert the object information to the correct type and print it
Definition at line 71 of file XMLOutputModule.cc.
Referenced by typeidToName().
typedef void(* FunctionType)(std::ostream &, std::string const &, std::string const &, ROOT::Reflex::Object const &, std::string const &) |
Definition at line 113 of file XMLOutputModule.cc.
typedef std::map<std::string, FunctionType> TypeToPrintMap |
Definition at line 115 of file XMLOutputModule.cc.
static void addToMap | ( | TypeToPrintMap & | iMap | ) | [inline, static] |
Definition at line 118 of file XMLOutputModule.cc.
References name.
00118 { 00119 iMap[typeid(T).name()]=doPrint<T>; 00120 }
static void doPrint | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object const & | iObject, | |||
std::string const & | iIndent | |||
) | [inline, static] |
Definition at line 93 of file XMLOutputModule.cc.
00093 { 00094 oStream << iIndent<<iPrefix <<typeidToName(typeid(T))<<kNameValueSep<<*reinterpret_cast<T*>(iObject.Address())<<iPostfix<<"\n"; 00095 }
static void doPrint< bool > | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object const & | iObject, | |||
std::string const & | iIndent | |||
) | [inline, static] |
static void doPrint< char > | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object const & | iObject, | |||
std::string const & | iIndent | |||
) | [inline, static] |
static void doPrint< unsigned char > | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object const & | iObject, | |||
std::string const & | iIndent | |||
) | [inline, static] |
static std::string formatXML | ( | std::string const & | iO | ) | [static] |
Definition at line 40 of file XMLOutputModule.cc.
References i, and HLT_VtxMuL3::result.
Referenced by printAsContainer(), and printObject().
00041 { 00042 std::string result(iO); 00043 static std::string const kSubs("<>&"); 00044 static std::string const kLeft("<"); 00045 static std::string const kRight(">"); 00046 static std::string const kAmp("&"); 00047 00048 std::string::size_type i = 0; 00049 while( std::string::npos != (i = result.find_first_of(kSubs,i))) { 00050 switch( result.at(i) ) { 00051 case '<': 00052 result.replace(i,1,kLeft); 00053 break; 00054 case '>': 00055 result.replace(i,1,kRight); 00056 break; 00057 case '&': 00058 result.replace(i,1,kAmp); 00059 } 00060 ++i; 00061 } 00062 return result; 00063 }
static bool printAsBuiltin | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object const | iObject, | |||
std::string const & | iIndent | |||
) | [static] |
Definition at line 122 of file XMLOutputModule.cc.
References cmsDriverOptions::isFirst, and void.
00126 { 00127 typedef void(*FunctionType)(std::ostream&, std::string const&, std::string const&, ROOT::Reflex::Object const&, std::string const&); 00128 typedef std::map<std::string, FunctionType> TypeToPrintMap; 00129 static TypeToPrintMap s_map; 00130 static bool isFirst = true; 00131 if(isFirst){ 00132 addToMap<bool>(s_map); 00133 addToMap<char>(s_map); 00134 addToMap<short>(s_map); 00135 addToMap<int>(s_map); 00136 addToMap<long>(s_map); 00137 addToMap<unsigned char>(s_map); 00138 addToMap<unsigned short>(s_map); 00139 addToMap<unsigned int>(s_map); 00140 addToMap<unsigned long>(s_map); 00141 addToMap<float>(s_map); 00142 addToMap<double>(s_map); 00143 isFirst=false; 00144 } 00145 TypeToPrintMap::iterator itFound =s_map.find(iObject.TypeOf().TypeInfo().name()); 00146 if(itFound == s_map.end()){ 00147 00148 return false; 00149 } 00150 itFound->second(oStream,iPrefix,iPostfix,iObject,iIndent); 00151 return true; 00152 }
static bool printAsContainer | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object const & | iObject, | |||
std::string const & | iIndent, | |||
std::string const & | iIndentDelta | |||
) | [static] |
Definition at line 322 of file XMLOutputModule.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), exception, formatXML(), index, kContainerClose, kContainerOpen, kObjectClose, kObjectOpen, printContentsOfStdContainer(), printObject(), size, and x.
00326 { 00327 using namespace ROOT::Reflex; 00328 Object sizeObj; 00329 try { 00330 sizeObj = iObject.Invoke("size"); 00331 00332 if(sizeObj.TypeOf().TypeInfo() != typeid(size_t)) { 00333 throw std::exception(); 00334 } 00335 size_t size = *reinterpret_cast<size_t*>(sizeObj.Address()); 00336 Member atMember; 00337 atMember = iObject.TypeOf().MemberByName("at"); 00338 if(!atMember) { 00339 throw std::exception(); 00340 } 00341 std::string typeName(iObject.TypeOf().Name(SCOPED)); 00342 if(typeName.empty()){ 00343 typeName="{unknown}"; 00344 } 00345 00346 oStream <<iIndent<<iPrefix<<formatXML(typeName)<<"\">\n" 00347 <<iIndent<<kContainerOpen<<size<<"\">\n"; 00348 Object contained; 00349 std::string indexIndent=iIndent+iIndentDelta; 00350 for(size_t index = 0; index != size; ++index) { 00351 contained = atMember.Invoke(iObject, Tools::MakeVector(static_cast<void*>(&index))); 00352 //std::cout <<"invoked 'at'"<<std::endl; 00353 try { 00354 printObject(oStream,kObjectOpen,kObjectClose,contained,indexIndent,iIndentDelta); 00355 }catch(std::exception& iEx) { 00356 std::cout <<iIndent<<" <exception caught(" 00357 <<iEx.what()<<")>\n"; 00358 } 00359 } 00360 oStream <<iIndent<<kContainerClose<<std::endl; 00361 oStream <<iIndent<<iPostfix<<std::endl; 00362 return true; 00363 } catch(std::exception const& x){ 00364 //std::cerr <<"failed to invoke 'at' because "<<x.what()<<std::endl; 00365 try { 00366 //oStream <<iIndent<<iPrefix<<formatXML(typeName)<<"\">\n"; 00367 std::string typeName(iObject.TypeOf().Name(SCOPED)); 00368 if(typeName.empty()){ 00369 typeName="{unknown}"; 00370 } 00371 if( printContentsOfStdContainer(oStream, 00372 iIndent+iPrefix+formatXML(typeName)+"\">\n", 00373 iIndent+iPostfix, 00374 iObject.Invoke("begin"), 00375 iObject.Invoke("end"), 00376 iIndent, 00377 iIndentDelta) ) { 00378 if(typeName.empty()){ 00379 typeName="{unknown}"; 00380 } 00381 return true; 00382 } 00383 } catch(std::exception const& x) { 00384 } 00385 return false; 00386 } 00387 return false; 00388 }
static bool printContentsOfStdContainer | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object | iBegin, | |||
ROOT::Reflex::Object const & | iEnd, | |||
std::string const & | iIndent, | |||
std::string const & | iIndentDelta | |||
) | [static] |
Definition at line 270 of file XMLOutputModule.cc.
References TestMuL1L2Filter_cff::cerr, edm::serviceregistry::deref(), dummy, lat::endl(), exception, kContainerClose, kContainerOpen, kObjectClose, kObjectOpen, printObject(), and size.
Referenced by printAsContainer().
00276 { 00277 using namespace ROOT::Reflex; 00278 size_t size=0; 00279 std::ostringstream sStream; 00280 if( iBegin.TypeOf() != iEnd.TypeOf() ) { 00281 std::cerr <<" begin (" << iBegin.TypeOf().Name(SCOPED) <<") and end (" << iEnd.TypeOf().Name(SCOPED) << ") are not the same type"<<std::endl; 00282 throw std::exception(); 00283 } 00284 try { 00285 Member compare(iBegin.TypeOf().MemberByName("operator!=")); 00286 if(!compare) { 00287 //std::cerr<<"no 'operator!=' for "<< iBegin.TypeOf().Name()<< std::endl; 00288 return false; 00289 } 00290 Member incr(iBegin.TypeOf().MemberByName("operator++")); 00291 if(!incr) { 00292 //std::cerr<<"no 'operator++' for "<< iBegin.TypeOf().Name()<<std::endl; 00293 return false; 00294 } 00295 Member deref(iBegin.TypeOf().MemberByName("operator*")); 00296 if(!deref) { 00297 //std::cerr<<"no 'operator*' for "<< iBegin.TypeOf().Name()<<std::endl; 00298 return false; 00299 } 00300 00301 std::string indexIndent = iIndent+iIndentDelta; 00302 int dummy=0; 00303 //std::cerr<<"going to loop using iterator "<<iBegin.TypeOf().Name(SCOPED)<<std::endl; 00304 00305 for(; *reinterpret_cast<bool*>(compare.Invoke(iBegin, Tools::MakeVector((iEnd.Address()))).Address()); incr.Invoke(iBegin,Tools::MakeVector(static_cast<void*>(&dummy))),++size) { 00306 //std::cerr <<"going to print"<<std::endl; 00307 printObject(sStream,kObjectOpen,kObjectClose,deref.Invoke(iBegin),indexIndent,iIndentDelta); 00308 //std::cerr <<"printed"<<std::endl; 00309 } 00310 } catch( std::exception const& iE) { 00311 std::cerr <<"while printing std container caught exception "<<iE.what()<<std::endl; 00312 return false; 00313 } 00314 oStream<<iPrefix<<iIndent<<kContainerOpen<<size<<"\">\n"; 00315 oStream<<sStream.str(); 00316 oStream <<iIndent<<kContainerClose<<std::endl; 00317 oStream <<iPostfix; 00318 //std::cerr<<"finished loop"<<std::endl; 00319 return true; 00320 }
static void printDataMembers | ( | std::ostream & | oStream, | |
ROOT::Reflex::Object const & | iObject, | |||
ROOT::Reflex::Type const & | iType, | |||
std::string const & | iIndent, | |||
std::string const & | iIndentDelta | |||
) | [static] |
Definition at line 232 of file XMLOutputModule.cc.
References GenMuonPlsPt100GeV_cfg::cout, exception, prof2calltree::prefix, and printObject().
Referenced by printObject().
00237 { 00238 //print all the base class data members 00239 for(ROOT::Reflex::Base_Iterator itBase = iType.Base_Begin(); 00240 itBase != iType.Base_End(); 00241 ++itBase) { 00242 printDataMembers(oStream, iObject.CastObject(itBase->ToType()), itBase->ToType(), iIndent, iIndentDelta); 00243 } 00244 static std::string const kPrefix("<datamember name=\""); 00245 static std::string const ktype("\" type=\""); 00246 static std::string const kPostfix("</datamember>"); 00247 00248 for(ROOT::Reflex::Member_Iterator itMember = iType.DataMember_Begin(); 00249 itMember != iType.DataMember_End(); 00250 ++itMember){ 00251 //std::cout <<" debug "<<itMember->Name()<<" "<<itMember->TypeOf().Name()<<"\n"; 00252 if ( itMember->IsTransient() ) { 00253 continue; 00254 } 00255 try { 00256 std::string prefix = kPrefix + itMember->Name()+ktype; 00257 printObject( oStream, 00258 prefix, 00259 kPostfix, 00260 itMember->Get( iObject), 00261 iIndent, 00262 iIndentDelta); 00263 }catch(std::exception& iEx) { 00264 std::cout <<iIndent<<itMember->Name()<<" <exception caught(" 00265 <<iEx.what()<<")>\n"; 00266 } 00267 } 00268 }
static void printObject | ( | std::ostream & | oStream, | |
edm::Event const & | iEvent, | |||
std::string const & | iClassName, | |||
std::string const & | iModuleLabel, | |||
std::string const & | iInstanceLabel, | |||
std::string const & | iIndent, | |||
std::string const & | iIndentDelta | |||
) | [static] |
Definition at line 389 of file XMLOutputModule.cc.
References className(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), formatXML(), edm::Event::getByLabel(), kObjectClose, kObjectOpen, and printObject().
00395 { 00396 using namespace edm; 00397 try { 00398 GenericHandle handle(iClassName); 00399 }catch(edm::Exception const&) { 00400 std::cout <<iIndent<<" \""<<iClassName<<"\""<<" is an unknown type"<<std::endl; 00401 return; 00402 } 00403 GenericHandle handle(iClassName); 00404 iEvent.getByLabel(iModuleLabel,iInstanceLabel,handle); 00405 std::string className = formatXML(iClassName); 00406 printObject(oStream,kObjectOpen,kObjectClose,*handle,iIndent,iIndentDelta); 00407 }
static void printObject | ( | std::ostream & | oStream, | |
std::string const & | iPrefix, | |||
std::string const & | iPostfix, | |||
ROOT::Reflex::Object const & | iObject, | |||
std::string const & | iIndent, | |||
std::string const & | iIndentDelta | |||
) | [static] |
Definition at line 167 of file XMLOutputModule.cc.
References formatXML(), lat::indent(), kContainerClose, kContainerOpen, kObjectClose, kObjectOpen, VarParsing::obj, printAsBuiltin(), printAsContainer(), printDataMembers(), printObject(), size, and tmp.
00172 { 00173 using namespace ROOT::Reflex; 00174 Object objectToPrint = iObject; 00175 std::string indent(iIndent); 00176 if(iObject.TypeOf().IsPointer()) { 00177 oStream<<iIndent<<iPrefix<<formatXML(iObject.TypeOf().Name(SCOPED))<<"\">\n"; 00178 indent +=iIndentDelta; 00179 int size = (0!=iObject.Address()) ? (0!=*reinterpret_cast<void**>(iObject.Address())?1:0) : 0; 00180 oStream<<indent<<kContainerOpen<<size<<"\">\n"; 00181 if(size) { 00182 std::string indent2 = indent+iIndentDelta; 00183 Object obj(iObject.TypeOf().ToType(),*reinterpret_cast<void**>(iObject.Address())); 00184 obj = obj.CastObject(obj.DynamicType()); 00185 printObject(oStream,kObjectOpen,kObjectClose,obj,indent2,iIndentDelta); 00186 } 00187 oStream<<indent<<kContainerClose<<"\n"; 00188 oStream<<iIndent<<iPostfix<<"\n"; 00189 Type pointedType = iObject.TypeOf().ToType(); 00190 if(ROOT::Reflex::Type::ByName("void") == pointedType || 00191 pointedType.IsPointer() || 00192 iObject.Address()==0) { 00193 return; 00194 } 00195 return; 00196 00197 //have the code that follows print the contents of the data to which the pointer points 00198 objectToPrint = ROOT::Reflex::Object(pointedType, iObject.Address()); 00199 //try to convert it to its actual type (assuming the original type was a base class) 00200 objectToPrint = ROOT::Reflex::Object(objectToPrint.CastObject(objectToPrint.DynamicType())); 00201 indent +=iIndentDelta; 00202 } 00203 std::string typeName(objectToPrint.TypeOf().Name(SCOPED)); 00204 if(typeName.empty()){ 00205 typeName="{unknown}"; 00206 } 00207 00208 //see if we are dealing with a typedef 00209 ROOT::Reflex::Type objectType = objectToPrint.TypeOf(); 00210 bool wasTypedef = false; 00211 while(objectType.IsTypedef()) { 00212 objectType = objectType.ToType(); 00213 wasTypedef = true; 00214 } 00215 if(wasTypedef){ 00216 Object tmp(objectType,objectToPrint.Address()); 00217 objectToPrint = tmp; 00218 } 00219 if(printAsBuiltin(oStream,iPrefix,iPostfix,objectToPrint,indent)) { 00220 return; 00221 } 00222 if(printAsContainer(oStream,iPrefix,iPostfix,objectToPrint,indent,iIndentDelta)){ 00223 return; 00224 } 00225 00226 oStream<<indent<<iPrefix<<formatXML(typeName)<<"\">\n"; 00227 printDataMembers(oStream,objectToPrint,objectType,indent+iIndentDelta,iIndentDelta); 00228 oStream<<indent<<iPostfix<<"\n"; 00229 00230 }
static std::string const& typeidToName | ( | std::type_info const & | iID | ) | [static] |
Definition at line 72 of file XMLOutputModule.cc.
References FILLNAME.
00073 { 00074 static std::map<std::string, std::string> s_toName; 00075 if(s_toName.empty()) { 00076 FILLNAME(short); 00077 FILLNAME(int); 00078 FILLNAME(long); 00079 FILLNAME(long long); 00080 00081 FILLNAME(unsigned short); 00082 FILLNAME(unsigned int); 00083 FILLNAME(unsigned long); 00084 FILLNAME(unsigned long long); 00085 00086 FILLNAME(double); 00087 FILLNAME(float); 00088 } 00089 return s_toName[iID.name()]; 00090 }
char const* kContainerClose = "</container>" [static] |
Definition at line 67 of file XMLOutputModule.cc.
Referenced by printAsContainer(), printContentsOfStdContainer(), and printObject().
char const* kContainerOpen = "<container size=\"" [static] |
Definition at line 66 of file XMLOutputModule.cc.
Referenced by printAsContainer(), printContentsOfStdContainer(), and printObject().
char const* kNameValueSep = "\">" [static] |
Definition at line 65 of file XMLOutputModule.cc.
std::string const kObjectClose = "</object>" [static] |
Definition at line 69 of file XMLOutputModule.cc.
Referenced by printAsContainer(), printContentsOfStdContainer(), and printObject().
std::string const kObjectOpen = "<object type=\"" [static] |
Definition at line 68 of file XMLOutputModule.cc.
Referenced by printAsContainer(), printContentsOfStdContainer(), and printObject().