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))) {
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) {
254 std::string typeName(objectToPrint.TypeOf().Name(Reflex::SCOPED));
255 if(typeName.empty()){
256 typeName=
"{unknown}";
261 bool wasTypedef =
false;
262 while(objectType.IsTypedef()) {
263 objectType = objectType.ToType();
267 Reflex::Object
tmp(objectType, objectToPrint.Address());
270 if(printAsBuiltin(oStream, iPrefix, iPostfix, objectToPrint, indent)) {
273 if(printAsContainer(oStream, iPrefix, iPostfix, objectToPrint, indent, iIndentDelta)){
277 oStream << indent << iPrefix << formatXML(typeName) <<
"\">\n";
278 printDataMembers(oStream, objectToPrint, objectType, indent+iIndentDelta, iIndentDelta);
279 oStream << indent << iPostfix <<
"\n";
283 void printDataMembers(std::ostream& oStream,
284 Reflex::Object
const& iObject,
286 std::string
const& iIndent,
287 std::string
const& iIndentDelta) {
289 for(Reflex::Base_Iterator itBase = iType.Base_Begin();
290 itBase != iType.Base_End();
292 printDataMembers(oStream, iObject.CastObject(itBase->ToType()), itBase->ToType(), iIndent, iIndentDelta);
294 static std::string
const kPrefix(
"<datamember name=\"");
295 static std::string
const ktype(
"\" type=\"");
296 static std::string
const kPostfix(
"</datamember>");
298 for(Reflex::Member_Iterator itMember = iType.DataMember_Begin();
299 itMember != iType.DataMember_End();
302 if (itMember->IsTransient()) {
306 std::string
prefix = kPrefix + itMember->Name() + ktype;
310 itMember->Get(iObject),
314 std::cout << iIndent << itMember->Name() <<
" <exception caught("
315 << iEx.what() <<
")>\n";
320 bool printContentsOfStdContainer(std::ostream& oStream,
321 std::string
const& iPrefix,
322 std::string
const& iPostfix,
323 Reflex::Object iBegin,
324 Reflex::Object
const& iEnd,
325 std::string
const& iIndent,
326 std::string
const& iIndentDelta){
328 std::ostringstream sStream;
329 if(iBegin.TypeOf() != iEnd.TypeOf()) {
330 std::cerr <<
" begin (" << iBegin.TypeOf().Name(Reflex::SCOPED) <<
") and end ("
331 << iEnd.TypeOf().Name(Reflex::SCOPED) <<
") are not the same type" << std::endl;
335 Reflex::Member
compare(iBegin.TypeOf().MemberByName(
"operator!="));
340 Reflex::Member incr(iBegin.TypeOf().MemberByName(
"operator++"));
345 Reflex::Member
deref(iBegin.TypeOf().MemberByName(
"operator*"));
351 std::string indexIndent = iIndent+iIndentDelta;
355 std::vector<void*> compareArgs = Reflex::Tools::MakeVector((iEnd.Address()));
356 std::vector<void*> incrArgs = Reflex::Tools::MakeVector(static_cast<void*>(&dummy));
358 Reflex::Object objCompareResult(Reflex::Type::ByTypeInfo(
typeid(
bool)), &compareResult);
359 Reflex::Object objIncr;
360 void* objIncrRefBuffer;
361 boost::shared_ptr<Reflex::Object> incrMemHolder = initReturnValue(incr, &objIncr, &objIncrRefBuffer);
363 compare.Invoke(iBegin, &objCompareResult, compareArgs), compareResult;
364 incr.Invoke(iBegin, &objIncr, incrArgs), ++
size) {
366 Reflex::Object iTemp;
367 void* derefRefBuffer;
368 boost::shared_ptr<Reflex::Object> derefMemHolder = initReturnValue(
deref, &iTemp, &derefRefBuffer);
369 deref.Invoke(iBegin, &iTemp);
370 if(iTemp.TypeOf().IsReference()) {
371 iTemp = Reflex::Object(iTemp.TypeOf(), derefRefBuffer);
373 printObject(sStream, kObjectOpen, kObjectClose, iTemp, indexIndent, iIndentDelta);
377 std::cerr <<
"while printing std container caught exception " << iE.what() << std::endl;
380 oStream << iPrefix << iIndent << kContainerOpen << size <<
"\">\n";
381 oStream << sStream.str();
382 oStream << iIndent << kContainerClose << std::endl;
388 bool printAsContainer(std::ostream& oStream,
389 std::string
const& iPrefix, std::string
const& iPostfix,
390 Reflex::Object
const& iObject,
391 std::string
const& iIndent,
392 std::string
const& iIndentDelta) {
393 Reflex::Object sizeObj;
396 sizeObj = Reflex::Object(Reflex::Type::ByTypeInfo(
typeid(
size_t)), &temp);
397 iObject.Invoke(
"size", &sizeObj);
399 if(sizeObj.TypeOf().TypeInfo() !=
typeid(size_t)) {
402 size_t size = *
reinterpret_cast<size_t*
>(sizeObj.Address());
403 Reflex::Member atMember;
404 atMember = iObject.TypeOf().MemberByName(
"at");
408 std::string typeName(iObject.TypeOf().Name(Reflex::SCOPED));
409 if(typeName.empty()){
410 typeName=
"{unknown}";
413 oStream << iIndent << iPrefix << formatXML(typeName) <<
"\">\n"
414 << iIndent << kContainerOpen << size <<
"\">\n";
415 Reflex::Object contained;
416 std::string indexIndent=iIndent+iIndentDelta;
419 boost::shared_ptr<Reflex::Object> atMemHolder = initReturnValue(atMember, &contained, &atRefBuffer);
421 atMember.Invoke(iObject, &contained, Reflex::Tools::MakeVector(static_cast<void*>(&
index)));
422 if(contained.TypeOf().IsReference()) {
423 contained = Reflex::Object(contained.TypeOf(), atRefBuffer);
427 printObject(oStream, kObjectOpen, kObjectClose, contained, indexIndent, iIndentDelta);
429 std::cout << iIndent <<
" <exception caught("
430 << iEx.what() <<
")>\n";
433 oStream << iIndent << kContainerClose << std::endl;
434 oStream << iIndent << iPostfix << std::endl;
440 std::string typeName(iObject.TypeOf().Name(Reflex::SCOPED));
441 if(typeName.empty()){
442 typeName=
"{unknown}";
444 Reflex::Object iObjBegin;
445 void* beginRefBuffer;
446 Reflex::Member beginMember = iObject.TypeOf().MemberByName(
"begin");
447 boost::shared_ptr<Reflex::Object> beginMemHolder = initReturnValue(beginMember, &iObjBegin, &beginRefBuffer);
448 Reflex::Object iObjEnd;
450 Reflex::Member endMember = iObject.TypeOf().MemberByName(
"end");
451 boost::shared_ptr<Reflex::Object> endMemHolder = initReturnValue(endMember, &iObjEnd, &endRefBuffer);
453 beginMember.Invoke(iObject, &iObjBegin);
454 endMember.Invoke(iObject, &iObjEnd);
455 if(printContentsOfStdContainer(oStream,
456 iIndent+iPrefix+formatXML(typeName)+
"\">\n",
462 if(typeName.empty()){
463 typeName=
"{unknown}";
474 void printObject(std::ostream& oStream,
476 std::string
const& iClassName,
477 std::string
const& iModuleLabel,
478 std::string
const& iInstanceLabel,
479 std::string
const& iIndent,
480 std::string
const& iIndentDelta) {
484 std::cout << iIndent <<
" \"" << iClassName <<
"\"" <<
" is an unknown type" << std::endl;
488 iEvent.getByLabel(iModuleLabel, iInstanceLabel,
handle);
489 std::string
className = formatXML(iClassName);
490 printObject(oStream, kObjectOpen, kObjectClose, *
handle, iIndent, iIndentDelta);
503 stream_(iPSet.getUntrackedParameter<std::string>(
"fileName").c_str()),
508 stream_ <<
"<cmsdata>" << std::endl;
517 stream_ <<
"</cmsdata>" << std::endl;
538 Event event(const_cast<EventPrincipal&>(iEP), desc);
539 stream_ <<
"<event run=\"" <<
event.id().run() <<
"\" number=\"" <<
event.id().event() <<
"\" >\n";
544 stream_ <<
"<product type=\"" << (*itBD)->friendlyClassName()
545 <<
"\" module=\"" << (*itBD)->moduleLabel()
546 <<
"\" productInstance=\"" << (*itBD)->productInstanceName() <<
"\">\n";
549 (*itBD)->className(),
550 (*itBD)->moduleLabel(),
551 (*itBD)->productInstanceName(),
556 stream_ <<
"</event>" << std::endl;
562 desc.
setComment(
"Prints event information into a file in XML format.");
565 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)
bool isFirst(HepMC::GenParticle *x)
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)
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)