TimingSimulationStructures.cpp

Go to the documentation of this file.
00001 //Copyright GSI 2012
00002 #include <fesa-core/Utilities/StringUtilities.h>
00003 #include <fesa-core-gsi/Exception/GSIException.h>
00004 #include <fesa-core-gsi/RealTime/TimingSimulationStructures.h>
00005 
00006 namespace fesaGSI
00007 {
00008         EventConfig::EventConfig(fesa::ElementXML* config)
00009         {
00010         type_ = Event;
00011 
00012         if(config->attributeList_.size() < 2)//payload is a "may"
00013                 {
00014                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00015                 }
00016 
00017                 std::vector<fesa::AttributeXML*>::iterator attributeIter;
00018                 for(attributeIter = config->attributeList_.begin();attributeIter != config->attributeList_.end();attributeIter++)
00019                 {
00020                         if((*attributeIter)->name_ == "eventname")
00021                         {
00022                                 eventName_ =  (*attributeIter)->value_;
00023                         }
00024                         else if((*attributeIter)->name_ == "delay")
00025                         {
00026                                 fesa::StringUtilities::fromString(delay_, (*attributeIter)->value_);
00027                         }
00028                         else if((*attributeIter)->name_ == "payload")
00029                         {
00030                                 payload_ =  (*attributeIter)->value_;
00031                         }
00032                         else
00033                         {
00034                                 //dont throw error, since TimingSimulationEventBurstElement inherits from us
00035                         }
00036                 }
00037         }
00038 
00039         EventBurstConfig::EventBurstConfig(fesa::ElementXML* config) : EventConfig(config)
00040     {
00041         type_ = EventBurst;
00042         if(config->attributeList_.size() < 5)
00043                 {
00044                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00045                 }
00046 
00047                 std::vector<fesa::AttributeXML*>::iterator attributeIter;
00048                 for(attributeIter = config->attributeList_.begin();attributeIter != config->attributeList_.end();attributeIter++)
00049                 {
00050                         if((*attributeIter)->name_ == "period")
00051                         {
00052                                 fesa::StringUtilities::fromString(period_, (*attributeIter)->value_);
00053                                 if(period_ <= 0)
00054                                         throw GSIException(__FILE__,__LINE__,FESAGSIErrorWrongEventPeriod.c_str());
00055                         }
00056                         else if((*attributeIter)->name_ == "occurrences")
00057                         {
00058                                 fesa::StringUtilities::fromString(occurrences_, (*attributeIter)->value_);
00059                                 if(occurrences_ <= 0)
00060                                         throw GSIException(__FILE__,__LINE__,FESAGSIErrorWrongEventOcurrences.c_str());
00061                         }
00062                         else
00063                         {
00064                                 //dont throw error ... the baseclass attributes
00065                         }
00066                 }
00067     }
00068 
00069     EventSequenceConfig::EventSequenceConfig(fesa::ElementXML* config)
00070     {
00071         if(config->attributeList_.size() < 1)
00072                 {
00073                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00074                 }
00075 
00076                 std::vector<fesa::AttributeXML*>::iterator attributeIter;
00077                 for(attributeIter = config->attributeList_.begin();attributeIter != config->attributeList_.end();attributeIter++)
00078                 {
00079                         if((*attributeIter)->name_ == "name")
00080                         {
00081                                 name_ =(*attributeIter)->value_;
00082                         }
00083                         else
00084                         {
00085                                 throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00086                         }
00087                 }
00088 
00089                 std::vector<fesa::ElementXML*>::iterator childIter;
00090         for(childIter = config->childList_.begin();childIter != config->childList_.end();childIter++)
00091         {
00092                 EventConfig *temp;
00093                 if((*childIter)->name_ == "event")
00094                 {
00095                         temp = new EventConfig(*childIter);
00096                         events_.push_back(temp);
00097                 }
00098                 else if((*childIter)->name_ == "event-burst")
00099                 {
00100                         temp = new EventBurstConfig(*childIter);
00101                         events_.push_back(temp);
00102                 }
00103                 else
00104                 {
00105                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00106                 }
00107         }
00108     }
00109 
00110     EventSequenceConfig::~EventSequenceConfig()
00111     {
00112         std::vector<EventConfig*>::iterator iter;
00113         for(iter= events_.begin();iter!=events_.end();iter++)
00114         {
00115                 delete *iter;
00116         }
00117     }
00118 
00119     TelegramDataConfig::TelegramDataConfig(fesa::ElementXML* config)
00120     {
00121         //the defaults
00122         destination_ = spCon_ = "";
00123         particleType_ = -1;
00124 
00125                 std::vector<fesa::AttributeXML*>::iterator attributeIter;
00126                 for(attributeIter = config->attributeList_.begin();attributeIter != config->attributeList_.end();attributeIter++)
00127                 {
00128                         if((*attributeIter)->name_ == "DEST")
00129                         {
00130                                 destination_ = (*attributeIter)->value_;
00131                         }
00132                         else if((*attributeIter)->name_ == "PARTY")
00133                         {
00134                                 particleType_ = (*attributeIter)->value_;
00135                         }
00136                         else if((*attributeIter)->name_ == "SPCON")
00137                         {
00138                                 spCon_ = (*attributeIter)->value_;
00139                         }
00140                         else
00141                         {
00142                                 throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00143                         }
00144                 }
00145     }
00146 
00147     CycleConfig::CycleConfig(fesa::ElementXML* config,long cycleID)
00148     {
00149         cycleID_ = cycleID;
00150 
00151         if(config->attributeList_.size() < 3)
00152                 {
00153                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00154                 }
00155 
00156                 std::vector<fesa::AttributeXML*>::iterator attributeIter;
00157 
00158                 for(attributeIter = config->attributeList_.begin();attributeIter != config->attributeList_.end();attributeIter++)
00159                 {
00160                         if((*attributeIter)->name_ == "basic-period-multiple")
00161                         {
00162                                 fesa::StringUtilities::fromString(basicPeriodMultiple_, (*attributeIter)->value_);
00163                                 if(basicPeriodMultiple_ <= 0)
00164                                         throw GSIException(__FILE__,__LINE__,FESAGSIErrorWrongBasicPeriod.c_str());
00165                         }
00166                         else if((*attributeIter)->name_ == "event-sequence-name-ref")
00167                         {
00168                                 eventSequenceName_ = (*attributeIter)->value_;
00169                         }
00170                         else if((*attributeIter)->name_ == "name")
00171                         {
00172                                 cycleName_ = (*attributeIter)->value_;
00173                         }
00174                         else
00175                         {
00176                                 throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00177                         }
00178                 }
00179                 telegramData_ = NULL; //the default
00180                 std::vector<fesa::ElementXML*>::iterator childIter;
00181         for(childIter = config->childList_.begin();childIter != config->childList_.end();childIter++)
00182         {
00183                 if((*childIter)->name_ == "telegram-data")
00184                 {
00185                         telegramData_ = new TelegramDataConfig(*childIter);
00186                 }
00187         }
00188     }
00189 
00190     SuperCycleConfig::SuperCycleConfig()
00191     {
00192                 //The cycleID's start at 1
00193                 cycleIDCounter_ = 1;
00194     }
00195 
00196     void SuperCycleConfig::initialize(fesa::ElementXML* config)
00197     {
00198         if(config->attributeList_.size() < 1)
00199                 {
00200                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00201                 }
00202 
00203                 std::vector<fesa::AttributeXML*>::iterator attributeIter;
00204                 for(attributeIter = config->attributeList_.begin();attributeIter != config->attributeList_.end();attributeIter++)
00205                 {
00206                         if((*attributeIter)->name_ == "shift-delay")
00207                         {
00208                                 fesa::StringUtilities::fromString(shiftDelay_, (*attributeIter)->value_);
00209                                 if(shiftDelay_ < 0)
00210                                         throw GSIException(__FILE__,__LINE__,FESAGSIErrorWrongShiftDelay.c_str());
00211                         }
00212                         else
00213                         {
00214                                 throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00215                         }
00216                 }
00217 
00218                 std::vector<fesa::ElementXML*>::iterator childIter;
00219         for(childIter = config->childList_.begin();childIter != config->childList_.end();childIter++)
00220         {
00221                 if((*childIter)->name_ == "cycle")
00222                 {
00223                         cycleCol_.push_back(CycleConfig(*childIter,cycleIDCounter_));
00224                         cycleIDCounter_++;
00225                 }
00226         }
00227     }
00228 
00229     void SuperCycleConfig::linkEventSequences(std::vector<EventSequenceConfig*>& eventSequenceCol)
00230     {
00231         bool found = false;
00232         std::vector<CycleConfig>::iterator cycleIter;
00233         std::vector<EventSequenceConfig*>::iterator eventSeqIter;
00234         for(cycleIter= cycleCol_.begin();cycleIter!=cycleCol_.end();cycleIter++)
00235         {
00236                 found = false;
00237                 for(eventSeqIter=eventSequenceCol.begin();eventSeqIter!=eventSequenceCol.end();eventSeqIter++)
00238                 {
00239                         if(cycleIter->eventSequenceName_ == (*eventSeqIter)->name_)
00240                         {
00241                                 cycleIter->eventSequenceRef_ = *eventSeqIter;
00242                                 found = true;
00243                                 continue;//next cycle
00244                         }
00245                 }
00246                 if(!found)//if the EventSequence, used by this cycle cannot be located
00247                 {
00248                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00249                 }
00250         }
00251     }
00252 
00253     DomainConfig::DomainConfig(fesa::ElementXML* config)
00254     {
00255         if(config->attributeList_.size() < 2)
00256                 {
00257                         throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00258                 }
00259 
00260                 std::vector<fesa::AttributeXML*>::iterator attributeIter;
00261                 for(attributeIter = config->attributeList_.begin();attributeIter != config->attributeList_.end();attributeIter++)
00262                 {
00263                         if((*attributeIter)->name_ == "name")
00264                         {
00265                                 name_ =(*attributeIter)->value_;
00266                         }
00267                         if((*attributeIter)->name_ == "enable")
00268                         {
00269                                 fesa::StringUtilities::fromString(enable_, (*attributeIter)->value_);
00270                         }
00271                 }
00272 
00273                 std::vector<fesa::ElementXML*>::iterator childIter;
00274         for(childIter = config->childList_.begin();childIter != config->childList_.end();childIter++)
00275         {
00276                 if((*childIter)->name_ == "super-cycle")
00277                 {
00278                         superCycle_.initialize(*childIter);
00279                 }
00280                 if((*childIter)->name_ == "event-sequence")
00281                 {
00282                         eventSequenceCol_.push_back(new EventSequenceConfig(*childIter));
00283                 }
00284         }
00285         //links the cycles to concrete EventSequences
00286         superCycle_.linkEventSequences(eventSequenceCol_);
00287     }
00288 
00289     DomainConfig::~DomainConfig()
00290     {
00291         std::vector<EventSequenceConfig*>::iterator iter;
00292         for(iter= eventSequenceCol_.begin();iter!=eventSequenceCol_.end();iter++)
00293         {
00294                 delete *iter;
00295         }
00296     }
00297 
00298     TimingSimulationConfig::TimingSimulationConfig(const std::string& timingSimulationConfigFile)
00299     {
00300         timingSimulationConfigFile_ = timingSimulationConfigFile;
00301         fesa::XMLParser parser(timingSimulationConfigFile_,true);
00302 
00303         //get the Element-collection
00304         std::vector<fesa::ElementXML*>* pElCol = parser.extractElements("timing-simulation");
00305 
00306         if (pElCol == NULL)
00307         {
00308             throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00309         }
00310         if(pElCol->size() != 1)
00311         {
00312                 throw GSIException(__FILE__, __LINE__, FesaGSITimingSimulationFileCorrupt.c_str());
00313         }
00314 
00315         std::vector<fesa::ElementXML*>::iterator TSElement = pElCol->begin();
00316         std::vector<fesa::AttributeXML*>::iterator attributeIter;
00317         std::vector<fesa::ElementXML*>::iterator domainIter;
00318 
00319         //fill direct class attributes
00320         for(attributeIter = (*TSElement)->attributeList_.begin();attributeIter != (*TSElement)->attributeList_.end();attributeIter++)
00321         {
00322                 if((*attributeIter)->name_ == "basic-period-length")
00323                 {
00324                 fesa::StringUtilities::fromString(basicPeriodLengthMs_, (*attributeIter)->value_);
00325                 if(basicPeriodLengthMs_ == 0)
00326                         throw GSIException(__FILE__,__LINE__,FESAGSIErrorWrongBasicPeriodLength.c_str());
00327             }
00328                 if((*attributeIter)->name_ == "repetition")
00329                 {
00330                         fesa::StringUtilities::fromString(superCycleRepetition_, (*attributeIter)->value_);
00331                         if(superCycleRepetition_ < -1)
00332                                 throw GSIException(__FILE__,__LINE__,FESAGSIErrorWrongRepetitionAttribute.c_str());
00333                 }
00334         }
00335 
00336         //pass the collection-part down for each timing domain
00337         for(domainIter = (*TSElement)->childList_.begin();domainIter != (*TSElement)->childList_.end();domainIter++)
00338         {
00339                 timingDomainCol_.push_back(new DomainConfig(*domainIter));
00340         }
00341 
00342         for (unsigned int i = 0; i < pElCol->size(); i++)
00343         {
00344             delete (*pElCol)[i];
00345         }
00346                 delete pElCol;
00347     }
00348 
00349     TimingSimulationConfig::~TimingSimulationConfig()
00350     {
00351         std::vector<DomainConfig*>::iterator iter;
00352         for(iter= timingDomainCol_.begin();iter!=timingDomainCol_.end();iter++)
00353         {
00354                 delete *iter;
00355         }
00356     }
00357 }

Generated on 25 Jan 2013 for fesa-core-gsi by  doxygen 1.6.1