//----------------------------------------------------------------------------- // Dec 28 2000 P.Murat: Run II STNTUPLE input module //----------------------------------------------------------------------------- #include "TROOT.h" #include "TChain.h" #include "TFile.h" #include "TSystem.h" #include "TBranchElement.h" #include "TBranchObject.h" #include "TLeafObject.h" #include "Stntuple/obj/TStnNode.hh" #include "Stntuple/obj/TStnEvent.hh" #include "Stntuple/loop/TStnAna.hh" #include "Stntuple/base/TStnDataset.hh" #include "Stntuple/loop/TStnRun2InputModule.hh" ClassImp(TStnRun2InputModule) //_____________________________________________________________________________ TStnRun2InputModule::TStnRun2InputModule(): TStnInputModule() { } //_____________________________________________________________________________ TStnRun2InputModule::TStnRun2InputModule(const char* FileName, const char* TreeName): TStnInputModule("Run2InputModule","Run II Input Module") { InitChain(FileName,TreeName); fCurrent = -1; } //_____________________________________________________________________________ TStnRun2InputModule::TStnRun2InputModule(TChain* chain): TStnInputModule("Run2InputModule","Run II Input Module") { fChain = chain; fCurrent = -1; } //_____________________________________________________________________________ TStnRun2InputModule::TStnRun2InputModule(TStnDataset* Dataset): TStnInputModule("Run2InputModule","Run II Input Module") { fDatasetList->Add(Dataset); fChain = Dataset->GetChain(); fCurrent = -1; } //_____________________________________________________________________________ TStnRun2InputModule::~TStnRun2InputModule() { } //_____________________________________________________________________________ Int_t TStnRun2InputModule::RegisterInputBranches(TStnEvent* Event) { // for each input branch create a node and add it to the ListOfNodes // this registration doesn't mean that all the branches will be read in TObjArray* list = fChain->GetListOfBranches(); TIter it(list); TBranch* input_branch; TLeafObject* leaf; const char* class_name; TStnNode* node; TClass* cl; TObjArray* list_of_nodes = Event->GetListOfInputNodes(); // Should be empty to begin with and analysis is responsible anyways list_of_nodes->Print(); //list_of_nodes->Delete(); while ((input_branch = (TBranchElement*) it.Next())) { // branch can be either TBranchElement or // TBranchObject if (strcmp(input_branch->ClassName(),"TBranchElement") == 0) class_name = ((TBranchElement*)input_branch)->GetClassName(); else { leaf = (TLeafObject*) ((TBranchObject*)input_branch)->GetLeaf(input_branch->GetName()); class_name = leaf->GetTypeName(); } cl = gROOT->GetClass(class_name); if (!cl || !cl->InheritsFrom("TStnDataBlock")) Error("RegisterInputBranches", "class %s does not inheriting from TStnDataBlock",class_name); else { node = new TStnNode(input_branch,cl,Event); list_of_nodes->Add(node); } } return 0; } //_____________________________________________________________________________ TStnNode* TStnRun2InputModule::GetNode(const char* BranchName, const char* ClassName) { // check if a node with the name exists TStnNode* node; TStnEvent* ev = fAna->GetEvent(); node = ev->FindNode(BranchName); if (node) return node; // node doesn't exist, // make sure branch exists TBranch* b = fChain->GetBranch(BranchName); if (!b) { Error("GetNode","branch %s doesn\'t exist",BranchName); return NULL; } TClass* cl = gROOT->GetClass(ClassName); if (!cl || !cl->InheritsFrom("TStnDataBlock")) { Error("GetNode","wrong class name %s",ClassName); return NULL; } // node = new TStnNode(BranchName,cl,ev); ev->GetListOfNodes()->Add(node); return node; } //_____________________________________________________________________________ Int_t TStnRun2InputModule::SetBranches() { // called by LoadTree when loading new file to get branch pointers TStnEvent* ev = fAna->GetEvent(); TIter it(ev->GetListOfNodes()); while (TStnNode* node = (TStnNode*) it.Next()) { const char* branch_name = node->GetName(); TBranch* b = fChain->GetBranch(branch_name); node->SetBranch(b); if (b != 0) { b->SetAddress(node->GetDataBlockAddress()); b->SetAutoDelete(0); } else { Error("SetBranches",Form("%s doesn\'t have branch %s", GetChain()->GetFile()->GetName(), branch_name)); } } return 0; } //_____________________________________________________________________________ int TStnRun2InputModule::BeginJob() { if (fAna->GetEvent() == 0) { fAna->SetEvent(new TStnEvent()); } return 0; } //_____________________________________________________________________________ int TStnRun2InputModule::BeginRun() { return 0; } //_____________________________________________________________________________ int TStnRun2InputModule::Event(Int_t i) { return 0; } //_____________________________________________________________________________ int TStnRun2InputModule::EndRun() { return 0; } //_____________________________________________________________________________ int TStnRun2InputModule::EndJob() { return 0; }