EMANE  1.2.1
eelloaderantennaprofile.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2012 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
39 
40 #include <sstream>
41 #include <cstring>
42 
44 {}
45 
47 {}
48 
50  const ModuleId & moduleId,
51  const EventType & ,
52  const InputArguments & args)
53 {
54  if(moduleType == "nem")
55  {
56  if(args.size() != 1)
57  {
58  throw FormatException("LoaderAntennaProfile loader expects 1 argument");
59  }
60  else
61  {
62  InputArguments params;
63 
64  size_t posStart = 0;
65  size_t posEnd = 0;
66 
67 
68 
69  while(posEnd != std::string::npos)
70  {
71  posEnd = args[0].find_first_of(",",posStart);
72 
73  params.push_back(args[0].substr(posStart, posEnd - posStart));
74 
75  posStart = posEnd + 1;
76  }
77 
78  AntennaProfileId profileId{};
79  double dAntennaAzimuthDegrees{};
80  double dAntennaElevationDegrees{};
81 
82  try
83  {
84  for(size_t i = 0; i < params.size(); i++)
85  {
86  switch(i)
87  {
88  case 0:
89  profileId = Utils::ParameterConvert(params[i]).toUINT16();
90  break;
91 
92  case 1:
93  dAntennaAzimuthDegrees = Utils::ParameterConvert(params[i]).toDouble();
94  break;
95 
96  case 2:
97  dAntennaElevationDegrees = Utils::ParameterConvert(params[i]).toDouble();
98  break;
99 
100  default:
101  throw FormatException("LoaderAntennaProfile too many arguments");
102  }
103  }
104  }
106  {
107  std::stringstream sstream;
108  sstream<<"EELEventGenerator: Parameter conversion error. "<<exp.what()<<std::ends;
109  throw FormatException(sstream.str());
110  }
111 
112  Events::AntennaProfile antennaProfile{moduleId,
113  profileId,
114  dAntennaAzimuthDegrees,
115  dAntennaElevationDegrees};
116 
117 
118  // update the full cache
119  std::pair<AntennaProfileEntryMap::iterator,bool> ret =
120  antennaProfileEntryMap_.insert(std::make_pair(moduleId,antennaProfile));
121 
122  if(!ret.second)
123  {
124  ret.first->second = antennaProfile;
125  }
126 
127  // update the delta cache
128  ret = antennaProfileEntryDeltaMap_.insert(std::make_pair(moduleId,antennaProfile));
129 
130  if(!ret.second)
131  {
132  ret.first->second = antennaProfile;
133  }
134  }
135 
136  }
137 }
138 
140 {
141  EventInfoList eventInfoList;
142  AntennaProfileEntryMap * pCache = 0;
143 
144  if(mode == DELTA)
145  {
146  pCache = &antennaProfileEntryDeltaMap_;
147  }
148  else
149  {
150  pCache = &antennaProfileEntryMap_;
151  }
152 
153  Events::AntennaProfiles profiles;
154 
155  for(const auto & entry : *pCache)
156  {
157  profiles.push_back(entry.second);
158  }
159 
160  if(!profiles.empty())
161  {
162  eventInfoList.push_back({0,
164  Events::AntennaProfileEvent(profiles).serialize()});
165 
166  }
167 
168  antennaProfileEntryDeltaMap_.clear();
169 
170  return eventInfoList;
171 }
172 
173 
std::vector< std::string > InputArguments
#define DECLARE_EEL_LOADER_PLUGIN(X)
Definition: loaderplugin.h:91
Parameter conversion exception class.
std::uint16_t toUINT16(std::uint16_t u16Min=std::numeric_limits< std::uint16_t >::min(), std::uint16_t u16Max=std::numeric_limits< std::uint16_t >::max()) const
double toDouble(double dMin=std::numeric_limits< double >::lowest(), double dMax=std::numeric_limits< double >::max()) const
const char * what() const
Definition: exception.h:62
std::uint16_t AntennaProfileId
Definition: types.h:57
EventInfoList getEvents(EventPublishMode mode) override
void load(const ModuleType &modelType, const ModuleId &moduleId, const EventType &eventType, const InputArguments &args) override
std::list< EventInfo > EventInfoList
Holds NEM Id, antenna profile Id, azimuth and elevation.
Parameter conversion class with range checks.
std::list< AntennaProfile > AntennaProfiles