// $Id$ // // File: DEventSourceROOT_mcGenerator.cc // Created: Wed Aug 9 2006 // Creator: davidl (on Darwin Harriet.local 8.6.0 powerpc) // #include using std::string; #include #include #include #include "DEventSourceROOT_mcGenerator.h" #include "DEventSourceROOT_mc.h" // Routine used to allow us to register our JEventSourceGenerator extern "C"{ void InitPlugin(JApplication *app){ app->AddEventSourceGenerator(new DEventSourceROOT_mcGenerator()); } } // "C" //--------------------------------- // Description //--------------------------------- const char* DEventSourceROOT_mcGenerator::Description(void) { return "ROOT-mc for bcal06"; } //--------------------------------- // CheckOpenable //--------------------------------- double DEventSourceROOT_mcGenerator::CheckOpenable(string source) { // ROOT will print an ugly message if we try to open a non-ROOT // file (bad form ROOT!). So we restrict actually ouselves to // files with a ".root" suffix if(source.find(".root")==string::npos)return 0.0; // Make sure this is a ROOT file and that it has the right // TTree defined. TFile *f = new TFile(source.c_str()); if(!f)return 0.0; // Looks like a ROOT file. See if there is a TTree named "h999". // We do this slightly different from the ROOT documentation which // does a blind cast. (That would assume if the "h999" object is found // it must be a TTree.) bool found_h999 = false; TObject *obj = (TObject*)f->Get("h999"); if(obj){ if(dynamic_cast(obj))found_h999 = true; delete obj; } delete f; return found_h999 ? 0.9:0.0; } //--------------------------------- // MakeJEventSource //--------------------------------- JEventSource* DEventSourceROOT_mcGenerator::MakeJEventSource(string source) { return new DEventSourceROOT_mc(source.c_str()); }