TimingContext.cpp

Go to the documentation of this file.
00001 //Copyright GSI 2012
00002 #include <climits>
00003 #include <fesa-core-gsi/Synchronization/TimingContext.h>
00004 #include <fesa-core/Synchronization/Timing.h>
00005 #include <fesa-core-gsi/Exception/GSIException.h>
00006 #include <fesa-core-gsi/Synchronization/GSICycleDescriptor.h>
00007 #include <fesa-core/Synchronization/SynchronizationLabObjectFactory.h>
00008 
00009 namespace fesaGSI
00010 {
00011 
00012         // This constructor is only used by the on-subscription event-source
00013     TimingContext::TimingContext(long long cycleStamp, const std::string& cycleName) :
00014         fesa::TimingContext()
00015     {
00016         type_ = fesa::MultiplexingContext::CycleOccurrenceCtxt;
00017         forewarning_ = false;
00018         fesa::CycleSelector cycleSelector;
00019         fesa::parseCycleSelector(cycleName, cycleSelector);
00020         fesa::SynchronizationLabObjectFactory* syncFactory = fesa::SynchronizationLabObjectFactory::getInstance();
00021         fesaGSI::GSICycleDescriptor *ptd = dynamic_cast<fesaGSI::GSICycleDescriptor*> (syncFactory->getCycleDescriptor(cycleSelector.domain_, cycleSelector.criterion_));
00022         cycleStamp_ = cycleStamp;
00023         cycleName_ = cycleName;
00024         cycleId_ = ptd->getCycleSelectorId(cycleName);
00025         timingDomainId_ = ptd->getTgmMachineId();
00026         timingDomainName_ = cycleSelector.domain_;
00027         cycleTimeStamp_.Second = cycleStamp / 1000000000;
00028         cycleTimeStamp_.Nano = cycleStamp % 1000000000;
00029         cycleTimeStamp_.CTrain = 0;
00030         cycleTimeStamp_.Machine = ptd->getTgmMachineId();
00031     }
00032 
00033     //This constructor is the important one. It is used to create TimingContexts from within the TimingEventSource
00034     TimingContext::TimingContext(TimLibTime& interruptTimeStamp, unsigned long payload, bool forewarning) :
00035         fesa::TimingContext(), interruptTimeStamp_(interruptTimeStamp)
00036     {
00037         type_ = fesa::MultiplexingContext::CycleOccurrenceCtxt;
00038         forewarning_ = forewarning;
00039         init(payload);
00040     }
00041 
00042     void TimingContext::init(unsigned long payload)
00043         {
00044         // timingDomainName_
00045         timingDomainName_ = TgmGetMachineName(interruptTimeStamp_.Machine);
00046 
00047         // TimingDomainID_
00048         timingDomainId_ = interruptTimeStamp_.Machine;
00049 
00050         //Getting CycleStamp
00051         TimLibError err = TimLibGetTgmInfo(interruptTimeStamp_, &cycleTimeStamp_, NULL, NULL);
00052         if (err != TimLibErrorSUCCESS)
00053         {
00054             throw GSIException(__FILE__, __LINE__, FesaGSIErrorAccessingTimLib.c_str());
00055         }
00056 
00057         // long long cycleStamp_
00058         cycleStamp_ = cycleTimeStamp_.Second * (long long) 1000000000 + cycleTimeStamp_.Nano;
00059 
00060         // Getting cycleID
00061         unsigned long userGroupNb = TgmGetGroupNumber((TgmMachine) interruptTimeStamp_.Machine, "USER");
00062         err = TimLibGetGroupValueFromStamp(cycleTimeStamp_, userGroupNb, 0, (long unsigned int*)&cycleId_);
00063         if (err != TimLibErrorSUCCESS)
00064         {
00065             throw GSIException(__FILE__, __LINE__, FesaGSIErrorAccessingTimLib.c_str());
00066         }
00067 
00068         // forewarning_ //TODO Think of usage @ GSI
00069 //        if ((interruptTimeStamp_.Machine == TgmSPS) && (forewarning_ == false) && (payload < SCHAR_MAX))
00070 //        {
00071 //            forewarning_ = ((long int)payload != cycleId_) ? true : false;
00072 //            if (forewarning_ == true)
00073 //            {
00074 //                cycleId_ = payload;
00075 //            }
00076 //        }
00077 
00078         fesa::SynchronizationLabObjectFactory* syncFactory = fesa::SynchronizationLabObjectFactory::getInstance();
00079         fesa::CycleDescriptor *td = syncFactory->createOrGetEventCycleDescriptor(timingDomainName_, "USER");
00080         cycleName_ = td->getCycleSelectorName(cycleId_);
00081     }
00082 
00083     int64_t TimingContext::getInterruptTimeStamp()
00084     {
00085         return interruptTimeStamp_.Second * (int64_t) 1000000000 + interruptTimeStamp_.Nano;
00086     }
00087 
00088     uint32_t TimingContext::getCycleTime()
00089     {
00090         return interruptTimeStamp_.CTrain;
00091     }
00092 
00093 }//end namespace
00094 

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