#ifndef IOUTIL_HH_INCLUDED #define IOUTIL_HH_INCLUDED #include "TMethodCall.h" #include "TDataMember.h" #include "TBranch.h" #include "TBranchElement.h" #include "TClass.h" #include #include using std::string; #include using std::vector; #include "Vec.hh" #include "Mat.hh" #include "Hit.hh" #include "Trk.hh" #include "Evt.hh" #include "Det.hh" #include "Head.hh" #ifdef HAVEJPP #include "JReconstruction/JEvt.hh" #include "km3net-dataformat/definitions/reconstruction.hh" inline void read( Trk& trk, JFIT::JFit& fit) { trk.pos.set( fit.getX(), fit.getY(), fit.getZ() ); trk.dir.set( fit.getDX(), fit.getDY(), fit.getDZ()); trk.t = fit.getT(); trk.E = fit.getE(); trk.lik = fit.getQ(); trk.rec_type = JPP_RECONSTRUCTION_TYPE; trk.error_matrix = fit.getV(); trk.fitinf = fit.getW(); trk.status = fit.getStatus(); trk.rec_stages.clear(); for(auto h : fit.getHistory() ) { trk.rec_stages.push_back( h.type ); } } inline void read( Evt& evt , JFIT::JEvt jevt ) { for( auto& f : jevt ) { Trk t; read( t, f ); evt.trks.push_back( t ); } } #endif /*! return a list of sub-brachnes as c++ variable declaration string */ inline string generate_member_list( TBranchElement* B ) { string s=""; for( auto m : *(B->GetListOfBranches() ) ) { TBranchElement* b = (TBranchElement*) m; s += string( b->GetTypeName() )+ " " + b->GetName() + ";\n"; } return s; } /*! return string containing c++ definition of class corresponding to branch -- for simple brances */ inline string generate_class( TBranchElement* B ) { int nmembers = B->GetListOfBranches()->GetEntries(); if ( nmembers == 0 ) return ""; string s = string("struct ") +B -> GetClassName() +"\n{\n" + generate_member_list(B) + "};\n"; return s; } /* return the TClass of a datamember */ inline TClass* getclass_of_datamember( TDataMember* m ) { const char* n = m->GetTypeName(); if (!n) return nullptr; TClass* c = TClass::GetClass( n ); return c; } vector< vector< string > > get_datamembers( TClass* c, void* obj_ptr ); // in cc file vector< vector< string > > get_all_datamembers( TClass* c, void* obj_ptr ); template vector< vector< string > > get_all_datamembers( T& obj ) { return get_all_datamembers( obj.IsA(), &obj); } void xdump_( const std::type_info& t, void* obj_ptr ); void xdump_( TClass* c, void* obj_ptr ); template void dump(const T& obj) { xdump_( typeid(obj), (void*) &obj ); } #define ADD_PRINT( T ) \ namespace cling \ { \ inline std::string printValue(const T* t) \ { \ ostringstream s; \ t->print(s); \ return s.str(); \ } \ } #define ADD_OSTREAM(T) \ inline std::ostream& operator<<(std::ostream& out, const T& obj) \ { \ obj.print(out ); \ return out; \ } #define ADD_DUMP(T) \ template void dump(const T& obj); // explicit template instantiation (for pyroot) #define ADD_PRINTING(T) \ ADD_PRINT( T ) \ ADD_OSTREAM( T ) \ ADD_DUMP( T ) ADD_PRINT( Vec ) ADD_DUMP( Vec ) ADD_PRINTING( Mat ) ADD_PRINTING( Hit ) ADD_PRINTING( Trk ) ADD_PRINTING( Evt ) ADD_PRINTING( Pmt ) ADD_PRINTING( Dom ) ADD_PRINT( Head ) #endif