aimsdata 6.0.0
Neuroimaging data handling
bckR.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34/*
35 * Bucket reader class
36 */
37#ifndef AIMS_IO_BCKR_H
38#define AIMS_IO_BCKR_H
39
41#include <aims/io/bckItemR.h>
42#include <aims/bucket/bucket.h>
43#include <aims/io/bckheader.h>
44#include <cartobase/exception/ioexcept.h>
46
47
48namespace aims
49{
50
51 template<class T> class AIMSDATA_API BckReader
52 {
53 public:
54 BckReader( const std::string& name ) : _name(name), _itemr( 0 ) {}
55 ~BckReader() { delete _itemr; }
56
57 void read( AimsBucket<T> & thing, int frame = -1 );
59 { delete _itemr; _itemr = ir; }
60
61 private:
62 std::string _name;
64 };
65
66
67 template<class T> inline
68 void BckReader<T>::read( AimsBucket<T> & thing, int frame )
69 {
70 if ( frame >= 0 )
71 std::cerr
72 << "Warning : .bck single frame reading not implemented yet -\n"
73 << "reading whole bucket\n";
74
75 BckHeader hdr( _name );
76 uint32_t buf;
77 hdr.read( &buf );
78 std::ifstream::off_type offset = buf; // ## does not support large files!
79
80 std::string fname = hdr.filename();
81 bool ascii = ( hdr.openMode() == "ascii" );
82 std::ifstream is( fname.c_str(), std::ios::in | std::ios::binary );
83 if ( !is )
85 is.unsetf( std::ios::skipws );
86 is.seekg( offset );
87 if ( !is )
89
90 if ( !ascii )
91 is.unsetf( std::ios::skipws );
92 if ( !_itemr )
94 std::unique_ptr< ItemReader<AimsBucketItem<T> > > ir( _itemr->reader( hdr.openMode(), hdr.byteOrder() != AIMS_MAGIC_NUMBER ) );
96 std::unique_ptr< ItemReader<uint32_t> > sr( sr1.reader( hdr.openMode(), hdr.byteOrder() != AIMS_MAGIC_NUMBER ) );
97
98 thing.clear();
99 thing.setHeader( hdr );
100
101 int size = hdr.dimT();
102 uint32_t time=0, nitem=0;
103 std::string tmp;
104
105 for ( int t=0; t<size; ++t )
106 {
107 if ( ascii )
108 {
109 carto::StreamUtil::skip( is );
110 is >> tmp;
111 if ( tmp != "-time" )
112 throw carto::invalid_format_error( fname );
113 }
114 sr->read( is, time );
115 if ( ascii )
116 {
117 carto::StreamUtil::skip( is );
118 is >> tmp;
119 if ( tmp != "-dim" )
120 throw carto::invalid_format_error( fname );
121 }
122 sr->read( is, nitem );
123 if ( !is )
125 std::list<AimsBucketItem<T> > & items = thing[ time ];
127
128 for ( uint32_t n=0; n<nitem; ++n )
129 {
130 ir->read( is, item );
131 items.push_back(item);
132 }
133 if ( !is )
135 }
136 }
137
138}
139
140
141template<class T> inline
143 AimsBucket<T> & thing )
144{
145 reader.read( thing );
146 return reader;
147}
148
149
150#endif
#define AIMSDATA_API
aims::BckReader< T > & operator>>(aims::BckReader< T > &reader, AimsBucket< T > &thing)
Definition bckR.h:142
The template base class for all types of bucket items.
Definition item.h:63
The bucket base class to manage packages of points associated to their value during time.
Definition bucket.h:70
void setHeader(const aims::PythonHeader &hdr)
Definition bucket.h:149
Descriptor class for the .bck BUCKET file format header.
Definition bckheader.h:52
std::string filename() const
uint byteOrder() const
Definition bckheader.h:72
virtual int dimT() const
Definition bckheader.h:66
void read(uint32_t *offset=0)
std::string openMode() const
Definition bckheader.h:73
BckReader(const std::string &name)
Definition bckR.h:54
void read(AimsBucket< T > &thing, int frame=-1)
Definition bckR.h:68
void setItemReader(ItemReader< T > *ir)
Definition bckR.h:58
Default low-levels readers.
virtual ItemReader< T > * reader(const std::string &openmode="binar", bool bswap=false) const
Low-level "small item" reader, used by higher-level file readers.
Definition itemR.h:99
static void launchErrnoExcept(const std::string &filename="")
#define AIMS_MAGIC_NUMBER
Definition general.h:51
The class for EcatSino data write operation.