/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

LtbTraits.cc
Go to the documentation of this file.
00001 /*
00002  *  LtbTraits.cc
00003  *  LtbReadoutFormat
00004  *
00005  *  Created by Simon Patton on 7/21/10.
00006  *  Copyright 2010 DayaBay Collaboration. All rights reserved.
00007  *
00008  */
00009 
00010 #include <map>
00011 
00012 #include "LtbReadoutFormat/LtbTraits_v3_8.h"
00013 #include "LtbReadoutFormat/LtbTraits_v4_1.h"
00014 #include "LtbReadoutFormat/LtbTraits_v4_3.h"
00015 #include "LtbReadoutFormat/LtbTraits_v4_6.h"
00016 
00017 #include "LtbReadoutFormat/LtbTime.h"
00018 #include "LtbReadoutFormat/LtbTraits.h"
00019 
00020 using DybDaq::LtbTime;
00021 using DybDaq::LtbTraits;
00022 using DybDaq::LtbTraits_v3_8;
00023 using DybDaq::LtbTraits_v4_1;
00024 using DybDaq::LtbTraits_v4_3;
00025 using DybDaq::LtbTraits_v4_6;
00026 using std::string;
00027 
00028 // Components in this format
00029 const unsigned int LtbTraits::kHead = 0;
00030 const unsigned int LtbTraits::kFrameFront = LtbTraits::kHead + 1;
00031 const unsigned int LtbTraits::kTime = LtbTraits::kFrameFront + 1;
00032 const unsigned int LtbTraits::kFrameBack = LtbTraits::kTime + 1;
00033 const unsigned int LtbTraits::kFoot = LtbTraits::kFrameBack + 1;
00034 const unsigned int LtbTraits::kUnixTime = LtbTraits::kFoot + 1;
00035 const unsigned int LtbTraits::kGpsTime = LtbTraits::kUnixTime + 1;
00036 
00037 // Known triggers
00038 const unsigned int LtbTraits::kManualTrigger = 0;
00039 const unsigned int LtbTraits::kCrossTrigger = LtbTraits::kManualTrigger + 1;
00040 const unsigned int LtbTraits::kPeriodicTrigger = LtbTraits::kCrossTrigger + 1;
00041 const unsigned int LtbTraits::kPedestalTrigger = LtbTraits::kPeriodicTrigger + 1;
00042 const unsigned int LtbTraits::kCalibTrigger = LtbTraits::kPedestalTrigger + 1;
00043 const unsigned int LtbTraits::kRandomTrigger = LtbTraits::kCalibTrigger + 1;
00044 const unsigned int LtbTraits::kMultiplicityTrigger = LtbTraits::kRandomTrigger + 3;
00045 const unsigned int LtbTraits::kEsumAdcTrg = LtbTraits::kMultiplicityTrigger + 1;
00046 const unsigned int LtbTraits::kHighEsumCompTrg = LtbTraits::kEsumAdcTrg + 1;
00047 const unsigned int LtbTraits::kLowEsumCompTrg = LtbTraits::kHighEsumCompTrg + 1;
00048 const unsigned int LtbTraits::kAllEsumCompTrg = LtbTraits::kLowEsumCompTrg + 1;
00049 const unsigned int LtbTraits::kNHitLowTrigger = LtbTraits::kAllEsumCompTrg + 1;
00050 const unsigned int LtbTraits::kNHitHighTrigger = LtbTraits::kNHitLowTrigger + 1;
00051 
00052 // Head
00053 const unsigned int LtbTraits::kRawTriggerTotal = 0;
00054 const unsigned int LtbTraits::kRawTriggersSaved = LtbTraits::kRawTriggerTotal + 1;
00055 const unsigned int LtbTraits::kLtbStatus = LtbTraits::kRawTriggersSaved + 1;
00056 const unsigned int LtbTraits::kLocalTriggerNumber = LtbTraits::kLtbStatus + 1;
00057 
00058 // Frame
00059 const unsigned int LtbTraits::kFrameNumber = LtbTraits::kLocalTriggerNumber + 1;
00060 const unsigned int LtbTraits::kReadoutType = LtbTraits::kFrameNumber + 1;
00061 const unsigned int LtbTraits::kTriggerMask = LtbTraits::kReadoutType + 1;
00062 const unsigned int LtbTraits::kYear = LtbTraits::kTriggerMask + 1;
00063 const unsigned int LtbTraits::kMonth = LtbTraits::kYear + 1;
00064 const unsigned int LtbTraits::kDay = LtbTraits::kMonth + 1;
00065 const unsigned int LtbTraits::kHour = LtbTraits::kDay + 1;
00066 const unsigned int LtbTraits::kMinutes = LtbTraits::kHour + 1;
00067 const unsigned int LtbTraits::kSeconds = LtbTraits::kMinutes + 1;
00068 const unsigned int LtbTraits::kTicks = LtbTraits::kSeconds + 1;
00069 const unsigned int LtbTraits::kHitSum = LtbTraits::kTicks + 1;
00070 const unsigned int LtbTraits::kTotalEsum = LtbTraits::kHitSum + 1;
00071 const unsigned int LtbTraits::kHighEsum = LtbTraits::kTotalEsum + 1;
00072 const unsigned int LtbTraits::kLowEsum = LtbTraits::kHighEsum + 1;
00073 const unsigned int LtbTraits::kEnergySum = LtbTraits::kLowEsum + 1;
00074 const unsigned int LtbTraits::kCrossTriggerSource = LtbTraits::kEnergySum + 1;
00075 
00076 // Foot
00077 const unsigned int LtbTraits::kFootDataLength = LtbTraits::kCrossTriggerSource + 1;
00078 
00079 // New in 4.1
00080 
00081 // Head
00082 const unsigned int LtbTraits::kClockError = LtbTraits::kFootDataLength + 1;
00083 const unsigned int LtbTraits::kVersion = LtbTraits::kClockError + 1;
00084 
00085 // Frame
00086 const unsigned int LtbTraits::kAccumulationStatus = LtbTraits::kVersion + 1;
00087 const unsigned int LtbTraits::kValidGps = LtbTraits::kAccumulationStatus + 1;
00088 const unsigned int LtbTraits::kUsingUtc = LtbTraits::kValidGps + 1;
00089 const unsigned int LtbTraits::kValidClockSystem = LtbTraits::kUsingUtc + 1;
00090 const unsigned int LtbTraits::kHighNanoseconds = LtbTraits::kValidClockSystem + 1;
00091 const unsigned int LtbTraits::kLowNanoseconds = LtbTraits::kHighNanoseconds + 1;
00092 const unsigned int LtbTraits::kHighUnixTime = LtbTraits::kLowNanoseconds + 1;
00093 const unsigned int LtbTraits::kLowUnixTime = LtbTraits::kHighUnixTime + 1;
00094 const unsigned int LtbTraits::kHighAccumulation = LtbTraits::kLowUnixTime + 1;
00095 const unsigned int LtbTraits::kLowAccumulation = LtbTraits::kHighAccumulation + 1;
00096 const unsigned int LtbTraits::kFeeBufferFull = LtbTraits::kLowAccumulation + 1;
00097 const unsigned int LtbTraits::kLtbBufferFull = LtbTraits::kFeeBufferFull + 1;
00098 const unsigned int LtbTraits::kBlockedTriggerCount = LtbTraits::kLtbBufferFull + 1;
00099 
00100 // New in 4.6
00101 
00102 // Frame
00103 const unsigned int LtbTraits::kHighCrossTrigger = LtbTraits::kBlockedTriggerCount + 1;
00104 const unsigned int LtbTraits::kLowCrossTrigger = LtbTraits::kHighCrossTrigger + 1;
00105 
00106 static const unsigned int kLengthOfDataTime = 21;
00107 
00108 static std::map<const char*, LtbTraits*> m_allTraits;
00109 
00110 LtbTraits::LtbTraits() {
00111 }
00112 
00113 LtbTraits::~LtbTraits() {
00114 }
00115 
00116 const LtbTraits& LtbTraits::defaultTraits() {
00117     if (0 == m_allTraits.size()) {
00118         m_allTraits.insert(std::pair<const char*, LtbTraits*>(LtbTraits_v3_8::key(),new LtbTraits_v3_8()));
00119         m_allTraits.insert(std::pair<const char*, LtbTraits*>(LtbTraits_v4_1::key(),new LtbTraits_v4_1()));
00120         m_allTraits.insert(std::pair<const char*, LtbTraits*>(LtbTraits_v4_3::key(),new LtbTraits_v4_3()));
00121         m_allTraits.insert(std::pair<const char*, LtbTraits*>(LtbTraits_v4_6::key(),new LtbTraits_v4_6()));
00122     }
00123     return *m_allTraits[LtbTraits_v4_6::key()];
00124 }
00125 
00126 const LtbTraits* LtbTraits::readTraits(const char*& buffer) {
00127     const unsigned int vers = readUnsignedInt(buffer,
00128                                             defaultTraits(),
00129                                             LtbTraits::kVersion);
00130     unsigned int major = 0;
00131     unsigned int minor = 0;
00132     if (0x0 == vers) {
00133         major = 3;
00134         minor = 8;
00135     } else if (0x2 == vers) {
00136         major = 4;
00137         minor = 1;
00138     } else if (0x3 == vers) {
00139         major = 4;
00140         minor = 3;
00141     } else if (0x4 == vers) {
00142         major = 4;
00143         minor = 6;
00144     }
00145 
00146     const LtbTraits* result = 0;
00147     if (4 > major) {
00148         result = m_allTraits[LtbTraits_v3_8::key()];
00149     } else if (4U == major && 1U == minor) {
00150         result = m_allTraits[LtbTraits_v4_1::key()];
00151     } else if (4U == major && 3U == minor) {
00152         result = m_allTraits[LtbTraits_v4_3::key()];
00153     } else if (4U == major && 6U == minor) {
00154         result = m_allTraits[LtbTraits_v4_6::key()];
00155     }        
00156     return result;
00157 }
00158 
00159 unsigned int LtbTraits::illegalMarker() const {
00160     return 0xffffffffU;
00161 }
00162 
00163 unsigned int LtbTraits::illegalField() const {
00164     return 0xffffffffU;
00165 }
00166 
00167 const LtbTraits::TriggerLines* LtbTraits::triggerLines(const unsigned int mask) const {
00168     TriggerLines* result = new TriggerLines();
00169     unsigned int bit = 1;
00170     for (unsigned int line = 0; line != triggerLineEnd(); ++ line) {
00171         if (mask & bit) {
00172             const char* name = triggerLineAsString(line);
00173             if (0 != name) {
00174                 result->push_back(name);
00175             }
00176         }
00177         bit = bit << 1;
00178     }
00179     return result;
00180 }
00181 
00182 const char* LtbTraits::triggerLineAsString(unsigned int line) const {
00183     return triggerLineStrings()[line];
00184 }
00185 
00186 unsigned int LtbTraits::triggerLineBit(const unsigned int line) const {
00187     return triggerLineBits()[line];
00188 }
00189 
00190 const string LtbTraits::dateTimeAsString(const LtbTraits::LtbDateTime& time) const {
00191     const time_t unixTime = time.unixTime();
00192     struct tm* tmStruct = gmtime(&unixTime);
00193     
00194     char* dateTime = new char[kLengthOfDataTime];
00195     if (0 == strftime(dateTime,
00196                       kLengthOfDataTime,
00197                       "%Y-%m-%dT%H:%M:%SZ",
00198                       tmStruct)) {
00199         return "0000-00-00T00:00:00Z";
00200     };
00201     dateTime[kLengthOfDataTime - 1] = 0;
00202     string result(dateTime);
00203     delete dateTime;
00204     return result;
00205 }
00206 
00207 const LtbTraits::LtbDateTime* LtbTraits::makeDateTime(const time_t& time) const {
00208     return new LtbDateTime(time,
00209                            0,
00210                            0,
00211                            *this);
00212 }
00213 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:53:06 for LtbReadoutFormat by doxygen 1.7.4