Beispiel #1
0
	void ARehabMainWindow::slot_actionRutaFichero(void)
	{
		if (!dirFiles.exists())
		{
			dirFiles.mkdir("./ARehabFiles");
		}
		if (fileDialog)
		{
			fileDialog->setFileMode(QFileDialog::AnyFile);
			fileDialog->setDefaultSuffix(".arehab");
			if (fileDialog->exec())
			{
				QString arehabFileMetadataURL = fileDialog->selectedFiles().first();
				if (arehabFileMetadataURL != "")
				{
					QFile metadataFile(arehabFileMetadataURL);
					if (!metadataFile.open(QIODevice::WriteOnly)) {
						qWarning() << "Error abriendo el fichero para guardar." << endl;
						return;
					}
					this->arehabFileMetadata.arehabFileURL = QUrl::fromLocalFile(arehabFileMetadataURL).toLocalFile();
					ui.txARehabFile->setText(QUrl::fromLocalFile(arehabFileMetadataURL).toLocalFile());

					this->validateARehabFileURL();
				}
			}
		}
	}
Beispiel #2
0
bool SphinxControl::initializeRecognition(const QString &modelPath)
{
  kDebug() << "Initializing to " << modelPath << m_lastModel;
  if (modelPath != m_lastModel) { //already initialized / tried to initialize with this exact model
    m_lastModel = modelPath;
    kDebug() << "Initializing";
    uninitialize();
    m_startRequests = 0;

    QString path = KStandardDirs::locateLocal("tmp", "/simond/"+username+"/sphinx/");
    if(!QDir(path).entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst).isEmpty())
    {
      kDebug() << "Removing old data from working dir";
      FileUtils::removeDirRecursive(path);
      path = KStandardDirs::locateLocal("tmp", "/simond/"+username+"/sphinx/");
    }

    kDebug() << "Unpacking model to working dir";
    if (!FileUtils::unpackAll(modelPath, path))
    {
      return false;
    }

    QFile metadataFile(path+QLatin1String("metadata.xml"));
    if(!metadataFile.open(QIODevice::ReadOnly))
    {
      emit recognitionError(i18n("Failed to read metadata from \"%1\"", path+QLatin1String("metadata.xml")),
                            getBuildLog());
      return NULL;
    }
    ModelMetadata metadata;
    QDomDocument DomDocument;
    DomDocument.setContent(&metadataFile);
    metadata.deserializeXml(DomDocument.documentElement());

    metadataFile.close();

    modelName = metadata.name();
  }
  kDebug() << "Emitting recognition ready";
  emit recognitionReady();
  return true;
}
//*************************************************************************************************
//! Initializes the support data member with metadata file info. Returns TRUE if successful
//*************************************************************************************************
bool rspfQuickbirdRpcModel::parseMetaData(const rspfFilename& base_name)
{

   rspfFilename metadataFile (base_name);
   metadataFile.setExtension("IMD");
   if (!findSupportFile(metadataFile))
      return false;

   if ( !theSupportData.valid() )
      theSupportData = new rspfQuickbirdMetaData();

   if(!theSupportData->open(metadataFile))
   {
      theSupportData = 0; // rspfRefPtr
      rspfNotify(rspfNotifyLevel_WARN) << "rspfQuickbirdRpcModel::parseNitfFile WARNING:"
         << "\nCould not open IMD file.  Sensor ID unknown." << std::endl;
      return false;
   }

   theSensorID = theSupportData->getSatID();
   return true;
}
Beispiel #4
0
bool WriteMetadataFile(TraceMetadata* inMetadata, const std::string& inMetadataFilepath, std::string& outMetadataXML)
{
    bool bWriteSuccessful = false;

    gtString fullMetadataFilepathAsGTString;
    fullMetadataFilepathAsGTString.fromASCIIString(inMetadataFilepath.c_str());

    osFile metadataFile(fullMetadataFilepathAsGTString);
    bool bMetadataFileOpened = metadataFile.open(osChannel::OS_ASCII_TEXT_CHANNEL, osFile::OS_OPEN_TO_WRITE);

    if (bMetadataFileOpened)
    {
        // Write the metadata xml into the output file.
        gtASCIIString metadataXMLString;
        inMetadata->WriteToXML(metadataXMLString);

        // Now, just for fun, convert the gtASCIIString to a gtString.
        gtString metadataXMLAsGTString;
        metadataXMLAsGTString.fromASCIIString(metadataXMLString.asCharArray());

        // Write the metadata XML into the file, and close.
        metadataFile.writeString(metadataXMLAsGTString);
        metadataFile.close();

        // The client will receive the full metadata XML string to parse.
        outMetadataXML.assign(metadataXMLString.asCharArray());

        Log(logMESSAGE, "Wrote XML metadata file to '%s'.\n", inMetadataFilepath.c_str());

        bWriteSuccessful = true;
    }
    else
    {
        Log(logERROR, "Failed to open trace metadata file for writing: '%s'\n", inMetadataFilepath.c_str());
    }

    return bWriteSuccessful;
}
//--------------------------------------------------------------------------
/// Write a trace's metadata file and return the contenst through the out-param.
/// \param inFullResponseString The full response string for a collected linked trace request.
/// \param outMetadataXML The XML metadata string to return to the client.
/// \returns True if writing the metadata file was successful.
//--------------------------------------------------------------------------
bool MultithreadedTraceAnalyzerLayer::WriteTraceAndMetadataFiles(const std::stringstream& inFullResponseString, std::string& outMetadataXML)
{
    bool bWrittenSuccessfully = false;

    // Empty out the incoming path to the metadata file. We'll know the exact path later.
    outMetadataXML.assign("");

    osModuleArchitecture moduleArchitecture;
    osRuntimePlatform currentPlatform;
    gtString executablePath;
    gtString commandLine;
    gtString workingDirectory;

    // Retrieve the name of the instrumented application. Construct a metadata filename which references it.
    if (osGetProcessLaunchInfo(osGetCurrentProcessId(), moduleArchitecture, currentPlatform, executablePath, commandLine, workingDirectory) == true)
    {
        osFilePath executableFilepath;
        executableFilepath.setFullPathFromString(executablePath);

        gtString appName;
        if (executableFilepath.getFileName(appName) == true)
        {
            osTime currentTime;
            currentTime.setFromCurrentTime();
            tm timeStruct;
            currentTime.timeAsTmStruct(timeStruct, osTime::LOCAL);

            // Need to add 1900, since tm contains "years since 1900".
            int year = timeStruct.tm_year + 1900;

            // Need to add 1, since tm contains "months since January".
            int month = timeStruct.tm_mon + 1;
            int day = timeStruct.tm_mday;

            int hour = timeStruct.tm_hour;
            int minute = timeStruct.tm_min;
            int second = timeStruct.tm_sec;

            gtASCIIString metadataFilename;

            // ExecutableFilename-YEAR-MM-DD-HOUR-MINUTE-SECOND
            metadataFilename.appendFormattedString("description-%s-%d-%d-%d-%d-%d-%d.xml",
                appName.asASCIICharArray(),
                year, month, day,
                hour, minute, second);

            // Build a path to the GPS folder within the Temp directory.
            osFilePath systemTempDirectory;
            systemTempDirectory.setPath(osFilePath::OS_TEMP_DIRECTORY);


            gtString toolDirectory;
#ifdef CODEXL_GRAPHICS
            toolDirectory.fromASCIIString("CodeXL");
#else
            toolDirectory.fromASCIIString(GetPerfStudioDirName());
#endif
            // @TODO: Construct a path from the temp + tool directory.
            systemTempDirectory.appendSubDirectory(toolDirectory);

            gtList<osFilePath> toolDirectoryPaths;
            osDirectory d;
            d.setDirectoryPath(systemTempDirectory);

            // @TODO: Find a better way to create the "Session" directory. We shouldn't need to search through existing session directories.
            int maxSessionIndex = 0;
            bool bGotSubDirectories = d.getSubDirectoriesPaths(osDirectory::SORT_BY_NAME_DESCENDING, toolDirectoryPaths);
            if (bGotSubDirectories)
            {
                // Step through each directory, and look for "Session" folders.
                gtList<osFilePath>::iterator subdirectoryIter;
                for (subdirectoryIter = toolDirectoryPaths.begin(); subdirectoryIter != toolDirectoryPaths.end(); ++subdirectoryIter)
                {
                    gtString subdirString;
                    osFilePath subdir = *subdirectoryIter;
                    subdir.getFileName(subdirString);

                    if (subdir.isDirectory() && subdirString.startsWith(L"Session"))
                    {
                        // Remove the "Session" part of the string. We're only interested in the number at the end.
                        subdirString.replace(L"Session", L"", true);

                        const char* sessionIndexAsString = subdirString.asASCIICharArray();
                        int thisSessionId = atoi(sessionIndexAsString);

                        if (thisSessionId > maxSessionIndex)
                        {
                            maxSessionIndex = thisSessionId;
                        }
                    }

                }
            }


            gtASCIIString pathToDataDirectory = systemTempDirectory.asString().asASCIICharArray();

            // Metadata files will be saved to the temp directory with the following filename scheme:
            // "%TEMP%/ToolDirectory/Session[Index]/ApplicationBinaryName/Frame[Index]/description.xml"

            int frameIndex = GetInterceptor()->GetParentLayerManager()->GetFrameCount();

            // Generate a "Session" folder with a number at the end. Compute the correct number by looking at the
            // Session folders that already exist
            gtASCIIString sessionString;
            sessionString.appendFormattedString("Session%d", maxSessionIndex + 1);

            pathToDataDirectory.appendFormattedString("\\%s\\%s\\Frame%d\\", sessionString.asCharArray(), appName.asASCIICharArray(), frameIndex);

            // Create the data directory if it doesn't already exist.
            gtString fullPathToDataDirectoryAsGTString;
            fullPathToDataDirectoryAsGTString.fromASCIIString(pathToDataDirectory.asCharArray());

            osDirectory dir;
            dir.setDirectoryFullPathFromString(fullPathToDataDirectoryAsGTString);
            if (!dir.exists())
            {
                bool bDirectoryCreated = dir.create();
                if (!bDirectoryCreated)
                {
                    Log(logERROR, "Failed to create data directory for traced frame: '%s'.\n", fullPathToDataDirectoryAsGTString.asASCIICharArray());
                }
            }

            gtASCIIString pathToMetadataFile = pathToDataDirectory;
            pathToMetadataFile.appendFormattedString("%s", metadataFilename.asCharArray());

            gtString fullMetadataFilepathAsGTString;
            fullMetadataFilepathAsGTString.fromASCIIString(pathToMetadataFile.asCharArray());

            osFile metadataFile(fullMetadataFilepathAsGTString);
            bool bMetadataFileOpened = metadataFile.open(osChannel::OS_ASCII_TEXT_CHANNEL, osFile::OS_OPEN_TO_WRITE);

            // If we've successfully opened the metadata file, we'll also attempt to write the trace file.
            if (bMetadataFileOpened)
            {
                osFilePath traceFileDirectory;
                traceFileDirectory.setPath(osFilePath::OS_TEMP_DIRECTORY);

                traceFileDirectory.appendSubDirectory(toolDirectory);

                // Construct a filename for the cached trace response.
                gtASCIIString fullTraceFilename;
                fullTraceFilename.appendFormattedString("LinkedTrace-%s-%d-%d-%d-%d-%d-%d.ltr", appName.asASCIICharArray(), year, month, day, hour, minute, second);

                gtASCIIString fullTraceFilePath = pathToDataDirectory;
                fullTraceFilePath.appendFormattedString("%s", fullTraceFilename.asCharArray());

                gtString fullTraceResponseFilepathGTString;
                fullTraceResponseFilepathGTString.fromASCIIString(fullTraceFilePath.asCharArray());

                // Write the contents of the trace response file.
                osFile traceResponseFile(fullTraceResponseFilepathGTString);
                bool bTraceResponseFileOpened = traceResponseFile.open(osChannel::OS_ASCII_TEXT_CHANNEL, osFile::OS_OPEN_TO_WRITE);
                if (bTraceResponseFileOpened)
                {
                    // Dump the response into an ASCII string.
                    std::string responseAsString = inFullResponseString.str();

                    // Now put the ASCII string into a gtString so we can write it to the open file.
                    gtString gtStringResponse;
                    std::wstring wideString;
                    wideString.assign(responseAsString.begin(), responseAsString.end());
                    gtStringResponse.appendFormattedString(L"%s", wideString.c_str());
                    traceResponseFile.writeString(gtStringResponse);
                    traceResponseFile.close();
                }
                else
                {
                    Log(logERROR, "Failed to write trace response to file: '%s'\n", fullTraceResponseFilepathGTString.asASCIICharArray());
                }

                // Write the filename for the associated trace response that was just collected.
                std::string traceFilepathAsString;
                traceFilepathAsString.assign(fullTraceResponseFilepathGTString.asASCIICharArray());

                TraceMetadata metadata;

                // Insert the location of the metadata file being written out.
                metadata.mMetadataFilepath = pathToMetadataFile.asCharArray();

                // Insert the path to the cached trace file.
                metadata.mPathToTraceFile = fullTraceFilePath.asCharArray();

                // @TODO: When we have a framebuffer image system working, assign the path-to-image here.
                metadata.mPathToFrameBufferImage = "UNKNOWNPATH";

                ModernAPILayerManager* layerManager = GetInterceptor()->GetParentLayerManager();

                FrameInfo frameInfo;

                layerManager->GetFrameInfo(frameInfo);

                // Populate the metadata structure with the values stored in the LayerManager.
                metadata.mFrameInfo = frameInfo;
                metadata.mFrameIndex = frameIndex;
                metadata.mArchitecture = moduleArchitecture;

                // Write the metadata xml into the output file.
                gtASCIIString metadataXMLString;
                metadata.WriteToXML(metadataXMLString);
                gtString metadataXMLAsGTString;
                metadataXMLAsGTString.fromASCIIString(metadataXMLString.asCharArray());

                // Write the metadata XML into the file, and close.
                metadataFile.writeString(metadataXMLAsGTString);
                metadataFile.close();

                // The client will receive the full metadata XML string to parse.
                outMetadataXML.assign(metadataXMLString.asCharArray());

                bWrittenSuccessfully = true;
            }
            else
            {
                Log(logERROR, "Failed to open trace metadata file for writing: '%s'\n", metadataFilename);
            }
        }
        else
        {
            Log(logERROR, "Failed to retrieve the instrumented process's application filename.\n");
        }
    }
    else
    {
        Log(logERROR, "Failed to retrieve process launch info for target application.\n");
    }

    return bWrittenSuccessfully;
}
Beispiel #6
0
bool Deck::importMnemosyne(QString fileName)
{
    QFileInfo fi(fileName);
    QString baseName = fi.baseName().toLower();

    QString tempFolder = utils::combinePaths(tempPath(), baseName);
    QString metadataPath = utils::combinePaths(tempFolder, "METADATA"); 
    QString cardsPath = utils::combinePaths(tempFolder, "cards.xml"); 

    utils::createDirectory(tempFolder);

    Compressor c;
    if(!c.decompressFolder(fileName, tempFolder)) {
        return false;
    }

    /// import metadata
    ///
    QTextStream s;
    QFile metadataFile(metadataPath);

    metadataFile.open(QIODevice::ReadOnly | QIODevice::Text);

    if(!metadataFile.isOpen())
        return false;

    s.setDevice(&metadataFile);
    s.setCodec("UTF-8");

    QStringList sl;
    QString l = s.readLine();
    while (!s.atEnd()) {
        sl = l.split(":");

        if(sl.size()>1) {
            if(sl[0]=="tags")
                setTags(sl[1]);
            else if(sl[0]=="notes")
                setDesc(sl[1]);
            else if(sl[0]=="author_name")
                setAuthor(sl[1]);
            else if(sl[0]=="card_set_name")
                setName(sl[1]);
        }

        l = s.readLine();
    }

    /// read cards
    QDomDocument domDocument;
    QString errorStr;
    int errorLine;
    int errorColumn;
    QString front, back, level;
    QFile cardsFile(cardsPath);

    cardsFile.open(QIODevice::ReadOnly | QIODevice::Text);

    if(!cardsFile.isOpen())
        return false;

    if (!domDocument.setContent(&cardsFile, true, &errorStr, &errorLine,
        &errorColumn)) {
            qDebug() << QString("Parse error at line %1, column %2:\n%3")
                .arg(errorLine)
                .arg(errorColumn)
                .arg(errorStr);
            return false;
    }

    QDomElement root = domDocument.documentElement();
    QString rootName = root.tagName().toLower();

    if (rootName == "opensm2sync") {
        QDomNodeList nodes = root.elementsByTagName("log");
        QDomNode node;
        QDomElement elnode;
        
        int count = nodes.count();

        for(int no = 0; no < count; no++) {
            node = nodes.at(no);

            if(node.attributes().namedItem("type").nodeValue()=="16") {
                elnode = node.firstChildElement("f");
                front = elnode.text();

                elnode = node.firstChildElement("b");
                back = elnode.text();

                if(!front.isEmpty()) {
                    Card *card = new Card();

                    card->updateFront(front);
                    card->updateBack(back);

                    addCard(card);
                }
            }
        }
    }

    metadataFile.close();
    cardsFile.close();

    utils::removeFile(metadataPath);
    utils::removeFile(cardsPath);
    utils::copyDirectory(getDeckPath(), tempFolder);

    return true;
}
ControllerMetadata loadControllerMetadata(string path, string packageName, bool formatName) {
	string line;
	string key;
	string value;
	ControllerMetadata result;

	if (formatName)
		result.name = cleanUpPackageName(packageName);
	else
		result.name = packageName;
	result.description = string("No description");
	result.version = string("Unknown version");
	result.author = string("Unknown author");
	result.startScriptPath = path + "/start.ops";
    result.stopScriptPath = path + "/stop.ops";
	result.guiLibPath = path + "/lib/libcontroller_gui.so";
	result.guiDescriptionPath = path + "/controller_gui.glade";
    result.guiConfigPath = path + "/gui_config.yaml";
	result.guiTabWidgetName = string("controller_tab");
	result.loadSuccessful = false;

	ifstream metadataFile((path + "/controller.txt").c_str(), ios::in);
	if (metadataFile.is_open()) {
		while (metadataFile.good()) {
			getline(metadataFile, line);
			key = getKey(line);
			trim(key);
			toLowercase(&key);
			if (key == "name") {
				value = getValue(line);
				trim(value);
				result.name = value;
			} else if (key == "description") {
				value = getValue(line);
				trim(value);
				result.description = value;
			} else if (key == "version") {
				value = getValue(line);
				trim(value);
				result.version = value;
			} else if (key == "author") {
				value = getValue(line);
				trim(value);
				result.author = value;
			} else if (key == "startscriptpath") {
				value = getValue(line);
				trim(value);
				result.startScriptPath = value;
            } else if (key == "stopscriptpath") {
                value = getValue(line);
                trim(value);
                result.stopScriptPath = value;
			} else if (key == "guilibpath") {
				value = getValue(line);
				trim(value);
				result.guiLibPath = value;
			} else if (key == "guitabwidgetname") {
				value = getValue(line);
				trim(value);
				result.guiTabWidgetName = value;
			} else if (key == "guidescriptionpath") {
				value = getValue(line);
				trim(value);
				result.guiDescriptionPath = value;
			}
		}
		metadataFile.close();
		result.loadSuccessful = true;
	}
	return result;
}
int main(int argc, char* argv[])
{
  OpenAB::OpenAB_init();
  OpenAB::Logger::OutLevel() = OpenAB::Logger::Debug;

  std::map<std::string, std::string> availablePlugins = OpenAB::PluginManager::getInstance().PluginManager::getListOfPlugins();
  std::string pluginsDescription = "Available plugins: ";
  std::map<std::string, std::string>::const_iterator it;
  for (it = availablePlugins.begin(); it != availablePlugins.end();++it)
  {
    pluginsDescription += (*it).first + " ";
  }


  const char* syncType = NULL;

  const char* localPlugin = NULL;
  const char* remotePlugin = NULL;

  const char* localParams = NULL;
  const char* remoteParams = NULL;

  poptContext optCon;
  struct poptOption optionsTable[] = {
    {"syncType", ' ', POPT_ARG_STRING, &syncType, ' ', "Available Synchronization type: OneWay or TwoWay", "Type of synchronization to be performed"},
    {"localPlugin", ' ', POPT_ARG_STRING, &localPlugin, ' ', pluginsDescription.c_str(), "Name of plugin to be used for local storage"},
    {"remotePlugin", ' ', POPT_ARG_STRING, &remotePlugin, ' ', pluginsDescription.c_str(), "Name of plugin to be used for remote source/storage"},
    {"localParams", ' ', POPT_ARG_STRING, &localParams, ' ', "Please refer to OpenAB plugins documentation for parameters specific to given plugin", "JSON encoded parameters for local plugin"},
    {"remoteParams", ' ', POPT_ARG_STRING, &remoteParams, ' ', "Please refer to OpenAB plugins documentation for parameters specific to given plugin", "JSON encoded parameters for remote plugin"},
    POPT_AUTOHELP
    POPT_TABLEEND
  };
  optCon = poptGetContext(NULL, argc, (const char **) argv, optionsTable, 0);

  char opt;
  while ((opt = (char)poptGetNextOpt(optCon)) >= 0)
  {

  }

  poptFreeContext(optCon);

  if (syncType == NULL || localPlugin == NULL || remotePlugin == NULL || localParams == NULL || remoteParams == NULL)
  {
    LOG_ERROR()<<"Please provide all required parameters"<<std::endl;
    return 1;
  }

  OpenAB_Sync::Parameters params;
  params.setValue("remote_plugin", remotePlugin);
  if (!params.remoteSourcePluginParams.fromJSON(remoteParams))
  {
    LOG_ERROR()<<"Cannot parse remote plugin parameters: "<<remoteParams<<std::endl;
    return 1;
  }
  params.remoteStoragePluginParams = params.remoteSourcePluginParams;

  params.setValue("local_plugin", localPlugin);
  if (!params.localSourcePluginParams.fromJSON(localParams))
  {
   LOG_ERROR()<<"Cannot parse local plugin parameters: "<<localParams<<std::endl;
   return 1;
  }
  params.localStoragePluginParams = params.localSourcePluginParams;

  params.setValue("callback", &cb);

  std::string metadata;
  std::string line;
  std::ifstream metadataFile (".metadata");
  if (metadataFile.is_open())
  {
    while (std::getline(metadataFile, line))
    {
      metadata += line;
    }

    metadataFile.close();
    unlink(".metadata");
    params.setValue("metadata", metadata);
  }

  OpenAB_Sync::Sync* s = OpenAB::PluginManager::getInstance().getPluginInstance<OpenAB_Sync::Sync>(syncType, params);

  if (NULL == s)
  {
    LOG_ERROR()<<"Cannot initialize synchronization plugin"<<std::endl;
    return 1;
  }

  std::vector<std::string> ignore;
  s->addPhase("empty", ignore);

  if ( s->eInitOk != s->init() )
  {
    LOG_ERROR()<<"Initialization failed"<<std::endl;
    OpenAB::PluginManager::getInstance().freePluginInstance(s);
    return 1;
  }
  s->synchronize();

   /* while(std::getline(std::cin, line) && !finished)
    {
      if(line.compare("p") == 0)
      {
        s->suspend();
        printf("Suspend\n");
      }
      if(line.compare("r") == 0)
      {
        s->resume();
        printf("Resume\n");
      }
      if(line.compare("c") == 0)
      {
        s->cancel();
        printf("Cancel\n");
      }
      if(line.compare("e") == 0)
      {

        break;
      }
    }*/
    while(!finished)
         usleep(100000);

    unsigned int lAdd, lMod, lRem, rAdd, rMod, rRem;
    s->getStats(lAdd, lMod, lRem, rAdd, rMod, rRem);
    LOG_DEBUG()<<"Synchronization statistics:"<<std::endl;
    LOG_DEBUG()<<"Locally added items: "<<lAdd<<std::endl;
    LOG_DEBUG()<<"Locally modified items: "<<lMod<<std::endl;
    LOG_DEBUG()<<"Locally removed items: "<<lRem<<std::endl;
    LOG_DEBUG()<<std::endl;
    LOG_DEBUG()<<"Remotely added items: "<<rAdd<<std::endl;
    LOG_DEBUG()<<"Remotely modified items: "<<rMod<<std::endl;
    LOG_DEBUG()<<"Remotely removed items: "<<rRem<<std::endl;

    OpenAB::PluginManager::getInstance().freePluginInstance(s);

}
 void metadataUpdated(const std::string& metadata)
 {
   std::ofstream metadataFile (".metadata");
   metadataFile<<metadata;
   metadataFile.close();
 }
