source: Sophya/trunk/SophyaExt/FitsIOServer/fitsmanager.cc@ 2864

Last change on this file since 2864 was 2864, checked in by ansari, 20 years ago

1/ Ajout methode CheckReadability() , retour int pour CheckHandling() ds l'interface FitsHandler et propagation vers handler TArray et DataTable
2/ Correction dans FitsManager et ajout initialiseur de module FitsIOServer (fiosinit.h .cc)
3/ FitsSwapper complete - corrige - full template (suppression de fitsswapper.cc)
4/ MAJ Makefile et objlist.list suite ajout fiosinit.cc et swfitsdtable

Reza , 2 Jan 2006

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#include "machdefs.h"
2#include "sopnamsp.h"
3
4#include <stdio.h>
5#include <string.h>
6#include <iostream>
7#include <typeinfo>
8
9#include "fitsmanager.h"
10#include "fitshandler.h"
11
12struct hand_list_el {
13 FitsHandlerInterface * fhi;
14 string clname;
15};
16
17typedef list<hand_list_el> HandlerList;
18
19static HandlerList * hlistp = NULL;
20
21static inline void ChkHLP()
22{
23 if (hlistp == NULL) hlistp = new HandlerList;
24}
25
26int FitsManager::RegisterHandler(FitsHandlerInterface * fhi, string clname)
27{
28 ChkHLP();
29 if (fhi == NULL)
30 throw NullPtrError("FitsManager::RegisterHandler() fhi=NULL ");
31 HandlerList::iterator it;
32 for(it = hlistp->begin(); it != hlistp->end(); it++) {
33 if (typeid(*((*it).fhi)) == typeid(*fhi))
34 throw DuplicateIdExc("FitsManager::RegisterHandler() Already registered handler");
35 }
36 hand_list_el hle;
37 hle.fhi = fhi;
38 hle.clname = clname;
39 hlistp->push_back(hle);
40 return hlistp->size();
41}
42
43int FitsManager::ListHandlers()
44{
45 ChkHLP();
46 int kk=0;
47 cout << "---- FitsManager::ListHandlers() NbHandlers= " << hlistp->size()
48 << endl;
49 HandlerList::iterator it;
50 for(it = hlistp->begin(); it != hlistp->end(); it++) {
51 kk++;
52 cout << kk << "- " << (*it).clname << " : "
53 << typeid(*((*it).fhi)).name() << endl;
54 }
55 return hlistp->size();
56}
57
58FitsHandlerInterface* FitsManager::FindHandler(AnyDataObj & o)
59{
60 ChkHLP();
61 FitsHandlerInterface * fhi = NULL;
62 HandlerList::iterator it;
63 int hfg = 0;
64 int bhfg = 0;
65 for(it = hlistp->begin(); it != hlistp->end(); it++) {
66 hfg = (*it).fhi->CheckHandling(o);
67 if ( hfg > bhfg ) {
68 fhi = (*it).fhi; bhfg = hfg;
69 }
70 }
71 if (fhi == NULL) {
72 string msg = "FitsManager::FindHandler() Handler not found for ";
73 msg += typeid(o).name();
74 throw NotFoundExc(msg);
75 }
76 else return fhi;
77}
78
79void FitsManager::Write(FitsInOutFile& os, AnyDataObj & o)
80{
81 FitsHandlerInterface * fhi2 = FindHandler(o)->Clone();
82 fhi2->SetDataObj(o);
83 fhi2->Write(os);
84 return;
85}
86
87void FitsManager::Read(FitsInOutFile& is, AnyDataObj & o)
88{
89 FitsHandlerInterface * fhi2 = FindHandler(o)->Clone();
90 fhi2->SetDataObj(o);
91 fhi2->Read(is);
92 delete fhi2;
93 return;
94}
95
96FitsHandlerInterface * FitsManager::FindReader(FitsInOutFile& is)
97{
98 ChkHLP();
99 FitsHandlerInterface * fhi = NULL;
100 HandlerList::iterator it;
101 int hfg = 0;
102 int bhfg = 0;
103 for(it = hlistp->begin(); it != hlistp->end(); it++) {
104 hfg = (*it).fhi->CheckReadability(is);
105 if ( hfg > bhfg ) {
106 fhi = (*it).fhi; bhfg = hfg;
107 }
108 }
109 if (fhi == NULL) {
110 string msg = "FitsManager::FindReader() Reader/Handler not found ";
111 msg += is.FileName();
112 char buff[64];
113 sprintf(buff, " HDU= %d Type= %d", (int)(is.CurrentHDU()),
114 (int)(is.CurrentHDUType()) );
115 msg += buff;
116 throw NotFoundExc(msg);
117 }
118 else return fhi;
119}
120
121FitsHandlerInterface * FitsManager::Read(FitsInOutFile& is)
122{
123 FitsHandlerInterface * fhi2 = FindReader(is)->Clone();
124 fhi2->Read(is);
125 return fhi2;
126}
Note: See TracBrowser for help on using the repository browser.