QDP++
qdp_map_obj_disk.h
Go to the documentation of this file.
1// -*- C++ -*-
5
6
7#ifndef __qdp_map_obj_disk_h__
8#define __qdp_map_obj_disk_h__
9
10#include "qdp_map_obj.h"
11#include <limits>
12#include <unordered_map>
13
14namespace QDP
15{
16
17 namespace MapObjDiskEnv {
18 typedef unsigned int file_version_t;
19
21 std::string getFileMagic();
22
24 std::string getMetaData(const std::string& filename);
25
27 bool checkForNewFile(const std::string& filename, std::ios_base::openmode mode);
28 };
29
30
31
32
33 //----------------------------------------------------------------------------
35 template<typename K, typename V>
36 class MapObjectDisk : public MapObject<K,V>
37 {
38 public:
40 MapObjectDisk() : file_version(1), state(INIT), level(0) {}
41
44
46 void setDebug(int level);
47
49 int getDebug() const {return level;}
50
52 void open(const std::string& file, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
53
55 bool fileExists(const std::string& file) const {
56 return (! MapObjDiskEnv::checkForNewFile(file, std::ios_base::in));
57 }
58
60 void close();
61
69 int insert(const K& key, const V& val);
70
77 int get(const K& key, V& val) const;
78
79
83 void flush();
84
85
91 bool exist(const K& key) const;
92
96 unsigned int size() const {return static_cast<unsigned long>(src_map.size());}
97
103 void keys(std::vector<K>& keys_) const;
104
111 int insertUserdata(const std::string& user_data);
112
119 int getUserdata(std::string& user_data) const;
120
121 public:
122 typedef std::iostream::pos_type pos_type; // position in buffer
123 typedef std::iostream::off_type off_type; // offset in buffer
124
125 private:
127
133 typedef std::array<uint64_t, 2> priv_pos_type_t;
134
136 typedef std::unordered_map<std::string, priv_pos_type_t> MapType_t;
137
139 enum State {INIT, UNCHANGED, MODIFIED};
140
142 State state;
143
145 int level;
146
149
151 mutable MapType_t src_map;
152
154 std::string filename;
155
157 std::string user_data;
158
160 mutable BinaryFileReaderWriter streamer;
161
163 priv_pos_type_t convertToPrivate(const pos_type& input) const;
164
166 pos_type convertFromPrivate(const priv_pos_type_t& input) const;
167
169 void openWrite(const std::string& file, std::ios_base::openmode mode);
170
172 void openRead(const std::string& file, std::ios_base::openmode mode);
173
174 // Internal Utility: Create/Skip past header
175 void writeSkipHeader(void);
176
178 priv_pos_type_t readCheckHeader(void);
179
181 void writeMapBinary(void);
182
184 void readMapBinary(const priv_pos_type_t& md_start);
185
187 void closeWrite(void);
188
190 void errorState(const std::string err) const {
191 throw err;
192 }
193 };
194
195
196
197 /* ****************** IMPLEMENTATIONS ********************** */
198
200 template<typename K, typename V>
201 void
203 {
204 level = level_;
205 }
206
207
209 template<typename K, typename V>
210 typename MapObjectDisk<K,V>::priv_pos_type_t
211 MapObjectDisk<K,V>::convertToPrivate(const pos_type& input) const
212 {
213 const pos_type max_uint64 = pos_type(std::numeric_limits<uint64_t>::max()) + pos_type(1u);
214 uint64_t less = uint64_t(input % max_uint64);
215 uint64_t more = input / max_uint64;
216 // NOTE comment on priv_pos_type_t
217 return (QDPUtil::big_endian() ? priv_pos_type_t{more, less} : priv_pos_type_t{less, more});
218 }
219
221 template<typename K, typename V>
223 MapObjectDisk<K,V>::convertFromPrivate(const priv_pos_type_t& input) const
224 {
225 const pos_type max_uint64 = pos_type(std::numeric_limits<uint64_t>::max()) + pos_type(1u);
226 // NOTE comment on priv_pos_type_t
227 if (!QDPUtil::big_endian())
228 return pos_type(input[0]) + pos_type(input[1]) * max_uint64;
229 else
230 return pos_type(input[1]) + pos_type(input[0]) * max_uint64;
231 }
232
233
235 template<typename K, typename V>
236 void
237 MapObjectDisk<K,V>::open(const std::string& file, std::ios_base::openmode mode)
238 {
239 if ( MapObjDiskEnv::checkForNewFile(file, mode) )
240 {
241 openWrite(file, mode);
242 }
243 else
244 {
245 openRead(file, mode);
246 }
247 }
248
249
251 template<typename K, typename V>
252 void
253 MapObjectDisk<K,V>::openWrite(const std::string& file, std::ios_base::openmode mode)
254 {
255 switch(state) {
256 case INIT:
257 {
258 filename = file;
259
260 QDPIO::cout << "MapObjectDisk: opening file " << filename
261 << " for writing" << std::endl;
262
263 streamer.open(filename, mode);
264
265 if (level >= 2) {
266 QDPIO::cout << "sizeof(unsigned char) = " << sizeof(unsigned char) << std::endl;
267 QDPIO::cout << "sizeof(int) = " << sizeof(int) << std::endl;
268 QDPIO::cout << "sizeof(pos_type) = " << sizeof(pos_type) << std::endl;
269 QDPIO::cout << "sizeof(priv_pos_type_t) = " << sizeof(priv_pos_type_t) << std::endl;
270 QDPIO::cout << "sizeof(file_version)t) = " << sizeof(MapObjDiskEnv::file_version_t) << std::endl;
271 }
272
273 if (level >= 2) {
274 QDPIO::cout << "Writing file magic: len= " << MapObjDiskEnv::getFileMagic().length() << std::endl;
275 }
276
277 // Write string
278 streamer.writeDesc(MapObjDiskEnv::getFileMagic());
279
280 if (level >= 2) {
281 QDPIO::cout << "Wrote magic. Current Position: " << streamer.currentPosition() << std::endl;
282 }
283
284 write(streamer, (MapObjDiskEnv::file_version_t)file_version);
285
286 if (level >= 2) {
287 QDPIO::cout << "Wrote Version. Current Position is: " << streamer.currentPosition() << std::endl;
288 }
289
290 if (level >= 2) {
291 QDPIO::cout << "Writing User Data string=" << user_data << std::endl;
292 }
293 writeDesc(streamer, user_data);
294
295 if (level >= 2) {
296 QDPIO::cout << "Wrote User Data string. Current Position is: " << streamer.currentPosition() << std::endl;
297 }
298
299 priv_pos_type_t dummypos = convertToPrivate(streamer.currentPosition());
300
301 if (level >= 2) {
302 int user_len = user_data.length();
303 QDPInternal::broadcast(user_len);
304
305 QDPIO::cout << "Sanity Check 1" << std::endl; ;
306 pos_type cur_pos = streamer.currentPosition();
307 pos_type exp_pos =
308 MapObjDiskEnv::getFileMagic().length()+sizeof(int)
309 +user_len+sizeof(int)
311
312 QDPIO::cout << "cur pos=" << (size_t)(cur_pos) << " expected " << (size_t)(exp_pos) << std::endl;
313
314 if ( cur_pos != exp_pos ) {
315 QDPIO::cout << "ERROR: Sanity Check 1 failed." << std::endl;
316 QDPIO::cout << "cur pos=" << (size_t)(cur_pos) << " expected " << (size_t)(exp_pos) << std::endl;
317 QDP_abort(1);
318 }
319 }
320
321 /* Write a dummy link - make room for it */
322 streamer.writeArray((char *)&dummypos, sizeof(priv_pos_type_t), 1);
323
324 if (level >= 2) {
325 QDPIO::cout << "Wrote dummy link: Current Position " << streamer.currentPosition() << std::endl;
326 int user_len = user_data.length();
327 QDPInternal::broadcast(user_len);
328
329 QDPIO::cout << "Sanity Check 2" << std::endl;
330 pos_type cur_pos = streamer.currentPosition();
331 pos_type exp_pos =
332 MapObjDiskEnv::getFileMagic().length()+sizeof(int)
333 +user_len+sizeof(int)
335 +sizeof(priv_pos_type_t);
336
337 if ( cur_pos != exp_pos ) {
338 QDPIO::cout << "Cur pos = " << (size_t)(cur_pos) << std::endl;
339 QDPIO::cout << "Expected: " << (size_t)(exp_pos) << std::endl;
340 QDPIO::cout << "ERROR: Sanity Check 2 failed." << std::endl;
341 QDP_abort(1);
342 }
343 QDPIO::cout << "Finished sanity Check 2" << std::endl;
344 }
345
346 // Advance state machine state
347 state = MODIFIED;
348 break;
349 }
350
351 default:
352 errorState("MapOjectDisk: openWrite called from invalid state");
353 break;
354 }
355
356 return;
357 }
358
359
360
362 template<typename K, typename V>
363 void
364 MapObjectDisk<K,V>::openRead(const std::string& file, std::ios_base::openmode mode)
365 {
366 switch (state) {
367 case INIT:
368 {
369 filename = file;
370
371 QDPIO::cout << "MapObjectDisk: opening file " << filename
372 << " for reading" << std::endl;
373
374 // Open the reader
375 streamer.open(filename, mode);
376
377 QDPIO::cout << "MapObjectDisk: reading and checking header" << std::endl;
378
379 priv_pos_type_t md_start = readCheckHeader();
380
381 // Seek to metadata
382 QDPIO::cout << "MapObjectDisk: reading key/fileposition data" << std::endl;
383
384 /* Read the map in (metadata) */
385 readMapBinary(md_start);
386
387 /* And we are done */
388 state = UNCHANGED;
389 }
390 break;
391 default:
392 errorState("MapObjectDisk: openRead() called from invalid state");
393 break;
394 }
395
396 return;
397 }
398
399
400
402 template<typename K, typename V>
403 void
405 {
406 switch(state) {
407 case UNCHANGED:
408 if( streamer.is_open() ) {
409 streamer.close();
410 }
411 break;
412 case MODIFIED:
413 closeWrite(); // This finalizes files for us
414 if( streamer.is_open() ) {
415 streamer.close();
416 }
417 break;
418 case INIT:
419 break;
420 default:
421 errorState("close: destructor called from invalid state");
422 break;
423 }
424
425 state = INIT;
426 }
427
428
430 template<typename K, typename V>
435
436
438 template<typename K, typename V>
439 void
441 {
442 switch(state) {
443 case MODIFIED:
444 closeWrite(); // not optimal
445 state = UNCHANGED;
446 break;
447 case UNCHANGED:
448 break;
449 case INIT:
450 break;
451 default:
452 break;
453 }
454 }
455
456
458 template<typename K, typename V>
459 void
460 MapObjectDisk<K,V>::keys(std::vector<K>& keys_) const
461 {
462 if( streamer.is_open() )
463 {
464 typename MapType_t::const_iterator iter;
465 for(iter = src_map.begin();
466 iter != src_map.end();
467 ++iter)
468 {
469 BinaryBufferReader bin(iter->first);
470 K key;
471 read(bin, key);
472 keys_.push_back(key);
473 }
474 }
475 }
476
477
481 template<typename K, typename V>
482 int
483 MapObjectDisk<K,V>::insertUserdata(const std::string& _user_data)
484 {
485 int ret = 0;
486 switch(state) {
487 case INIT:
488 user_data = _user_data;
489 break;
490
491 case UNCHANGED:
492 case MODIFIED:
493 ret = 1;
494 break;
495
496 default:
497 errorState("MapObjectDisk::insertUserdata() called from invalid state");
498 break;
499 }
500
501 return ret;
502 }
503
504
511 template<typename K, typename V>
512 int
513 MapObjectDisk<K,V>::getUserdata(std::string& _user_data) const
514 {
515 int ret = 0;
516
517 switch(state) {
518 case INIT:
519 {
520 ret = 1;
521 break;
522 }
523 case UNCHANGED:
524 case MODIFIED:
525 {
526 _user_data = user_data;
527 break;
528 }
529 default:
530 errorState("MapObjectDisk::getUserdata called from unknown state");
531 break;
532 }
533
534 return ret;
535 }
536
537
541 template<typename K, typename V>
542 int
543 MapObjectDisk<K,V>::insert(const K& key, const V& val)
544 {
545 int ret = 0;
546
547 switch (state) {
548 case MODIFIED :
549 case UNCHANGED : {
550 // Find key
552 write(bin, key);
553 typename MapType_t::const_iterator key_ptr = src_map.find(bin.str());
554
555 if (key_ptr != src_map.end()) {
556 // Key does exist
557 pos_type wpos = convertFromPrivate(key_ptr->second);
558 if (level >= 2) {
559 QDPIO::cout << "Found key to update. Position is " << wpos << std::endl;
560 }
561
562 streamer.seek(wpos);
563
564 if (level >= 2) {
565 QDPIO::cout << "Sought write position. Current Position: " << streamer.currentPosition() << std::endl;
566 }
567 streamer.resetChecksum(); // Reset checksum. It gets calculated on write.
568 write(streamer, val);
569
570 if (level >= 2) {
571 QDPIO::cout << "Wrote value to disk. Current Position: " << streamer.currentPosition() << std::endl;
572 }
573 write(streamer, streamer.getChecksum()); // Write Checksum
574 streamer.flush(); // Sync the file
575
576 if (level >= 2) {
577 QDPIO::cout << "Wrote checksum " << streamer.getChecksum() << " to disk. Current Position: " << streamer.currentPosition() << std::endl;
578 }
579
580 // Done
581 state = MODIFIED;
582 }
583 else {
584 // Key does not exist
585
586 // Make note of current writer position
587 pos_type pos = streamer.currentPosition();
588
589 // Insert pos into map
590 src_map.insert(std::make_pair(bin.str(), convertToPrivate(pos)));
591
592 streamer.resetChecksum();
593
594 // Add position to the map
595 StopWatch swatch;
596 swatch.reset();
597 swatch.start();
598
599 write(streamer, val); // DO write
600 swatch.stop();
601
602 // Get diagnostics.
603 if (level >= 1) {
604 pos_type end_pos = streamer.currentPosition();
605 double MiBWritten = (double)(end_pos - pos)/(double)(1024*1024);
606 double time = swatch.getTimeInSeconds();
607
608 QDPIO::cout << " wrote: " << MiBWritten << " MiB. Time: " << time << " sec. Write Bandwidth: " << MiBWritten/time<<std::endl;
609 }
610
611 if (level >= 2) {
612 QDPIO::cout << "Wrote value to disk. Current Position: " << streamer.currentPosition() << std::endl;
613 }
614
615 write(streamer, streamer.getChecksum()); // Write Checksum
616 streamer.flush();
617
618 if (level >= 2) {
619 QDPIO::cout << "Wrote checksum " << streamer.getChecksum() << " to disk. Current Position: " << streamer.currentPosition() << std::endl;
620 }
621
622 // Done
623 state = MODIFIED;
624 }
625 break;
626 }
627 default:
628 ret = 1;
629 break;
630 }
631
632 return ret;
633 }
634
635
636
640 template<typename K, typename V>
641 int
642 MapObjectDisk<K,V>::get(const K& key, V& val) const
643 {
644 int ret = 0;
645
646 switch(state) {
647 case UNCHANGED: // Deliberate fallthrough
648 case MODIFIED: {
650 write(bin, key);
651 typename MapType_t::const_iterator key_ptr = src_map.find(bin.str());
652
653 if (key_ptr != src_map.end())
654 {
655 // If key exists find file offset
656 pos_type pos = convertFromPrivate(key_ptr->second);
657
658 // Do the seek and time it
659 StopWatch swatch;
660
661 swatch.reset();
662 swatch.start();
663 streamer.seek(pos);
664 swatch.stop();
665 double seek_time = swatch.getTimeInSeconds();
666
667 // Reset the checkums
668 streamer.resetChecksum();
669
670 // Grab start pos: We've just seeked it
671 pos_type start_pos = pos;
672
673 // Time the read
674 swatch.reset();
675 swatch.start();
676 read(streamer, val);
677 swatch.stop();
678
679 double read_time = swatch.getTimeInSeconds();
680 pos_type end_pos = streamer.currentPosition();
681
682 // Print data
683 if (level >= 1) {
684 double MiBRead = (double)(end_pos - start_pos)/(double)(1024*1024);
685 QDPIO::cout << " seek time: " << seek_time
686 << " sec. read time: " << read_time
687 << " " << MiBRead <<" MiB, " << MiBRead/read_time << " MiB/sec" << std::endl;
688 }
689
690
691 if (level >= 2) {
692 QDPIO::cout << "Read record. Current position: " << streamer.currentPosition() << std::endl;
693 }
694
695 QDPUtil::n_uint32_t calc_checksum=streamer.getChecksum();
696 QDPUtil::n_uint32_t read_checksum;
697 read(streamer, read_checksum);
698
699 if (level >= 2) {
700 QDPIO::cout << " Record checksum: " << read_checksum << " Current Position: " << streamer.currentPosition() << std::endl;
701 }
702
703 if( read_checksum != calc_checksum ) {
704 QDPIO::cout << "Mismatched Checksums: Expected: " << calc_checksum << " but read " << read_checksum << std::endl;
705 QDP_abort(1);
706 }
707
708 if (level >= 2) {
709 QDPIO::cout << " Checksum OK!" << std::endl;
710 }
711 }
712 else {
713 ret = 1;
714 }
715 break;
716 }
717 default:
718 ret = 1;
719 break;
720 }
721
722 return ret;
723 }
724
725
731 template<typename K, typename V>
732 bool
733 MapObjectDisk<K,V>::exist(const K& key) const
734 {
736 write(bin, key);
737 return (src_map.find(bin.str()) == src_map.end()) ? false : true;
738 }
739
740
741
742 /***************** UTILITY ******************/
743
744
746 template<typename K, typename V>
747 void
748 MapObjectDisk<K,V>::writeSkipHeader(void)
749 {
750 switch(state) {
751 case MODIFIED: {
752 if ( streamer.is_open() )
753 {
754 int user_len = user_data.length();
755 QDPInternal::broadcast(user_len);
756
757 streamer.seek( MapObjDiskEnv::getFileMagic().length() + sizeof(int)
758 + user_len + sizeof(int)
760 }
761 else {
762 QDPIO::cerr << "Attempting writeSkipHeader, not in write mode" <<std::endl;
763 QDP_abort(1);
764 }
765 }
766 break;
767 default:
768 errorState("MapObjectDisk: writeSkipHeader() called not in MODIFIED state");
769 break;
770 }
771 }
772
774 template<typename K, typename V>
775 typename MapObjectDisk<K,V>::priv_pos_type_t
776 MapObjectDisk<K,V>::readCheckHeader(void)
777 {
778 priv_pos_type_t md_position{0, 0};
779
780 if( streamer.is_open() )
781 {
782 if (level >= 2) {
783 QDPIO::cout << "Rewinding File" << std::endl;
784 }
785
786 streamer.rewind();
787
788 std::string read_magic;
789 streamer.readDesc(read_magic);
790
791 // Check magic
792 if (read_magic != MapObjDiskEnv::getFileMagic()) {
793 QDPIO::cerr << "Magic String Wrong: Expected: " << MapObjDiskEnv::getFileMagic()
794 << " but read: " << read_magic << std::endl;
795 QDP_abort(1);
796 }
797
798 if (level >= 2) {
799 QDPIO::cout << "Read File Magic. Current Position: " << streamer.currentPosition() << std::endl;
800 }
801
803 read(streamer, read_version);
804
805 if (level >= 2) {
806 QDPIO::cout << "Read File Verion. Current Position: " << streamer.currentPosition() << std::endl;
807 }
808
809 // Check version
810 QDPIO::cout << "MapObjectDisk: file has version: " << read_version << std::endl;
811
812 QDP::readDesc(streamer, user_data);
813 if (level >= 2) {
814 QDPIO::cout << "User data. String=" << user_data << ". Current Position: " << streamer.currentPosition() << std::endl;
815 }
816
817 // Read MD location
818 streamer.readArray((char *)&md_position, sizeof(priv_pos_type_t), 1);
819
820 if (level >= 2) {
821 QDPIO::cout << "Read MD Location. Current position: " << streamer.currentPosition() << std::endl;
822 }
823
824 if (level >= 2) {
825 QDPIO::cout << "Metadata starts at position: " << convertFromPrivate(md_position) << std::endl;
826 }
827
828 }
829 else {
830 QDPIO::cerr << "readCheckHeader needs reader mode to be opened. It is not" << std::endl;
831 QDP_abort(1);
832 }
833
834 return md_position;
835 }
836
838 // Private utility function -- no one else should use.
839 template<typename K, typename V>
840 void
841 MapObjectDisk<K,V>::writeMapBinary(void)
842 {
843 unsigned int map_size = src_map.size();
844
845 streamer.resetChecksum();
846 write(streamer, map_size);
847 if (level >= 2) {
848 QDPIO::cout << "Wrote map size: " << map_size << " entries. Current position : " << streamer.currentPosition() << std::endl;
849 }
850
851 typename MapType_t::const_iterator iter;
852 for(iter = src_map.begin();
853 iter != src_map.end();
854 ++iter)
855 {
856 priv_pos_type_t pos=iter->second;
857
858 writeDesc(streamer, iter->first);
859 streamer.writeArray((char *)&pos,sizeof(priv_pos_type_t),1);
860
861 if (level >= 2) {
862 QDPIO::cout << "Wrote Key/Position pair: Current Position: " << streamer.currentPosition() << std::endl;
863 }
864 }
865 write(streamer, streamer.getChecksum());
866 QDPIO::cout << "Wrote Checksum On Map: " << streamer.getChecksum() << std::endl;
867 streamer.flush();
868 }
869
871 // assume positioned at start of map data
872 // Private utility function -- no one else should use.
873 template<typename K, typename V>
874 void
875 MapObjectDisk<K,V>::readMapBinary(const priv_pos_type_t& md_start)
876 {
877 streamer.seek(convertFromPrivate(md_start));
878 streamer.resetChecksum();
879
880 if (level >= 2) {
881 QDPIO::cout << "Sought start of metadata. Current position: " << streamer.currentPosition() << std::endl;
882 }
883
884 unsigned int num_records;
885 read(streamer, num_records);
886
887 if (level >= 2) {
888 QDPIO::cout << "Read num of entries: " << num_records << " records. Current Position: " << streamer.currentPosition() << std::endl;
889 }
890
891 for(unsigned int i=0; i < num_records; i++)
892 {
893 priv_pos_type_t rpos;
894 std::string key_str;
895 readDesc(streamer, key_str);
896
897 streamer.readArray((char *)&rpos, sizeof(priv_pos_type_t),1);
898
899 if (level >= 2) {
900 QDPIO::cout << "Read Key/Position pair. Current position: " << streamer.currentPosition() << std::endl;
901 }
902 // Add position to the map
903 src_map.insert(std::make_pair(key_str,rpos));
904 }
905 QDPUtil::n_uint32_t calc_checksum = streamer.getChecksum();
906 QDPUtil::n_uint32_t read_checksum;
907 read(streamer, read_checksum);
908
909 if (level >= 2) {
910 QDPIO::cout << "Read Map checksum: " << read_checksum << " Current Position: " << streamer.currentPosition();
911 }
912 if( read_checksum != calc_checksum ) {
913 QDPIO::cout << "Mismatched Checksums: Expected: " << calc_checksum << " but read " << read_checksum << std::endl;
914 QDP_abort(1);
915 }
916
917 if (level >= 2) {
918 QDPIO::cout << " Map Checksum OK!" << std::endl;
919 }
920 }
921
922
923
929 template<typename K, typename V>
930 void
931 MapObjectDisk<K,V>::closeWrite(void)
932 {
933 switch(state) {
934 case MODIFIED:
935 {
936 if (level >= 2) {
937 QDPIO::cout << "Beginning closeWrite: current position: " << streamer.currentPosition() << std::endl;
938 }
939
940 // Go to end of file
941 streamer.seekEnd(0);
942
943 // Take note of current position
944 priv_pos_type_t metadata_start = convertToPrivate(streamer.currentPosition());
945
946 if (level >= 2) {
947 QDPIO::cout << "CloseWrite: Metadata starts at position: " << convertFromPrivate(metadata_start) << std::endl;
948 }
949
950 // Dump metadata
951 writeMapBinary();
952
953 // Rewind and Skip header
954 streamer.rewind();
955 if (level >= 2) {
956 QDPIO::cout << "Rewound file. Current Position: " << streamer.currentPosition() << std::endl;
957 }
958 writeSkipHeader();
959 if (level >= 2) {
960 QDPIO::cout << "Skipped Header. Current Position: " << streamer.currentPosition() << std::endl;
961 }
962 // write start position of metadata
963 streamer.writeArray((const char *)&metadata_start,sizeof(priv_pos_type_t),1);
964
965 if (level >= 2) {
966 QDPIO::cout << "Wrote link to metadata. Current Position: " << streamer.currentPosition() << std::endl;
967 }
968
969 // skip to end and close
970 streamer.seekEnd(0);
971 streamer.flush();
972
973 QDPIO::cout << "MapObjectDisk: Closed file " << filename<< " for write access" << std::endl;
974 }
975 break;
976 default:
977 errorState("MapObjectDisk: closeWrite() called in an invalid state");
978 break;
979 }
980 }
981
982
983} // namespace Chroma
984
985#endif
Binary buffer input class.
Definition qdp_io.h:905
Binary buffer output class.
Definition qdp_io.h:1390
std::string str() const
Return entire buffer as a string.
Definition qdp_io.cc:1372
Binary file input/output class.
Definition qdp_io.h:1626
void flush()
Destructor.
~MapObjectDisk()
Finalizes object.
std::iostream::pos_type pos_type
MapObjectDisk()
Empty constructor.
unsigned int size() const
int insert(const K &key, const V &val)
std::iostream::off_type off_type
void setDebug(int level)
Set debugging level.
int insertUserdata(const std::string &user_data)
void close()
Close the file.
int get(const K &key, V &val) const
bool exist(const K &key) const
void open(const std::string &file, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Open a file.
int getDebug() const
Get debugging level.
bool fileExists(const std::string &file) const
Check if a DB file exists before opening.
void keys(std::vector< K > &keys_) const
Dump keys.
int getUserdata(std::string &user_data) const
A wrapper over maps.
Definition qdp_map_obj.h:21
void write(BinaryWriter &bin, const std::string &output)
Definition qdp_io.cc:1204
void readDesc(BinaryReader &bin, std::string &input)
Definition qdp_io.cc:774
void writeDesc(BinaryWriter &bin, const std::string &output)
Definition qdp_io.cc:1200
void read(BinaryReader &bin, std::string &input, size_t maxBytes)
Definition qdp_io.cc:778
void close(QDPFileReader &qsw)
Close a QDPFileReader.
Definition qdp_qdpio.cc:207
double getTimeInSeconds()
Get time in seconds.
void reset()
Reset the timer.
void start()
Start the timer.
void stop()
Stop the timer.
unsigned int n_uint32_t
bool big_endian()
Is the native byte order big endian?
bool checkForNewFile(const std::string &file, std::ios_base::openmode mode)
Check if this will be a new file.
std::string getFileMagic()
Get the file magic.
unsigned int file_version_t
std::string getMetaData(const std::string &filename)
Get the meta-data from a file.
StandardOutputStream cout
Definition qdp_stdio.cc:21
StandardOutputStream cerr
Definition qdp_stdio.cc:22
void broadcast(T &dest)
Broadcast from primary node to all other nodes.
Yet another random number generator.
void QDP_abort(int status)
Panic button.
Wrapper over maps.