CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Attributes

L1GtVhdlTemplateFile Class Reference

#include <L1GtVhdlTemplateFile.h>

List of all members.

Public Member Functions

void append (const std::string &str)
 adds a line at the end of the the file with the content of str
void append (const L1GtVhdlTemplateFile &file)
 adds the content of file at the end of (*this); the parameter map won't be changed
bool close ()
bool extractParametersFromString (const std::string &str, std::vector< std::string > &parameters)
void getConditionsFromAlgo (std::string condString, std::vector< std::string > &result)
 extracts all conditions from a algorithm
std::string getInternalParameter (const std::string &indentifier)
 returns a parameter of a internal template file
std::vector< std::string > getSubstitutionParametersFromTemplate ()
 returns a vector with all substitution parameters that are found in the template file
bool insert (const std::string &atLine, std::vector< std::string > content)
 replaces the whole line containing atLine and inserts content instead of it
bool insert (const std::string atLine, L1GtVhdlTemplateFile file)
 replaces the whole line containing atLine with the content of file
bool isBlank (const char &chr)
 checks weather a char is a blank
 L1GtVhdlTemplateFile (const std::string &filename)
 constructor with filename
 L1GtVhdlTemplateFile ()
 standard constructor
 L1GtVhdlTemplateFile (const L1GtVhdlTemplateFile &rhs)
 copy constructor
std::string lines2String ()
 returns a string with the content of vector lines
bool open (const std::string &fileName, bool internal=false)
 opens a template file. If the header information shall be parsed intern has to be set to true
void print ()
 prints the content of the VHDL File (only lines_)
void printParameterMap ()
 prints the parameter map
bool removeEmptyLines ()
 deletes all empty lines in a template file
bool removeLineWithContent (const std::string &str)
 removes all lines that contain the str
std::vector< std::string > returnLines ()
 returns a string vector with the current content of the VHDL File
std::map< std::string,
std::string > 
returnParameterMap ()
 returns parameter map
bool save (const std::string &fileName)
 saves the content of the template file to a local file (the content of parameterMap_ will not be saved!)
bool split (const std::string &param, std::vector< std::string > &result)
 seperates a string at all blanks and saves the elements in result
bool substitute (const std::string &searchString, const std::string &replaceString)
 replaces searchString with replaceString
 ~L1GtVhdlTemplateFile ()
 destructor

Static Public Member Functions

static const bool findAndReplaceString (std::string &paramString, const std::string &searchString, const std::string &replaceString)
 replaces searchString with replaceString at it's first occurance in string

Private Attributes

bool intern_
std::vector< std::string > lines_
 containing the content of the VHDL file
std::map< std::string,
std::string > 
parameterMap_
 containing the header information of internal files

Detailed Description

The routines of this class provide all necessary features to deal with the VHDL templates for the firmware code of the GT

Implementation: <TODO: enter implementation details>

Author:
Philipp Wagner

$Date$ $Revision$

Description: a class to deal with VHDL template files

Implementation: <TODO: enter implementation details>

Author:
: Philipp Wagner

$Date$ $Revision$

Definition at line 27 of file L1GtVhdlTemplateFile.h.


Constructor & Destructor Documentation

L1GtVhdlTemplateFile::L1GtVhdlTemplateFile ( )

standard constructor

Definition at line 31 of file L1GtVhdlTemplateFile.cc.

References intern_.

{
    intern_=false;
}
L1GtVhdlTemplateFile::L1GtVhdlTemplateFile ( const std::string &  filename)

constructor with filename

Definition at line 38 of file L1GtVhdlTemplateFile.cc.

References gather_cfg::cout, and open().

{
    if (!open(filename,false)) std::cout<<"Error while opening file: "<<filename<<std::endl;
}
L1GtVhdlTemplateFile::L1GtVhdlTemplateFile ( const L1GtVhdlTemplateFile rhs)

copy constructor

Definition at line 45 of file L1GtVhdlTemplateFile.cc.

References intern_, lines_, and parameterMap_.

L1GtVhdlTemplateFile::~L1GtVhdlTemplateFile ( )

destructor

Definition at line 55 of file L1GtVhdlTemplateFile.cc.

{
    // empty
}

Member Function Documentation

void L1GtVhdlTemplateFile::append ( const std::string &  str)

