Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:51

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: Sat Nov 24 08:56:52 CET 2007
0006 
0007 use Term::ANSIColor;
0008 use Cwd;
0009 use File::stat;
0010 use Time::localtime;
0011 
0012 $firstRun     = @ARGV[0];
0013 $lastRun      = @ARGV[1];
0014 $useMatacq    = @ARGV[2];
0015 $useShape     = @ARGV[3];
0016 $fitAB        = @ARGV[4];
0017 $linkName     = @ARGV[5];
0018 $user         = @ARGV[6];
0019 $ecalPart     = @ARGV[7];
0020 $nmaxjobshead = @ARGV[8];
0021 $nmaxjobstot  = @ARGV[9];
0022 
0023 # Defaults arguments values 
0024 #===========================
0025 
0026 $firstRunDefault = "0" ;
0027 $lastRunDefault  = "100000" ;
0028 $useMatacqDefault = 1 ;
0029 $useShapeDefault = 1 ;
0030 $linkNameDefault = "LaserMonitoring" ;
0031 $userDefault="ecallaser";
0032 $ecalPartDefault="Ecal";
0033 $debug=0;
0034 
0035 @analyzeSMRunning = (0,0,0,0,0,0,0,0,0,0,
0036              0,0,0,0,0,0,0,0,0,0,
0037              0,0,0,0,0,0,0,0,0,0,
0038              0,0,0,0,0,0,0,0,0,0,
0039              0,0,0,0,0,0,0,0,0,0,
0040              0,0,0,0);
0041 @detectSMRunning  = (0,0,0,0,0,0,0,0,0,0,
0042              0,0,0,0,0,0,0,0,0,0,
0043              0,0,0,0,0,0,0,0,0,0,
0044              0,0,0,0,0,0,0,0,0,0,
0045              0,0,0,0,0,0,0,0,0,0,
0046              0,0,0,0);
0047 
0048 # Setup defaults arguments values 
0049 #=================================
0050 
0051 if( $firstRun eq "" )
0052 {
0053     $firstRun = $firstRunDefault; 
0054     $lastRun = $lastRunDefault;
0055 }
0056 elsif( $lastRun eq "+" ) 
0057 { 
0058     $lastRun = "99999"; 
0059 }
0060 elsif( $lastRun eq "" ) 
0061 { 
0062     $lastRun = $firstRun; 
0063 }
0064 
0065 if( $useMatacq eq "" )
0066 {
0067     $useMatacq=$useMatacqDefault;
0068 }
0069 if( $useShape eq "" ){
0070     $useShape=$useShapeDefault;
0071 }
0072 
0073 if( $useMatacq == 0 ) {
0074     $useShape = 0;
0075 }
0076 
0077 if( $user eq "" ){
0078     $user=$userDefault;
0079 }
0080 if( $ecalPart eq "" ){
0081     $ecalPart = $ecalPartDefault;
0082 }
0083 
0084 # Directories settings
0085 #======================
0086 
0087 $localdir     = cwd;
0088 if (  $linkName eq "" ) {
0089     $proddir      = "${localdir}/${linkNameDefault}";
0090 }else{
0091     $proddir      = "${localdir}/${linkName}";
0092 }
0093 
0094 $scriptdir    = "$proddir/scripts";
0095 $shapedir     = "$proddir/shapes";
0096 $sortdir      = "$proddir/sorting";
0097 
0098 # ECAL numbering settings
0099 #=========================
0100 
0101 $firsteem     = 601;
0102 $firstebm     = 610;
0103 $firstebp     = 628;
0104 $firsteep     = 646;
0105 $lastecal     = 654;
0106 
0107 do "${scriptdir}/monitoringFunctions.pl";
0108 
0109 print color("red"),"\n\n ***** Saclay Ecal Laser Monitoring & Analysis *****\n", color("reset");
0110 print color("red"),     " *****           Analyzing : ${ecalPart}              *****\n\n", color("reset");
0111 
0112 
0113 
0114 # Analyze the sorting directory:
0115 #===============================
0116 
0117 while( 1 ) 
0118 {
0119     system date;    
0120     analyze();
0121     sleep 60;
0122 }
0123 
0124 exit;
0125 
0126 sub analyze 
0127 {
0128     print color("green"), " \n ** Restarting Analyzer ** \n\n", color("reset");
0129     
0130     opendir(SORTDIR, $sortdir) || die "cannot open sorting directory $sortdir \n";
0131     
0132     $dirname = "";
0133     $fedname = "";
0134     $lbname = "";
0135     $run     = 0;
0136     $fed     = 0;
0137     
0138     my @sortdirs = sort  readdir( SORTDIR );
0139 
0140     # Detect news super-modules
0141     #===========================
0142 
0143     foreach my $dir (@sortdirs)
0144     {
0145     if( $debug == 1 ) { print "Directory: ${dir} detected.\n"; }
0146     
0147     next unless( $dir =~ /E(E|B)(\+|-)(\d{1})/ );
0148     $fed = getFedNumber(${dir});  
0149     
0150     if( $debug == 1 ) { print "Cut1Passed fed:${fed},dir:${dir},ecalPart:${ecalPart} \n";}
0151 
0152     next unless( doProcessFed($fed, $ecalPart) == 1 );
0153 
0154     if( $debug == 1 ) { print "Cut2Passed (doProcessFed) \n";}
0155 
0156 
0157     # Create eventually new directory
0158     # ================================
0159 
0160     my $smdir      = "${proddir}/${dir}";
0161 
0162     if( -e ${smdir} ) 
0163     {
0164         if( $debug == 1 ) { print "${smdir} exists.\n"; }
0165 
0166     }else{
0167         print "creating directory ${smdir}\n";
0168         $command =  "${scriptdir}/createDirs.csh ${proddir} ${dir}" ;
0169         system ${command};
0170     }
0171     
0172     # Check if analyzer is running and eventuelly launch it
0173     # ======================================================
0174 
0175     if( $detectSMRunning[$fed-600] == 0 ){
0176         $detectSMRunning[$fed-600]= isDetectSMRunning($fed, $dir, $user, $linkName);
0177     }
0178     if( $detectSMRunning[$fed-600] == 0 ){   
0179         print "now launch the script to detect new files for module ${dir}\n";
0180         
0181         my $curtime=time();
0182         
0183         my $smlog="${smdir}/detectSM_${curtime}.log";
0184         
0185         $command = "nohup ${scriptdir}/detectSM.pl ${firstRun} ${lastRun} ${fed} ${dir} ${useShape} ${fitAB} ${linkName} ${user} ${nmaxjobshead} ${debug} > ${smlog} &\n"; 
0186         system ${command};    
0187         $detectSMRunning[$fed-600]=1;
0188     }
0189     
0190 
0191     if( $analyzeSMRunning[$fed-600] == 0 ){
0192         $analyzeSMRunning[$fed-600]= isAnalyzeSMRunning($fed, $dir, $user, $linkName);
0193     }
0194     if( $analyzeSMRunning[$fed-600] == 0 ){   
0195         print "now launch the script to analyze module ${dir}\n";
0196         
0197         my $curtime=time();
0198         
0199         my $smlog="${smdir}/analyzeSM_${curtime}.log";
0200         
0201         $command = "nohup ${scriptdir}/analyzeSM.pl ${fed} ${dir} ${useMatacq} ${useShape} ${fitAB} ${linkName} ${user} ${nmaxjobstot} ${debug} > ${smlog} &\n"; 
0202         system ${command};    
0203         $analyzeSMRunning[$fed-600]=1;
0204     }
0205     
0206     sleep 1;
0207     }
0208         
0209     close(SORTDIR);
0210 }
0211 
0212 sub isAnalyzeSMRunning
0213 {    
0214     my $fedToCheck=$_[0];
0215     my $smToCheck=$_[1];
0216     my $username=$_[2];
0217     my $linkName=$_[3];
0218     
0219     my $isItRunning=1;
0220 
0221     my $command = "ps x -u $username";
0222      
0223     my $nproc=0;
0224     
0225     open(COMMAND, "${command}|" ) or die $!;
0226     while( my $ligne = <COMMAND> ) {
0227     next unless( $ligne =~ /(.*)analyzeSM.pl $fedToCheck $smToCheck(.*)$linkName(.*)/ ); 
0228     $nproc=$nproc+1;
0229     }
0230     close COMMAND;
0231     
0232     if( $debug ==1 ) {print "isAnalyzeSMRunning: $fed nproc= $nproc \n"; }
0233     if( $nproc == 0 ) {
0234     $isItRunning=0;
0235     }
0236     return $isItRunning; 
0237 }
0238 
0239 sub isDetectSMRunning
0240 {    
0241     my $fedToCheck=$_[0];
0242     my $smToCheck=$_[1];
0243     my $username=$_[2];
0244     my $linkName=$_[3];
0245     
0246     my $isItRunning=1;
0247 
0248     my $command = "ps x -u $username";
0249      
0250     my $nproc=0;
0251     
0252     open(COMMAND, "${command}|" ) or die $!;
0253     while( my $ligne = <COMMAND> ) {
0254     next unless( $ligne =~ /(.*)detectSM.pl $fedToCheck $smToCheck(.*)$linkName(.*)/ ); 
0255     $nproc=$nproc+1;
0256     }
0257     close COMMAND;
0258     
0259     if( $debug ==1 ) {print "isDetectSMRunning: $fed nproc= $nproc \n"; }
0260     if( $nproc == 0 ) {
0261     $isItRunning=0;
0262     }
0263     return $isItRunning; 
0264 }
0265 
0266