32 MarlinSteerCheck::MarlinSteerCheck(
const char* steeringFile,
const CommandLineParametersMap * cmdlineparams ) : _parser(NULL), _gparam(NULL), _steeringFile(
"Untitled.xml") {
34 if( steeringFile != 0 ){
44 _gparam = std::make_shared<StringParameters>();
47 _gparam->add(
"MaxRecordNumber", value);
50 _gparam->add(
"SkipNEvents", value);
52 value.push_back(
"false");
53 _gparam->add(
"SupressCheck", value);
55 value.push_back(
"gear_ldc.xml");
56 _gparam->add(
"GearXMLFile", value);
58 value.push_back(
"MESSAGE");
59 _gparam->add(
"Verbosity", value);
130 for(
unsigned int i=0; i<v.
size(); i++ ){
143 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
146 if(
_aProc[i] == proc ){
break; }
155 for(
unsigned int i=0; i<v.
size(); i++ ){
156 if( v[i]->getType() == type ){
197 HANDLE_LCIO_EXCEPTIONS;
200 LCReader*
lcReader = LCFactory::getInstance()->createLCReader();
202 lcReader->open( file );
205 _gparam->getStringVals(
"LCIOReadCollectionNames" , readCols );
206 if( ! readCols.
empty() )
207 lcReader->setReadCollectionNames( readCols ) ;
209 catch( Exception& e){
211 error <<
"Error opening LCIO file [" << file <<
"]. File doesn't exist, or link is not valid!!";
213 cerr <<
"addLCIOFile Exception: " << e.what() <<
endl;
223 cout <<
"Loading LCIO file [" << file <<
"]\n";
224 cout <<
"Reading Events...";
226 while( ((evt = lcReader->readNextEvent()) != 0) && nEvents <
MAXEVENTS ){
230 const StringVec* strVec = evt->getCollectionNames();
231 StringVec::const_iterator name;
233 for( name = strVec->
begin(); name != strVec->
end(); name++ ){
234 LCCollection* col = evt->getCollection( *name ) ;
258 cout <<
"\nLCIO file [" << file <<
"] was loaded successfully\n";
270 for(
unsigned int i=0; i<q->second.size(); i++ ){
319 cerr <<
"changeLCIOFilePos: Index out of bounds!!" <<
endl;
357 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
358 if(( name ==
"" &&
_aProc[i]->getType() == type ) || (
_aProc[i]->getType() == type &&
_aProc[i]->getName() == name )){
362 for(
unsigned int i=0; i<
_iProc.
size(); i++ ){
363 if(( name ==
"" &&
_iProc[i]->getType() == type ) || (
_iProc[i]->getType() == type &&
_iProc[i]->getName() == name )){
376 _iProc[index]->changeStatus();
384 cerr <<
"activateProcessor: Index out of bounds!!" <<
endl;
394 _aProc[index]->changeStatus();
397 if(
_aProc[index]->getConditions().
size() != 0 ){
407 cerr <<
"activateProcessor: Index out of bounds!!" <<
endl;
424 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
435 cerr <<
"changeProcessorPos: Index out of bounds!!" <<
endl;
444 ColVec inputCols, outputCols, matchCols;
447 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
460 for(
unsigned int j=0; j<inputCols.
size(); j++ ){
465 if( matchCols.
size() == 0 ){
467 _aProc[i]->addUCol( inputCols[j] );
472 for(
unsigned int j=0; j<outputCols.
size(); j++ ){
477 if( matchCols.
size() != 0 ){
479 _aProc[i]->addDCol( outputCols[j] );
484 availableCols.
insert( availableCols.
end(), outputCols.
begin(), outputCols.
end() );
496 cmd <<
"ls " << file <<
" >/dev/null 2>/dev/null";
502 StringVec lcioFiles, availableProcs, activeProcs, conditions;
511 if( filen.
rfind(
".xml") == std::string::npos ||
512 !( filen.
rfind(
".xml")
524 if( cmdlineparams != NULL ){
533 catch( Exception& e ){
534 cerr <<
"parseXMLFile: Failed to load file: " << e.what() <<
endl;
545 _gparam->getStringVals(
"MaxRecordNumber" , value );
546 if( value.
size() == 0 ){
548 _gparam->add(
"MaxRecordNumber", value);
551 _gparam->getStringVals(
"SkipNEvents" , value );
552 if( value.
size() == 0 ){
554 _gparam->add(
"SkipNEvents", value);
557 _gparam->getStringVals(
"SupressCheck" , value );
558 if( value.
size() == 0 ){
560 _gparam->add(
"SupressCheck", value);
565 _gparam->getStringVals(
"GearXMLFile" , value );
566 if( value.
size() == 0 ){
567 value.
push_back(
"__unknown_gear_file__");
568 _gparam->add(
"GearXMLFile", value);
571 if( value.
size() > 1 ){
572 string gfile=value[0];
575 _gparam->erase(
"GearXMLFile" );
576 _gparam->add(
"GearXMLFile", value );
580 cmd <<
"ls " << value[0] <<
" >/dev/null 2>/dev/null";
584 error <<
"Error opening GEAR file [" << value[0] <<
"]. File doesn't exist, or link is not valid!!";
589 _gparam->getStringVals(
"LCIOInputFiles" , lcioFiles );
590 _gparam->erase(
"LCIOInputFiles");
594 _gparam->getStringVals(
"AvailableProcessors" , availableProcs );
595 _gparam->erase(
"AvailableProcessors");
598 _gparam->getStringVals(
"ActiveProcessors" , activeProcs );
599 _gparam->erase(
"ActiveProcessors");
602 _gparam->getStringVals(
"ProcessorConditions" , conditions );
603 _gparam->erase(
"ProcessorConditions");
609 for(
unsigned int i=0; i<lcioFiles.
size(); i++ ){
617 for(
unsigned int i=0; i<availableProcs.
size(); i++ ){
623 string type = p->getStringVal(
"ProcessorType" );
630 for(
unsigned int i=0; i<activeProcs.
size(); i++ ){
635 for(
unsigned int j=0; j<
_iProc.
size(); j++ ){
636 if( activeProcs[i] ==
_iProc[j]->getName() ){
655 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
659 _aProc[i]->setConditions( conditions[i] );
661 _aProc[i]->setConditions(
"true" );
663 for( sSet::const_iterator p=
_aProc[i]->getConditions().
begin();
664 p!=
_aProc[i]->getConditions().
end(); p++ ){
668 if( !
_aProc[i]->isInstalled() ){
671 if(
_aProc[i]->hasErrorCols() ){
672 _errors.
insert(
"Some Active Processors have collection errors");
675 for(
unsigned int i=0; i<
_iProc.
size(); i++ ){
676 if( !
_iProc[i]->isInstalled() ){
677 _errors.
insert(
"Warning: Some Inactive Processors are not installed");
688 for(
unsigned int i=0; i<v.
size(); i++ ){
689 if( v[i]->getSrcProc() != srcProc && v[i]->getType() == type ){
690 if( value !=
"UNDEFINED" ){
692 if( name !=
"UNDEFINED" ){
693 if( v[i]->getName() == name ){
719 for(
unsigned int i=0; i<v.
size(); i++ ){
744 sSet::const_iterator p;
759 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
760 if(
_aProc[i]->hasCondition( oldCond )){
770 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
771 if(
_aProc[i]->hasCondition( condition )){
788 cols.
insert( cols.
end(), p->second.begin(), p->second.end() );
798 for(
unsigned int i=0; i<v.
size(); i++ ){
799 cols.
insert( cols.
end(), v[i]->getCols( iotype ).
begin(), v[i]->getCols( iotype ).
end() );
822 if( file.
size() == 0 ){
return false; }
829 cerr <<
"MarlinSteerCheck::saveAsXMLFile: Error creating or modifying XML File [" << file <<
"]\n";
838 outfile <<
"<?xml version=\"1.0\" encoding=\"us-ascii\"?>" <<
endl;
839 outfile <<
"<!-- ?xml-stylesheet type=\"text/xsl\" href=\"http://ilcsoft.desy.de/marlin/marlin.xsl\"? -->" << endl;
840 outfile <<
"<!-- ?xml-stylesheet type=\"text/xsl\" href=\"marlin.xsl\"? -->" << endl << endl;
843 outfile <<
"============================================================================================================================\n";
844 outfile <<
" Steering File generated by Marlin GUI on " <<
ctime(pnow) << endl;
845 outfile <<
" WARNING: - Please be aware that comments made in the original steering file were lost.\n";
846 outfile <<
" - Processors that are not installed in your Marlin binary lost their parameter's descriptions and types as well.\n";
847 outfile <<
" - Extra parameters that aren't categorized as default in a processor lost their description and type.\n";
848 outfile <<
"============================================================================================================================\n";
851 outfile <<
"\n\n<marlin xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
852 outfile <<
"xsi:noNamespaceSchemaLocation=\"http://ilcsoft.desy.de/marlin/marlin.xsd\">" << endl << endl;
858 outfile <<
" <execute>\n";
863 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
868 for( sSet::const_iterator p=
_aProc[i]->getConditions().
begin(); p!=
_aProc[i]->getConditions().
end(); p++ ){
871 for(
unsigned int j=(i+1); j<
_aProc.
size(); j++ ){
872 if(
_aProc[j]->hasCondition(*p) ){
882 for(
unsigned int j=0; j<openConditions.
size(); j++ ){
883 if( openConditions[j].first.find(*p) != openConditions[j].first.
end() ){
890 condLength[length].
insert(*p);
894 for(
unsigned int j=0; j<openConditions.
size(); j++ ){
895 openConditions[j].second--;
901 outfile <<
string( (openConditions.
size()+1)*3,
' ') <<
"<if condition=\"";
903 if( p->second.size() != 1 ){
904 for( sSet::const_iterator q=p->second.begin(); q!=p->second.end(); q++ ){
905 if( ((*q).find(
'&',0)!=string::npos) || ((*q).find(
'|',0)!=string::npos) || ((*q).find(
'!',0)!=string::npos) ){
906 outfile <<
"(" << *q <<
")";
911 if( ++size < p->second.size() ){
917 outfile << *p->second.begin();
921 outfile <<
string( (openConditions.
size()+2)*3,
' ') <<
"<processor name=\"" <<
_aProc[i]->getName() <<
"\"/>\n";
925 for( pos=0; pos<openConditions.
size(); pos++ ){
926 if( openConditions[pos].second==1 ){
930 if( pos != openConditions.
size() ){
931 for(
unsigned int j=openConditions.
size(); j>pos; j-- ){
932 outfile <<
string( (openConditions.
size()+1)*3,
' ') <<
"</if>\n";
938 outfile <<
" <processor name=\"" <<
_aProc[i]->getName() <<
"\"/>\n";
941 for(
unsigned int i=0; i<
_iProc.
size(); i++ ){
942 outfile <<
" <!--processor name=\"" <<
_iProc[i]->getName() <<
"\"/-->\n";
945 outfile <<
" </execute>\n\n";
951 outfile <<
" <global>\n";
954 outfile <<
" <parameter name=\"LCIOInputFiles\">";
959 outfile <<
" </parameter>\n";
962 _gparam->getStringKeys( keys );
965 for(
unsigned int i=0; i<keys.
size(); i++ ){
966 outfile <<
" <parameter name=\"" << keys[i] <<
"\"";
970 _gparam->getStringVals( keys[i], values );
972 outfile << ( values.
size() == 1 ?
" value=\"" :
">" );
974 for(
unsigned int j=0; j<values.
size(); j++ ){
975 outfile << ( values.
size() == 1 ?
"" :
" ") << values[j];
977 outfile << ( values.
size() == 1 ?
"\"/>\n" :
" </parameter>\n" );
980 outfile <<
" </global>\n\n";
986 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
987 _aProc[i]->writeToXML( outfile );
989 for(
unsigned int i=0; i<
_iProc.
size(); i++ ){
990 _iProc[i]->writeToXML( outfile );
993 outfile <<
"</marlin>\n";
1005 if( file.
size() == 0 ){
return false; }
1012 cerr <<
"MarlinSteerCheck::saveAsDOTFile: Error creating or modifying DOT File [" << file <<
"]\n";
1017 dotfile <<
"digraph MarlinSteering {\n"
1018 <<
"node [ fontname = \"Helvetica\","
1019 <<
"style = filled ];\n";
1023 dotfile <<
"LCIOFile [color=darkgreen, fontcolor=white, label=\"" <<
getLCIOFiles()[0] <<
"\"]\n";
1025 dotfile <<
"LCIOFile [color=darkgreen, fontcolor=white, label=\"LCIO File\"]\n";
1036 for(
unsigned int i=0; i<lcioCols.
size(); i++ ){
1037 producer_of[lcioCols[i]->getValue()] =
"LCIOFile";
1038 type_of[lcioCols[i]->getValue()] = lcioCols[i]->getType();
1043 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
1044 ColVec inputCols,outputCols;
1047 for(
unsigned int j=0; j<inputCols.
size(); j++ ){
1048 string producer = producer_of[inputCols[j]->getValue()];
1049 if (producer.
size() > 0){
1051 dotfile << inputCols[j]->getValue() <<
" -> " <<
_aProc[i]->getName() <<
";\n";
1056 cout << inputCols[j]->getValue() <<
" not found for " <<
_aProc[i]->getName() <<
"\n";
1058 for(
unsigned int j=0; j<outputCols.
size(); j++ ){
1059 producer_of[outputCols[j]->getValue()] =
_aProc[i]->getName();
1060 type_of[outputCols[j]->getValue()] = outputCols[j]->getType();
1067 for(
int i=0; i<new_end-used_outputs.
begin(); i++ ){
1068 dotfile << used_outputs[i] <<
" [color=lightsteelblue2, label=<<TABLE BORDER=\"0\"><TR><TD>"
1069 << used_outputs[i] <<
"</TD></TR><TR><TD><FONT POINT-SIZE=\"11.0\">"
1070 << type_of[used_outputs[i]] <<
"</FONT></TD></TR></TABLE>>];\n";
1071 dotfile << producer_of[used_outputs[i]] <<
" -> " << used_outputs[i] <<
";\n";
1075 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
1076 if (
_aProc[i]->getType() !=
"LCIOOutputProcessor")
1077 dotfile <<
_aProc[i]->getName() <<
" [color=navyblue, fontcolor=white, label=\""
1078 <<
_aProc[i]->getName() <<
"\"shape=rectangle];\n";
1085 cout <<
"DOT File written...\n";
1086 cout <<
"Now run dot eg: dot -Tps " << file <<
" > "<< file <<
".ps\n";
1127 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
1137 " [ " <<
_aProc[i]->getStatusDesc() <<
" ] ";
1140 if(
_aProc[i]->hasErrors() ){
1141 cout <<
" ( " <<
_aProc[i]->getError() <<
" )";
1153 for(
unsigned int i=0; i<
_iProc.
size(); i++ ){
1162 " [ " <<
_iProc[i]->getStatusDesc() <<
" ] ";
1165 if(
_iProc[i]->hasErrors() ){
1166 cout <<
" ( " <<
_iProc[i]->getError() <<
" )";
1180 for(
unsigned int i=0; i<
_aProc.
size(); i++ ){
1184 cout << endl << endl;
1188 cout << (*p) << endl;
1193 cout <<
"\nNo Errors were found :)" << endl;
1196 cout <<
"\nErrors were found (see above)..." << endl;
1209 stream <<
"\nProcessor [" <<
1210 _aProc[i]->getName() <<
"] of type [" <<
1211 _aProc[i]->getType() <<
"] has following errors:" <<
1217 for( sSet::const_iterator q=dTypes.
begin(); q!=dTypes.
end(); q++){
1218 stream <<
"\n* Following Collections of type [";
1220 stream <<
"] were already found in the event:\n";
1226 for(
unsigned int j=0; j<dCols.
size(); j++ ){
1231 stream <<
"\n * Following collections are in conflict with this collection:\n";
1232 for(
unsigned int j=0; j<dCols.
size(); j++ ){
1235 if( lcioCols.
size() != 0 ){
1236 for(
unsigned int k=0; k<lcioCols.
size(); k++ ){
1239 stream <<
"] in LCIO file: [" << lcioCols[k]->getName() <<
"]\n";
1243 if( oCols.
size() != 0 ){
1244 for(
unsigned int k=0; k<oCols.
size(); k++ ){
1247 stream <<
"] in [Active] Processor [" << oCols[k]->getSrcProc()->getName()
1248 <<
"] of Type [" << oCols[k]->getSrcProc()->getType() <<
"]\n";
1259 for( sSet::const_iterator p=uTypes.
begin(); p!=uTypes.
end(); p++){
1260 stream <<
"\n* Following Collections of type [";
1262 stream <<
"] are unavailable:\n";
1268 for(
unsigned int j=0; j<uCols.
size(); j++ ){
1278 if( avCols.
size() != 0 ){
1280 stream <<
" * Following available collections of the same type were found:" << endl;
1282 for(
unsigned int k=0; k<avCols.
size(); k++ ){
1285 for(
unsigned int j=0; j<uCols.
size(); j++ ){
1288 stream << avCols[k]->getValue();
1291 if( avCols[k]->getSrcProc() == 0 ){
1292 stream <<
"] in LCIO file: [" << avCols[k]->getName() <<
"]" << endl;
1295 stream <<
"] in [" <<
1296 avCols[k]->getSrcProc()->getStatusDesc() <<
"] Processor [" <<
1297 avCols[k]->getSrcProc()->getName() <<
"] of Type [" <<
1298 avCols[k]->getSrcProc()->getType() <<
"]" <<
1305 stream <<
" * Sorry, no suitable collections were found." << endl;
1308 stream <<
string( 170,
'-') << endl;
XML parser for Marlin steering files.
virtual void setCmdLineParameters(const CommandLineParametersMap &cmdlineparams)=0
set command line parameters
void remProcessor(unsigned int index, bool status)
Remove processor with the given status at the given index.
static CMProcessor * instance()
return the instance of this class
void repCondition(const std::string &oldCond, const std::string &newCond)
Replace a Condition.
ColVec & getProcCols(const ProcVec &v, const std::string &iotype) const
handles information about LCIO collections needed by MarlinSteerCheck
ColVec & getLCIOCols() const
Returns the collections read from LCIO files.
ColVec & findMatchingCols(ColVec &v, CCProcessor *srcProc, const std::string &type, const std::string &value="UNDEFINED", const std::string &name="UNDEFINED")
void remCondition(const std::string &condition)
Removes the given condition.
std::shared_ptr< StringParameters > _gparam
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
virtual void parse()=0
Parse the input file.
CCProcessor * popProc(ProcVec &v, CCProcessor *p)
handles information about marlin processors and their collections needed by MarlinSteerCheck ...
void dump_information()
Dumps all information read from the steering file to stdout.
const std::string getCondition(unsigned int index)
Returns the condition for a given index.
Simple parser class for Marlin.
void activateProcessor(unsigned int index)
Activate processor at the given index.
bool parseXMLFile(const std::string &file, const CommandLineParametersMap *cmdlineparams=NULL)
sSet & getColsSet(const std::string &type, const std::string &name, CCProcessor *proc)
Returns a list of all available Collections for a given type, name and processor (to use in a ComboBo...
std::string _steeringFile
ColVec & getAllCols() const
bool saveAsDOTFile(const std::string &file)
Saves steering file in dot format.
Always the top level node.
void addProcessor(bool status, const std::string &name, const std::string &type, std::shared_ptr< StringParameters > p)
Add a new processor.
bool saveAsXMLFile(const std::string &file)
Saves the data to an XML file with the given name Returns false if error occured. ...
ColVec & getCols(const std::string &iotype, const std::string &type_name="ALL_COLLECTIONS")
Returns collections of a given iotype ( INPUT, OUTPUT, UNAVAILABLE, DUPLICATE ) for a given name or t...
void consistencyCheck()
Performs a check at all active processors to search for unavailable collections.
ProcVec & getAllProcs() const
void changeProcessorPos(unsigned int pos, unsigned int newPos)
Change the active processor at the given index to the new given position.
void dumpColErrors(unsigned int i, std::ostream &stream, bool separators=false)
Writes the collection errors for the active processor with given index to the given stream...
void deactivateProcessor(unsigned int index)
Deactivate processor at the given index.
virtual std::shared_ptr< StringParameters > getParameters(const std::string §ionName) const =0
Return the StringParameters defined for this section of the steering file.
StringVec & getLCIOFiles()
Returns the names of the LCIO files found in the global section.
bool isActive()
Returns true if the processor is active.
void changeLCIOFilePos(unsigned int pos, unsigned int newPos)
Change the LCIO File at the given index to the new given position.
void addCondition(const std::string &condition)
Add a new Condition.
int addLCIOFile(const std::string &file)
Add LCIO file and read all collections inside it.
void remLCIOFile(const std::string &file)
Remove LCIO file and all collections associated to it.
CMProcessor * _marlinProcs
int existsProcessor(const std::string &type, const std::string &name="")
Check if a processor of the given type with the given name already exists Returns 0 if the processor ...