// wrapper for OpenFiles
// the while loop checks whether the file we wish to open is in the currently
// open file list
// we have to prevent it from opening directories above the one that might
// be passed here
void FileManager::OpenNewSet(int argc,char **argv)
	{
	file_iterator = filenames.begin(); // we have to check whether we're not opening a directory
	std::list<Glib::ustring>::iterator end = filenames.end();
	
	// let's see if the file is already in our list
	if( initialised && filter_filename( argv[1] ) )
		{
		while( file_iterator != end )
			{
			#ifdef DEBUG		
			std::cout << "OPENNEWSET: Looking for: " << argv[1] << " in " << *file_iterator << std::endl;
			#endif
			if( file_iterator->find( argv[1] ) != Glib::ustring::npos )
				break;
			file_iterator++;
			}
		}

	// if we have a file which we cannot open, it must be a directory
	if( !initialised || file_iterator == end || !filter_filename( argv[1] ) )
		{		
		if( OpenFiles(argc,argv) )
			initialised = true;
		else
			initialised = false;
		}
	else
		initialised = true;

	}
Esempio n. 2
0
main(int argc, Char *argv[])
{  /* ---- Main program ------------------------ */
  PASCAL_MAIN(argc, argv);
  strcpy(this_version, version);
  strcpy(this_version_date, version_date);
  printf("==> This is M-Tx %s (Music from TeXt) %s\n", version, version_date);

  mtxLevel(version);
  OpenFiles();
  no_commands_yet = true;
  preambleDefaults();
  no_report_errors = false;
  topOfPMXfile();
  do {
    readParagraph(P, orig_line_no, &para_len);
    control_paragraph = isControlParagraph(P, para_len);
    if (control_paragraph) {
      augmentPreamble(no_report_errors);
      no_report_errors = true;
      if (para_len == 0)
	error("No music paragraphs!", !print);
    }
  } while (control_paragraph);
  doPreamble();
  doMusic();
  if (!pmx_preamble_done)
    error("No music paragraphs!", !print);
  putLine("% Coded by M-Tx");
  CloseFiles();
  printf("PrePMX done.  Now run PMX.\n");
  _Escape(0);
  exit(EXIT_SUCCESS);
}
Esempio n. 3
0
static BROTLI_BOOL DecompressFiles(Context* context) {
  while (NextFile(context)) {
    BROTLI_BOOL is_ok = BROTLI_TRUE;
    BrotliDecoderState* s = BrotliDecoderCreateInstance(BrotliAllocFunc, BrotliFreeFunc, &scratch_buffer_size);
    if (!s) {
      fprintf(stderr, "out of memory\n");
      return BROTLI_FALSE;
    }
    /* This allows decoding "large-window" streams. Though it creates
       fragmentation (new builds decode streams that old builds don't),
       it is better from used experience perspective. */
    BrotliDecoderSetParameter(s, BROTLI_DECODER_PARAM_LARGE_WINDOW, 1u);
    is_ok = OpenFiles(context);
    if (is_ok && !context->current_input_path &&
        !context->force_overwrite && isatty(STDIN_FILENO)) {
      fprintf(stderr, "Use -h help. Use -f to force input from a terminal.\n");
      is_ok = BROTLI_FALSE;
    }
    if (is_ok) is_ok = DecompressFile(context, s);
    BrotliDecoderDestroyInstance(s);
    if (!CloseFiles(context, is_ok)) is_ok = BROTLI_FALSE;
    if (!is_ok) return BROTLI_FALSE;
  }
  return BROTLI_TRUE;
}
Esempio n. 4
0
static	pascal	OSStatus AppEventEventHandlerProc( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
{
	#pragma unused ( inCallRef, inUserData )
	HICommand		command;
	OSStatus 		err			= eventNotHandledErr;
	UInt32			eventClass	= GetEventClass( inEvent );
	UInt32			eventKind	= GetEventKind(inEvent);
	
	switch ( eventClass )
	{
		case kEventClassCommand:
			GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command );
			if ( eventKind == kEventCommandProcess )
			{
				if ( command.commandID == kHICommandNew )
				{
					DisplaySimpleWindow();
				}
				else if ( command.commandID == kHICommandOpen )		//	Open... menu choice
				{
					OpenFiles();
				}
			}
			break;
	}

	return( err );
}
Esempio n. 5
0
void PoeditApp::OnOpen(wxCommandEvent&)
{
    wxString path = wxConfig::Get()->Read("last_file_path", wxEmptyString);

    wxFileDialog dlg(nullptr,
                     _("Open catalog"),
                     path,
                     wxEmptyString,
                     _("GNU gettext catalogs (*.po)|*.po|All files (*.*)|*.*"),
                     wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);

    if (dlg.ShowModal() == wxID_OK)
    {
        wxConfig::Get()->Write("last_file_path", dlg.GetDirectory());
        wxArrayString paths;
        dlg.GetPaths(paths);

        if (paths.size() == 1)
        {
            TRY_FORWARD_TO_ACTIVE_WINDOW( OpenFile(paths[0]) );
        }

        OpenFiles(paths);
    }
}
// Command handler for dumping cycle lengths
int CCommandCycles::Process()
{
	// Open the file
	if (!OpenFiles(resCycles))
		return 7;

	int perline = perLine ? perLine : 16;

	// Dump all cycles
	int index = 0;
	while (true)
	{
		if ((index++ % perline)==0)
		{
			if (showPositionInfo)
				printf("\n[@%12i] ", file->CurrentPosition());
			else
				printf("\n");
		}

		int cyclelen= file->ReadCycleLen();
		if (cyclelen<0)
			break;


		printf("#%i ", cyclelen);
	}

	printf("\n\n");

	return 0;
}
Esempio n. 7
0
CAsyncFileReader::CAsyncFileReader(CAtlList<CHdmvClipInfo::PlaylistItem>& Items, HRESULT& hr) 
	: CUnknown(NAME("CAsyncFileReader"), NULL, &hr)
	, m_len((ULONGLONG)-1)
	, m_hBreakEvent(NULL)
	, m_lOsError(0)
{
	hr = OpenFiles(Items, modeRead|shareDenyNone|typeBinary|osSequentialScan) ? S_OK : E_FAIL;
	if(SUCCEEDED(hr)) m_len = GetLength();
}
Esempio n. 8
0
void PottsMeshReader<SPACE_DIM>::Reset()
{
    CloseFiles();
    OpenFiles();
    ReadHeaders();

    mNodesRead = 0;
    mElementsRead = 0;
}
Esempio n. 9
0
void CLogManager::Init(E_LOGDEST _eWarningDest, E_LOGDEST _eErrorDest, E_LOGDEST _eInfoDest)
{
	m_eWarningDest = _eWarningDest;
	m_eErrorDest = _eErrorDest;
	m_eInfoDest = _eInfoDest;

	OpenFiles();

	LOG_INFO("LogManager: Initialized");
}
Esempio n. 10
0
int main(int argc, char **argv) {
    char *filename;
    
    char source[255];
    char listing[255];
    char assembly[255];
    
    
    
    if(argc == 2) {
        filename = argv[1];
        
        strcpy(source, "io/input/");
        strcpy(listing, "io/output/");
        strcpy(assembly, "io/output/");
        
        strcat(source, filename);
        strcat(listing, filename);
        strcat(assembly, filename);
        
        strcat(source, ".src");
        strcat(listing, ".lst");
        strcat(assembly, ".asm");
        
        if(!OpenFiles(source, listing)) {
            printf("SOMETHING F****D UP\n");
        }
        
        InitCodeGen(assembly);
        InitSemantics();
        
        switch(yyparse()) {
            case 0:
                PostMessage(GetCurrentColumn(), "COMPILATION SUCSESSFUL");
                break;
            case 1:
                PostMessage(GetCurrentColumn(), "COMPILATION FAILED - BAD INPUT");
                printf("COMPILATION FAILED - BAD INPUT\n");
                break;
            case 2:
                PostMessage(GetCurrentColumn(), "COMPILATION FAILED - OUT OF MEMORY");
                printf("COMPILATION FAILED - OUT OF MEMORY\n");
                break;
            default:
                PostMessage(GetCurrentColumn(), "SOMETHING UNEXPECTED HAPPENED");
                printf("SOMETHING UNEXPECTED HAPPENED\n");
                break;
        }
        UpdateListingFile();
    } else {
        printf("Useage: Q <SourceName>");
    }
    
    exit(0);
}
Esempio n. 11
0
PottsMeshReader<SPACE_DIM>::PottsMeshReader(std::string pathBaseName)
    : mFilesBaseName(pathBaseName),
      mIndexFromZero(false), // initially assume that nodes are not numbered from zero
      mNumNodes(0),
      mNumElements(0),
      mNodesRead(0),
      mElementsRead(0),
      mNumElementAttributes(0)
{
    OpenFiles();
    ReadHeaders();
}
Esempio n. 12
0
void PoeditApp::OnOpenHist(wxCommandEvent& event)
{
    TRY_FORWARD_TO_ACTIVE_WINDOW( OnOpenHist(event) );

    wxString f(FileHistory().GetHistoryFile(event.GetId() - wxID_FILE1));
    if ( !wxFileExists(f) )
    {
        wxLogError(_("File '%s' doesn't exist."), f.c_str());
        return;
    }

    OpenFiles(wxArrayString(1, &f));
}
FString ImportPresetFile()
{
        TArray<FString> OutOpenFilenames;
        FString InOutLastPath = ".";
        if ( OpenFiles( TEXT("Import Preset"), TEXT("Import Types (*.sbsprs)|*.sbsprs;|All Files|*.*"),
                        InOutLastPath,
                        EFileDialogFlags::None, //single selection
                        OutOpenFilenames )
             )
                 return OutOpenFilenames[0];
        else
                 return FString();
}
Esempio n. 14
0
static BROTLI_BOOL CompressFiles(Context* context) {
  while (NextFile(context)) {
    BROTLI_BOOL is_ok = BROTLI_TRUE;
    BrotliEncoderState* s = BrotliEncoderCreateInstance(NULL, NULL, NULL);
    if (!s) {
      fprintf(stderr, "out of memory\n");
      return BROTLI_FALSE;
    }
    BrotliEncoderSetParameter(s,
        BROTLI_PARAM_QUALITY, (uint32_t)context->quality);
    if (context->lgwin > 0) {
      /* Specified by user. */
      /* Do not enable "large-window" extension, if not required. */
      if (context->lgwin > BROTLI_MAX_WINDOW_BITS) {
        BrotliEncoderSetParameter(s, BROTLI_PARAM_LARGE_WINDOW, 1u);
      }
      BrotliEncoderSetParameter(s,
          BROTLI_PARAM_LGWIN, (uint32_t)context->lgwin);
    } else {
      /* 0, or not specified by user; could be chosen by compressor. */
      uint32_t lgwin = DEFAULT_LGWIN;
      /* Use file size to limit lgwin. */
      if (context->input_file_length >= 0) {
        int32_t size = 1 << BROTLI_MIN_WINDOW_BITS;
        lgwin = BROTLI_MIN_WINDOW_BITS;
        while (size < context->input_file_length) {
          size <<= 1;
          lgwin++;
          if (lgwin == BROTLI_MAX_WINDOW_BITS) break;
        }
      }
      BrotliEncoderSetParameter(s, BROTLI_PARAM_LGWIN, lgwin);
    }
    if (context->input_file_length > 0) {
      uint32_t size_hint = context->input_file_length < (1 << 30) ?
          (uint32_t)context->input_file_length : (1u << 30);
      BrotliEncoderSetParameter(s, BROTLI_PARAM_SIZE_HINT, size_hint);
    }
    is_ok = OpenFiles(context);
    if (is_ok && !context->current_output_path &&
        !context->force_overwrite && isatty(STDOUT_FILENO)) {
      fprintf(stderr, "Use -h help. Use -f to force output to a terminal.\n");
      is_ok = BROTLI_FALSE;
    }
    if (is_ok) is_ok = CompressFile(context, s);
    BrotliEncoderDestroyInstance(s);
    if (!CloseFiles(context, is_ok)) is_ok = BROTLI_FALSE;
    if (!is_ok) return BROTLI_FALSE;
  }
  return BROTLI_TRUE;
}
Esempio n. 15
0
MainWindow::MainWindow()
{
    mUI.setupUi(this);
    libxdiff_tools_init();

    connect(mUI.mActionExit, SIGNAL(triggered()), this, SLOT(close()));
    connect(mUI.mActionOpenDirs, SIGNAL(triggered()), this, SLOT(OpenDirs()));
    connect(mUI.mActionOpenFiles, SIGNAL(triggered()), this, SLOT(OpenFiles()));

    connect(mUI.mActionToolBarMain, SIGNAL(toggled(bool)), this, SLOT(ToggleMainToolBar()));
    connect(mUI.mActionStatusBar, SIGNAL(toggled(bool)), this, SLOT(ToggleStatusBar()));

    connect(mUI.mActionAboutWinMerge, SIGNAL(triggered()), this, SLOT(AboutWinMerge()));
}
Esempio n. 16
0
int main()
{
	string sFileLine;				 // a string to read in each line of the file
	vector<string> sParsedLine;
	Scholarship scholars;			 // this object is initialized using default constructor

	// Open input and output files and test to make sure they openned correctly
	ifstream fin;
	ofstream fout;
	OpenFiles(fin, fout);
	scholars = readFile(sFileLine, sParsedLine, fin);
	writeFile(scholars, fout);
	
	return 0;
}
Esempio n. 17
0
void TrianglesMeshReader<ELEMENT_DIM, SPACE_DIM>::Reset()
{
    CloseFiles();

    mNodesRead = 0;
    mElementsRead = 0;
    mFacesRead = 0;
    mBoundaryFacesRead = 0;
    mCableElementsRead = 0;
    mNclItemsRead = 0;
    mEofException = false;

    OpenFiles();
    ReadHeaders();
}
Esempio n. 18
0
PUBLIC int main ( int argc, char *argv[] )
{
    if ( OpenFiles( argc, argv ) )  {
        InitCharProcessor( InputFile, ListFile );
        CurrentToken = GetToken();
        ParseProgram();
        fclose( InputFile );
        fclose( ListFile );
	printf("ok\n");
        return  EXIT_SUCCESS;
    }
    else 
      printf("failed\n");
      return EXIT_FAILURE;
}
Esempio n. 19
0
bool XMLPacketGen::ParseElements( const TiXmlElement* field )
{
    if( !OpenFiles() )
    {
        sLog.Error( "XMLPacketGen", "Unable to open output files: %s.", strerror( errno ) );
        return false;
    }

    const std::string def = FNameToDef( mHeaderFileName.c_str() );

    //headers:
    fprintf( mHeaderFile,
        "%s\n"
        "\n"
        "#ifndef %s\n"
        "#define %s\n"
        "\n"
        "#include \"python/PyVisitor.h\"\n"
        "#include \"python/PyRep.h\"\n"
        "\n",
        smGenFileComment,
        def.c_str(),
        def.c_str()
    );
    fprintf( mSourceFile,
        "%s\n"
        "\n"
        "#include \"EVECommonPCH.h\"\n"
	    "\n"
        "#include \"%s\"\n"
        "\n",
        smGenFileComment,
        mHeaderFileName.c_str()
    );

    //content
    bool res = ParseElementChildren( field );

    //footers:
    fprintf( mHeaderFile,
        "#endif /* !%s */\n"
        "\n",
        def.c_str()
    );

    return res;
}
Esempio n. 20
0
void main ( void )
{
   ifstream Inp;
   ofstream Out;
   char  TxtIn[255];
   int   NumIn;

   OpenFiles  (Inp, Out);

   Inp >> NumIn;        // Initialize CTicket::m_NextNumber
   CTicket::SetNumber(NumIn);

   Inp >> TxtIn;        // Read the first record type

   while ( !Inp.eof() )
   {
      if ( stricmp(TxtIn, "Pops") == 0 )
      {
         CPops Tick(Inp);
         Tick.Print(Out);
      }
      else if ( stricmp(TxtIn, "Ensemble") == 0 )
      {
		  CEnsemble Tick(Inp);
         Tick.Print(Out);
      }
      else if ( stricmp(TxtIn, "Recital") == 0 )
      {
		CRecital Tick(Inp);
         Tick.Print(Out);
      }
      else
      {
         cout << "Unrecognized ticket type " << TxtIn
              << "\nAborting the run." << endl;
         break;
      }

      Out << endl << endl;   // Spacing blank lines in output

      Inp >> TxtIn;          // Read the first record type
   }
// Preserve the screen output to allow copying:
   cout << "\n\nPress ENTER to exit:";
   cin.ignore(255, '\n');
}
Esempio n. 21
0
PUBLIC int main ( int argc, char *argv[] )
{
    if ( OpenFiles( argc, argv ) )  {
        InitCharProcessor( InputFile, ListFile );
        InitCodeGenerator( CodeFile );
        CurrentToken = GetToken();
        ParseExpression();
        _Emit( I_WRITE );   /* Print out top of stack, i.e, result of exp.  */
        _Emit( I_HALT );    /* Stop simulator.                              */
        WriteCodeFile();
        fclose( InputFile );
        fclose( ListFile );
        return  EXIT_SUCCESS;
    }
    else 
        return EXIT_FAILURE;
}
Esempio n. 22
0
int main(int argc, char** argv)
{
	if (argc == 4)
	{
		OpenFiles(argv[1],argv[2]);
		WriteHintHeader(argv[3]);
		WriteHintFile();
		CleanUp();
		printf("Hints extracted successfully");
	}
	else
	{
		printf("HintLink v1.0 by Stefan Meier.\n\n"
		       "Extractor for the hints in the Magnetic Windows versions of\n"
		       "Magnetic Scrolls games (Wonderland and the MS Collection Volume 1).\n"
		       "Usage: HintLink index text result\n\n");
	}
	return 0;
}
Esempio n. 23
0
int CompareFiles( void )
/**********************/
{
    int         error;
    int         result;
    WResFileID  fileid1;
    WResFileID  fileid2;

    error = OpenFiles( &fileid1, &fileid2 );

    if (!error) {
        result = CompareContents( fileid1, fileid2 );
    } else {
        result = -1;
    }

    CloseFiles( fileid1, fileid2 );

    return( result );
}
Esempio n. 24
0
FileManager::FileManager(int argc, char **argv)
	{
	// we have not initialised yet
	initialised = false;
	// no operations carried out yet
	last_op_next = false;
	last_op_previous = false;


	// initialise magic database
	if( (cookie = magic_open(MAGIC_SYMLINK) ) == NULL)
		std::cout << GT( "FILEMANAGER: ERROR during magic open" ) << std::endl;
	if( magic_load(cookie,NULL) != 0 )
		std::cout << GT( "FILEMANAGER: ERROR during magic load" ) << std::endl;

	numfiles=0;
	cwd_checked=0;
	/* let's call OpenFiles() to scan through the directories and set the initialised variable
	   to tell everyone we're up and running */
	if( OpenFiles(argc,argv) )
		initialised = true;
	}
