Example #1
0
TH1D* getSimplePlot(TString INPUTDIR_PREFIX, TString SCENARIO, TString dataMC, TString vartype, TString SCEN_TRIG, TString RR) {

   TString DENOM = "_Glb_pass_&_Tight2012_pass"; //"_&_Glb_pass_&_Tight2012_pass";
   if (SCENARIO == "Glb_Tight2012") DENOM = "";
   else if (SCENARIO == "Glb_Tight2012_IsolPFRelCombNoEGammaR03PU_"+SCEN_TRIG) DENOM = "_Glb_pass_&_IsolPFRelCombNoEGammaR03PU_pass_&_Tight2012_pass";
   else if (SCENARIO == "Glb_Tight2012_IsolPFRelCombNoEGammaR03_"+SCEN_TRIG) DENOM = "_Glb_pass_&_IsolPFRelCombNoEGammaR03_pass_&_Tight2012_pass";

   TString POSTFIX = "";
   if (vartype == "vtx") POSTFIX = ""; //"_vtx";
   else if (vartype == "run") POSTFIX = ""; //"_rrr";
   else if (vartype == "rrr2") POSTFIX = "_rrr2";
   else if (vartype == "rrr3") POSTFIX = "_rrr3";

   if (dataMC == "datalike_mc") {
     RR = "";
   } else {
     RR = "_"+RR;
   }
   TFile *thisf = new TFile(INPUTDIR_PREFIX+"TnP_2011_MuonID_item_"+dataMC+"_"+SCENARIO+POSTFIX+"_"+vartype+RR+".root");
   cout << "HERE " << INPUTDIR_PREFIX+"TnP_2011_MuonID_item_"+dataMC+"_"+SCENARIO+POSTFIX+"_"+vartype+RR+".root" << endl;
   thisf->cd();
   gDirectory->cd("tpTree/"+SCENARIO+"_"+vartype+"/fit_eff_plots");
   cout << "tpTree/"+SCENARIO+"_"+vartype+"/fit_eff_plots" << endl;

   TCanvas* c = (TCanvas*)gDirectory->Get(getFolder(vartype)+DENOM);
   cout << getFolder(vartype)+DENOM << endl;
   c->GetListOfPrimitives();
   RooHist* hpt = (RooHist*)c->GetPrimitive("hxy_fit_eff");

   TH1D* test = rooHist_to_TH1D(hpt,vartype,SCENARIO);
   for (int ibin = 0; ibin < test->GetXaxis()->GetNbins();ibin++) {
       cout << "AFTER " << test->GetBinContent(ibin+1) << endl;
    }
   return rooHist_to_TH1D(hpt,vartype,SCENARIO);
}
Example #2
0
 /**
 * Given a path and a folder Name
 * return file to write
 *
 */
 FILE *getFile(const char* path, const char* name, const char overwrite){
 	char year[5];
 	char month[3];
 	const char *pointer = name;

 	FILE *fp;
 	char *absoluteFileName, *newPath;

 	strncpy(year, pointer, 4); year[4] = '\0';
 	pointer = pointer + 4;
 	strncpy(month, pointer, 2); month[2] = '\0';

 	getFolder(path, year);
	newPath = malloc(strlen(path) + strlen(year) + 2);
	strcpy(newPath, path);
 	strcat(newPath, "/");
 	strcat(newPath, year);

 	getFolder(newPath, month);
	free(newPath);

 	absoluteFileName = malloc(strlen(path) + strlen(year) + strlen(month) + strlen(name) + strlen(FILE_SUFFIX_TYPE) + 4);
 	strcpy(absoluteFileName, path);
 	strcat(absoluteFileName, "/");
 	strcat(absoluteFileName, year);
 	strcat(absoluteFileName, "/");
 	strcat(absoluteFileName, month);
 	strcat(absoluteFileName, "/");
 	strcat(absoluteFileName, name);
 	strcat(absoluteFileName, FILE_SUFFIX_TYPE);

 	if (overwrite == 'R'){// it's not  overwrite

 		fp=fopen(absoluteFileName,"r");
		if (fp != NULL)
		{
			if (fclose(fp) < 0){
				fprintf(stderr, "%s: Couldn’t close file %s; %s\n", "getFile", absoluteFileName, strerror (errno));
				exit (EXIT_FAILURE);
			}
			return NULL; // it's not overwrite
		}
 	}
 	fp=fopen(absoluteFileName,"w");
		if (fp == NULL)
		{
			fprintf(stderr, "%s: Couldn’t open file %s; %s\n", "getFile", absoluteFileName, strerror (errno));
			exit (EXIT_FAILURE);
		}
		// write the header
		fputs(FILE_HEADER, fp);
		fputs("\n", fp);


 	free(absoluteFileName);
 	return fp;
 }
