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 
0004 # SELMA - Saclay Ecal Laser Monitoring and Analysis
0005 # contacts: Julie Malcles, Gautier Hamel de Monchenault, Serguei Ganjour, Patrice Verrecchia
0006 # last modified: Sat Jul 28 09:58:19 CEST 2007
0007 
0008 use Term::ANSIColor;
0009 #use Date::Manip; 
0010 use Cwd;
0011 
0012 $fed         = @ARGV[0];
0013 $ecalmod     = @ARGV[1];
0014 $useMatacq   = @ARGV[2];
0015 $useShape    = @ARGV[3];
0016 $fitAB       = @ARGV[4];
0017 $linkname    = @ARGV[5];
0018 $user        = @ARGV[6];
0019 $nmaxjobstot = @ARGV[7];
0020 $debug       = @ARGV[8];
0021 
0022 die unless( $ecalmod =~ /E(E|B)(\+|-)(\d*)/ );
0023 
0024 $zone = "Barrel";
0025 $ecalPart="EB";
0026 $digis="ebDigis";
0027 if( $1 eq "E" ) { 
0028     $zone = "EndCap"; 
0029     $ecalPart="EE";
0030     $digis="eeDigis";
0031 }
0032 $side = "positive";
0033 if( $2 eq "-" ) { $side = "negative" };
0034 $sm = $3;
0035 
0036 $localdir     = cwd;
0037 if (  $linkname eq "" ) {
0038     $proddir      = "${localdir}/LaserMonitoring";
0039 }else{
0040     $proddir      = "${localdir}/${linkname}";
0041 }
0042 $fitab="True";
0043 if($fitAB==0){
0044     $fitab="False";
0045 }
0046 
0047 $sortdir      = "$proddir/sorting";
0048 $scriptdir    = "$proddir/scripts";
0049 $shapedir     = "$proddir/shapes";
0050 $templatesdir = "$proddir/templates";
0051 $runsdir      = "$proddir/${ecalmod}/Runs";
0052 $laserdir     = "$proddir/${ecalmod}/Laser";
0053 $pedestaldir  = "$proddir/${ecalmod}/Pedestal";
0054 $leddir       = "$proddir/${ecalmod}/LED";
0055 $testpulsedir = "$proddir/${ecalmod}/TestPulse";
0056 $mailboxdir   = "$proddir/MailBox";
0057 
0058 do "${scriptdir}/monitoringFunctions.pl";
0059 
0060 print color("red"), "\n\n***** Saclay Ecal Laser Monitoring & Analysis *****\n\n", color("reset");
0061 
0062 
0063 while( 1 ) 
0064 {
0065     system date;
0066   #  doLaser();
0067   #  doTestPulse();
0068     doBoth(); 
0069     sleep 1;
0070 }
0071 
0072 exit;
0073 
0074 sub doBoth 
0075 {
0076     print color("green"), "\n *** Restarting Analyzer for FED: ${fed} ***\n\n", color("reset");
0077     
0078     my $detected = "$laserdir/Detected";
0079     my $analyzed = "$laserdir/Analyzed";
0080     my $failed   = "$laserdir/Analyzed/Failed";
0081 
0082     my $TPdetected = "$testpulsedir/Detected";
0083     my $TPanalyzed = "$testpulsedir/Analyzed";
0084     my $TPfailed   = "$testpulsedir/Analyzed/Failed";
0085 
0086     opendir( DIR, $detected ) || die "cannot open $detected directory\n";
0087     
0088     my @dirs = sort  readdir( DIR );
0089     
0090     foreach my $dirname (@dirs)
0091     { 
0092     # skip if already analyzed
0093 
0094     next if( -e "${laserdir}/Analyzed/${dirname}");
0095     
0096     my $isThereTP=0;
0097     if( -e "$TPdetected/${dirname}") {
0098         $isThereTP=1;
0099     }
0100 
0101     # skip if already analyzed
0102     
0103     if( -e "$TPanalyzed/${dirname}"){
0104         $isThereTP=0;
0105     }
0106     
0107     if( $dirname =~ /Run(\d*)_LB(\d*)/ )
0108     {
0109         my $run = $1;
0110         my $lb = $2;
0111         print color("blue"), " Analyzing Laser data for Run: $run, and Lumi Block $lb \n", color("reset");
0112         my $mydate = `date +%s`;
0113         print " Starting at: ${mydate} \n";
0114         system date;    
0115 
0116         my $jobdir = "${runsdir}/${dirname}";
0117         
0118         my $statusfile   = "$jobdir/statusLaser.txt";
0119         my $TPstatusfile   = "$jobdir/statusTestPulse.txt";
0120         my $command;
0121         
0122         die unless( opendir( CURRENTDIR, ${jobdir} ) );
0123  
0124         open( STATUSFILE, ">>$statusfile" ) || die "cannot open file $statusfile\n";
0125 
0126         # set pointer to the last detected run
0127         if( -e "${laserdir}/lastDetected" ) { system "rm -f ${laserdir}/lastDetected"; }
0128         system "ln -sf ../Runs/${dirname} ${laserdir}/lastDetected";
0129 
0130         if($isThereTP==1){
0131         
0132         open( STATUSFILETP, ">>$TPstatusfile" ) || die "cannot open file $TPstatusfile\n";
0133         
0134         # set pointer to the last detected run
0135         if( -e "${testpulsedir}/lastDetected" ) { system "rm -f ${testpulsedir}/lastDetected"; }
0136         system "ln -sf ../Runs/${dirname} ${testpulsedir}/lastDetected";
0137         }
0138         
0139         # check MATACQ
0140         # ==============
0141         
0142         my $matacqOK=0;
0143         my $matacqlog="header";
0144         
0145         if( $useMatacq == 1 ){
0146         $matacqOK = checkMatacqJob($dirname, $matacqlog );
0147         }
0148         my $laserOK2=0;
0149         my $laserOK=0;
0150         my $TPOK=0;
0151         my $ABOK=0;
0152 
0153         
0154         # analyze LASER data
0155         # ====================
0156 
0157         if( $matacqOK && $useMatacq && $useShape ){ 
0158         
0159         # with templates method if matacq is OK
0160         $laserOK2 = analyzeLaser2($dirname);
0161         
0162         # get alpha and beta if laser analysis OK
0163         if($laserOK2) {
0164             $ABOK = analyzeAB($dirname);
0165         }
0166         
0167         # analyze data with alpha beta if not
0168         else {
0169             
0170             @OKBoth = analyzeBoth($dirname, $isThereTP ); 
0171             $laserOK = @OKBoth[0];
0172             $TPOK = @OKBoth[1];
0173         }
0174         
0175         }else{
0176         
0177         # with alpha and beta 
0178         
0179         @OKBoth = analyzeBoth($dirname, $isThereTP ); 
0180         $laserOK = @OKBoth[0];
0181         $TPOK = @OKBoth[1];
0182         
0183         if( $laserOK ) {
0184             $ABOK = 1;
0185         }
0186         }
0187         
0188         my $mydate = `date +%s`;
0189         print " ....... done at: ${mydate} \n";
0190         system date;    
0191         
0192         print STATUSFILE  "RUN = $run\n";
0193         print STATUSFILE  "LB = $lb\n";
0194         if( $matacqOK ) { print STATUSFILE  "MATACQ = OK\n" } else  { print STATUSFILE  "MATACQ = FAILED\n" }
0195         if( $laserOK2 )  { 
0196         print STATUSFILE  "LASER = OK\n";
0197         print STATUSFILE "Templates method\n";
0198         if( $ABOK )  { print STATUSFILE     "AB = OK\n" } 
0199         }elsif( $laserOK )  {   
0200         print STATUSFILE  "LASER = OK\n";
0201         if($fitAB==0){ print STATUSFILE "Fixed AlphaBeta method\n";}
0202         if($fitAB==1){ print STATUSFILE "Fitted AlphaBeta method\n";}
0203         }
0204         
0205 #       if ( ($laserOK && $useMatacq==0) || (($laserOK || $laserOK2) && $matacqOK )) 
0206         if ( ($laserOK) || ($laserOK2 && $matacqOK) )  # if redundant prb with mtq 
0207         {
0208         
0209         print STATUSFILE  "STATUS = ANALYZED\n";
0210         system "ln -sf ../../Runs/${dirname} ${laserdir}/Analyzed/${dirname}";
0211         
0212         # set pointer to the last analyzed run
0213         if( -e "${laserdir}/lastAnalyzed" ) { system "rm -f ${laserdir}/lastAnalyzed"; }
0214         system "ln -sf ../Runs/${dirname} ${laserdir}/lastAnalyzed";
0215         
0216         }  else 
0217         {
0218         print STATUSFILE  "STATUS = FAILED\n";
0219         system "rm -f ${detected}/${dirname}; ln -sf ../../../Runs/${dirname} ${failed}/${dirname}";
0220         }
0221         
0222         close STATUSFILE;
0223         
0224         if($isThereTP==1){
0225         
0226         print TPSTATUSFILE  "RUN = $run\n";
0227         print TPSTATUSFILE  "LB = $lb\n";
0228         if ( $TPOK == 1 ) 
0229         {
0230             
0231             print TPSTATUSFILE  "STATUS = ANALYZED\n";
0232             system "rm -f ${TPdetected}/${dirname}; ln -sf ../../Runs/${dirname} ${TPanalyzed}/${dirname}";
0233             
0234             # set pointer to the last analyzed run
0235             if( -e "${testpulsedir}/lastAnalyzed" ) { system "rm -f ${testpulsedir}/lastAnalyzed"; }
0236             system "ln -sf ../Runs/${dirname} ${testpulsedir}/lastAnalyzed";
0237         }
0238         else 
0239         {
0240             print TPSTATUSFILE  "STATUS = FAILED\n";
0241             system "rm -f ${TPdetected}/${dirname}; ln -sf  ../../../Runs/${dirname} ${TPfailed}/${dirname}";
0242         }
0243         close TPSTATUSFILE;
0244         }
0245         
0246     }
0247     }
0248     closedir( DIR ); 
0249 }
0250 
0251 sub doLaser 
0252 {
0253 
0254     print color("green"), "\n *** Restarting Laser Analyzer for FED: ${fed} ***\n\n", color("reset");
0255     
0256     my $detected = "$laserdir/Detected";
0257     my $analyzed = "$laserdir/Analyzed";
0258     my $failed   = "$laserdir/Analyzed/Failed";
0259 
0260     opendir( DIR, $detected ) || die "cannot open $detected directory\n";
0261 
0262     my @dirs = sort  readdir( DIR );
0263 
0264     foreach my $dirname (@dirs)
0265     { 
0266     # skip if already analyzed
0267 
0268     next if( -e "${laserdir}/Analyzed/${dirname}");
0269     
0270     if( $dirname =~ /Run(\d*)_LB(\d*)/ )
0271     {
0272         my $run = $1;
0273         my $lb = $2;
0274         print color("blue"), " Analyzing Laser data for Run: $run, and Lumi Block $lb \n", color("reset");
0275         
0276         my $jobdir = "${runsdir}/${dirname}";
0277     
0278         my $statusfile   = "$jobdir/statusLaser.txt";
0279         my $command;
0280 
0281         die unless( opendir( CURRENTDIR, ${jobdir} ) );
0282  
0283         open( STATUSFILE, ">>$statusfile" ) || die "cannot open file $statusfile\n";
0284 
0285         # set pointer to the last detected run
0286         if( -e "${laserdir}/lastDetected" ) { system "rm -f ${laserdir}/lastDetected"; }
0287         system "ln -sf ../Runs/${dirname} ${laserdir}/lastDetected";
0288 
0289        
0290         # analyze MATACQ
0291         # ===============
0292         my $matacqOK=0;
0293         my $laserOK2=0;
0294         my $laserOK=0;
0295         my $ABOK=0;
0296 
0297         my $matacqlog="header";
0298         
0299         if( $useMatacq == 1 ){
0300         $matacqOK = checkMatacqJob($dirname, $matacqlog );
0301         }
0302         
0303         # analyze LASER data
0304         # ====================
0305 
0306         if( $matacqOK && $useMatacq && $useShape ){ 
0307         
0308         # with templates method if matacq is OK
0309         $laserOK2 = analyzeLaser2($dirname);
0310         
0311         # get alpha and beta if laser analysis OK
0312         if($laserOK2) {
0313             $ABOK = analyzeAB($dirname);
0314         }
0315         
0316         # analyze data with alpha beta if not
0317         else {
0318             $laserOK = analyzeLaser($dirname); 
0319         }
0320         
0321         }else{
0322         
0323         # with alpha and beta if there is no matacq
0324         $laserOK = analyzeLaser($dirname); 
0325         if( $laserOK ) {
0326             $ABOK = 1;
0327         }
0328         }
0329         
0330         print STATUSFILE  "RUN = $run\n";
0331         print STATUSFILE  "LB = $lb\n";
0332         if( $matacqOK ) { print STATUSFILE  "MATACQ = OK\n" } else  { print STATUSFILE  "MATACQ = FAILED\n" }
0333         if( $laserOK2 )  { 
0334         print STATUSFILE  "LASER = OK\n";
0335         print STATUSFILE "Templates method\n";
0336         if( $ABOK )  { print STATUSFILE     "AB = OK\n" } 
0337         }elsif( $laserOK )  {   
0338         print STATUSFILE  "LASER = OK\n";
0339         if($fitAB==0){ print STATUSFILE "Fixed AlphaBeta method\n";}
0340         if($fitAB==1){ print STATUSFILE "Fitted AlphaBeta method\n";}
0341         }
0342         
0343 #       if ( ($laserOK && $useMatacq==0) || (($laserOK || $laserOK2) && $matacqOK )) 
0344         if ( ($laserOK ) || ($laserOK2 && $matacqOK )) # if redundant prb with mtq 
0345         {
0346         
0347         print STATUSFILE  "STATUS = ANALYZED\n";
0348         system "ln -sf ../../Runs/${dirname} ${laserdir}/Analyzed/${dirname}";
0349         
0350         # set pointer to the last analyzed run
0351         if( -e "${laserdir}/lastAnalyzed" ) { system "rm -f ${laserdir}/lastAnalyzed"; }
0352         system "ln -sf ../Runs/${dirname} ${laserdir}/lastAnalyzed";
0353         
0354         }  else 
0355         {
0356         print STATUSFILE  "STATUS = FAILED\n";
0357         system "rm -f ${detected}/${dirname}; ln -sf ../../../Runs/${dirname} ${failed}/${dirname}";
0358         }
0359         
0360         close STATUSFILE;
0361     }
0362     }
0363     closedir( DIR ); 
0364 }
0365 
0366 sub doTestPulse 
0367 {
0368     
0369     print color("green"), "\n *** Restarting TestPulse Analyzer for FED: ${fed} ***\n\n", color("reset");
0370 
0371     my $detected = "$testpulsedir/Detected";
0372     my $analyzed = "$testpulsedir/Analyzed";
0373     my $failed   = "$testpulsedir/Analyzed/Failed";
0374 
0375 
0376     opendir( DIR, $detected ) || die "cannot open $detected directory\n";
0377 
0378     my @dirs = sort  readdir( DIR );
0379     foreach my $dirname (@dirs)
0380     {
0381     # skip if already analyzed
0382     
0383     next if( -e "${testpulsedir}/Analyzed/${dirname}");
0384     
0385     if( $dirname =~ /Run(\d*)_LB(\d*)/ )
0386     {
0387         my $run = $1;
0388         my $lb = $2;
0389         print color("blue"), " Analyzing Test-Pulse data for Run: $run, and Lumi Block $lb \n", color("reset");
0390     
0391         my $jobdir = "${runsdir}/${dirname}";
0392         my $statusfile   = "$jobdir/statusTestPulse.txt";
0393         my $command;
0394 
0395         die unless( opendir( CURRENTDIR, ${jobdir} ) );
0396  
0397         open( STATUSFILE, ">>$statusfile" ) || die "cannot open file $statusfile\n";
0398 
0399         # set pointer to the last detected run
0400         if( -e "${testpulsedir}/lastDetected" ) { system "rm -f ${testpulsedir}/lastDetected"; }
0401         system "ln -sf ../Runs/${dirname} ${testpulsedir}/lastDetected";
0402 
0403         # analyze TESTPULSE
0404         my $testpulseOK =  analyzeTestPulse($dirname);
0405 
0406         print STATUSFILE  "RUN = $run\n";
0407         print STATUSFILE  "LB = $lb\n";
0408         if ( $testpulseOK ) 
0409         {
0410             
0411         print STATUSFILE  "STATUS = ANALYZED\n";
0412         system "rm -f ${detected}/${dirname}; ln -sf ../../Runs/${dirname} ${analyzed}/${dirname}";
0413 
0414         # set pointer to the last analyzed run
0415         if( -e "${testpulsedir}/lastAnalyzed" ) { system "rm -f ${testpulsedir}/lastAnalyzed"; }
0416         system "ln -sf ../Runs/${dirname} ${testpulsedir}/lastAnalyzed";
0417         }
0418         else 
0419         {
0420         print STATUSFILE  "STATUS = FAILED\n";
0421         system "rm -f ${detected}/${dirname}; ln -sf  ../../../Runs/${dirname} ${failed}/${dirname}";
0422         }
0423         close STATUSFILE;
0424     }
0425     }
0426     closedir(DIR)
0427 }
0428 
0429 sub analyzeMatacq 
0430 {
0431     my $arg = 0;
0432     my $dirname    = shift;
0433     my $cfgfile = "matacq";
0434     my $jobdir = "${runsdir}/${dirname}";
0435     open( TEMPLATE, "${templatesdir}/${cfgfile}.py" );
0436     open( CFGFILE, ">${jobdir}/${cfgfile}.py" );
0437     while( <TEMPLATE> )
0438     {  
0439     $_ =~ s/FFFF/$fed/g;
0440     $_ =~ s/DDDD/$debug/g;
0441     print CFGFILE $_;
0442     }
0443     close CFGFILE;
0444     close TEMPLATE;
0445 
0446     print " - Getting Matacq primitives";
0447 
0448     # submit the MATACQ job
0449 
0450     my $key="matacq";
0451     my $key2="cmsRun";
0452     
0453     my $isItSent = sendCMSJob(${key}, ${key2}, ${nmaxjobstot}, ${user}, ${jobdir}, ${scriptdir});        
0454     if( $isItSent == 1 ){ 
0455     print "....... done\n"; 
0456     }
0457     
0458 
0459     $arg = checkMatacqJob($dirname,${cfgfile});
0460     return $arg;
0461 }
0462 
0463 sub analyzeLaser 
0464 {
0465     my $arg = 0;
0466     my $dirname    = shift;
0467     my $cfgfile = "laser";
0468     my $jobdir = "${runsdir}/${dirname}";
0469     open( TEMPLATE, "${templatesdir}/${cfgfile}.py" );
0470     open( CFGFILE, ">${jobdir}/${cfgfile}.py" );
0471     while( <TEMPLATE> )
0472     {
0473     $_ =~ s/CCCC/$digis/g;
0474     $_ =~ s/PPPP/$ecalPart/g;
0475     $_ =~ s/FFFF/$fed/g;
0476     $_ =~ s/DDDD/$debug/g;
0477     $_ =~ s/AAAA/$fitab/g;
0478     print CFGFILE $_;
0479     }
0480     close CFGFILE;
0481     close TEMPLATE;
0482     
0483     print " - Getting APD primitives (AB method)";
0484 
0485     # submit the LASER job
0486 
0487     my $key="laser";
0488     my $key2="cmsRun";
0489     
0490     my $isItSent = sendCMSJob(${key}, ${key2}, ${nmaxjobstot}, ${user}, ${jobdir}, ${scriptdir});        
0491     if( $isItSent == 1 ){ print "....... done\n"; }
0492 
0493     $arg = checkLaserJob($dirname,$cfgfile);
0494     return $arg;
0495 }
0496 
0497 sub analyzeLaser2 
0498 {
0499     my $arg = 0;
0500     my $dirname    = shift;
0501     my $cfgfile = "laser2";
0502     my $jobdir = "${runsdir}/${dirname}";
0503     open( TEMPLATE, "${templatesdir}/${cfgfile}.py" );
0504     open( CFGFILE, ">${jobdir}/${cfgfile}.py" );
0505     while( <TEMPLATE> )
0506     {
0507     $_ =~ s/CCCC/$digis/g;
0508     $_ =~ s/PPPP/$ecalPart/g;
0509     $_ =~ s/FFFF/$fed/g;
0510     $_ =~ s/DDDD/$debug/g;
0511     print CFGFILE $_;
0512     }
0513     close CFGFILE;
0514     close TEMPLATE;
0515 
0516     print " - Getting APD primitives (shape method)";
0517 
0518     # submit the LASER job
0519 
0520     my $key="laser2";
0521     my $key2="cmsRun";
0522     
0523     my $isItSent = sendCMSJob(${key}, ${key2}, ${nmaxjobstot}, ${user}, ${jobdir}, ${scriptdir});        
0524     if( $isItSent == 1 ){ print "....... done\n"; }
0525 
0526     $arg = checkLaserJob2($dirname,${cfgfile});
0527     return $arg;
0528 }
0529 sub analyzeAB 
0530 {
0531     my $arg = 0;
0532     my $dirname    = shift;
0533     my $cfgfile = "ab";
0534     my $jobdir = "${runsdir}/${dirname}";
0535     open( TEMPLATE, "${templatesdir}/${cfgfile}.py" );
0536     open( CFGFILE, ">${jobdir}/${cfgfile}.py" );
0537     while( <TEMPLATE> )
0538     {
0539     $_ =~ s/CCCC/$digis/g;
0540     $_ =~ s/FFFF/$fed/g;
0541     print CFGFILE $_;
0542     }
0543     close CFGFILE;
0544     close TEMPLATE;
0545     
0546     print "Getting alpha and beta";
0547 
0548     # submit the AB job
0549     my $key="ab";
0550     my $key2="cmsRun";
0551     
0552     my $isItSent = sendCMSJob(${key}, ${key2}, ${nmaxjobstot}, ${user}, ${jobdir}, ${scriptdir});        
0553     if( $isItSent == 1 ){ print "....... done\n"; }
0554 
0555     $arg = checkABJob($dirname, $cfgfile);
0556     return $arg;
0557 }
0558 
0559 sub analyzeTestPulse 
0560 {
0561     my $arg = 0;
0562     my $dirname    = shift;
0563     my $cfgfile = "testpulse";
0564     my $jobdir = "${runsdir}/${dirname}";
0565     open( TEMPLATE, "${templatesdir}/${cfgfile}.py" );
0566     open( CFGFILE, ">${jobdir}/${cfgfile}.py" );
0567     while( <TEMPLATE> )
0568     {
0569     $_ =~ s/CCCC/$digis/g;
0570     $_ =~ s/FFFF/$fed/g;
0571     print CFGFILE $_;
0572     }
0573     close CFGFILE;
0574     close TEMPLATE;
0575 
0576     print " - Getting APD primitives";
0577 
0578     # submit the TESTPULSE job 
0579     my $key="testpulse";
0580     my $key2="cmsRun";
0581     
0582     my $isItSent = sendCMSJob(${key}, ${key2}, ${nmaxjobstot}, ${user}, ${jobdir}, ${scriptdir});        
0583     if( $isItSent == 1 ){ print "....... done\n"; }
0584 
0585     $arg = checkTestPulseJob($dirname, $cfgfile);
0586     return $arg;
0587 }
0588 
0589 sub checkMatacqJob 
0590 {
0591     my $arg = 1;
0592     my $dirname=$_[0];
0593     my $logname=$_[1];
0594 
0595     print "Check result of Matacq data analysis\n";
0596 
0597     my $jobdir = "${runsdir}/${dirname}";
0598     my $file = "$jobdir/${logname}.log";
0599     my $run = 0;
0600     my $event = 0;
0601     my $nrun = 0;
0602     my $ii = 0;
0603     
0604     open ( FILE, $file) || die "cannot open $file log file \n";
0605     while (<FILE>)
0606     {
0607     chomp ($_);
0608     $theLine = $_;
0609     if( $theLine =~ /BeforeEvents/ )
0610     {
0611         print "$theLine\n";
0612     }
0613     if( $theLine =~ /PostModule/ )
0614     {
0615         $ii++;
0616         if($ii==1) { print "$theLine\n"; }
0617     }
0618     if( $theLine =~ /Run: (.*) Event: (.*)/)
0619     {
0620         if( $1 != $run ) 
0621         {
0622         $nrun++;
0623         $run= $1;
0624         }
0625         $event = $2;
0626     }
0627     if( $theLine =~ /\+=\+/ )
0628     {
0629         print "$theLine\n";
0630         
0631     }
0632     if( $theLine =~ /WARNING! NO MATACQ/ ){
0633         print "$theLine\n";
0634         $arg =0;   
0635     }
0636     
0637     }
0638     close FILE;
0639     if( $nrun > 1 )
0640     {
0641     print "WARNING! More than one run analyzed!\n";
0642     $arg = 0;
0643     } 
0644     if( $arg ) 
0645     {
0646     print "....... OK\n";
0647     }
0648     else
0649     {
0650     print "....... Failure\n";
0651     }
0652     return $arg;
0653 }
0654 
0655 sub checkLaserJob 
0656 {
0657     my $dirname=$_[0];
0658     my $logname=$_[1];
0659     my $arg = 1;
0660     print "Check result of Laser data analysis\n";
0661 
0662     my $jobdir = "${runsdir}/${dirname}";
0663     my $file = "$jobdir/${logname}.log";
0664     my $run = 0;
0665     my $event = 0;
0666     my $nrun = 0;
0667     my $ii = 0;
0668 
0669 
0670     my $computeAB    = 0;
0671     if($fitAB==0){ 
0672     $computeAB=1; 
0673     }
0674     my $analyzeAPD   = 0;
0675     my $allOK        = 0;
0676     
0677     open ( FILE, $file) || die "cannot open $file log file \n";
0678     while (<FILE>)
0679     {
0680     chomp ($_);
0681     $theLine = $_;
0682     if( $theLine =~ /FwkReport:  main_input:source (.*) CEST BeforeEvents/ )
0683     {
0684         $t1 = $1;
0685         print "$theLine\n";
0686     }
0687     if( $theLine  =~ /FwkJob:  PostModule (.*) CEST/ )
0688     {
0689         $t2 = $1;
0690         $ii++;
0691         if($ii==1) { print "$theLine\n"; }
0692     }
0693     if( $theLine =~ /Run: (.*) Event: (.*)/)
0694     {
0695         if( $1 != $run ) 
0696         {
0697         $nrun++;
0698         $run= $1;
0699         }
0700         $event = $2;
0701     }
0702 
0703     if( $theLine =~ /No Laser Events/)
0704     {
0705         print "$theLine\n";
0706     }
0707     if( $theLine =~ /\+=\+/ )
0708     {
0709         print "$theLine\n";
0710         if( $computeAB == 1 )
0711         {
0712         if( $analyzeAPD == 1 )
0713         {
0714             $allOK = 1;
0715         }
0716         else
0717         {
0718             if( $analyzeAPD == 2 && $theLine =~ /... done/ )
0719             {
0720             $analyzeAPD = 1;
0721             }
0722             elsif( $theLine =~ /Analyzing laser data/ )
0723             {
0724             $analyzeAPD = 2;
0725             
0726             }
0727             elsif( $theLine =~ /APD GAIN WAS NOT 1/ )
0728             {
0729             $analyzeAPD = 0;
0730             
0731             }
0732         }
0733         }
0734         else
0735         {
0736         if( $computeAB == 2 && $theLine =~ /... done/ )
0737         {
0738             $computeAB = 1;
0739         }
0740         elsif( $theLine =~ /Analyzing data/ )
0741         {
0742             $computeAB = 2;
0743         }
0744         }
0745     }
0746     }
0747 
0748     close FILE;
0749    
0750     if( ! $allOK ) 
0751     {
0752     $arg = 0;
0753     }
0754     
0755     if( $nrun > 1 )
0756     {
0757     print "WARNING! More than one run analyzed!\n";
0758     $arg = 0;
0759     } 
0760     
0761     if( $arg ) 
0762     {
0763     print "....... OK\n";
0764     }
0765     else
0766     {
0767     print "....... Failure\n";
0768     }
0769     return $arg;
0770 }
0771 
0772 sub checkLaserJob2 
0773 {
0774     my $dirname=$_[0];
0775     my $logname=$_[1];
0776     my $arg = 1;
0777     print "Check result of Laser data analysis\n";
0778 
0779     my $jobdir = "${runsdir}/${dirname}";
0780     my $file = "$jobdir/${logname}.log";
0781     my $run = 0;
0782     my $event = 0;
0783     my $nrun = 0;
0784     my $ii = 0;
0785 
0786     my $analyzeAPD   = 0;
0787     my $allOK        = 0;
0788     my $shape        = 1;
0789     
0790     open ( FILE, $file) || die "cannot open $file log file \n";
0791     while (<FILE>)
0792     {
0793     chomp ($_);
0794     $theLine = $_;
0795     if( $theLine =~ /FwkReport:  main_input:source (.*) CEST BeforeEvents/ )
0796     {
0797         $t1 = $1;
0798         print "$theLine\n";
0799     }
0800     if( $theLine  =~ /FwkJob:  PostModule (.*) CEST/ )
0801     {
0802         $t2 = $1;
0803         $ii++;
0804         if($ii==1) { print "$theLine\n"; }
0805     }
0806     if( $theLine =~ /Run: (.*) Event: (.*)/)
0807     {
0808         if( $1 != $run ) 
0809         {
0810         $nrun++;
0811         $run= $1;
0812         }
0813         $event = $2;
0814     }
0815     if( $theLine =~ /No Laser Events/)
0816     {
0817         print "$theLine\n";
0818     }
0819     if( $theLine =~ /\+=\+/ )
0820     {
0821         print "$theLine\n";
0822         
0823         if( $analyzeAPD == 1 )
0824         {
0825         $allOK = 1;
0826         }
0827         else
0828         {
0829         if( $analyzeAPD == 2 && $theLine =~ /... done/ )
0830         {
0831             $analyzeAPD = 1;
0832         }
0833         elsif( $theLine =~ /Analyzing laser data/ )
0834         {
0835             $analyzeAPD = 2;
0836         }
0837         elsif( $theLine =~ /APD GAIN WAS NOT 1/ )
0838         {
0839             $analyzeAPD = 0;
0840             
0841         }
0842         }
0843     }
0844 
0845     if( $theLine =~ /No matacq shape available/ )
0846     {
0847         print "$theLine\n";
0848         $shape = 0;    
0849         
0850     }
0851     if( $theLine =~ /Matacq shape file not found/ )
0852     {
0853         print "$theLine\n";
0854         $shape = 0;    
0855     }
0856     
0857     }
0858     
0859     close FILE;
0860  
0861     if( $allOK && $shape ){  
0862     
0863     $arg = 1;
0864     }else
0865     {
0866     $arg = 0;
0867     } 
0868     
0869     if( $nrun > 1 )
0870     {
0871     print "WARNING: More than one run analyzed!\n";
0872     $arg = 0;
0873     } 
0874     
0875     if( $arg ) 
0876     {
0877     print "....... OK\n";
0878     }
0879     else
0880     {
0881     print "....... Failure\n";
0882     }
0883     return $arg;
0884 }
0885 
0886 sub checkTestPulseJob 
0887 {
0888     my $arg = 1;
0889     my $dirname=$_[0];
0890     my $logname=$_[1];
0891     print "Check result of Test-Pulse data analysis\n";
0892 
0893     my $jobdir = "${runsdir}/${dirname}";
0894     my $file = "$jobdir/${logname}.log";
0895     my $run = 0;
0896     my $event = 0;
0897     my $nrun = 0;
0898     my $ii = 0;
0899     
0900     open ( FILE, $file) || die "cannot open $file log file \n";
0901     while (<FILE>)
0902     {
0903     chomp ($_);
0904     $theLine = $_;
0905     if( $theLine =~ /FwkReport:  main_input:source (.*) CEST BeforeEvents/ )
0906     {
0907         $t1 = $1;
0908         print "$theLine\n";
0909     }
0910     if( $theLine  =~ /FwkJob:  PostModule (.*) CEST/ )
0911     {
0912         $t2 = $1;
0913         $ii++;
0914         if($ii==1) { print "$theLine\n"; }
0915     }
0916     if( $theLine =~ /Run: (.*) Event: (.*)/)
0917     {
0918         if( $1 != $run ) 
0919         {
0920         $nrun++;
0921         $run= $1;
0922         }
0923         $event = $2;
0924     }
0925     if( $theLine =~ /\+=\+/ )
0926     {
0927         $arg = 1;
0928         print "$theLine\n";
0929     }
0930     }
0931 
0932     close FILE;
0933     if( $arg ) 
0934     {
0935     print "....... OK\n";
0936     }
0937     else
0938     {
0939     print "....... Failure\n";
0940     }
0941     return $arg;
0942 }
0943 
0944 sub checkABJob 
0945 {
0946 
0947     my $arg = 1;
0948     my $dirname=$_[0];
0949     my $logname=$_[1];
0950     print "Check result of alpha and beta computation \n";
0951 
0952     my $jobdir = "${runsdir}/${dirname}";
0953     my $file = "$jobdir/${logname}.log";
0954     my $run = 0;
0955     my $event = 0;
0956     my $nrun = 0;
0957     my $ii = 0;
0958 
0959     my $computeAB    = 0;
0960     my $allOK        = 0;
0961     
0962     open ( FILE, $file) || die "cannot open $file log file \n";
0963     while (<FILE>)
0964     {
0965     chomp ($_);
0966     $theLine = $_;
0967     if( $theLine =~ /FwkReport:  main_input:source (.*) CEST BeforeEvents/ )
0968     {
0969         $t1 = $1;
0970         print "$theLine\n";
0971     }
0972     if( $theLine  =~ /FwkJob:  PostModule (.*) CEST/ )
0973     {
0974         $t2 = $1;
0975         $ii++;
0976         if($ii==1) { print "$theLine\n"; }
0977     }
0978     if( $theLine =~ /Run: (.*) Event: (.*)/)
0979     {
0980         if( $1 != $run ) 
0981         {
0982         $nrun++;
0983         $run= $1;
0984         }
0985         $event = $2;
0986     }
0987     if( $theLine =~ /\+=\+/ )
0988     {
0989         print "$theLine\n";
0990         if( $computeAB != 1 )
0991         {
0992         if( $computeAB == 2 && $theLine =~ /... done/ )
0993         {
0994             $computeAB = 1;
0995         }
0996         elsif( $theLine =~ /Analyzing data/ )
0997         {
0998             $computeAB = 2;
0999         }
1000         }
1001     }
1002     }
1003     
1004     close FILE;
1005 
1006     if( ! $allOK ) 
1007     {
1008     $arg = 0;
1009     }
1010     
1011     if( $nrun > 1 )
1012     {
1013     print "WARNING: More than one run analyzed!\n";
1014     $arg = 0;
1015     } 
1016     
1017     if( $arg ) 
1018     {
1019     print "....... OK\n";
1020     }
1021     else
1022     {
1023     print "....... Failure\n";
1024     }
1025     return $arg;
1026 }
1027 
1028 sub analyzeBoth 
1029 {
1030     my $dirname=$_[0];
1031     my $isThereTP=$_[1];
1032 
1033     my $cfgfile = "";
1034 
1035     if($isThereTP == 1){
1036     $cfgfile = "both";
1037     }else{
1038     $cfgfile = "laser";
1039     }
1040     
1041     my $jobdir = "${runsdir}/${dirname}";
1042     open( TEMPLATE, "${templatesdir}/${cfgfile}.py" );
1043     open( CFGFILE, ">${jobdir}/${cfgfile}.py" );
1044     while( <TEMPLATE> )
1045     {
1046     $_ =~ s/CCCC/$digis/g;
1047     $_ =~ s/PPPP/$ecalPart/g;
1048     $_ =~ s/FFFF/$fed/g;
1049     $_ =~ s/DDDD/$debug/g;  
1050     $_ =~ s/AAAA/$fitab/g;
1051     print CFGFILE $_;
1052     }
1053     close CFGFILE;
1054     close TEMPLATE;
1055     
1056     print " - Getting APD primitives for Laser (AB method) and TP";
1057 
1058     # submit the LASER job
1059 
1060     my $key="NoKey";
1061     
1062     my $isItSent = sendCMSJob(${cfgfile}, ${key}, ${nmaxjobstot}, ${user}, ${jobdir}, ${scriptdir});        
1063     if( $isItSent == 1 ){ print "....... done\n"; }
1064     
1065     my @arg=checkBothJob($dirname, $isThereTP, $cfgfile);
1066 
1067     return @arg;
1068 }
1069 
1070 sub checkBothJob 
1071 {
1072     my $dirname=$_[0];
1073     my $isThereTP=$_[1];
1074     my $logname=$_[2];
1075     
1076     my $arg1 = checkLaserJob($dirname,$logname);
1077     if( $isThereTP==1 ){
1078     my $arg2 = checkTestPulseJob($dirname,$logname);
1079     }else{
1080     my $arg2=2;
1081     }
1082     my @output;
1083     push(@output, $arg1);
1084     push(@output, $arg2);
1085     
1086     return @output;
1087 }