Esempio n. 25
0
int main(int argc, char *argv[])
{
  int myproc, numprocs, j;
  MPI_Comm comm;
  gridT *grid;
  physT *phys;
  propT *prop;

  StartMpi(&argc,&argv,&comm,&myproc,&numprocs);

  ParseFlags(argc,argv,myproc);
  
  if(GRID)
    GetGrid(&grid,myproc,numprocs,comm);
  else
    ReadGrid(&grid,myproc,numprocs,comm);
  

  if(SOLVE) {
    //read parameters in suntans.dat into the solver
    ReadProperties(&prop,grid,myproc);
    // give space and initialize dzf(edge) dzz(center) dzzold(center)
    InitializeVerticalGrid(&grid,myproc);
    AllocatePhysicalVariables(grid,&phys,prop);
    AllocateTransferArrays(&grid,myproc,numprocs,comm);
    OpenFiles(prop,myproc);
    if(RESTART)
      ReadPhysicalVariables(grid,phys,prop,myproc,comm);
    else
      InitializePhysicalVariables(grid,phys,prop,myproc,comm);

    Solve(grid,phys,prop,myproc,numprocs,comm);
    //    FreePhysicalVariables(grid,phys,prop);
    //    FreeTransferArrays(grid,myproc,numprocs,comm);
  }

  EndMpi(&comm);
}
BOOL CNamedIndexesOptimiser::Optimise(void)
{
	int						i;
	CNamedIndexesBlocks*	pcBlocks;
	CIndexedFile*			pcIndexedFile;
	TRISTATE				tTotalResult;
	BOOL					bResult;

	ReturnOnFalse(OpenFiles());
	AssignBlockNumbers();

	tTotalResult = TRIFALSE;
	for (i = 0; i < mpacBlocks->NumElements(); i++)
	{
		pcBlocks = mpacBlocks->Get(i);
		pcIndexedFile = GetFile(pcBlocks->GetDataSize(), pcBlocks->GetFileNumber());
		bResult = OptimiseBlock(pcBlocks, pcIndexedFile);
		if (!bResult)
		{
			return CloseFiles(FALSE);
		}
	}
	return CloseFiles(TRUE);
}
Esempio n. 27
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : main
@INPUT      : 
@OUTPUT     : none
@RETURNS    : none
@DESCRIPTION: Sets up a new MINC file so that it can contain image data.
              Creates the dimensions, and the image, time, time-width,
              image-max, and image-min variables.
