#include #include #include #include #include #include #include // ECAL #include #include // CyDet //#include #include //================================================================================ // The constructor //================================================================================ IReconGlobalMain::IReconGlobalMain() : fCalibApplyIsEnabled(false), fReconIsEnabled(false) { // Push the IXXXXYYYYYEventFunctions fCalibReconFunc.push_back(new CalibReconFuncPair("CyDet", NULL /*new ICyDetCalibApplyEventFunction()*/, new ICyDetReconEventFunction())); fCalibReconFunc.push_back(new CalibReconFuncPair("ECAL", new IECALCalibApplyEventFunction(), new IECALReconEventFunction())); } //================================================================================ // The destructor //================================================================================ IReconGlobalMain::~IReconGlobalMain() { for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ delete (*func); } } //================================================================================ // Usage //================================================================================ void IReconGlobalMain::Usage() { std::cout << "============================================================================" << std::endl << std::endl << "Global Reconstruction Tool" << std::endl << " Run each detector or system specific reconstruction function." << std::endl << std::endl; //-------------------------------------------- // ReconGlobal's Usage() //-------------------------------------------- std::cout << "Global Options:\n" << " -O verbose=[(0|quiet), (1|log), (2|info), (3|verbose)]\n" << " Set verbose level of all the recon functions.\n" << std::endl; //-------------------------------------------- // Common usage among all recon functions //-------------------------------------------- std::cout << "The following \"XXXX\" is the function name to be any one of " << std::endl; for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ std::cout << " (" << 1 + std::distance(fCalibReconFunc.begin(), func) << ") " << (*func)->recon->GetLowerName() << std::endl; } std::cout << std::endl << std::endl; // Give usage of the core and common options IVEventFunction::UsageOfCoreOptions(); if(fCalibApplyIsEnabled) ICalibApplyEventFunction::UsageOfCommonOptions(); if(fReconIsEnabled ) IReconEventFunction::UsageOfCommonOptions(); //-------------------------------------------- // Each function's Usage() //-------------------------------------------- for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ // Name std::cout << std::endl << "------------------------------------------------------------" << std::endl << (*func)->name << std::endl; // CalibApply if(fCalibApplyIsEnabled && (*func)->calib){ std::cout << std::endl << "Calib. Apply :" << std::endl; (*func)->calib->Usage(); } // Recon if(fReconIsEnabled && (*func)->recon){ std::cout << std::endl << "Reconstruction :" << std::endl; (*func)->recon->Usage(); } } } //================================================================================ // operator () //================================================================================ bool IReconGlobalMain::operator () (COMET::ICOMETEvent& event) { int evtNo = event.GetContext().GetEvent(); if(COMET::ICOMETLog::GetLogLevel("ReconGlobal") >= COMET::ICOMETLog::InfoLevel || evtNo%100 == 0 ) std::cout << "Global reconstruction: processing event # " << evtNo << std::endl; // ------------------------------------------------------------------------- try{ // Loop for recon functions for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ Int_t cErr = 0, rErr = 0; // Process calib. apply if(fCalibApplyIsEnabled && (*func)->calib) cErr = (*func)->calib->Process(event); // Process reconstruction if(fReconIsEnabled && (*func)->recon) rErr = (*func)->recon->Process(event); // Check Error (not exception) if(cErr || rErr){ COMETError("CalibApply and/or Recon event function returned error."); if(cErr) COMETError(" >>> " << (*func)->calib->GetFullName() << " error code " << cErr); if(rErr) COMETError(" >>> " << (*func)->recon->GetFullName() << " error code " << rErr); } } } catch (COMET::ERecon& excep) { COMETError("Caught Global Recon Exception: " << excep.what()); return false; } catch (COMET::ECalibApply& excep) { COMETError("Caught Global CalibApply Exception: " << excep.what()); return false; } return true; } //================================================================================ // SetOption //================================================================================ bool IReconGlobalMain::SetOption(std::string option, std::string value) { //-------------------------------------------- // Global setting for ReconGlobal //-------------------------------------------- // Set log level globally if(option == "verbose"){ COMET::ICOMETLog::LogPriority logLevel; if (value == "0" || value == "quiet" ) logLevel = COMET::ICOMETLog::QuietLevel; else if(value == "1" || value == "log" ) logLevel = COMET::ICOMETLog::LogLevel; else if(value == "2" || value == "info" ) logLevel = COMET::ICOMETLog::InfoLevel; else if(value == "3" || value == "verbose") logLevel = COMET::ICOMETLog::VerboseLevel; else{ COMETWarn("There is no such verbose level, " << value); return false; } // Set common log level COMET::ICOMETLog::SetLogLevel(logLevel); COMET::ICOMETLog::SetLogLevel("ReconGlobal", logLevel); for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ if(fCalibApplyIsEnabled && (*func)->calib) (*func)->calib->SetLogLevel(logLevel); if(fReconIsEnabled && (*func)->recon) (*func)->recon->SetLogLevel(logLevel); } return true; } //-------------------------------------------- // Each recon function specific options //-------------------------------------------- else{ for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ bool ret = false; // Process option parsing independently for calib. appy and recon. // This is for some common option valid for the both, such as -O XXXX-disable. if(fCalibApplyIsEnabled && (*func)->calib) ret |= (*func)->calib->ParseSpecificOption(option, value); if(fReconIsEnabled && (*func)->recon) ret |= (*func)->recon->ParseSpecificOption(option, value); if(ret) return true; } } return false; } //================================================================================ // CheckOptions //================================================================================ bool IReconGlobalMain::CheckOptions() { for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ if(fCalibApplyIsEnabled && (*func)->calib && not (*func)->calib->CheckOptions()) return false; if(fReconIsEnabled && (*func)->recon && not (*func)->recon->CheckOptions()) return false; } return true; } //================================================================================ // Initialize //================================================================================ void IReconGlobalMain::Initialize(void) { for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ if(fCalibApplyIsEnabled && (*func)->calib) (*func)->calib->Initialize(); if(fReconIsEnabled && (*func)->recon) (*func)->recon->Initialize(); } } //================================================================================ // Finalize //================================================================================ void IReconGlobalMain::Finalize(COMET::ICOMETOutput * const file) { for(CalibReconFuncVector::iterator func = fCalibReconFunc.begin(); func != fCalibReconFunc.end(); func++){ if(fCalibApplyIsEnabled && (*func)->calib) (*func)->calib->Finalize(file); if(fReconIsEnabled && (*func)->recon) (*func)->recon->Finalize(file); } }