adds a line at the end of the the file with the content of str

Definition at line 342 of file L1GtVhdlTemplateFile.cc.

References lines_.

Referenced by L1GtVhdlWriterCore::buildDefValuesBuffer(), L1GtVhdlWriterCore::getCondChipVhdContentFromTriggerMenu(), and L1GtVhdlWriterCore::writeMuonSetupVhdl().

{
    lines_.push_back(str);
}
void L1GtVhdlTemplateFile::append ( const L1GtVhdlTemplateFile file)

adds the content of file at the end of (*this); the parameter map won't be changed

Definition at line 348 of file L1GtVhdlTemplateFile.cc.

References i, and lines_.

{
    for (unsigned int i=0; i<file.lines_.size(); i++)
    {
        lines_.push_back(file.lines_.at(i));
    }
}
bool L1GtVhdlTemplateFile::close ( void  )

Definition at line 249 of file L1GtVhdlTemplateFile.cc.

{
    //empty
    return true;
}
bool L1GtVhdlTemplateFile::extractParametersFromString ( const std::string &  str,
std::vector< std::string > &  parameters 
)

finds all substitution parameters in str and collects them in the vector parameters. This routine is used by getSubstitutionParametersFromTemplate();

Definition at line 294 of file L1GtVhdlTemplateFile.cc.

References Parameters::parameters.

Referenced by getSubstitutionParametersFromTemplate().

{
    // check, weather the current line is containing a substitution parameter
    // the routine is making sure, that it's not extracting a parameter from
    // a comment
    if (int pos1=str.find("$(")!=std::string::npos && str.substr(0,2)!="--")
    {
        int pos2=str.find(")");
        // get the substituion parameter
        std::string tempStr=(str.substr(pos1+1,(pos2-pos1-1)));
        // return a pair with the substitution parameter and the
        // the rest of the string after the substitution parameter

        // here a should be checked, weather the vector is already containing
        // the parameter befor adding it.

        parameters.push_back(tempStr);
        //recursive call
        while (extractParametersFromString(str.substr(pos2), parameters)) extractParametersFromString(str.substr(pos2), parameters);

        return true;
    }
    else
    {
        return false;
    }
    
    return true;
}
const bool L1GtVhdlTemplateFile::findAndReplaceString ( std::string &  paramString,
const std::string &  searchString,
const std::string &  replaceString 
) [static]
void L1GtVhdlTemplateFile::getConditionsFromAlgo ( std::string  condString,
std::vector< std::string > &  result 
)

extracts all conditions from a algorithm

Definition at line 427 of file L1GtVhdlTemplateFile.cc.

References findAndReplaceString(), i, findQualityFiles::size, and split().

Referenced by L1GtVhdlWriterCore::processAlgorithmMap().

{
    std::vector<std::string> operators;

    operators.push_back("AND");
    operators.push_back("OR");
    operators.push_back("NOT");
    operators.push_back("(");
    operators.push_back(")");

    for (unsigned int i =0; i<operators.size(); i++)
    {
        while (findAndReplaceString(condString, operators.at(i), "")) findAndReplaceString(condString, operators.at(i), "");
    }

    split(condString,result);

}
std::string L1GtVhdlTemplateFile::getInternalParameter ( const std::string &  indentifier)

returns a parameter of a internal template file

Definition at line 463 of file L1GtVhdlTemplateFile.cc.

References parameterMap_.

Referenced by L1GtVhdlWriterCore::buildDefValuesBuffer(), L1GtVhdlWriterCore::getCondChipVhdContentFromTriggerMenu(), and L1GtVhdlWriterCore::writeDefValPkg().

{
    return parameterMap_[indentifier];
}
std::vector< std::string > L1GtVhdlTemplateFile::getSubstitutionParametersFromTemplate ( )

returns a vector with all substitution parameters that are found in the template file

Definition at line 325 of file L1GtVhdlTemplateFile.cc.

References extractParametersFromString(), lines_, and groupFilesInBlocks::temp.

Referenced by L1GtVhdlWriterCore::writeMuonSetupVhdl().

