/* return PLFS_SUCCESS or PLFS_E* */ plfs_error_t Access( const string& path, IOStore *store, int mask ) { // there used to be some concern here that the accessfile might not // exist yet but the way containers are made ensures that an accessfile // will exist if the container exists // doing just Access is insufficient when plfs daemon run as root // root can access everything. so, we must also try the open mode_t open_mode = 0; plfs_error_t ret; IOSHandle *fh; mlog(FOP_DAPI, "%s Check existence of %s", __FUNCTION__, path.c_str()); ret = store->Access( path.c_str(), F_OK ); if ( ret == PLFS_SUCCESS ) { // at this point, we know the file exists if(checkMask(mask,W_OK|R_OK)) { open_mode = O_RDWR; } else if(checkMask(mask,R_OK)||checkMask(mask,X_OK)) { open_mode = O_RDONLY; } else if(checkMask(mask,W_OK)) { open_mode = O_WRONLY; } else if(checkMask(mask,F_OK)) { return PLFS_SUCCESS; // we already know this } mlog(FOP_DCOMMON, "The file exists attempting open"); ret = store->Open(path.c_str(),open_mode,&fh); mlog(FOP_DCOMMON, "Open %s: %s",path.c_str(),ret==PLFS_SUCCESS?"Success":strplfserr(ret)); if (fh != NULL) { store->Close(fh); } // else, ret was set already } return ret; }
void *next() { if(m_next >= m_a.size()) { noNextElementError(s_className); } checkUpdateCount(); for(m_current = m_next++; (m_next < m_a.size()) && !checkMask(m_next); m_next++); return &m_a[m_current]; }
// helper function for AccessOp // this used to be in Container since Container was the one that did // the lookup for us of the access file from the container name // but now plfs_file_operation is doing that so this code isn't appropriate // in container. really it should just be embedded in AccessOp::op() but // then I'd have to mess with indentation // return 0 or -err int Access( const string& path, IOStore *store, int mask ) { // there used to be some concern here that the accessfile might not // exist yet but the way containers are made ensures that an accessfile // will exist if the container exists // doing just Access is insufficient when plfs daemon run as root // root can access everything. so, we must also try the open mode_t open_mode; int ret; IOSHandle *fh; bool mode_set=false; //doing this to suppress a valgrind complaint char *cstr = strdup(path.c_str()); mlog(FOP_DAPI, "%s Check existence of %s", __FUNCTION__, cstr); ret = store->Access( cstr, F_OK ); if ( ret == 0 ) { // at this point, we know the file exists if(checkMask(mask,W_OK|R_OK)) { open_mode = O_RDWR; mode_set=true; } else if(checkMask(mask,R_OK)||checkMask(mask,X_OK)) { open_mode = O_RDONLY; mode_set=true; } else if(checkMask(mask,W_OK)) { open_mode = O_WRONLY; mode_set=true; } else if(checkMask(mask,F_OK)) { delete cstr; return 0; // we already know this } assert(mode_set); mlog(FOP_DCOMMON, "The file exists attempting open"); fh = store->Open(cstr,open_mode,ret); mlog(FOP_DCOMMON, "Open %s: %s",cstr,ret==0?"Success":strerror(-ret)); if (fh != NULL) { store->Close(fh); } // else, ret was set already } delete cstr; return ret; }
/*==================================================================*/ void ModifyStation::readIni(int no) { //获取当前工作站数目 int sNum = Settings::readStationNum(); //添加工作站的页面 if(type == STATION_ADD) { ++sNum; ui.lineEdit_stationName->setText(Settings::readName(sNum)); return; } //临时设置当前待添加station的名字 ui.lineEdit_stationName->setText(Settings::readName(no)); //当修改或者查看其他station ui.lineEdit_note->setText(Settings::readNote(no)); //更新checkbox传感器 checkMask(no); }
size_t first() const { size_t i; for(i = 0; (i < m_a.size()) && !checkMask(i); i++); return i; }
void testCheckMask(){ void* a; int numbytes; float fldata; double dbdata; int intdata; short shdata; long long lldata; // test scenarios // 1. all on // 2. some on // 3. all off // test float fldata = 0xffffffff; assert(checkMask((void*) &fldata,4)==1 && "float all masks on test failed"); fldata = 0x0f5ff09f; assert(checkMask((void*) &fldata,4)==1 && "float some masks on test failed"); fldata = 0x00000000; assert(checkMask((void*) &fldata,4)==0 && "float all masks off test failed"); // test double dbdata = 0xffffffffffffffff; assert(checkMask((void*) &dbdata,8)==1 && "double all masks on test failed"); dbdata = 0x0f5ff09f0f5ff09f; assert(checkMask((void*) &dbdata,8)==1 && "double some masks on test failed"); dbdata = 0x0000000000000000; assert(checkMask((void*) &dbdata,8)==0 && "double all masks off test failed"); // test short shdata = 0xffff; assert(checkMask((void*) &shdata,2)==1 && "short all masks on test failed"); shdata = 0x0f5f; assert(checkMask((void*) &shdata,2)==1 && "short some masks on test failed"); shdata = 0x0000; assert(checkMask((void*) &shdata,2)==0 && "short all masks off test failed"); // test int intdata = 0xffffffff; assert(checkMask((void*) &intdata,4)==1 && "int all masks on test failed"); intdata = 0x0f5ff09f; assert(checkMask((void*) &intdata,4)==1 && "int some masks on test failed"); intdata = 0x00000000; assert(checkMask((void*) &intdata,4)==0 && "int all masks off test failed"); // test long long lldata = 0xffffffffffffffff; assert(checkMask((void*) &lldata,8)==1 && "long long all masks on test failed"); lldata = 0x0f5ff09f0f5ff09f; assert(checkMask((void*) &lldata,8)==1 && "long long some masks on test failed"); lldata = 0x0000000000000000; assert(checkMask((void*) &lldata,8)==0 && "long long all masks off test failed"); }
int app( int argc, char** argv ) { // First parse any options and the filename we need. gengetopt_args_info options; int err = cmdline_parser( argc, argv, &options ); if ( err != EXIT_SUCCESS ) { return EXIT_FAILURE; } maim::IMEngine* imengine = new maim::IMEngine(options); // Then set up the x interface. if ( options.xdisplay_given ) { err = xengine->init( options.xdisplay_arg ); } else { // If we weren't specifically given a xdisplay, we try // to parse it from environment variables char* display = getenv( "DISPLAY" ); if ( display ) { err = xengine->init( display ); } else { fprintf( stderr, "Warning: Failed to parse environment variable: DISPLAY. Using \":0\" instead.\n" ); err = xengine->init( ":0" ); } } if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to grab X display!\n" ); return EXIT_FAILURE; } // Then the imlib2 interface err = imengine->init(); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to initialize imlib2!\n" ); return EXIT_FAILURE; } // Grab all of our variables from the options. bool gotGeometry = false; bool gotSelectFlag = options.select_flag; int x, y, w, h; float delay; err = sscanf( options.delay_arg, "%f", &delay ); if ( err != 1 ) { fprintf( stderr, "Failed to parse %s as a float for delay!\n", options.delay_arg ); return EXIT_FAILURE; } struct timespec delayTime; delayTime.tv_sec = delay; delayTime.tv_nsec = 0; // Get our geometry if we have any. if ( options.x_given && options.y_given && options.w_given && options.h_given && !options.geometry_given ) { x = options.x_arg; y = options.y_arg; w = options.w_arg; h = options.h_arg; gotGeometry = true; } else if ( ( options.x_given || options.y_given || options.w_given || options.h_given ) && !options.geometry_given ) { fprintf( stderr, "Partial geometry arguments were set, but it isn't enough data to take a screenshot!\n" ); fprintf( stderr, "Please give the geometry argument or give ALL of the following arguments: x, y, w, h.\n" ); cmdline_parser_free( &options ); return EXIT_FAILURE; } else if ( options.geometry_given ) { err = parseGeometry( options, &x, &y, &w, &h ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to parse geometry %s, should be in format WxH+X+Y!\n", options.geometry_orig ); cmdline_parser_free( &options ); return EXIT_FAILURE; } gotGeometry = true; } // Get our window if we have one, default to the root window. Window window = xengine->m_root; if ( options.windowid_given ) { window = (Window)options.windowid_arg; } // Get our file name std::string file = ""; // If we don't have a file, default to writing to the home directory. if ( options.inputs_num == 0 ) { // Try as hard as we can to get the current directory. int trycount = 0; char* home_env = getenv("HOME"); int length = MAXPATHLEN; char* currentdir = new char[ length ]; char* error = getcwd( currentdir, length ); while ( error == NULL ) { delete[] currentdir; length *= 2; currentdir = new char[ length ]; error = getcwd( currentdir, length ); trycount++; // Ok someone's trying to be whacky with the current directory if we're going 8 times over // the max path length. if ( trycount > 3 ) { fprintf( stderr, "Failed to grab the current directory!" ); // Try to HOME later if ( home_env == NULL ) { fprintf( stderr, "Failed to get HOME environment variable, no where left to save!" ); cmdline_parser_free( &options ); delete [] currentdir; return EXIT_FAILURE; } } } if ( is_valid_directory ( currentdir ) == EXIT_SUCCESS ) { file = currentdir; } else { file = home_env; } // Get unix timestamp std::stringstream result; result << (int)time( NULL ); file += "/" + result.str() + ".png"; printf( "No file specified, using %s\n", file.c_str() ); delete [] currentdir; } else if ( options.inputs_num == 1 ) { file = options.inputs[ 0 ]; } else { fprintf( stderr, "Unexpected number of output files! There should only be one.\n" ); cmdline_parser_free( &options ); return EXIT_FAILURE; } // Finally we have all our information, now to use it. if ( gotSelectFlag ) { err = slop( options, &x, &y, &w, &h, &window ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Selection was cancelled or slop failed to run. Make sure it's installed!\n" ); cmdline_parser_free( &options ); return EXIT_FAILURE; } err = nanosleep( &delayTime, NULL ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." ); } err = imengine->screenshot( window, x, y, w, h ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } if ( options.showcursor_flag ) { imengine->blendCursor( window, x, y ); } if ( checkMask( options.mask_arg, x, y, w, h, window ) ) { imengine->mask( x, y, w, h ); } err = imengine->save( file, options.format_arg ); cmdline_parser_free( &options ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } return EXIT_SUCCESS; } if ( gotGeometry ) { err = nanosleep( &delayTime, NULL ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." ); } err = imengine->screenshot( window, x, y, w, h ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } if ( options.showcursor_flag ) { imengine->blendCursor( window, x, y ); } if ( checkMask( options.mask_arg, x, y, w, h, window ) ) { imengine->mask( x, y, w, h ); } err = imengine->save( file, options.format_arg ); cmdline_parser_free( &options ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } return EXIT_SUCCESS; } // If we didn't get any special options, just screenshot the specified window // (Which defaults to the whole screen). err = nanosleep( &delayTime, NULL ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." ); } err = imengine->screenshot( window ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } if ( options.showcursor_flag ) { imengine->blendCursor( window ); } if ( checkMask( options.mask_arg, 0, 0, WidthOfScreen( xengine->m_screen ), HeightOfScreen( xengine->m_screen ), window ) ) { imengine->mask(); } err = imengine->save( file, options.format_arg ); cmdline_parser_free( &options ); if ( err != EXIT_SUCCESS ) { fprintf( stderr, "Failed to take screenshot.\n" ); return EXIT_FAILURE; } return EXIT_SUCCESS; }
void TriggerInputsForMuonEventCuts ( TString runListFilename, TString selectedInputs="", TString defaultStorage = "raw://" ) { AliCDBManager::Instance()->SetDefaultStorage(defaultStorage.Data()); TObjArray inputsList; inputsList.SetOwner(); TObjArray* selectedInputsList = selectedInputs.Tokenize(","); // Read input run list ifstream inFile(runListFilename.Data()); TString srun = ""; if ( inFile.is_open() ) { while ( ! inFile.eof() ) { srun.ReadLine(inFile,kFALSE); if ( ! srun.IsDigit() ) continue; // For each run, read trigger inputs from OCDB Int_t runNumber = srun.Atoi(); AliCDBManager::Instance()->SetRun(runNumber); // Get trigger class configuration AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/CTP/Config"); if ( ! entry ) continue; THashList* runInputs = new THashList(); runInputs->SetOwner(); runInputs->SetUniqueID((UInt_t)runNumber); AliTriggerConfiguration* trigConf = (AliTriggerConfiguration*)entry->GetObject(); const TObjArray& trigInputsArray = trigConf->GetInputs(); AliTriggerInput* trigInput = 0x0; TIter next(&trigInputsArray); while ( ( trigInput = static_cast<AliTriggerInput*>(next()) ) ) { if ( selectedInputsList->GetEntriesFast() > 0 && ! selectedInputsList->FindObject(trigInput->GetName()) ) continue; Int_t inputId = (Int_t)TMath::Log2(trigInput->GetMask()); TObjString* currInput = new TObjString(trigInput->GetName()); currInput->SetUniqueID(inputId); runInputs->Add(currInput); } inputsList.Add(runInputs); } inFile.close(); } delete selectedInputsList; // Loop on the trigger inputs // and group runs with an equal list of inputs Int_t nentries = inputsList.GetEntries(); TArrayI checkMask(nentries); checkMask.Reset(1); for ( Int_t irun=0; irun<nentries; irun++ ) { if ( checkMask[irun] == 0 ) continue; THashList* currList = static_cast<THashList*>(inputsList.At(irun)); TString runRange = Form("Run range: %u", currList->GetUniqueID()); for ( Int_t jrun=irun+1; jrun<nentries; jrun++ ) { if ( checkMask[jrun] == 0 ) continue; THashList* checkList = static_cast<THashList*>(inputsList.At(jrun)); Bool_t isDifferent = kFALSE; for ( Int_t itrig=0; itrig<currList->GetEntries(); itrig++ ) { TObjString* currInput = static_cast<TObjString*>(currList->At(itrig)); TObject* checkInput = checkList->FindObject(currInput->GetName()); if ( ! checkInput || checkInput->GetUniqueID() != currInput->GetUniqueID() ) { isDifferent = kTRUE; break; } } // loop on trigger inputs if ( isDifferent ) continue; checkMask[jrun] = 0; runRange += Form(",%u", checkList->GetUniqueID()); } // loop on runs TString outString = "\nSetTrigInputsMap(\""; for ( Int_t itrig=0; itrig<currList->GetEntries(); itrig++ ) { TObjString* currInput = static_cast<TObjString*>(currList->At(itrig)); outString += Form("%s:%u,",currInput->GetString().Data(), currInput->GetUniqueID()); } outString.Append("\");\n"); outString.ReplaceAll(",\"","\""); outString += runRange; printf("%s\n", outString.Data()); } // loop on runs }
int main( int argc, char** argv ) { // First parse any options and the filename we need. gengetopt_args_info options; int err = cmdline_parser( argc, argv, &options ); if ( err ) { return err; } // Then set up the x interface. err = xengine->init( options.xdisplay_arg ); if ( err ) { fprintf( stderr, "Failed to grab X display!\n" ); return err; } // Then the imlib2 interface err = imengine->init(); if ( err ) { fprintf( stderr, "Failed to initialize imlib2!\n" ); return err; } float delay = atof( options.delay_arg ); if ( !options.windowid_given ) { options.windowid_arg = None; } std::string file = ""; // If we don't have a file, default to writing to the home directory. if ( options.inputs_num <= 0 ) { char currentdir[MAXPATHLEN]; // FIXME: getcwd is fundamentally broken, switch it with a C++ equivalent that won't ever have // buffer sizing issues. char* error = getcwd( currentdir, MAXPATHLEN ); if ( error == NULL ) { fprintf( stderr, "Failed to get current working directory!\n" ); return errno; } file = currentdir; // Get unix timestamp std::stringstream result; result << (int)time( NULL ); file += "/" + result.str() + ".png"; printf( "No file specified, using %s\n", file.c_str() ); } else if ( options.inputs_num == 1 ) { file = options.inputs[ 0 ]; } else { fprintf( stderr, "Unexpected number of output files! There should only be one.\n" ); cmdline_parser_free( &options ); return 1; } // Check if we were asked to prompt for selection: if ( options.select_flag ) { // Execute slop with any options given. std::string result; std::stringstream slopcommand; slopcommand << "slop "; slopcommand << options.nokeyboard_flag ? "--nokeyboard" : ""; slopcommand << " -b " << options.bordersize_arg; slopcommand << " -p " << options.padding_arg; slopcommand << " -t " << options.tolerance_arg; slopcommand << " -g " << options.gracetime_arg; slopcommand << " -c " << options.color_arg; slopcommand << options.nodecorations_flag ? "-n" : ""; slopcommand << " --min=" << options.min_arg; slopcommand << " --max=" << options.max_arg; slopcommand << options.highlight_flag ? "-l" : ""; err = exec( slopcommand.str(), &result ); if ( err ) { fprintf( stderr, "slop failed to run, canceling screenshot. Is slop installed?\n" ); cmdline_parser_free( &options ); return 1; } // from here we'll just be parsing the output of slop. // Replace all ='s with spaces in the result, this is so sscanf works properly. int find = result.find( "=" ); while( find != result.npos ) { result.at( find ) = ' '; find = result.find( "=" ); } int x, y, w, h; int num = sscanf( result.c_str(), "X %d\n Y %d\n W %d\n H %d\n%*s", &x, &y, &w, &h ); if ( num == 4 && ( w > 0 && h > 0 ) ) { bool mask = checkMask( options.mask_arg, x, y, w, h, options.windowid_arg ); // Wait the designated amount of time before taking the screenshot. // 1000000 microseconds = 1 second usleep( (unsigned int)(delay * 1000000.f) ); err = imengine->screenshot( file, x, y, w, h, options.hidecursor_flag, options.windowid_arg, mask ); cmdline_parser_free( &options ); if ( err ) { return err; } return 0; } fprintf( stderr, "Either the user canceled the query for selection, or slop failed to run properly. Canceling screenshot.\n" ); cmdline_parser_free( &options ); return 1; } if ( options.x_given && options.y_given && options.w_given && options.h_given ) { options.geometry_given = true; char temp[128]; sprintf( temp, "%ix%i+%i+%i\0", options.w_arg, options.h_arg, options.x_arg, options.y_arg ); options.geometry_arg = temp; } else if ( ( options.x_given || options.y_given || options.w_given || options.h_given ) && !options.geometry_given ) { fprintf( stderr, "Partial geometry arguments were set, but it isn't enough data to take a screenshot!" ); fprintf( stderr, "Either give the geometry arugment, or give ALL of the following arguments: x, y, w, h," ); fprintf( stderr, " or don't give any of them." ); cmdline_parser_free( &options ); return 1; } // Just take a full screen shot if we didn't get any geometry. if ( !options.geometry_given ) { // Wait the designated amount of time before taking the screenshot. // 1000000 microseconds = 1 second usleep( (unsigned int)(delay * 1000000.f) ); err = imengine->screenshot( file, options.hidecursor_flag, options.windowid_arg, strcmp( options.mask_arg, "off" ) ? true : false ); cmdline_parser_free( &options ); if ( err ) { return err; } return 0; } // Otherwise take a screen shot of the supplied region. int x, y, w, h; parseGeometry( options.geometry_arg, &x, &y, &w, &h ); bool mask = checkMask( options.mask_arg, x, y, w, h, options.windowid_arg ); usleep( (unsigned int)(delay * 1000000.f) ); err = imengine->screenshot( file, x, y, w, h, options.hidecursor_flag, options.windowid_arg, mask ); cmdline_parser_free( &options ); if ( err ) { return err; } return 0; }