LLGAnalysis::LLGAnalysis( char *configFileName ) {
    
    
    // Setup the default values for the cuts:
    JET_PT_CUT_SV = 30;
    JET_PT_CUT_PV = 75;
    JET_ETA_CUT = 5.0;
    LEADING_SV_JET_CUT = 10000.;
    MJJ_CUT = 10000;
    MUON_PT_CUT = 15.;
    ELECTRON_PT_CUT = 15.;
    MET_CUT = 210.;
    PROC_XSEC = 1.;
    PROC_NTOT = 1.;
    applyEventWeights = false;
    TARGET_LUMI = 1000.;
    //SELECTION = "SignalRegion";
    SELECTION = "TTJetsCR";
    metadataFileName = "Configuration/DatasetMetadata.txt";
    datasetName = "Signal_500_60";
    _writeOutputTree = true;

    ifstream configFile( configFileName, ios::in );
    while( configFile.good() ) {
        string key, value;
        configFile >> key >> ws >> value;
        if( configFile.eof() ) break;
        if( key == "InputFile"         ) _inputFileNames.push_back( value ); 
        if( key == "InputTree"         ) _inputTreeName = value; 
        if( key == "JET_PT_CUT_SV"     ) JET_PT_CUT_SV = atof(value.c_str());
        if( key == "JET_PT_CUT_PV"     ) JET_PT_CUT_PV = atof(value.c_str());
        if( key == "JET_ETA_CUT"       ) JET_ETA_CUT = atof(value.c_str());
        if( key == "MUON_PT_CUT"       ) MUON_PT_CUT = atof(value.c_str()); 
        if( key == "ELECTRON_PT_CUT"   ) ELECTRON_PT_CUT = atof(value.c_str()); 
        if( key == "MET_CUT"           ) MET_CUT = atof(value.c_str()); 
        //if( key == "PROC_XSEC"         ) PROC_XSEC = atof(value.c_str());
        //if( key == "PROC_NTOT"         ) PROC_NTOT = atof(value.c_str());
        if( key == "TARGET_LUMI"       ) TARGET_LUMI = atof(value.c_str());
        if( key == "ApplyEventWeights" ) applyEventWeights = ( atoi(value.c_str()) == 1 );
        if( key == "Selection"         ) SELECTION = value;
        if( key == "MetadataFileName"  ) metadataFileName = value;
        if( key == "DatasetName"       ) datasetName = value;
        if( key == "WriteOutputTree"   ) _writeOutputTree = (bool)(atoi(value.c_str()));
        if( key == "LEADING_SV_JET_CUT" ) LEADING_SV_JET_CUT = atof(value.c_str());
        if( key == "MJJ_CUT"           ) MJJ_CUT = atof(value.c_str());
    }
    outputHistos = datasetName + "_histos.root";
    //_outputHistos = datasetName + "_histos.root";
    _outputFileName = datasetName + "_tree.root";
    _outputFile = new TFile( _outputFileName.c_str(), "RECREATE" );
    _outputTree = new TTree( _inputTreeName.c_str(), _inputTreeName.c_str() );

    bool foundMetadata = false;
    ifstream metadataFile( metadataFileName.c_str(), ios::in );
    while( metadataFile.good() ) {
      string name, xs, ntot;
      metadataFile >> name >> ws >> xs >> ws >> ntot;
      if( metadataFile.eof() ) break;
      if( name == datasetName ) {
        PROC_XSEC = atof( xs.c_str() );
        PROC_NTOT = atof( ntot.c_str() );
        foundMetadata = true;
        break;
      }
    }
    if( !foundMetadata ) {
      cout << "Did not find dataset " << datasetName << " in " << metadataFileName << ". Using standard values for xsec and ntot: " << PROC_XSEC << " " << PROC_NTOT << endl;
    }
    evtWeight = applyEventWeights ? PROC_XSEC/PROC_NTOT * TARGET_LUMI : 1.;
    std::cout << "evtWeight is " << evtWeight << std::endl;
}
//--------------------------------------------------------------------------
/// Write a trace's metadata file and return the contenst through the out-param.
/// \param inHeaderString The full response string for a collected linked trace request.
/// \param inResponseString Response string
/// \param outMetadataXML The XML metadata string to return to the client.
/// \returns True if writing the metadata file was succesful.
//--------------------------------------------------------------------------
bool MultithreadedTraceAnalyzerLayer::WriteTraceAndMetadataFiles(const gtASCIIString& inHeaderString, const gtASCIIString& inResponseString, std::string& outMetadataXML)
{
    bool bWrittenSuccessfully = false;

    // Empty out the incoming path to the metadata file. We'll know the exact path later.
    outMetadataXML.assign("");

    // Use this object to pass data into and out of the GetSessionManagaerData() method.
    SessionManagerData smd;

    smd.frameIndex = GetParentLayerManager()->GetFrameCount();

    bool result = SessionManager::Instance()->GetSessionManagerData(smd);

    if (result == false)
    {
        return result;
    }

    gtASCIIString pathToMetadataFile = smd.pathToDataDirectory; //pathToDataDirectory;
    pathToMetadataFile.appendFormattedString("%s", smd.metadataFilename.asCharArray());

    gtString fullMetadataFilepathAsGTString;
    fullMetadataFilepathAsGTString.fromASCIIString(pathToMetadataFile.asCharArray());

    osFile metadataFile(fullMetadataFilepathAsGTString);
    bool bMetadataFileOpened = metadataFile.open(osChannel::OS_ASCII_TEXT_CHANNEL, osFile::OS_OPEN_TO_WRITE);

    // If we've successfully opened the metadata file, we'll also attempt to write the trace file.
    if (bMetadataFileOpened == false)
    {
        Log(logERROR, "Failed to open trace metadata file for writing: '%s'\n", smd.metadataFilename.asCharArray());
        return false;
    }

    osFilePath traceFileDirectory;
    traceFileDirectory.setPath(osFilePath::OS_TEMP_DIRECTORY);

    traceFileDirectory.appendSubDirectory(smd.toolDirectory);

    // Construct a filename for the cached trace response.
    gtASCIIString fullTraceFilename;
    fullTraceFilename.appendFormattedString("LinkedTrace-%s-%d-%d-%d-%d-%d-%d.ltr", smd.appName.asASCIICharArray(), smd.year, smd.month, smd.day, smd.hour, smd.minute, smd.second);

    gtASCIIString fullTraceFilePath = smd.pathToDataDirectory;
    fullTraceFilePath.appendFormattedString("%s", fullTraceFilename.asCharArray());

    gtString fullTraceResponseFilepathGTString;
    fullTraceResponseFilepathGTString.fromASCIIString(fullTraceFilePath.asCharArray());

    // Write the contents of the trace response file.
    osFile traceResponseFile(fullTraceResponseFilepathGTString);
    bool bTraceResponseFileOpened = traceResponseFile.open(osChannel::OS_ASCII_TEXT_CHANNEL, osFile::OS_OPEN_TO_WRITE);

    if (bTraceResponseFileOpened)
    {
        traceResponseFile.writeString(inHeaderString);
        traceResponseFile.writeString(inResponseString);
        traceResponseFile.close();
    }
    else
    {
        Log(logERROR, "Failed to write trace response to file: '%s'\n", fullTraceResponseFilepathGTString.asASCIICharArray());
    }

    // Write the filename for the associated trace response that was just collected.
    std::string traceFilepathAsString;
    traceFilepathAsString.assign(fullTraceResponseFilepathGTString.asASCIICharArray());

    TraceMetadata metadataToWrite;

    // Insert the location of the metadata file being written out.
    metadataToWrite.mMetadataFilepath = pathToMetadataFile.asCharArray();

    // Insert the path to the cached trace file.
    metadataToWrite.mPathToTraceFile = fullTraceFilePath.asCharArray();

    // Write object files info. It is currently assumed trace and object data will exists simultaneously.
    metadataToWrite.mPathToObjectTreeFile = smd.pathToDataDirectory.asCharArray();
    metadataToWrite.mPathToObjectTreeFile.append("ObjectTree.xml");

    metadataToWrite.mPathToObjectDatabaseFile = smd.pathToDataDirectory.asCharArray();
    metadataToWrite.mPathToObjectDatabaseFile.append("FullObjectDatabase.xml");

    ModernAPIFrameDebuggerLayer* frameDebugger = GetParentLayerManager()->GetFrameDebuggerLayer();

    unsigned char* pngData = NULL;
    unsigned int numBytes = 0;

    // NOTE: Passing in 0 for the width and height will cause the renderer to render the PNG image at the same resolution as the applications frame buffer (i.e full resolution).
    bool bCapturedSuccessfully = frameDebugger->CaptureFrameBuffer(0, 0, &pngData, &numBytes, true);

    if (bCapturedSuccessfully)
    {
        gtASCIIString fullImageFilename;
        fullImageFilename.appendFormattedString("%s_FrameBuffer%d.png", smd.appName.asASCIICharArray(), smd.frameIndex);

        gtASCIIString imageFilepath = smd.pathToDataDirectory;
        imageFilepath.appendFormattedString("%s", fullImageFilename.asCharArray());

        FILE* frameBufferImageFile = fopen(imageFilepath.asCharArray(), "wb");

        if (frameBufferImageFile != NULL)
        {
            fwrite(pngData, sizeof(unsigned char), numBytes, frameBufferImageFile);
            fclose(frameBufferImageFile);

            // Add the captured image's path into the XML metadata.
            metadataToWrite.mPathToFrameBufferImage = imageFilepath.asCharArray();
        }
        else
        {
            Log(logERROR, "Failed to write frame buffer image file.\n");
        }

        SAFE_DELETE_ARRAY(pngData);
    }
    else
    {
        metadataToWrite.mPathToFrameBufferImage = "ERROR - Failed to capture frame buffer image.";
        Log(logERROR, "Failed to capture frame buffer for captured frame.\n");
    }

    // @TODO: This is placeholder for now to get a prototype working.
    // We should also be able to set this to "Capture".
    metadataToWrite.mTraceType = kTraceType_Linked;

    // @TODO: This is temporary until TraceMetadata generation is moved to the LayerManager.
    FrameInfo frameInfo;
    frameDebugger->GetFrameInfo(&frameInfo);

    // Populate the metadata structure with the values stored in the LayerManager.
    metadataToWrite.mFrameInfo = &frameInfo;
    metadataToWrite.mArchitecture = smd.moduleArchitecture;
    metadataToWrite.mAPICallCount = GetNumTracedAPICalls();
    metadataToWrite.mDrawCallCount = GetNumTracedDrawCalls();

    bool bMetadataWriteSuccessful = WriteMetadataFile(&metadataToWrite, pathToMetadataFile.asCharArray(), outMetadataXML);

    if (bMetadataWriteSuccessful)
    {
        bWrittenSuccessfully = true;
    }

    return bWrittenSuccessfully;
}