|
//____________________________________________________________________ // // BrCopyModule // // This module makes it possible to copy BrDataObjects from one event // node to another in a script runned by bratmain. // // BrDataObjects (or objects of classes that inherits from // BrDataObject) with names specified in the fObjectNames array will // be copied (from inNode to outNode) when the event method of // BrCopyModule is called. The names of the object that should be // copied can be set by the AddObject and RemoveObject methods. // // If the name of an event node is specified all the objects it // contains will be copied. // // If an name of an object that is contained by an event node is // specified only the object will be copied -- the above data // structure is not kept in the output node. (an option that tells if // the data structure should be kept or not could perhaps be added // later!) // //____________________________________________________________________ // // $Id: BrCopyModule.cxx,v 1.1 2001/07/19 11:48:11 ekman Exp $ // $Author: ekman $ // $Date: 2001/07/19 11:48:11 $ // $Copyright: (C) 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov> // #ifndef BRAT_BrCopyModule #include "BrCopyModule.h" #endif #ifndef ROOT_TDirectory #include "TDirectory.h" #endif #ifndef WIN32 #include <iostream> #else #include <iostream.h> #endif //____________________________________________________________________ ClassImp(BrCopyModule); //____________________________________________________________________ BrCopyModule::BrCopyModule() { // Default constructor. DO NOT USE SetState(kSetup); } //____________________________________________________________________ BrCopyModule::BrCopyModule(const Char_t* name, const Char_t* title) : BrModule(name, title) { // Named Constructor SetState(kSetup); fObjectNames = new TObjArray(); } //____________________________________________________________________ void BrCopyModule::AddObject(const Char_t* name) { // add name to list of names of object to be copied if (GetState()>=kInit) { Warning("AddObject", "addition of object name is not allowed after Init()!"); return; } if(DebugLevel()>10) cout << "BrCopyModule::AddObject(): object [" << name << "] will be added to array fObjectNames" << endl; TObjString* objName; //check if the name is already in the array. if yes: return for (Int_t i=0; i<fObjectNames->GetEntries(); i++) { objName = (TObjString*)fObjectNames->At(i); if (!objName->GetString().CompareTo(name)) { //warning!!! Warning("AddObject",Form("objectName [%s] is already in array fObjectNames!",name)); return; } } //add object name fObjectNames->Add(new TObjString(name)); if(DebugLevel()>10) cout << "BrCopyModule::AddObject(): object [" << name << "] is now added to array fObjectNames" << endl; } //____________________________________________________________________ void BrCopyModule::RemoveObject(const Char_t* name) { // remove name to list of names of object to be copied if (GetState()>=kInit) { Warning("RemoveObject", "removal of object name is not allowed after Init()!"); return; } if(DebugLevel()>10) { if(fObjectNames->GetEntries()>0) cout << "BrCopyModule::RemoveObject(): object [" << name << "] will be removed from array fObjectNames" << endl; else cout << "BrCopyModule::RemoveObject(): no entries in array fObjectNames" << endl; } TObjString* objName; //loop over object names in objectName array for (Int_t i=0; i<fObjectNames->GetEntries(); i++) { objName = (TObjString*)fObjectNames->At(i); //compare object names to name if (!objName->GetString().CompareTo(name)) { //if equal remove and compress objectName array fObjectNames->RemoveAt(i); fObjectNames->Compress(); if(DebugLevel()>20) cout << "BrCopyModule::RemoveObject(): object [" << name << "] removed from array fObjectNames" << endl; return; } else { if(DebugLevel()>20) cout << "BrCopyModule::RemoveObject(): object [" << name << "] is not in array fObjectNames - cannot be removed!" << endl; } } } //____________________________________________________________________ void BrCopyModule::Event(BrEventNode* inNode, BrEventNode* outNode) { // Per event method SetState(kEvent); if(DebugLevel()>30) { cout << "BrCopyModule::Event(): "; Print("L"); } TObjString* objName; //loop over object names in objectName array for (Int_t i=0; i<fObjectNames->GetEntries(); i++) { objName = (TObjString*)fObjectNames->At(i); //objects with name objName are copied from inNode to outNode: if (inNode->GetObject(objName->GetString().Data())) { BrDataObject* obj = (BrDataObject*) inNode->GetObject(objName->GetString().Data())->Clone(); outNode->AddObject(obj); if(DebugLevel()>35) cout << "BrCopyModule::Event(): object [" << objName->GetString().Data() << "] copied from inputNode to outputNode " << endl; } else { if(DebugLevel()>35) cout << "BrCopyModule::Event(): object [" << objName->GetString().Data() << "] not found in inputNode and is therefore not copied! " << endl; } } } //____________________________________________________________________ void BrCopyModule::Print(Option_t* option) const { // Print module information // See BrModule::Print for options. // In addition this module defines the Option: // <fill in here> TString opt(option); opt.ToLower(); BrModule::Print(option); if (opt.Contains("d")) cout << endl << " Original author: Claus O. E. Jorgensen" << endl << " Last Modifications: " << endl << " $Author: ekman $" << endl << " $Date: 2001/07/19 11:48:11 $" << endl << " $Revision: 1.1 $ " << endl << endl << "-------------------------------------------------" << endl; if (opt.Contains("l")) { cout << "BrObjects with name(s) ["; TIter next(fObjectNames); TObjString* o = 0; //loop over object names in objectName array while((o = (TObjString*)next())) { cout << o->GetString() << (o == fObjectNames->Last() ? "": ", ") << flush; } cout << "] will be copied!" << endl; } } //____________________________________________________________________ // // $Log: BrCopyModule.cxx,v $ // Revision 1.1 2001/07/19 11:48:11 ekman // Added source file of BrCopyModule. See log of header for documentation. // // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|