{
    std::vector<std::string> temp;
    std::vector<std::string>::iterator iter = lines_.begin();

    // loop until the substitution parameter is discovered the first time
    while( iter != lines_.end() )
    {
        extractParametersFromString((*iter), temp);
        iter++;
    }

    return temp;

}
bool L1GtVhdlTemplateFile::insert ( const std::string &  atLine,
std::vector< std::string >  content 
)

replaces the whole line containing atLine and inserts content instead of it

Definition at line 212 of file L1GtVhdlTemplateFile.cc.

References lines_, and summarizeEdmComparisonLogfiles::success.

Referenced by L1GtVhdlWriterCore::buildCommonHeader(), insert(), L1GtVhdlWriterCore::openVhdlFileWithCommonHeader(), L1GtVhdlWriterCore::writeCondChipPkg(), L1GtVhdlWriterCore::writeConditionChipSetup(), L1GtVhdlWriterCore::writeDefValPkg(), and L1GtVhdlWriterCore::writeMuonSetupVhdl().

{
    bool success = false;
    std::vector<std::string>::iterator iter = lines_.begin();

    //Loop until the substitution parameter is discovered the first time
    while( iter != lines_.end() )
    {
        //check, weather the current line is containing the substitution parameter
        if ((*iter).find(atLine)!=std::string::npos)
        {
            //Delete the line with the subsitution parameter
            iter = lines_.erase(iter);
            //insert the content of file
            lines_.insert(iter,content.begin(),content.end());

            success=true;
            break;
        }

        iter++;
    }

    return success;
}
bool L1GtVhdlTemplateFile::insert ( const std::string  atLine,
L1GtVhdlTemplateFile  file 
)

replaces the whole line containing atLine with the content of file

Definition at line 239 of file L1GtVhdlTemplateFile.cc.

References insert(), returnLines(), and groupFilesInBlocks::temp.

{
    std::vector<std::string> temp = file.returnLines();

    if (insert(atLine,temp)) return true;

    return false;
}
bool L1GtVhdlTemplateFile::isBlank ( const char &  chr)

checks weather a char is a blank

Definition at line 391 of file L1GtVhdlTemplateFile.cc.

Referenced by split().

{
    if (chr==' ') return true;
    return false;

}
std::string L1GtVhdlTemplateFile::lines2String ( )

returns a string with the content of vector lines

Definition at line 447 of file L1GtVhdlTemplateFile.cc.

References lines_.

{
    std::vector<std::string>::iterator iter = lines_.begin();
    std::ostringstream buffer;

    while( iter != lines_.end() )
    {
        buffer<<(*iter)<<std::endl;
        iter++;

    }

    return buffer.str();
}
bool L1GtVhdlTemplateFile::open ( const std::string &  fileName,
bool  internal = false 
)

opens a template file. If the header information shall be parsed intern has to be set to true

Definition at line 71 of file L1GtVhdlTemplateFile.cc.

References recoMuon::in, analyzePatCleaning_cfg::inputFile, lines_, and parameterMap_.

Referenced by L1GtVhdlWriterCore::buildCommonHeader(), L1GtVhdlWriterCore::buildDefValuesBuffer(), L1GtVhdlWriterCore::getCondChipVhdContentFromTriggerMenu(), L1GtVhdlTemplateFile(), L1GtVhdlWriterCore::writeDefValPkg(), L1GtVhdlWriterCore::writeMuonSetupVhdl(), and L1GtVhdlWriterCore::writeQsfSetupFiles().

