NODE_SELECTION (June 2005)

Antonio Sobreira de Almeida <Antonio.Sobreira.de.Almeida@cern.ch> 

PURPOSE:
Given: 1. a file with tags and hosts (called here source_file) and 
       2. another file (called here command_file) with 'new tags' and 'old tags', 'number' of nodes and their 'multiplicity', 

the program makes a new file (output_file) with a new node configuration (a 'new tag' followed by a 'number' of nodes 
repeated 'multiplicity' times from the selected 'old tag')   


Syntax: node_selection.py source_file command_file.txt output_file 

(the user can specify the source_file name, as well as the command_file and output_file names)


REMARKS:
-In the source_file, the tag should be made of just one string (WITHOUT whitespaces): OK: '# TAG1FAST'     NOT_OK: '# TAG1 FAST' 
The same to the old tag (should be equal to one of the tags in the source file), since if there were whitespaces in the command file
they would be interpreted as separate fields                                   
-Nodes are given to each new_tag sequentially as in the source file 
-This script has a strong error detection mechanism: it detects several formating errors in the command_file and displays what errors have occurred; if some error is detected, no output_file will be created (it will even delete some output_file already created to avoid misusing of one output_file already created in a previous use of this script
-Lines starting with # in the command_file will be considered as comments
-Lines starting with # in the source_file will be considered as tags 
-The script has tolerance to blanklines, tabs '\t' and different number of whitespaces 
-In the output_file, tags will be of type: # Tag_Name, accordingly to usual convention, even if in the source_file the space (' ') has not been considered. There is no blankline between node_names and new_tags
-After a node has been included to some new_tag (with the specified multiplicity), it will not appear under another new_tag
-If a Multiplicity is not specified, it will be 1 BY DEFAULT.
-A sequence of commands of this type:

#Function (new_tag)              From (old_tag)           Number                      Multiplicity
HOSTS_A              	    	 NODES_SET1          	    4                               8
HOSTS_A                          NODES_SET1                 2

will have the expected result: after the #HOSTS_A tag, 4 nodes belonging to NODES_SET1 repeated 8 times, followed by
more two of these nodes (but not those which were already used) (each one appearing only once - Multiplicity ==1)    


 

Example:

Command: 
>node_selection.py source_file_example command_file_example outputfile_example

*******
OK!!
Program executed successfully
'output_file' file  was created
*******



_______________________________________source_file_example__________________________
# File with nodes

# NODES_SET0

# NODES_SET1  
node1_1			
node1_2 
node1_3
node1_4
node1_5
node1_6
node1_7
node1_8
node1_9
node1_10
node1_11
node1_12
node1_13
node1_14
node1_15
node1_16
node1_17
node1_18
node1_19
node1_20
node1_21
node1_22
node1_23
node1_24
node1_25
node1_26
node1_27
node1_28
node1_29
node1_30

#NODES_SET2
node2_1
node2_2
node2_3
node2_4
node2_5
node2_6
node2_7
node2_8
node2_9
node2_10
node2_11
node2_12
node2_13
node2_14
node2_15

#NODES_SET3
node3_1
node3_2
node3_3
node3_4
node3_5
node3_6
node3_7
node3_8
node3_9

#NODES_SET4
node4_1
node4_2
node4_3
node4_4
node4_5
node4_6
node4_7
node4_8
node4_9

#NODES_SET5
node5_1
node5_1

#NODES_SET6


#NODES_SET7
node7_1
node7_2
node7_3
node7_4
node7_5
node7_6



************************************************************************************
_______________________________________command_file_example________________________
#COMMAND FILE EXAMPLE [uncomment the lines and remove their description in front if you want to test the response to some possible errors]
#Function (newtag)              From (oldtag)           Number                      Multiplicity
HOSTS_A              	    	 NODES_SET1          	 4                                 8
HOSTS_REMAINING_1                NODES_SET1              0                                 2
HOSTS_B                  	 NODES_SET2            	 1                                 6                              
HOSTS_C        	       	         NODES_SET3            	 2                                 5         
HOSTS_D 			 NODES_SET4            	 1                                
#HOSTS_NON_DIGIT                 NODES_SET4              a                                     #non digit error    
HOSTS_E              		 NODES_SET5           	 1                                          

#HOSTS_F      			 NODES_SET6		 1		                        #not existing nodes
HOSTS_G             		 NODES_SET7              1
#HOSTS_H                 	 NODES_SET_NON_EXIST     1                                      #not existing tag in source_file         

#HOSTS_I                 	 NODES_SET5              1
HOSTS_J              		 NODES_SET2              1
HOSTS_K               		 NODES_SET3              1
HOSTS_L                 	 NODES_SET4              6                                           
#HOSTS_M           		 NODES_SET1              1                                      #nodes overflow
HOSTS_N				 NODES_SET4              1
HOSTS_REMAINING_7                NODES_SET7              0
                          



**************************************OUTPUT FILE********
______________________________________output_file_example_________________________
# HOSTS_A
node1_1
node1_1
node1_1
node1_1
node1_1
node1_1
node1_1
node1_1
node1_2
node1_2
node1_2
node1_2
node1_2
node1_2
node1_2
node1_2
node1_3
node1_3
node1_3
node1_3
node1_3
node1_3
node1_3
node1_3
node1_4
node1_4
node1_4
node1_4
node1_4
node1_4
node1_4
node1_4
# HOSTS_REMAINING_1
node1_5
node1_5
node1_6
node1_6
node1_7
node1_7
node1_8
node1_8
node1_9
node1_9
node1_10
node1_10
node1_11
node1_11
node1_12
node1_12
node1_13
node1_13
node1_14
node1_14
node1_15
node1_15
node1_16
node1_16
node1_17
node1_17
node1_18
node1_18
node1_19
node1_19
node1_20
node1_20
node1_21
node1_21
node1_22
node1_22
node1_23
node1_23
node1_24
node1_24
node1_25
node1_25
node1_26
node1_26
node1_27
node1_27
node1_28
node1_28
node1_29
node1_29
node1_30
node1_30
# HOSTS_B
node2_1
node2_1
node2_1
node2_1
node2_1
node2_1
# HOSTS_C
node3_1
node3_1
node3_1
node3_1
node3_1
node3_2
node3_2
node3_2
node3_2
node3_2
# HOSTS_D
node4_1
# HOSTS_E
node5_1
# HOSTS_G
node7_1
# HOSTS_J
node2_2
# HOSTS_K
node3_3
# HOSTS_L
node4_2
node4_3
node4_4
node4_5
node4_6
node4_7
# HOSTS_N
node4_8
# HOSTS_REMAINING_7
node7_2
node7_3
node7_4
node7_5
node7_6