Example #3
0
LayerImage* Sprite::getBackgroundLayer() const
{
  if (getFolder()->getLayersCount() > 0) {
    Layer* bglayer = *getFolder()->getLayerBegin();

    if (bglayer->isBackground()) {
      ASSERT(bglayer->isImage());
      return static_cast<LayerImage*>(bglayer);
    }
  }
  return NULL;
}
Example #4
0
 /**
  * Create a anomalia file
  */
 void createErrorFile(const char* path, const char* name){
	 	char year[5];
	 	char month[3];
	 	const char *pointer = name;

	 	FILE *fp;
	 	char *absoluteFileName, *newPath;

	 	strncpy(year, pointer, 4); year[4] = '\0';
	 	pointer = pointer + 4;
	 	strncpy(month, pointer, 2); month[2] = '\0';

	 	getFolder(path, year);
		newPath = malloc(strlen(path) + strlen(year) + 2);
		strcpy(newPath, path);
	 	strcat(newPath, "/");
	 	strcat(newPath, year);

	 	getFolder(newPath, month);
		free(newPath);

	 	absoluteFileName = malloc(strlen(path) + strlen(year) + strlen(month) + strlen(name) + strlen(FILE_SUFFIX_TYPE) + 4);
	 	strcpy(absoluteFileName, path);
	 	strcat(absoluteFileName, "/");
	 	strcat(absoluteFileName, year);
	 	strcat(absoluteFileName, "/");
	 	strcat(absoluteFileName, month);
	 	strcat(absoluteFileName, "/");
	 	strcat(absoluteFileName, name);
	 	strcat(absoluteFileName, FILE_ERR_SUFFIX_TYPE);

	 	fp=fopen(absoluteFileName,"w");
			if (fp == NULL)
			{
				fprintf(stderr, "%s: Couldn’t open file %s; %s\n", "getFile", absoluteFileName, strerror (errno));
				exit (EXIT_FAILURE);
			}
			fputs("Error", fp);
			fputs("\n", fp);


	 	free(absoluteFileName);
	 	int err = fclose(fp);
	 	if (err < 0){
	 		fprintf(stderr, "%s: Couldn’t close file %s; %s\n", "getFile", absoluteFileName, strerror (errno));
	 		exit (EXIT_FAILURE);
	 	}
 }
int OpenMediaFolderDialog::exec() {
	getFolder();
	if (d->ui.folder->text().isEmpty())
		return Rejected;
	return QDialog::exec();

}
Example #6
0
unsigned long Folder::countRecursiveFiles() {
    createFolderItems();
    unsigned long count = fileCount();
    for (unsigned long i = 0; i < folderCount(); i++)
        count += getFolder(i).countRecursiveFiles();
    return count;
}
Example #7
0
PathButton::PathButton(QWidget *parent)
    : QPushButton(parent), d(new Data)
{
    QPushButton::setText(d->getText());

    connect(this, &QPushButton::clicked, this, [=] () {
        switch (d->mode) {
        case Folder: {
            const auto ret = getFolder();
            if (!ret.isEmpty()) {
                emit folderSelected(ret);
                if (d->editor)
                    d->prop.write(d->editor, ret);
            }
            break;
        } case SingleFile: {
            const auto ret = getFile();
            if (!ret.isEmpty()) {
                emit fileSelected(ret);
                if (d->editor)
                    d->prop.write(d->editor, ret);
            }
            break;
        } case MultiFile: {
            const auto ret = getFiles();
            if (!ret.isEmpty()) {
                emit filesSelected(ret);
                if (d->editor)
                    d->prop.write(d->editor, ret);
            }
        } default:
            break;
        }
    });
}
Example #8
0
void Sprite::render(Image* image, int x, int y, FrameNumber frame) const
{
  fill_rect(image, x, y, x+m_width-1, y+m_height-1,
            (m_format == IMAGE_INDEXED ? getTransparentColor(): 0));

  layer_render(getFolder(), image, x, y, frame);
}
terrama2::core::DataSetSeries terrama2::core::DataAccessorDcpToa5::getSeries(const std::string& uri,
        const terrama2::core::Filter& filter,
        terrama2::core::DataSetPtr dataSet) const

