Line data Source code
1 : #include <alma/ASDM/ArrayTimeInterval.h> 2 : 3 : using namespace std; 4 : 5 : namespace asdm { 6 : 7 : bool ArrayTimeInterval::readStartTimeDurationInBin_ = false; 8 : bool ArrayTimeInterval::readStartTimeDurationInXML_ = false; 9 : 10 : #ifndef WITHOUT_ACS 11 : /** 12 : * Create a ArrayTimeInterval from an IDLArrayTimeInterval object. 13 : * @param t The IDL ArrayTimeInterval object. 14 : */ 15 : ArrayTimeInterval::ArrayTimeInterval (asdmIDLTypes::IDLArrayTimeInterval t) { 16 : start = ArrayTime(t.start); 17 : duration = Interval(t.duration); 18 : } 19 : 20 : // inline to IDL conversion. 21 : const asdmIDLTypes::IDLArrayTimeInterval ArrayTimeInterval::toIDLArrayTimeInterval()const { 22 : asdmIDLTypes::IDLArrayTimeInterval x; 23 : x.start = start.get(); 24 : x.duration = duration.get(); 25 : return x; 26 : } 27 : #endif 28 : 29 0 : void ArrayTimeInterval::toBin(EndianOSStream& eoss) const { 30 0 : int64_t start = getStart().get(); 31 0 : int64_t midpoint = start + getDuration().get() / 2; 32 0 : eoss.writeLongLong(midpoint); 33 0 : eoss.writeLongLong(duration.get()); 34 0 : } 35 : 36 0 : void ArrayTimeInterval::toBin(const vector<ArrayTimeInterval>& arrayTimeInterval, EndianOSStream& eoss) { 37 0 : eoss.writeInt((int) arrayTimeInterval.size()); 38 0 : for (unsigned int i = 0; i < arrayTimeInterval.size(); i++) { 39 0 : arrayTimeInterval.at(i).toBin(eoss); 40 : } 41 0 : } 42 : 43 0 : void ArrayTimeInterval::toBin(const vector<vector<ArrayTimeInterval> >& arrayTimeInterval, EndianOSStream& eoss) { 44 0 : eoss.writeInt((int) arrayTimeInterval.size()); 45 0 : eoss.writeInt((int) arrayTimeInterval.at(0).size()); 46 0 : for (unsigned int i = 0; i < arrayTimeInterval.size(); i++) 47 0 : for (unsigned int j = 0; j < arrayTimeInterval.at(0).size(); j++) { 48 0 : arrayTimeInterval.at(i).at(j).toBin(eoss); 49 : } 50 0 : } 51 : 52 0 : void ArrayTimeInterval::toBin(const vector< vector<vector<ArrayTimeInterval> > >& arrayTimeInterval, EndianOSStream& eoss) { 53 0 : eoss.writeInt((int) arrayTimeInterval.size()); 54 0 : eoss.writeInt((int) arrayTimeInterval.at(0).size()); 55 0 : eoss.writeInt((int) arrayTimeInterval.at(0).at(0).size()); 56 0 : for (unsigned int i = 0; i < arrayTimeInterval.size(); i++) 57 0 : for (unsigned int j = 0; j < arrayTimeInterval.at(0).size(); j++) 58 0 : for (unsigned int k = 0; k < arrayTimeInterval.at(0).at(0).size(); j++) { 59 0 : arrayTimeInterval.at(i).at(j).at(k).toBin(eoss); 60 : } 61 0 : } 62 : 63 0 : void ArrayTimeInterval::readStartTimeDurationInBin(bool b) { 64 0 : readStartTimeDurationInBin_ = b; 65 0 : } 66 : 67 0 : bool ArrayTimeInterval::readStartTimeDurationInBin() { 68 0 : return readStartTimeDurationInBin_; 69 : } 70 : 71 0 : void ArrayTimeInterval::readStartTimeDurationInXML(bool b) { 72 0 : readStartTimeDurationInXML_ = b; 73 0 : } 74 : 75 0 : bool ArrayTimeInterval::readStartTimeDurationInXML() { 76 0 : return readStartTimeDurationInXML_; 77 : } 78 : 79 : 80 0 : ArrayTimeInterval ArrayTimeInterval::fromBin(EndianIStream & eis) { 81 : int64_t start, duration; 82 0 : if (readStartTimeDurationInBin_) { 83 0 : start = eis.readLongLong(); 84 0 : duration = eis.readLongLong(); 85 : } 86 : else { 87 0 : int64_t midpoint = eis.readLongLong(); 88 0 : duration = eis.readLongLong(); 89 0 : start = midpoint - duration / 2; 90 : } 91 0 : return ArrayTimeInterval(start, duration); 92 : } 93 : 94 0 : vector<ArrayTimeInterval> ArrayTimeInterval::from1DBin(EndianIStream & eis) { 95 0 : int dim1 = eis.readInt(); 96 0 : vector<ArrayTimeInterval> result; 97 0 : for (int i = 0; i < dim1; i++) { 98 0 : result.push_back(fromBin(eis)); 99 : } 100 0 : return result; 101 0 : } 102 : 103 0 : vector<vector<ArrayTimeInterval > > ArrayTimeInterval::from2DBin(EndianIStream & eis) { 104 0 : int dim1 = eis.readInt(); 105 0 : int dim2 = eis.readInt(); 106 0 : vector< vector<ArrayTimeInterval> >result; 107 0 : vector <ArrayTimeInterval> aux; 108 0 : for (int i = 0; i < dim1; i++) { 109 0 : aux.clear(); 110 0 : for (int j = 0; j < dim2; j++) { 111 0 : aux.push_back(fromBin(eis)); 112 : } 113 0 : result.push_back(aux); 114 : } 115 0 : return result; 116 0 : } 117 : 118 0 : vector<vector<vector<ArrayTimeInterval > > > ArrayTimeInterval::from3DBin(EndianIStream & eis) { 119 0 : int dim1 = eis.readInt(); 120 0 : int dim2 = eis.readInt(); 121 0 : int dim3 = eis.readInt(); 122 0 : vector<vector< vector<ArrayTimeInterval> > >result; 123 0 : vector < vector<ArrayTimeInterval> >aux1; 124 0 : vector <ArrayTimeInterval> aux2; 125 0 : for (int i = 0; i < dim1; i++) { 126 0 : aux1.clear(); 127 0 : for (int j = 0; j < dim2; j++) { 128 0 : aux2.clear(); 129 0 : for (int k = 0; k < dim3; k++) { 130 0 : aux2.push_back(fromBin(eis)); 131 : } 132 0 : aux1.push_back(aux2); 133 : } 134 0 : result.push_back(aux1); 135 : } 136 0 : return result; 137 0 : } 138 : 139 0 : string ArrayTimeInterval::toString() const { 140 0 : ostringstream oss; 141 0 : oss << "start=" << start.toFITS() << ",duration=" << duration / 1.e9 << "s." ; 142 0 : return oss.str(); 143 0 : } 144 : } // end name space