{

    const char paramIndicator='#';
    const char commentIndicator='%';
    char buffer[2000];
    std::string stringBuffer;

    std::fstream inputFile(fileName.c_str(),std::ios::in);
    //check weather file has been opened successfully
    if(!inputFile.is_open()) return false;

    //store content of the template in Vector lines
    while(!inputFile.eof())
    {
        inputFile.getline(buffer,2000);
        stringBuffer=buffer;
        //Remove DOS seperators (For example if the template file was created under NT)
        if (stringBuffer[stringBuffer.length()-1]==13)
        {
            stringBuffer.replace(stringBuffer.length()-1,1,"");
        }
        //the current buffer + a seperator to the vector lines
        lines_.push_back(stringBuffer/*+"\n"*/);
    }

    inputFile.close();

    if (internal)
    {
        
        //Delete lines containing parameters after moving them to parameterMap_
        std::vector<std::string>::iterator iter = lines_.begin();
        while( iter != lines_.end() )
        {
            while ((*iter)[0]==commentIndicator && (*iter)[1]==commentIndicator)
                lines_.erase(iter);
            
            if ((*iter)[0]==paramIndicator)
            {
                std::vector<std::string>::iterator iter2 = iter;
                
                // get the first line of content
                iter2++;
                
                while (iter2!=lines_.end())
                {
                    if ((*iter2)[0]==paramIndicator && (*iter2)[1]==paramIndicator)
                    {
                        iter2++;
                        break;
                    }
                    
                   
                    
                    parameterMap_[(*iter).substr(1)]+=(*iter2);
                    
                    // overtake the newlines
                    std::vector<std::string>::iterator tmpIter= iter2;
                    tmpIter++;
                   
                    // check weather the next line is the end of the block
                    if (!((*tmpIter)[0]==paramIndicator && (*tmpIter)[1]==paramIndicator))
                        parameterMap_[(*iter).substr(1)]+="\n";
                    
                   
                    iter2++;
                }
                
                // there has been a syntax error in the internal template
                // stop the routine
                if (iter2==lines_.end()) 
                    return false;
 
                // deletes the content, thas has been added to parameter map before
                // (iter one at the moment is at the beginnig of the block, iter2 at its end)
                lines_.erase(iter,iter2 );
                
            }
            
            // just for security
            if (iter!=lines_.end()) iter++;
        }

        //remove empty lines
        iter = lines_.begin();
        while( iter != lines_.end() )
        {
            if ((*iter)=="" || (*iter).length()==0 || (*iter)=="    ") lines_.erase(iter); else
                iter++;
        }

    }

    return true;

}
void L1GtVhdlTemplateFile::print ( void  )

prints the content of the VHDL File (only lines_)

Definition at line 256 of file L1GtVhdlTemplateFile.cc.

References gather_cfg::cout, and lines_.

Referenced by L1GtVhdlWriterCore::printCommonHeader().

{
    std::vector<std::string>::iterator iter = lines_.begin();
    while( iter != lines_.end())
    {
        std::cout<<*iter<<std::endl;
        iter++;
    }

}
void L1GtVhdlTemplateFile::printParameterMap ( )

prints the parameter map

Definition at line 274 of file L1GtVhdlTemplateFile.cc.

References gather_cfg::cout, and parameterMap_.

{
    std::cout<<"Enter parametermap"<<std::endl;

    std::map<std::string,std::string>::iterator iter =  parameterMap_.begin();

    while( iter != parameterMap_.end())
    {
        std::cout<<(*iter).first<<": "<<(*iter).second<<std::endl;
        iter++;;
    }
}
bool L1GtVhdlTemplateFile::removeEmptyLines ( )

deletes all empty lines in a template file

Definition at line 377 of file L1GtVhdlTemplateFile.cc.

References lines_.

Referenced by L1GtVhdlWriterCore::getCondChipVhdContentFromTriggerMenu(), and L1GtVmeWriterCore::writeVME().

{
    std::vector<std::string>::iterator iter = lines_.begin();

    while( iter != lines_.end() )
    {
        if ((*iter)=="" || (*iter).length()==0 || (*iter)=="    ") lines_.erase(iter); else
            iter++;
    }

    return true;
}
bool L1GtVhdlTemplateFile::removeLineWithContent ( const std::string &  str)

removes all lines that contain the str

Definition at line 357 of file L1GtVhdlTemplateFile.cc.

References lines_, position, and summarizeEdmComparisonLogfiles::success.

Referenced by L1GtVhdlWriterCore::writeMuonSetupVhdl().

{
    bool success = false;

    std::vector<std::string>::iterator iter = lines_.begin();
    while( iter != lines_.end())
    {
        size_t position;
        position = (*iter).find(str);

        if (position != std::string::npos)
        {
            lines_.erase(iter);
            success=true;
        } else iter++;
    }
    return success;
}
std::vector< std::string > L1GtVhdlTemplateFile::returnLines ( )

returns a string vector with the current content of the VHDL File

Definition at line 268 of file L1GtVhdlTemplateFile.cc.

References lines_.

Referenced by insert(), and L1GtVmeWriterCore::writeVME().