{
    std::string mask = getMask(dataSet);
    std::string folder = getFolder(dataSet);

    QTemporaryDir tempBaseDir;
    if(!tempBaseDir.isValid())
    {
        QString errMsg = QObject::tr("Can't create temporary folder.");
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    QDir tempDir(tempBaseDir.path());
    tempDir.mkdir(QString::fromStdString(folder));
    tempDir.cd(QString::fromStdString(folder));

    QUrl url((uri+"/"+folder+"/"+mask).c_str());
    QFileInfo originalInfo(url.path());

    QFile file(url.path());
    QFile tempFile(tempDir.path()+"/"+originalInfo.fileName());
    if(!file.open(QIODevice::ReadOnly))
    {
        QString errMsg = QObject::tr("Can't open file: dataset %1.").arg(dataSet->id);
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    if(!tempFile.open(QIODevice::ReadWrite))
    {
        QString errMsg = QObject::tr("Can't open temporary file: dataset %1.").arg(dataSet->id);
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    file.readLine();//ignore first line
    tempFile.write(file.readLine()); //headers line

    //ignore third and fourth lines
    file.readLine();
    file.readLine();

    //read all file
    tempFile.write(file.readAll()); //headers line

    //update file path
    std::string tempUri = "file://"+tempBaseDir.path().toStdString();

    file.close();
    tempFile.close();

    auto dataSeries = terrama2::core::DataAccessorFile::getSeries(tempUri, filter, dataSet);

    return dataSeries;
}
//virtual
void LLPlacesFolderBridge::performAction(LLInventoryModel* model, std::string action)
{
	if ("expand" == action)
	{
		LLFolderViewFolder* act_folder = getFolder();
		act_folder->toggleOpen();
	}
	else if ("collapse" == action)
	{
		LLFolderViewFolder* act_folder = getFolder();
		act_folder->toggleOpen();
	}
	else
	{
		LLFolderBridge::performAction(model, action);
	}
}
Example #11
0
QString SystemSong::getPath(SongKind kind) const{
    if (id() == -1)
        return "";

    QString folder = getFolder(kind, m_isBR);

    return Common::pathCombine(folder, name());
}
Example #12
0
void SessionMgr::saveSession(QString name)
{
    QDir dir(getFolder());
    if(!dir.exists())
        dir.mkpath(dir.absolutePath());

    if(m_sessions.contains(name))
        removeSession(name);

    QByteArray data;
    DataFileParser parser(&data, QIODevice::WriteOnly, getFolder(), name);

    sWorkTabMgr.saveData(&parser);

    parser.close();

    DataFileBuilder::writeWithHeader(getFolder() + name + ".cldta", data, true, DATAFILE_SESSION);
}
Example #13
0
File& Folder::getRecursiveFile(unsigned long i) {
    createFolderItems();
    orAssert(i < countRecursiveFiles());
    if (i < fileCount()) {
        return getFile(i);
    } else {
        unsigned long count = fileCount();
        for (unsigned long n = 0; n < folderCount(); n++) {
            if ((i - count) < getFolder(n).countRecursiveFiles()) {
                return getFolder(n).getRecursiveFile(i - count);
            }
            count += getFolder(n).countRecursiveFiles();
        }
    }

    orAssert(false);
    return files.at(0);
}
Example #14
0
std::string Folder::getRecursiveFileName(unsigned long i) {
    createFolderItems();
    orAssert(i < countRecursiveFiles());
    if (i < fileCount()) {
        return getFile(i).getName();
    } else {
        unsigned long count = fileCount();
        for (unsigned long n = 0; n < folderCount(); n++) {
            if ((i - count) < getFolder(n).countRecursiveFiles()) {
                return getFolder(n).getName() + '/'
                       + getFolder(n).getRecursiveFileName(i - count);
            }
            count += getFolder(n).countRecursiveFiles();
        }
    }

    orAssert(false);
    return "";
}
Example #15
0
		std::wstring getFileName(std::wstring pathname, std::wstring filename) {
			if (file_.empty()) {
				std::wstring path = getFolder() + _T("\\") + pathname;
				if (!directoryExists(path)) {
					if (_wmkdir(path.c_str()) != 0)
						return _T("");
				}
				file_ = path + _T("\\") + filename;
			}
			return file_;
		}
    //-------------------------------------------------------------------------
    //! @brief Factory method to create a SimpleValue model and assign it to
    //! retrieve the path to the next photo to display.
    //! @returns a shared pointer to the SimpleValue.
    //-------------------------------------------------------------------------
    static std::shared_ptr< IModel > const createPhotoFolder()
    {
        auto photo_mgr = Factory< IPhotoManager >::get( "PhotoManager" );

        std::function< variant() > method( [photo_mgr](){ return photo_mgr->getFolder(); } );

        std::shared_ptr< IModel > model( new SimpleValue( String( "" )
                                                        , method
                                                        , photo_mgr->getSignal()
                                                        , std::static_pointer_cast< ITech >( photo_mgr ) ) );

        return model;
    }
Example #17
0
Tree putSubFolder(Tree folder, Tree path, Tree item) 
{
	if (isNil(path)) {
        //return putFolder(folder, item);
        return addToFolder(folder, item);
	} else {
		Tree subfolder = getFolder(folder, hd(path));
		if (isUiFolder(subfolder)) {
			return putFolder(folder, putSubFolder(subfolder, tl(path), item));
		} else {
			return putFolder(folder, makeSubFolderChain(path, item));
		}
	}
}
Example #18
0
	std::string expand_path(std::string file) {
		std::string::size_type pos = file.find('$');
		while (pos != std::string::npos) {
			std::string::size_type pstart = file.find('{', pos);
			std::string::size_type pend = file.find('}', pstart);
			std::string key = file.substr(pstart + 1, pend - 2);

			std::string tmp = file;
			strEx::replace(file, "${" + key + "}", getFolder(key));
			if (file == tmp)
				pos = file.find_first_of('$', pos + 1);
			else
				pos = file.find_first_of('$');
		}
		return file;
	}
Example #19
0
void SessionMgr::loadSession(QString name)
{
    bool closeOther = name.isNull();
    if(closeOther)
        name = tr("[Last session]");

    if(!name.contains("cldta"))
        name.append(".cldta");

    QByteArray data = openSessionFile(name);
    if(data.isEmpty())
        return;

    DataFileParser parser(&data, QIODevice::ReadOnly, getFolder());
    sWorkTabMgr.loadData(&parser, closeOther);
}
Example #20
0
void SessionMgr::removeSession(QString name)
{
    if(!name.contains("cldta"))
        name.append(".cldta");

    QString folder = getFolder();
    QFile::remove(folder + name);

    // Remove attachment files
    int at = 0;
    name.remove(".cldta");
    name = QString("%1_%2_at%3.cldta").arg(folder).arg(name);
    while(QFile::remove(name.arg(at)))
        ++at;

    updateSessions();
}
Example #21
0
void DataLocalMessage::exportXML(shared_ptr<XMLPortalExporter> exporter, const String &subject, const String &body, bool secure)
{
	shared_ptr<XMLNode> node = exporter->getRoot();

	node->setAttributeString(_S("subject"), subject);
	node->setAttributeString(_S("body"), body);
	node->setAttributeBool(_S("secure"), secure);

	node->setAttributeString(DBTABLES::LOCAL_MESSAGES::ID, id.toXML());
	node->setAttributeDateTime(DBTABLES::LOCAL_MESSAGES::SUBMIT_DATE, submit_date);
	node->setAttributeDateTime(DBTABLES::LOCAL_MESSAGES::READ_DATE, read_date);
	node->setAttributeString(DBTABLES::LOCAL_MESSAGES::FOLDER, toString(getFolder()));
	node->setAttributeString(DBTABLES::LOCAL_MESSAGES::STATUS, toString(getStatus()));
	node->setAttributeString(_S("href"), exporter->getPortal()->getPrivateMessageLink(id, true));

	shared_ptr<ObjectsUser> user = objects_user_cast(exporter->getPage()->getObject(author));
	if(user != nullptr)
		user->exportXML(exporter->createChild<XMLPortalExporter>(exporter->createNode(DBTABLES::AUTHOR)));	
}
Example #22
0
void Tulpa::loadByName(std::string name, bool load_sessions)
{
    this->name = name;
    local_file = std::string(TULPA_FOLDER) + this->name + std::string(".json");
    checkFolder(getFolder(local_file));

    this->name[0] = toupper(this->name[0]);

    unsigned int i=0;

    if(!checkFile(local_file))
    {
        root["personality_traits"] = Json::arrayValue;
        root["name"] = this->name;
        root["birth_time"] = (int)time(NULL);
        root["first_word_time"] = 0;

        saveJSONFile(root,local_file.c_str());
    }

    root = loadJSONFile(local_file.c_str());

    personality_traits.clear();

    while(root["personality_traits"][i] != Json::nullValue)
    {
        addPersonalityTrait(root["personality_traits"][i].asString());
        i++;
    }

    if(load_sessions)
    {
        i=0;
        while(root["session_id"][i] != Json::nullValue)
        {
            loadSession(root["session_id"][i].asInt());
            i++;
        }
    }

    birth_time = root["birth_time"].asString();
    first_word_time = root["first_word_time"].asString();
}
Example #23
0
void StyleNode::init()
{
    // Initialize children
    QDomElement e = elem.firstChildElement();
    while ( !e.isNull() )
    {
        children.append(new StyleNode(this, e));
        e = e.nextSiblingElement();
    }

    // Initialize prototypes
    if ( elem.hasAttribute("prototypes") )
    {
        QStringList proto = elem.attribute("prototypes", QString()).split(',');
        for (int i = 0; i < proto.size(); ++i)
        {
            prototypes.append(new StyleNode(this, proto[i], getFolder()));
        }
    }
}
bool HelloWorld::convert(string filePath)
{
    if (filePath =="")
        return false;
    
    size_t pos = filePath.find("file://");
    if (pos != string::npos){
        filePath = filePath.substr (pos+7);
    }
    
    Magick::Image masterImage(filePath);
    
    if (!masterImage.isValid()){
        return false;
    }
    
    showPreview(masterImage);
    
    
    string saveFolder = getFolder(filePath) + "/IconResized/" ;
    makeDirectory(saveFolder);
    
    string openDir;
    
    typedef map<string, string>::iterator it_type;
    for(it_type iterator = sizes.begin(); iterator != sizes.end(); iterator++) {
        // iterator->first = key
        // iterator->second = value
        // Repeat if you also want to iterate through the second map.
        string savePath = saveFolder + iterator->second;
        
        openDir = savePath;
        resizeAndWriteImage(masterImage, savePath, iterator->first);
    }
    
    openSavedFolder(openDir);
    
    return true;
}
Example #25
0
void SessionMgr::updateSessions()
{
    QDir dir(getFolder());
    m_sessions = dir.entryList((QStringList() << "[^_]*.cldta"), (QDir::Files | QDir::Readable), QDir::Name);

    for(std::set<QMenu*>::iterator itr = m_menus.begin(); itr != m_menus.end(); ++itr)
    {
        QMenu *menu = *itr;

        QAction *separator = NULL;
        QList<QAction*> actions = menu->actions();
        for(int i = 0; i < actions.size(); ++i)
        {
            if(actions[i]->isSeparator())
            {
                separator = actions[i];
                break;
            }
            delete actions[i];
        }

        if(m_sessions.empty())
        {
            QAction *empty = new QAction(tr("No saved sessions"), this);
            menu->insertAction(separator, empty);
            empty->setEnabled(false);
        }
        else
        {
            for(int i = 0; i < m_sessions.size(); ++i)
            {
                QAction *act = new QAction(m_sessions[i].remove(".cldta"), this);
                menu->insertAction(separator, act);
                m_sig_map->setMapping(act, act->text());
                connect(act, SIGNAL(triggered()), m_sig_map, SLOT(map()));
            }
        }
    }
}
Example #26
0
Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits (ProjectType::Target::Type forTarget) const
{
    Array<File> files;
    getFolder().findChildFiles (files, File::findFiles, false);

    FileSorter sorter;
    files.sort (sorter);

    Array<LibraryModule::CompileUnit> units;

    for (auto& file : files)
    {
        if (file.getFileName().startsWithIgnoreCase (getID())
              && file.hasFileExtension (sourceFileExtensions))
        {
            if (forTarget == ProjectType::Target::unspecified
             || forTarget == Project::getTargetTypeFromFilePath (file, true))
            {
                CompileUnit cu;
                cu.file = file;
                units.add (cu);
            }
        }
    }

    for (auto& cu : units)
    {
        cu.isCompiledForObjC = true;
        cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m");

        if (cu.isCompiledForNonObjC)
            if (files.contains (cu.file.withFileExtension ("mm")))
                cu.isCompiledForObjC = false;

        jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
    }

    return units;
}
Example #27
0
Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits() const
{
    Array<File> files;
    getFolder().findChildFiles (files, File::findFiles, false);

    FileSorter sorter;
    files.sort (sorter);

    Array<LibraryModule::CompileUnit> units;

    for (int i = 0; i < files.size(); ++i)
    {
        CompileUnit cu;
        cu.file = files.getReference(i);

        if (cu.file.getFileName().startsWithIgnoreCase (getID())
              && cu.file.hasFileExtension (sourceFileExtensions))
        {
            units.add (cu);
        }
    }

    for (int i = 0; i < units.size(); ++i)
    {
        CompileUnit& cu = units.getReference(i);

        cu.isCompiledForObjC = true;
        cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m");

        if (cu.isCompiledForNonObjC)
            if (files.contains (cu.file.withFileExtension ("mm")))
                cu.isCompiledForObjC = false;

        jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
    }

    return units;
}
Example #28
0
QByteArray SessionMgr::openSessionFile(const QString& name)
{
    QFile file(getFolder() + name);
    if(!file.open(QIODevice::ReadOnly))
        return QByteArray();

    QByteArray data;
    QByteArray str = file.read(4);
    file.seek(0);

    if(str == QByteArray::fromRawData("LDTA", 4))
    {
        try {
            data = DataFileBuilder::readAndCheck(file, DATAFILE_SESSION);
        }
        catch(const QString& ex) {
            Utils::showErrorBox(tr("Error loading session file: %1").arg(ex));
            return data;
        }
    }
    // Legacy
    else
    {
        QByteArray magic = file.read(sizeof(CLDTA_DATA_MAGIC));
        if(magic.size() != sizeof(CLDTA_DATA_MAGIC))
            return QByteArray();

        for(quint8 i = 0; i < sizeof(CLDTA_DATA_MAGIC); ++i)
            if(magic[i] != CLDTA_DATA_MAGIC[i])
                return QByteArray();

        data = qUncompress(file.readAll());
    }

    return data;
}
Example #29
0
void MediaStorageDlg::slotSetUserLogFolder()
{
    ui.usertextEdit->setText(getFolder());
}
Example #30
0
void MediaStorageDlg::slotSetChanLogFolder()
{
    ui.chanlogEdit->setText(getFolder());
}