22 #include <TInterpreter.h>
30 printout(FATAL,
"Geant4ROOTDump",
"usage: Geant4ROOTDump -opt (app-opts) --opt=value (plugin-opts)");
31 printout(FATAL,
"Geant4ROOTDump",
" app-opts: ");
32 printout(FATAL,
"Geant4ROOTDump",
" -print INFO Print container summaries only.");
33 printout(FATAL,
"Geant4ROOTDump",
" -print DEBUG Print container content as well.");
34 printout(FATAL,
"Geant4ROOTDump",
" -print VERBOSE Print full data.");
35 printout(FATAL,
"Geant4ROOTDump",
" plugin opts: ");
36 printout(FATAL,
"Geant4ROOTDump",
" --usage: Print this output.");
37 printout(FATAL,
"Geant4ROOTDump",
" --input=<file> Print content of this file.");
38 printout(FATAL,
"Geant4ROOTDump",
" --entry=<number> Print specified event in the file. (starts with 0!)");
42 static std::pair<TClass*,void*> load(TBranch* branch,
int entry) {
43 TClass* cl = gROOT->GetClass(branch->GetClassName(),kTRUE);
45 return std::pair<TClass*,void*>(0,0);
47 void *obj = cl->New();
48 branch->SetAddress(&obj);
49 branch->SetAutoDelete(kFALSE);
50 int nb = branch->GetEntry(entry);
53 return std::pair<TClass*,void*>(0,0);
55 return std::pair<TClass*,void*>(cl,obj);
60 std::string input =
"", tag=
"Geant4ROOTDump";
63 for(
int j=0; j<argc; ++j) {
64 std::string a = argv[j];
65 if ( a[0]==
'-' ) a = argv[j]+1;
66 if ( a[0]==
'-' ) a = argv[j]+2;
67 size_t idx = a.find(
'=');
68 if ( strncmp(a.c_str(),
"usage",5)==0 ) {
73 std::string p1 = a.substr(0,idx);
74 std::string p2 = a.substr(idx+1);
75 if ( strncmp(p1.c_str(),
"input",3)==0 ) {
78 if ( strncmp(p1.c_str(),
"entry",5)==0 ) {
79 if ( 1 != ::sscanf(p2.c_str(),
"%d",&entry) ) {
80 printout(FATAL,tag,
"+++ Argument %s is not properly formatted. must be --entry=<number>.",argv[j]);
86 printout(FATAL,tag,
"+++ Argument %s is IGNORED! No value is found (string has no '=')",argv[j]);
89 const char* line =
"+----------------------------------------------------------------------------------+";
90 printout(INFO,tag,line);
91 printout(INFO,tag,
"| Input:%-74s|",input.c_str());
92 printout(INFO,tag,line);
94 if ( input.empty() ) {
99 TFile* f = TFile::Open(input.c_str());
101 if ( f && !f->IsZombie() ) {
102 TTree* tree = (TTree*)f->Get(
"EVENT");
106 TObjArray* branches = tree->GetListOfBranches();
107 Int_t nbranches = branches->GetEntriesFast();
108 typedef std::pair<TClass*,void*> ENTRY;
109 typedef std::map<std::string,ENTRY> ENTRIES;
111 for(Int_t ievt=entry<0 ? 0 : entry, nevt=entry<0 ? tree->GetEntries() : entry+1; ievt<nevt; ++ievt) {
113 printout(INFO,tag,line);
114 printout(INFO,tag,
"| Event: %6d |",ievt);
115 printout(INFO,tag,line);
118 for (Int_t i=0;i<nbranches;i++) {
119 TBranch* branch = (TBranch*)branches->UncheckedAt(i);
120 std::pair<TClass*,void*> data = load(branch,ievt);
121 if ( data.first )
event[branch->GetName()] = std::move(data);
124 for(ENTRIES::const_iterator i=event.begin(); i!=event.end(); ++i) {
125 std::pair<TClass*,void*> data = (*i).second;
126 if ( data.first == cl_particles ) {
128 dump.print(INFO, (*i).first, parts);
129 for_each(parts->begin(), parts->end(), detail::DestroyObject<dd4hep::sim::Geant4Particle*>());
132 for(ENTRIES::const_iterator i=event.begin(); i!=event.end(); ++i) {
133 std::pair<TClass*,void*> data = (*i).second;
134 if ( data.first == cl_particles ) {
136 else if ( data.first == cl_tracker ) {
138 dump.print(INFO, (*i).first, hits);
139 for_each(hits->begin(), hits->end(), detail::DestroyObject<dd4hep::sim::Geant4Tracker::Hit*>());
141 else if ( data.first == cl_calo ) {
143 dump.print(INFO, (*i).first, hits);
144 for_each(hits->begin(), hits->end(), detail::DestroyObject<dd4hep::sim::Geant4Calorimeter::Hit*>());
146 if ( data.first ) data.first->Destructor(data.second);
152 printout(FATAL,tag,
"+++ FAILED to open input file:%s",input.c_str());