void testHashMap(const std::string& dictFileName, const std::string &searchFileName){
  std::unordered_map<std::string,std::string> map;
  std::ifstream dictFile;
  if(openInFile(dictFileName,dictFile)){
    int lineNo=0;
    std::string line;
    while(getline(dictFile,line)){
      lineNo++;
      //printf("Adding line no %d\n",lineNo);
      std::pair<std::string,std::string> record (line,line);
      map.insert(record);
    }
    printf("Added %d lines\n",lineNo);
    dictFile.close();
    if(openInFile(searchFileName,dictFile)){
      int found=0;
      int notFound=0;
      while(getline(dictFile,line)){
	if(map.find(line)==map.end())
	  //printf("Found record %s\n",line.c_str());
	  notFound++;
	else
	  found++;
	//printf("Record %s not found\n",line.c_str());
      }
      printf("Found %d records not found %d records.\n",found,notFound);
      dictFile.close();
    }
  }
}
void testBurstTrie(const std::string& dictFileName, const std::string &searchFileName){
  BurstTrie bt;
  std::ifstream dictFile;
  if(openInFile(dictFileName,dictFile)){
    int lineNo=0;
    std::string line;
    while(getline(dictFile,line)){
      lineNo++;
      //printf("Adding line no %d\n",lineNo);
      bt.addRecord(Record(line));
    }
    printf("Added %d lines\n",lineNo);
    dictFile.close();
    if(openInFile(searchFileName,dictFile)){
      int found=0;
      int notFound=0;
      while(getline(dictFile,line)){
	if(bt.findRecord(Record(line)))
	  //printf("Found record %s\n",line.c_str());
	  found++;
	else
	  notFound++;
	//printf("Record %s not found\n",line.c_str());
      }
      printf("Found %d records not found %d records.\n",found,notFound);
      dictFile.close();
    }
  }
}
int AnalysisManager::initializeTree(std::string fileName)
{
    openInFile(fileName);
    inFilesList_[fileName]->cd();
    if(treeFilesList_[fileName] == 0)
    {
        treeFilesList_[fileName] = (TTree*)inFilesList_[fileName]->Get("CaptanTrack");
        if(!treeFilesList_[fileName])
        {
            std::string msg = "ERROR: Can't find tree CaptanTrack in file " + fileName;
            FATAL(msg,ACRed);
            exit(EXIT_FAILURE);
        }
        int threadNumber = fileNameToTreePos_[fileName].first;
        int treeNumber   = fileNameToTreePos_[fileName].second;
        threadedTrees_ [threadNumber][treeNumber] = treeFilesList_[fileName];
        if(threadedData_.find(threadNumber) == threadedData_.end()
                && threadedData_[threadNumber].find(treeNumber) == threadedData_[threadNumber].end())
            threadedData_  [threadNumber][treeNumber] = Data();

        threadedData_  [threadNumber][treeNumber].setBranchAddress(treeFilesList_[fileName]);
        threadedCurrentEntries_[threadNumber][treeNumber] = 0     ;
    }

    return treeFilesList_[fileName]->GetEntries();
}
Beispiel #4
0
int main (int args, char * argsv[])
{	
	printf("\nAssignment 7 written by Paul Szyller\n\n");
	FILE *fp = openInFile (argsv[1]);	
	DynamicArray *workforce = construct(0);
	readData (workforce, fp);
	
	int i;
	for (i = 0; workforce->employees[i]; i++)
	{
		free (workforce->employees[i]->name);
	}
	free (workforce);
}
Beispiel #5
0
std::vector < RVector3 > loadRVector3(const std::string & fileName){
    std::vector < RVector3 > l;
    std::fstream file; openInFile(fileName, & file, true);
    std::vector < std::string > row;

    while (! file.eof()){
        row = getNonEmptyRow(file);
        switch (row.size()){
            case 1 : l.push_back(RVector3(toDouble(row[0]), 0.0, 0.0)); break;
            case 2 : l.push_back(RVector3(toDouble(row[0]), toDouble(row[1]), 0.0)); break;
            case 3 : l.push_back(RVector3(toDouble(row[0]), toDouble(row[1]),
                                    toDouble(row[2]))); break;
        }
    }
    file.close();
    return l;
}
Beispiel #6
0
std::map < int, int > loadIntMap(const std::string & filename){
    std::map < int, int > aMap;

    std::fstream file; if (!openInFile(filename, & file)){
        std::cerr << WHERE_AM_I << " Map not found: " << filename << std::endl;
        return aMap;
    }

    std::vector < std::string > row;
    while (! file.eof()) {
        row = getNonEmptyRow(file);
        if (row.size() == 2) aMap[toInt(row[0])] = toInt(row[1]);
    }

    file.close();
    return aMap;
}
Beispiel #7
0
uint countColumnsInFile(const std::string & fname, uint & columnsCount){
    columnsCount = 0;
    std::fstream file; if (!openInFile(fname, & file, false)) { return 0; }

    std::vector < std::string > subStrings;
    std::string str, tmp;

    while (!file.eof()){
        getline(file, str);
        if (str.find('#') != std::string::npos || str.empty()) {
            columnsCount++;
        } else {
            file.close();
            return getSubstrings(str).size();
        }
    }

    file.close();
    return 0;
}
Beispiel #8
0
int loadLabels (const char *fileName, long nbObjects, int *labels) {
    FILE *inLabels = openInFile(fileName);
    long nbO, nbC;
    fscanf(inLabels, "%li %li", &nbO, &nbC);
    if (nbO != nbObjects)
      errorAndQuit("\nNumber of objects in label file (%li) does not match expected number of objects (%li).\n\n", nbO, nbObjects);
    int minClass = INT_MAX;
    int maxClass = INT_MIN;
    for (int i=0; i<nbObjects; i++) {
      if (!fscanf(inLabels, "%i", labels+i))
	errorAndQuit("\nUnexpected en of input while reading init label file '%s'.\n\n", fileName);
      if (labels[i] < minClass) minClass = labels[i];
      if (labels[i] > maxClass) maxClass = labels[i];
    }
    long nbClasses = maxClass - minClass + 1;
    if (nbClasses != nbC)
      errorAndQuit("\nObserved number of classes (%i), not equal to declared number of classes (%li)\nin labels file '%s'.\n\n", nbClasses, nbC, fileName);
    // Normalize to have labels in [0, nbClasses-1]
    for (int i=0; i<nbObjects; i++)
      labels[i] -= minClass;
    fclose(inLabels);
    return (int)nbClasses;
}
Beispiel #9
0
std::map < float, float > loadFloatMap(const std::string & filename){
    std::map < float, float > aMap;

    std::fstream file; if (!openInFile(filename, & file)){
        std::cerr << WHERE_AM_I << " Map not found: " << filename << std::endl;
        return aMap;
    }

    std::vector < std::string > row;
    while (!file.eof()) {
        row = getNonEmptyRow(file);
        if (row.size() == 2){
            aMap[toFloat(row[0])] = toFloat(row[1]);
        } else {
            if (aMap.size() == 0){
                throwError(1, "no proper format found for map <float, Complex> in " + filename  + " " + str(row.size()) );
            }
        }
    }

    file.close();
    return aMap;
}
Beispiel #10
0
void getGlu(const char * mode = "pp2")
{
  TH1::SetDefaultSumw2();

  int nbinsFine = 28;
  TH1D * recoGlu = new TH1D("recoGlu","",nbinsFine,60,200);
  TH1D * recoTot = new TH1D("recoTot","",nbinsFine,60,200);
  TH1D * genGlu = new TH1D("genGlu","",nbinsFine,60,200);
  TH1D * genTot = new TH1D("genTot","",nbinsFine,60,200);
 
//setting up files 
  std::vector<std::string> fileList;
  if(strcmp("pp2",mode)==0) fileList = readInputFileList("pp2MCFiles.txt");
  if(strcmp("pPb5",mode)==0) fileList = readInputFileList("pPbMCFiles.txt");
  if(strcmp("pp7",mode)==0) fileList = readInputFileList("pp7MCFiles.txt");
  int nFiles = fileList.size();

  //pp7 MC reweighting
  int totalEntriesForWeighting[7] = {0};
  if(strcmp(mode, "pp7")==0)
  {
    for(int f=0; f<nFiles; f++)
    { 
      if(f%100 == 0) std::cout << "tabulating entries; file " << f << "/" << nFiles <<std::endl;
      int isGoodFile = openInFileFast(fileList[f].data(),mode,1);
      if( isGoodFile == 0)
      { 
        closeInFileFast(0);
        continue;
      }

      for(int i = 0; i<7; i++)
      {
        if(fileList[f].find(Form("%dto%d",(int)pp7PthatBounds[i],(int)pp7PthatBounds[i+1])) != std::string::npos) totalEntriesForWeighting[i] += trackIn->GetEntries();
      }
      closeInFileFast();
    }
    for(int i = 0 ; i<7; i++) std::cout << pp7PthatBounds[i] << " has " << totalEntriesForWeighting[i] << " entries." <<std::endl;
  }

//start of skim here 
  //looping over forests to skim out of
  //change f= at 2 spots to change starting point, as well as skim outFileNum
  for(int f = 0; f<nFiles; f++)
  {   
    int isGoodFile = openInFile(fileList[f].data(),mode,1);
    if( isGoodFile == 0)
    {
      closeInFile(0);
      continue;
    }

    int nEntries = ak3PFIn->GetEntries();
    //nEntries = 50;
    for(int i = 0; i<nEntries; i++)
    {
      if(i%10000==0) std::cout <<"file: " << f << " event: " << i << "/" << nEntries << std::endl;
      skimIn->GetEntry(i);
      if(pPAcollisionEventSelectionPA == 0 && pcollisionEventSelection == 0) continue; 
   
      ak3PFIn->GetEntry(i);
      float boost = 0;
      if(strcmp("pp2",mode)==0)
      {
        if(pthat > pp2PthatBounds[f+2]) continue;
        weight = crossSection2[f]/(float)nEntries;
      }
      if(strcmp("pPb5",mode)==0 || strcmp("Pbp5",mode)==0)
      {
        boost = pPbRapidity;
        if(pthat > pPb5PthatBounds[f+2]) continue; 
        weight = crossSection5[f]/(float)nEntries;
      }
      if(strcmp("pp7",mode)==0)
      {
        for(int k = 0; k<7; k++)
        {
          if(fileList[f].find(Form("%dto%d",(int)pp7PthatBounds[k],(int)pp7PthatBounds[k+1])) != std::string::npos) weight = crossSection7[k]/(float)totalEntriesForWeighting[k];
        }    
      }
       
      for(int j =0; j < nref; j++)
      {  
        if(TMath::Abs(jteta[j]+boost)>1.5) continue;
        if(TMath::Abs(refparton_flavor[j]) < 901)
        {
          recoTot->Fill(jtpt[j],weight);
          if(refparton_flavor[j] == 21) recoGlu->Fill(jtpt[j],weight);
          genTot->Fill(refpt[j],weight);
          if(refparton_flavor[j] == 21) genGlu->Fill(refpt[j],weight);
        }
      } 
    }
    //cleanup so we can open another
    closeInFile();  
  }
  recoGlu->Divide(recoTot);
  genGlu->Divide(genTot);
  recoGlu->SetDirectory(0);
  genGlu->SetDirectory(0);
  TFile * outputFile = new TFile("gluonFracs.root","update");
  recoGlu->SetName(Form("%s_gFrac_recoMC",mode));
  genGlu->SetName(Form("%s_gFrac_genMC",mode));
  recoGlu->Write();
  genGlu->Write();
  outputFile->Close();
  delete recoGlu;
  delete genGlu;
  delete recoTot;
  delete genTot; 
}
void AnalysisManager::openInFiles(void)
{
    for(std::map<std::string,TFile*>::iterator fileIt=inFilesList_.begin(); fileIt!=inFilesList_.end(); fileIt++)
        openInFile(fileIt->first);
}
Beispiel #12
0
uint countRowsInFile(const std::string & fname){
    std::fstream file; openInFile(fname, & file);
    CERR_TO_IMPL;
    file.close();
    return 0;
}