void CContextMenuHandler::FinalRelease() { f_log(__FUNCTION__); #ifdef DEBUG_TO_LOG_FILES if(m_log!=INVALID_HANDLE_VALUE) CloseHandle(m_log); #endif }
long int TMulti::testMulti() { //MULTI *pmp = multi->GetPM(); if( pm.MK || pm.PZ ) { if( paTProfil->p.PSM >= 2 ) { fstream f_log("ipmlog.txt", ios::out|ios::app ); f_log << "Warning " << pm.stkey << ": " << pm.errorCode << ":" << endl; f_log << pm.errorBuf << endl; } if( showMss ) { addErrorMessage(" \nContinue?"); switch( vfQuestion3(0, pm.errorCode, pm.errorBuf, "&Yes", "&No", "&Yes to All" )) { case VF3_3: showMss=0l; case VF3_1: break; case VF3_2: Error(pmp->errorCode, pmp->errorBuf); } } return 1L; } return 0L ; }
STDMETHODIMP CContextMenuHandler::Initialize(PCIDLIST_ABSOLUTE pidlFolder,IDataObject *pdtobj,HKEY hkeyProgID) { #ifdef DEBUG_TO_LOG_FILES char tbuf[100]; sprintf_s(tbuf,100,__FUNCTION__ ": Folder=%p, Object=%p",pidlFolder,pdtobj); f_log(tbuf); #endif // clear path if any sPath.Empty(); // get path from folder PIDL if exists - that means that we were called from background of folder if(pidlFolder) { TCHAR tbuf[MAX_PATH+1]; if(SHGetPathFromIDList(pidlFolder,tbuf)) sPath=tbuf; else f_log("Error: Cannot retrieve folder name"); return S_OK; // we get all that we need } // get path from file object if(pdtobj) { TCHAR tbuf[MAX_PATH+1]; STGMEDIUM medium; FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; UINT uCount; if(SUCCEEDED(pdtobj->GetData(&fe, &medium))) { // Get the count of files dropped. uCount = DragQueryFile((HDROP)medium.hGlobal,(UINT)-1,NULL,0); // Get the first file name from the CF_HDROP. if(uCount) { DragQueryFile((HDROP)medium.hGlobal,0,tbuf,sizeof(tbuf)/sizeof(TCHAR)); sPath = tbuf; } ReleaseStgMedium(&medium); } } return S_OK; }
int CContextMenuHandler::LoadConfig() { TCHAR tbuf[1024]; HKEY hK; DWORD iSize,/*iInd,*/iType; // FILETIME ftLastWrite; // load path as module path sExePath = Helpers::GetModulePath(hModuleInst).c_str(); // load global config if present if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,szConfigPath,0,KEY_READ,&hK)==ERROR_SUCCESS) { // get path iSize = 1024*sizeof(TCHAR); if(RegQueryValueEx(hK,szConfigVPath,NULL,&iType,(LPBYTE)tbuf,&iSize)==ERROR_SUCCESS) if(iType==REG_SZ) {// ok sExePath = tbuf; // add trailing '\' if(sExePath.GetLength()>0) if(tbuf[sExePath.GetLength()-1]!=_T('\\')) sExePath+=_T("\\"); #ifdef DEBUG_TO_LOG_FILES char _tbuf[1024]; sprintf_s(_tbuf,1024,"Executable path: %S",tbuf); f_log(_tbuf); #endif } else {f_log("Wrong executable path type");} else f_log("Cannot query global config value"); // close key RegCloseKey(hK); } else f_log("Cannot open global config key"); // reload global config if required if(hConfigChanged) if(WaitForSingleObject(hConfigChanged,0)==WAIT_OBJECT_0) { LoadConsoleSettings(); // ::MessageBox(NULL,L"Reloading console settings",L"Info",MB_ICONINFORMATION|MB_OK); // DEBUG } return S_OK; }
/// Output to "ipmlog.txt" file Warnings long int TMulti::testMulti( ) { if( pm.MK || pm.PZ ) { if( paTProfil->p.PSM == 2 ) { fstream f_log("ipmlog.txt", ios::out|ios::app ); f_log << "Warning " << pm.stkey << ": " << pm.errorCode << ":" << endl; f_log << pm.errorBuf << endl; } return 1L; } return 0L ; }
HRESULT CContextMenuHandler::FinalConstruct() { #ifdef DEBUG_TO_LOG_FILES char fname[MAX_PATH]; ULARGE_INTEGER iTime; GetSystemTimeAsFileTime((FILETIME*)&iTime); sprintf_s(fname,MAX_PATH,"c:\\ContextMenuHandler-%I64u.log",iTime.QuadPart); m_log = CreateFileA(fname,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); #endif f_log(__FUNCTION__); // load config LoadConfig(); return S_OK; }
int CContextMenuHandler::RunConsole(LPCTSTR sQueriedPath, bool post, LPCTSTR sQueriedTab) { // We cannot run without path if (!sQueriedPath) return E_FAIL; // is path folder or file? CString queriedPath = sQueriedPath; // vds: poasted command CString sCheckedPath = sQueriedPath; CString sCheckedFilePath = L""; // vds: posted command DWORD iFA = GetFileAttributes(sQueriedPath); if (iFA == 0xFFFFFFFF) { f_log("Cannot get path attributes - assume it is folder"); } else if(!(iFA & FILE_ATTRIBUTE_DIRECTORY)) { // It is file - trim it int dir_index = queriedPath.ReverseFind(_T('\\')); // vds: posted command if (dir_index == -1) { // Hmm, there is no folder separator so path is relative to current dir, get it as path sCheckedPath = _T("."); } else { sCheckedPath = queriedPath.Left(dir_index); // vds: posted command sCheckedFilePath = queriedPath.Mid(dir_index + 1); // vds: posted command } } // Construct command line CString sCmdLine = _T("\""); // Construct executable name (quoted to avoid problems with spaces in path) sCmdLine += sExePath; sCmdLine += szExeName; sCmdLine += _T("\" "); // Construct parameters if (sQueriedTab && (_tcslen(sQueriedTab) > 0)) { sCmdLine += _T("-t "); // sCmdLine += _T("-t \""); sCmdLine += sQueriedTab; sCmdLine += _T(" "); // sCmdLine += _T("\" "); } sCmdLine += _T("-d \""); sCmdLine += sCheckedPath; sCmdLine += _T("\""); // vds: posted command >> if (post && sCheckedFilePath != "") { sCmdLine += _T(" -p \""); sCmdLine += sCheckedFilePath; sCmdLine += _T("\""); } // vds: posted command << #ifdef DEBUG_TO_LOG_FILES char tbuf[MAX_PATH]; sprintf_s(tbuf,MAX_PATH,__FUNCTION__ ": cmd=%S",sCmdLine.GetString()); f_log(tbuf); #endif // Run process STARTUPINFO si; PROCESS_INFORMATION pi; memset(&si,0,sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); if (CreateProcess(NULL, sCmdLine.GetBuffer(), NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi)) { // Success // Close handles CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } else { f_log("Cannot start console process"); } return S_OK; }
STDMETHODIMP CContextMenuHandler::GetCommandString(UINT_PTR idCmd, UINT uType, UINT *pReserved, LPSTR pszName,UINT cchMax) { #ifdef DEBUG_TO_LOG_FILES char tbuf[200]; sprintf_s(tbuf,200,__FUNCTION__ ": cmd=%lu, type=%u, name=%s",(DWORD)idCmd,uType,pszName); f_log(tbuf); #endif HRESULT hr = E_INVALIDARG; const char *aHelp = ""; size_t aHelpSize = 0; const wchar_t *wHelp = L""; size_t wHelpSize = 0; const char *aVerb = ""; size_t aVerbSize = 0; const wchar_t *wVerb = L""; size_t wVerbSize = 0; if (idCmd == m_idCmdFirst + eMC_RunConsole) { aHelp = szDescrRunConsoleA; aHelpSize = sizeof(szDescrRunConsoleA); wHelp = szDescrRunConsoleW; wHelpSize = sizeof(szDescrRunConsoleW); aVerb = szVerbRunConsoleA; aVerbSize = sizeof(szVerbRunConsoleA); wVerb = szVerbRunConsoleW; wVerbSize = sizeof(szVerbRunConsoleW); } else if (idCmd == m_idCmdFirst + eMC_PostConsole) { aHelp = szDescrPostConsoleA; aHelpSize = sizeof(szDescrPostConsoleA); wHelp = szDescrPostConsoleW; wHelpSize = sizeof(szDescrPostConsoleW); aVerb = szVerbPostConsoleA; aVerbSize = sizeof(szVerbPostConsoleA); wVerb = szVerbPostConsoleW; wVerbSize = sizeof(szVerbPostConsoleW); } if (idCmd == m_idCmdFirst + eMC_RunConsoleWithTabFake) { aHelp = szDescrRunConsoleWithTabA; aHelpSize = sizeof(szDescrRunConsoleWithTabA); wHelp = szDescrRunConsoleWithTabW; wHelpSize = sizeof(szDescrRunConsoleWithTabW); aVerb = szVerbRunConsoleWithTabA; aVerbSize = sizeof(szVerbRunConsoleWithTabA); wVerb = szVerbRunConsoleW; wVerbSize = sizeof(szVerbRunConsoleWithTabW); } if (idCmd == m_idCmdFirst + eMC_PostConsoleWithTabFake) { aHelp = szDescrPostConsoleWithTabA; aHelpSize = sizeof(szDescrPostConsoleWithTabA); wHelp = szDescrPostConsoleWithTabW; wHelpSize = sizeof(szDescrPostConsoleWithTabW); aVerb = szVerbPostConsoleWithTabA; aVerbSize = sizeof(szVerbPostConsoleWithTabA); wVerb = szVerbPostConsoleWithTabW; wVerbSize = sizeof(szVerbPostConsoleWithTabW); } else { } switch(uType) { case GCS_HELPTEXTA: hr = StringCbCopyNA(pszName, cchMax, aHelp, aHelpSize); break; case GCS_HELPTEXTW: hr = StringCbCopyNW((LPWSTR)pszName, cchMax * sizeof(wchar_t), wHelp, wHelpSize); break; case GCS_VERBA: hr = StringCbCopyNA(pszName, cchMax, aVerb, aVerbSize); break; case GCS_VERBW: hr = StringCbCopyNW((LPWSTR)pszName, cchMax * sizeof(wchar_t), wVerb, wVerbSize); break; default: hr = S_OK; break; } return hr; }
STDMETHODIMP CContextMenuHandler::InvokeCommand(CMINVOKECOMMANDINFO *pici) { f_log(__FUNCTION__); BOOL fEx = FALSE; BOOL fUnicode = FALSE; if (pici->cbSize = sizeof(CMINVOKECOMMANDINFOEX)) { fEx = TRUE; if ((pici->fMask & CMIC_MASK_UNICODE)) { fUnicode = TRUE; } } if (!fUnicode && HIWORD(pici->lpVerb)) { if (StrCmpIA(pici->lpVerb, szVerbRunConsoleA) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, false); } return S_OK; } else if (StrCmpIA(pici->lpVerb, szVerbPostConsoleA) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, true); } return S_OK; } return E_FAIL; } if (fUnicode && HIWORD(reinterpret_cast<CMINVOKECOMMANDINFOEX*>(pici)->lpVerbW)) { if (StrCmpIW(reinterpret_cast<CMINVOKECOMMANDINFOEX*>(pici)->lpVerbW, szVerbRunConsoleW) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, false); } return S_OK; } else if (StrCmpIW(reinterpret_cast<CMINVOKECOMMANDINFOEX*>(pici)->lpVerbW, szVerbRunConsoleW) == 0) { if (!sPath.IsEmpty()) { RunConsole(sPath, true); } return S_OK; } return E_FAIL; } if (LOWORD(pici->lpVerb) == eMC_RunConsole) { // Run console with default tab if(!sPath.IsEmpty()) { RunConsole(sPath, false); } } else if (LOWORD(pici->lpVerb) == eMC_PostConsole) { // Run console with default tab if(!sPath.IsEmpty()) { RunConsole(sPath, true); } } else if (LOWORD(pici->lpVerb) >= eMC_RunConsoleWithTab && LOWORD(pici->lpVerb) < eMC_RunConsoleWithTab + 50) { // Run console with specified tab if (!sPath.IsEmpty()) { wstring sTabName; // get tab name { // synchronization syncAutoLock oLock(g_oSync); if ((LOWORD(pici->lpVerb) - eMC_RunConsoleWithTab) < (int)g_vTabs.size()) sTabName = g_vTabs[LOWORD(pici->lpVerb) - eMC_RunConsoleWithTab]->sName; } // run RunConsole(sPath, false, sTabName.c_str()); } } else if (LOWORD(pici->lpVerb) >= eMC_PostConsoleWithTab && LOWORD(pici->lpVerb) < eMC_PostConsoleWithTab + 50) { // Run console with specified tab if (!sPath.IsEmpty()) { wstring sTabName; // get tab name { // synchronization syncAutoLock oLock(g_oSync); if ((LOWORD(pici->lpVerb) - eMC_PostConsoleWithTab) < (int)g_vTabs.size()) sTabName = g_vTabs[LOWORD(pici->lpVerb) - eMC_PostConsoleWithTab]->sName; } // run RunConsole(sPath, true, sTabName.c_str()); } } return S_OK; }
STDMETHODIMP CContextMenuHandler::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { #ifdef DEBUG_TO_LOG_FILES char tbuf[200]; sprintf_s(tbuf,200,__FUNCTION__ ": index=%u, first=%u, last=%u, flags=%.08lX, path=%S",indexMenu,idCmdFirst,idCmdLast,uFlags,sPath.GetString()); f_log(tbuf); #endif if (CMF_DEFAULTONLY & uFlags) return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0)); if (sPath.IsEmpty()) return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0)); m_idCmdFirst = idCmdFirst; DWORD lastId = idCmdFirst; // Synchronization syncAutoLock oLock(g_oSync); // This lock is REQUIRED to protect shared configuration access { MENUITEMINFO miSeparator; miSeparator.fMask = MIIM_TYPE; miSeparator.fType = MFT_SEPARATOR; InsertMenuItem(hmenu, indexMenu++, TRUE, &miSeparator); } if (g_settingsHandler->GetBehaviorSettings().shellSettings.bRunConsoleMenItem) { // get item name wstring sItemName = g_settingsHandler->GetInternationalizationSettings().strExplorerMenuRunItem; if (sItemName.size() <= 0) sItemName = szItemRunConsole; // Fill main menu first item info MENUITEMINFO miRunConsole; memset(&miRunConsole, 0, sizeof(MENUITEMINFO)); miRunConsole.cbSize = sizeof(MENUITEMINFO); miRunConsole.fMask = 0; miRunConsole.fMask |= MIIM_ID; miRunConsole.wID = idCmdFirst + eMC_RunConsole; miRunConsole.fMask |= MIIM_TYPE; miRunConsole.fType = MFT_STRING; miRunConsole.dwTypeData = const_cast<LPTSTR>(sItemName.c_str()); miRunConsole.cch = sItemName.size(); miRunConsole.fMask |= MIIM_STATE; miRunConsole.fState = MFS_ENABLED; miRunConsole.fMask |= MIIM_CHECKMARKS; miRunConsole.hbmpChecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); miRunConsole.hbmpUnchecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); // Insert menu item BOOL r = InsertMenuItem(hmenu, indexMenu, TRUE, &miRunConsole); indexMenu++; lastId = idCmdFirst + eMC_RunConsole; } if (g_settingsHandler->GetBehaviorSettings().shellSettings.bPostConsoleMenItem) { // get item name wstring sItemName = g_settingsHandler->GetInternationalizationSettings().strExplorerMenuPostItem; if (sItemName.size() <= 0) sItemName = szItemPostConsole; // Fill main menu first item info MENUITEMINFO miPostConsole; memset(&miPostConsole, 0, sizeof(MENUITEMINFO)); miPostConsole.cbSize = sizeof(MENUITEMINFO); miPostConsole.fMask = 0; miPostConsole.fMask |= MIIM_ID; miPostConsole.wID = idCmdFirst + eMC_PostConsole; miPostConsole.fMask |= MIIM_TYPE; miPostConsole.fType = MFT_STRING; miPostConsole.dwTypeData = const_cast<LPTSTR>(sItemName.c_str()); miPostConsole.cch = sItemName.size(); miPostConsole.fMask |= MIIM_STATE; miPostConsole.fState = MFS_ENABLED; miPostConsole.fMask |= MIIM_CHECKMARKS; miPostConsole.hbmpChecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); miPostConsole.hbmpUnchecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); // Insert menu item BOOL r = InsertMenuItem(hmenu, indexMenu, TRUE, &miPostConsole); indexMenu++; lastId = idCmdFirst + eMC_PostConsole; } if (g_settingsHandler->GetBehaviorSettings().shellSettings.bRunConsoleTabMenuItem) { HMENU hSubMenu = CreateMenu(); if (!hSubMenu) return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0)); // Create submenu for (DWORD i = 0, lim = g_vTabs.size(); i < lim; ++i) { wstring sTabName = g_vTabs[i]->sName; HBITMAP hTabIcon = g_vTabs[i]->hIconBmp; // Fill main menu item info MENUITEMINFO miRunTabConsole; memset(&miRunTabConsole, 0, sizeof(MENUITEMINFO)); miRunTabConsole.cbSize = sizeof(MENUITEMINFO); miRunTabConsole.fMask = MIIM_STRING | MIIM_ID | (hTabIcon ? MIIM_CHECKMARKS : 0); miRunTabConsole.wID = idCmdFirst + eMC_RunConsoleWithTab + i; miRunTabConsole.dwTypeData = const_cast<LPTSTR>(sTabName.c_str()); miRunTabConsole.cch = sTabName.size(); if (hTabIcon) miRunTabConsole.hbmpChecked = miRunTabConsole.hbmpUnchecked = hTabIcon; // Insert menu item InsertMenuItem(hSubMenu, i, TRUE, &miRunTabConsole); lastId = miRunTabConsole.wID; } // get item name wstring sItemName = g_settingsHandler->GetInternationalizationSettings().strExplorerMenuRunWithItem; if (sItemName.size() <= 0) sItemName = szItemRunConsoleWithTab; // Fill main menu item info MENUITEMINFO miRunTabConsoleMenu; memset(&miRunTabConsoleMenu, 0, sizeof(MENUITEMINFO)); miRunTabConsoleMenu.cbSize = sizeof(MENUITEMINFO); miRunTabConsoleMenu.fMask = MIIM_CHECKMARKS|MIIM_STRING|MIIM_ID|MIIM_SUBMENU; miRunTabConsoleMenu.wID = idCmdFirst + eMC_RunConsoleWithTabFake; miRunTabConsoleMenu.dwTypeData = const_cast<LPTSTR>(sItemName.c_str()); miRunTabConsoleMenu.cch = sItemName.size(); miRunTabConsoleMenu.hSubMenu = hSubMenu; miRunTabConsoleMenu.hbmpChecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); miRunTabConsoleMenu.hbmpUnchecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); // Insert menu item InsertMenuItem(hmenu, indexMenu++, TRUE, &miRunTabConsoleMenu); lastId = idCmdFirst + eMC_RunConsoleWithTab + g_vTabs.size() - 1; } if (g_settingsHandler->GetBehaviorSettings().shellSettings.bPostConsoleTabMenuItem) { HMENU hSubMenu = CreateMenu(); if (!hSubMenu) return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0)); // Create submenu for (DWORD i = 0, lim = g_vTabs.size(); i < lim; ++i) { wstring sTabName = g_vTabs[i]->sName; HBITMAP hTabIcon = g_vTabs[i]->hIconBmp; // Fill main menu item info MENUITEMINFO miPostTabConsole; memset(&miPostTabConsole, 0, sizeof(MENUITEMINFO)); miPostTabConsole.cbSize = sizeof(MENUITEMINFO); miPostTabConsole.fMask = MIIM_STRING | MIIM_ID | (hTabIcon ? MIIM_CHECKMARKS : 0); miPostTabConsole.wID = idCmdFirst + eMC_PostConsoleWithTab + i; miPostTabConsole.dwTypeData = const_cast<LPTSTR>(sTabName.c_str()); miPostTabConsole.cch = sTabName.size(); if (hTabIcon) miPostTabConsole.hbmpChecked = miPostTabConsole.hbmpUnchecked = hTabIcon; // Insert menu item InsertMenuItem(hSubMenu, i, TRUE, &miPostTabConsole); lastId = miPostTabConsole.wID; } // get item name wstring sItemName = g_settingsHandler->GetInternationalizationSettings().strExplorerMenuPostWithItem; if (sItemName.size() <= 0) sItemName = szItemPostConsoleWithTab; // Fill main menu item info MENUITEMINFO miPostTabConsoleMenu; memset(&miPostTabConsoleMenu, 0, sizeof(MENUITEMINFO)); miPostTabConsoleMenu.cbSize = sizeof(MENUITEMINFO); miPostTabConsoleMenu.fMask = MIIM_CHECKMARKS|MIIM_STRING|MIIM_ID|MIIM_SUBMENU; miPostTabConsoleMenu.wID = idCmdFirst + eMC_PostConsoleWithTabFake; miPostTabConsoleMenu.dwTypeData = const_cast<LPTSTR>(sItemName.c_str()); miPostTabConsoleMenu.cch = sItemName.size(); miPostTabConsoleMenu.hSubMenu = hSubMenu; miPostTabConsoleMenu.hbmpChecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); miPostTabConsoleMenu.hbmpUnchecked = (HBITMAP)LoadImage(_AtlBaseModule.GetResourceInstance(),MAKEINTRESOURCE(IDB_MENU_PICTURE),IMAGE_BITMAP,0,0,LR_LOADTRANSPARENT); // Insert menu item InsertMenuItem(hmenu, indexMenu++, TRUE, &miPostTabConsoleMenu); lastId = idCmdFirst + eMC_PostConsoleWithTab + g_vTabs.size() - 1; } #if 0 { MENUITEMINFO miSeparator; miSeparator.fMask = MIIM_TYPE; miSeparator.fType = MFT_SEPARATOR; InsertMenuItem(hmenu, indexMenu++, TRUE, &miSeparator); } #endif return ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(lastId - idCmdFirst + 1))); //return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(lastId - idCmdFirst + 1)); }
bool TestExtMath::test_log() { VC(f_log(8), 2.0794415416798); VS(f_log(8, 2), 3.0); return Count(true); }
bool TestExtMath::test_is_infinite() { VERIFY(!f_is_infinite(5)); VERIFY(f_is_infinite(f_log(0))); return Count(true); }
//this file stores the data events in our signal regions in several histograms //that are used by MT2Results_PlotsAndTables.C //can also choose to store files in control region or MC events //additionally it creates a log file with run:lumisection:eventnumber for all those events. void MakeDataFile(){ fLogStream = new std::ostringstream(); bool poisson = false;//set poissonian uncertainties, works from next root version on //decide on filename histograms are stored, also define the samples.dat gROOT->ProcessLine(".x SetStyle_PRD.C"); TString fOutDir = "../Results/Filtered/"; TString outputname = "NewDataNumbers.root"; if(ourfilter ) outputname = "NewDataNumbersOurFilter.root"; if(calometfilter) outputname = "NewDataNumbersOurFilterCaloMETfilter.root"; if(tobtecfilter ) outputname = "NewDataNumbersOurFilterCaloMETfilterTOBTECFilter.root"; if(poisson) outputname = "NewDataNumbersPoisson.root"; TString samples = "samples/samples_HTandMET_filter.dat"; //definition of the histograms map<string, TH1D*> histos; for(int i2 = 0; i2<signalregionsize; ++i2){ for(int i3 = 0; i3<HTbinsize; ++i3){ int NMT2bins; if(i3==0){ if(signal_region[i2]=="2j0b") NMT2bins = gNMT2bins_2j0b_lHT; if(signal_region[i2]=="2j1to2b") NMT2bins = gNMT2bins_2j1b_lHT; if(signal_region[i2]=="3to5j0b") NMT2bins = gNMT2bins_3j0b_lHT; if(signal_region[i2]=="3to5j1b") NMT2bins = gNMT2bins_3j1b_lHT; if(signal_region[i2]=="3to5j2b") NMT2bins = gNMT2bins_3j2b_lHT; if(signal_region[i2]=="6j0b") NMT2bins = gNMT2bins_6j0b_lHT; if(signal_region[i2]=="6j1b") NMT2bins = gNMT2bins_6j1b_lHT; if(signal_region[i2]=="6j2b") NMT2bins = gNMT2bins_6j2b_lHT; if(signal_region[i2]=="3b") NMT2bins = gNMT2bins_3b_lHT; } if(i3==1){ if(signal_region[i2]=="2j0b") NMT2bins = gNMT2bins_2j0b_mHT; if(signal_region[i2]=="2j1to2b") NMT2bins = gNMT2bins_2j1b_mHT; if(signal_region[i2]=="3to5j0b") NMT2bins = gNMT2bins_3j0b_mHT; if(signal_region[i2]=="3to5j1b") NMT2bins = gNMT2bins_3j1b_mHT; if(signal_region[i2]=="3to5j2b") NMT2bins = gNMT2bins_3j2b_mHT; if(signal_region[i2]=="6j0b") NMT2bins = gNMT2bins_6j0b_mHT; if(signal_region[i2]=="6j1b") NMT2bins = gNMT2bins_6j1b_mHT; if(signal_region[i2]=="6j2b") NMT2bins = gNMT2bins_6j2b_mHT; if(signal_region[i2]=="3b") NMT2bins = gNMT2bins_3b_mHT; } if(i3==2){ if(signal_region[i2]=="2j0b") NMT2bins = gNMT2bins_2j0b_hHT; if(signal_region[i2]=="2j1to2b") NMT2bins = gNMT2bins_2j1b_hHT; if(signal_region[i2]=="3to5j0b") NMT2bins = gNMT2bins_3j0b_hHT; if(signal_region[i2]=="3to5j1b") NMT2bins = gNMT2bins_3j1b_hHT; if(signal_region[i2]=="3to5j2b") NMT2bins = gNMT2bins_3j2b_hHT; if(signal_region[i2]=="6j0b") NMT2bins = gNMT2bins_6j0b_hHT; if(signal_region[i2]=="6j1b") NMT2bins = gNMT2bins_6j1b_hHT; if(signal_region[i2]=="6j2b") NMT2bins = gNMT2bins_6j2b_hHT; if(signal_region[i2]=="3b") NMT2bins = gNMT2bins_3b_hHT; } double MT2bins[NMT2bins+1]; if(i3==0){ if(signal_region[i2]=="2j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_2j0b_lHT[i0]; } if(signal_region[i2]=="2j1to2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_2j1b_lHT[i0]; } if(signal_region[i2]=="3to5j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j0b_lHT[i0]; } if(signal_region[i2]=="3to5j1b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j1b_lHT[i0]; } if(signal_region[i2]=="3to5j2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j2b_lHT[i0]; } if(signal_region[i2]=="6j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j0b_lHT[i0]; } if(signal_region[i2]=="6j1b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j1b_lHT[i0]; } if(signal_region[i2]=="6j2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j2b_lHT[i0]; } if(signal_region[i2]=="3b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3b_lHT[i0]; } } if(i3==1){ if(signal_region[i2]=="2j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_2j0b_mHT[i0]; } if(signal_region[i2]=="2j1to2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_2j1b_mHT[i0]; } if(signal_region[i2]=="3to5j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j0b_mHT[i0]; } if(signal_region[i2]=="3to5j1b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j1b_mHT[i0]; } if(signal_region[i2]=="3to5j2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j2b_mHT[i0]; } if(signal_region[i2]=="6j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j0b_mHT[i0]; } if(signal_region[i2]=="6j1b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j1b_mHT[i0]; } if(signal_region[i2]=="6j2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j2b_mHT[i0]; } if(signal_region[i2]=="3b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3b_mHT[i0]; } } if(i3==2){ if(signal_region[i2]=="2j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_2j0b_hHT[i0]; } if(signal_region[i2]=="2j1to2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_2j1b_hHT[i0]; } if(signal_region[i2]=="3to5j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j0b_hHT[i0]; } if(signal_region[i2]=="3to5j1b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j1b_hHT[i0]; } if(signal_region[i2]=="3to5j2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3j2b_hHT[i0]; } if(signal_region[i2]=="6j0b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j0b_hHT[i0]; } if(signal_region[i2]=="6j1b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j1b_hHT[i0]; } if(signal_region[i2]=="6j2b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_6j2b_hHT[i0]; } if(signal_region[i2]=="3b") { for(int i0 = 0; i0<=NMT2bins; ++i0) MT2bins[i0] = gMT2bins_3b_hHT[i0]; } } string hs = string("_") + HT_bin[i3] + string("_") + signal_region[i2]; string mapname = "MT2" + hs; if(histos.count(mapname) == 0 ) histos[mapname] = new TH1D(mapname.c_str(), "", NMT2bins, MT2bins); // if(poisson) histos[mapname]->SetBinErrorOption((TH1::EBinErrorOpt)1);//store already here the poissonian errors, works from next root version on }} for(map<string,TH1D*>::iterator h=histos.begin(); h!=histos.end();++h){ h->second->Sumw2();} //signal selection cuts std::ostringstream fCutStreamSignal; fCutStreamSignal << " " << "misc.MT2>=100" << "&&" << "misc.MET>=30" << "&&" << "misc.HT >=450" << "&&" << "NEles==0" << "&&" << "NMuons==0" << "&&" << "NTausIDLoose3Hits==0" << "&&" << "misc.Jet0Pass ==1" << "&&" << "misc.Jet1Pass ==1" << "&&" << "misc.PassJet40ID ==1" << "&&" << "NJetsIDLoose40 >=2" << "&&" << "misc.MinMetJetDPhi4Pt40 >0.3" << "&&" << "misc.Vectorsumpt < 70" << "&&" // Noise << "(misc.HBHENoiseFlag == 0 || misc.ProcessID==10)" << "&&" // for rare SM samples << "misc.CSCTightHaloIDFlag == 0" << "&&" << "misc.trackingFailureFlag==0" << "&&" << "misc.eeBadScFlag==0" << "&&" << "misc.EcalDeadCellTriggerPrimitiveFlag==0" << "&&" << "misc.TrackingManyStripClusFlag==0" << "&&" << "misc.TrackingTooManyStripClusFlag==0" << "&&" << "misc.TrackingLogErrorTooManyClustersFlag==0" << "&&" << "misc.CrazyHCAL==0"; fCutStreamSignal << "&&((misc.MET>=200&&misc.MT2>=200&&misc.HT<750)||(misc.HT>750))"; fCutStreamSignal << "&&NJetsIDLoose40>=2"; fCutStreamSignal << "&&misc.MET/misc.CaloMETRaw<=2."; TString cuts = fCutStreamSignal.str().c_str(); std::ostringstream triggerStream; triggerStream << "( ( ( " << "trigger.HLT_PFHT650_v5 == 1 || trigger.HLT_PFHT650_v6 == 1 || trigger.HLT_PFHT650_v7 == 1 || trigger.HLT_PFHT650_v8 == 1 || trigger.HLT_PFHT650_v9 == 1 || " << "trigger.HLT_PFNoPUHT650_v1 == 1 || trigger.HLT_PFNoPUHT650_v3 == 1 || trigger.HLT_PFNoPUHT650_v4 == 1) ||"; triggerStream << "( ( " << "trigger.HLT_PFMET150_v2 == 1 || trigger.HLT_PFMET150_v3 == 1 || trigger.HLT_PFMET150_v4 == 1 || " << "trigger.HLT_PFMET150_v5 == 1 || trigger.HLT_PFMET150_v6 == 1 || trigger.HLT_PFMET150_v7 == 1 )" << "||(" << "trigger.HLT_PFHT350_PFMET100_v3==1 || trigger.HLT_PFHT350_PFMET100_v4==1 || trigger.HLT_PFHT350_PFMET100_v5==1 || " << "trigger.HLT_PFHT350_PFMET100_v6==1 || trigger.HLT_PFHT350_PFMET100_v7==1 || trigger.HLT_PFNoPUHT350_PFMET100_v1==1 || " << "trigger.HLT_PFNoPUHT350_PFMET100_v3==1 || trigger.HLT_PFNoPUHT350_PFMET100_v4==1 ) ) )&&TOBTECTagger<=8&&ExtraBeamHaloFilter==0)"; TString trigger = triggerStream.str().c_str(); load(samples.Data()); int counterAll = 0; for(size_t i = 0; i < fSamples.size(); ++i){ string sampletype = (string)fSamples[i].type; if(sampletype!="data") continue;//run only over data - extendable to MC Double_t sample_weight = fSamples[i].xsection * fSamples[i].kfact * fSamples[i].lumi / (fSamples[i].nevents*fSamples[i].PU_avg_weight); if(fVerbose>2) cout << "ZnunuNumbers: looping over " << fSamples[i].name << " added in " << sampletype << endl; if(fVerbose>2) cout << " sample has weight " << sample_weight << " and " << fSamples[i].tree->GetEntries() << " entries" << endl; if(fVerbose>2 && fSamples[i].tree->GetEntries()==0) cout << "skip sample, has no entries" << endl; if(fSamples[i].tree->GetEntries()==0) continue; MT2tree* fMT2tree = new MT2tree(); fSamples[i].tree->SetBranchAddress("MT2tree", &fMT2tree); Long64_t nentries = fSamples[i].tree->GetEntries(); Long64_t nbytes = 0, nb = 0; int nev =0; TString myCuts = cuts;// + "&&" + basecuts; if( fSamples[i].type=="data") myCuts += " && " + trigger; //cuts to be aplied only on data cout << "Cuts for Flow: " << myCuts << endl; fSamples[i].tree->Draw(">>selList", myCuts); TEventList *myEvtList = (TEventList*)gDirectory->Get("selList"); fSamples[i].tree->SetEventList(myEvtList); int counter=0; cout << "Filtering done, size=" <<myEvtList->GetN() << endl; if(myEvtList->GetSize()==0) continue; *fLogStream << "Sample " << fSamples[i].name << endl; //run over all selected events while(myEvtList->GetEntry(counter++) !=-1){ int jentry = myEvtList->GetEntry(counter-1); nb = fSamples[i].tree->GetEntry(jentry); nbytes += nb; fSamples[i].tree->SetBranchAddress("MT2tree", &fMT2tree); if ( fVerbose>2 && counter % 5000 == 0 ) cout << "+++ Proccessing event " << counter << endl; string sHT;//HT region if(fMT2tree->misc.HT<450.) sHT = "_HTge0"; else if(fMT2tree->misc.HT<750.) sHT = "_lowHT"; else if(fMT2tree->misc.HT<1200.)sHT = "_mediumHT"; else sHT = "_highHT"; string ssignal;//topological region if(fMT2tree->NJetsIDLoose40 == 2 && fMT2tree->NBJets40CSVM == 0) ssignal = "_2j0b"; if(fMT2tree->NJetsIDLoose40 == 2 && fMT2tree->NBJets40CSVM >= 1) ssignal = "_2j1to2b"; if(fMT2tree->NJetsIDLoose40 >= 3 && fMT2tree->NJetsIDLoose40 <= 5 && fMT2tree->NBJets40CSVM == 0) ssignal = "_3to5j0b"; if(fMT2tree->NJetsIDLoose40 >= 3 && fMT2tree->NJetsIDLoose40 <= 5 && fMT2tree->NBJets40CSVM == 1) ssignal = "_3to5j1b"; if(fMT2tree->NJetsIDLoose40 >= 3 && fMT2tree->NJetsIDLoose40 <= 5 && fMT2tree->NBJets40CSVM == 2) ssignal = "_3to5j2b"; if( fMT2tree->NBJets40CSVM >= 3) ssignal = "_3b"; if(fMT2tree->NJetsIDLoose40 >= 6 && fMT2tree->NBJets40CSVM == 0) ssignal = "_6j0b"; if(fMT2tree->NJetsIDLoose40 >= 6 && fMT2tree->NBJets40CSVM == 1) ssignal = "_6j1b"; if(fMT2tree->NJetsIDLoose40 >= 6 && fMT2tree->NBJets40CSVM == 2) ssignal = "_6j2b"; string hh = sHT + ssignal; histos[(string)"MT2" + hh]->Fill(fMT2tree->misc.MT2);//fill histogram if(fMT2tree->misc.MT2>histos[(string)"MT2" + hh]->GetBinLowEdge(1)){ if(sHT=="_lowHT" && (fMT2tree->trigger.HLT_PFHT350_PFMET100_v3==1||fMT2tree->trigger.HLT_PFHT350_PFMET100_v4==1||fMT2tree->trigger.HLT_PFHT350_PFMET100_v5==1||fMT2tree->trigger.HLT_PFHT350_PFMET100_v6==1||fMT2tree->trigger.HLT_PFHT350_PFMET100_v7==1 || fMT2tree->trigger.HLT_PFNoPUHT350_PFMET100_v1==1 || fMT2tree->trigger.HLT_PFNoPUHT350_PFMET100_v3==1 || fMT2tree->trigger.HLT_PFNoPUHT350_PFMET100_v4==1 ) ) *fLogStream << "HTMHT "; else if(sHT=="_lowHT") *fLogStream << "MET "; else *fLogStream << "JetHT "; *fLogStream << int(fMT2tree->misc.Run) << ":" << int(fMT2tree->misc.LumiSection) << ":" << int(fMT2tree->misc.Event) << endl;//file log file (including trigger stream ++counterAll; } }//while delete fMT2tree; delete fSamples[i].tree; }//for samples cout << "add overflow to last bin" << endl; for(map<string,TH1D*>::iterator h=histos.begin(); h!=histos.end();++h){ h->second->SetBinContent(h->second->GetNbinsX(), h->second->GetBinContent(h->second->GetNbinsX() )+ h->second->GetBinContent(h->second->GetNbinsX()+1) ); h->second->SetBinError( h->second->GetNbinsX(), sqrt(h->second->GetBinError(h->second->GetNbinsX() )* h->second->GetBinError(h->second->GetNbinsX() )+ h->second->GetBinError(h->second->GetNbinsX()+1)* h->second->GetBinError(h->second->GetNbinsX()+1) )); } cout << "Saving." << endl; TFile *fsavefile = new TFile(fOutDir + outputname,"RECREATE"); fsavefile->cd(); for(map<string,TH1D*>::iterator h=histos.begin(); h!=histos.end();++h){ h->second->Write(); } fsavefile->Close(); cout << "Saved histograms in " << fOutDir << outputname << endl; TString logname ="eventlistMT2inclusive.log"; cout << counterAll << " events in " << logname.Data() << endl; ofstream f_log (logname.Data(), ios::trunc); f_log << fLogStream->str(); }