Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:50

0001 #!/usr/bin/env perl
0002 
0003 # SELMA - Saclay Ecal Laser Monitoring and Analysis
0004 # contacts: Julie Malcles, Gautier Hamel de Monchenault 
0005 # last modified: Wed Jun 18 16:48:40 CEST 2008
0006 
0007 use Term::ANSIColor;
0008 use Cwd;
0009 use File::stat;
0010 use Time::localtime;
0011 
0012 $firsteem     = 601;
0013 $firstebm     = 610;
0014 $firstebp     = 628;
0015 $firsteep     = 646;
0016 $lastecal     = 654;
0017 
0018 $debugMF=0;
0019 
0020 sub getSMname
0021 {
0022 
0023     my $fed    = shift;
0024     
0025     my $ecal = "";
0026     my $ecalmod = "";
0027     my $nsm  = 0;
0028     
0029     if( $fed<$firsteem || $fed>$lastecal )
0030     {
0031     print "Wrong SM number in getSMname: $fed \n";
0032     }
0033     if( $fed<$firstebm )
0034     {
0035     $ecal = "EE-";
0036     $nsm = $fed-$firsteem+1-3;
0037     if ($nsm <= 0 ){ $nsm+=9; }
0038     }
0039     elsif( $fed<$firstebp )
0040     {
0041     $ecal = "EB-";
0042     $nsm = $fed-$firstebm+1;
0043     }
0044     elsif( $fed<$firsteep )
0045     {
0046     $ecal = "EB+";
0047     $nsm = $fed-$firstebp+1;
0048     }
0049     else
0050     {
0051     $ecal = "EE+";
0052     $nsm = $fed-$firsteep+1-3;
0053     if($nsm <= 0) { $nsm+=9; }
0054     }
0055     
0056     $ecalmod = $ecal.$nsm;
0057 
0058     return $ecalmod;
0059 
0060 }
0061 
0062 
0063 sub getFedNumber
0064 {
0065 
0066     my $smname    = shift;
0067     my $fed = 0;
0068 
0069     if( $smname =~ /EE-(\d*)/ ){
0070     
0071     $nsm = $1;
0072     my $num=$nsm+3;
0073     if($num>9) {$num-=9;}
0074 
0075     $fed =  $num + $firsteem -1;
0076     
0077 
0078     }elsif ( $smname =~ /EE\+(\d*)/ ){
0079 
0080     $nsm = $1;
0081     my $num=$nsm+3;
0082     if($num>9) {$num-=9;}
0083     $fed = $num + $firsteep -1;
0084     
0085     }elsif ( $smname =~ /EB-(\d*)/ ){
0086 
0087     $nsm = $1;
0088     $fed = $nsm + $firstebm - 1;
0089 
0090     
0091     }elsif ( $smname =~ /EB\+(\d*)/ ){
0092 
0093     $nsm = $1;
0094     $fed =  $nsm+ $firstebp-1;
0095     
0096     }else {
0097 
0098     print "Wrong SM name in getFedNumber: $fed\n";
0099     $fed =0;
0100     }
0101    
0102     return $fed;
0103     
0104 }
0105 
0106 sub doProcessFed{
0107     
0108     my $fed=$_[0];
0109     my $ecalpart=$_[1];
0110     my $doprocess=0;
0111     
0112     
0113     if( $fed<$firsteem || $fed>$lastecal )
0114     {
0115     print "Wrong SM number in doProcessFed: $fed \n";
0116     return $doprocess;
0117     }
0118     
0119     if( $ecalpart eq "Ecal" ){
0120     $doprocess=1;
0121     }
0122     elsif( $ecalpart eq "EB" ){
0123     if( getSMname($fed) =~ /EB(.*)/ ){
0124         $doprocess=1;
0125     }
0126     }
0127     elsif( $ecalpart eq "EE" ){
0128     if( getSMname($fed) =~ /EE(.*)/ ){
0129         $doprocess=1;
0130     }
0131     }   
0132     elsif( $ecalpart eq "EB-" ){
0133     if( getSMname($fed) =~ /EB-(\d*)/ ){
0134         $doprocess=1;
0135     }
0136     }   
0137     elsif( $ecalpart eq "EB+" ){
0138     if( getSMname($fed) =~ /EB\+(\d*)/ ){
0139         $doprocess=1;
0140     }
0141     }   
0142     elsif( $ecalpart eq "EE-" ){
0143     if( getSMname($fed) =~ /EE-(\d*)/ ){
0144         $doprocess=1;
0145     }
0146     }   
0147     elsif( $ecalpart eq "EE+" ){
0148     if( getSMname($fed) =~ /EE\+(\d*)/ ){
0149         $doprocess=1;
0150     }
0151     } 
0152     elsif( $ecalpart eq "EcalEven" ){
0153     my $odd=$fed%2;
0154     if( $odd == 0 ) {
0155         $doprocess=1;
0156     }
0157     }
0158     elsif( $ecalpart eq "EcalOdd" ){
0159     my $odd=$fed%2;
0160     if( $odd%2  == 1 ) {
0161         $doprocess=1;
0162     }
0163     }
0164     elsif( $ecalpart eq "EBEven" ){
0165     
0166     if( getSMname($fed) =~ /EB(.*)/ ){
0167         if( $fed%2 == 0 ){  
0168         $doprocess=1;
0169         }
0170     }
0171     }
0172     elsif( $ecalpart eq "EBOdd" ){
0173     
0174     if( getSMname($fed) =~ /EB(.*)/ ){
0175         if( $fed%2 ==1 ) {
0176         $doprocess=1;
0177         }
0178     }
0179     }
0180     elsif( $ecalpart =~ /E(E|B)(\+|-)(\d{1})/ ){
0181     if( getSMname($fed) eq  $ecalpart ){
0182         $doprocess=1;
0183     }
0184     } else {
0185     
0186     print "Unknown ecalpart: $ecalpart \n";
0187     }
0188     
0189     return $doprocess;
0190 }
0191 
0192 
0193 sub sendCMSJob{
0194     
0195     my $keyword=$_[0];  # header, matacq, laser, testpulse
0196     my $keyword2=$_[1]; # for ps command
0197     my $nmaxjobs=$_[2]; 
0198     my $user=$_[3];
0199     my $jobdir=$_[4];
0200     my $scriptdir=$_[5];
0201 
0202 
0203     if( $debugMF==1 ){
0204     print " debug - sendCMSJob 1 : ${cfg} ${log} ${keyword2} ${nmaxjobs} \n";
0205     }
0206     my $isItSent = 0;
0207     my $njobs = 8;
0208     my $nsub = 8;
0209     my $ntot = 8;
0210     my $timewaiting=0;
0211     my $command="";
0212     
0213     if( $keyword2 eq "NoKey" ){
0214     $command="ps x -u ${user} | grep cmsRun | grep py | grep -v 'ps x -u' |  wc -l"; 
0215     }else {
0216     $command="ps x -u ${user} | grep cmsRun | grep py | grep -v 'ps x -u' | grep ${keyword2} |wc -l";
0217     }
0218     $njobs =`$command`;
0219     $njobs =$njobs+0;
0220 
0221     if( $keyword2 eq "NoKey" ){
0222     $command2="ps x -u ${user} | grep submitJobPy | grep -v 'ps x -u' | wc -l";
0223     }else{
0224     $command2="ps x -u ${user} | grep submitJobPy | grep -v 'ps x -u' | grep ${keyword2} | wc -l";
0225     }
0226     
0227     $nsub =`$command2`;
0228     $nsub =$nsub+0;
0229 
0230     $ntot=$nsub+$njobs;
0231     
0232     if( $debugMF==1 ) {
0233     print "debug - sendCMSJob 2 : njobs= ${njobs}, nsub= ${nsub}, ntot= ${ntot} \n";
0234     }
0235     
0236     my $commandToSend = "${scriptdir}/submitJobPy.csh ${keyword} ${jobdir}";
0237 
0238     while($ntot >=$nmaxjobs){
0239     
0240     sleep 5;
0241     $timewaiting+=5;
0242 
0243     $njobs =`$command`;  
0244     $njobs =$njobs+0;
0245     $nsub =`$command2`;  
0246     $nsub =$nsub+0;
0247     
0248     $ntot=$nsub+$njobs;
0249 
0250     if( $debugMF==1 ) {
0251         print "debug - sendCMSJob 3 : inside loop njobs= ${njobs}, nsub= ${nsub}, ntot= ${ntot}  \n";
0252         
0253     }
0254     }
0255 
0256     my $mydate = `date +%s`;
0257     print " ....... job sent at: ${mydate} after waiting ${timewaiting} seconds \n";
0258     print " njobs: ${njobs}, nsub: ${nsub}, ntot: ${ntot} \n";
0259     
0260     system $commandToSend ;
0261     
0262     
0263     $isItSent=1;
0264     
0265     if( $debugMF==1 ) {
0266     print "debug - sendCMSJob 4 : isItSent: ${isItSent} \n";
0267     print "debug - sendCMSJob 5 : command: ${commandToSend} \n";
0268     }
0269     
0270     return  $isItSent;
0271 }
0272 
0273