Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-30 22:45:14

0001 #!/bin/bash
0002 
0003 dumpHelpAndExit(){
0004 cat << EOF
0005 
0006 examples:
0007     ./genLUT.sh dumpAll card=cardPhysics.sh
0008     ./genLUT.sh generate card=cardPhysics.sh
0009     ./genLUT.sh diff conditions/newtag/newtag.xml conditions/oldtag/oldtag.xml
0010     ./genLUT.sh validate card=cardPhysics.sh
0011 
0012 EOF
0013 exit 0
0014 }
0015 
0016 FullPath=`pwd -P`
0017 BaseDir=${FullPath#${CMSSW_BASE}/src/}
0018 CondDir=conditions
0019 templatefile=template.py
0020 
0021 inputConditions=(ElectronicsMap LutMetadata LUTCorrs QIETypes QIEData SiPMParameters TPParameters TPChannelParameters ChannelQuality Gains Pedestals RespCorrs L1TriggerObjects)
0022 
0023 
0024 
0025 CheckParameter(){
0026     if [[ -z ${!1} ]]
0027     then
0028         echo "ERROR: Parameter '$1' is not provided."
0029         exit 1
0030     fi
0031 }
0032 
0033 CheckFile(){
0034     if [[ ! -f $1 ]]
0035     then
0036         echo "ERROR: file $1 not found."
0037         exit 1
0038     fi
0039 }
0040 
0041 ###
0042 ###Parse input 
0043 ###
0044 
0045 cmd=$1
0046 
0047 echo ">>>>>>>>>>>>>>>>> genLUT::$cmd <<<<<<<<<<<<<<<<<<<<<"
0048 for var in "$@"
0049 do
0050     if [[ $var == *=* ]]
0051     then
0052         map=(${var//=/ })
0053         echo "${map[0]}:\"${map[@]:1}\"" 
0054         eval "${map[0]}=\"${map[@]:1}\""
0055     fi
0056 done
0057 
0058 
0059 
0060 ###
0061 ### Run
0062 ###
0063 
0064 
0065 dump(){
0066     CheckParameter record 
0067     CheckParameter Run
0068     CheckParameter GlobalTag
0069 
0070     dumpCmd="cmsRun $CMSSW_RELEASE_BASE/src/CondTools/Hcal/test/runDumpHcalCond_cfg.py geometry=DB prefix="""
0071 
0072     if [ -z $frontier ]
0073     then
0074         frontier="frontier://FrontierProd/CMS_CONDITIONS"
0075     fi
0076 
0077     if [ ! -z $tag ]
0078     then
0079         if ! $dumpCmd dumplist=$record run=$Run globaltag=$GlobalTag  frontierloc=$frontier frontierlist=Hcal${record}Rcd:$tag  
0080         then
0081             exit 1
0082         fi
0083     else 
0084         if ! $dumpCmd dumplist=$record run=$Run globaltag=$GlobalTag 
0085         then
0086             exit 1
0087         fi
0088     fi
0089 
0090     mkdir -p $CondDir/$record
0091     mv ${record}_Run$Run.txt $CondDir/$record/.
0092 }
0093 
0094 if [[ "$cmd" == "dump" ]]
0095 then
0096     dump 
0097 
0098 elif [[ "$cmd" == "dumpAll" ]]
0099 then
0100     CheckParameter card
0101     CheckFile $card
0102     source $card
0103     for i in ${inputConditions[@]}; do
0104         record=$i
0105         tag=${!i}
0106         dump 
0107     done
0108 
0109 
0110 elif [[ "$cmd" == "generate" ]]
0111 then
0112     CheckParameter card
0113     CheckFile $card
0114     source $card
0115 
0116     CheckFile $HOAsciiInput
0117 
0118     rm -rf $CondDir/$Tag
0119 
0120     echo "genLUT.sh::generate: Preparing the configuration file..."
0121 
0122     sed -e "s#__LUTtag__#$Tag#g" \
0123     -e "s#__RUN__#$Run#g" \
0124     -e "s#__CONDDIR__#$BaseDir/$CondDir#g" \
0125     -e "s#__GlobalTag__#$GlobalTag#g" \
0126     -e "s#__HO_master_file__#$HOAsciiInput#g" \
0127     $templatefile > $Tag.py
0128 
0129     echo "genLUT.sh::generate: Running..."
0130 
0131     if ! cmsRun $Tag.py
0132     then
0133         echo "ERROR: LUT Generation has failed. Exiting..." 
0134         exit 1
0135     fi
0136 
0137     echo "genLUT.sh::generate: Wrapping up..."
0138 
0139     for file in $Tag*.xml; do mv $file $file.dat; done
0140 
0141     echo "-------------------"
0142     echo "-------------------"
0143     echo "Creating LUT Loader..."
0144     echo 
0145     timestamp=$(date +%s)
0146     flist=$(ls $Tag*_[0-9]*.xml.dat | xargs)
0147     if ! hcalLUT create-lut-loader outputFile="$flist" tag="$Tag" storePrepend="$description"
0148     then
0149         echo "ERROR: LUT loader generation has failed. Exiting..."
0150         exit 1
0151     fi
0152     echo
0153     echo "LUT Loader created."
0154     echo "-------------------"
0155     echo "-------------------"
0156     echo
0157 
0158     zip -j $Tag.zip *$Tag*.{xml,dat}
0159 
0160     mkdir -p $CondDir/$Tag
0161     mkdir -p $CondDir/$Tag/Deploy
0162     mv $Tag.zip $Tag.py Gen_L1TriggerObjects_$Tag.txt $CondDir/$Tag/Deploy
0163 
0164     mkdir -p $CondDir/$Tag/Debug
0165     hcalLUT merge storePrepend="$flist" outputFile=$CondDir/$Tag/${Tag}.xml
0166     mv *$Tag*.{xml,dat} $CondDir/$Tag/Debug
0167 
0168     echo "-------------------"
0169     echo "-------------------"
0170     echo "Creating Trigger Key..."
0171     echo 
0172 
0173     HcalInput=( "${inputConditions[@]/#/Hcal}" )
0174     declare -A tagMap
0175     eval $(conddb list $GlobalTag | grep -E "$(export IFS="|"; echo "${HcalInput[*]}")" | \
0176         awk '{if($2=="-" || $2=="effective") if(!($1~/^HcalPed/ && $2=="-")) print "tagMap["$1"]="$3}')
0177 
0178     individualInputTags=""
0179     for i in ${inputConditions[@]}; do
0180         t=$i
0181         v=${!t}
0182         if [[ -z $v ]]; then
0183             v=${tagMap[Hcal${i}Rcd]}
0184         fi
0185         individualInputTags="""$individualInputTags
0186     <Parameter type=\"string\" name=\"$t\">$v</Parameter>"""
0187     done
0188 
0189     dd=$(date +"%Y-%m-%d %H:%M:%S")
0190     echo """<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>
0191 <CFGBrickSet>
0192 <CFGBrick>
0193     <Parameter type=\"string\" name=\"INFOTYPE\">TRIGGERKEY</Parameter>
0194     <Parameter type=\"string\" name=\"CREATIONSTAMP\">$dd</Parameter>
0195     <Parameter type=\"string\" name=\"CREATIONTAG\">$Tag</Parameter> 
0196     <Parameter type=\"string\" name=\"HCAL_LUT_TAG\">$Tag</Parameter>  
0197     <Parameter type=\"boolean\" name=\"applyO2O\">$applyO2O</Parameter>  
0198     <Parameter type=\"string\" name=\"CMSSW\">$CMSSW_VERSION</Parameter> 
0199     <Parameter type=\"string\" name=\"InputRun\">$Run</Parameter> 
0200     <Parameter type=\"string\" name=\"GlobalTag\">$GlobalTag</Parameter>$individualInputTags 
0201     <Data elements=\"1\">1</Data> 
0202 </CFGBrick>
0203 </CFGBrickSet>""" > $CondDir/$Tag/tk_$Tag.xml
0204     
0205 elif [[ "$cmd" == "validate" ]]
0206 then
0207     CheckParameter card
0208     CheckFile $card
0209     source $card
0210 
0211     echo "Comparing input and re-generated L1TriggerObjects files"
0212     diff $CondDir/L1TriggerObjects/L1TriggerObjects_Run$Run.txt $CondDir/$Tag/Deploy/Gen_L1TriggerObjects_$Tag.txt 
0213 
0214     #parse LUT xml file and check that changes are consistent with changes in input conditions
0215     runs=$OldRun,$Run
0216     mkdir -p $CondDir/$Tag/Figures
0217     cmsRun PlotLUT.py globaltag=$GlobalTag run=$Run \
0218         inputDir=$BaseDir/$CondDir plotsDir=$CondDir/$Tag/Figures/ \
0219         tags=$OldTag,$Tag gains=$runs respcorrs=$runs pedestals=$runs quality=$runs 
0220 
0221 elif [ "$cmd" == "upload" ]
0222 then
0223     CheckParameter tag 
0224     CheckParameter dropbox
0225     lutfile=$CMSSW_BASE/src/$BaseDir/$CondDir/$tag/Deploy/$tag.zip
0226     CheckFile $lutfile
0227 
0228     scp $lutfile cmsusr:~/.
0229 
0230     cmd="scp $tag.zip $dropbox" 
0231     ssh -XY cmsusr $cmd
0232 
0233 elif [ "$cmd" == "diff" ]
0234 then
0235     if [[ $# -lt 3 ]]
0236     then
0237         echo "Bad input."
0238         exit 1
0239     fi
0240 
0241     CheckFile $2
0242     CheckFile $3
0243     echo $BaseDir/$2,$BaseDir/$3
0244 
0245     if [[ -z $verbosity ]]
0246     then
0247         verbosity=0
0248     fi
0249 
0250     hcalLUT diff inputFiles=$BaseDir/$2,$BaseDir/$3 section=$verbosity
0251 
0252 else
0253     dumpHelpAndExit
0254 fi
0255 
0256