|
// // BrParameterDbManager // // This manager class will be the owner of the DetectorParameter // Objects Its intended use if for a user module to access database // only via this mechanism, and not by opening any files by // themselves. It also ensures that in the case that several user // modules uses a given geometry it is ensured that // a) The refer to the same object // b) The application can use the setter methods to change values for a // geometry constant and will thus be the same for all modules. // c) The objects are owned by the manager and will be deleted only // when the program exists (The instance is a static object). // // Sample code: // // The application can load the Manager and keep a global pointer // accesible via a Brat common application file. It is in fact // implemented via a Singletom mechanism. This enables us to use both // the global mechanism as well as the instantons. // // Main application will have // --------------------------- // BrParameterDbManager *gParamDb = BrParameterDbManager::Instance(); // // gGeomDb->SetParameterFileName("DetectorParameters.txt"); // // The user module should have (either in the Named Constructor // or in the Init() method. // ------------------------------------ // BrParameterDbManager *gParamDb = BrParameterDbManager::Instance(); // // BrDetectorParamsDC* par = (BrDetectorParamsDC*) // gParamDb->GetDetectorVolume("BrDetectorParamsDC",name); // // where name may have been obtained from either the name of the module // example BrDigitizeTPC name == GetName() // or from another entry in the contsructor (e.g. name of tracking // chambers. // // // $Id: BrParameterDbManager.cxx,v 1.1.1.1 2001/06/21 14:55:17 hagel Exp $ // $Author: hagel $ // $Date: 2001/06/21 14:55:17 $ // #include <cstdio> #include <BrIostream.h> // // ROOT classes //#include "CallFunc.h" #include "TMethodCall.h" #include "TClass.h" #ifndef ROOT_TROOT #include "TROOT.h" #endif // // Brat classes #include "BrParameterDbManager.h" #include "BrGeometryDbManager.h" //to be able to use BrDbObject ClassImp(BrParameterDbManager); //____________________________________________________ // // Static instance of // BrParameterDbManager* BrParameterDbManager::fInstance=0; //____________________________________________________ // BrParameterDbManager::BrParameterDbManager() { // CTOR - DO NOT USE - use Instance instead fObjectlist = new TObjArray(); fState = INIT; fDebugLevel = 0; //fMethodCall = new TMethodCall(); } //____________________________________________________ BrParameterDbManager* BrParameterDbManager::Instance() { // Get an isntance of the manager if( fInstance == 0) fInstance = new BrParameterDbManager; return fInstance; } //__________________________________________________ BrParameterDbManager::~BrParameterDbManager() { // DTOR if(!fObjectlist) fObjectlist->Delete(); delete fObjectlist; } //_________________________________________________________ void BrParameterDbManager::SetDbParameterFileName(Char_t* filename) { // Set the parameter file name, usually "DetectorParameters.txt" is // fine strcpy(fFileName, filename); fState = OPEN; } //_________________________________________________________ Bool_t BrParameterDbManager::Open(Char_t* filename) { // Open the parameter file strcpy(fFileName, filename); fState = OPEN; return kTRUE; } //___________________________________________________________ TObject* BrParameterDbManager::GetDetectorParameters(const Char_t* classname, const Char_t* detector){ //Return a pointer to the concrete class. //This is the only place where specific references to concrete class are //given. But in order to avoid cyclic dependencies, references are //made indirectly through the TMethodCall interface. That also makes //this routine much more general. It should not have to be modified //whenever a new parameter class is added. The only thing one has to //take care of is that the parameter class inherits from TObject, or //better yet (I think) TNamed. They must also have a constructor //with 3 arguments that are Char_t *'s, eg //BrDetectorParamsTof::BrDetectorParamsTof(Char_t *name,Char_t *title,Char_t *filename) BrDbObject* obj; if(fDebugLevel > 1) { cout <<"GetDetectorParams Requestn "; cout << classname << " : " << detector <<endl; } if((obj = GetDbObject(classname, detector))) { if(fDebugLevel > 0){ cout << "Found " << detector << "n"; cout << obj << endl; } return (obj->fDetectorGeometry); } else { // Create a TClass for classname, e.g. BrDetectorParamsTof //TClass *cl = new TClass(classname,0); TClass *cl = gROOT->GetClass(classname); TMethodCall *call = new TMethodCall(); //G__CallFunc func; //void *address; //long offset; if(fState == OPEN) { // Set the call function to the constructor of the class we want. In this case // we hope the user is asking for a parameter class, but for the purposes of // this routine, it will not make any difference as long as there is a method // of classname with arguments of three Char_t *'s if(fDebugLevel > 1) { cout<<"Setting func for class = "<<classname<<endl; cout<<"Class created = "<<cl->GetName()<<endl; } call->InitWithPrototype(cl,classname,"Char_t *,Char_t *,Char_t *"); //First, set the args Long_t args[3]; args[0] = (Long_t)detector; args[1] = (Long_t)detector; args[2] = (Long_t)fFileName; call->SetParamPtrs(args); //func.SetFunc(cl->GetClassInfo()->GetMethod(classname, // "Char_t *,Char_t *,Char_t *", &offset).InterfaceMethod()); if(fDebugLevel > 1) { cout<<"Setting args, detector = "<<detector; cout<<" filename = "<<fFileName<<endl; } // Set arguments to what we want for the arguments of the constructor //func.SetArg((long)detector); //Name //func.SetArg((long)detector); //Title //func.SetArg((long)fFileName); //FileName } else if(fState == DEFAULT_PARAMETER_SET || fState == INIT) { //Set the call function to the constructor of the class we want. //In this case we hope the user is asking for a parameter class, //but for the purposes of this routine, it will not make any //difference as long as there is a method of classname with //arguments of two Char_t *'s call->InitWithPrototype(cl,classname,"Char_t *,Char_t *"); //First, set the args Long_t args[2]; args[0] = (Long_t)detector; args[1] = (Long_t)detector; call->SetParamPtrs(args); //func.SetFunc(cl->GetClassInfo()->GetMethod(classname, // "Char_t *,Char_t *", &offset).InterfaceMethod()); //Set arguments to what we want for the arguments of the constructor //func.SetArg((long)detector); //Name //func.SetArg((long)detector); //Title } //Change the type of offset to be used as an argument to ExecInt //address = (void*)offset; if(fDebugLevel > 1)cout<<"Creating the object"<<endl; // This actually creates an instance of the class. //TObject *par = (TObject*)func.ExecInt(address); Long_t objj; call->Execute((void*)0,objj); //This executes the constructor delete call; TObject *par = (TObject*)objj; if(fDebugLevel > 1) cout<<"Object is created"<<endl; if(!par){ // Warn user that object was not found. Then return before getting // an access violation Warning("BrParameterDbManager", "Cannot execute default constructor for %s",classname); return 0; } if(fDebugLevel > 0) cout << " Adding " << classname << " for " << detector << endl; if(fDebugLevel > 1) cout << par << endl; // Make another BrDbObject with this class and add it to the object list. obj = new BrDbObject(classname, detector, par); fObjectlist->Add(obj); // Return the parameter we have been after all along return par; } //Should never get here. return 0; } //______________________________________________________________________ BrDbObject* BrParameterDbManager::GetDbObject(const Char_t* classname, const Char_t* detector) { // Find a geometry database member with the requested detector and in the // given class. // TIter next(fObjectlist); BrDbObject* dbobj; while ((dbobj = (BrDbObject*) next())){ if( !strcmp(detector, dbobj->fDetectorName) && !strcmp(classname, dbobj->fClassName)) return dbobj; } return 0; } //______________________________________________________________________ void BrParameterDbManager::List() { // List the currently registered parameter objects. TIter next(fObjectlist); BrDbObject* dbobj; cout << "BrDbManager Object List" << endl; while ((dbobj = (BrDbObject*) next())) cout << dbobj ; } // $Log: BrParameterDbManager.cxx,v $ // Revision 1.1.1.1 2001/06/21 14:55:17 hagel // Initial revision of brat2 // // Revision 1.15 2001/06/05 18:41:58 cholm // Removed BrDbInc.h an all references to it // // Revision 1.14 2001/03/07 17:48:16 hagel // Change from use of G__CallFunc to TMethodCall to clean up. Also, remove delete cl (TClass) because of new crashes in root v3 // // Revision 1.13 2001/03/07 12:18:28 cholm // * BrDb... classes changed no to use BrException classes. // * Better user authentification in BrDb. // // Revision 1.12 2000/11/17 22:23:13 videbaek // Clean up of cvsinfo and log // // Revision 1.11 2000/03/21 21:21:56 cholm // Several changes: A few hacks where needed to compile on Digital Unix, noticably in my - Christian Holm - classes for the DB and Exceptions. Proberly still need to do something to some of Konstantins stuff. Also, I removed a lot of warnings fromt the compiler, by teddying up the code. Several places, old C-style indecies in for loops were assumed. Corrected. Unused variables have been commented out. // // Revision 1.10 1999/04/21 14:42:08 videbaek // Removed diasnostic Instance adress print outs // // Revision 1.9 1999/03/07 22:43:47 videbaek // Cosmetic changes (apostrophe removed // // Revision 1.8 1999/03/07 00:00:43 hagel // 1. Implemented BrFSTrackingModule. Started with BrMRSTrackingModule and made // appropriate changes to handle the forward spectrometer. It uses the new // track classes as well as extensively using geometry classes. It also uses // new methods and functionality as described below. // 2. Changed BrMagnetVolume // a. Added method SwimBack(BrLine3D &,Double_t momentum): takes a // track at the exit of magnet and given the momentum, calculates // where the track would come into the front of the magnet. // b. Added method GlobalToLocal(BrLine3D &): does a combination of // GlobalToLocal(BrVector3D &,BrVector3D&,0) and // GlobalToLocal(BrVector3D &,BrVector3D&,1) // c. Added method LocalToGlobal(BrLine3D &): does a combination of // LocalToGlobal(BrVector3D &,BrVector3D&,0) and // LocalToGlobal(BrVector3D &,BrVector3D&,1) // d. Changed BrDetectorVolume: same additions of methods GlobalToLocal // and LocalToGlobal as in BrMagnetVolume // 2. Added a parameter base class BrDetectorParamsBase: helps when reading // in database files. Declared ASCII reading routines to be virtual. // Has main ReadASCIIFile which decodes the ASCII parameter files, then // calls the detector specific methods SetASCIIParameter // 3. Implemented SetASCIIParameter in BrDetectorParamsDC, BrDetectorParamsTPC, // BrDetectorParamsTof, BrDetectorParamsBB // 4. Implemented BrParameterDbManager. It currently works similarly to // BrGeometryDbManager and creates the BrDetectorParamsXXX objects when // called. These objects then read in ASCII parameter files with a currently // "well defined" format using the above implemented routines using a constructor: // BrDetectorParamsXXX(Char_t *name, Char_t *title,Char_t *ASCIIFileName); // 5. If no parameter file is specified, it executes the constructor we // have been using so far, namely BrDetectorParamsXXX(Char_t *name,Char_t *title). // These constructors generate default parameters and are semi-intelligent // which means they generate approximately appropriate parameters depending // upon which detector they are. I should say that the parameters were // deemed appropriate at the time of writing the SetDefaultParams routine. // a. It is used in the same way as BrGeometryDbManager, that is: // BrParameterDbManager *gParamDb = BrParameterDbManager::Instance(); // gParamDb->SetDbParameterFileName("DetectorParameters.txt"); // 6. Added a new directory, params, in BRAT. This directory has the file // DetectorParameters.txt in it. If the BrParameterDbManager is started // and the DetectorParameter.txt file is specified, it will look in the // $BRATSYS/params directory if it cannot find the file in the directory // that the user has set default to. // 7. Implemented BrParameterDbManager in DC digitize and tracking code. The // SetDetectorParams methods have been moved to private and can no longer be // used from the macro or program. // 8. Implemented BrParameterDbManager in TPC digitize and tracking code. // 9. Implemented BrParameterDbManager in Tof Calibrate and GeneratePid code. // 10 Changed the GetEntries() in BrDataTable to use the GetLast()+1 method in // TObjArray. This should be much faster, but has the caveat that it assumes // that all slots in TObjArray are full. That seems to me to be the case // in how we use TObjArray at least in BrDataTable, but if problems arise due // to this change, it can always be easily changed back. It has been used a // fair amount before checking in and no problems were found. // // // Revision 1.7 1999/02/24 15:21:23 hagel // Enforce const in arguments // // Revision 1.6 1999/02/23 21:00:58 hagel // Improve indirect access of parameter objects // // Revision 1.5 1999/02/17 23:53:02 hagel // Fix bugs in indirect access of parameter objects // // Revision 1.4 1999/02/17 22:23:46 hagel // Clean up potential memory leak // // Revision 1.3 1999/02/17 21:26:01 hagel // Removed cyclic dependencies from BrParameterDbManager. Now all references are // indirect using ROOT infrastructure to get at the classes. If this works, it is // general and should be considered for the other DbManager classes. Or perhaps // in a base DbManager class. // // Revision 1.2 1999/02/04 21:28:17 hagel // Took out BrDbObject code that had accidentally been left in during the // copy from BrGeometryDbManager. That caused conflicts. Now resolved. // // Revision 1.1 1999/02/04 20:42:30 hagel // Initial revision. // This class could in principle be redundant as the methods could be embedded // in the BrGeometryDbManager. But since parameters will in the long run // probably be handled differently than Geometry, I decided to separate them // at least for the time being. It would also be kind of funny using // BrGeometryDbManager to manage parameters. But there might be arguments // for putting all in one class and perhaps renaming it BrDbManager or something // like that. The best argument is that there would be less setup statements. // Having them separate will require yet another call to set things up. // // // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|