@METHOD     : none
@GLOBALS    : ncopts
@CALLS      : GetArgs
              CreateDims
              MINC library
              NetCDF library
@CREATED    : June 3, 1993 by MW
@MODIFIED   : 
---------------------------------------------------------------------------- */
int main (int argc, char *argv[])
{
   char   *TimeStamp;           /* to be put in the history attribute */
   nc_type NCType;
   Boolean Signed;

   long    NumFrames;           /* lengths of the various image dimensions */
   long    NumSlices;
   long    Height;
   long    Width;

   int     ChildCDF;
   int     ParentCDF;

   /* NumDim will be the number of image dimensions actually created in
    * the MINC file; DimIDs and DimNames will hold the ID's and names
    * of these dimensions.  There will be 2 dimensions if both NumFrames
    * and NumSlices are zero; 3 dimensions if either one but not both is
    * zero; and 4 dimensions if neither are zero.  (Height and Width must
    * always be non-zero.)
    */

   int     NumDim;       
   int     DimIDs [MAX_IMAGE_DIM];
   char   *DimNames [MAX_IMAGE_DIM];

   int	   NumExclude;
   int	   Exclude[MAX_NC_DIMS];


   ErrMsg = (char *) calloc (256, sizeof (char));
   TimeStamp = time_stamp (argc, argv);
   GetArgs (&argc, argv,
            &NumFrames, &NumSlices, &Height, &Width, 
            &NCType, &Signed);

#ifdef DEBUG
   printf ("main: Parent file: %s; new file: %s\n\n", gParentFile, gChildFile);
#endif

   ncopts = 0;

   ERROR_CHECK 
      (OpenFiles (gParentFile, gChildFile, &ParentCDF, &ChildCDF));

   ERROR_CHECK 
      (CreateDims (ChildCDF, NumFrames, NumSlices, Height, Width, 
		   gOrientation, &NumDim, DimIDs, DimNames));
   ERROR_CHECK
      (CreateDimVars (ParentCDF, ChildCDF, NumDim, DimIDs, DimNames, 
		      &NumExclude, Exclude));

   ERROR_CHECK 
      (CreateImageVars (ChildCDF, NumDim, DimIDs, NCType, Signed, gValidRange));

#ifdef DEBUG
   printf ("--------------------------------------------------------------\n");
   printf ("State of %s immediately before entering CopyOthers:\n",gParentFile);
   DumpInfo (ParentCDF);

   printf ("--------------------------------------------------------------\n");
   printf ("State of %s immediately before entering CopyOthers:\n", gChildFile);
   DumpInfo (ChildCDF);
#endif


   /*
    * Now, copy everything else of possible interest from the parent file
    * (but only if it exists!) to the child file.
    */

   if (ParentCDF != -1)
   {
      FinishExclusionLists (ParentCDF, NumDim, DimNames, &NumExclude, Exclude);

      ERROR_CHECK
	 (CopyOthers (ParentCDF, ChildCDF, NumExclude, Exclude, TimeStamp));
   }

   if (gImageVal != DBL_MAX)
      ERROR_CHECK (FillImage (ChildCDF, NumDim, DimIDs, gImageVal));

   ncclose (ChildCDF);
   if (ParentCDF != -1)
   {
      ncclose (ParentCDF);
   }
   return (0);

}
void checkOriginSelectedMuon(){

  //if(!strcmp(outFileName.c_str(), "")){
  //  std::cout << "No output specified. return" << std::endl;
  //  return;
  //}
  OpenFiles("~/Documents/MCtt_tcHigh_All.root", 0);            //NoLepIso cut done
  //TFile* outFile = new TFile(outFileName.c_str(),"RECREATE");

  int test = 0, yes = 0;
  for(int i = 0; i < nFiles; i++){

    SetAddressBranches(i);

    for(int entry = 0; entry < (int)tr_[i]->GetEntries(); entry++){
      
      tr_[i]->GetEntry(entry);

      if(hiBin < 160) continue;

      int indexMuon = -999;
      double Ptlepfirst = 0.;
      for(int ilep = 0; ilep<nLep; ilep++){
        if(lepPt[ilep] > Ptlepfirst){
          Ptlepfirst = lepPt[ilep];
          indexMuon = ilep;
        }
      }

      if(lepPt[indexMuon] < 18.) continue;

      if(hiBin<20 && lepIso[indexMuon]>0.58) continue;
      else if(hiBin>=20 && hiBin<60 && lepIso[indexMuon]>0.45) continue;
      else if(hiBin>=60 && hiBin<100 && lepIso[indexMuon]>0.3) continue;
      else if(hiBin>=100 && hiBin<140 && lepIso[indexMuon]>0.24) continue;
      else if(hiBin>=140 && lepIso[indexMuon]>0.18) continue;

      std::vector<int> indexJets;
      for(int ij = 0; ij < nJt; ij++){

        if(jtPt[ij] < 30.) continue;
        if(fabs(jtEta[ij]) > 2.) continue;

        double drJetToMuon = sqrt( pow( TMath::Abs(TVector2::Phi_mpi_pi(lepPhi[indexMuon] - jtPhi[ij]) ) ,2) + pow(jtEta[ij]-lepEta[indexMuon],2) ); 
        if(drJetToMuon < 0.3)  continue;

        indexJets.push_back(ij);
      }

      std::vector<int> indexbJets = FindbJets(indexJets);
      std::vector<int> srt_indexJets = BuildCSVVectorLeadingbJets(indexJets);

      if((int)indexJets.size() < nJets && (int)indexbJets.size() < nbJets) continue;
/*
      for(int iMC = 0; iMC < nGen; iMC++){
        if(fabs(genPdg[iMC]) < 10 || fabs(genPdg[iMC]) == 24){
          cout << iMC << ": " << genPdg[iMC] << " " << genEta[iMC] << " " << genPhi[iMC] << endl;
        }
      }
      cout << endl << endl;
*/
      int iWplus(-99), iWmin(-99);
      for(int iMC = 0; iMC < nGen; iMC++){
        if(genPdg[iMC] == -24) iWmin = iMC;
        if(genPdg[iMC] == 24) iWplus = iMC;
      }

      TLorentzVector j1, j2, j12;
      std::vector<int> vector_j1, vector_j2;
      std::vector<TLorentzVector> vector_j12;
      for(int i = 0; i < nJt; i++){
        j1.SetPtEtaPhiM(jtPt[i],jtEta[i],jtPhi[i],jtM[i]);
        for(int j = i+1; j < nJt; j++){
          j2.SetPtEtaPhiM(jtPt[j],jtEta[j],jtPhi[j],jtM[j]);
          j12 = j1 + j2;

          double deltaphi = TMath::Abs(TVector2::Phi_mpi_pi(j12.Phi() - genPhi[iWmin]) );
          double deltaeta = TMath::Abs(j12.Eta() - genEta[iWmin] );

          //cout << j12.M() << " " ;
          if(j12.M() < 90. && j12.M() > 70. /*&& deltaeta < 0.2 && deltaphi < 0.2 */){
            vector_j1.push_back(i);
            vector_j2.push_back(j);
            vector_j12.push_back(j12);
          }
        }
      }

      cout << vector_j1.size() << " " << vector_j2.size() << endl;
      if((int)vector_j1.size() == 1){
        //cout << jtPt[vector_j1[0]]<<" " << jtEta[vector_j1[0]]<<" "<<jtPhi[vector_j1[0]]<<" "<<jtM[vector_j1[0]]<<endl;
        cout << vector_j12[0].Pt() <<" "<<vector_j12[0].Eta()<<" "<<vector_j12[0].Phi()<<" "<<vector_j12[0].M()<<endl;
        cout << genPt[iWplus]<<" "<<genEta[iWplus]<<" "<<genPhi[iWplus]<<endl;
        cout << genPt[iWmin]<<" "<<genEta[iWmin]<<" "<<genPhi[iWmin]<<endl;
      }

	    //if(checkSelectedMuon(indexMuon, entry)) yes++;
      test++;
  	}
    cout << yes << " good matches of " << test << " in total of " << tr_[i]->GetEntries() << " events" << endl;
  }
}
Esempio n. 29
0
UINT COXFileChanger::Run()
	// --- In      :
	// --- Out     : 
	// --- Returns : occurences of found match or replacement
	// --- Effect  : perform search/replace
	{
	int  M = PtrToInt(m_pSearch->GetSize());
	// ... search text/binary length
	int	 M_1 = M - 1;
	// ... array max subscript
	int	 MM_1 = M + M_1;
	// ... i shift value when found
	int	 n = 0;
	// ... actual bytes read from the file at one time
	int	 i = 0;
	// ... scanning position pointer of file buffer
	int	 j = 0;
	// ... scanning position pointer of search text/binary
	int	 w = 0;
	// ... write position pointer in the loaded file buffer
	int	 t = 0;
	// ... temp value
	int	 skip[255];					
	// ... skip array for each byte value

	LONG lPos0 = 0;
	// ... file position of the current buffer[0]
	LONG nCurInPos = 0;
	// ... loading position of the input file
	LONG nInPos = 0;
	// ... match found position of the input file
	LONG nCurOutPos = 0;
	// ... writing position of the output file
	LONG nOutPos = 0;
	// ... replace text/binary position of the output file
	LONG nChPos = 0;
	// ... position of prev/next char for whole word match
	LONG nChPosMax = 0;
	// ... maximum file position of prev/next char for whole word match
	UINT nResult = 0;
	// ... match occurence
	BYTE* pBuffer = NULL;	
	// ... file buffer

	BOOL bEOF = FALSE;
	// ... end of file
	BOOL bContinue = TRUE;
	// ... default bContinue value
	BOOL bReplace = GetFlag(m_nFlagReplace);
	// ... Replace() (TRUE) or Search() (FALSE)
	BOOL bText = GetFlag(m_nFlagText);
	// ... whether text search
	BOOL bMatchCase = (!bText || GetFlag(m_nFlagMatchCase));
	// ... whether case-insensitive
	BOOL bWholeWord = (bText && GetFlag(m_nFlagWholeWord));
	// ... whether whole word
	char ch = '\0';
	// ... prev/next char for whole word match
	CString sSafeStack;
	// Increases the stack size
	
	if (M == 0)
		{
		TRACE0("COXFileChanger::Run(): aborted: zero length search text/binary encountered.\r\n");
		return 0;
		}

	if (m_nBufferSize < M)
		{
		TRACE0("COXFileChanger::Run(): aborted: length of search text/binary exceeds upper limit.\r\n");
		return 0;
		}

	// Initialize skip array
	for (j = 0; j < 256; j++) 
		skip[j] = M;
	for (j = 0, t = M; j < M; j++) 
		skip[m_pSearch->GetAt(j)] = --t;
	if (!bMatchCase) 
		for (j = 0, t = M; j < M; j++) 
			skip[m_pSearchOppositeCase->GetAt(j)] = --t;
		
	try
		{
		// Alllocate the buffer
		pBuffer = new BYTE[m_nBufferSize];

		OpenFiles();
		nChPosMax = (LONG) m_pFileIn->GetLength() - 1;
		while (!bEOF && (n = m_pFileIn->Read(pBuffer, m_nBufferSize)) > 0)
			{
			bEOF = (n < m_nBufferSize);
			if (!bContinue && bReplace)
				{ 
				// Cycle until all remaining contents are copied
				m_pFileOut->Write(pBuffer, n);
				continue;
				}

			if (!bContinue || n < M) 
				break;
			i = - M; w = 0;
			while (bContinue)
				{
				// search one occurence
				for (i += MM_1, j = M_1; 0 <= j && i < n; i--, j--)
					{
					while (pBuffer[i] != m_pSearch->GetAt(j) && (bMatchCase || 
						   pBuffer[i] != m_pSearchOppositeCase->GetAt(j)))
						{
						t = skip[pBuffer[i]];
						i += __max(M - j, t);
						if (n <= i)	
							{
							i++; 
							break;
							}
						j = M_1;
						}
					}
				// out of buffer boundary
				if (n <= i)
					{
					if (bReplace) 
						m_pFileOut->Write(pBuffer + w, (bEOF ? n : i - M_1) - w);
					if (!bEOF) 
						lPos0 = (LONG) m_pFileIn->Seek(i - M_1 - n, CFile::current);
					break;
					}

				i++;
				nCurInPos = (LONG) m_pFileIn->GetPosition();
				nInPos = lPos0 + i;
				
				// test wholeword match
				if (bWholeWord)
					{
					nChPos = i - 1;
					for (t = 0; t < 2; t++)
						{
						// look in buffer first
						if (0 <= nChPos && nChPos < n)
							ch = *(pBuffer + nChPos);
						else
							{ // look in the file
							nChPos += lPos0;
							if (0 <= nChPos && nChPos <= nChPosMax)
								{
								m_pFileIn->Seek(nChPos, CFile::begin);
								m_pFileIn->Read(&ch, 1);
								}
							else 
								// beginning or the end of the file
								ch = ' ';
							}
						if (isalnum(ch)) 
							break;
						nChPos = i + M;
						}
					if (t < 2)
						{
						m_pFileIn->Seek(nCurInPos, CFile::begin);
						i -= M_1;
						continue;
						}
					}

				// found one match
				bContinue = GetFlag(m_nFlagAll);
				m_pFileIn->Seek(nInPos, CFile::begin);
				if (bReplace)
					{
					if (OnPreReplace(m_pFileIn, nInPos, bContinue))
						{
						nResult++;
						m_pFileOut->Write(pBuffer + w, i - w);
						nOutPos = (LONG) m_pFileOut->GetPosition();
						m_pFileOut->Write(m_pReplace->GetData(), PtrToUint(m_pReplace->GetSize()));
						w = i + M;
						nCurOutPos = (LONG) m_pFileOut->GetPosition();
						m_pFileOut->Seek(nOutPos, CFile::begin);
						OnPostReplace(m_pFileOut, nOutPos);
						m_pFileOut->Seek(nCurOutPos, CFile::begin);
						}
					if (!bContinue)	
						m_pFileOut->Write(pBuffer + w, n - w);
					}
				else
					{
					if (OnFound(m_pFileIn, nInPos, bContinue))
						nResult++;
					}
				m_pFileIn->Seek(nCurInPos, CFile::begin);
				}
			}
		CloseFiles();
		}
	catch (...)
		{
		if (!GetFlag(m_nFlagUseCFile))
			{
			CString sTempFileName = m_pFileOut->GetFilePath();
			m_pFileIn->Abort();
			m_pFileOut->Abort();
			if (bReplace && GetFlag(m_nFlagOverwrite) && !sTempFileName.IsEmpty())
				::DeleteFile(sTempFileName);
			}
		m_pFileIn = NULL;
		m_pFileOut = NULL;
		delete[] pBuffer;
		pBuffer = NULL;
		throw;
		}

	// Clean up
	delete[] pBuffer;
	pBuffer = NULL;
	m_pFileIn = NULL;
	m_pFileOut = NULL;
	return nResult;
	}