{
    return lines_;
}
std::map< std::string, std::string > L1GtVhdlTemplateFile::returnParameterMap ( )
bool L1GtVhdlTemplateFile::save ( const std::string &  fileName)

saves the content of the template file to a local file (the content of parameterMap_ will not be saved!)

Definition at line 170 of file L1GtVhdlTemplateFile.cc.

References lines_, and download_sqlite_cfg::outputFile.

Referenced by L1GtVhdlWriterCore::writeAlgoSetup(), L1GtVhdlWriterCore::writeCondChipPkg(), L1GtVhdlWriterCore::writeConditionChipSetup(), L1GtVhdlWriterCore::writeDefValPkg(), L1GtVhdlWriterCore::writeEtmSetup(), L1GtVhdlWriterCore::writeMuonSetupVhdl(), and L1GtVhdlWriterCore::writeQsfSetupFiles().

{
    std::ofstream outputFile(fileName.c_str());
    std::vector<std::string>::iterator iter = lines_.begin();

    //Write content of lines_ into the outputfile.
    while( iter != lines_.end() )
    {
        //std::cout<<"Last sign: "<<*iter[(*iter).length()-3];
        outputFile << *iter<<std::endl;
        iter++;
    }

    outputFile.close();
   
    return true;

}
bool L1GtVhdlTemplateFile::split ( const std::string &  param,
std::vector< std::string > &  result 
)

seperates a string at all blanks and saves the elements in result

Definition at line 399 of file L1GtVhdlTemplateFile.cc.

References i, isBlank(), pos, query::result, and groupFilesInBlocks::temp.

Referenced by getConditionsFromAlgo().

{
    unsigned int i = 0;
    while (isBlank(param[i]))
    {
        i++;
    }

    std::string temp = param.substr(i);
    std::size_t pos = temp.find(" ");

    if (pos != std::string::npos)
    {
        std::string temp2 = temp.substr(0, pos);
        result.push_back(temp2);
        while (split(temp.substr(pos),result)) split(temp.substr(pos),result);

    } else if (!isBlank(temp[pos+1]))
    {
        result.push_back(temp);
        return false;
    } else
    return false;

    return false;
}
bool L1GtVhdlTemplateFile::substitute ( const std::string &  searchString,
const std::string &  replaceString 
)

replaces searchString with replaceString

Definition at line 190 of file L1GtVhdlTemplateFile.cc.

References findAndReplaceString(), lines_, and summarizeEdmComparisonLogfiles::success.

Referenced by L1GtVhdlWriterCore::buildCommonHeader(), L1GtVhdlWriterCore::buildDefValuesBuffer(), L1GtVhdlWriterCore::getCondChipVhdContentFromTriggerMenu(), L1GtVhdlWriterCore::openVhdlFileWithCommonHeader(), L1GtVhdlWriterCore::writeAlgoSetup(), L1GtVhdlWriterCore::writeCondChipPkg(), L1GtVhdlWriterCore::writeConditionChipSetup(), L1GtVhdlWriterCore::writeEtmSetup(), L1GtVhdlWriterCore::writeMuonSetupVhdl(), L1GtVhdlWriterCore::writeQsfSetupFiles(), and L1GtVmeWriterCore::writeVME().

{

    bool success = false;

    std::vector<std::string>::iterator iter = lines_.begin();
    while( iter != lines_.end())
    {
        //The substitution parameter always appears as follows: $(parameter)
        while (findAndReplaceString(*iter,("$("+searchString+")"), replaceString))
        {
            findAndReplaceString(*iter,("$("+searchString+")"), replaceString);
            success = true;
        }
        iter++;
    }

    return success;

}

Member Data Documentation

internal files additionally have entries in parameterMap_ for "normal" files parameterMap is empty

Definition at line 33 of file L1GtVhdlTemplateFile.h.

Referenced by L1GtVhdlTemplateFile().

std::vector<std::string> L1GtVhdlTemplateFile::lines_ [private]
std::map<std::string,std::string> L1GtVhdlTemplateFile::parameterMap_ [private]

containing the header information of internal files

Definition at line 37 of file L1GtVhdlTemplateFile.h.

Referenced by getInternalParameter(), L1GtVhdlTemplateFile(), open(), printParameterMap(), and returnParameterMap().