Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-06 22:22:00

0001 #!/bin/bash
0002 
0003 #
0004 # Author: Ph Gras. CEA/IRFU - Saclay
0005 #
0006 
0007 binpath="`readlink -f "$0"`"
0008 bindir="`dirname "$binpath"`"
0009 
0010 function sigHdl(){
0011         if [ -e $TMPFILE ]; then
0012                 rm "$TMPFILE"
0013         fi
0014         exit 0
0015 }
0016 
0017 
0018 trap sigHdl SIGKILL SIGABRT SIGQUIT SIGTERM SIGPIPE SIGINT
0019 
0020 # Note that we use `"$@"' to let each command-line parameter expand to a
0021 # separate word. The quotes around `$@' are essential!
0022 # We need TEMP as the `eval set --' would nuke the return value of getopt.
0023 temp=`getopt -o hs:n:N:p:Adqgfrle: --long help,l1axmin:,l1axmax:,no-l1a-history,local-file,fed-size,feds: \
0024      -n 'dumpRaw' -- "$@"`
0025 
0026 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
0027 
0028     # Note the quotes around `$TEMP': they are essential!
0029 eval set -- "$temp"
0030 
0031 function help(){
0032      echo "usage: dumpRaw [OPTIONS...] {run_num|file_name}
0033    Dump ECAL raw data running DumpRaw module of CMSSW. CMSSW environment must be setup beforehand (see scramv1 runtime).
0034 
0035    OPTIONS:
0036     -h displays this help on usage
0037     -s N specifies number of event to skip (default 0)
0038     -n N specifies number of events to process including skipped ones
0039     -N N specifies number of events to process excluding skipped ones.
0040        To be used in place of -n option.
0041     -e event1,event2,... processes events with ID event1, event2, ...
0042     -p N prescale factor (only supported for .lmf file)
0043     -A skip ADC count dump
0044     -q no dump
0045     -d runs EBDigiAna
0046     -l runs ListCollection
0047     --fed-size runs FedSize 
0048     -g runs within gdb debugger
0049     -f --local-file file_name is a local file
0050     -r execute eval \`scramv1 runtime -sh\` in directory of $0.
0051     --no-l1a-history Disable display of L1A, BX and orbit counter history
0052     --l1axmin lower bound on l1a for histogramming 
0053     --l1aymin upper bound on l1a for histogramming 
0054     --feds FED ID range. Format first:last. E.g. for every ECAL DCCs: 601:654
0055 "
0056 }
0057 
0058 nskip=0
0059 nevts=-1
0060 dump="True"
0061 dumpAdc="True"
0062 prog=DumpRaw
0063 l1axmin=1
0064 l1axmax=600
0065 fedmin=601
0066 fedmax=654
0067 prescale=1
0068 fedmin=601
0069 fedmax=654
0070 unset nevts_
0071 l1aHist="True"
0072 unset prefix
0073 unset gdb
0074 unset cmsswdir
0075 unset eventList
0076 while true ; do
0077     case "$1" in
0078         -h|--help) help; exit 0;;
0079         -s) nskip="$2"; shift 2;;
0080         -n) nevts="$2"; shift 2;;
0081         -N) nevts_="$2"; shift 2;;
0082         -p) prescale="$2"; shift 2;;
0083         -A) dumpAdc="False"; shift;;
0084         -d) prog="EBDigiAna"; shift;;
0085         -l) prog="ListCollection";shift;;
0086         --fed-size) prog="FedSize";shift;;
0087         -q) dump="False"; shift;;
0088         -g) gdb="gdb --args"; shift;;
0089         -f|--local-file) prefix="file:"; shift;;
0090         --l1axmin) l1axmin="$2"; shift 2;;
0091         --l1axmax) l1axmax="$2"; shift 2;;
0092         --no-l1a-history) l1aHist="False"; shift;;
0093         --feds) eval `echo $2 | sed 's/\([[:digit:]]\+\):\([[:digit:]]\)/fedmin=\1 fedmax=\2/'`; shift 2;;
0094         -r) cmsswdir="$bindir"; shift;;
0095         -e) eventList="$2"; shift 2;;
0096         --) shift ; break ;; #end of options. It remains only the args.
0097         *) echo "Internal error!" ; exit 1 ;;
0098     esac
0099 done
0100 
0101 [ -n "$nevts_" ] && nevts=$((nskip+nevts_))
0102 
0103 if [ -z "$cmsswdir" -a -z "$CMSSW_BASE" ]; then
0104     echo "CMSSW environment not set (CMSSW_BASE variable not found). Setting CMSSW environment for $bindir area (scramv1 runtime)."
0105     cmsswdir="$bindir"
0106 fi
0107 
0108 if [ -n "$cmsswdir" ]; then
0109     eval `(cd "$cmsswdir" && scramv1 runtime -sh)`
0110 fi
0111 
0112 TMPFILE=`mktemp -t dumpRaw.XXXXXXX`
0113 mv "$TMPFILE" "$TMPFILE.py"
0114 TMPFILE="$TMPFILE.py"
0115 if [ -z $TMPFILE ]; then
0116         echo 'Failed to create a temporary file!'
0117         exit 1
0118 fi
0119 
0120 if [ -n "$1" ]; then
0121     if [ X"$1" = X-h -o X"$1" = X-h ];then
0122         echo "Usage: dumpRaw [datasetpath]
0123   for a local file, prefix the path by file:// or -f
0124   -s N skip N events
0125   -n N process N evnts
0126   +a skip ADC count dump
0127 "
0128         exit 0;
0129     fi
0130     if [ $1 == "-f" ]; then
0131         dataset="file://$2"
0132     else 
0133         dataset="$1"
0134     fi
0135 else
0136     echo -n "Dataset/P5 run number: "
0137     read dataset
0138 fi
0139 
0140 echo $dataset | egrep -q '^[[:digit:]]+$'
0141 
0142 if [ X$? = X0 ]; then #run number was provided instead of dataset name
0143 # local daq old format:
0144 #    dataset=`printf file:/local_data/daq/p5/P5_Co.%08d.A.0.0.root $dataset`
0145 # for P5 local daq:
0146     dataset=`printf /local_data/daq/p5/ecal_local.%08d.0001.A.storageManager.0.*.dat $dataset`
0147 #dataset=`printf /local_data/daq/p5/CalPrivateGlobal.%08d.0001.A.storageManager.0.*.dat $dataset`
0148     dataset=`ls $dataset`
0149     dataset=`echo $dataset | sed 's/[^[:space:]]*/'\''file:\0'\''/g' | tr ' ' ,`
0150 else 
0151     dataset="'${prefix}${dataset}'"
0152 fi
0153 
0154 if [ -z "$dataset" ]; then
0155         echo 'A data set name is required!'
0156         exit 1
0157 fi
0158 
0159 
0160 format=`echo "$dataset" | sed 's/.*\.\(.*\)'\''/\1/'`
0161 
0162 if [ X$format != Xlmf -a X$prescale != X1 ]; then
0163     echo "Prescale is not supported for $format file"
0164     exit 1
0165 fi
0166 
0167 cat > "$TMPFILE" <<EOF
0168 import FWCore.ParameterSet.Config as cms
0169 
0170 process = cms.Process("TEST")
0171 EOF
0172 
0173 if [ "X$format" = Xroot ]; then
0174 cat >> "$TMPFILE" <<EOF
0175 process.source = cms.Source("PoolSource",
0176    fileNames = cms.untracked.vstring( $dataset ),
0177 )
0178 EOF
0179 elif [ "X$format" = Xlmf ]; then
0180 cat >> "$TMPFILE" <<EOF
0181 process.load("CalibCalorimetry.EcalLaserSorting.LmfSource_cfi")
0182 process.source.fileNames = cms.vstring( $dataset )
0183 process.source.preScale = cms.uint32( $prescale )
0184 process.source.orderedRead = cms.bool(True)
0185 process.source.verbosity = cms.untracked.int32(0)
0186 process.source.firstLuminosityBlockForEachRun = cms.untracked.VLuminosityBlockID()
0187 EOF
0188 else
0189 cat >> "$TMPFILE" <<EOF
0190 process.source = cms.Source("NewEventStreamFileReader",
0191    fileNames = cms.untracked.vstring( $dataset )
0192 )
0193 EOF
0194 fi
0195 cat >> "$TMPFILE" <<EOF
0196 process.MessageLogger = cms.Service("MessageLogger",
0197      cout = cms.untracked.PSet(
0198          threshold = cms.untracked.string('WARNING'),
0199          default = cms.untracked.PSet(
0200              limit = cms.untracked.int32(0)
0201          )
0202      ),
0203      destinations = cms.untracked.vstring('cout')
0204  )
0205 EOF
0206 if [ X$prog = XDumpRaw ];then
0207 if [ X$l1aHist = XTrue ]; then
0208     cat >> "$TMPFILE" <<EOF
0209 process.load('EventFilter.ScalersRawToDigi.ScalersRawToDigi_cfi')
0210 process.scalersRawToDigi.scalersInputTag = 'rawDataCollector'
0211 EOF
0212     cmssw_path="process.scalersRawToDigi*"
0213 else 
0214     cmssw_path=""
0215 fi
0216 cmssw_path="${cmssw_path}process.dumpRaw"
0217 cat >> "$TMPFILE" <<EOF
0218 process.load("EventFilter.EcalRawToDigi.EcalDumpRaw_cfi")
0219 process.dumpRaw.fedRawDataCollectionTag = "source"
0220 process.dumpRaw.l1aMinX = $l1axmin
0221 process.dumpRaw.l1aMaxX = $l1axmax
0222 
0223 process.dumpRaw.first_event = $((nskip+1))
0224 process.dumpRaw.last_event  = cms.untracked.int32($((nskip+nevts)))
0225 process.dumpRaw.dumpAdc = $dumpAdc
0226 process.dumpRaw.dump = $dump
0227 process.dumpRaw.l1aHistory = $l1aHist
0228 process.dumpRaw.beg_fed_id = $fedmin
0229 process.dumpRaw.end_fed_id = $fedmax
0230 process.dumpRaw.eventList = [ $eventList ]
0231 
0232 process.dumpRaw.beg_fed_id = $fedmin
0233 process.dumpRaw.end_fed_id =  $fedmax
0234 
0235 process.p = cms.Path($cmssw_path)
0236 EOF
0237 elif [ X$prog = XListCollection ]; then
0238 cat >> "$TMPFILE" <<EOF
0239 process.load("pgras.ListCollection.ListCollection_cfi")
0240 process.p = cms.Path(process.listColl)
0241 EOF
0242 elif [ X$prog = XFedSize ]; then
0243 cat >> "$TMPFILE" <<EOF
0244 process.load("pgras.FedSize.FedSize_cfi")
0245 process.fedSize.verbosity = 2
0246 process.p = cms.Path(process.fedSize)
0247 process.TFileService = cms.Service("TFileService",
0248                                    fileName = cms.string("fedsize.root"))
0249 EOF
0250 else
0251 cat >> "$TMPFILE" <<EOF
0252 process.load("EventFilter.EcalRawToDigi.EcalUnpackerData_cfi")
0253 process.load("pgras.EBDigiAna.EBDigiAna_cfi")
0254 process.load("Geometry.EcalMapping.EcalMapping_cfi")
0255 process.load("Geometry.EcalMapping.EcalMappingRecord_cfi")
0256 
0257 process.p = cms.Path(process.ecalEBunpacker*process.ebDigiAna)
0258 EOF
0259 fi
0260 
0261 EXE=cmsRun
0262 which $EXE > /dev/null
0263 if [ $? != 0 ]; then
0264         echo "$EXE not found in PATH.  Has the CMSSW environment been set with scramv1 runtime command?"
0265         exit 1
0266 fi
0267 
0268 $gdb "$EXE" $TMPFILE
0269 
0270 if [ $? != 0 ]; then
0271 cat 1>&2 <<EOF
0272 
0273 ********************************************************************************
0274  In case of \"ProductNotFound\" exception (see above) about type
0275  "FEDRawDataCollection", try to run with the option --no-l1a-history.
0276 ********************************************************************************
0277 
0278 EOF
0279 fi
0280 
0281 #"$EXE" $TMPFILE
0282 
0283 #rm $TMPFILE