// $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 #include #include //#include "HDGEOMETRY/DMaterialMapCalibDB.h" #include #include "DFactoryGenerator.h" #include "DANARootErrorHandler.h" #include //--------------------------------- // DApplication (Constructor) //--------------------------------- DApplication::DApplication(int narg, char* argv[]):JApplication(narg, argv) { pthread_mutex_init(&mutex, NULL); // Add plugin paths to Hall-D specific binary directories const char *bms_osname = getenv("BMS_OSNAME"); string sbms_osname(bms_osname==NULL ? "":bms_osname); if(const char *ptr = getenv("DANA_PLUGIN_PATH")){ AddPluginPath(string(ptr)); } if(const char *ptr = getenv("HALLD_MY")){ AddPluginPath(string(ptr) + "/" + sbms_osname + "/plugins"); // SBMS AddPluginPath(string(ptr) + "/lib/" + sbms_osname); // BMS } if(const char *ptr = getenv("HALLD_HOME")){ AddPluginPath(string(ptr) + "/" + sbms_osname + "/plugins"); // SBMS AddPluginPath(string(ptr) + "/lib/" + sbms_osname); // BMS } //Register CCDB calibration generator AddCalibrationGenerator(new DCalibrationGeneratorCCDB()); // 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, // unless the user has set it explicitly on the command line. map parmap; JParameterManager *pm = GetJParameterManager(); pm->GetParameters(parmap, "THREAD_TIMEOUT"); if (parmap.empty()) { pm->SetParameter("THREAD_TIMEOUT", "30 seconds"); } /// Add DEventSourceHDDMGenerator and /// DFactoryGenerator, which adds the default /// list of Hall-D factories bool HDDM_ENABLE = true; pm->SetDefaultParameter("HDDM:ENABLE", HDDM_ENABLE, "Enable the HDDM source readers. If set to 0, input files are assumed to never be of an HDDM format."); if(HDDM_ENABLE){ event_source_generator = new DEventSourceHDDMGenerator(); AddEventSourceGenerator(event_source_generator); AddEventSourceGenerator(new DEventSourceRESTGenerator()); } factory_generator = new DFactoryGenerator(); AddFactoryGenerator(factory_generator); 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); // Check if running on a cpu that supports the instruction set // extensions that were assumed when this application was built unsigned int cpeinfo; unsigned int cpsse3; unsigned int amdinfo; asm("mov $0x01, %%eax\ncpuid\n" : "=d" (cpeinfo), "=c" (cpsse3) ); asm("mov $0x80000001, %%eax\ncpuid\n" : "=d" (amdinfo) ); int mmx,sse,sse2,sse3,ssse3,sse4_1,sse4_2,sse4a; mmx = ((cpeinfo >> 23) & 0x1 ); sse = ((cpeinfo >> 25) & 0x1 ); sse2 = ((cpeinfo >> 26) & 0x1 ); sse3 = ((cpsse3 ) & 0x1 ); ssse3 = ((cpsse3 >> 9) & 0x1 ); sse4_1 = ((cpsse3 >> 19) & 0x1 ); sse4_2 = ((cpsse3 >> 20) & 0x1 ); sse4a = ((amdinfo >> 6) & 0x1 ); #if USE_SIMD if (sse == 0) { jerr<<"DApplication::Init error - application was built" <<" to run only on machines" << endl <<"supporting the SSE processor extensions." <<" Please run on a processor that" << endl <<"supports SSE, or rebuild with DISABLE_SIMD=yes." << endl; return UNRECOVERABLE_ERROR; } #endif #if USE_SSE2 if (sse2 == 0) { jerr<<"DApplication::Init error - application was built" <<" to run only on machines" << endl <<"supporting the SSE2 processor extensions." <<" Please run on a processor that" << endl <<"supports SSE2, or rebuild with DISABLE_SSE2=yes." << endl; return UNRECOVERABLE_ERROR; } #endif #if USE_SSE3 if (sse3 == 0) { jerr<<"DApplication::Init error - application was built" <<" to run only on machines" << endl <<"supporting the SSE3 processor extensions." <<" Please run on a processor that" << endl <<"supports SSE3, or rebuild with DISABLE_SSE3=yes." << endl; return UNRECOVERABLE_ERROR; } #endif return NOERROR; } //--------------------------------- // ~DApplication (Destructor) //--------------------------------- DApplication::~DApplication() { if(bfield) delete bfield; if(lorentz_def) delete lorentz_def; // As of JANA 0.6.3 and later, the following are // automatically deleted when ~JApplication is called. // Freeing them a second time causes seg. faults. so // we disable that here. 2/14/2011 DL //if(event_source_generator) delete event_source_generator; //if(factory_generator) delete factory_generator; //if(RootGeom) delete RootGeom; //for(unsigned int i=0; iNOT 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; } } jout<<"Creating DGeometry:"<GetRunRequested()<<" found:"<GetRunFound()<GetRunMin()<<"-"<GetRunMax()<GetURL()<<"\""<<" context=\""<GetContext()<<"\""<className()<<"\""<SetDefaultParameter("BFIELD_TYPE", bfield_type); if(bfield_type=="CalibDB"|| bfield_type=="FineMesh"){ bfield = new DMagneticFieldMapFineMesh(this,run_number); jout<<"Created Magnetic field map of type DMagneticFieldMapFineMesh."<