52 #ifndef __PCL_GaiaDatabaseFile_h
53 #define __PCL_GaiaDatabaseFile_h
125 namespace GaiaStarFlag
130 NoGBPMag = 0x00000002,
131 NoGRPMag = 0x00000004,
132 LackingData = 0x00000007,
135 GoldDec = 0x00000020,
136 GoldPMRA = 0x00000040,
137 GoldPMDec = 0x00000080,
139 SilverRA = 0x00000100,
140 SilverDec = 0x00000200,
141 SilverPMRA = 0x00000400,
142 SilverPMDec = 0x00000800,
144 BronzeRA = 0x00001000,
145 BronzeDec = 0x00002000,
146 BronzePMRA = 0x00004000,
147 BronzePMDec = 0x00008000,
149 GoldGMag = 0x00010000,
150 GoldGBPMag = 0x00020000,
151 GoldGRPMag = 0x00040000,
152 GoldParx = 0x00080000,
154 SilverGMag = 0x00100000,
155 SilverGBPMag = 0x00200000,
156 SilverGRPMag = 0x00400000,
157 SilverParx = 0x00800000,
159 BronzeGMag = 0x01000000,
160 BronzeGBPMag = 0x02000000,
161 BronzeGRPMag = 0x04000000,
162 BronzeParx = 0x08000000,
164 BPRPExcess = 0x10000008,
165 BPRPExcessHigh = 0x20000000,
167 GoldAstrometry = 0x000800F0,
168 SilverAstrometry = 0x00800F00,
169 BronzeAstrometry = 0x0800F000,
171 GoldPhotometry = 0x00070000,
172 SilverPhotometry = 0x00700000,
173 BronzePhotometry = 0x07000000
338 static_assert(
sizeof( EncodedStarData ) == 32,
"Invalid sizeof( GaiaDatabaseFile::EncodedStarData )" );
339 static_assert(
sizeof( EncodedStarSPData ) == 41,
"Invalid sizeof( GaiaDatabaseFile::EncodedStarSPData )" );
340 if (
Metadata().databaseIdentifier ==
"GaiaDR3" )
342 else if (
Metadata().databaseIdentifier ==
"GaiaDR3SP" )
345 m_hasSpectrumData =
true;
348 throw Error(
"Missing parameters Data element attribute: " + filePath );
350 m_parameters.Break( tokens,
',' );
351 for (
const String& token : tokens )
354 token.Break( items,
'=' );
355 if ( items.
Length() != 2 )
356 throw Error(
"Invalid parameter specification '" + token +
"': " + filePath );
357 if ( items[0] ==
"spectrumStart" )
358 m_spectrumStart = items[1].ToFloat();
359 else if ( items[0] ==
"spectrumStep" )
360 m_spectrumStep = items[1].ToFloat();
361 else if ( items[0] ==
"spectrumCount" )
362 m_spectrumCount = items[1].ToInt();
363 else if ( items[0] ==
"spectrumBits" )
364 m_spectrumBits = items[1].ToInt();
366 if ( m_spectrumStart <= 0 || m_spectrumStep <= 0 || m_spectrumCount <= 0 ||
367 m_spectrumBits != 8 && m_spectrumBits != 16 )
368 throw Error(
"Invalid parameters attribute value '" + m_parameters +
"': " + filePath );
369 m_spectrumRange = (1 << m_spectrumBits) - 1;
379 if ( tokens.
Length() < 3 || tokens[0].ToInt() < 1 || tokens[1].ToInt() < 0 || tokens[2].ToInt() < 2 )
380 throw Error(
"Unsupported Gaia DR2 database version '"
381 +
Metadata().databaseVersion +
"': " + filePath );
384 throw Error(
"Invalid or unsupported Gaia database file with unknown identifier '"
385 +
Metadata().databaseIdentifier +
"': " + filePath );
421 return m_hasSpectrumData;
433 return m_spectrumStart;
445 return m_spectrumStep;
457 return m_spectrumCount;
469 return m_spectrumBits;
507 for (
const XPSD::IndexTree& tree : m_index )
515 bool m_hasSpectrumData =
false;
516 float m_spectrumStart = 0;
517 float m_spectrumStep = 0;
518 int m_spectrumCount = 0;
519 int m_spectrumBits = 0;
520 float m_spectrumRange = 0;
522 #pragma pack(push, 1)
527 struct EncodedStarData
552 struct EncodedStarSPData :
public EncodedStarData
559 constexpr
size_type EncodedStarSPDataSize()
const
561 return sizeof( EncodedStarSPData ) - 1 + (m_spectrumBits >> 3)*(m_spectrumCount + (m_spectrumCount & 1));
566 void GetEncodedData(
const ByteArray& data,
const XPSD::IndexTree& tree,
const XPSD::IndexNode& node,
void* searchData )
const override
569 GaiaSearchData* search =
reinterpret_cast<GaiaSearchData*
>( searchData );
570 double searchRadius =
Rad( search->radius );
571 int itemSize = m_hasSpectrumData ? EncodedStarSPDataSize() : sizeof( EncodedStarData );
572 int count = int( data.Size() / itemSize );
574 for (
int i = 0; i < count; ++i )
576 const EncodedStarData* S =
reinterpret_cast<const EncodedStarData*
>( data.Begin() + i*itemSize );
577 if ( search->requiredFlags == 0 || (S->flags & search->requiredFlags) == search->requiredFlags )
578 if ( search->inclusionFlags == 0 || (S->flags & search->inclusionFlags) != 0 )
579 if ( search->exclusionFlags == 0 || (S->flags & search->exclusionFlags) == 0 )
581 float magG = 0.001*S->magG - 1.5;
582 if ( magG >= search->magnitudeLow )
583 if ( magG <= search->magnitudeHigh )
585 double x = node.x0 + double( S->dx )/3600/1000/500;
586 double y = node.y0 + double( S->dy )/3600/1000/500;
588 tree.Unproject( star.ra, star.dec, x, y );
589 if ( unlikely( S->dra != 0 ) )
591 star.ra += double( S->dra )/3600/1000/100;
594 else if ( star.ra >= 360 )
597 if ( Distance( search->centerRA, search->centerDec, star.ra, star.dec ) < searchRadius )
601 if ( search->stars.Length() <
size_type( search->sourceLimit ) )
605 star.pmdec = S->pmdec;
607 star.magBP = 0.001*S->magBP - 1.5;
608 star.magRP = 0.001*S->magRP - 1.5;
609 star.flags = S->flags;
611 if ( m_hasSpectrumData )
613 const EncodedStarSPData* SS =
static_cast<const EncodedStarSPData*
>( S );
614 star.flux =
FVector( m_spectrumCount );
615 if ( search->photonFluxUnits )
617 for (
int j = 0; j < m_spectrumCount; ++j )
618 star.flux[j] = (SS->flux[j]*SS->fluxMul + SS->fluxMin) * (m_spectrumStart + j*m_spectrumStep)/1.602e-19/1.239979e-3;
619 if ( search->normalizeSpectrum )
620 star.flux /= star.flux.MaxComponent();
624 if ( search->normalizeSpectrum )
625 for (
int j = 0; j < m_spectrumCount; ++j )
626 star.flux[j] = SS->flux[j]/m_spectrumRange;
628 for (
int j = 0; j < m_spectrumCount; ++j )
629 star.flux[j] = SS->flux[j]*SS->fluxMul + SS->fluxMin;
633 search->stars << star;
636 ++search->excessCount;
642 search->rejectCount += count - matchCount;
643 search->timeDecode += T();
646 friend class GaiaDR2DatabaseFileGenerator;
647 friend class GaiaEDR3DatabaseFileGenerator;
648 friend class GaiaDR3DatabaseFileGenerator;
649 friend class GaiaDR3SPDatabaseFileGenerator;
size_type Length() const noexcept
Dynamic array of 8-bit unsigned integers.
High-resolution time stamp.
A simple exception with an associated error message.
32-bit floating point real vector.
Gaia catalog star database file (XPSD format).
GaiaDatabaseFile(const GaiaDatabaseFile &)=delete
bool HasMeanSpectrumData() const
int SpectrumCount() const
float SpectrumStart() const
GaiaDatabaseFile(const String &filePath)
GaiaDatabaseFile()=default
float SpectrumStep() const
GaiaDatabaseFile & operator=(GaiaDatabaseFile &&)=default
const IsoString & DataRelease() const
void Search(GaiaSearchData &data) const
bool IsEmpty() const noexcept
Generic vector of arbitrary length.
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Point source and star catalog database files (XPSD format).
const XPSD::Metadata & Metadata() const
A first-class data type that can be safely used to implement Boolean process parameters on all suppor...
constexpr T Rad(T x) noexcept
Data items and parameters for Gaia catalog search operations.
pcl_bool normalizeSpectrum
Star data base structure for Gaia catalog search operations.
Star data structure for Gaia catalog search operations.
double radius
Field radius in degrees (search parameter).
double centerDec
Field center declination coordinate in degrees (search parameter).
double centerRA
Field center right ascension coordinate in degrees (search parameter).
double timeTotal
Total search time in seconds (output data).
Data items and parameters for catalog search operations.