Esempio n. 30
0
TrianglesMeshReader<ELEMENT_DIM, SPACE_DIM>::TrianglesMeshReader(std::string pathBaseName,
                                                                 unsigned orderOfElements,
                                                                 unsigned orderOfBoundaryElements,
                                                                 bool readContainingElementForBoundaryElements)
    : mFilesBaseName(pathBaseName),
      mNodeItemWidth(0),
      mElementItemWidth(0),
      mFaceItemWidth(0),
      mNumNodes(0),
      mNumElements(0),
      mNumFaces(0),
      mNumCableElements(0),
      mNodesRead(0),
      mElementsRead(0),
      mCableElementsRead(0),
      mFacesRead(0),
      mBoundaryFacesRead(0),
      mNclItemsRead(0),
      mNumNodeAttributes(0),
      mNumElementAttributes(0),
      mNumFaceAttributes(0),
      mNumCableElementAttributes(0),
      mOrderOfElements(orderOfElements),
      mOrderOfBoundaryElements(orderOfBoundaryElements),
      mEofException(false),
      mReadContainingElementOfBoundaryElement(readContainingElementForBoundaryElements),
      mFilesAreBinary(false),
      mMeshIsHexahedral(false),
      mNodeFileReadBuffer(NULL),
      mElementFileReadBuffer(NULL),
      mFaceFileReadBuffer(NULL),
      mNodePermutationDefined(false)
{
    // Only linear and quadratic elements
    assert(orderOfElements==1 || orderOfElements==2);
    if ( mOrderOfBoundaryElements == 2 &&  mReadContainingElementOfBoundaryElement)
    {
        EXCEPTION("Boundary element file should not have containing element info if it is quadratic");
    }
    if (mOrderOfElements==1)
    {
        mNodesPerElement = ELEMENT_DIM+1;
    }
    else
    {
        #define COVERAGE_IGNORE
        assert(SPACE_DIM==ELEMENT_DIM);
        #undef COVERAGE_IGNORE
        mNodesPerElement = (ELEMENT_DIM+1)*(ELEMENT_DIM+2)/2;
    }

    if (mOrderOfBoundaryElements==1)
    {
        mNodesPerBoundaryElement = ELEMENT_DIM;
    }
    else
    {
        #define COVERAGE_IGNORE
        assert(SPACE_DIM==ELEMENT_DIM);
        #undef COVERAGE_IGNORE
        mNodesPerBoundaryElement = ELEMENT_DIM*(ELEMENT_DIM+1)/2;
    }

    mIndexFromZero = false; // Initially assume that nodes are not numbered from zero

    OpenFiles();
    ReadHeaders();
}