GSICycleDescriptor.cpp

Go to the documentation of this file.
00001 //Copyright GSI 2012
00002 #include <fesa-core-gsi/Synchronization/GSICycleDescriptor.h>
00003 #include <fesa-core/Core/AbstractEquipment.h>
00004 #include <fesa-core/Utilities/Lock.h>
00005 #include <fesa-core-gsi/Exception/GSIException.h>
00006 
00007 
00008 #include <sstream>
00009 #include <iostream>
00010 
00011 namespace fesaGSI
00012 {
00013         GSICycleDescriptor::GSICycleDescriptor(const std::string& machineName,const std::string& groupName) :
00014                 fesa::CycleDescriptor(machineName,groupName)
00015     {
00016         tgmMachineName_ = machineName;
00017         tgmGroupName_ = groupName;
00018 
00019         log_ = fesa::FesaLogger::getLogger(fesa::evtLogName, "GSICycleDescriptor", fesa::AbstractEquipment::getInstance()->getEquipmentName());
00020 
00021         //since TgmGetMachineId does a hard "exit" on failure, we need to cout+log some text here
00022         //The file-descriptor-check we do in the TimingEventSource does not work here
00023         std::string bevoreTgmGetMachineId1;
00024         std::string bevoreTgmGetMachineId2;
00025         bevoreTgmGetMachineId1 += "Accessing Timlib to get maschineID (This CERN-Timing method does a hard exit on failure)";
00026         bevoreTgmGetMachineId2 += "Caution: If your application crashes in this line, you are possibly running a Timing-class on a FEC which is not connected to the Timing-Network.";
00027         std::string afterTgmGetMachineId;
00028         afterTgmGetMachineId += "Timlib-access was successful";
00029 
00030         log_->send(bevoreTgmGetMachineId1.c_str(),log_->traceType);
00031         std::cout << bevoreTgmGetMachineId1 << std::endl;
00032         log_->send(bevoreTgmGetMachineId2.c_str(),log_->traceType);
00033         std::cout << bevoreTgmGetMachineId2 << std::endl;
00034         tgmMachineID_ = TgmGetMachineId((char*) tgmMachineName_.c_str());
00035         log_->send(afterTgmGetMachineId.c_str(),log_->traceType);
00036         std::cout << afterTgmGetMachineId << std::endl;
00037 
00038         //seems to be the constant for 'machine not valid'
00039         if(tgmMachineID_ == 4294967295)
00040         {
00041             throw GSIException(__FILE__, __LINE__,FESAGSIErrorWrongMachineName.c_str(),tgmMachineName_.c_str());
00042         }
00043 
00044         tgmGroup_ = TgmGetGroupNumber((TgmMachine) tgmMachineID_, (char*) tgmGroupName_.c_str());
00045 
00046         if (TgmGetGroupDescriptor((TgmMachine) tgmMachineID_, tgmGroup_, &group_) != TgmSUCCESS)
00047         {
00048             throw GSIException(__FILE__, __LINE__,FESAGSIErrorGroupDescriptorFailedForMachine.c_str(),
00049                             tgmMachineName_.c_str(), tgmGroupName_.c_str());
00050         }
00051 
00052         // line names go from minimum value to maximum
00053         // In case of numerical value or bit-pattern the lineNameCol and timingSelectorCol are empty
00054         if (group_.Type == TgmEXCLUSIVE)
00055         {
00056             refreshData();
00057         }
00058         else
00059         {
00060             lineNamesCol_.push_back("");
00061             addSelector("");
00062         }
00063     }
00064 
00065         GSICycleDescriptor::~GSICycleDescriptor()
00066     {
00067 
00068     }
00069 
00070     void GSICycleDescriptor::refreshData()
00071     {
00072         if (group_.Type == TgmEXCLUSIVE)
00073         {
00074             TgmLineNameTable lnt;
00075             if (TgmGetLineNameTable((TgmMachine) tgmMachineID_, (char*) tgmGroupName_.c_str(), &lnt) == TgmSUCCESS)
00076             {
00077                 for (unsigned int i = 0; i < lnt.Size; ++i)
00078                 {
00079                     std::string s(lnt.Table[i].Name);
00080 
00081                     if (lineNamesCol_.size() > i) // if element exists
00082                     {
00083                         if (lineNamesCol_[i] != s) // rename existing element
00084                         {
00085                                 std::string oldName = tgmMachineName_ + "." + tgmGroupName_ + "." + lineNamesCol_[i];
00086                                 std::string newName = tgmMachineName_ + "." + tgmGroupName_ + "." + s;
00087                             renameSelector(oldName,newName);
00088                             lineNamesCol_[i] = s;
00089                         }
00090                     }
00091                     else
00092                     {
00093                         lineNamesCol_.push_back(s);
00094                         addSelector(tgmMachineName_ + "." + tgmGroupName_ + "." + s);
00095                     }
00096                 }
00097             }
00098         }
00099     }
00100 
00101     bool GSICycleDescriptor::isValidCycleSelector(const std::string& timingSelectorName)
00102     {
00103         if (group_.Type == TgmEXCLUSIVE)
00104         {
00105             if (TgmCheckTable((TgmMachine) tgmMachineID_, TgmLINE_NAMES))
00106             {
00107                 refreshData();
00108             }
00109 
00110             //call the baseclass method after refresh
00111             return CycleDescriptor::isValidCycleSelector(timingSelectorName);
00112         }
00113         else
00114         {
00115             size_t sep = timingSelectorName.rfind('.');
00116             if (sep == std::string::npos)
00117             {
00118                 throw GSIException(__FILE__, __LINE__,FESAGSIErrorTimingSelectorSeparatorNotFound.c_str(),'.', timingSelectorName.c_str());
00119             }
00120             std::string lineName = timingSelectorName.substr(sep + 1, timingSelectorName.size() - sep - 1);
00121 
00122             int val = atoi(lineName.c_str());
00123             if ((val >= group_.Minimum) && (val <= group_.Maximum))
00124             {
00125                 return true;
00126             }
00127         }
00128         return false;
00129     }
00130 
00131     int GSICycleDescriptor::getCycleSelectorId(const std::string& timingSelectorName)
00132     {
00133         if (group_.Type == TgmEXCLUSIVE)
00134         {
00135             if (TgmCheckTable((TgmMachine) tgmMachineID_, TgmLINE_NAMES))
00136             {
00137                 refreshData();
00138             }
00139 
00140             //call the baseclass method after refresh
00141             return CycleDescriptor::getCycleSelectorId(timingSelectorName);
00142         }
00143         else
00144         {
00145             return 0;
00146         }
00147     }
00148 
00149     const std::string GSICycleDescriptor::getCycleSelectorName(int timingSelectorID)
00150     {
00151         if (group_.Type == TgmEXCLUSIVE)
00152         {
00153             if (TgmCheckTable((TgmMachine) tgmMachineID_, TgmLINE_NAMES))
00154             {
00155                 refreshData();
00156             }
00157 
00158             //call the baseclass method after refresh
00159             return CycleDescriptor::getCycleSelectorName(timingSelectorID);
00160         }
00161         else
00162         {
00163             return CycleDescriptor::getCycleSelectorName(0);
00164         }
00165     }
00166 
00167     int GSICycleDescriptor::getTgmGroupId()
00168     {
00169         return tgmGroup_;
00170     }
00171 }

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