21 #include "Reflex/Base.h"
22 #include "Reflex/Member.h"
73 void callDestruct(Reflex::Object* iObj) {
79 boost::shared_ptr<Reflex::Object> initReturnValue(Reflex::Member
const& iMember,
83 if(returnType.IsReference()) {
84 *iObj = Reflex::Object(returnType, iRefBuffer);
85 return boost::shared_ptr<Reflex::Object>(iObj,
doNotDelete);
87 *iObj = returnType.Construct();
88 return boost::shared_ptr<Reflex::Object>(iObj, callDestruct);
92 std::string formatXML(std::string
const& iO) {
94 static std::string
const kSubs(
"<>&");
95 static std::string
const kLeft(
"<");
96 static std::string
const kRight(
">");
97 static std::string
const kAmp(
"&");
100 while(std::string::npos != (i =
result.find_first_of(kSubs, i))) {
103 result.replace(i, 1, kLeft);
106 result.replace(i, 1, kRight);
109 result.replace(i, 1, kAmp);
116 char const* kNameValueSep =
"\">";
117 char const* kContainerOpen =
"<container size=\"";
118 char const* kContainerClose =
"</container>";
119 std::string
const kObjectOpen =
"<object type=\"";
120 std::string
const kObjectClose =
"</object>";
122 #define FILLNAME(_type_) s_toName[typeid(_type_).name()]= #_type_;
123 std::string
const& typeidToName(std::type_info
const& iID) {
124 static std::map<std::string, std::string> s_toName;
125 if(s_toName.empty()) {
139 return s_toName[iID.name()];
143 void doPrint(std::ostream& oStream, std::string
const& iPrefix, std::string
const& iPostfix, Reflex::Object
const& iObject, std::string
const& iIndent) {
144 oStream << iIndent << iPrefix << typeidToName(
typeid(T)) << kNameValueSep
145 << *
reinterpret_cast<T*
>(iObject.Address()) << iPostfix <<
"\n";
149 void doPrint<char>(std::ostream& oStream, std::string
const& iPrefix, std::string
const& iPostfix, Reflex::Object
const& iObject, std::string
const& iIndent) {
150 oStream << iIndent << iPrefix <<
"char" << kNameValueSep
151 <<
static_cast<int>(*
reinterpret_cast<char*
>(iObject.Address())) << iPostfix <<
"\n";
155 void doPrint<unsigned char>(std::ostream& oStream, std::string
const& iPrefix, std::string
const& iPostfix, Reflex::Object
const& iObject, std::string
const& iIndent) {
156 oStream << iIndent << iPrefix <<
"unsigned char" << kNameValueSep << static_cast<unsigned int>(*
reinterpret_cast<unsigned char*
>(iObject.Address())) << iPostfix <<
"\n";
160 void doPrint<bool>(std::ostream& oStream, std::string
const& iPrefix, std::string
const& iPostfix, Reflex::Object
const& iObject, std::string
const& iIndent) {
161 oStream << iIndent << iPrefix <<
"bool" << kNameValueSep
162 << ((*
reinterpret_cast<bool*
>(iObject.Address()))?
"true":
"false") << iPostfix <<
"\n";
166 typedef void(*FunctionType)(std::ostream&, std::string
const&,
167 std::string
const&, Reflex::Object
const&, std::string
const&);
168 typedef std::map<std::string, FunctionType> TypeToPrintMap;
171 void addToMap(TypeToPrintMap& iMap){
172 iMap[
typeid(T).
name()]=doPrint<T>;
175 bool printAsBuiltin(std::ostream& oStream,
176 std::string
const& iPrefix,
177 std::string
const& iPostfix,
178 Reflex::Object
const iObject,
179 std::string
const& iIndent){
180 typedef void(*FunctionType)(std::ostream&, std::string
const&, std::string
const&, Reflex::Object
const&, std::string
const&);
181 typedef std::map<std::string, FunctionType> TypeToPrintMap;
182 static TypeToPrintMap s_map;
185 addToMap<bool>(s_map);
186 addToMap<char>(s_map);
187 addToMap<short>(s_map);
188 addToMap<int>(s_map);
189 addToMap<long>(s_map);
190 addToMap<unsigned char>(s_map);
191 addToMap<unsigned short>(s_map);
192 addToMap<unsigned int>(s_map);
193 addToMap<unsigned long>(s_map);
194 addToMap<float>(s_map);
195 addToMap<double>(s_map);
198 TypeToPrintMap::iterator itFound =s_map.find(iObject.TypeOf().TypeInfo().name());
199 if(itFound == s_map.end()){
203 itFound->second(oStream, iPrefix, iPostfix, iObject, iIndent);
207 bool printAsContainer(std::ostream& oStream,
208 std::string
const& iPrefix,
209 std::string
const& iPostfix,
210 Reflex::Object
const& iObject,
211 std::string
const& iIndent,
212 std::string
const& iIndentDelta);
214 void printDataMembers(std::ostream& oStream,
215 Reflex::Object
const& iObject,
217 std::string
const& iIndent,
218 std::string
const& iIndentDelta);
220 void printObject(std::ostream& oStream,
221 std::string
const& iPrefix,
222 std::string
const& iPostfix,
223 Reflex::Object
const& iObject,
224 std::string
const& iIndent,
225 std::string
const& iIndentDelta) {
226 Reflex::Object objectToPrint = iObject;
227 std::string
indent(iIndent);
228 if(iObject.TypeOf().IsPointer()) {
229 oStream << iIndent << iPrefix << formatXML(iObject.TypeOf().Name(Reflex::SCOPED)) <<
"\">\n";
231 int size = (0!=iObject.Address()) ? (0!=*reinterpret_cast<void**>(iObject.Address())?1:0) : 0;
232 oStream << indent << kContainerOpen << size <<
"\">\n";
234 std::string indent2 = indent + iIndentDelta;
235 Reflex::Object
obj(iObject.TypeOf().ToType(), *
reinterpret_cast<void**
>(iObject.Address()));
237 printObject(oStream, kObjectOpen, kObjectClose,
obj, indent2, iIndentDelta);
239 oStream << indent << kContainerClose <<
"\n";
240 oStream << iIndent << iPostfix <<
"\n";
242 if(Reflex::Type::ByName(
"void") == pointedType || pointedType.IsPointer() || iObject.Address()==0) {
248 objectToPrint = Reflex::Object(pointedType, iObject.Address());
250 objectToPrint = Reflex::Object(objectToPrint.CastObject(objectToPrint.DynamicType()));
251 indent +=iIndentDelta;
253 std::string typeName(objectToPrint.TypeOf().Name(Reflex::SCOPED));
254 if(typeName.empty()){
255 typeName=
"{unknown}";
260 bool wasTypedef =
false;
261 while(objectType.IsTypedef()) {
262 objectType = objectType.ToType();
266 Reflex::Object
tmp(objectType, objectToPrint.Address());
269 if(printAsBuiltin(oStream, iPrefix, iPostfix, objectToPrint, indent)) {
272 if(printAsContainer(oStream, iPrefix, iPostfix, objectToPrint, indent, iIndentDelta)){
276 oStream << indent << iPrefix << formatXML(typeName) <<
"\">\n";
277 printDataMembers(oStream, objectToPrint, objectType, indent+iIndentDelta, iIndentDelta);
278 oStream << indent << iPostfix <<
"\n";
282 void printDataMembers(std::ostream& oStream,
283 Reflex::Object
const& iObject,
285 std::string
const& iIndent,
286 std::string
const& iIndentDelta) {
288 for(Reflex::Base_Iterator itBase = iType.Base_Begin();
289 itBase != iType.Base_End();
291 printDataMembers(oStream, iObject.CastObject(itBase->ToType()), itBase->ToType(), iIndent, iIndentDelta);
293 static std::string
const kPrefix(
"<datamember name=\"");
294 static std::string
const ktype(
"\" type=\"");
295 static std::string
const kPostfix(
"</datamember>");
297 for(Reflex::Member_Iterator itMember = iType.DataMember_Begin();
298 itMember != iType.DataMember_End();
301 if (itMember->IsTransient()) {
305 std::string
prefix = kPrefix + itMember->Name() + ktype;
309 itMember->Get(iObject),
313 std::cout << iIndent << itMember->Name() <<
" <exception caught("
314 << iEx.what() <<
")>\n";
319 bool printContentsOfStdContainer(std::ostream& oStream,
320 std::string
const& iPrefix,
321 std::string
const& iPostfix,
322 Reflex::Object iBegin,
323 Reflex::Object
const& iEnd,
324 std::string
const& iIndent,
325 std::string
const& iIndentDelta){
327 std::ostringstream sStream;
328 if(iBegin.TypeOf() != iEnd.TypeOf()) {
329 std::cerr <<
" begin (" << iBegin.TypeOf().Name(Reflex::SCOPED) <<
") and end ("
330 << iEnd.TypeOf().Name(Reflex::SCOPED) <<
") are not the same type" << std::endl;
334 Reflex::Member
compare(iBegin.TypeOf().MemberByName(
"operator!="));
339 Reflex::Member incr(iBegin.TypeOf().MemberByName(
"operator++"));
344 Reflex::Member
deref(iBegin.TypeOf().MemberByName(
"operator*"));
350 std::string indexIndent = iIndent+iIndentDelta;
354 std::vector<void*> compareArgs = Reflex::Tools::MakeVector((iEnd.Address()));
355 std::vector<void*> incrArgs = Reflex::Tools::MakeVector(static_cast<void*>(&dummy));
357 Reflex::Object objCompareResult(Reflex::Type::ByTypeInfo(
typeid(
bool)), &compareResult);
358 Reflex::Object objIncr;
359 void* objIncrRefBuffer;
360 boost::shared_ptr<Reflex::Object> incrMemHolder = initReturnValue(incr, &objIncr, &objIncrRefBuffer);
362 compare.Invoke(iBegin, &objCompareResult, compareArgs), compareResult;
363 incr.Invoke(iBegin, &objIncr, incrArgs), ++
size) {
365 Reflex::Object iTemp;
366 void* derefRefBuffer;
367 boost::shared_ptr<Reflex::Object> derefMemHolder = initReturnValue(
deref, &iTemp, &derefRefBuffer);
368 deref.Invoke(iBegin, &iTemp);
369 if(iTemp.TypeOf().IsReference()) {
370 iTemp = Reflex::Object(iTemp.TypeOf(), derefRefBuffer);
372 printObject(sStream, kObjectOpen, kObjectClose, iTemp, indexIndent, iIndentDelta);
376 std::cerr <<
"while printing std container caught exception " << iE.what() << std::endl;
379 oStream << iPrefix << iIndent << kContainerOpen << size <<
"\">\n";
380 oStream << sStream.str();
381 oStream << iIndent << kContainerClose << std::endl;
387 bool printAsContainer(std::ostream& oStream,
388 std::string
const& iPrefix, std::string
const& iPostfix,
389 Reflex::Object
const& iObject,
390 std::string
const& iIndent,
391 std::string
const& iIndentDelta) {
392 Reflex::Object sizeObj;
395 sizeObj = Reflex::Object(Reflex::Type::ByTypeInfo(
typeid(
size_t)), &temp);
396 iObject.Invoke(
"size", &sizeObj);
398 if(sizeObj.TypeOf().TypeInfo() !=
typeid(size_t)) {
401 size_t size = *
reinterpret_cast<size_t*
>(sizeObj.Address());
402 Reflex::Member atMember;
403 atMember = iObject.TypeOf().MemberByName(
"at");
407 std::string typeName(iObject.TypeOf().Name(Reflex::SCOPED));
408 if(typeName.empty()){
409 typeName=
"{unknown}";
412 oStream << iIndent << iPrefix << formatXML(typeName) <<
"\">\n"
413 << iIndent << kContainerOpen << size <<
"\">\n";
414 Reflex::Object contained;
415 std::string indexIndent=iIndent+iIndentDelta;
418 boost::shared_ptr<Reflex::Object> atMemHolder = initReturnValue(atMember, &contained, &atRefBuffer);
420 atMember.Invoke(iObject, &contained, Reflex::Tools::MakeVector(static_cast<void*>(&
index)));
421 if(contained.TypeOf().IsReference()) {
422 contained = Reflex::Object(contained.TypeOf(), atRefBuffer);
426 printObject(oStream, kObjectOpen, kObjectClose, contained, indexIndent, iIndentDelta);
428 std::cout << iIndent <<
" <exception caught("
429 << iEx.what() <<
")>\n";
432 oStream << iIndent << kContainerClose << std::endl;
433 oStream << iIndent << iPostfix << std::endl;
439 std::string typeName(iObject.TypeOf().Name(Reflex::SCOPED));
440 if(typeName.empty()){
441 typeName=
"{unknown}";
443 Reflex::Object iObjBegin;
444 void* beginRefBuffer;
445 Reflex::Member beginMember = iObject.TypeOf().MemberByName(
"begin");
446 boost::shared_ptr<Reflex::Object> beginMemHolder = initReturnValue(beginMember, &iObjBegin, &beginRefBuffer);
447 Reflex::Object iObjEnd;
449 Reflex::Member endMember = iObject.TypeOf().MemberByName(
"end");
450 boost::shared_ptr<Reflex::Object> endMemHolder = initReturnValue(endMember, &iObjEnd, &endRefBuffer);
452 beginMember.Invoke(iObject, &iObjBegin);
453 endMember.Invoke(iObject, &iObjEnd);
454 if(printContentsOfStdContainer(oStream,
455 iIndent+iPrefix+formatXML(typeName)+
"\">\n",
461 if(typeName.empty()){
462 typeName=
"{unknown}";
473 void printObject(std::ostream& oStream,
475 std::string
const& iClassName,
476 std::string
const& iModuleLabel,
477 std::string
const& iInstanceLabel,
478 std::string
const& iIndent,
479 std::string
const& iIndentDelta) {
483 std::cout << iIndent <<
" \"" << iClassName <<
"\"" <<
" is an unknown type" << std::endl;
487 iEvent.getByLabel(iModuleLabel, iInstanceLabel,
handle);
488 std::string
className = formatXML(iClassName);
489 printObject(oStream, kObjectOpen, kObjectClose, *
handle, iIndent, iIndentDelta);
502 stream_(iPSet.getUntrackedParameter<std::string>(
"fileName").c_str()),
507 stream_ <<
"<cmsdata>" << std::endl;
516 stream_ <<
"</cmsdata>" << std::endl;
537 Event event(const_cast<EventPrincipal&>(iEP), desc);
538 stream_ <<
"<event run=\"" <<
event.id().run() <<
"\" number=\"" <<
event.id().event() <<
"\" >\n";
543 stream_ <<
"<product type=\"" << (*itBD)->friendlyClassName()
544 <<
"\" module=\"" << (*itBD)->moduleLabel()
545 <<
"\" productInstance=\"" << (*itBD)->productInstanceName() <<
"\">\n";
548 (*itBD)->className(),
549 (*itBD)->moduleLabel(),
550 (*itBD)->productInstanceName(),
555 stream_ <<
"</event>" << std::endl;
561 desc.
setComment(
"Prints event information into a file in XML format.");
564 descriptions.
add(
"XMLoutput", desc);
T getUntrackedParameter(std::string const &, T const &) const
virtual void writeRun(RunPrincipal const &)
SelectionsArray const & keptProducts() const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual void write(EventPrincipal const &e)
#define DEFINE_FWK_MODULE(type)
XMLOutputModule const & operator=(XMLOutputModule const &)
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &)
Type returnType(const Member &mem)
XMLOutputModule(ParameterSet const &)
void setComment(std::string const &value)
tuple obj
Example code starts here #.
T::value_type deref(T &iT)
#define FILLNAME(_type_)
convert the object information to the correct type and print it
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual ~XMLOutputModule()
static void fillDescriptions(ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescription(ParameterSetDescription &desc)
std::vector< std::vector< double > > tmp
tuple size
Write out results.
std::string className(const T &t)