Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:54

0001 #!/bin/bash
0002 
0003 if [[ $3 == '' || $4 != '' ]]
0004 then
0005   echo "This script accepts exactly 3 command line arguments"
0006   echo "Invoke it in this way:"
0007   echo "getOfflineDQMData.sh Path dirName fileNameTemplate"
0008   echo "    Path:            name of the path where the files are"
0009   echo "    dirName: name of the directory where the log files are. Usually QualityLog"
0010   echo "    fileNameTemplate: prefix of the log file name"
0011   echo "Exiting."
0012   exit 1
0013 fi
0014 
0015 # The script accepts 4 command line parameters:
0016 # Example: cms_orcoff_prod
0017 export Path=$1
0018 export baseDir=$2
0019 export baseName=$3
0020 
0021 export workdir=$Path/$baseDir
0022 
0023 if [[ !( -d $workdir ) ]]
0024 then
0025   echo "Directory $workdir does not exist!"
0026   echo "Exiting."
0027   exit 1
0028 fi
0029 
0030 # Name of file to be skipped from loop (contains no real data)
0031 export badFileName=${baseName}1.txt
0032 
0033 # [Temporary] text file with summary data for each iteration step
0034 export outFileTK=./TrackerSummary.txt
0035 
0036 # File with output histograms
0037 export outRootFileTK=./TrackerSummary.root
0038 
0039 # File with prettier plots
0040 export outRootPlotsTK=./TrackerPlots.root
0041 
0042 #if [[ -f $outFileTK ]]
0043 #then
0044 #  echo "ERROR: txt output file already exists. Exiting."
0045 #  exit 1;
0046 #fi
0047 
0048 #if [[ -f $outRootFileTK ]]
0049 #  then
0050 #  echo "ERROR: root output file already exists. Exiting."
0051 #  exit 1;
0052 #fi
0053 
0054 # Use the root installation defined above
0055 #source ${ROOTSYS}/bin/thisroot.sh
0056 
0057 # In order to make the for loop work properly, I insert underscores here, and transform them to spaces afterwards
0058 for partName0 in Tracker TIB TID TOB TEC TIB_Layer_1_ TIB_Layer_2_ TIB_Layer_3_ TIB_Layer_4_ TID+_Disk_1_ TID+_Disk_2_ TID+_Disk_3_ TID-_Disk_1_ TID-_Disk_2_ TID-_Disk_3_ TOB_Layer_1_ TOB_Layer_2_ TOB_Layer_3_ TOB_Layer_4_ TOB_Layer_5_ TOB_Layer_6_ TEC+_Disk_1_ TEC+_Disk_2_ TEC+_Disk_3_ TEC+_Disk_4_ TEC+_Disk_5_ TEC+_Disk_6_ TEC+_Disk_7_ TEC+_Disk_8_ TEC+_Disk_9_ TEC-_Disk_1_ TEC-_Disk_2_ TEC-_Disk_3_ TEC-_Disk_4_ TEC-_Disk_5_ TEC-_Disk_6_ TEC-_Disk_7_ TEC-_Disk_8_ TEC-_Disk_9_ ;
0059 do
0060   # Change underscores to spaces, and add a colon at the end
0061   partName=`echo $partName0 | sed s/_/\ /g | sed s/$/:/g`
0062   if [[ $partName0 == "Tracker" || $partName0 == "TIB" || $partName0 == "TID" || $partName0 == "TOB" || $partName0 == "TEC" ]] ;
0063   then
0064     subDetName=$partName0
0065     partType="All"
0066     partNumber=0
0067   else
0068     subDetName=`echo $partName | awk '{print $1}'`
0069     partType=`echo $partName | awk '{print $2}'`
0070     partNumber=`echo $partName | awk '{print $3}'`
0071   fi
0072   touch $outFileTK
0073   echo Processing subDetName $subDetName, partType $partType, partNumber $partNumber
0074  
0075   for fileName in `ls $workdir` ;
0076   do
0077     # This has not any real data
0078     if [[ $fileName != "${baseName}1.txt" ]] ;
0079     then
0080       if [[ $fileName == "${baseName}"*  && $(( `wc -l "$workdir/$fileName" | awk '{print $1}'` - 51 )) > 0 ]] ; # File name must start with this string and must have at least that many lines
0081       then
0082         # Extract run number from first row of file
0083 # AV runNumber of line definition changed to be less dependent on the details of the log file
0084 #        runNumber=`head -n 1 "$workdir/$fileName" | awk '{print $6}'`
0085 #        line=`head -n 52 $workdir/$fileName | tail -n 44 | grep "$partName" | awk -F ":" '{print $2}'`
0086         runNumber=`grep "New IOV" "$workdir/$fileName" | awk '{print $6}'`
0087         line=`grep -A 10000 "Global Info" $workdir/$fileName | grep -B 10000 Detid | grep "$partName" | awk -F ":" '{print $2}'`
0088 #                echo $line
0089 #                echo $fileName
0090         nBadModulesTK=`echo $line | awk {'print $1'}`
0091         #         # If we have bad modules, check how many fibers they have
0092         #         if [[ $nBadModulesTK > '0' ]] ;
0093         #         then
0094         #           nBadModulesWithThreeFibersTK=0;
0095         #           for fiber in `tail +57 $workdir/$fileName  | grep -v TIB | grep -v TID | grep -v TOB | grep -v TEC | awk 'NF>0' | awk '$2>0 {print $4}'` ;
0096         #           do
0097         #             if [[ $fiber != 'x' ]] ;
0098         #             then
0099         #               let nBadModulesWithThreeFibersTK++;
0100         #             fi
0101         #           done
0102         #           let nBadModulesWithTwoFibersTK=$nBadModulesTK-$nBadModulesWithThreeFibersTK
0103         #           let nBadFibersFromModulesTK=$nBadModulesWithThreeFibersTK*3+$nBadModulesWithTwoFibersTK*2
0104         #           nAllBadFibersTK=`echo $line | awk {'print $3'}`
0105         #           let nBadFibersTK=$nAllBadFibersTK-$nBadFibersFromModulesTK
0106         #         else
0107         #           # We don't have bad modules: all bad fibers are tagged individually
0108         #           nBadFibersTK=`echo $line | awk {'print $3'}`
0109         #           nAllBadFibersTK=$nBadFibersTK
0110         #         fi
0111         nAllBadFibersTK=`echo $line | awk '{print $2}'`
0112         nAllBadAPVsTK=`echo $line | awk '{print $3}'`
0113         let nBadAPVsFromFibersTK=$nAllBadFibersTK*2
0114         let nBadAPVsTK=$nAllBadAPVsTK-$nBadAPVsFromFibersTK
0115         nAllBadStripsTK=`echo $line | awk '{print $4}'`
0116         let nBadStripsFromAPVsTK=$nAllBadAPVsTK*128;
0117         let nBadStripsTK=$nAllBadStripsTK-$nBadStripsFromAPVsTK
0118         echo $runNumber $nBadModulesTK $nAllBadFibersTK $nAllBadAPVsTK $nBadStripsTK $nBadStripsFromAPVsTK $nAllBadStripsTK >> $outFileTK
0119       elif [[ $fileName =~ "^${baseName}"  && $(( 52 - `wc -l "$workdir/$fileName" | awk '{print $1}'` )) > 0 ]] ;
0120       then
0121         echo "*** ERROR! Skipping file: $fileName because it is blank or has too few lines!"
0122         echo "*** Number of lines in the file =" `wc -l "$workdir/$fileName" | awk '{print $1}'`
0123         echo "*** The execution will continue without that IOV."
0124       fi
0125     fi
0126   done
0127   if [[ -f tmp.txt ]] ;
0128   then
0129 #    echo "Temporary file tmp.txt exists! remove it and retry!"
0130 #    exit 1
0131     rm tmp.txt;
0132   fi
0133   # Remove last newline from file, otherwise the macro will read twice the last line
0134   cat $outFileTK | awk '{if(NR>1)print l;l=$0};END{if(NR>=1)printf("%s",l);}' > tmp.txt
0135   mv tmp.txt $outFileTK
0136   # Now we have the file with all the data for the given partName. Process it with the ROOT macro
0137   makeTKTrend $outFileTK $outRootFileTK $subDetName $partType $partNumber
0138   rm $outFileTK
0139 done
0140 
0141 # Run a macro that creates prettier plots
0142 if [[ -f $outRootFileTK ]] ;
0143 then
0144     makePlots $outRootFileTK $outRootPlotsTK
0145 fi