1 | #include "brdiskw.h"
|
---|
2 | #include <exception>
|
---|
3 | #include "timestamp.h"
|
---|
4 | #include "ctimer.h"
|
---|
5 |
|
---|
6 | using namespace SOPHYA;
|
---|
7 | //----------------------------------------------------------------
|
---|
8 | // Projet BAORadio - (C) LAL/IRFU 2008-2010
|
---|
9 | // Classes de threads ecriture de donnees traitees BAORadio
|
---|
10 | //----------------------------------------------------------------
|
---|
11 |
|
---|
12 | //----------------------------------------------------------------
|
---|
13 | // ---- Classe FitsCubeWriter :
|
---|
14 | // Ecriture de fichier FITS BAORadio 3D (plusieurs fibres dans un fichier)
|
---|
15 | //----------------------------------------------------------------
|
---|
16 | /*!
|
---|
17 | \class FitsCubeWriter
|
---|
18 | \ingroup TAcq
|
---|
19 |
|
---|
20 | \brief Writes data from multiple fibers into a single FITS file as a 3D array.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /* --Methode-- */
|
---|
24 | FitsCubeWriter::FitsCubeWriter(RAcqMemZoneMgr& mmgr, string outpath, uint_4 nblocperfile)
|
---|
25 | : memgr_(mmgr), outpath_(outpath), nblocperfile_(nblocperfile)
|
---|
26 | {
|
---|
27 | stop_ = false;
|
---|
28 | numfile_=0;
|
---|
29 | totnbyteswrt_=0;
|
---|
30 | }
|
---|
31 |
|
---|
32 | /* --Methode-- */
|
---|
33 | void FitsCubeWriter::run()
|
---|
34 | {
|
---|
35 | try {
|
---|
36 | TimeStamp ts;
|
---|
37 | Timer tm("FitsCubeWriter", false);
|
---|
38 |
|
---|
39 | uint_4 paqsz = memgr_.PaqSize();
|
---|
40 | cout << " FitsCubeWriter::run() - Starting NBloc/File=" << nblocperfile_ << " PaqSz=" << paqsz << endl;
|
---|
41 | vector<Byte*> fbuff;
|
---|
42 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) fbuff.push_back(NULL);
|
---|
43 |
|
---|
44 | size_t npaqperfile = memgr_.NbPaquets()*nblocperfile_; // Nombre de paquets ecrits dans un fichier
|
---|
45 |
|
---|
46 | bool fgrun=true;
|
---|
47 | MiniFITSFile mff;
|
---|
48 | uint_4 numblk=0;
|
---|
49 | char fname[1024];
|
---|
50 | while (fgrun) {
|
---|
51 | if (stop_) break;
|
---|
52 | if (memgr_.GetRunState() == MemZR_Stopped) break;
|
---|
53 | int mid = memgr_.FindMemZoneId(MemZA_Save);
|
---|
54 | Byte* buffg = memgr_.GetMemZone(mid);
|
---|
55 | if (buffg == NULL) {
|
---|
56 | cout << "FitsCubeWriter::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
---|
57 | setRC(7); fgrun=false;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | if (numblk%nblocperfile_ == 0) {
|
---|
61 | if (mff.IsOpen()) {
|
---|
62 | mff.Close();
|
---|
63 | cout << " FitsCubeWriter::run() " << numfile_ << " End write file" << fname << endl;
|
---|
64 | }
|
---|
65 | sprintf(fname,"%ssig3d%d.fits",outpath_.c_str(),(int)numfile_);
|
---|
66 | mff.Open(fname, MF_Write);
|
---|
67 | mff.setDTypeNaxis(MF_Byte, paqsz, memgr_.NbFibres(), npaqperfile);
|
---|
68 | numfile_++;
|
---|
69 | }
|
---|
70 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
71 | fbuff[fib] = memgr_.GetMemZone(mid,fib);
|
---|
72 | if (fbuff[fib] == NULL) { // cela ne devrait pas arriver
|
---|
73 | cout << "FitsCubeWriter::run()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
|
---|
74 | setRC(9); fgrun=false;
|
---|
75 | break;
|
---|
76 | }
|
---|
77 | for(size_t jp=0; jp<memgr_.NbPaquets(); jp++) {
|
---|
78 | mff.WriteB(fbuff[fib],paqsz); // ecriture
|
---|
79 | totnbyteswrt_+=paqsz;
|
---|
80 | }
|
---|
81 | } // Fin de la boucle sur les fibres
|
---|
82 | memgr_.FreeMemZone(mid, MemZS_Saved);
|
---|
83 | numblk++;
|
---|
84 | } // Fin de boucle sur les zones a traiter
|
---|
85 | //------------------------------------
|
---|
86 | cout << " ------------------ FitsCubeWriter::run() END ----------------- " << endl;
|
---|
87 | // ts.SetNow();
|
---|
88 | tm.SplitQ();
|
---|
89 | // cout << " END writing : " << ts ;
|
---|
90 | cout << " TotalDiskWrite= " << totnbyteswrt_/(1024*1024) << " MBytes Disk-Write rate= "
|
---|
91 | << (double)(totnbyteswrt_)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;
|
---|
92 | // cout << " FitsCubeWriter::run()/Timing: \n"; tm.Print();
|
---|
93 | cout << " --------------------------------------------------------------- " << endl;
|
---|
94 | }
|
---|
95 | catch (MiniFITSException& exc) {
|
---|
96 | cout << " FitsCubeWriter::run()/catched MiniFITSException " << exc.Msg() << endl;
|
---|
97 | setRC(5);
|
---|
98 | return;
|
---|
99 | }
|
---|
100 | catch (std::exception& exc) {
|
---|
101 | cout << " FitsCubeWriter::run()/catched std::exception : " << exc.what() << endl;
|
---|
102 | setRC(5);
|
---|
103 | return;
|
---|
104 | }
|
---|
105 | catch(...) {
|
---|
106 | cout << " FitsCubeWriter::run()/catched unknown ... exception " << endl;
|
---|
107 | setRC(5);
|
---|
108 | return;
|
---|
109 | }
|
---|
110 |
|
---|
111 | }
|
---|