Diana Software
QFrameWorkConfig.cc
Go to the documentation of this file.
1 #include "QFrameWorkConfig.hh"
2 #include <fstream>
3 #include <set>
4 
6 
7 QError QFrameWorkConfig::GetModuleByLabel(const std::string& label, QModuleConfig& mod) const
8 {
9 
10  std::vector<QSequenceConfig*>::const_reverse_iterator iter = fSequences.rbegin();
11  while(iter!= fSequences.rend()) {
12  if((*iter)->GetModuleByLabel(label,mod) == QERR_SUCCESS) {
13  return QERR_SUCCESS;
14  }
15  iter++;
16  }
17  return QERR_OUT_OF_RANGE;
18 }
19 
20 
21 void QFrameWorkConfig::Dump(std::ostream& o) const
22 {
23  for(size_t s = 0; s < fSequences.size(); s++) {
24  o<<"sequence "<<fSequences[s]->fName<<std::endl;
25  o<<std::endl;
26  fSequences[s]->Dump(o);
27  o<<"endseq"<<std::endl;
28  o<<std::endl;
29  }
30 }
32 {
33  std::cout<<"Sequence / Original filename"<<std::endl;
34  for(size_t s = 0; s < fSequences.size(); s++) {
35  std::cout<<fSequences[s]->fName<<" / "<<fSequences[s]->fFilename<<std::endl;
36  }
37 }
38 bool QFrameWorkConfig::SaveSequence(const std::string& seq, const std::string& outputfile, bool append) const
39 {
40  QSequenceConfig* sc = 0;
41  for(size_t s = 0; s < fSequences.size(); s++) {
42  if(fSequences[s]->fName == seq) {
43  sc = fSequences[s];
44  break;
45  }
46  }
47  if(!sc) {
48  std::cerr<<"Error: sequence name not found"<<std::endl;
49  return false;
50  }
51 
52  std::string outname = outputfile;
53  if(outname.empty()) outname = sc->fFilename;
54  std::ofstream of;
55  if(append)
56  of.open(outname.c_str(),std::ios::app);
57  else
58  of.open(outname.c_str());
59  if(of.fail()) {
60  std::cerr<<"Cannot open file \""<<outname<<std::endl;
61  return false;
62  }
63  of<<"# Dumped by QFramework config. Original filename: "<<sc->fFilename<<std::endl;
64 
65  of<<"sequence "<<sc->fName<<std::endl;
66  of<<std::endl;
67  sc->Dump(of);
68  of<<"endseq"<<std::endl;
69  of<<std::endl;
70 
71  of.close();
72 
73  return true;
74 }
75 
76 bool QFrameWorkConfig::SaveAllSequences(const std::string& outputfilename) const
77 {
78  if(fSequences.empty()) {
79  std::cerr<<"Error: no sequence available"<<std::endl;
80  return false;
81  }
82  bool ok = true;
83  for(size_t s = 0; s < fSequences.size(); s++) {
84  ok = SaveSequence(fSequences[s]->fName,outputfilename,s!=0);
85  if(!ok) return false;
86  }
87  return true;
88 }
89 
90 bool QFrameWorkConfig::SaveFile(const std::string& origfilename, const std::string& outputfile) const
91 {
92  std::vector<QSequenceConfig*> selected;
93  for(size_t s = 0; s < fSequences.size(); s++) {
94  if(fSequences[s]->fFilename == origfilename) {
95  selected.push_back(fSequences[s]);
96  }
97  }
98  if(selected.empty()) {
99  std::cerr<<"Error: filename not found"<<std::endl;
100  return false;
101  }
102 
103  std::string outname = outputfile;
104  if(outname.empty()) outname = origfilename;
105 
106 
107  bool ok = true;
108  for(size_t s = 0; s < selected.size(); s++) {
109  ok = SaveSequence(selected[s]->fName,outname,s!=0);
110  if(!ok) return false;
111  }
112  return true;
113 }
114 
115 bool QFrameWorkConfig::SaveAllFiles(const std::string& outputdir, const std::string& prefix) const
116 {
117  std::set<std::string> selected;
118 
119  for(size_t s = 0; s < fSequences.size(); s++) {
120  selected.insert(fSequences[s]->fFilename);
121  }
122  if(selected.empty()) {
123  std::cerr<<"Error: filename not found"<<std::endl;
124  return false;
125  }
126  bool ok = true;
127  std::set<std::string>::iterator iter = selected.begin();
128  while(iter != selected.end()) {
129  std::string file = outputdir + "/";
130  file += prefix;
131  file += *iter;
132  ok = SaveFile(*iter,file);
133  if(!ok) return false;
134  iter++;
135  }
136  return true;
137 }
138 
139 
QOptimumFilter of(ap, an,-1, false)
@ QERR_OUT_OF_RANGE
Definition: QError.hh:28
@ QERR_SUCCESS
Definition: QError.hh:27
QObjectImp(QFrameWorkConfig)
error class with error type and description
Definition: QError.hh:115
QObject storing a set of QSecuenceConfigs.
void Dump(std::ostream &o) const
print all sequences to stream
bool SaveSequence(const std::string &seq, const std::string &outputfile="", bool append=false) const
save sequence with name seq to outputfile (defaults to QSequenceConfig::fFilename),...
bool SaveAllSequences(const std::string &outputfilename) const
save all sequences to a single file. Returns true/false in case of success/failure.
bool SaveFile(const std::string &origfilename, const std::string &outputfile="") const
save all sequences belonging to origfilename to outputfile (defaults to origfilename)....
std::vector< QSequenceConfig * > fSequences
QSequenceConfig of all sequences run on this data.
void List() const
list all sequence names and file names
bool SaveAllFiles(const std::string &outputdir=".", const std::string &prefix="") const
calls SaveFile on all files present in the QSequenceConfigs and saves each file (preprnding an option...
QError GetModuleByLabel(const std::string &label, QModuleConfig &mod) const
get QModuleConfig matching label
QObject to store a QBaseModule configuration.
QObject storing a QSequence configuration, a set of QModuleConfigs.
std::string fFilename
file name of this sequence
std::string fName
name of this sequence
void Dump(std::ostream &o) const
dump on stream