// $Id$ // // File: DApplication.cc // Created: Mon Jul 3 21:46:01 EDT 2006 // Creator: davidl (on Darwin Harriet.local 8.6.0 powerpc) // #include using std::string; #include #include #include "DApplication.h" #include #include #include #include #include #include //#include "HDGEOMETRY/DMaterialMapCalibDB.h" #include #include "DFactoryGenerator.h" #include "DANARootErrorHandler.h" //--------------------------------- // DApplication (Constructor) //--------------------------------- DApplication::DApplication(int narg, char* argv[]):JApplication(narg, argv) { pthread_mutex_init(&mutex, NULL); /// Add DEventSourceHDDMGenerator and /// DFactoryGenerator, which adds the default /// list of Hall-D factories AddEventSourceGenerator(new DEventSourceHDDMGenerator()); AddFactoryGenerator(new DFactoryGenerator()); // Add plugin paths to Hall-D specific binary directories const char *bms = getenv("BMS_OSNAME"); string sbms(bms==NULL ? "":bms); if(const char *ptr = getenv("DANA_PLUGIN_PATH")){ AddPluginPath(string(ptr)); } if(const char *ptr = getenv("HALLD_MY")){ AddPluginPath(string(ptr) + "/lib/" + sbms); } if(const char *ptr = getenv("HALLD_HOME")){ AddPluginPath(string(ptr) + "/lib/" + sbms); } // Initialize pointers to NULL. Objects will be instantiated as needed bfield = NULL; lorentz_def = NULL; RootGeom = NULL; // Since we defer reading in some tables until they are requested // (likely while processing the first event) that time gets counted // against the thread as being non-reponsive. The default timeout // of 8 seconds is therefore too small. Change it to 30 here. GetJParameterManager()->SetParameter("THREAD_TIMEOUT", "30 seconds"); // when converted to a number, it via string stream, it will be 30 if(JVersion::minor<5)Init(); } //--------------------------------- // Init //--------------------------------- jerror_t DApplication::Init(void) { this->JApplication::Init(); // Install our own error handler for ROOT message int ROOT_ERROR_LEVEL_SUPRESS = 10000; GetJParameterManager()->SetDefaultParameter("ROOT_ERROR_LEVEL_SUPRESS", ROOT_ERROR_LEVEL_SUPRESS); InitDANARootErrorHandler(ROOT_ERROR_LEVEL_SUPRESS); return NOERROR; } //--------------------------------- // ~DApplication (Destructor) //--------------------------------- DApplication::~DApplication() { } //--------------------------------- // GetDGeometry //--------------------------------- DGeometry* DApplication::GetDGeometry(unsigned int run_number) { /// Get the DGeometry object for the specified run number. /// The DGeometry class is Hall-D specific. It uses the /// JGeometry class from JANA to access values in the HDDS /// XML files. However, it supplies some useful and more /// user friendly methods for getting at some of the values. /// /// This will first look for the DGeometry object in a list /// kept internal to DApplication and return a pointer to the /// object if found there. If it is not found there, then /// a new DGeometry object will be created and added to the /// internal list before returning a pointer to it. /// /// Note that since this method can change internal data /// members, a mutex is locked to ensure integrity. This /// means that it is NOT efficient to call this /// method for every event. The pointer should be obtained /// in a brun() method and kept in a local variable if /// needed outside of brun(). // At this point in time, only simulation exists with geometry coming // from a JGeometryXML object. The run range for these objects is // always set to include only the run number requested so if multiple // places in the code ask for different run numbers (as happens) a // second DGeometry object is created unecessarily. Here, we look to // see if a sole DGeometry object already exists and if so, if it is // built on a JGeometryFile object. If so, simply return it under the // assumption we are still doing development with simulated data and // a single set of geometry files. Lock(); if(geometries.size()==1 && string("JGeometryXML")==geometries[0]->GetJGeometry()->className()){ Unlock(); return geometries[0]; } Unlock(); // First, get the JGeometry object using our JApplication // base class. Then, use that to find the correct DGeometry // object if it exists. JGeometry *jgeom = GetJGeometry(run_number); if(!jgeom){ _DBG_<<"ERROR: Unable get geometry for run "<GetJGeometry() == jgeom){ DGeometry *dgeom = geometries[i]; Unlock(); return dgeom; } } cout<<"Creating DGeometry:"<GetRunRequested()<<" found:"<GetRunFound()<GetRunMin()<<"-"<GetRunMax()<GetURL()<<"\""<<" context=\""<GetContext()<<"\""<className()<<"\""<SetDefaultParameter("BFIELD_TYPE", bfield_type); if(bfield_type=="CalibDB"){ bfield = new DMagneticFieldMapCalibDB(this); cout<<"Created Magnetic field map of type DMagneticFieldMapCalibDB."<