CycleDescriptor.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/Synchronization/CycleDescriptor.h>
00004 
00005 #include <fesa-core/Utilities/Lock.h>
00006 #include <fesa-core/Exception/FesaException.h>
00007 
00008 #include <sstream>
00009 
00010 
00011 namespace fesa
00012 {
00013 
00014 CycleDescriptor::CycleDescriptor(const std::string& timingDomain, const std::string& multiplexingCriterion) :
00015     timingDomain_(timingDomain), timingCriterion_(multiplexingCriterion)
00016 {
00017     name_ = timingDomain + "." + multiplexingCriterion;
00018 }
00019 
00020 CycleDescriptor::~CycleDescriptor()
00021 {
00022 
00023 }
00024 
00025 int32_t CycleDescriptor::getCycleSelectorId(const std::string& cycleSelectorName)
00026 {
00027     std::map<std::string, int32_t>::iterator iter;
00028 
00029     Lock lock(cycleSelectorColMutex_);
00030     iter = cycleSelectorCol_.find(cycleSelectorName);
00031 
00032     if (iter == cycleSelectorCol_.end())
00033     {
00034         throw FesaException(__FILE__, __LINE__, FesaErrorCycleSelectorNameNotFound.c_str(),cycleSelectorName.c_str());
00035     }
00036     else
00037     {
00038         return (*iter).second;
00039     }
00040 }
00041 
00042 const std::string CycleDescriptor::getCycleSelectorName(int32_t cycleSelectorID)
00043 {
00044     std::map<std::string, int32_t>::const_iterator iter;
00045     Lock lock(cycleSelectorColMutex_);
00046     for (iter = cycleSelectorCol_.begin(); iter != cycleSelectorCol_.end(); iter++)
00047     {
00048         if ((*iter).second == cycleSelectorID)
00049         {
00050             return (*iter).first;
00051         }
00052     }
00053     std::stringstream buf;
00054     buf << cycleSelectorID;
00055     throw FesaException(__FILE__, __LINE__, FesaErrorCycleSelectorIDNotFound.c_str(), buf.str().c_str());
00056 }
00057 
00058 bool CycleDescriptor::isValidCycleSelector(const std::string& cycleSelectorName)
00059 {
00060     std::map<std::string, int32_t>::iterator iter;
00061 
00062     Lock lock(cycleSelectorColMutex_);
00063     iter = cycleSelectorCol_.find(cycleSelectorName);
00064 
00065     if (iter == cycleSelectorCol_.end())
00066     {
00067         return false;
00068     }
00069     else
00070     {
00071         return true;
00072     }
00073 }
00074 
00075 void CycleDescriptor::addSelector(const std::string& cycleSelectorName)
00076 {
00077     if(isValidCycleSelector(cycleSelectorName))
00078     {
00079         throw FesaException(__FILE__, __LINE__, FesaErrorDublicateSelectionCriterion.c_str(),cycleSelectorName.c_str());
00080     }
00081 
00082     //we start with 0, not with 1
00083     int32_t newID = static_cast<int32_t>(cycleIdsCol_.size());
00084     cycleIdsCol_.push_back(newID);
00085     Lock lock(cycleSelectorColMutex_);
00086     {
00087         cycleSelectorCol_.insert(std::make_pair(cycleSelectorName, newID));
00088     }
00089 }
00090 
00091 void CycleDescriptor::renameSelector(const std::string& oldCycleSelectorName,const std::string& newCycleSelectorName)
00092 {
00093     Lock lock(cycleSelectorColMutex_);
00094     std::map<std::string, int32_t>::iterator iter = cycleSelectorCol_.find(oldCycleSelectorName);
00095     if (iter == cycleSelectorCol_.end())
00096     {
00097         throw FesaException(__FILE__, __LINE__, FesaErrorCycleSelectorNameNotFound.c_str(),oldCycleSelectorName.c_str());
00098     }
00099     int32_t id  = iter->second;
00100     cycleSelectorCol_.erase(iter);
00101     cycleSelectorCol_.insert(std::make_pair(newCycleSelectorName, id));
00102 }
00103 
00104 const std::string& CycleDescriptor::getTimingDomain()
00105 {
00106     return timingDomain_;
00107 }
00108 
00109 const std::string& CycleDescriptor::getTimingCriterion()
00110 {
00111     return timingCriterion_;
00112 }
00113 
00114 const std::string& CycleDescriptor::getName()
00115 {
00116     return name_;
00117 }
00118 
00119 const std::vector<int32_t>& CycleDescriptor::getCycleIdsCol()
00120 {
00121     return cycleIdsCol_;
00122 }
00123 
00124 const std::map<std::string, int32_t>& CycleDescriptor::getCycleSelectorCol()
00125 {
00126     return cycleSelectorCol_;
00127 }
00128 
00129 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1