27 me =
new QModuleFactory();
42 std::list<QSequence*>::iterator it;
43 for(it = sequences.begin(); it != sequences.end(); it++)
44 if((*it)->GetName() == s)
return *it;
59 if(reader)
return reader;
68 if(filter)
return filter;
77 if(driver)
return driver;
87 if(writer)
return writer;
98 if(module)
return module;
112 size_t lineCounter = 0;
114 std::map<std::string,std::string> userConfigFile;
120 std::ifstream in2(fname.c_str());
128 while(getline(in2,line)) {
135 if ( pos != std::string::npos )
146 pos = line.find(
'=');
147 if ( pos != std::string::npos ) {
148 std::string key = line.substr(0,line.find(
'='));
151 std::string value = line.substr(line.find(
'=')+1,std::string::npos);
154 userConfigFile[key] = ReplaceCFGVar(value);
157 snprintf(cfgerr,128,
"Syntax error in cfg file, line %u: \"%s\"",(
unsigned int)lineCounter,line.c_str());
158 throw std::runtime_error(cfgerr);
164 catch(std::exception& ex) {
166 snprintf(buf,512,
"Syntax error in pfg file: %s",ex.what());
173 std::ifstream in(fname.c_str());
175 throw std::runtime_error(
"Cannot find configuration file: " + fname );
180 std::vector<std::pair<std::string, int> > cfgFileLines;
182 while(getline(in,line)) {
183 cfgFileLines.push_back(std::make_pair(line, lineno));
187 std::string frameworkSection =
"";
188 std::string current_loader =
"";
189 std::string current_var =
"";
190 std::string current_module=
"";
191 std::string current_sequence=
"";
192 std::string current_group=
"";
193 std::vector<std::pair<std::string, std::string> > current_group_options;
194 std::vector<std::string> alias_files;
195 QBaseModule *p_Module=NULL;
199 for(
size_t lineCounter = 0; lineCounter < cfgFileLines.size(); lineCounter++) {
200 std::string line = cfgFileLines[lineCounter].first;
201 int fileLineNum = cfgFileLines[lineCounter].second;
207 if ( pos != std::string::npos )
218 if(frameworkSection ==
"") {
219 if (current_loader !=
"") {
221 snprintf(cfgerr,128,
"Syntax error in cfg file, line %u: \"%s\"",(
unsigned int)fileLineNum,line.c_str());
222 throw std::runtime_error(cfgerr);
225 if( s ==
"framework") {
226 frameworkSection =
"framework";
231 }
else if (current_loader ==
"" || current_var ==
"") {
232 if(line ==
"endfw") {
233 current_loader =
".";
237 s = line.substr(0,line.find(
' '));
239 current_loader = line.substr(line.find(
' ')+1,std::string::npos);
240 LoadLoadable(current_loader);
244 else if ( s ==
"cfgvar" ) {
245 std::string key = line.substr(line.find(
' '),std::string::npos);
246 key = key.substr(0,key.find(
'='));
249 std::string value = line.substr(line.find(
'=')+1,std::string::npos);
253 std::string fullname = std::string(
"CFGVar.")+key;
264 }
else if ( s ==
"groupfile" ) {
265 std::string file_name = line.substr(line.find(
' ')+1,std::string::npos);
266 alias_files.push_back(ReplaceCFGVar(file_name));
271 snprintf(cfgerr,128,
"Syntax error in cfg file, line %u: \"%s\"",(
unsigned int)fileLineNum,line.c_str());
276 if ( current_sequence ==
"") {
278 if (current_module !=
"") {
280 snprintf(cfgerr,128,
"Syntax error in cfg file, line %u: \"%s\"",(
unsigned int)fileLineNum,line.c_str());
281 throw std::runtime_error(cfgerr);
284 s = line.substr(0,line.find(
' '));
285 if ( s ==
"sequence" ) {
286 current_sequence = line.substr(line.find(
' ') + 1, std::string::npos);
289 if ( FindSequence(current_sequence) != NULL ) {
290 throw std::runtime_error(
"Sequence: "+current_sequence+
" already exist!");
294 p_Sequence =
new QSequence(current_sequence);
299 if(!driver.empty()) {
302 p_Sequence->
p_Driver = CreateDriver(driver, p_Sequence);
308 snprintf(cfgerr,128,
"Syntax error in cfg file, line %u: \"%s\"",(
unsigned int)fileLineNum,line.c_str());
309 throw std::runtime_error(cfgerr);
311 sequences.push_back(p_Sequence);
317 snprintf(cfgerr,128,
"Syntax error in cfg file, line %u: \"%s\"",(
unsigned int)fileLineNum,line.c_str());
318 throw std::runtime_error(cfgerr);
322 if (current_module ==
"") {
323 if (line==
"endseq") {
329 s = line.substr(0,line.find(
' '));
330 if ( s ==
"module" ) {
331 current_module = line.substr(line.find(
' ')+1,std::string::npos);
332 p_Sequence->
modules.push_back(CreateModule(current_module, p_Sequence));
333 p_Module = p_Sequence->
modules.back();
336 if ( s ==
"reader" ) {
337 current_module = line.substr(line.find(
' ')+1,std::string::npos);
338 p_Sequence->
p_Reader = CreateReader(current_module, p_Sequence);
342 if ( s ==
"writer" ) {
343 current_module = line.substr(line.find(
' ')+1,std::string::npos);
344 p_Sequence->
p_Writer = CreateWriter(current_module, p_Sequence);
348 if ( s ==
"filter" ) {
349 current_module = line.substr(line.find(
' ')+1,std::string::npos);
350 p_Sequence->
modules.push_back(CreateFilter(current_module, p_Sequence));
351 p_Module = p_Sequence->
modules.back();
354 if ( s ==
"includegroup" ) {
355 current_module =
"includegroup";
356 current_group = line.substr(line.find(
' ')+1,std::string::npos);
359 if ( s ==
"driver" ) {
360 current_module = line.substr(line.find(
' ')+1,std::string::npos);
361 p_Sequence->
p_Driver = CreateDriver(current_module, p_Sequence);
367 pos = line.find(
'=');
368 if ( pos != std::string::npos ) {
369 std::string key = line.substr(0,line.find(
'='));
372 std::string value = line.substr(line.find(
'=')+1,std::string::npos);
376 if (current_module ==
"includegroup") {
377 current_group_options.push_back(make_pair(key, value));
382 value = ReplaceCFGVar(value);
383 QOptions::GetInstance().SetParameter(current_sequence,current_module,p_Module->GetOccurrence(),key, value);
388 snprintf(obuf,128,
"%u",(
unsigned int)p_Module->GetOccurrence());
389 std::string upk = current_sequence+
"."+current_module+
"."+obuf+
"."+key;
391 if(userConfigFile.find(upk) == userConfigFile.end()) {
393 snprintf(buf,256,
"Syntax error in cfg file, line %u: %s",(
unsigned int)fileLineNum,
err.GetDescription().c_str());
397 catch(std::exception& ex) {
399 snprintf(obuf,128,
"%u",(
unsigned int)p_Module->GetOccurrence());
400 std::string upk = current_sequence+
"."+current_module+
"."+obuf+
"."+key;
402 if(userConfigFile.find(upk) == userConfigFile.end()) {
404 snprintf(buf,512,
"Syntax error in cfg file, line %u: %s",(
unsigned int)fileLineNum,ex.what());
413 if ( line ==
"endmod") {
415 if (current_module ==
"includegroup") {
416 AddAliasGroup(cfgFileLines, lineCounter, alias_files, current_group, current_group_options);
423 snprintf(cfgerr,128,
"Syntax error in cfg file, line %u: \"%s\"",(
unsigned int)fileLineNum,line.c_str());
424 throw std::runtime_error(cfgerr);
438 std::map<std::string,std::string>::const_iterator up = userConfigFile.begin();
439 while(up != userConfigFile.end()) {
446 std::stringstream msg;
458 std::list<QSequence* >::iterator it;
459 for( it = sequences.begin(); it != sequences.end(); it++) {
467 std::string retstring = value;
468 size_t rightbr = std::string::npos;
470 size_t leftbr = retstring.find(
"${");
471 rightbr = std::string::npos;
472 if(leftbr != std::string::npos) {
473 rightbr = retstring.find_first_of(
"}");
475 if(rightbr != std::string::npos) {
476 std::string varname = retstring.substr(leftbr+2,rightbr-leftbr-2);
477 std::string fullname =
"CFGVar.";
480 retstring.replace(leftbr,rightbr-leftbr+1,varval);
482 }
while(rightbr != std::string::npos);
487 std::vector<std::pair<std::string, int> >& cfgFileLines,
int location,
488 const std::vector<std::string>& alias_files,
const std::string& group,
489 const std::vector<std::pair<std::string, std::string> >& group_options) {
490 std::vector<std::pair<std::string, int> > lines_to_add;
491 std::vector<std::string>::const_iterator fname;
492 for (fname = alias_files.begin(); fname != alias_files.end(); ++fname) {
493 if ((*fname).empty())
495 bool ingroup =
false;
496 std::ifstream in((*fname).c_str());
502 while(getline(in,line)) {
504 std::string target_line =
"group " + group;
505 if (!ingroup && line != target_line)
507 if (line == target_line) {
511 if (line ==
"endgroup") {
517 if (line ==
"endmod") {
519 std::vector<std::pair<std::string, std::string> >::const_iterator option;
520 for (option = group_options.begin(); option != group_options.end(); ++option) {
521 lines_to_add.push_back(make_pair((*option).first +
"=" + (*option).second, location));
524 lines_to_add.push_back(make_pair(line, -1));
532 if (lines_to_add.size())
533 cfgFileLines.insert(cfgFileLines.begin() + location + 1, lines_to_add.begin(), lines_to_add.end());
535 QMessageHandler::Get()->Send(
PanicMsg,
"QModuleFactory",
"Unable to find group \"" + group +
"\" in group files, or no group file given.");
#define Q_BEGIN_NAMESPACE
unsigned int GetOccurrence() const
get the number of times the same module is loaded inside a QSequence
Base class for diana drivers.
error class with error type and description
Base class for diana filters.
QFilter * CreateFilter(const std::string &name, QSequence *s)
static QGeneralFactory & GetInstance()
QWriter * CreateWriter(const std::string &name, QSequence *s)
QModule * CreateModule(const std::string &name, QSequence *s)
QReader * CreateReader(const std::string &name, QSequence *s)
QDriver * CreateDriver(const std::string &name, QSequence *s)
static QGlobalRWFactory & GetInstance()
void LoadPlugin(const std::string &name)
static QMessageHandler * Get()
static void Panic(const std::string &sender, const std::string &msg)
virtual ~QModuleFactory()
void Dump(std::ostream &)
QFilter * CreateFilter(const std::string &n, QSequence *)
void LoadLoadable(const std::string &n)
void AddAliasGroup(std::vector< std::pair< std::string, int > > &cfgFileLines, int location, const std::vector< std::string > &alias_files, const std::string &group, const std::vector< std::pair< std::string, std::string > > &group_options)
std::string ReplaceCFGVar(const std::string &value)
QModule * CreateModule(const std::string &n, QSequence *)
static QModuleFactory * Get()
QDriver * CreateDriver(const std::string &n, QSequence *)
static QModuleFactory * me
QReader * CreateReader(const std::string &n, QSequence *)
QWriter * CreateWriter(const std::string &n, QSequence *)
QSequence * FindSequence(const std::string &s)
Base class for diana modules.
base class for anything that has a name
static QOptions & GetInstance()
Base class for diana event readers.
std::string fFilename
file name of this sequence
Diana Reconstruction program.
QDriver * p_Driver
Pointer to a driver.
std::vector< QBaseModule * > modules
The list of the modules.
QWriter * p_Writer
Pointer to the writer.
QReader * p_Reader
Pointer to the reader.
QSequenceConfig fConfig
Sequence config data.
Abstract class for diana writers.
general purpose string manipulation functions
std::string & RSwallowSpaces(std::string &s)
remove spaces and tabs from the end of s
std::string & SwallowSpaces(std::string &s)
remove spaces and tabs from the beginning of s